[gtk+/composite-templates] Added gtk_builder_add_to_parent_from_resource() Used gtk_builder_add_to_parent_from_* as gtk_builder



commit d73a688523607f8b48f8e2169395e21f51a45bf9
Author: Juan Pablo Ugarte <juanpablougarte gmail com>
Date:   Mon Jun 25 22:08:30 2012 -0300

    Added gtk_builder_add_to_parent_from_resource()
    Used gtk_builder_add_to_parent_from_* as gtk_builder_add_from_* implementation.

 gtk/gtkbuilder.c |   92 +++++++++++++++++++-----------------------------------
 gtk/gtkbuilder.h |    4 ++
 2 files changed, 36 insertions(+), 60 deletions(-)
---
diff --git a/gtk/gtkbuilder.c b/gtk/gtkbuilder.c
index f5c0a9d..002fd59 100644
--- a/gtk/gtkbuilder.c
+++ b/gtk/gtkbuilder.c
@@ -902,41 +902,7 @@ gtk_builder_add_from_file (GtkBuilder   *builder,
                            const gchar  *filename,
                            GError      **error)
 {
-  gchar *buffer;
-  gsize length;
-  GError *tmp_error;
-
-  g_return_val_if_fail (GTK_IS_BUILDER (builder), 0);
-  g_return_val_if_fail (filename != NULL, 0);
-  g_return_val_if_fail (error == NULL || *error == NULL, 0);
-
-  tmp_error = NULL;
-
-  if (!g_file_get_contents (filename, &buffer, &length, &tmp_error))
-    {
-      g_propagate_error (error, tmp_error);
-      return 0;
-    }
-  
-  g_free (builder->priv->filename);
-  g_free (builder->priv->resource_prefix);
-  builder->priv->filename = g_strdup (filename);
-  builder->priv->resource_prefix = NULL;
-
-  _gtk_builder_parser_parse_buffer (builder, NULL, filename,
-                                    buffer, length,
-                                    NULL,
-                                    &tmp_error);
-
-  g_free (buffer);
-
-  if (tmp_error != NULL)
-    {
-      g_propagate_error (error, tmp_error);
-      return 0;
-    }
-
-  return 1;
+  return gtk_builder_add_to_parent_from_file (builder, NULL, filename, error);
 }
 
 /**
@@ -978,7 +944,9 @@ gtk_builder_add_to_parent_from_file (GtkBuilder   *builder,
     }
   
   g_free (builder->priv->filename);
+  g_free (builder->priv->resource_prefix);
   builder->priv->filename = g_strdup (filename);
+  builder->priv->resource_prefix = NULL;
 
   _gtk_builder_parser_parse_buffer (builder, parent, filename,
                                     buffer, length,
@@ -1087,6 +1055,31 @@ gtk_builder_add_from_resource (GtkBuilder   *builder,
 			       const gchar  *resource_path,
 			       GError      **error)
 {
+  return gtk_builder_add_to_parent_from_resource (builder, NULL, resource_path, error);
+}
+
+/**
+ * gtk_builder_add_to_parent_from_resource:
+ * @builder: a #GtkBuilder
+ * @parent: the parent object to be assumed in context while parsing the file
+ * @resource_path: the resource path to parse
+ * @error: (allow-none): return location for an error, or %NULL
+ *
+ * Like gtk_builder_add_from_file() except the format will expect
+ * <child> instead of <object> as its first elements and expose
+ * @parent in the build context, children defined in the UI fragment
+ * will be added to @parent.
+ * 
+ * Returns: A positive value on success, 0 if an error occurred
+ *
+ * Since: ...
+ **/
+guint
+gtk_builder_add_to_parent_from_resource (GtkBuilder   *builder,
+                                         GObject      *parent,
+                                         const gchar  *resource_path,
+                                         GError      **error)
+{
   GError *tmp_error;
   GBytes *data;
   char *filename_for_errors;
@@ -1119,7 +1112,7 @@ gtk_builder_add_from_resource (GtkBuilder   *builder,
 
   filename_for_errors = g_strconcat ("<resource>", resource_path, NULL);
 
-  _gtk_builder_parser_parse_buffer (builder, NULL, filename_for_errors,
+  _gtk_builder_parser_parse_buffer (builder, parent, filename_for_errors,
                                     g_bytes_get_data (data, NULL), g_bytes_get_size (data),
                                     NULL,
                                     &tmp_error);
@@ -1239,30 +1232,7 @@ gtk_builder_add_from_string (GtkBuilder   *builder,
                              gsize         length,
                              GError      **error)
 {
-  GError *tmp_error;
-
-  g_return_val_if_fail (GTK_IS_BUILDER (builder), 0);
-  g_return_val_if_fail (buffer != NULL, 0);
-  g_return_val_if_fail (error == NULL || *error == NULL, 0);
-
-  tmp_error = NULL;
-
-  g_free (builder->priv->filename);
-  g_free (builder->priv->resource_prefix);
-  builder->priv->filename = g_strdup (".");
-  builder->priv->resource_prefix = NULL;
-
-  _gtk_builder_parser_parse_buffer (builder, NULL, "<input>",
-                                    buffer, length,
-                                    NULL,
-                                    &tmp_error);
-  if (tmp_error != NULL)
-    {
-      g_propagate_error (error, tmp_error);
-      return 0;
-    }
-
-  return 1;
+  return gtk_builder_add_to_parent_from_string (builder, NULL, buffer, length, error);
 }
 
 
@@ -1299,7 +1269,9 @@ gtk_builder_add_to_parent_from_string (GtkBuilder   *builder,
   tmp_error = NULL;
 
   g_free (builder->priv->filename);
+  g_free (builder->priv->resource_prefix);
   builder->priv->filename = g_strdup (".");
+  builder->priv->resource_prefix = NULL;
 
   _gtk_builder_parser_parse_buffer (builder, parent, "<input>",
                                     buffer, length,
diff --git a/gtk/gtkbuilder.h b/gtk/gtkbuilder.h
index ac7fe4c..b2e8db5 100644
--- a/gtk/gtkbuilder.h
+++ b/gtk/gtkbuilder.h
@@ -146,6 +146,10 @@ guint        gtk_builder_add_to_parent_from_string (GtkBuilder   *builder,
 						    const gchar  *buffer,
 						    gsize         length,
 						    GError      **error);
+guint        gtk_builder_add_to_parent_from_resource (GtkBuilder   *builder,
+                                                      GObject      *parent,
+                                                      const gchar  *resource_path,
+                                                      GError      **error);
 GObject*     gtk_builder_get_object              (GtkBuilder    *builder,
                                                   const gchar   *name);
 GSList*      gtk_builder_get_objects             (GtkBuilder    *builder);



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