Fixed display of the no_identity widget, and don't allow it to be removed
[moonshot-ui.git] / src / moonshot-identity-management-view.vala
index aebaec9..1c7a384 100644 (file)
@@ -231,7 +231,7 @@ public class IdentityManagerView : Window {
         }
 
         foreach (IdCard id_card in card_list) {
-            logger.trace(@"load_id_cards: Adding card with display name '$(id_card.display_name)'");
+            logger.trace(@"load_id_cards: Loading card with display name '$(id_card.display_name)'");
             add_id_card_data(id_card);
             IdCardWidget id_card_widget = add_id_card_widget(id_card);
             if (id_card_widget.id_card.nai == current_idcard_nai) {
@@ -305,7 +305,8 @@ public class IdentityManagerView : Window {
 
     private void widget_selected_cb(IdCardWidget id_card_widget)
     {
-        this.remove_button.set_sensitive(true);
+        bool allow_removes = !id_card_widget.id_card.is_no_identity();
+        this.remove_button.set_sensitive(allow_removes);
         this.edit_button.set_sensitive(true);
         this.custom_vbox.receive_expanded_event(id_card_widget);
 
@@ -334,7 +335,7 @@ public class IdentityManagerView : Window {
         Gtk.MessageDialog dialog;
         IdCard? prev_id = identities_manager.find_id_card(id_card.nai, force_flat_file_store);
         logger.trace("add_identity(flat=%s, card='%s'): find_id_card returned %s"
-                     .printf(force_flat_file_store.to_string(), id_card.display_name, (prev_id != null ? "non-null" : "null")));
+                     .printf(force_flat_file_store.to_string(), id_card.display_name, (prev_id != null ? prev_id.display_name : "null")));
         if (prev_id!=null) {
             int flags = prev_id.Compare(id_card);
             logger.trace("add_identity: compare returned " + flags.to_string());
@@ -490,7 +491,10 @@ public class IdentityManagerView : Window {
 
     public void queue_identity_request(IdentityRequest request)
     {
-        if (!this.selection_in_progress())
+        bool queue_was_empty = !this.selection_in_progress();
+        this.request_queue.push_tail(request);
+
+        if (queue_was_empty)
         { /* setup widgets */
             candidates = request.candidates;
             filter.refilter();
@@ -499,7 +503,6 @@ public class IdentityManagerView : Window {
             remember_identity_binding.show();
             make_visible();
         }
-        this.request_queue.push_tail(request);
     }
 
 
@@ -881,7 +884,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(
+                                                   _("<span font-weight='heavy'>Do you wish to use the %s service?</span>"),
+                                                   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;
     }
 }