summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2023-02-20 13:12:27 +0000
committerMatthias Clasen <mclasen@redhat.com>2023-02-20 13:12:27 +0000
commit624458df9dd8d1cfc6af212916a608a7216dbdbd (patch)
tree9705b95d19d4887dabaa4a89bcebfbb3715ef817
parentfbfbaa484dd2b5300e608ad9a609014e456ae603 (diff)
parent3de10847b95268e51a3fea05174c3982f8c0da8a (diff)
downloadgtk+-624458df9dd8d1cfc6af212916a608a7216dbdbd.tar.gz
Merge branch 'builder-tool-child-properties' into 'main'
gtk4-builder-tool: Prefer child properties Closes #5609 See merge request GNOME/gtk!5543
-rw-r--r--testsuite/tools/simplify-data-3to4/paned.expected8
-rw-r--r--testsuite/tools/simplify-data/test10.expected10
-rw-r--r--testsuite/tools/simplify-data/test10.ui9
-rw-r--r--testsuite/tools/simplify-data/test11.expected15
-rw-r--r--testsuite/tools/simplify-data/test11.ui14
-rw-r--r--testsuite/tools/simplify-data/test12.expected15
-rw-r--r--testsuite/tools/simplify-data/test12.ui14
-rw-r--r--testsuite/tools/simplify-data/test13.expected20
-rw-r--r--testsuite/tools/simplify-data/test13.ui19
-rw-r--r--testsuite/tools/simplify-data/test5.expected4
-rw-r--r--testsuite/tools/simplify-data/test8.expected10
-rw-r--r--testsuite/tools/simplify-data/test8.ui9
-rw-r--r--testsuite/tools/simplify-data/test9.expected10
-rw-r--r--testsuite/tools/simplify-data/test9.ui9
-rw-r--r--tools/gtk-builder-tool-simplify.c182
15 files changed, 324 insertions, 24 deletions
diff --git a/testsuite/tools/simplify-data-3to4/paned.expected b/testsuite/tools/simplify-data-3to4/paned.expected
index d767086ba8..117fd2d4b6 100644
--- a/testsuite/tools/simplify-data-3to4/paned.expected
+++ b/testsuite/tools/simplify-data-3to4/paned.expected
@@ -4,11 +4,11 @@
<object class="GtkPaned">
<property name="resize-end-child">0</property>
<property name="shrink-start-child">0</property>
- <child>
+ <property name="start-child">
<object class="GtkButton" id="button"/>
- </child>
- <child>
+ </property>
+ <property name="end-child">
<object class="GtkLabel" id="label"/>
- </child>
+ </property>
</object>
</interface>
diff --git a/testsuite/tools/simplify-data/test10.expected b/testsuite/tools/simplify-data/test10.expected
new file mode 100644
index 0000000000..54dec91df8
--- /dev/null
+++ b/testsuite/tools/simplify-data/test10.expected
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <object class="GtkWindow">
+ <property name="child">
+ <object class="GtkLabel">
+ <property name="label">start</property>
+ </object>
+ </property>
+ </object>
+</interface>
diff --git a/testsuite/tools/simplify-data/test10.ui b/testsuite/tools/simplify-data/test10.ui
new file mode 100644
index 0000000000..3b5e171633
--- /dev/null
+++ b/testsuite/tools/simplify-data/test10.ui
@@ -0,0 +1,9 @@
+<interface>
+ <object class="GtkWindow">
+ <child>
+ <object class="GtkLabel">
+ <property name="label">start</property>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/testsuite/tools/simplify-data/test11.expected b/testsuite/tools/simplify-data/test11.expected
new file mode 100644
index 0000000000..d54c185bd6
--- /dev/null
+++ b/testsuite/tools/simplify-data/test11.expected
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <object class="GtkPaned">
+ <property name="start-child">
+ <object class="GtkLabel">
+ <property name="label">start</property>
+ </object>
+ </property>
+ <property name="end-child">
+ <object class="GtkLabel">
+ <property name="label">end</property>
+ </object>
+ </property>
+ </object>
+</interface>
diff --git a/testsuite/tools/simplify-data/test11.ui b/testsuite/tools/simplify-data/test11.ui
new file mode 100644
index 0000000000..1f546a1d08
--- /dev/null
+++ b/testsuite/tools/simplify-data/test11.ui
@@ -0,0 +1,14 @@
+<interface>
+ <object class="GtkPaned">
+ <child>
+ <object class="GtkLabel">
+ <property name="label">start</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="label">end</property>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/testsuite/tools/simplify-data/test12.expected b/testsuite/tools/simplify-data/test12.expected
new file mode 100644
index 0000000000..bc43c43753
--- /dev/null
+++ b/testsuite/tools/simplify-data/test12.expected
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <object class="GtkPaned">
+ <property name="end-child">
+ <object class="GtkLabel">
+ <property name="label">end</property>
+ </object>
+ </property>
+ <property name="start-child">
+ <object class="GtkLabel">
+ <property name="label">start</property>
+ </object>
+ </property>
+ </object>
+</interface>
diff --git a/testsuite/tools/simplify-data/test12.ui b/testsuite/tools/simplify-data/test12.ui
new file mode 100644
index 0000000000..865dfb41c4
--- /dev/null
+++ b/testsuite/tools/simplify-data/test12.ui
@@ -0,0 +1,14 @@
+<interface>
+ <object class="GtkPaned">
+ <child type="end">
+ <object class="GtkLabel">
+ <property name="label">end</property>
+ </object>
+ </child>
+ <child type="start">
+ <object class="GtkLabel">
+ <property name="label">start</property>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/testsuite/tools/simplify-data/test13.expected b/testsuite/tools/simplify-data/test13.expected
new file mode 100644
index 0000000000..ef4a037789
--- /dev/null
+++ b/testsuite/tools/simplify-data/test13.expected
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <object class="GtkCenterBox">
+ <property name="end-widget">
+ <object class="GtkLabel">
+ <property name="label">end</property>
+ </object>
+ </property>
+ <property name="center-widget">
+ <object class="GtkLabel">
+ <property name="label">center</property>
+ </object>
+ </property>
+ <property name="start-widget">
+ <object class="GtkLabel">
+ <property name="label">start</property>
+ </object>
+ </property>
+ </object>
+</interface>
diff --git a/testsuite/tools/simplify-data/test13.ui b/testsuite/tools/simplify-data/test13.ui
new file mode 100644
index 0000000000..b8a1397938
--- /dev/null
+++ b/testsuite/tools/simplify-data/test13.ui
@@ -0,0 +1,19 @@
+<interface>
+ <object class="GtkCenterBox">
+ <child type="end">
+ <object class="GtkLabel">
+ <property name="label">end</property>
+ </object>
+ </child>
+ <child type="center">
+ <object class="GtkLabel">
+ <property name="label">center</property>
+ </object>
+ </child>
+ <child type="start">
+ <object class="GtkLabel">
+ <property name="label">start</property>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/testsuite/tools/simplify-data/test5.expected b/testsuite/tools/simplify-data/test5.expected
index 24b18f4a52..73d04161ec 100644
--- a/testsuite/tools/simplify-data/test5.expected
+++ b/testsuite/tools/simplify-data/test5.expected
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow">
- <child>
+ <property name="child">
<object class="GtkBox">
<child>
<placeholder/>
</child>
</object>
- </child>
+ </property>
</object>
</interface>
diff --git a/testsuite/tools/simplify-data/test8.expected b/testsuite/tools/simplify-data/test8.expected
new file mode 100644
index 0000000000..8862b26584
--- /dev/null
+++ b/testsuite/tools/simplify-data/test8.expected
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <object class="GtkAspectFrame">
+ <property name="child">
+ <object class="GtkLabel">
+ <property name="label">start</property>
+ </object>
+ </property>
+ </object>
+</interface>
diff --git a/testsuite/tools/simplify-data/test8.ui b/testsuite/tools/simplify-data/test8.ui
new file mode 100644
index 0000000000..ef4f5061a8
--- /dev/null
+++ b/testsuite/tools/simplify-data/test8.ui
@@ -0,0 +1,9 @@
+<interface>
+ <object class="GtkAspectFrame">
+ <child>
+ <object class="GtkLabel">
+ <property name="label">start</property>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/testsuite/tools/simplify-data/test9.expected b/testsuite/tools/simplify-data/test9.expected
new file mode 100644
index 0000000000..1eb645aa4c
--- /dev/null
+++ b/testsuite/tools/simplify-data/test9.expected
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <object class="GtkComboBox">
+ <property name="child">
+ <object class="GtkLabel">
+ <property name="label">start</property>
+ </object>
+ </property>
+ </object>
+</interface>
diff --git a/testsuite/tools/simplify-data/test9.ui b/testsuite/tools/simplify-data/test9.ui
new file mode 100644
index 0000000000..fa3ee56d95
--- /dev/null
+++ b/testsuite/tools/simplify-data/test9.ui
@@ -0,0 +1,9 @@
+<interface>
+ <object class="GtkComboBox">
+ <child>
+ <object class="GtkLabel">
+ <property name="label">start</property>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/tools/gtk-builder-tool-simplify.c b/tools/gtk-builder-tool-simplify.c
index b66b4143ce..d279aa526f 100644
--- a/tools/gtk-builder-tool-simplify.c
+++ b/tools/gtk-builder-tool-simplify.c
@@ -1279,6 +1279,114 @@ rewrite_paned (Element *element,
}
static void
+replace_child_by_property (Element *element,
+ Element *child,
+ const char *property,
+ MyParserData *data)
+{
+ Element *obj, *elt;
+
+ obj = child->children->data;
+ g_assert (obj && g_str_equal (obj->element_name, "object"));
+ child->children = g_list_remove (child->children, obj);
+
+ elt = g_new0 (Element, 1);
+ elt->parent = element;
+ elt->element_name = g_strdup ("property");
+ elt->attribute_names = g_new0 (char *, 2);
+ elt->attribute_names[0] = g_strdup ("name");
+ elt->attribute_values = g_new0 (char *, 2);
+ elt->attribute_values[0] = g_strdup (property);
+ elt->children = g_list_prepend (NULL, obj);
+
+ for (GList *l = element->children; l; l = l->next)
+ {
+ if (l->data == child)
+ {
+ l->data = elt;
+ elt = NULL;
+ free_element (child);
+ break;
+ }
+ }
+
+ g_assert (elt == NULL);
+}
+
+static void
+rewrite_start_end_children (Element *element,
+ MyParserData *data)
+{
+ Element *start_child = NULL;
+ Element *end_child = NULL;
+ GList *l;
+
+ for (l = element->children; l; l = l->next)
+ {
+ Element *child = l->data;
+
+ if (!g_str_equal (child->element_name, "child"))
+ continue;
+
+ if (has_attribute (child, "type", "start"))
+ start_child = child;
+ else if (has_attribute (child, "type", "end"))
+ end_child = child;
+ else if (start_child == NULL)
+ start_child = child;
+ else if (end_child == NULL)
+ end_child = child;
+ else
+ g_warning ("%s only accepts two children", get_class_name (element));
+ }
+
+ if (start_child)
+ replace_child_by_property (element, start_child, "start-child", data);
+
+ if (end_child)
+ replace_child_by_property (element, end_child, "end-child", data);
+}
+
+static void
+rewrite_start_center_end_children (Element *element,
+ MyParserData *data)
+{
+ Element *start_child = NULL;
+ Element *center_child = NULL;
+ Element *end_child = NULL;
+ GList *l;
+
+ for (l = element->children; l; l = l->next)
+ {
+ Element *child = l->data;
+
+ if (has_attribute (child, "type", "start"))
+ start_child = child;
+ else if (has_attribute (child, "type", "center"))
+ center_child = child;
+ else if (has_attribute (child, "type", "end"))
+ end_child = child;
+ else if (start_child == NULL)
+ start_child = child;
+ else if (center_child == NULL)
+ center_child = child;
+ else if (end_child == NULL)
+ end_child = child;
+ else
+ g_warning ("%s only accepts three children", get_class_name (element));
+ }
+
+ if (start_child)
+ replace_child_by_property (element, start_child, "start-widget", data);
+
+ if (center_child)
+ replace_child_by_property (element, center_child, "center-widget", data);
+
+ if (end_child)
+ replace_child_by_property (element, end_child, "end-widget", data);
+}
+
+static void
rewrite_dialog (Element *element,
MyParserData *data)
{
@@ -2004,8 +2112,8 @@ simplify_tree (MyParserData *data)
}
static gboolean
-rewrite_element (Element *element,
- MyParserData *data)
+rewrite_element_3to4 (Element *element,
+ MyParserData *data)
{
GList *l;
@@ -2014,7 +2122,7 @@ rewrite_element (Element *element,
{
GList *next = l->next;
Element *child = l->data;
- if (rewrite_element (child, data))
+ if (rewrite_element_3to4 (child, data))
{
element->children = g_list_remove (element->children, child);
free_element (child);
@@ -2070,6 +2178,52 @@ rewrite_element (Element *element,
rewrite_fixed (element, data);
if (element_is_object_or_template (element) &&
+ g_str_equal (get_class_name (element), "GtkRadioButton"))
+ rewrite_radio_button (element, data);
+
+ if (element_is_object_or_template (element) &&
+ g_str_equal (get_class_name (element), "GtkScale"))
+ rewrite_scale (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;
+
+ if (g_str_equal (element->element_name, "requires"))
+ rewrite_requires (element, data);
+
+ return FALSE;
+}
+
+static void
+rewrite_tree_3to4 (MyParserData *data)
+{
+ rewrite_element_3to4 (data->root, data);
+}
+
+static gboolean
+rewrite_element (Element *element,
+ MyParserData *data)
+{
+ GList *l;
+
+ l = element->children;
+ while (l)
+ {
+ GList *next = l->next;
+ Element *child = l->data;
+ if (rewrite_element (child, data))
+ {
+ element->children = g_list_remove (element->children, child);
+ free_element (child);
+ }
+ l = next;
+ }
+
+ 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") ||
@@ -2087,22 +2241,12 @@ rewrite_element (Element *element,
rewrite_bin_child (element, data);
if (element_is_object_or_template (element) &&
- g_str_equal (get_class_name (element), "GtkRadioButton"))
- rewrite_radio_button (element, data);
+ g_str_equal (get_class_name (element), "GtkPaned"))
+ rewrite_start_end_children (element, data);
if (element_is_object_or_template (element) &&
- g_str_equal (get_class_name (element), "GtkScale"))
- rewrite_scale (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;
-
- if (g_str_equal (element->element_name, "requires"))
- rewrite_requires (element, data);
+ g_str_equal (get_class_name (element), "GtkCenterBox"))
+ rewrite_start_center_end_children (element, data);
return FALSE;
}
@@ -2319,8 +2463,10 @@ simplify_file (const char *filename,
if (data.convert3to4)
{
enhance_tree (&data);
- rewrite_tree (&data);
+ rewrite_tree_3to4 (&data);
}
+
+ rewrite_tree (&data);
simplify_tree (&data);
dump_tree (&data);