Use more friendly exit confirm dialogs
authorJakob Cornell <jakob@jcornell.net>
Tue, 7 Jan 2020 02:30:23 +0000 (20:30 -0600)
committerJakob Cornell <jakob@jcornell.net>
Tue, 7 Jan 2020 02:30:23 +0000 (20:30 -0600)
main.py

diff --git a/main.py b/main.py
index 41448c19e77afce0e0948271bdf1a04538ce7da7..389a781d2300bc940af4fdddabb73b3288bdef3f 100644 (file)
--- a/main.py
+++ b/main.py
@@ -182,11 +182,13 @@ class MainView(View):
                def on_close():
                        if self.editor_views:
                                next(iter(self.editor_views.values())).root.lift()
-                       elif (
-                               not self.controller.dirty
-                               or messagebox.askokcancel("Confirm", "You have unsaved changes. Quit anyway?")
-                       ):
-                               self.controller.save_state()
+                       elif self.controller.dirty:
+                               result = messagebox.askyesnocancel("Confirm", "You have unsaved changes. Save before exiting?")
+                               if result is True:
+                                       self.controller.save_state()
+                               if result is not None:
+                                       self.root.destroy()
+                       else:
                                self.root.destroy()
                self.root.protocol('WM_DELETE_WINDOW', on_close)
 
@@ -388,8 +390,13 @@ class DataEditView(View):
                self.parent_view = parent_view
 
                def on_close():
-                       do = not self.dirty or messagebox.askokcancel("Confirm", "Discard changes?")
-                       if do:
+                       if self.dirty:
+                               result = messagebox.askyesnocancel("Confirm", "Save data before closing?")
+                               if result is True:
+                                       on_ok()
+                               elif result is False:
+                                       self.finish()
+                       else:
                                self.finish()
                self.root = tk.Toplevel(parent)
                self.root.resizable(False, False)