[gitg/vala] Added convenience function for building ui from resource



commit 7354780e04fb10606e53557053a5face827485e1
Author: Jesse van den Kieboom <jesse vandenkieboom epfl ch>
Date:   Wed Jul 18 17:35:09 2012 +0200

    Added convenience function for building ui from resource

 libgitg-ext/Makefile.am      |    4 ++-
 libgitg-ext/gitg-ext-ui.vala |   59 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 1 deletions(-)
---
diff --git a/libgitg-ext/Makefile.am b/libgitg-ext/Makefile.am
index b9d7d59..8398105 100644
--- a/libgitg-ext/Makefile.am
+++ b/libgitg-ext/Makefile.am
@@ -13,6 +13,7 @@ COMMON_VALA_FLAGS =				\
 	--pkg libgitg-1.0			\
 	--pkg gio-2.0				\
 	--pkg gtk+-3.0				\
+	--pkg gee-1.0				\
 	--basedir $(top_srcdir)			\
 	--gir GitgExt-1.0.gir			\
 	--girdir $(top_builddir)/libgitg	\
@@ -46,7 +47,8 @@ VALA_FILES =					\
 	gitg-ext-message-bus.vala		\
 	gitg-ext-object-selection.vala		\
 	gitg-ext-command-line.vala		\
-	gitg-ext-preferences.vala
+	gitg-ext-preferences.vala		\
+	gitg-ext-ui.vala
 
 libgitg_ext_1_0_la_SOURCES =		\
 	$(VALA_FILES)			\
diff --git a/libgitg-ext/gitg-ext-ui.vala b/libgitg-ext/gitg-ext-ui.vala
new file mode 100644
index 0000000..ab3e6b7
--- /dev/null
+++ b/libgitg-ext/gitg-ext-ui.vala
@@ -0,0 +1,59 @@
+/*
+ * 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 GitgExt
+{
+	public class UI
+	{
+		public static Gee.HashMap<string, Object>? from_builder(string path, ...)
+		{
+			var builder = new Gtk.Builder();
+
+			try
+			{
+				builder.add_from_resource("/org/gnome/gitg/" + path);
+			}
+			catch (Error e)
+			{
+				warning("Failed to load ui: %s", e.message);
+				return null;
+			}
+
+			Gee.HashMap<string, Object> ret = new Gee.HashMap<string, Object>();
+
+			var l = va_list();
+
+			while (true)
+			{
+				string? id = l.arg();
+
+				if (id == null)
+				{
+					break;
+				}
+
+				ret[id] = builder.get_object(id);
+			}
+
+			return ret;
+		}
+	}
+}
+
+// vi:ts=4



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