builder: Make <lookup> type optional

If no type is set, use the type of the expression.
This commit is contained in:
Benjamin Otte 2019-11-25 08:01:31 +01:00 committed by Matthias Clasen
parent d3dc9c41b4
commit ed22af50bc

View File

@ -1144,7 +1144,7 @@ parse_lookup_expression (ParserData *data,
{
ExpressionInfo *info;
const char *property_name;
const char *type_name;
const char *type_name = NULL;
GType type;
if (!check_expression_parent (data))
@ -1154,7 +1154,7 @@ parse_lookup_expression (ParserData *data,
}
if (!g_markup_collect_attributes (element_name, names, values, error,
G_MARKUP_COLLECT_STRING, "type", &type_name,
G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "type", &type_name,
G_MARKUP_COLLECT_STRING, "name", &property_name,
G_MARKUP_COLLECT_INVALID))
{
@ -1162,15 +1162,22 @@ parse_lookup_expression (ParserData *data,
return;
}
type = gtk_builder_get_type_from_name (data->builder, type_name);
if (type == G_TYPE_INVALID)
if (type_name == NULL)
{
g_set_error (error,
GTK_BUILDER_ERROR,
GTK_BUILDER_ERROR_INVALID_VALUE,
"Invalid type '%s'", type_name);
_gtk_builder_prefix_error (data->builder, &data->ctx, error);
return;
type = G_TYPE_INVALID;
}
else
{
type = gtk_builder_get_type_from_name (data->builder, type_name);
if (type == G_TYPE_INVALID)
{
g_set_error (error,
GTK_BUILDER_ERROR,
GTK_BUILDER_ERROR_INVALID_VALUE,
"Invalid type '%s'", type_name);
_gtk_builder_prefix_error (data->builder, &data->ctx, error);
return;
}
}
info = g_slice_new0 (ExpressionInfo);