From ea0290c50eec6c95a4badd6914d8c55a67ea5800 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Thu, 22 Mar 2018 22:03:47 +0100 Subject: [PATCH] builder: Allow named objects to be used in paintable/pixbuf properties Instead of erroring if an object by a name already exists, use that object. --- gtk/gtkbuilder.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/gtk/gtkbuilder.c b/gtk/gtkbuilder.c index 98bde12161..dc18c1faa2 100644 --- a/gtk/gtkbuilder.c +++ b/gtk/gtkbuilder.c @@ -2057,16 +2057,27 @@ gtk_builder_value_from_string_type (GtkBuilder *builder, gchar *filename; GError *tmp_error = NULL; GdkPixbuf *pixbuf = NULL; + GObject *object; - if (g_hash_table_contains (builder->priv->objects, string)) + object = g_hash_table_lookup (builder->priv->objects, string); + + if (object) { - g_set_error (error, - GTK_BUILDER_ERROR, - GTK_BUILDER_ERROR_INVALID_VALUE, - "Could not load image '%s': " - " '%s' is already used as object id", - string, string); - return FALSE; + if (g_type_is_a (G_OBJECT_TYPE (object), G_VALUE_TYPE (value))) + { + g_value_set_object (value, object); + return TRUE; + } + else + { + g_set_error (error, + GTK_BUILDER_ERROR, + GTK_BUILDER_ERROR_INVALID_VALUE, + "Could not load image '%s': " + " '%s' is already used as object id for a %s", + string, string, G_OBJECT_TYPE_NAME (object)); + return FALSE; + } } filename = _gtk_builder_get_resource_path (builder, string);