Skip to content

Commit fefeac2

Browse files
committed
Added confirmation button before overwriting file
1 parent 2259fc7 commit fefeac2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

main.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,14 @@ def save_file(self):
216216
# Overwrite existing file
217217
content = self.text_edit.toPlainText()
218218
try:
219-
with open(self.current_file_path, "w", encoding="utf-8") as file:
220-
file.write(content)
219+
reply = QMessageBox.question(self, "Confirm File Overwrite",
220+
f"You are about to overwrite:{self.current_file_path}"
221+
f"This will permanently replace the existing file. Are you sure you want to continue?",
222+
QMessageBox.StandardButton.Yes,
223+
QMessageBox.StandardButton.No)
224+
if reply == QMessageBox.StandardButton.Yes:
225+
with open(self.current_file_path, "w", encoding="utf-8") as file:
226+
file.write(content)
221227
except Exception as e:
222228
QMessageBox.critical(self, "Error", f"Failed to save file: {str(e)}")
223229
else:

0 commit comments

Comments
 (0)