[gtk/wip/matthiasc/listview-2: 32/174] builder: Make <lookup> type optional



commit 494f25ca75fabc25b28569572fbb3394f56f83f0
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 fffe99e0c1..b171946156 100644
--- a/gtk/gtkbuilderparser.c
+++ b/gtk/gtkbuilderparser.c
@@ -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);
@@ -1264,6 +1271,7 @@ expression_info_construct (GtkBuilder      *builder,
     case EXPRESSION_PROPERTY:
       {
         GtkExpression *expression;
+        GType type;
 
         if (info->property.expression)
           {
@@ -1275,7 +1283,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]