From 7ef2862128043325316a1494bfc23687fb30421f Mon Sep 17 00:00:00 2001 From: Dan Breslau Date: Wed, 17 Aug 2016 18:18:07 -0400 Subject: [PATCH] Intercept window close attempts, and ask user to confirm if selection is in progress --- src/moonshot-identity-management-view.vala | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/moonshot-identity-management-view.vala b/src/moonshot-identity-management-view.vala index aebaec9..2b0a4ba 100644 --- a/src/moonshot-identity-management-view.vala +++ b/src/moonshot-identity-management-view.vala @@ -881,7 +881,31 @@ SUCH DAMAGE. private void connect_signals() { - this.destroy.connect(Gtk.main_quit); + this.destroy.connect(() => { + logger.trace("Destroy event; calling Gtk.main_quit()"); + Gtk.main_quit(); + }); this.identities_manager.card_list_changed.connect(this.on_card_list_changed); + this.delete_event.connect(() => {return confirm_quit();}); + } + + private bool confirm_quit() { + logger.trace("delete_event intercepted; selection_in_progress()=" + selection_in_progress().to_string()); + + if (selection_in_progress()) { + var result = WarningDialog.confirm(this, + Markup.printf_escaped( + _("Do you wish to use the %s service?"), + this.request_queue.peek_head().service) + + _("\n\nSelect Yes to select an ID for this service, or No to cancel"), + "close_moonshot_window"); + if (result) { + // Prevent other handlers from handling this event; this keeps the window open. + return true; + } + } + + // Allow the window deletion to proceed. + return false; } } -- 2.1.4