[dconf] editor: Remember window size



commit 7fa7eee78d7d9152ed771da360527fa3b54fc34f
Author: Robert Ancell <robert ancell canonical com>
Date:   Sun May 8 18:13:53 2011 +0200

    editor: Remember window size
    
    Fixes https://bugzilla.gnome.org/show_bug.cgi?id=641293

 configure.ac                             |    3 ++
 editor/Makefile.am                       |    8 +++++-
 editor/ca.desrt.dconf-editor.gschema.xml |   20 +++++++++++++++++++
 editor/dconf-editor.ui                   |    2 +
 editor/dconf-editor.vala                 |   31 ++++++++++++++++++++++++++++++
 5 files changed, 62 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 1983c41..c83b423 100644
--- a/configure.ac
+++ b/configure.ac
@@ -15,6 +15,9 @@ AM_SILENT_RULES([yes])
 AC_PROG_CC
 AM_PROG_VALAC([0.11.7])
 
+# Use GSettings
+GLIB_GSETTINGS
+
 # Gtk-doc support
 GTK_DOC_CHECK([1.15])
 
diff --git a/editor/Makefile.am b/editor/Makefile.am
index df2ad1a..d33b332 100644
--- a/editor/Makefile.am
+++ b/editor/Makefile.am
@@ -10,6 +10,10 @@ desktopdir = $(datadir)/applications
 desktop_in_files = dconf-editor.desktop.in.in
 desktop_DATA = $(desktop_in_files:.desktop.in.in=.desktop)
 
+gsettings_SCHEMAS = ca.desrt.dconf-editor.gschema.xml
+ GSETTINGS_RULES@
+
 uidir = $(datadir)/dconf-editor
-ui_DATA = dconf-editor.ui
-EXTRA_DIST = dconf-editor.ui
+dist_ui_DATA = dconf-editor.ui
+
+EXTRA_DIST = $(gsettings_SCHEMAS)
diff --git a/editor/ca.desrt.dconf-editor.gschema.xml b/editor/ca.desrt.dconf-editor.gschema.xml
new file mode 100644
index 0000000..5d4ae62
--- /dev/null
+++ b/editor/ca.desrt.dconf-editor.gschema.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schemalist>
+  <schema id="ca.desrt.dconf-editor.Settings" path="/ca/desrt/glchess/" gettext-domain="dconf-editor">
+    <key name="width" type="i">
+      <default>600</default>
+      <summary>The width of the window</summary>
+      <description>The width of the main window in pixels.</description>
+    </key>
+    <key name="height" type="i">
+      <default>300</default>
+      <summary>The height of the window</summary>
+      <description>The height of the main window in pixels.</description>
+    </key>
+    <key name="maximized" type="b">
+      <default>false</default>
+      <summary>A flag to enable maximized mode</summary>
+      <description>A flag to enable maximized mode</description>
+    </key>
+  </schema>
+</schemalist>
diff --git a/editor/dconf-editor.ui b/editor/dconf-editor.ui
index 6dbdc8f..7416425 100644
--- a/editor/dconf-editor.ui
+++ b/editor/dconf-editor.ui
@@ -13,6 +13,8 @@
     <property name="title" translatable="yes">Configuration Editor</property>
     <property name="default_width">600</property>
     <property name="default_height">300</property>
+    <signal name="window-state-event" handler="main_window_window_state_event_cb" swapped="no"/>
+    <signal name="configure-event" handler="main_window_configure_event_cb" swapped="no"/>
     <child>
       <object class="GtkHBox" id="hbox1">
         <property name="visible">True</property>
diff --git a/editor/dconf-editor.vala b/editor/dconf-editor.vala
index 7b1356d..40e9e54 100644
--- a/editor/dconf-editor.vala
+++ b/editor/dconf-editor.vala
@@ -2,6 +2,7 @@ class ConfigurationEditor
 {
     private SettingsModel model;
 
+    private Settings settings;
     private Gtk.Builder ui;
     private Gtk.Window window;
     private Gtk.TreeView dir_tree_view;
@@ -18,6 +19,8 @@ class ConfigurationEditor
 
     public ConfigurationEditor()
     {
+        settings = new Settings ("ca.desrt.dconf-editor.Settings");
+
         model = new SettingsModel();
 
         ui = new Gtk.Builder();
@@ -33,6 +36,10 @@ class ConfigurationEditor
         window = (Gtk.Window)ui.get_object("main_window");
         window.destroy.connect(Gtk.main_quit);
 
+        window.set_default_size (settings.get_int ("width"), settings.get_int ("height"));
+        if (settings.get_boolean ("maximized"))
+            window.maximize ();
+
         dir_tree_view = new DConfDirView();
         dir_tree_view.set_model(model);
         dir_tree_view.get_selection().changed.connect(dir_selected_cb); // FIXME: Put in view
@@ -176,6 +183,30 @@ class ConfigurationEditor
         selected_key.set_to_default();
     }
 
+    [CCode (cname = "G_MODULE_EXPORT main_window_configure_event_cb", instance_pos = -1)]
+    public bool main_window_configure_event_cb (Gtk.Widget widget, Gdk.EventConfigure event)
+    {
+        if (!settings.get_boolean ("maximized"))
+        {
+            settings.set_int ("width", event.width);
+            settings.set_int ("height", event.height);
+        }
+
+        return false;
+    }
+
+    [CCode (cname = "G_MODULE_EXPORT main_window_window_state_event_cb", instance_pos = -1)]
+    public bool main_window_window_state_event_cb (Gtk.Widget widget, Gdk.EventWindowState event)
+    {
+        if ((event.changed_mask & Gdk.WindowState.MAXIMIZED) != 0)
+        {
+            var is_maximized = (event.new_window_state & Gdk.WindowState.MAXIMIZED) != 0;
+            settings.set_boolean ("maximized", is_maximized);
+        }
+
+        return false;
+    }
+
     public static int main(string[] args)
     {
         Gtk.init(ref args);



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