GtkBuilder: Prefer "type-func" over "class" when looking for the GType

https://bugzilla.gnome.org/show_bug.cgi?id=786932
This commit is contained in:
Debarshi Ray 2017-08-28 18:58:50 +02:00
parent bbb233464c
commit a827e92226
2 changed files with 25 additions and 15 deletions

View File

@ -268,20 +268,7 @@ parse_object (GMarkupParseContext *context,
return;
}
if (object_class)
{
object_type = gtk_builder_get_type_from_name (data->builder, object_class);
if (object_type == G_TYPE_INVALID)
{
g_set_error (error,
GTK_BUILDER_ERROR,
GTK_BUILDER_ERROR_INVALID_VALUE,
"Invalid object type '%s'", object_class);
_gtk_builder_prefix_error (data->builder, context, error);
return;
}
}
else if (type_func)
if (type_func)
{
/* Call the GType function, and return the GType, it's guaranteed afterwards
* that g_type_from_name on the name will return our GType
@ -297,6 +284,19 @@ parse_object (GMarkupParseContext *context,
return;
}
}
else if (object_class)
{
object_type = gtk_builder_get_type_from_name (data->builder, object_class);
if (object_type == G_TYPE_INVALID)
{
g_set_error (error,
GTK_BUILDER_ERROR,
GTK_BUILDER_ERROR_INVALID_VALUE,
"Invalid object type '%s'", object_class);
_gtk_builder_prefix_error (data->builder, context, error);
return;
}
}
else
{
error_missing_attribute (data, element_name, "class", error);

View File

@ -762,6 +762,10 @@ test_types (void)
" <object type-func=\"gtk_window_get_type\" id=\"window\"/>"
"</interface>";
const gchar buffer3[] =
"<interface>"
" <object class=\"XXXInvalidType\" type-func=\"gtk_window_get_type\" id=\"window\"/>"
"</interface>";
const gchar buffer4[] =
"<interface>"
" <object type-func=\"xxx_invalid_get_type_function\" id=\"window\"/>"
"</interface>";
@ -779,10 +783,16 @@ test_types (void)
g_assert (GTK_IS_WINDOW (window));
gtk_widget_destroy (GTK_WIDGET (window));
g_object_unref (builder);
builder = builder_new_from_string (buffer3, -1, NULL);
window = gtk_builder_get_object (builder, "window");
g_assert (GTK_IS_WINDOW (window));
gtk_widget_destroy (GTK_WIDGET (window));
g_object_unref (builder);
error = NULL;
builder = gtk_builder_new ();
gtk_builder_add_from_string (builder, buffer3, -1, &error);
gtk_builder_add_from_string (builder, buffer4, -1, &error);
g_assert_error (error, GTK_BUILDER_ERROR, GTK_BUILDER_ERROR_INVALID_TYPE_FUNCTION);
g_error_free (error);
g_object_unref (builder);