Patch for new feature, show whitespace



I created a patch to allow the user to show whitespace in diff. I
prefer to look at my diffs this way. I have exposed this feature
through the preferences the same what the show line numbers is done.

Let me know what you think.

Jon

diff --git a/data/ui/preferences.glade b/data/ui/preferences.glade
index 63e08f2..a339f05 100644
--- a/data/ui/preferences.glade
+++ b/data/ui/preferences.glade
@@ -283,6 +283,22 @@
                               </packing>
                             </child>
                             <child>
+                              <widget class="GtkCheckButton"
id="checkbutton_show_whitespace">
+                                <property name="label"
translatable="yes">Show w_hitespace</property>
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property
name="receives_default">False</property>
+                                <property name="use_underline">True</property>
+                                <property name="draw_indicator">True</property>
+                                <signal name="toggled"
handler="on_checkbutton_show_whitespace_toggled"/>
+                              </widget>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">False</property>
+                                <property name="position">6</property>
+                              </packing>
+                            </child>
+                            <child>
                               <widget class="GtkCheckButton"
id="checkbutton_use_syntax_highlighting">
                                 <property name="label"
translatable="yes">Use s_yntax highlighting</property>
                                 <property name="visible">True</property>
@@ -295,7 +311,7 @@
                               <packing>
                                 <property name="expand">False</property>
                                 <property name="fill">False</property>
-                                <property name="position">6</property>
+                                <property name="position">7</property>
                               </packing>
                             </child>
                           </widget>
diff --git a/meld/filediff.py b/meld/filediff.py
index b53437a..fd181bc 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -124,11 +124,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)
             srcviewer.set_tab_width(v, self.prefs.tab_size)
         self.keymask = 0
         self.load_font()
@@ -481,6 +483,10 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         elif key == "show_line_numbers":
             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
+            for v in self.textview:
+                v.set_draw_spaces(spaces_flag)
         elif key == "use_syntax_highlighting":
             for i in range(self.num_panes):
                 srcviewer.set_highlighting_enabled_from_file(
diff --git a/meld/preferences.py b/meld/preferences.py
index bc32feb..0c2605b 100644
--- a/meld/preferences.py
+++ b/meld/preferences.py
@@ -134,15 +134,18 @@ class PreferencesDialog(gnomeglade.Component):
         if srcviewer:
             self.checkbutton_spaces_instead_of_tabs.set_active(
self.prefs.spaces_instead_of_tabs )
             self.checkbutton_show_line_numbers.set_active(
self.prefs.show_line_numbers )
+            self.checkbutton_show_whitespace.set_active(self.prefs.show_whitespace)
             self.checkbutton_use_syntax_highlighting.set_active(
self.prefs.use_syntax_highlighting )
         else:
             self.checkbutton_spaces_instead_of_tabs.set_sensitive(False)
             self.checkbutton_show_line_numbers.set_sensitive(False)
+            self.checkbutton_show_whitespace.set_sensitive(False)
             self.checkbutton_use_syntax_highlighting.set_sensitive(False)
             if gtk.pygtk_version >= (2, 12, 0):
                 no_sourceview_text = _("Only available if you have
gnome-python-desktop installed")

self.checkbutton_spaces_instead_of_tabs.set_tooltip_text(no_sourceview_text)

self.checkbutton_show_line_numbers.set_tooltip_text(no_sourceview_text)
+
self.checkbutton_show_whitespace.set_tooltip_text(no_sourceview_text)

self.checkbutton_use_syntax_highlighting.set_tooltip_text(no_sourceview_text)
         # TODO: This doesn't restore the state of character wrapping when word
         # wrapping is disabled, but this is hard with our existing gconf keys
@@ -205,6 +208,8 @@ class PreferencesDialog(gnomeglade.Component):
         self.prefs.supply_newline = check.get_active()
     def on_checkbutton_show_line_numbers_toggled(self, check):
         self.prefs.show_line_numbers = check.get_active()
+    def on_checkbutton_show_whitespace_toggled(self, check):
+        self.prefs.show_whitespace = check.get_active()
     def on_checkbutton_use_syntax_highlighting_toggled(self, check):
         self.prefs.use_syntax_highlighting = check.get_active()

@@ -245,6 +250,7 @@ class MeldPreferences(prefs.Preferences):
         "tab_size": prefs.Value(prefs.INT, 4),
         "spaces_instead_of_tabs": prefs.Value(prefs.BOOL, False),
         "show_line_numbers": prefs.Value(prefs.BOOL, 0),
+        "show_whitespace": prefs.Value(prefs.BOOL, False),
         "use_syntax_highlighting": prefs.Value(prefs.BOOL, 0),
         "edit_wrap_lines" : prefs.Value(prefs.INT, 0),
         "edit_command_type" : prefs.Value(prefs.STRING, "gnome"),
#gnome, custom


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