diff --git a/connect_gui.py b/connect_gui.py index 6d0bbab..4c21ab9 100644 --- a/connect_gui.py +++ b/connect_gui.py @@ -4,3 +4,4 @@ def connect_gui(app): app.main_window.openFile.triggered.connect(app.file_actions.open_files) app.main_window.saveFile.triggered.connect(app.file_actions.save_current_file) app.main_window.openFileTabs.tabCloseRequested.connect(app.file_actions.close_current_file) + app.QTMainWindow.closeEvent = app.utils.on_close diff --git a/file.py b/file.py index bc3854c..ad833cf 100644 --- a/file.py +++ b/file.py @@ -55,6 +55,12 @@ class FileActions: self.close_file(current_file_path, tab_index) + def save_all_files(self): + for file_path in self.app.open_files: + file = self.app.open_files[file_path] + + self.save_file(file.path) + class File: def __init__(self, app, path, name): diff --git a/utils.py b/utils.py index f89318d..1642356 100644 --- a/utils.py +++ b/utils.py @@ -52,3 +52,25 @@ class Utils: binary_string = bytes(bytes_int) return binary_string + + def on_close(self, event): + changes = False + + for file_path in self.app.open_files: + file = self.app.open_files[file_path] + + if file.not_saved: + changes = True + break + + if changes: + save_or_not = self.unsaved_changes_popup() + + match save_or_not: + case "save": + self.app.file_actions.save_all_files() + + case "cancel": + event.ignore() + + print("Bye!")