From ec624029089d0e9ffc4d1b759b15e0983fb87f1d Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 24 Sep 2021 16:34:48 -0400 Subject: [PATCH] builder: Fix parsing of mixed declarations The GtkBuilder parser constructs the object e.g. when handling a element. There may be more elements after it, which we were just not applying. Fix that by always applying property when we see . To do that, we need to track the applied status per property. Test included. Fixes: #4208 --- gtk/gtkbuilder.c | 16 ++++++++++++++-- gtk/gtkbuilderparser.c | 5 ----- gtk/gtkbuilderprivate.h | 6 +++--- testsuite/reftests/late-property.ref.ui | 18 ++++++++++++++++++ testsuite/reftests/late-property.ui | 18 ++++++++++++++++++ testsuite/reftests/meson.build | 2 ++ 6 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 testsuite/reftests/late-property.ref.ui create mode 100644 testsuite/reftests/late-property.ui diff --git a/gtk/gtkbuilder.c b/gtk/gtkbuilder.c index a151ec78cf..47af4df1fe 100644 --- a/gtk/gtkbuilder.c +++ b/gtk/gtkbuilder.c @@ -540,6 +540,9 @@ gtk_builder_get_parameters (GtkBuilder *builder, const char *property_name = prop->pspec->name; GValue property_value = G_VALUE_INIT; + if (prop->applied) + continue; + if (prop->value) { g_value_init (&property_value, G_PARAM_SPEC_VALUE_TYPE (prop->pspec)); @@ -582,6 +585,9 @@ gtk_builder_get_parameters (GtkBuilder *builder, continue; } /* Delay setting property */ + + prop->applied = TRUE; + property = g_slice_new (DelayedProperty); property->pspec = prop->pspec; property->object = g_strdup (object_name); @@ -612,9 +618,15 @@ gtk_builder_get_parameters (GtkBuilder *builder, g_assert (G_IS_VALUE (&property_value)); if ((prop->pspec->flags & filter_flags) != 0 && filtered_parameters) - object_properties_add (filtered_parameters, property_name, &property_value); + { + object_properties_add (filtered_parameters, property_name, &property_value); + prop->applied = TRUE; + } else if ((prop->pspec->flags & filter_flags) == 0 && parameters) - object_properties_add (parameters, property_name, &property_value); + { + object_properties_add (parameters, property_name, &property_value); + prop->applied = TRUE; + } else g_value_unset (&property_value); } diff --git a/gtk/gtkbuilderparser.c b/gtk/gtkbuilderparser.c index c5b4039781..f91523d598 100644 --- a/gtk/gtkbuilderparser.c +++ b/gtk/gtkbuilderparser.c @@ -470,9 +470,6 @@ builder_construct (ParserData *data, g_assert (object_info != NULL); - if (object_info->object && object_info->applied_properties) - return object_info->object; - if (object_info->object == NULL) { object = _gtk_builder_construct (data->builder, object_info, error); @@ -488,8 +485,6 @@ builder_construct (ParserData *data, _gtk_builder_apply_properties (data->builder, object_info, error); } - object_info->applied_properties = TRUE; - g_assert (G_IS_OBJECT (object)); object_info->object = object; diff --git a/gtk/gtkbuilderprivate.h b/gtk/gtkbuilderprivate.h index 913fa263a9..32cb470f4b 100644 --- a/gtk/gtkbuilderprivate.h +++ b/gtk/gtkbuilderprivate.h @@ -53,7 +53,6 @@ typedef struct { GObject *object; CommonInfo *parent; - gboolean applied_properties; } ObjectInfo; typedef struct { @@ -71,8 +70,9 @@ typedef struct { GParamSpec *pspec; gpointer value; GString *text; - gboolean translatable:1; - gboolean bound:1; + gboolean translatable : 1; + gboolean bound : 1; + gboolean applied : 1; char *context; int line; int col; diff --git a/testsuite/reftests/late-property.ref.ui b/testsuite/reftests/late-property.ref.ui new file mode 100644 index 0000000000..f079ea78a5 --- /dev/null +++ b/testsuite/reftests/late-property.ref.ui @@ -0,0 +1,18 @@ + + + + + + + Title widget + + + + + Button + + + + + + diff --git a/testsuite/reftests/late-property.ui b/testsuite/reftests/late-property.ui new file mode 100644 index 0000000000..5283860044 --- /dev/null +++ b/testsuite/reftests/late-property.ui @@ -0,0 +1,18 @@ + + + + + + + Button + + + + + Title widget + + + + + + diff --git a/testsuite/reftests/meson.build b/testsuite/reftests/meson.build index ea967f2d0c..e4e860fc9f 100644 --- a/testsuite/reftests/meson.build +++ b/testsuite/reftests/meson.build @@ -331,6 +331,8 @@ testdata = [ # that are not valid with subpixel positioning #'label-wrap-justify.ref.ui', #'label-wrap-justify.ui', + 'late-property.ui', + 'late-property.ref.ui', 'letter-spacing.css', 'letter-spacing.ui', 'letter-spacing.ref.ui',