[meld] sourceview: Support toggling whitespace drawing from statusbar (#119)



commit 949652b0ec376850f75104c4208f394658c52aa8
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sat Jan 19 07:24:17 2019 +1000

    sourceview: Support toggling whitespace drawing from statusbar (#119)

 meld/filediff.py                    |  1 +
 meld/resources/ui/statusbar-menu.ui |  4 ++++
 meld/sourceview.py                  | 24 ++++++++++++++++++++++++
 3 files changed, 29 insertions(+)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index 649bea06..b178c302 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -239,6 +239,7 @@ class FileDiff(Gtk.VBox, MeldDoc):
 
         # Set up property actions for statusbar toggles
         sourceview_prop_actions = [
+            'draw-spaces-bool',
             'highlight-current-line-local',
             'show-line-numbers',
             'wrap-mode-bool',
diff --git a/meld/resources/ui/statusbar-menu.ui b/meld/resources/ui/statusbar-menu.ui
index 8f16c77a..a5da4f8f 100644
--- a/meld/resources/ui/statusbar-menu.ui
+++ b/meld/resources/ui/statusbar-menu.ui
@@ -5,6 +5,10 @@
       <attribute name="label">Display line numbers</attribute>
       <attribute name="action">show-line-numbers</attribute>
     </item>
+    <item>
+      <attribute name="label">Show whitespace</attribute>
+      <attribute name="action">draw-spaces-bool</attribute>
+    </item>
     <item>
       <attribute name="label">Highlight current line</attribute>
       <attribute name="action">highlight-current-line-local</attribute>
diff --git a/meld/sourceview.py b/meld/sourceview.py
index 948b6ce4..e4fc6740 100644
--- a/meld/sourceview.py
+++ b/meld/sourceview.py
@@ -132,6 +132,15 @@ class MeldSourceView(GtkSource.View):
         ),
     )
 
+    draw_spaces_bool = GObject.Property(
+        type=bool, default=False,
+        nick="Draw spaces (Boolean version)",
+        blurb=(
+            "Mirror of the draw-spaces GtkSourceView property, "
+            "reduced to a single Boolean for UI ease-of-use."
+        ),
+    )
+
     replaced_entries = (
         # We replace the default GtkSourceView undo mechanism
         (Gdk.KEY_z, Gdk.ModifierType.CONTROL_MASK),
@@ -260,6 +269,21 @@ class MeldSourceView(GtkSource.View):
         )
         self.wrap_mode_bool = wrap_mode_to_bool(None, self.props.wrap_mode)
 
+        def draw_spaces_from_bool(binding, from_value):
+            return GtkSource.DrawSpacesFlags.ALL if from_value else 0
+
+        def draw_spaces_to_bool(binding, from_value):
+            return bool(from_value)
+
+        self.bind_property(
+            'draw-spaces-bool', self, 'draw-spaces',
+            GObject.BindingFlags.BIDIRECTIONAL,
+            draw_spaces_from_bool,
+            draw_spaces_to_bool,
+        )
+        self.draw_spaces_bool = draw_spaces_to_bool(
+            None, self.props.draw_spaces)
+
         self.on_setting_changed(meldsettings, 'font')
         self.on_setting_changed(meldsettings, 'style-scheme')
         return GtkSource.View.do_realize(self)


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