[gedit-plugins/wip/port-drawspaces] drawspaces: port to the GtkSourceSpaceDrawer:matrix property



commit 2e54e579a9bef05fe1b642935f477fb76510763b
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Oct 5 17:20:47 2016 +0200

    drawspaces: port to the GtkSourceSpaceDrawer:matrix property

 configure.ac                                       |    2 +-
 plugins/drawspaces/drawspaces.plugin.desktop.in.in |    4 +-
 .../drawspaces/gedit-drawspaces-app-activatable.c  |   36 ++++++++++++++++++--
 .../drawspaces/gedit-drawspaces-view-activatable.h |    4 +-
 ...nome.gedit.plugins.drawspaces.gschema.xml.in.in |   18 ++--------
 5 files changed, 42 insertions(+), 22 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index db9353d..2eb83dc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -57,7 +57,7 @@ PKG_CHECK_MODULES(GEDIT, [
        glib-2.0 >= 2.32.0
        gio-2.0 >= 2.32.0
        gtk+-3.0 >= 3.9.0
-       gtksourceview-3.0 >= 3.21.3
+       gtksourceview-3.0 >= 3.23.1
        libpeas-1.0 >= 1.7.0
        libpeas-gtk-1.0 >= 1.7.0
        gedit >= 3.16.0
diff --git a/plugins/drawspaces/drawspaces.plugin.desktop.in.in 
b/plugins/drawspaces/drawspaces.plugin.desktop.in.in
index adf6fca..f3ffe2b 100644
--- a/plugins/drawspaces/drawspaces.plugin.desktop.in.in
+++ b/plugins/drawspaces/drawspaces.plugin.desktop.in.in
@@ -3,7 +3,7 @@ Module=drawspaces
 IAge=3
 _Name=Draw Spaces
 _Description=Draw spaces and tabs
-Authors=Paolo Borelli <pborelli katamail com>;Steve Frécinaux <code istique net>;Ignacio Casal Quinteiro 
<nacho resa gmail com>
-Copyright=Copyright © 2006 Paolo Borelli;Copyright © 2007 Steve Frécinaux;Copyright © 2008 Ignacio Casal 
Quinteiro
+Authors=Paolo Borelli <pborelli katamail com>;Steve Frécinaux <code istique net>;Ignacio Casal Quinteiro 
<nacho resa gmail com>;Sébastien Wilmet <swilmet gnome org>
+Copyright=Copyright © 2006 Paolo Borelli;Copyright © 2007 Steve Frécinaux;Copyright © 2008 Ignacio Casal 
Quinteiro;Copyright © 2016 Sébastien Wilmet
 Website=http://www.gedit.org
 Version=@VERSION@
diff --git a/plugins/drawspaces/gedit-drawspaces-app-activatable.c 
b/plugins/drawspaces/gedit-drawspaces-app-activatable.c
index 0cbe326..d8ed277 100644
--- a/plugins/drawspaces/gedit-drawspaces-app-activatable.c
+++ b/plugins/drawspaces/gedit-drawspaces-app-activatable.c
@@ -28,6 +28,7 @@
 #include <gedit/gedit-app-activatable.h>
 #include <gedit/gedit-debug.h>
 #include <gio/gio.h>
+#include <gtksourceview/gtksource.h>
 #include <glib/gi18n-lib.h>
 #include <libpeas-gtk/peas-gtk-configurable.h>
 
@@ -42,7 +43,7 @@ typedef struct _DrawspacesConfigureWidget DrawspacesConfigureWidget;
 struct _DrawspacesConfigureWidget
 {
        GSettings *settings;
-       GtkSourceDrawSpacesFlags flags;
+       GtkSourceSpaceDrawer *space_drawer;
 
        GtkWidget *content;
 
@@ -251,11 +252,29 @@ on_draw_trailing_toggled (GtkToggleButton           *button,
        set_flag (widget, GTK_SOURCE_DRAW_SPACES_TRAILING, gtk_toggle_button_get_active (button));
 }
 
+static gboolean
+matrix_get_mapping (GValue   *value,
+                   GVariant *variant,
+                   gpointer  user_data)
+{
+       g_value_set_variant (value, variant);
+       return TRUE;
+}
+
+static GVariant *
+matrix_set_mapping (const GValue       *value,
+                   const GVariantType *expected_type,
+                   gpointer            user_data)
+{
+       return g_value_dup_variant (value);
+}
+
 static DrawspacesConfigureWidget *
 get_configuration_widget (GeditDrawspacesAppActivatable *activatable)
 {
        DrawspacesConfigureWidget *widget = NULL;
        GtkBuilder *builder;
+       GVariant *matrix;
 
        gchar *root_objects[] = {
                "content",
@@ -264,8 +283,19 @@ get_configuration_widget (GeditDrawspacesAppActivatable *activatable)
 
        widget = g_slice_new (DrawspacesConfigureWidget);
        widget->settings = g_settings_new (DRAWSPACES_SETTINGS_BASE);
-       widget->flags = g_settings_get_flags (widget->settings,
-                                             SETTINGS_KEY_DRAW_SPACES);
+       widget->space_drawer = gtk_source_space_drawer_new ();
+
+       matrix = g_settings_get_value (widget->settings, SETTINGS_KEY_MATRIX);
+       gtk_source_space_drawer_set_matrix (widget->space_drawer, matrix);
+       g_variant_unref (matrix);
+
+       g_settings_bind_with_mapping (widget->settings, SETTINGS_KEY_MATRIX,
+                                     widget->space_drawer, "matrix",
+                                     G_SETTINGS_BIND_DEFAULT,
+                                     matrix_get_mapping,
+                                     matrix_set_mapping,
+                                     NULL,
+                                     NULL);
 
        builder = gtk_builder_new ();
        gtk_builder_set_translation_domain (builder, GETTEXT_PACKAGE);
diff --git a/plugins/drawspaces/gedit-drawspaces-view-activatable.h 
b/plugins/drawspaces/gedit-drawspaces-view-activatable.h
index 4968369..fda58b1 100644
--- a/plugins/drawspaces/gedit-drawspaces-view-activatable.h
+++ b/plugins/drawspaces/gedit-drawspaces-view-activatable.h
@@ -33,9 +33,9 @@ G_BEGIN_DECLS
 #define GEDIT_IS_DRAWSPACES_VIEW_ACTIVATABLE_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GEDIT_TYPE_DRAWSPACES_VIEW_ACTIVATABLE))
 #define GEDIT_DRAWSPACES_VIEW_ACTIVATABLE_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GEDIT_TYPE_DRAWSPACES_VIEW_ACTIVATABLE, GeditDrawspacesViewActivatableClass))
 
-#define DRAWSPACES_SETTINGS_BASE   "org.gnome.gedit.plugins.drawspaces"
+#define DRAWSPACES_SETTINGS_BASE "org.gnome.gedit.plugins.drawspaces"
 #define SETTINGS_KEY_SHOW_WHITE_SPACE "show-white-space"
-#define SETTINGS_KEY_DRAW_SPACES   "draw-spaces"
+#define SETTINGS_KEY_MATRIX "matrix"
 
 typedef struct _GeditDrawspacesViewActivatable         GeditDrawspacesViewActivatable;
 typedef struct _GeditDrawspacesViewActivatableClass    GeditDrawspacesViewActivatableClass;
diff --git a/plugins/drawspaces/org.gnome.gedit.plugins.drawspaces.gschema.xml.in.in 
b/plugins/drawspaces/org.gnome.gedit.plugins.drawspaces.gschema.xml.in.in
index ca0d061..ba9b5ef 100644
--- a/plugins/drawspaces/org.gnome.gedit.plugins.drawspaces.gschema.xml.in.in
+++ b/plugins/drawspaces/org.gnome.gedit.plugins.drawspaces.gschema.xml.in.in
@@ -1,24 +1,14 @@
 <schemalist>
-  <flags id='org.gnome.gedit.plugins.drawspaces.GtkSourceDrawSpacesFlags'>
-    <value nick='space' value='1'/>
-    <value nick='tab' value='2'/>
-    <value nick='newline' value='4'/>
-    <value nick='nbsp' value='8'/>
-    <value nick='leading' value='16'/>
-    <value nick='text' value='32'/>
-    <value nick='trailing' value='64'/>
-  </flags>
-
   <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.gedit.plugins.drawspaces" 
path="/org/gnome/gedit/plugins/drawspaces/">
     <key name="show-white-space" type="b">
       <default>true</default>
       <_summary>Show _White Space</_summary>
       <_description>If TRUE drawing will be enabled.</_description>
     </key>
-    <key name="draw-spaces" flags="org.gnome.gedit.plugins.drawspaces.GtkSourceDrawSpacesFlags">
-      <default>['space', 'tab', 'leading', 'text', 'trailing']</default>
-      <_summary>Draw Spaces</_summary>
-      <_description>The type of spaces to be drawn.</_description>
+    <key name="matrix" type="au">
+      <default>[11, 11, 11]</default>
+      <_summary>Matrix</_summary>
+      <_description>Where and what kind of white spaces to draw.</_description>
     </key>
   </schema>
 </schemalist>


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