Merge branch 'wip/sadiq/buildable-2080' into 'master'

builderparser: Allow bind-source without bind-property

Closes #2080

See merge request GNOME/gtk!1047
This commit is contained in:
Timm Bäder 2019-08-10 13:39:47 +00:00
commit 0544633755
4 changed files with 27 additions and 15 deletions

View File

@ -131,9 +131,9 @@
* *
* It is also possible to bind a property value to another object's * It is also possible to bind a property value to another object's
* property value using the attributes * property value using the attributes
* "bind-source" to specify the source object of the binding, * "bind-source" to specify the source object of the binding, and
* "bind-property" to specify the source property and optionally * optionally, "bind-property" and "bind-flags" to specify the
* "bind-flags" to specify the binding flags * source property and source binding flags respectively.
* Internally builder implement this using GBinding objects. * Internally builder implement this using GBinding objects.
* For more information see g_object_bind_property() * For more information see g_object_bind_property()
* *

View File

@ -598,7 +598,7 @@ parse_property (ParserData *data,
g_markup_parse_context_get_position (data->ctx, &line, &col); g_markup_parse_context_get_position (data->ctx, &line, &col);
if (bind_source && bind_property) if (bind_source)
{ {
BindingInfo *binfo; BindingInfo *binfo;
@ -606,17 +606,17 @@ parse_property (ParserData *data,
binfo->target = NULL; binfo->target = NULL;
binfo->target_pspec = pspec; binfo->target_pspec = pspec;
binfo->source = g_strdup (bind_source); binfo->source = g_strdup (bind_source);
binfo->source_property = g_strdup (bind_property); binfo->source_property = bind_property ? g_strdup (bind_property) : g_strdup (name);
binfo->flags = bind_flags; binfo->flags = bind_flags;
binfo->line = line; binfo->line = line;
binfo->col = col; binfo->col = col;
object_info->bindings = g_slist_prepend (object_info->bindings, binfo); object_info->bindings = g_slist_prepend (object_info->bindings, binfo);
} }
else if (bind_source || bind_property) else if (bind_property)
{ {
error_missing_attribute (data, element_name, error_missing_attribute (data, element_name,
(bind_source) ? "bind-property" : "bind-source", "bind-source",
error); error);
return; return;
} }
@ -626,7 +626,7 @@ parse_property (ParserData *data,
info->pspec = pspec; info->pspec = pspec;
info->text = g_string_new (""); info->text = g_string_new ("");
info->translatable = translatable; info->translatable = translatable;
info->bound = (bind_source && bind_property); info->bound = bind_source != NULL;
info->context = g_strdup (context); info->context = g_strdup (context);
info->line = line; info->line = line;
info->col = col; info->col = col;

View File

@ -103,9 +103,11 @@
<attribute name="bind-source"> <attribute name="bind-source">
<text/> <text/>
</attribute> </attribute>
<attribute name="bind-property"> <optional>
<text/> <attribute name="bind-property">
</attribute> <text/>
</attribute>
</optional>
<optional> <optional>
<attribute name="bind-flags"> <attribute name="bind-flags">
<text/> <text/>

View File

@ -2450,14 +2450,19 @@ test_property_bindings (void)
" <property name=\"sensitive\" bind-source=\"checkbutton\" bind-property=\"active\" />" " <property name=\"sensitive\" bind-source=\"checkbutton\" bind-property=\"active\" />"
" </object>" " </object>"
" </child>" " </child>"
" <child>"
" <object class=\"GtkButton\" id=\"button3\">"
" <property name=\"sensitive\" bind-source=\"button\" bind-flags=\"sync-create\" />"
" </object>"
" </child>"
" </object>" " </object>"
" </child>" " </child>"
" </object>" " </object>"
"</interface>"; "</interface>";
GtkBuilder *builder; GtkBuilder *builder;
GObject *checkbutton, *button, *button2, *window; GObject *checkbutton, *button, *button2, *button3, *window;
builder = builder_new_from_string (buffer, -1, NULL); builder = builder_new_from_string (buffer, -1, NULL);
checkbutton = gtk_builder_get_object (builder, "checkbutton"); checkbutton = gtk_builder_get_object (builder, "checkbutton");
@ -2471,11 +2476,16 @@ test_property_bindings (void)
button2 = gtk_builder_get_object (builder, "button2"); button2 = gtk_builder_get_object (builder, "button2");
g_assert (GTK_IS_BUTTON (button2)); g_assert (GTK_IS_BUTTON (button2));
g_assert (gtk_widget_get_sensitive (GTK_WIDGET (button2))); g_assert (gtk_widget_get_sensitive (GTK_WIDGET (button2)));
button3 = gtk_builder_get_object (builder, "button3");
g_assert (GTK_IS_BUTTON (button3));
g_assert (!gtk_widget_get_sensitive (GTK_WIDGET (button3)));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbutton), TRUE); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbutton), TRUE);
g_assert (gtk_widget_get_sensitive (GTK_WIDGET (button))); g_assert (gtk_widget_get_sensitive (GTK_WIDGET (button)));
g_assert (gtk_widget_get_sensitive (GTK_WIDGET (button2))); g_assert (gtk_widget_get_sensitive (GTK_WIDGET (button2)));
g_assert (gtk_widget_get_sensitive (GTK_WIDGET (button3)));
window = gtk_builder_get_object (builder, "window"); window = gtk_builder_get_object (builder, "window");
gtk_widget_destroy (GTK_WIDGET (window)); gtk_widget_destroy (GTK_WIDGET (window));
g_object_unref (builder); g_object_unref (builder);