Commit a827e922 authored by Debarshi Ray's avatar Debarshi Ray

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

https://bugzilla.gnome.org/show_bug.cgi?id=786932
parent bbb23346
......@@ -268,34 +268,34 @@ parse_object (GMarkupParseContext *context,
return;
}
if (object_class)
if (type_func)
{
object_type = gtk_builder_get_type_from_name (data->builder, object_class);
/* Call the GType function, and return the GType, it's guaranteed afterwards
* that g_type_from_name on the name will return our GType
*/
object_type = _get_type_by_symbol (type_func);
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_ERROR_INVALID_TYPE_FUNCTION,
"Invalid type function '%s'", type_func);
_gtk_builder_prefix_error (data->builder, context, error);
return;
}
}
}
else if (type_func)
else if (object_class)
{
/* Call the GType function, and return the GType, it's guaranteed afterwards
* that g_type_from_name on the name will return our GType
*/
object_type = _get_type_by_symbol (type_func);
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_TYPE_FUNCTION,
"Invalid type function '%s'", type_func);
GTK_BUILDER_ERROR_INVALID_VALUE,
"Invalid object type '%s'", object_class);
_gtk_builder_prefix_error (data->builder, context, error);
return;
}
}
}
else
{
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment