[gtk/stackpage] builder: Allow specifying objects inline



commit 22c73b84548fe885cf35c37ff56031b3717918e7
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Feb 6 18:53:06 2019 -0500

    builder: Allow specifying objects inline
    
    In addition to <property name="foo">bar</property> referring
    to an object with ID bar, we now also parse
    <property name="foo"><object>...
    to specify a property 'inline'.

 gtk/gtkbuilder.c        | 10 +++++++---
 gtk/gtkbuilderparser.c  | 18 ++++++++----------
 gtk/gtkbuilderprivate.h | 11 +++++++++++
 3 files changed, 26 insertions(+), 13 deletions(-)
---
diff --git a/gtk/gtkbuilder.c b/gtk/gtkbuilder.c
index 52244862ac..cbbed790b9 100644
--- a/gtk/gtkbuilder.c
+++ b/gtk/gtkbuilder.c
@@ -536,7 +536,7 @@ gtk_builder_get_parameters (GtkBuilder         *builder,
           (G_PARAM_SPEC_VALUE_TYPE (prop->pspec) != G_TYPE_FILE))
         {
           GObject *object = g_hash_table_lookup (priv->objects,
-                                                 prop->text->str);
+                                                 g_strstrip (prop->text->str));
 
           if (object)
             {
@@ -722,7 +722,9 @@ _gtk_builder_construct (GtkBuilder  *builder,
    * be set once.
    */
   if (info->constructor ||
-      (info->parent && ((ChildInfo*)info->parent)->internal_child != NULL))
+      (info->parent &&
+       info->parent->tag_type == TAG_CHILD &&
+       ((ChildInfo*)info->parent)->internal_child != NULL))
     param_filter_flags = G_PARAM_CONSTRUCT_ONLY;
   else
     param_filter_flags = G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY;
@@ -758,7 +760,9 @@ _gtk_builder_construct (GtkBuilder  *builder,
       if (construct_parameters->len)
         g_warning ("Can't pass in construct-only parameters to %s", info->id);
     }
-  else if (info->parent && ((ChildInfo*)info->parent)->internal_child != NULL)
+  else if (info->parent &&
+           info->parent->tag_type == TAG_CHILD &&
+           ((ChildInfo*)info->parent)->internal_child != NULL)
     {
       gchar *childname = ((ChildInfo*)info->parent)->internal_child;
       obj = gtk_builder_get_internal_child (builder, info, childname, error);
diff --git a/gtk/gtkbuilderparser.c b/gtk/gtkbuilderparser.c
index 94c5b8b6c1..2c08df0f02 100644
--- a/gtk/gtkbuilderparser.c
+++ b/gtk/gtkbuilderparser.c
@@ -34,16 +34,6 @@
 static void free_property_info (PropertyInfo *info);
 static void free_object_info (ObjectInfo *info);
 
-enum {
-  TAG_PROPERTY,
-  TAG_MENU,
-  TAG_REQUIRES,
-  TAG_OBJECT,
-  TAG_CHILD,
-  TAG_SIGNAL,
-  TAG_INTERFACE,
-  TAG_TEMPLATE,
-};
 
 static inline void
 state_push (ParserData *data, gpointer info)
@@ -1066,6 +1056,12 @@ end_element (GMarkupParseContext  *context,
     {
       ObjectInfo *object_info = state_pop_info (data, ObjectInfo);
       ChildInfo* child_info = state_peek_info (data, ChildInfo);
+      PropertyInfo* prop_info = state_peek_info (data, PropertyInfo);
+
+      if (child_info && child_info->tag_type != TAG_CHILD)
+        child_info = NULL;
+      if (prop_info && prop_info->tag_type != TAG_PROPERTY)
+        prop_info = NULL;
 
       if (data->requested_objects && data->inside_requested_object &&
           (data->cur_object_level == data->requested_object_level))
@@ -1089,6 +1085,8 @@ end_element (GMarkupParseContext  *context,
         }
       if (child_info)
         child_info->object = object_info->object;
+      if (prop_info)
+        g_string_assign (prop_info->text, object_info->id);
 
       if (GTK_IS_BUILDABLE (object_info->object) &&
           GTK_BUILDABLE_GET_IFACE (object_info->object)->parser_finished)
diff --git a/gtk/gtkbuilderprivate.h b/gtk/gtkbuilderprivate.h
index 22577df32d..5b71bdf76d 100644
--- a/gtk/gtkbuilderprivate.h
+++ b/gtk/gtkbuilderprivate.h
@@ -21,6 +21,17 @@
 
 #include "gtkbuilder.h"
 
+enum {
+  TAG_PROPERTY,
+  TAG_MENU,
+  TAG_REQUIRES,
+  TAG_OBJECT,
+  TAG_CHILD,
+  TAG_SIGNAL,
+  TAG_INTERFACE,
+  TAG_TEMPLATE,
+};
+
 typedef struct {
   guint tag_type;
 } CommonInfo;


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