[gtk/stackpage: 11/11] builder-tool: Convert assistant pages too



commit 9f088c1a6dc31bb1c293a9bb86aa3bc9ad5de2fd
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Feb 7 15:34:54 2019 -0500

    builder-tool: Convert assistant pages too
    
    Do the same transformation for GtkAssistantPage that
    we already do for GtkStackPage, to transform GTK 3 .ui
    files to GTK 4 ways of doing things.

 gtk/tools/gtk-builder-tool-simplify.c | 69 +++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)
---
diff --git a/gtk/tools/gtk-builder-tool-simplify.c b/gtk/tools/gtk-builder-tool-simplify.c
index c84fdbca59..e4db3c0321 100644
--- a/gtk/tools/gtk-builder-tool-simplify.c
+++ b/gtk/tools/gtk-builder-tool-simplify.c
@@ -576,6 +576,71 @@ rewrite_stack (Element      *element,
   element->children = new_children;
 }
 
+static Element *
+rewrite_assistant_child (Element *child, MyParserData *data)
+{
+  Element *object = NULL;
+  Element *packing = NULL;
+  Element *new_object;
+  Element *prop;
+  GList *l;
+
+  if (!g_str_equal (child->element_name, "child"))
+    return child;
+
+  for (l = child->children; l; l = l->next)
+    {
+      Element *elt = l->data;
+      if (g_str_equal (elt->element_name, "object"))
+        object = elt;
+      else if (g_str_equal (elt->element_name, "packing"))
+        packing = elt;
+    }
+
+  if (!packing)
+    return child;
+
+  new_object = g_new0 (Element, 1);
+  new_object->element_name = g_strdup ("object");
+  new_object->attribute_names = g_new0 (char *, 2);
+  new_object->attribute_names[0] = g_strdup ("class");
+  new_object->attribute_values = g_new0 (char *, 2);
+  new_object->attribute_values[0] = g_strdup ("GtkAssistantPage");
+  new_object->children = packing->children;
+  packing->children = NULL;
+
+  prop = g_new0 (Element, 1);
+  prop->element_name = g_strdup ("property");
+  prop->attribute_names = g_new0 (char *, 2);
+  prop->attribute_names[0] = g_strdup ("name");
+  prop->attribute_values = g_new0 (char *, 2);
+  prop->attribute_values[0] = g_strdup ("child");
+  prop->children = g_list_append (prop->children, object);
+  new_object->children = g_list_append (new_object->children, prop);
+      
+  g_list_free (child->children);
+  child->children = g_list_append (NULL, new_object);
+
+  return child;
+}
+
+static void
+rewrite_assistant (Element      *element,
+                   MyParserData *data)
+{
+  GList *l, *new_children;
+
+  new_children = NULL;
+  for (l = element->children; l; l = l->next)
+    {
+      Element *child = l->data;
+      new_children = g_list_append (new_children, rewrite_assistant_child (child, data));
+    }
+
+  g_list_free (element->children);
+  element->children = new_children;
+}
+
 static gboolean
 simplify_element (Element      *element,
                   MyParserData *data)
@@ -617,6 +682,10 @@ simplify_element (Element      *element,
       if (g_str_equal (element->element_name, "object") &&
           g_str_equal (get_class_name (element), "GtkStack"))
         rewrite_stack (element, data);
+
+      if (g_str_equal (element->element_name, "object") &&
+          g_str_equal (get_class_name (element), "GtkAssistant"))
+        rewrite_assistant (element, data);
           
       if (g_str_equal (element->element_name, "property") &&
           property_has_been_removed (element, data))


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