mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-28 22:41:43 +00:00
GtkBuilder: Enforce "class" as a mandatory attribute for <object>
https://bugzilla.gnome.org/show_bug.cgi?id=786931
This commit is contained in:
parent
d09f695172
commit
60cee7339f
@ -268,6 +268,12 @@ parse_object (GMarkupParseContext *context,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Even though 'class' is a mandatory attribute, we don't flag its
|
||||||
|
* absence here because it's supposed to throw
|
||||||
|
* GTK_BUILDER_ERROR_MISSING_ATTRIBUTE, not
|
||||||
|
* G_MARKUP_ERROR_MISSING_ATTRIBUTE. It's handled immediately
|
||||||
|
* afterwards.
|
||||||
|
*/
|
||||||
if (!g_markup_collect_attributes (element_name, names, values, error,
|
if (!g_markup_collect_attributes (element_name, names, values, error,
|
||||||
G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "class", &object_class,
|
G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "class", &object_class,
|
||||||
G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "constructor", &constructor,
|
G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "constructor", &constructor,
|
||||||
@ -279,6 +285,12 @@ parse_object (GMarkupParseContext *context,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!object_class)
|
||||||
|
{
|
||||||
|
error_missing_attribute (data, element_name, "class", error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (type_func)
|
if (type_func)
|
||||||
{
|
{
|
||||||
/* Call the GType function, and return the GType, it's guaranteed afterwards
|
/* Call the GType function, and return the GType, it's guaranteed afterwards
|
||||||
@ -295,8 +307,10 @@ parse_object (GMarkupParseContext *context,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (object_class)
|
else
|
||||||
{
|
{
|
||||||
|
g_assert_nonnull (object_class);
|
||||||
|
|
||||||
object_type = gtk_builder_get_type_from_name (data->builder, object_class);
|
object_type = gtk_builder_get_type_from_name (data->builder, object_class);
|
||||||
if (object_type == G_TYPE_INVALID)
|
if (object_type == G_TYPE_INVALID)
|
||||||
{
|
{
|
||||||
@ -308,11 +322,6 @@ parse_object (GMarkupParseContext *context,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
error_missing_attribute (data, element_name, "class", error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!object_id)
|
if (!object_id)
|
||||||
{
|
{
|
||||||
|
@ -670,7 +670,7 @@ test_types (void)
|
|||||||
"</interface>";
|
"</interface>";
|
||||||
const gchar buffer2[] =
|
const gchar buffer2[] =
|
||||||
"<interface>"
|
"<interface>"
|
||||||
" <object type-func=\"gtk_window_get_type\" id=\"window\"/>"
|
" <object class=\"GtkWindow\" type-func=\"gtk_window_get_type\" id=\"window\"/>"
|
||||||
"</interface>";
|
"</interface>";
|
||||||
const gchar buffer3[] =
|
const gchar buffer3[] =
|
||||||
"<interface>"
|
"<interface>"
|
||||||
@ -678,7 +678,11 @@ test_types (void)
|
|||||||
"</interface>";
|
"</interface>";
|
||||||
const gchar buffer4[] =
|
const gchar buffer4[] =
|
||||||
"<interface>"
|
"<interface>"
|
||||||
" <object type-func=\"xxx_invalid_get_type_function\" id=\"window\"/>"
|
" <object class=\"GtkWindow\" type-func=\"xxx_invalid_get_type_function\" id=\"window\"/>"
|
||||||
|
"</interface>";
|
||||||
|
const gchar buffer5[] =
|
||||||
|
"<interface>"
|
||||||
|
" <object type-func=\"gtk_window_get_type\" id=\"window\"/>"
|
||||||
"</interface>";
|
"</interface>";
|
||||||
GtkBuilder *builder;
|
GtkBuilder *builder;
|
||||||
GObject *window;
|
GObject *window;
|
||||||
@ -707,6 +711,13 @@ test_types (void)
|
|||||||
g_assert_error (error, GTK_BUILDER_ERROR, GTK_BUILDER_ERROR_INVALID_TYPE_FUNCTION);
|
g_assert_error (error, GTK_BUILDER_ERROR, GTK_BUILDER_ERROR_INVALID_TYPE_FUNCTION);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
g_object_unref (builder);
|
g_object_unref (builder);
|
||||||
|
|
||||||
|
error = NULL;
|
||||||
|
builder = gtk_builder_new ();
|
||||||
|
gtk_builder_add_from_string (builder, buffer5, -1, &error);
|
||||||
|
g_assert_error (error, GTK_BUILDER_ERROR, GTK_BUILDER_ERROR_MISSING_ATTRIBUTE);
|
||||||
|
g_error_free (error);
|
||||||
|
g_object_unref (builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user