[gtk+/wip/resources: 2/3] Add gtk_ui_manager_add_ui_from_resource



commit 081b258a795a44523aabc3afab5993c11d16aa06
Author: Alexander Larsson <alexl redhat com>
Date:   Thu Jan 12 19:00:39 2012 +0100

    Add gtk_ui_manager_add_ui_from_resource
    
    This is a helper function to easily add ui from resource files.

 gtk/gtkuimanager.c |   35 +++++++++++++++++++++++++++++++++++
 gtk/gtkuimanager.h |    3 +++
 2 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkuimanager.c b/gtk/gtkuimanager.c
index 82c638c..1e644d2 100644
--- a/gtk/gtkuimanager.c
+++ b/gtk/gtkuimanager.c
@@ -2002,6 +2002,41 @@ gtk_ui_manager_add_ui_from_file (GtkUIManager *manager,
 }
 
 /**
+ * gtk_ui_manager_add_ui_from_resource:
+ * @manager: a #GtkUIManager object
+ * @resource_path: the resource path of the file to parse
+ * @error: return location for an error
+ *
+ * Parses a resource file containing a <link linkend="XML-UI">UI definition</link> and
+ * merges it with the current contents of @manager.
+ *
+ * Return value: The merge id for the merged UI. The merge id can be used
+ *   to unmerge the UI with gtk_ui_manager_remove_ui(). If an error occurred,
+ *   the return value is 0.
+ *
+ * Since: 3.4
+ **/
+guint
+gtk_ui_manager_add_ui_from_resource (GtkUIManager *manager,
+				     const gchar  *resource_path,
+				     GError      **error)
+{
+  GBytes *data;
+  guint res;
+
+  g_return_val_if_fail (GTK_IS_UI_MANAGER (manager), 0);
+
+  data = g_resources_lookup_data (resource_path, 0, error);
+  if (data == NULL)
+    return 0;
+
+  res = add_ui_from_string (manager, g_bytes_get_data (data, NULL), g_bytes_get_size (data), FALSE, error);
+  g_bytes_unref (data);
+
+  return res;
+}
+
+/**
  * gtk_ui_manager_add_ui:
  * @manager: a #GtkUIManager
  * @merge_id: the merge id for the merged UI, see gtk_ui_manager_new_merge_id()
diff --git a/gtk/gtkuimanager.h b/gtk/gtkuimanager.h
index d07cccc..8573f2a 100644
--- a/gtk/gtkuimanager.h
+++ b/gtk/gtkuimanager.h
@@ -152,6 +152,9 @@ guint          gtk_ui_manager_add_ui_from_string  (GtkUIManager          *manage
 guint          gtk_ui_manager_add_ui_from_file    (GtkUIManager          *manager,
 						   const gchar           *filename,
 						   GError               **error);
+guint          gtk_ui_manager_add_ui_from_resource(GtkUIManager          *manager,
+						   const gchar           *resource_path,
+						   GError               **error);
 void           gtk_ui_manager_add_ui              (GtkUIManager          *manager,
 						   guint                  merge_id,
 						   const gchar           *path,



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