[gtk] builder: Allow objects in gtk_builder_value_from_string_type()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk] builder: Allow objects in gtk_builder_value_from_string_type()
- Date: Tue, 3 Dec 2019 17:33:01 +0000 (UTC)
commit bfe42558072acff476e1ace0cfe7b277070bfee7
Author: Benjamin Otte <otte redhat com>
Date: Mon Nov 25 06:06:31 2019 +0100
builder: Allow objects in gtk_builder_value_from_string_type()
Instead of throwing an error, lookup objects with
gtk_builder_get_object().
gtk/gtkbuilder.c | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkbuilder.c b/gtk/gtkbuilder.c
index 1b39f30d09..8f6935c696 100644
--- a/gtk/gtkbuilder.c
+++ b/gtk/gtkbuilder.c
@@ -2167,7 +2167,31 @@ gtk_builder_value_from_string_type (GtkBuilder *builder,
ret = TRUE;
}
else
- ret = FALSE;
+ {
+ GObject *object = g_hash_table_lookup (priv->objects, string);
+
+ if (object && g_value_type_compatible (G_OBJECT_TYPE (object), type))
+ {
+ g_value_set_object (value, object);
+ }
+ else if (object)
+ {
+ g_set_error (error,
+ GTK_BUILDER_ERROR,
+ GTK_BUILDER_ERROR_INVALID_VALUE,
+ "Object named \"%s\" is of type \"%s\" which is not compatible with expected type
\%s\"",
+ string, G_OBJECT_TYPE_NAME (object), g_type_name (type));
+ ret = FALSE;
+ }
+ else
+ {
+ g_set_error (error,
+ GTK_BUILDER_ERROR,
+ GTK_BUILDER_ERROR_INVALID_VALUE,
+ "No object named \"%s\"", string);
+ ret = FALSE;
+ }
+ }
break;
case G_TYPE_POINTER:
if (G_VALUE_HOLDS (value, G_TYPE_GTYPE))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]