[gitg/vala] Implemented basic preferences dialog
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg/vala] Implemented basic preferences dialog
- Date: Wed, 18 Jul 2012 15:39:34 +0000 (UTC)
commit e259480b9dc93d9e87533114757229f830958e54
Author: Jesse van den Kieboom <jesse vandenkieboom epfl ch>
Date: Wed Jul 18 17:37:52 2012 +0200
Implemented basic preferences dialog
gitg/Makefile.am | 4 +-
gitg/gitg-application.vala | 30 ++++++++++++++-
gitg/gitg-preferences-dialog.vala | 69 +++++++++++++++++++++++++++++++++
gitg/resources/gitg-resources.xml | 1 +
gitg/resources/ui/gitg-preferences.ui | 66 +++++++++++++++++++++++++++++++
5 files changed, 168 insertions(+), 2 deletions(-)
---
diff --git a/gitg/Makefile.am b/gitg/Makefile.am
index c06f940..76e0c18 100644
--- a/gitg/Makefile.am
+++ b/gitg/Makefile.am
@@ -20,6 +20,7 @@ VALAFLAGS = \
--pkg gio-2.0 \
--pkg libpeas-1.0 \
--pkg gobject-introspection-1.0 \
+ --pkg gee-1.0 \
--girdir "$(top_builddir)/libgitg" \
--girdir "$(top_builddir)/libgitg-ext" \
--vapidir "$(top_builddir)/libgitg" \
@@ -33,7 +34,8 @@ VALASOURCES = \
gitg-application.vala \
gitg-plugins-engine.vala \
gitg-ui-elements.vala \
- gitg-autohide-frame.vala
+ gitg-autohide-frame.vala \
+ gitg-preferences-dialog.vala
BUILT_SOURCES = \
gitg-resources.c \
diff --git a/gitg/gitg-application.vala b/gitg/gitg-application.vala
index af998aa..8bdd0d0 100644
--- a/gitg/gitg-application.vala
+++ b/gitg/gitg-application.vala
@@ -50,6 +50,7 @@ public class Application : Gtk.Application
}
private static Options options;
+ private PreferencesDialog d_preferences;
static construct
{
@@ -220,11 +221,38 @@ public class Application : Gtk.Application
}
}
+ private void on_preferences_activated()
+ {
+ unowned List<Gtk.Window> wnds = get_windows();
+
+ // Create preferences dialog if needed
+ if (d_preferences == null)
+ {
+ d_preferences = Resource.load_object<PreferencesDialog>("ui/gitg-preferences.ui", "preferences");
+
+ d_preferences.destroy.connect((w) => {
+ d_preferences = null;
+ });
+
+ d_preferences.response.connect((w, r) => {
+ d_preferences.destroy();
+ });
+ }
+
+ if (wnds != null)
+ {
+ d_preferences.set_transient_for(wnds.data);
+ }
+
+ d_preferences.present();
+ }
+
private static const ActionEntry[] app_entries = {
{"new", on_app_new_window_activated},
{"help", on_app_help_activated},
{"about", on_app_about_activated},
- {"quit", on_app_quit_activated}
+ {"quit", on_app_quit_activated},
+ {"preferences", on_preferences_activated}
};
private void setup_menus()
diff --git a/gitg/gitg-preferences-dialog.vala b/gitg/gitg-preferences-dialog.vala
new file mode 100644
index 0000000..99b4416
--- /dev/null
+++ b/gitg/gitg-preferences-dialog.vala
@@ -0,0 +1,69 @@
+/*
+ * 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 PreferencesDialog : Gtk.Dialog, Gtk.Buildable
+{
+ private Gtk.Notebook d_notebook;
+
+ private void parser_finished(Gtk.Builder builder)
+ {
+ // Extract widgets from the builder
+ d_notebook = builder.get_object("notebook_elements") as Gtk.Notebook;
+
+ // Populate tabs from plugins
+ populate();
+
+ base.parser_finished(builder);
+ }
+
+ public void populate()
+ {
+ var engine = PluginsEngine.get_default();
+ var ext = new Peas.ExtensionSet(engine, typeof(GitgExt.Preferences));
+
+ var pages = new HashTable<string, Gtk.Box>(str_hash, str_equal);
+
+ ext.foreach((s, info, e) => {
+ var pref = e as GitgExt.Preferences;
+ Gtk.Box page;
+
+ if (!pages.lookup_extended(pref.id, null, out page))
+ {
+ page = new Gtk.Box(Gtk.Orientation.VERTICAL, 6);
+
+ page.show();
+ pages.insert(pref.id, page);
+
+ var lbl = new Gtk.Label(pref.display_name);
+ lbl.show();
+
+ d_notebook.append_page(page, lbl);
+ }
+
+ page.add(pref.widget);
+ });
+ }
+}
+
+}
+
+// vi:ts=4
diff --git a/gitg/resources/gitg-resources.xml b/gitg/resources/gitg-resources.xml
index 4700c6b..54887b4 100644
--- a/gitg/resources/gitg-resources.xml
+++ b/gitg/resources/gitg-resources.xml
@@ -4,6 +4,7 @@
<file>ui/gitg-window.ui</file>
<file>ui/gitg-menus.ui</file>
<file>ui/style.css</file>
+ <file>ui/gitg-preferences.ui</file>
</gresource>
</gresources>
diff --git a/gitg/resources/ui/gitg-preferences.ui b/gitg/resources/ui/gitg-preferences.ui
new file mode 100644
index 0000000..60a7e2c
--- /dev/null
+++ b/gitg/resources/ui/gitg-preferences.ui
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.0 -->
+ <object class="GitgPreferencesDialog" id="preferences">
+ <property name="can_focus">False</property>
+ <property name="border_width">5</property>
+ <property name="default_width">400</property>
+ <property name="default_height">500</property>
+ <property name="type_hint">dialog</property>
+ <property name="title" translatable="yes">gitg Preferences</property>
+ <child internal-child="vbox">
+ <object class="GtkBox" id="dialog-vbox1">
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox" id="dialog-action_area1">
+ <property name="can_focus">False</property>
+ <property name="layout_style">end</property>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <object class="GtkButton" id="button1">
+ <property name="label">gtk-close</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkNotebook" id="notebook_elements">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="-7">button1</action-widget>
+ </action-widgets>
+ </object>
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]