[gitg] Make the preferences interface a template



commit 4f4e730febc6138e29b12832efbc1545206d3b67
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Sun Jul 7 11:57:18 2013 +0200

    Make the preferences interface a template

 gitg/preferences/gitg-preferences-interface.vala |   38 ++++++++--------------
 gitg/resources/ui/gitg-preferences-interface.ui  |    4 +-
 2 files changed, 16 insertions(+), 26 deletions(-)
---
diff --git a/gitg/preferences/gitg-preferences-interface.vala 
b/gitg/preferences/gitg-preferences-interface.vala
index 948b747..061db85 100644
--- a/gitg/preferences/gitg-preferences-interface.vala
+++ b/gitg/preferences/gitg-preferences-interface.vala
@@ -20,57 +20,47 @@
 namespace Gitg
 {
 
-class PreferencesInterface : Object, GitgExt.Preferences
+[GtkTemplate (ui = "/org/gnome/gitg/ui/gitg-preferences-interface.ui")]
+public class PreferencesInterface : Gtk.Grid, GitgExt.Preferences
 {
        // Do this to pull in config.h before glib.h (for gettext...)
        private const string version = Gitg.Config.VERSION;
        private bool d_block;
 
-       private Gtk.Widget d_widget;
+       [GtkChild (name = "horizontal_layout_enabled")]
+       Gtk.CheckButton d_horizontal_layout_enabled;
 
-       private Gtk.Widget build_ui()
+       construct
        {
-               if (d_widget != null)
-               {
-                       return d_widget;
-               }
-
                var settings = new Settings("org.gnome.gitg.preferences.interface");
 
-               var ret = GitgExt.UI.from_builder("ui/gitg-preferences-interface.ui",
-                                                 "main",
-                                                 "horizontal_layout_enabled");
-
-               d_widget = ret["main"] as Gtk.Widget;
-
-               var check = ret["horizontal_layout_enabled"] as Gtk.CheckButton;
+               d_horizontal_layout_enabled.active = settings.get_enum("orientation") == 0;
 
-               check.active = settings.get_enum("orientation") == 0;
-
-               check.notify["active"].connect((obj, spec)=> {
+               d_horizontal_layout_enabled.notify["active"].connect((obj, spec)=> {
                        if (d_block)
                        {
                                return;
                        }
 
-                       if (!settings.set_enum("orientation", check.active ? 0 : 1))
+                       if (!settings.set_enum("orientation", d_horizontal_layout_enabled.active ? 0 : 1))
                        {
-                               check.active = settings.get_enum("orientation") == 0;
+                               d_horizontal_layout_enabled.active = settings.get_enum("orientation") == 0;
                        }
                });
 
                settings.changed["orientation"].connect((s, k) => {
                        d_block = true;
-                       check.active = settings.get_enum("orientation") == 0;
+                       d_horizontal_layout_enabled.active = settings.get_enum("orientation") == 0;
                        d_block = false;
                });
-
-               return d_widget;
        }
 
        public Gtk.Widget widget
        {
-               owned get { return build_ui(); }
+               owned get
+               {
+                       return this;
+               }
        }
 
        public string id
diff --git a/gitg/resources/ui/gitg-preferences-interface.ui b/gitg/resources/ui/gitg-preferences-interface.ui
index de7dc2b..85cd4c5 100644
--- a/gitg/resources/ui/gitg-preferences-interface.ui
+++ b/gitg/resources/ui/gitg-preferences-interface.ui
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
-  <object class="GtkGrid" id="main">
+  <template class="GitgPreferencesInterface" parent="GtkGrid">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
     <property name="has_focus">False</property>
@@ -91,5 +91,5 @@
         <property name="height">1</property>
       </packing>
     </child>
-  </object>
+  </template>
 </interface>


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