[gtk+] Improve formatting of CSS style prints



commit cfa0884165d306e64cca74213c6fbc20ad071c7e
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jan 3 17:05:16 2016 -0500

    Improve formatting of CSS style prints
    
    Add a newline after CSS properties, so things don't run into
    each other.

 gtk/gtkcssnode.c         |    9 +++++++--
 gtk/gtkcssstyle.c        |   21 ++++++++++++++++++++-
 gtk/gtkcssstyleprivate.h |    2 +-
 3 files changed, 28 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkcssnode.c b/gtk/gtkcssnode.c
index 676d0b2..a5dda31 100644
--- a/gtk/gtkcssnode.c
+++ b/gtk/gtkcssnode.c
@@ -1529,7 +1529,7 @@ gtk_css_node_print (GtkCssNode                *cssnode,
                     GString                   *string,
                     guint                      indent)
 {
-  GtkCssNode *node;
+  gboolean need_newline = FALSE;
 
   g_string_append_printf (string, "%*s", indent, "");
 
@@ -1544,10 +1544,15 @@ gtk_css_node_print (GtkCssNode                *cssnode,
   g_string_append_c (string, '\n');
 
   if (flags & GTK_STYLE_CONTEXT_PRINT_SHOW_STYLE)
-    gtk_css_style_print (gtk_css_node_get_style (cssnode), string, indent + 2, TRUE);
+    need_newline = gtk_css_style_print (gtk_css_node_get_style (cssnode), string, indent + 2, TRUE);
 
   if (flags & GTK_STYLE_CONTEXT_PRINT_RECURSE)
     {
+      GtkCssNode *node;
+
+      if (need_newline && gtk_css_node_get_first_child (cssnode))
+        g_string_append_c (string, '\n');
+
       for (node = gtk_css_node_get_first_child (cssnode); node; node = gtk_css_node_get_next_sibling (node))
         gtk_css_node_print (node, flags, string, indent + 2);
     }
diff --git a/gtk/gtkcssstyle.c b/gtk/gtkcssstyle.c
index 812c8dc..794a20a 100644
--- a/gtk/gtkcssstyle.c
+++ b/gtk/gtkcssstyle.c
@@ -114,13 +114,28 @@ gtk_css_style_is_static (GtkCssStyle *style)
   return GTK_CSS_STYLE_GET_CLASS (style)->is_static (style);
 }
 
-void
+/*
+ * gtk_css_style_print:
+ * @style: a #GtkCssStyle
+ * @string: the #GString to print to
+ * @indent: level of indentation to use
+ * @skip_initial: %TRUE to skip properties that have their initial value
+ *
+ * Print the @style to @string, in CSS format. Every property is printed
+ * on a line by itself, indented by @indent spaces. If @skip_initial is
+ * %TRUE, properties are only printed if their value in @style is different
+ * from the initial value of the property.
+ *
+ * Returns: %TRUE is any properties have been printed
+ */
+gboolean
 gtk_css_style_print (GtkCssStyle *style,
                      GString     *string,
                      guint        indent,
                      gboolean     skip_initial)
 {
   guint i;
+  gboolean retval = FALSE;
 
   g_return_if_fail (GTK_IS_CSS_STYLE (style));
   g_return_if_fail (string != NULL);
@@ -152,7 +167,11 @@ gtk_css_style_print (GtkCssStyle *style,
         }
 
       g_string_append_c (string, '\n');
+
+      retval = TRUE;
     }
+
+  return retval;
 }
 
 char *
diff --git a/gtk/gtkcssstyleprivate.h b/gtk/gtkcssstyleprivate.h
index d5cd405..f1d165f 100644
--- a/gtk/gtkcssstyleprivate.h
+++ b/gtk/gtkcssstyleprivate.h
@@ -70,7 +70,7 @@ GtkBitmask *            gtk_css_style_add_difference            (GtkBitmask
 gboolean                gtk_css_style_is_static                 (GtkCssStyle            *style);
 
 char *                  gtk_css_style_to_string                 (GtkCssStyle            *style);
-void                    gtk_css_style_print                     (GtkCssStyle            *style,
+gboolean                gtk_css_style_print                     (GtkCssStyle            *style,
                                                                  GString                *string,
                                                                  guint                   indent,
                                                                  gboolean                skip_initial);


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