[gtk/wip/matthiasc/popup5: 116/152] builder tool: Handle modal->autohide rename



commit 6876335a5028a58dc891e9ab7be016141c2f16b8
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun May 19 23:53:15 2019 +0000

    builder tool: Handle modal->autohide rename
    
    Add a facility for renamed properties,
    and use it for GtkPopover::modal.

 gtk/tools/gtk-builder-tool-simplify.c | 57 +++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)
---
diff --git a/gtk/tools/gtk-builder-tool-simplify.c b/gtk/tools/gtk-builder-tool-simplify.c
index 3f4cff4286..776496ca4a 100644
--- a/gtk/tools/gtk-builder-tool-simplify.c
+++ b/gtk/tools/gtk-builder-tool-simplify.c
@@ -216,6 +216,7 @@ keep_for_rewrite (const char *class_name,
     const char *property;
     PropKind kind;
   } props[] = {
+    { "GtkPopover", "modal", PROP_KIND_OBJECT },
     { "GtkActionBar", "pack-type", PROP_KIND_PACKING },
     { "GtkHeaderBar", "pack-type", PROP_KIND_PACKING },
     { "GtkPopoverMenu", "submenu", PROP_KIND_PACKING },
@@ -702,6 +703,59 @@ property_has_been_removed (Element      *element,
   return found;
 }
 
+static void
+maybe_rename_property (Element *element, MyParserData *data)
+{
+  const gchar *class_name;
+  const gchar *property_name;
+  struct _Prop {
+    const char *class;
+    const char *property;
+    PropKind kind;
+    const char *new_name;
+  } props[] = {
+    { "GtkPopover", "modal", PROP_KIND_OBJECT, "autohide" },
+  };
+  char *canonical_name;
+  int i, k;
+  PropKind kind;
+  int prop_name_index = 0;
+
+  kind = get_prop_kind (element);
+
+  class_name = get_class_name (element);
+  property_name = NULL;
+
+  for (i = 0; element->attribute_names[i]; i++)
+    {
+      if (strcmp (element->attribute_names[i], "name") == 0)
+        {
+          prop_name_index = i;
+          property_name = (const gchar *)element->attribute_values[i];
+        }
+    }
+
+  if (property_name == NULL)
+    return;
+
+  canonical_name = g_strdup (property_name);
+  g_strdelimit (canonical_name, "_", '-');
+
+  for (k = 0; k < G_N_ELEMENTS (props); k++)
+    {
+      if (strcmp (class_name, props[k].class) == 0 &&
+          strcmp (canonical_name, props[k].property) == 0 &&
+          kind == props[k].kind)
+        {
+          g_free (element->attribute_values[prop_name_index]);
+          element->attribute_values[prop_name_index] = g_strdup (props[k].new_name);
+          break;
+        }
+    }
+
+  g_free (canonical_name);
+}
+
 static Element *
 rewrite_stack_child (Element *child, MyParserData *data)
 {
@@ -1437,6 +1491,9 @@ rewrite_element (Element      *element,
       g_str_equal (get_class_name (element), "GtkFixed"))
     rewrite_layout_props (element, data);
 
+  if (g_str_equal (element->element_name, "property"))
+    maybe_rename_property (element, data);
+
   if (g_str_equal (element->element_name, "property") &&
       property_has_been_removed (element, data))
     return TRUE;


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