[meld] Make show-whitespace code not break the no-sourceview case



commit 704c65c102fb5f19ff5f24c3097c12c589bb4abe
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Fri Nov 26 08:33:15 2010 +1000

    Make show-whitespace code not break the no-sourceview case

 meld/filediff.py          |    6 +++---
 meld/util/sourceviewer.py |    4 ++++
 2 files changed, 7 insertions(+), 3 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index 7f8220c..d305a3d 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -186,13 +186,13 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
                                  gtk.gdk.CONTROL_MASK)
         gtk.binding_entry_remove(srcviewer.GtkTextView, gtk.keysyms.z,
                                  gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK)
-        spaces_flag = srcviewer.gsv.DRAW_SPACES_ALL if self.prefs.show_whitespace else 0
         for v in self.textview:
             v.set_buffer(srcviewer.GtkTextBuffer())
             v.set_show_line_numbers(self.prefs.show_line_numbers)
             v.set_insert_spaces_instead_of_tabs(self.prefs.spaces_instead_of_tabs)
             v.set_wrap_mode(self.prefs.edit_wrap_lines)
-            v.set_draw_spaces(spaces_flag)
+            if self.prefs.show_whitespace:
+                v.set_draw_spaces(srcviewer.spaces_flag)
             srcviewer.set_tab_width(v, self.prefs.tab_size)
         self.keymask = 0
         self.load_font()
@@ -570,7 +570,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
             for t in self.textview:
                 t.set_show_line_numbers( value )
         elif key == "show_whitespace":
-            spaces_flag = srcviewer.gsv.DRAW_SPACES_ALL if self.prefs.show_whitespace else 0
+            spaces_flag = srcviewer.spaces_flag if value else 0
             for v in self.textview:
                 v.set_draw_spaces(spaces_flag)
         elif key == "use_syntax_highlighting":
diff --git a/meld/util/sourceviewer.py b/meld/util/sourceviewer.py
index d897047..2274f95 100644
--- a/meld/util/sourceviewer.py
+++ b/meld/util/sourceviewer.py
@@ -28,6 +28,8 @@ class _srcviewer(object):
     # instance of the imported sourceviewer module
     gsv = None
 
+    spaces_flag = 0
+
     def __init__(self):
         if self.srcviewer_module is not None:
             self.gsv = __import__(self.srcviewer_module)
@@ -81,6 +83,7 @@ class _gtksourceview2(_srcviewer):
     def overrides(self):
         self.GtkTextView = self.gsv.View
         self.GtkTextBuffer = self.gsv.Buffer
+        self.spaces_flag = self.gsv.DRAW_SPACES_ALL
 
     def GtkLanguageManager(self):
         return self.gsv.LanguageManager()
@@ -182,6 +185,7 @@ class nullsourceview(_srcviewer):
             set_tab_width = lambda *args: None
             set_show_line_numbers = lambda *args: None
             set_insert_spaces_instead_of_tabs = lambda *args: None
+            set_draw_spaces = lambda *args: None
         gobject.type_register(NullTextView)
 
         self.GtkTextView = NullTextView



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