diff --git a/mtg-collector/gui.py b/mtg-collector/gui.py index ce55b58..28df7c8 100644 --- a/mtg-collector/gui.py +++ b/mtg-collector/gui.py @@ -102,6 +102,14 @@ class MainWindow(Gtk.Window): def mb_save_lib(self, menu_item): util.save_library() + def do_delete_event(self, event): + if util.unsaved_changes: + response = util.show_question_dialog("Unsaved Changes", "You have unsaved changes in your library. " + "Save before exiting?") + if response == Gtk.ResponseType.YES: + util.save_library() + + win = MainWindow() win.connect('delete-event', Gtk.main_quit) GObject.threads_init() diff --git a/mtg-collector/util.py b/mtg-collector/util.py index 14353f8..295e3a1 100644 --- a/mtg-collector/util.py +++ b/mtg-collector/util.py @@ -99,6 +99,14 @@ def push_status(msg): status_bar.push(0, msg) +def show_question_dialog(title, message): + dialog = Gtk.MessageDialog(window, 0, Gtk.MessageType.QUESTION, + Gtk.ButtonsType.YES_NO, title) + dialog.format_secondary_text(message) + response = dialog.run() + dialog.destroy + return response + def show_message(title, message): dialog = Gtk.MessageDialog(window, 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, title)