From dec5707ca918c6396d75b4eac4452b263ce16de6 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 1 May 2020 18:02:46 -0400 Subject: [PATCH] builder-tool: Convert former bin children Convert from elements to for former GtkBin subclasses. Update test results to match. --- gtk/tools/gtk-builder-tool-simplify.c | 67 +++++++++++++++++++ .../tools/simplify-data-3to4/grid.expected | 4 +- .../simplify-data-3to4/notebook.expected | 4 +- .../simplify-data-3to4/office-runner.expected | 4 +- .../tools/simplify-data-3to4/stack.expected | 4 +- 5 files changed, 75 insertions(+), 8 deletions(-) diff --git a/gtk/tools/gtk-builder-tool-simplify.c b/gtk/tools/gtk-builder-tool-simplify.c index 9d96c85e09..af9d902f3f 100644 --- a/gtk/tools/gtk-builder-tool-simplify.c +++ b/gtk/tools/gtk-builder-tool-simplify.c @@ -1491,6 +1491,56 @@ 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") || + has_attribute (child, "type", NULL)) + 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, @@ -1605,6 +1655,23 @@ 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), "GtkComboBox") || + g_str_equal (get_class_name (element), "GtkComboBoxText") || + g_str_equal (get_class_name (element), "GtkFlowBoxChild") || + g_str_equal (get_class_name (element), "GtkFrame") || + g_str_equal (get_class_name (element), "GtkListBoxRow") || + g_str_equal (get_class_name (element), "GtkOverlay") || + 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), "GtkSearchBar") || + 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); diff --git a/testsuite/tools/simplify-data-3to4/grid.expected b/testsuite/tools/simplify-data-3to4/grid.expected index 61989d49f8..5005cc0725 100644 --- a/testsuite/tools/simplify-data-3to4/grid.expected +++ b/testsuite/tools/simplify-data-3to4/grid.expected @@ -1,7 +1,7 @@ - + @@ -111,6 +111,6 @@ - + diff --git a/testsuite/tools/simplify-data-3to4/notebook.expected b/testsuite/tools/simplify-data-3to4/notebook.expected index c0f84f57f2..f0bc7f9e82 100644 --- a/testsuite/tools/simplify-data-3to4/notebook.expected +++ b/testsuite/tools/simplify-data-3to4/notebook.expected @@ -1,7 +1,7 @@ - + @@ -32,6 +32,6 @@ - + diff --git a/testsuite/tools/simplify-data-3to4/office-runner.expected b/testsuite/tools/simplify-data-3to4/office-runner.expected index 9c0189733d..11131a71e5 100644 --- a/testsuite/tools/simplify-data-3to4/office-runner.expected +++ b/testsuite/tools/simplify-data-3to4/office-runner.expected @@ -5,7 +5,7 @@ Office Runner 0 center - + 12 12 @@ -217,6 +217,6 @@ - + diff --git a/testsuite/tools/simplify-data-3to4/stack.expected b/testsuite/tools/simplify-data-3to4/stack.expected index 1c5c0beb56..611d20edf8 100644 --- a/testsuite/tools/simplify-data-3to4/stack.expected +++ b/testsuite/tools/simplify-data-3to4/stack.expected @@ -1,7 +1,7 @@ - + @@ -39,6 +39,6 @@ - +