[gtk/bin-removal: 14/15] builder-tool: Convert former bin children



commit 1734d2ae5fdf6813fcb92fb28abe8b555e267910
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri May 1 18:02:46 2020 -0400

    builder-tool: Convert former bin children
    
    Convert from <child> elements to <property name="child">
    for former GtkBin subclasses.

 gtk/tools/gtk-builder-tool-simplify.c | 60 +++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)
---
diff --git a/gtk/tools/gtk-builder-tool-simplify.c b/gtk/tools/gtk-builder-tool-simplify.c
index 06a31fb2b9..76b28560ae 100644
--- a/gtk/tools/gtk-builder-tool-simplify.c
+++ b/gtk/tools/gtk-builder-tool-simplify.c
@@ -1490,6 +1490,55 @@ rewrite_grid_layout (Element *element,
     }
 }
 
+static void
+rewrite_bin_child (Element      *element,
+                   MyParserData *data)
+{
+  GList *l, *ll;
+  const char *class_name;
+  GType type;
+
+  for (l = element->children; l; l = l->next)
+    {
+      Element *child = l->data;
+      Element *object = NULL;
+
+      if (!g_str_equal (child->element_name, "child"))
+        continue;
+
+      for (ll = child->children; ll; ll = ll->next)
+        {
+          Element *elem = ll->data;
+
+          if (!g_str_equal (elem->element_name, "object"))
+            continue;
+
+          class_name = get_attribute_value (elem, "class");
+          if (!class_name)
+            continue;
+
+          type = g_type_from_name (class_name);
+          if (!g_type_is_a (type, GTK_TYPE_WIDGET))
+            continue;
+
+          object = elem;
+        }
+
+      if (object)
+        {
+          g_free (child->element_name);
+          g_strfreev (child->attribute_names);
+          g_strfreev (child->attribute_values);
+          child->element_name = g_strdup ("property");
+          child->attribute_names = g_new0 (char *, 2);
+          child->attribute_names[0] = g_strdup ("name");
+          child->attribute_values = g_new0 (char *, 2);
+          child->attribute_values[0] = g_strdup ("child");
+          break;
+        }
+    }
+}
+
 /* returns TRUE to remove the element from the parent */
 static gboolean
 simplify_element (Element      *element,
@@ -1604,6 +1653,17 @@ rewrite_element (Element      *element,
       g_str_equal (get_class_name (element), "GtkFixed"))
     rewrite_layout_props (element, data);
 
+  if (element_is_object_or_template (element) &&
+      (g_str_equal (get_class_name (element), "GtkAspectFrame") ||
+       g_str_equal (get_class_name (element), "GtkFrame") ||
+       g_str_equal (get_class_name (element), "GtkPopover") ||
+       g_str_equal (get_class_name (element), "GtkPopoverMenu") ||
+       g_str_equal (get_class_name (element), "GtkRevealer") ||
+       g_str_equal (get_class_name (element), "GtkScrolledWindow") ||
+       g_str_equal (get_class_name (element), "GtkViewport") ||
+       g_str_equal (get_class_name (element), "GtkWindow")))
+    rewrite_bin_child (element, data);
+
   if (g_str_equal (element->element_name, "property"))
     maybe_rename_property (element, data);
 


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