[gitg] Added interface preferences pane



commit e35c202963a5b443fd5b1e4bf998fbb2cd08c1f8
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Fri Nov 2 17:02:01 2012 +0100

    Added interface preferences pane

 gitg/Makefile.am                                |    3 +-
 gitg/gitg-preferences-dialog.vala               |   40 +++++----
 gitg/gitg-preferences-interface.vala            |   98 ++++++++++++++++++++++
 gitg/resources/gitg-resources.xml               |    3 +-
 gitg/resources/ui/gitg-preferences-interface.ui |  101 +++++++++++++++++++++++
 5 files changed, 226 insertions(+), 19 deletions(-)
---
diff --git a/gitg/Makefile.am b/gitg/Makefile.am
index 4ccd7a2..35e6068 100644
--- a/gitg/Makefile.am
+++ b/gitg/Makefile.am
@@ -35,7 +35,8 @@ VALASOURCES =							\
 	gitg-plugins-engine.vala				\
 	gitg-ui-elements.vala					\
 	gitg-autohide-frame.vala				\
-	gitg-preferences-dialog.vala
+	gitg-preferences-dialog.vala				\
+	gitg-preferences-interface.vala
 
 BUILT_SOURCES = 						\
 	gitg-resources.c					\
diff --git a/gitg/gitg-preferences-dialog.vala b/gitg/gitg-preferences-dialog.vala
index 99b4416..c1c2672 100644
--- a/gitg/gitg-preferences-dialog.vala
+++ b/gitg/gitg-preferences-dialog.vala
@@ -35,31 +35,37 @@ class PreferencesDialog : Gtk.Dialog, Gtk.Buildable
 		base.parser_finished(builder);
 	}
 
-	public void populate()
+	private void add_page(GitgExt.Preferences pref, HashTable<string, Gtk.Box> pages)
 	{
-		var engine = PluginsEngine.get_default();
-		var ext = new Peas.ExtensionSet(engine, typeof(GitgExt.Preferences));
+		Gtk.Box page;
 
-		var pages = new HashTable<string, Gtk.Box>(str_hash, str_equal);
+		if (!pages.lookup_extended(pref.id, null, out page))
+		{
+			page = new Gtk.Box(Gtk.Orientation.VERTICAL, 6);
 
-		ext.foreach((s, info, e) => {
-			var pref = e as GitgExt.Preferences;
-			Gtk.Box page;
+			page.show();
+			pages.insert(pref.id, page);
+
+			var lbl = new Gtk.Label(pref.display_name);
+			lbl.show();
+
+			d_notebook.append_page(page, lbl);
+		}
 
-			if (!pages.lookup_extended(pref.id, null, out page))
-			{
-				page = new Gtk.Box(Gtk.Orientation.VERTICAL, 6);
+		page.add(pref.widget);
+	}
 
-				page.show();
-				pages.insert(pref.id, page);
+	public void populate()
+	{
+		var engine = PluginsEngine.get_default();
+		var ext = new Peas.ExtensionSet(engine, typeof(GitgExt.Preferences));
 
-				var lbl = new Gtk.Label(pref.display_name);
-				lbl.show();
+		var pages = new HashTable<string, Gtk.Box>(str_hash, str_equal);
 
-				d_notebook.append_page(page, lbl);
-			}
+		add_page(new PreferencesInterface(), pages);
 
-			page.add(pref.widget);
+		ext.foreach((s, info, e) => {
+			add_page(e as GitgExt.Preferences, pages);
 		});
 	}
 }
diff --git a/gitg/gitg-preferences-interface.vala b/gitg/gitg-preferences-interface.vala
new file mode 100644
index 0000000..ebb97d9
--- /dev/null
+++ b/gitg/gitg-preferences-interface.vala
@@ -0,0 +1,98 @@
+/*
+ * This file is part of gitg
+ *
+ * Copyright (C) 2012 - Jesse van den Kieboom
+ *
+ * gitg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * gitg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with gitg. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace Gitg
+{
+
+class PreferencesInterface : Object, 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;
+
+	private Gtk.Widget build_ui()
+	{
+		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;
+
+		check.active = settings.get_enum("orientation") == 0;
+
+		check.notify["active"].connect((obj, spec)=> {
+			if (d_block)
+			{
+				return;
+			}
+
+			d_block = true;
+
+			if (!settings.set_enum("orientation", check.active ? 1 : 0))
+			{
+				check.active = settings.get_enum("orientation") == 0;
+			}
+
+			d_block = false;
+		});
+
+		settings.changed["orientation"].connect((s, k) => {
+			if (d_block)
+			{
+				return;
+			}
+
+			d_block = true;
+			check.active = settings.get_enum("orientation") == 0;
+			d_block = false;
+		});
+
+		return d_widget;
+	}
+
+	public Gtk.Widget widget
+	{
+		owned get { return build_ui(); }
+	}
+
+	public string id
+	{
+		owned get { return "/org/gnome/gitg/Preferences/Interface"; }
+	}
+
+	public string display_name
+	{
+		owned get { return _("Interface"); }
+	}
+}
+
+}
+
+// vi:ts=4
diff --git a/gitg/resources/gitg-resources.xml b/gitg/resources/gitg-resources.xml
index 168e75d..d565f8a 100644
--- a/gitg/resources/gitg-resources.xml
+++ b/gitg/resources/gitg-resources.xml
@@ -3,8 +3,9 @@
   <gresource prefix="/org/gnome/gitg">
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-window.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-menus.ui</file>
-    <file compressed="true">ui/style.css</file>
+    <file compressed="true" preprocess="xml-stripblanks">ui/gitg-preferences-interface.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-preferences.ui</file>
+    <file compressed="true">ui/style.css</file>
     <file alias="icons/gitg.svg" compressed="true" preprocess="xml-stripblanks">../../data/icons/gitg.svg</file>
     <file alias="icons/gitg128x128.png">../../data/icons/gitg128x128.png</file>
   </gresource>
diff --git a/gitg/resources/ui/gitg-preferences-interface.ui b/gitg/resources/ui/gitg-preferences-interface.ui
new file mode 100644
index 0000000..36a41d3
--- /dev/null
+++ b/gitg/resources/ui/gitg-preferences-interface.ui
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkGrid" id="main">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="hexpand">True</property>
+    <property name="vexpand">True</property>
+    <property name="border_width">12</property>
+    <property name="row_spacing">18</property>
+    <property name="column_spacing">18</property>
+    <child>
+      <object class="GtkGrid" id="grid2">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="hexpand">True</property>
+        <property name="row_spacing">6</property>
+        <child>
+          <object class="GtkLabel" id="label1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="xalign">0</property>
+            <property name="label" translatable="yes">&lt;b&gt;Layout&lt;/b&gt;</property>
+            <property name="use_markup">True</property>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">0</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid" id="grid3">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="hexpand">True</property>
+            <child>
+              <object class="GtkLabel" id="label2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">    </property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkGrid" id="grid4">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="hexpand">True</property>
+                <property name="vexpand">True</property>
+                <property name="row_spacing">6</property>
+                <child>
+                  <object class="GtkCheckButton" id="horizontal_layout_enabled">
+                    <property name="label" translatable="yes">Use horizontal layout</property>
+                    <property name="use_action_appearance">False</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="use_action_appearance">False</property>
+                    <property name="xalign">0</property>
+                    <property name="draw_indicator">True</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">0</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">1</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">0</property>
+        <property name="width">1</property>
+        <property name="height">1</property>
+      </packing>
+    </child>
+  </object>
+</interface>



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