[meld] preferences/vcdialogs: Move VC commit-message settings to GSettings



commit dbe93512af9de9c0806f028b0806d988194f561f
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sat Nov 23 07:11:22 2013 +1000

    preferences/vcdialogs: Move VC commit-message settings to GSettings

 data/org.gnome.meld.gschema.xml |   17 +++++++++++++++++
 data/ui/preferences.ui          |    3 ---
 meld/preferences.py             |   30 +++++++-----------------------
 meld/ui/vcdialogs.py            |   32 ++++++++++++++++++++++----------
 4 files changed, 46 insertions(+), 36 deletions(-)
---
diff --git a/data/org.gnome.meld.gschema.xml b/data/org.gnome.meld.gschema.xml
index 998412e..57bb8c8 100644
--- a/data/org.gnome.meld.gschema.xml
+++ b/data/org.gnome.meld.gschema.xml
@@ -63,5 +63,22 @@
           <summary>File timestamp resolution</summary>
           <description>When comparing based on mtime, this is the minimum difference in nanoseconds between 
two files before they're considered to have different mtimes. This is useful when comparing files between 
filesystems with different timestamp resolution.</description>
       </key>
+
+      <!-- Version control properties -->
+      <key name="vc-show-commit-margin" type="b">
+          <default>true</default>
+          <summary>Show margin in commit message editor</summary>
+          <description>If true, a guide will be displayed to show what column the margin is at in the 
version control commit message editor.</description>
+      </key>
+      <key name="vc-commit-margin" type="i">
+          <default>72</default>
+          <summary>Margin column in commit message editor</summary>
+          <description>The column of the margin is at in the version control commit message 
editor.</description>
+      </key>
+      <key name="vc-break-commit-message" type="b">
+          <default>false</default>
+          <summary>Automatically hard-wrap commit messages</summary>
+          <description>If true, the version control commit message editor will hard-wrap (i.e., insert line 
breaks) at the defined commit margin before commit.</description>
+      </key>
   </schema>
 </schemalist>
diff --git a/data/ui/preferences.ui b/data/ui/preferences.ui
index 413312a..4760c4b 100644
--- a/data/ui/preferences.ui
+++ b/data/ui/preferences.ui
@@ -1034,7 +1034,6 @@
                                     <property name="use_underline">True</property>
                                     <property name="xalign">0</property>
                                     <property name="draw_indicator">True</property>
-                                    <signal name="toggled" 
handler="on_checkbutton_show_commit_margin_toggled" swapped="no"/>
                                   </object>
                                   <packing>
                                     <property name="expand">False</property>
@@ -1048,7 +1047,6 @@
                                     <property name="can_focus">True</property>
                                     <property name="adjustment">adjustment2</property>
                                     <property name="climb_rate">1</property>
-                                    <signal name="value-changed" 
handler="on_spinbutton_commit_margin_value_changed" swapped="no"/>
                                   </object>
                                   <packing>
                                     <property name="expand">False</property>
@@ -1077,7 +1075,6 @@
                                     <property name="use_underline">True</property>
                                     <property name="xalign">0</property>
                                     <property name="draw_indicator">True</property>
-                                    <signal name="toggled" 
handler="on_checkbutton_break_commit_lines_toggled" swapped="no"/>
                                   </object>
                                 </child>
                               </object>
diff --git a/meld/preferences.py b/meld/preferences.py
index cc782c5..025a8e4 100644
--- a/meld/preferences.py
+++ b/meld/preferences.py
@@ -196,6 +196,13 @@ class PreferencesDialog(gnomeglade.Component):
             ('show-line-numbers', self.checkbutton_show_line_numbers, 'active'),
             ('highlight-syntax', self.checkbutton_use_syntax_highlighting, 'active'),
             ('folder-shallow-comparison', self.checkbutton_shallow_compare, 'active'),
+            ('vc-show-commit-margin', self.checkbutton_show_commit_margin, 'active'),
+            ('vc-commit-margin', self.spinbutton_commit_margin, 'value'),
+            ('vc-break-commit-message', self.checkbutton_break_commit_lines, 'active'),
+            # Sensitivity bindings must come after value bindings, or the key
+            # writability in gsettings overrides manual sensitivity setting.
+            ('vc-show-commit-margin', self.spinbutton_commit_margin, 'sensitive'),
+            ('vc-show-commit-margin', self.checkbutton_break_commit_lines, 'sensitive'),
         ]
         for key, obj, attribute in bindings:
             settings.bind(key, obj, attribute, Gio.SettingsBindFlags.DEFAULT)
@@ -254,14 +261,6 @@ class PreferencesDialog(gnomeglade.Component):
         self.combo_file_order.set_active(
             1 if self.prefs.vc_left_is_local else 0)
 
-        self.checkbutton_show_commit_margin.set_active(
-            self.prefs.vc_show_commit_margin)
-        self.spinbutton_commit_margin.set_value(
-            self.prefs.vc_commit_margin)
-        self.checkbutton_break_commit_lines.set_sensitive(
-            self.prefs.vc_show_commit_margin)
-        self.checkbutton_break_commit_lines.set_active(
-            self.prefs.vc_break_commit_message)
 
         self.widget.show()
 
@@ -299,17 +298,6 @@ class PreferencesDialog(gnomeglade.Component):
         # Called on "activate" and "focus-out-event"
         self.prefs.edit_command_custom = entry.props.text
 
-    def on_checkbutton_show_commit_margin_toggled(self, check):
-        show_margin = check.get_active()
-        self.prefs.vc_show_commit_margin = show_margin
-        self.checkbutton_break_commit_lines.set_sensitive(show_margin)
-
-    def on_spinbutton_commit_margin_value_changed(self, spin):
-        self.prefs.vc_commit_margin = int(spin.get_value())
-
-    def on_checkbutton_break_commit_lines_toggled(self, check):
-        self.prefs.vc_break_commit_message = check.get_active()
-
     #
     # filters
     #
@@ -380,10 +368,6 @@ class MeldPreferences(prefs.Preferences):
                                          ["size 1", "modification time 1",
                                           "permissions 0"]),
 
-        "vc_show_commit_margin": prefs.Value(prefs.BOOL, True),
-        "vc_commit_margin": prefs.Value(prefs.INT, 72),
-        "vc_break_commit_message": prefs.Value(prefs.BOOL, False),
-
         "vc_left_is_local": prefs.Value(prefs.BOOL, False),
     }
 
diff --git a/meld/ui/vcdialogs.py b/meld/ui/vcdialogs.py
index 0790d32..d2303f4 100644
--- a/meld/ui/vcdialogs.py
+++ b/meld/ui/vcdialogs.py
@@ -22,10 +22,13 @@ import os
 import textwrap
 from gettext import gettext as _
 
+from gi.repository import Gio
+from gi.repository import GObject
 from gi.repository import Gtk
 from gi.repository import Pango
 
 from meld.misc import commonprefix
+from meld.settings import settings
 from meld.ui.gnomeglade import Component
 
 
@@ -38,9 +41,14 @@ def _commonprefix(files):
     return workdir
 
 
-class CommitDialog(Component):
+class CommitDialog(GObject.GObject, Component):
+
+    __gtype_name__ = "CommitDialog"
+
+    break_commit_message = GObject.property(type=bool, default=False)
 
     def __init__(self, parent):
+        GObject.GObject.__init__(self)
         Component.__init__(self, "vcview.ui", "commitdialog")
         self.parent = parent
         self.widget.set_transient_for(parent.widget.get_toplevel())
@@ -71,25 +79,29 @@ class CommitDialog(Component):
         # commit message.
         context = self.textview.get_pango_context()
         metrics = context.get_metrics(fontdesc, context.get_language())
-        char_width = metrics.get_approximate_char_width()
-        self.textview.set_size_request(80 * Pango.PIXELS(char_width), -1)
-
+        char_width = metrics.get_approximate_char_width() / Pango.SCALE
+        # FIXME: Apparently broken
+        self.textview.set_size_request(80 * char_width, -1)
+
+        settings.bind('vc-show-commit-margin', self.textview,
+                      'show-right-margin', Gio.SettingsBindFlags.DEFAULT)
+        settings.bind('vc-commit-margin', self.textview,
+                      'right-margin-position', Gio.SettingsBindFlags.DEFAULT)
+        settings.bind('vc-break-commit-message', self,
+                      'break-commit-message', Gio.SettingsBindFlags.DEFAULT)
         self.widget.show_all()
 
     def run(self):
-        prefs = self.parent.prefs
-        margin = prefs.vc_commit_margin
-        self.textview.set_right_margin_position(margin)
-        self.textview.set_show_right_margin(prefs.vc_show_commit_margin)
-
         self.previousentry.set_active(-1)
         self.textview.grab_focus()
         response = self.widget.run()
         if response == Gtk.ResponseType.OK:
+            show_margin = self.textview.get_show_right_margin()
+            margin = self.textview.get_right_margin_position()
             buf = self.textview.get_buffer()
             msg = buf.get_text(*buf.get_bounds(), include_hidden_chars=False)
             # This is a dependent option because of the margin column
-            if prefs.vc_show_commit_margin and prefs.vc_break_commit_message:
+            if show_margin and self.props.break_commit_message:
                 paragraphs = msg.split("\n\n")
                 msg = "\n\n".join(textwrap.fill(p, margin) for p in paragraphs)
             self.parent._command_on_selected(


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