[baobab] window: remember size and maximized state



commit c2bcb52dfee280f8ed027816f7d4d6d50635cfb1
Author: Stefano Facchini <stefano facchini gmail com>
Date:   Mon Oct 22 15:18:52 2012 +0200

    window: remember size and maximized state
    
    https://bugzilla.gnome.org/show_bug.cgi?id=611843

 data/org.gnome.baobab.gschema.xml.in |   10 ++++++++++
 src/baobab-application.vala          |   14 +++++++-------
 src/baobab-window.vala               |   23 ++++++++++++++++++++++-
 3 files changed, 39 insertions(+), 8 deletions(-)
---
diff --git a/data/org.gnome.baobab.gschema.xml.in b/data/org.gnome.baobab.gschema.xml.in
index bd45e54..28f1308 100644
--- a/data/org.gnome.baobab.gschema.xml.in
+++ b/data/org.gnome.baobab.gschema.xml.in
@@ -16,5 +16,15 @@
       <_summary>Active Chart</_summary>
       <_description>Which type of chart should be displayed.</_description>
     </key>
+    <key name="window-size" type="(ii)">
+      <default>(960, 600)</default>
+      <_summary>Window size</_summary>
+      <_description>The initial size of the window</_description>
+    </key>
+    <key name="window-state" type="i">
+      <default>0</default>
+      <_summary>Window state</_summary>
+      <_description>The GdkWindowState of the window</_description>
+    </key>
   </schema>
 </schemalist>
diff --git a/src/baobab-application.vala b/src/baobab-application.vala
index 4c6fc97..c5a493f 100644
--- a/src/baobab-application.vala
+++ b/src/baobab-application.vala
@@ -35,7 +35,6 @@ namespace Baobab {
             { "quit", on_quit_activate }
         };
 
-        Settings desktop_settings;
         Settings prefs_settings;
         Settings ui_settings;
 
@@ -80,7 +79,8 @@ namespace Baobab {
             // Settings
             ui_settings = new Settings ("org.gnome.baobab.ui");
             prefs_settings = new Settings ("org.gnome.baobab.preferences");
-            desktop_settings = new Settings ("org.gnome.desktop.interface");
+
+            ui_settings.delay ();
 
             // Menus: in gnome shell we just use the app menu, since the remaining
             // items are too few to look ok in a menubar and they are not essential
@@ -125,17 +125,17 @@ namespace Baobab {
             return base.local_command_line (ref arguments, out exit_status);
         }
 
+        protected override void shutdown () {
+            ui_settings.apply ();
+            base.shutdown ();
+        }
+
         public Application () {
             Object (application_id: "org.gnome.baobab", flags: ApplicationFlags.HANDLES_OPEN);
 
             add_action_entries (action_entries, this);
         }
 
-        public static Settings get_desktop_settings () {
-            var app = baobab;
-            return app.desktop_settings;
-        }
-
         public static Settings get_prefs_settings () {
             var app = baobab;
             return app.prefs_settings;
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index cb2ef7a..018e69f 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -162,9 +162,30 @@ namespace Baobab {
             drag_data_received.connect (on_drag_data_received);
             enable_drop ();
 
+            // Setup window geometry saving
+            Gdk.WindowState window_state = (Gdk.WindowState) ui_settings.get_int ("window-state");
+            if (Gdk.WindowState.MAXIMIZED in window_state) {
+                maximize ();
+            }
+
+            int width, height;
+            ui_settings.get ("window-size", "(ii)", out width, out height);
+            resize (width, height);
+
+            window_state_event.connect ((event) => {
+                ui_settings.set_int ("window-state", event.new_window_state);
+                return false;
+            });
+
+            configure_event.connect ((event) => {
+                if (!(Gdk.WindowState.MAXIMIZED in get_window ().get_state ())) {
+                    ui_settings.set ("window-size", "(ii)", event.width, event.height);
+                }
+                return false;
+            });
+
             add (builder.get_object ("window-contents") as Gtk.Widget);
             title = _("Disk Usage Analyzer");
-            set_default_size (960, 600);
             set_hide_titlebar_when_maximized (true);
 
             active_location = null;



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