[geary] Make application dialogs transient and modal: Closes bgno#720794



commit b4d259100c40647cce55cbffbce624b11ab66b1b
Author: William Jon McCann <william jon mccann gmail com>
Date:   Fri Dec 20 16:35:36 2013 -0800

    Make application dialogs transient and modal: Closes bgno#720794
    
    This makes both the Preferences and Accounts dialogs modal and
    transient for the parent window.  Additional code changes are to
    remove logic in place to deal with previouys modeless-ness of those
    dialogs.

 src/client/accounts/account-dialog.vala      |   25 ++------------
 src/client/application/geary-controller.vala |    8 +++-
 src/client/dialogs/preferences-dialog.vala   |   46 ++++++++-----------------
 3 files changed, 25 insertions(+), 54 deletions(-)
---
diff --git a/src/client/accounts/account-dialog.vala b/src/client/accounts/account-dialog.vala
index f6a4eae..1102bf5 100644
--- a/src/client/accounts/account-dialog.vala
+++ b/src/client/accounts/account-dialog.vala
@@ -7,8 +7,6 @@
 public class AccountDialog : Gtk.Dialog {
     private const int MARGIN = 12;
     
-    private static AccountDialog? account_dialog = null;
-    
     private Gtk.Notebook notebook = new Gtk.Notebook();
     private AccountDialogAccountListPane account_list_pane;
     private AccountDialogAddEditPane add_edit_pane;
@@ -16,9 +14,11 @@ public class AccountDialog : Gtk.Dialog {
     private AccountDialogRemoveConfirmPane remove_confirm_pane;
     private AccountDialogRemoveFailPane remove_fail_pane;
     
-    private AccountDialog() {
+    public AccountDialog(Gtk.Window parent) {
         set_size_request(450, -1); // Sets min size.
         title = _("Accounts");
+        set_transient_for(parent);
+        set_modal(true);
         get_content_area().margin_top = MARGIN;
         get_content_area().margin_left = MARGIN;
         get_content_area().margin_right = MARGIN;
@@ -42,8 +42,6 @@ public class AccountDialog : Gtk.Dialog {
         remove_confirm_pane.ok.connect(on_delete_account_confirmed);
         remove_confirm_pane.cancel.connect(on_cancel_back_to_list);
         remove_fail_pane.ok.connect(on_cancel_back_to_list);
-        delete_event.connect(on_delete);
-        response.connect(on_close);
         
         // Set default page.
         account_list_pane.present();
@@ -57,14 +55,6 @@ public class AccountDialog : Gtk.Dialog {
         notebook.show_all(); // Required due to longstanding Gtk.Notebook bug
     }
     
-    public static void show_instance() {
-        if (account_dialog == null) {
-            account_dialog = new AccountDialog();
-        }
-        account_dialog.show_all();
-        account_dialog.present();
-    }
-    
     // This is a hack to allow key events in this window.  Gtk.Notebook will attempt to propagate
     // key events to Widgets which have not yet been realized; by forcing them to realize here,
     // we can avoid assertions and allow the Escape key to close the dialog.
@@ -78,15 +68,8 @@ public class AccountDialog : Gtk.Dialog {
         account_list_pane.present();
     }
     
-    private bool on_delete() {
-        return hide_on_delete();
-    }
-    
     private void on_close() {
-        hide();
-        
-        // Go back to default page.
-        account_list_pane.present();
+        response(Gtk.ResponseType.CLOSE);
     }
     
     private void on_add_account() {
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 5b49fd4..da59363 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -1298,11 +1298,15 @@ public class GearyController : Geary.BaseObject {
     }
     
     private void on_accounts() {
-        AccountDialog.show_instance();
+        AccountDialog dialog = new AccountDialog(main_window);
+        dialog.show_all();
+        dialog.run();
+        dialog.destroy();
     }
     
     private void on_preferences() {
-        PreferencesDialog.show_instance();
+        PreferencesDialog dialog = new PreferencesDialog(main_window);
+        dialog.run();
     }
     
     private Gee.ArrayList<Geary.EmailIdentifier> get_conversation_email_ids(
diff --git a/src/client/dialogs/preferences-dialog.vala b/src/client/dialogs/preferences-dialog.vala
index d253fc9..8b7c592 100644
--- a/src/client/dialogs/preferences-dialog.vala
+++ b/src/client/dialogs/preferences-dialog.vala
@@ -5,8 +5,6 @@
  */
 
 public class PreferencesDialog : Object {
-    private static PreferencesDialog? preferences_dialog = null;
-    
     private Gtk.Dialog dialog;
     private Gtk.CheckButton autoselect;
     private Gtk.CheckButton display_preview;
@@ -16,12 +14,16 @@ public class PreferencesDialog : Object {
     private Gtk.Button close_button;
     private Configuration config;
     
-    private PreferencesDialog(Configuration config) {
-        this.config = config;
+    public PreferencesDialog(Gtk.Window parent) {
+        this.config = GearyApplication.instance.config;
+        
         Gtk.Builder builder = GearyApplication.instance.create_builder("preferences.glade");
         
         // Get all of the dialog elements.
         dialog = builder.get_object("dialog") as Gtk.Dialog;
+        dialog.set_transient_for(parent);
+        dialog.set_modal(true);
+        
         autoselect = builder.get_object("autoselect") as Gtk.CheckButton;
         display_preview = builder.get_object("display_preview") as Gtk.CheckButton;
         spell_check = builder.get_object("spell_check") as Gtk.CheckButton;
@@ -29,7 +31,11 @@ public class PreferencesDialog : Object {
         show_notifications = builder.get_object("show_notifications") as Gtk.CheckButton;
         close_button = builder.get_object("close_button") as Gtk.Button;
         
-        populate_preference_options();
+        autoselect.active = config.autoselect;
+        display_preview.active = config.display_preview;
+        spell_check.active = config.spell_check;
+        play_sounds.active = config.play_sounds;
+        show_notifications.active = config.show_notifications;
         
         // Connect to element signals.
         autoselect.toggled.connect(on_autoselect_toggled);
@@ -37,34 +43,12 @@ public class PreferencesDialog : Object {
         spell_check.toggled.connect(on_spell_check_toggled);
         play_sounds.toggled.connect(on_play_sounds_toggled);
         show_notifications.toggled.connect(on_show_notifications_toggled);
-        
-        dialog.delete_event.connect(on_delete);
-        dialog.response.connect(on_close);
-    }
-    
-    public void populate_preference_options() {
-        autoselect.active = config.autoselect;
-        display_preview.active = config.display_preview;
-        spell_check.active = config.spell_check;
-        play_sounds.active = config.play_sounds;
-        show_notifications.active = config.show_notifications;    
-    }
-    
-    public static void show_instance() {
-        if (preferences_dialog == null) 
-            preferences_dialog = new PreferencesDialog(GearyApplication.instance.config);
-        
-        preferences_dialog.populate_preference_options();
-        preferences_dialog.dialog.show_all();
-        preferences_dialog.dialog.present();
-    }
-    
-    private bool on_delete() {
-        return dialog.hide_on_delete(); //prevent widgets from getting destroyed
     }
     
-    private void on_close() {
-        dialog.hide();
+    public void run() {
+        dialog.show_all();
+        dialog.run();
+        dialog.destroy();
     }
     
     private void on_autoselect_toggled() {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]