[gtk/wip/otte/listview: 19/141] builder: Make <lookup> type optional
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/listview: 19/141] builder: Make <lookup> type optional
- Date: Tue, 26 Nov 2019 19:31:58 +0000 (UTC)
commit 85caf532bc7e2b0235031834a674fa7ee62bd10f
Author: Benjamin Otte <otte redhat com>
Date: Mon Nov 25 08:01:31 2019 +0100
builder: Make <lookup> type optional
If no type is set, use the type of the expression.
gtk/gtkbuilderparser.c | 43 ++++++++++++++++++++++++++++++++-----------
1 file changed, 32 insertions(+), 11 deletions(-)
---
diff --git a/gtk/gtkbuilderparser.c b/gtk/gtkbuilderparser.c
index 11d6f525e5..dba6b27028 100644
--- a/gtk/gtkbuilderparser.c
+++ b/gtk/gtkbuilderparser.c
@@ -1159,7 +1159,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))
@@ -1169,7 +1169,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))
{
@@ -1177,15 +1177,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);
@@ -1277,6 +1284,7 @@ expression_info_construct (GtkBuilder *builder,
case EXPRESSION_PROPERTY:
{
GtkExpression *expression;
+ GType type;
if (info->property.expression)
{
@@ -1288,7 +1296,20 @@ expression_info_construct (GtkBuilder *builder,
else
expression = NULL;
- expression = gtk_property_expression_new (info->property.this_type,
+ if (info->property.this_type != G_TYPE_INVALID)
+ type = info->property.this_type;
+ else if (expression != NULL)
+ type = gtk_expression_get_value_type (expression);
+ else
+ {
+ g_set_error (error,
+ GTK_BUILDER_ERROR,
+ GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
+ "%s:%d:%d Lookups require a type attribute if they don't have an expression.",
+ "???", 0, 0);
+ return NULL;
+ }
+ expression = gtk_property_expression_new (type,
expression,
info->property.property_name);
g_free (info->property.property_name);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]