[gtk+] gtk-builder-tool: Start an exception list



commit b8548d27a1b9ce23e75454c3dc27780ef631867b
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat May 2 07:35:35 2015 -0400

    gtk-builder-tool: Start an exception list
    
    We have a number of cases where properties should have their
    default value overridden in a subclass, but haven't because thats
    annoying to do. We also have properties where the absence of
    an explicit value has context-dependent meaning.
    Add a list of exceptions for these cases.

 gtk/gtk-builder-tool.c |   50 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtk-builder-tool.c b/gtk/gtk-builder-tool.c
index 40d7aa7..91cad48 100644
--- a/gtk/gtk-builder-tool.c
+++ b/gtk/gtk-builder-tool.c
@@ -95,6 +95,53 @@ value_is_default (MyParserData *data,
   return ret;
 }
 
+/* A number of properties unfortunately can't be omitted even
+ * if they are nominally set to their default value. In many
+ * cases, this is due to subclasses not overriding the default
+ * value from the superclass.
+ */
+static gboolean
+needs_explicit_setting (MyParserData *data,
+                        gint          i)
+{
+  struct _Prop {
+    const char *class;
+    const char *property;
+    gboolean packing;
+  } props[] = {
+    { "GtkRadioButton", "draw-indicator", 0 },
+    { "GtkGrid", "left-attach", 1 },
+    { "GtkGrid", "top-attach", 1 },
+    { NULL, NULL, 0 }
+  };
+  const gchar *class_name;
+  const gchar *property_name;
+  gchar *canonical_name;
+  gboolean found;
+  gint k;
+
+  class_name = (const gchar *)data->classes->data;
+  property_name = (const gchar *)data->attribute_values[i];
+  canonical_name = g_strdup (property_name);
+  g_strdelimit (canonical_name, "_", '-');
+
+  found = FALSE;
+  for (k = 0; props[k].class; k++)
+    {
+      if (strcmp (class_name, props[k].class) == 0 &&
+          strcmp (canonical_name, props[k].property) == 0 &&
+          data->packing == props[k].packing)
+        {
+          found = TRUE;
+          break;
+        }
+    }
+
+  g_free (canonical_name);
+
+  return found;
+}
+
 static void
 maybe_emit_property (MyParserData *data)
 {
@@ -109,6 +156,9 @@ maybe_emit_property (MyParserData *data)
           if (data->classes == NULL)
             break;
 
+          if (needs_explicit_setting (data, i))
+            break;
+
           if (value_is_default (data, i))
             return;
         }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]