Now the editor even warns when it gets closed and there are any unsaved files.
This commit is contained in:
parent
0a17c54d85
commit
782ada62d5
3 changed files with 29 additions and 0 deletions
|
@ -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
|
||||
|
|
6
file.py
6
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):
|
||||
|
|
22
utils.py
22
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!")
|
||||
|
|
Loading…
Reference in a new issue