From 7354780e04fb10606e53557053a5face827485e1 Mon Sep 17 00:00:00 2001 From: Jesse van den Kieboom Date: Wed, 18 Jul 2012 17:35:09 +0200 Subject: [PATCH] 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 deletion(-) create mode 100644 libgitg-ext/gitg-ext-ui.vala diff --git a/libgitg-ext/Makefile.am b/libgitg-ext/Makefile.am index b9d7d59a..83981052 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 00000000..ab3e6b7d --- /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 . + */ + +namespace GitgExt +{ + public class UI + { + public static Gee.HashMap? 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 ret = new Gee.HashMap(); + + 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