[gtk/matthiasc/for-master: 1/2] gtk-builder-tool: Simplify <style>
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/for-master: 1/2] gtk-builder-tool: Simplify <style>
- Date: Wed, 29 Sep 2021 01:20:57 +0000 (UTC)
commit c06c87a61e23a08f33f49327cdc0278f9e930953
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Sep 28 21:11:16 2021 -0400
gtk-builder-tool: Simplify <style>
Replace <style> elements with simply setting
the css-classes property. Less custom markup
is better, and we may want to drop the <style>
element in the future.
Test included.
testsuite/tools/simplify-data/test8.expected | 7 ++++++
testsuite/tools/simplify-data/test8.ui | 8 +++++++
tools/gtk-builder-tool-simplify.c | 32 ++++++++++++++++++++++++++++
3 files changed, 47 insertions(+)
---
diff --git a/testsuite/tools/simplify-data/test8.expected b/testsuite/tools/simplify-data/test8.expected
new file mode 100644
index 0000000000..1a3dae8d9b
--- /dev/null
+++ b/testsuite/tools/simplify-data/test8.expected
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <object class="GtkLabel">
+ <property name="css-classes">class1
+dim-label</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..3ff5106700
--- /dev/null
+++ b/testsuite/tools/simplify-data/test8.ui
@@ -0,0 +1,8 @@
+<interface>
+ <object class="GtkLabel">
+ <style>
+ <class name="class1"/>
+ <class name="dim-label"/>
+ </style>
+ </object>
+</interface>
diff --git a/tools/gtk-builder-tool-simplify.c b/tools/gtk-builder-tool-simplify.c
index 3eb5a21f78..f82590a447 100644
--- a/tools/gtk-builder-tool-simplify.c
+++ b/tools/gtk-builder-tool-simplify.c
@@ -1910,6 +1910,38 @@ simplify_element (Element *element,
warn_missing_property (element, data, class_name, property_name, PROP_KIND_OBJECT);
}
+ if (g_str_equal (element->element_name, "style"))
+ {
+ GString *s;
+
+ s = g_string_new ("");
+
+ for (l = element->children; l; l = l->next)
+ {
+ Element *child = l->data;
+
+ if (g_str_equal (child->element_name, "class"))
+ {
+ if (s->len > 0)
+ g_string_append_c (s, '\n');
+ g_string_append (s, get_attribute_value (child, "name"));
+ }
+ }
+
+ if (s->len > 0)
+ {
+ Element *child = add_element (element->parent, "property");
+ set_attribute_value (child, "name", "css-classes");
+ child->data = g_string_free (s, FALSE);
+ }
+ else
+ {
+ g_string_free (s, TRUE);
+ }
+
+ return TRUE;
+ }
+
return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]