[gitg] Handle window size and state



commit 746b40e78f81e9f70193354cc56bfc778616f09e
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Wed Feb 20 18:22:13 2013 +0100

    Handle window size and state

 gitg/gitg-application.vala |   16 ++++++++++++++++
 gitg/gitg-window.vala      |   32 ++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 0 deletions(-)
---
diff --git a/gitg/gitg-application.vala b/gitg/gitg-application.vala
index 5622237..876edbd 100644
--- a/gitg/gitg-application.vala
+++ b/gitg/gitg-application.vala
@@ -22,6 +22,13 @@ namespace Gitg
 
 public class Application : Gtk.Application
 {
+       private Settings d_state_settings;
+
+       public Settings state_settings
+       {
+               owned get { return d_state_settings; }
+       }
+
        public Application()
        {
                Object(application_id: "org.gnome.gitg",
@@ -279,12 +286,21 @@ public class Application : Gtk.Application
 
        protected override void startup()
        {
+               d_state_settings = new Settings("org.gnome.gitg.state.window");
+               d_state_settings.delay();
+
                Options.startup = true;
                base.startup();
 
                setup_menus();
        }
 
+       protected override void shutdown()
+       {
+               d_state_settings.apply();
+               base.shutdown();
+       }
+
        protected override void activate()
        {
                /* Application gets activated when no command line arguments have
diff --git a/gitg/gitg-window.vala b/gitg/gitg-window.vala
index c8fc52b..56dae14 100644
--- a/gitg/gitg-window.vala
+++ b/gitg/gitg-window.vala
@@ -22,6 +22,7 @@ namespace Gitg
 
 public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable, Gtk.Buildable
 {
+       private Settings d_state_settings;
        private Repository? d_repository;
        private GitgExt.MessageBus d_message_bus;
        private string? d_action;
@@ -59,6 +60,22 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable, Gtk.
                owned get { return d_repository; }
        }
 
+       protected override bool window_state_event(Gdk.EventWindowState event)
+       {
+               d_state_settings.set_int("state", event.new_window_state);
+               return base.window_state_event(event);
+       }
+
+       protected override bool configure_event(Gdk.EventConfigure event)
+       {
+               if (this.get_realized() && !(Gdk.WindowState.MAXIMIZED in get_window().get_state()))
+               {
+                       d_state_settings.set("size", "(ii)", event.width, event.height);
+               }
+
+               return base.configure_event(event);
+       }
+
        private void parser_finished(Gtk.Builder builder)
        {
                // Extract widgets from the builder
@@ -144,6 +161,10 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable, Gtk.
 
        private bool init(Cancellable? cancellable)
        {
+               // Settings
+               var app = application as Gitg.Application;
+               d_state_settings = app.state_settings;
+
                // Setup message bus
                d_message_bus = new GitgExt.MessageBus();
 
@@ -175,6 +196,16 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable, Gtk.
                        d_header_bar.title = workdir.get_basename();
                }
 
+               // Setup window geometry saving
+               Gdk.WindowState window_state = (Gdk.WindowState)d_state_settings.get_int("state");
+               if (Gdk.WindowState.MAXIMIZED in window_state) {
+                       maximize ();
+               }
+
+               int width, height;
+               d_state_settings.get ("size", "(ii)", out width, out height);
+               resize (width, height);
+
                activate_default_view();
                return true;
        }
@@ -187,6 +218,7 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable, Gtk.
 
                if (ret != null)
                {
+                       ret.application = app;
                        ret.d_repository = repository;
                        ret.d_action = action;
                }


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