[geary/wip/720794-modal] Make PreferencesDialog transitory dialog box



commit e32ca28ed9c4b0d6ae2ac17232b63a4613d9d80d
Author: Jim Nelson <jim yorba org>
Date:   Fri Dec 20 15:45:50 2013 -0800

    Make PreferencesDialog transitory dialog box

 src/client/application/geary-controller.vala |    3 +-
 src/client/dialogs/preferences-dialog.vala   |   48 ++++++++------------------
 2 files changed, 17 insertions(+), 34 deletions(-)
---
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 0f1b5c6..566b519 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -1302,7 +1302,8 @@ public class GearyController : Geary.BaseObject {
     }
     
     private void on_preferences() {
-        PreferencesDialog.show_instance(main_window);
+        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 91d48f8..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,36 +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(Gtk.Window parent) {
-        if (preferences_dialog == null) 
-            preferences_dialog = new PreferencesDialog(GearyApplication.instance.config);
-
-        preferences_dialog.dialog.set_transient_for(parent);
-        preferences_dialog.dialog.set_modal(true);
-        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]