[meld] preferences: Update word wrapping setting to use GSettings



commit 913fe0bb80dac399b868302c687e29b187d6c2b4
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Wed Dec 4 07:06:06 2013 +1000

    preferences: Update word wrapping setting to use GSettings

 data/org.gnome.meld.gschema.xml |   19 ++++++++++++++++++-
 data/ui/preferences.ui          |    2 +-
 meld/filediff.py                |   14 +++-----------
 meld/preferences.py             |   27 +++++++++++++--------------
 4 files changed, 35 insertions(+), 27 deletions(-)
---
diff --git a/data/org.gnome.meld.gschema.xml b/data/org.gnome.meld.gschema.xml
index 4a5f5ec..b933d0a 100644
--- a/data/org.gnome.meld.gschema.xml
+++ b/data/org.gnome.meld.gschema.xml
@@ -1,6 +1,13 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <schemalist>
 
+  <enum id="org.gnome.meld.wrapmode">
+    <value nick="none" value="0"/>
+    <value nick="char" value="1"/>
+    <value nick="word" value="2"/>
+    <value nick="word-char" value="3"/>
+  </enum>
+
   <flags id="org.gnome.meld.spacesflags">
     <value nick="space" value="1"/>
     <value nick="tab" value="2"/>
@@ -33,7 +40,7 @@
       </key>
 
 
-      <!-- Settings corresponding directly to GtkSourceView properties -->
+      <!-- Settings corresponding directly to GtkTextView/GtkSourceView properties -->
       <key name="indent-width" type="i">
           <default>8</default>
           <summary>Width of an indentation step</summary>
@@ -59,6 +66,16 @@
           <summary>Displayed whitespace</summary>
           <description>Selector for individual whitespace character types to be shown. Possible values are 
'space', 'tab', 'newline' and 'nbsp'.</description>
       </key>
+      <key name="wrap-mode" enum='org.gnome.meld.wrapmode'>
+          <aliases>
+            <alias value='GTK_WRAP_NONE' target='none'/>
+            <alias value='GTK_WRAP_CHAR' target='char'/>
+            <alias value='GTK_WRAP_WORD' target='word'/>
+          </aliases>
+          <default>'none'</default>
+          <summary>Wrap mode</summary>
+          <description>Lines in file comparisons will be wrapped according to this setting, either not at 
all ('none'), at any character ('char') or only at the end of words ('word').</description>
+      </key>
 
 
       <!-- Non-GtkSourceView editor properties -->
diff --git a/data/ui/preferences.ui b/data/ui/preferences.ui
index 249c238..3851a13 100644
--- a/data/ui/preferences.ui
+++ b/data/ui/preferences.ui
@@ -343,7 +343,7 @@
                                 <property name="can_focus">False</property>
                                 <property name="left_padding">18</property>
                                 <child>
-                                  <object class="GtkCheckButton" id="checkbutton_split_words">
+                                  <object class="GtkCheckButton" id="checkbutton_wrap_word">
                                     <property name="label" translatable="yes">Do not _split words over two 
lines</property>
                                     <property name="visible">True</property>
                                     <property name="sensitive">False</property>
diff --git a/meld/filediff.py b/meld/filediff.py
index 7267b5b..66770ba 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -188,7 +188,6 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
                         self.on_textbuffer_begin_user_action)
             buf.connect('end_user_action', self.on_textbuffer_end_user_action)
             v.set_buffer(buf)
-            v.set_wrap_mode(self.prefs.edit_wrap_lines)
             buf.data.connect('file-changed', self.notify_file_changed)
         self._keymask = 0
         self.load_font()
@@ -362,6 +361,9 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
                           Gio.SettingsBindFlags.DEFAULT)
             settings.bind('draw-spaces', view, 'draw-spaces',
                           Gio.SettingsBindFlags.DEFAULT)
+            settings.bind('wrap-mode', view, 'wrap-mode',
+                          Gio.SettingsBindFlags.DEFAULT)
+
         for buf in self.textbuffer:
             settings.bind('highlight-syntax', buf, 'highlight-syntax',
                           Gio.SettingsBindFlags.DEFAULT)
@@ -839,16 +841,6 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         if key == 'font':
             self.load_font()
 
-    def on_preference_changed(self, key, value):
-        if key == "edit_wrap_lines":
-            for t in self.textview:
-                t.set_wrap_mode(self.prefs.edit_wrap_lines)
-            # FIXME: On changing wrap mode, we get one redraw using cached
-            # coordinates, followed by a second redraw (e.g., on refocus) with
-            # correct coordinates. Overly-aggressive textview lazy calculation?
-            self.diffmap0.queue_draw()
-            self.diffmap1.queue_draw()
-
     def on_key_press_event(self, object, event):
         keymap = Gdk.Keymap.get_default()
         ok, keyval, group, lvl, consumed = keymap.translate_keyboard_state(
diff --git a/meld/preferences.py b/meld/preferences.py
index 5daa29d..2297b4a 100644
--- a/meld/preferences.py
+++ b/meld/preferences.py
@@ -202,15 +202,17 @@ class PreferencesDialog(gnomeglade.Component):
             'use-system-font', self.fontpicker, 'sensitive',
             Gio.SettingsBindFlags.DEFAULT | Gio.SettingsBindFlags.INVERT_BOOLEAN)
 
+        self.checkbutton_wrap_text.bind_property(
+            'active', self.checkbutton_wrap_word, 'sensitive',
+            GObject.BindingFlags.DEFAULT)
+
         # TODO: Fix once bind_with_mapping is available
         self.checkbutton_show_whitespace.set_active(
             bool(settings.get_flags('draw-spaces')))
-        # TODO: This doesn't restore the state of character wrapping when word
-        # wrapping is disabled, but this is hard with our existing gconf keys
-        if self.prefs.edit_wrap_lines != Gtk.WrapMode.NONE:
-            if self.prefs.edit_wrap_lines == Gtk.WrapMode.CHAR:
-                self.checkbutton_split_words.set_active(False)
-            self.checkbutton_wrap_text.set_active(True)
+
+        wrap_mode = settings.get_enum('wrap-mode')
+        self.checkbutton_wrap_text.set_active(wrap_mode != Gtk.WrapMode.NONE)
+        self.checkbutton_wrap_word.set_active(wrap_mode == Gtk.WrapMode.WORD)
 
         # file filters
         self.filefilter = FilterList("filename-filters", filters.FilterEntry.SHELL)
@@ -241,14 +243,12 @@ class PreferencesDialog(gnomeglade.Component):
 
     def on_checkbutton_wrap_text_toggled(self, button):
         if not self.checkbutton_wrap_text.get_active():
-            self.prefs.edit_wrap_lines = 0
-            self.checkbutton_split_words.set_sensitive(False)
+            wrap_mode = Gtk.WrapMode.NONE
+        elif self.checkbutton_wrap_word.get_active():
+            wrap_mode = Gtk.WrapMode.WORD
         else:
-            self.checkbutton_split_words.set_sensitive(True)
-            if self.checkbutton_split_words.get_active():
-                self.prefs.edit_wrap_lines = 2
-            else:
-                self.prefs.edit_wrap_lines = 1
+            wrap_mode = Gtk.WrapMode.CHAR
+        settings.set_enum('wrap-mode', wrap_mode)
 
     def on_checkbutton_show_whitespace_toggled(self, widget):
         value = GtkSource.DrawSpacesFlags.ALL if widget.get_active() else 0
@@ -266,7 +266,6 @@ class MeldPreferences(prefs.Preferences):
     defaults = {
         "window_size_x": prefs.Value(prefs.INT, 600),
         "window_size_y": prefs.Value(prefs.INT, 600),
-        "edit_wrap_lines" : prefs.Value(prefs.INT, 0),
         "vc_console_visible": prefs.Value(prefs.BOOL, 0),
         "vc_left_is_local": prefs.Value(prefs.BOOL, False),
     }


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