[gtksourceview/wip/space-drawing] SpaceDrawer: better default value for the matrix property



commit 93a7eb6f6304b3092cc3e3840849bed1b945676f
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Fri Sep 30 20:51:07 2016 +0200

    SpaceDrawer: better default value for the matrix property
    
    Now that there is the enable-matrix property (false by default), the
    matrix property can enable all types at all locations by default.

 gtksourceview/gtksourcespacedrawer.c |   40 +++++++++++++++++++++++++++++----
 tests/test-widget.c                  |    6 -----
 testsuite/test-space-drawer.c        |   10 ++++----
 3 files changed, 40 insertions(+), 16 deletions(-)
---
diff --git a/gtksourceview/gtksourcespacedrawer.c b/gtksourceview/gtksourcespacedrawer.c
index a5bed28..ddf28fd 100644
--- a/gtksourceview/gtksourcespacedrawer.c
+++ b/gtksourceview/gtksourcespacedrawer.c
@@ -43,9 +43,13 @@
  * Call gtk_source_view_get_space_drawer() to get the #GtkSourceSpaceDrawer
  * instance of a certain #GtkSourceView.
  *
- * By default, no white spaces are drawn. To draw white spaces,
- * gtk_source_space_drawer_set_types_for_locations() can be called to set the
- * #GtkSourceSpaceDrawer:matrix property.
+ * By default, no white spaces are drawn because the
+ * #GtkSourceSpaceDrawer:enable-matrix is %FALSE.
+ *
+ * To draw white spaces, gtk_source_space_drawer_set_types_for_locations() can
+ * be called to set the #GtkSourceSpaceDrawer:matrix property (by default all
+ * space types are enabled at all locations). Then call
+ * gtk_source_space_drawer_set_enable_matrix().
  *
  * For a finer-grained method, there is also the GtkSourceTag's
  * #GtkSourceTag:draw-spaces property.
@@ -63,6 +67,8 @@
  *                                                  GTK_SOURCE_SPACE_LOCATION_TRAILING,
  *                                                  GTK_SOURCE_SPACE_TYPE_ALL &
  *                                                  ~GTK_SOURCE_SPACE_TYPE_NEWLINE);
+ *
+ * gtk_source_space_drawer_set_enable_matrix (space_drawer, TRUE);
  * ]|
  */
 
@@ -112,6 +118,29 @@ get_number_of_locations (void)
        return num;
 }
 
+static GVariant *
+get_default_matrix (void)
+{
+       GVariantBuilder builder;
+       gint num_locations;
+       gint i;
+
+       g_variant_builder_init (&builder, G_VARIANT_TYPE ("au"));
+
+       num_locations = get_number_of_locations ();
+
+       for (i = 0; i < num_locations; i++)
+       {
+               GVariant *space_types;
+
+               space_types = g_variant_new_uint32 (GTK_SOURCE_SPACE_TYPE_ALL);
+
+               g_variant_builder_add_value (&builder, space_types);
+       }
+
+       return g_variant_builder_end (&builder);
+}
+
 static gboolean
 is_zero_matrix (GtkSourceSpaceDrawer *drawer)
 {
@@ -313,7 +342,7 @@ gtk_source_space_drawer_class_init (GtkSourceSpaceDrawerClass *klass)
         * If the array is shorter than the number of locations, then the value
         * for the missing locations will be %GTK_SOURCE_SPACE_TYPE_NONE.
         *
-        * The default value is the empty array `"[]"`.
+        * By default, %GTK_SOURCE_SPACE_TYPE_ALL is set for all locations.
         *
         * Since: 3.24
         */
@@ -322,8 +351,9 @@ gtk_source_space_drawer_class_init (GtkSourceSpaceDrawerClass *klass)
                                      "Matrix",
                                      "",
                                      G_VARIANT_TYPE ("au"),
-                                     g_variant_new ("au", NULL),
+                                     get_default_matrix (),
                                      G_PARAM_READWRITE |
+                                     G_PARAM_CONSTRUCT |
                                      G_PARAM_STATIC_STRINGS);
 
        g_object_class_install_properties (object_class, N_PROPERTIES, properties);
diff --git a/tests/test-widget.c b/tests/test-widget.c
index 8af7e2f..c065185 100644
--- a/tests/test-widget.c
+++ b/tests/test-widget.c
@@ -1066,13 +1066,7 @@ test_widget_init (TestWidget *self)
                          G_CALLBACK (on_background_pattern_changed),
                          self);
 
-       /* White space drawing */
        space_drawer = gtk_source_view_get_space_drawer (self->priv->view);
-
-       gtk_source_space_drawer_set_types_for_locations (space_drawer,
-                                                        GTK_SOURCE_SPACE_LOCATION_ALL,
-                                                        GTK_SOURCE_SPACE_TYPE_ALL);
-
        g_object_bind_property (self->priv->draw_spaces_checkbutton, "active",
                                space_drawer, "enable-matrix",
                                G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
diff --git a/testsuite/test-space-drawer.c b/testsuite/test-space-drawer.c
index 8ef1c89..2ba84c7 100644
--- a/testsuite/test-space-drawer.c
+++ b/testsuite/test-space-drawer.c
@@ -165,18 +165,18 @@ test_matrix_getters_setters (void)
        drawer = gtk_source_view_get_space_drawer (view);
 
        /* Default value */
-       matrix[LEADING_INDEX] = 0;
-       matrix[INSIDE_TEXT_INDEX] = 0;
-       matrix[TRAILING_INDEX] = 0;
+       matrix[LEADING_INDEX] = GTK_SOURCE_SPACE_TYPE_ALL;
+       matrix[INSIDE_TEXT_INDEX] = GTK_SOURCE_SPACE_TYPE_ALL;
+       matrix[TRAILING_INDEX] = GTK_SOURCE_SPACE_TYPE_ALL;
        check_equal_matrix (drawer, matrix);
 
        /* Set each location separately */
        set_matrix (drawer, matrix);
 
-       matrix[INSIDE_TEXT_INDEX] = GTK_SOURCE_SPACE_TYPE_NBSP;
+       matrix[INSIDE_TEXT_INDEX] = 0;
        set_matrix (drawer, matrix);
 
-       matrix[TRAILING_INDEX] = GTK_SOURCE_SPACE_TYPE_ALL;
+       matrix[TRAILING_INDEX] = GTK_SOURCE_SPACE_TYPE_NBSP;
        set_matrix (drawer, matrix);
 
        /* Reset to 0 all at once */


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