[meld] settings: Add bind_settings helper for attribute-specified properties
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] settings: Add bind_settings helper for attribute-specified properties
- Date: Sat, 26 Apr 2014 23:44:57 +0000 (UTC)
commit d78eef064c86cc7238f9753d62e7c97e9a866c48
Author: Kai Willadsen <kai willadsen gmail com>
Date: Wed Jan 1 11:31:20 2014 +1000
settings: Add bind_settings helper for attribute-specified properties
The idea here is to have settings bindings specified next to the
GObject attributes that they're often associated with. This commit
adds the helper, and moves all of the major uses of gsettings binding
to it.
meld/dirdiff.py | 22 ++++++++++------------
meld/filediff.py | 32 ++++++++------------------------
meld/meldbuffer.py | 6 ++++++
meld/settings.py | 8 ++++++++
meld/sourceview.py | 11 +++++++++++
meld/vcview.py | 15 ++++++++-------
6 files changed, 51 insertions(+), 43 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index 97a6b06..90f6e59 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -42,7 +42,7 @@ from collections import namedtuple
from decimal import Decimal
from meld.conf import _
-from meld.settings import meldsettings, settings
+from meld.settings import bind_settings, meldsettings, settings
################################################################################
@@ -248,6 +248,14 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
__gtype_name__ = "DirDiff"
+ __gsettings_bindings__ = (
+ ('folder-ignore-symlinks', 'ignore-symlinks'),
+ ('folder-shallow-comparison', 'shallow-comparison'),
+ ('folder-time-resolution', 'time-resolution'),
+ ('folder-status-filters', 'status-filters'),
+ ('ignore-blank-lines', 'ignore-blank-lines'),
+ )
+
ignore_blank_lines = GObject.property(
type=bool,
nick="Ignore blank lines",
@@ -302,6 +310,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
melddoc.MeldDoc.__init__(self)
gnomeglade.Component.__init__(self, "dirdiff.ui", "dirdiff",
["DirdiffActions"])
+ bind_settings(self)
self.ui_file = gnomeglade.ui_file("dirdiff-ui.xml")
self.actiongroup = self.DirdiffActions
@@ -408,17 +417,6 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
settings.connect('changed::folder-columns',
self.update_treeview_columns)
- settings.bind('folder-ignore-symlinks', self, 'ignore-symlinks',
- Gio.SettingsBindFlags.DEFAULT)
- settings.bind('folder-shallow-comparison', self, 'shallow-comparison',
- Gio.SettingsBindFlags.DEFAULT)
- settings.bind('folder-time-resolution', self, 'time-resolution',
- Gio.SettingsBindFlags.DEFAULT)
- settings.bind('folder-status-filters', self, 'status-filters',
- Gio.SettingsBindFlags.DEFAULT)
- settings.bind('ignore-blank-lines', self, 'ignore-blank-lines',
- Gio.SettingsBindFlags.DEFAULT)
-
self.update_comparator()
self.connect("notify::shallow-comparison", self.update_comparator)
self.connect("notify::time-resolution", self.update_comparator)
diff --git a/meld/filediff.py b/meld/filediff.py
index 195f241..1dee2d6 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -46,7 +46,7 @@ from .ui import findbar
from .ui import gnomeglade
from meld.const import MODE_REPLACE, MODE_DELETE, MODE_INSERT
-from meld.settings import meldsettings, settings
+from meld.settings import bind_settings, meldsettings, settings
from .util.compat import text_type
from meld.sourceview import LanguageManager
@@ -141,6 +141,11 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
__gtype_name__ = "FileDiff"
+ __gsettings_bindings__ = (
+ ('highlight-current-line', 'highlight-current-line'),
+ ('ignore-blank-lines', 'ignore-blank-lines'),
+ )
+
highlight_current_line = GObject.property(type=bool, default=False)
ignore_blank_lines = GObject.property(
type=bool,
@@ -171,6 +176,8 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
"""
melddoc.MeldDoc.__init__(self)
gnomeglade.Component.__init__(self, "filediff.ui", "filediff")
+ bind_settings(self)
+
widget_lists = [
"diffmap", "file_save_button", "file_toolbar", "fileentry",
"linkmap", "msgarea_mgr", "readonlytoggle",
@@ -362,29 +369,6 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
gutter = t.get_gutter(window)
gutter.insert(renderer, 10)
- # GSettings bindings
- for view in self.textview:
- settings.bind('indent-width', view, 'indent-width',
- Gio.SettingsBindFlags.DEFAULT)
- settings.bind('insert-spaces-instead-of-tabs', view,
- 'insert-spaces-instead-of-tabs',
- Gio.SettingsBindFlags.DEFAULT)
- settings.bind('show-line-numbers', view, 'show-line-numbers',
- 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)
-
- settings.bind('highlight-current-line', self, 'highlight-current-line',
- Gio.SettingsBindFlags.DEFAULT)
- settings.bind('ignore-blank-lines', self, 'ignore-blank-lines',
- Gio.SettingsBindFlags.DEFAULT)
-
self.connect("notify::ignore-blank-lines", self.refresh_comparison)
meldsettings.connect('changed', self.on_setting_changed)
diff --git a/meld/meldbuffer.py b/meld/meldbuffer.py
index 119ac8a..1ba2bb2 100644
--- a/meld/meldbuffer.py
+++ b/meld/meldbuffer.py
@@ -24,6 +24,7 @@ from gi.repository import GObject
from gi.repository import GtkSource
from meld.conf import _
+from meld.settings import bind_settings
from meld.util.compat import text_type
@@ -31,8 +32,13 @@ class MeldBuffer(GtkSource.Buffer):
__gtype_name__ = "MeldBuffer"
+ __gsettings_bindings__ = (
+ ('highlight-syntax', 'highlight-syntax'),
+ )
+
def __init__(self, filename=None):
GtkSource.Buffer.__init__(self)
+ bind_settings(self)
self.data = MeldBufferData(filename)
self.user_action_count = 0
diff --git a/meld/settings.py b/meld/settings.py
index 7498212..8cff34e 100644
--- a/meld/settings.py
+++ b/meld/settings.py
@@ -107,6 +107,14 @@ def create_settings(uninstalled=False):
meldsettings = MeldSettings()
+def bind_settings(obj):
+ global settings
+ for binding in getattr(obj, '__gsettings_bindings__', ()):
+ settings_id, property_id = binding
+ settings.bind(
+ settings_id, obj, property_id, Gio.SettingsBindFlags.DEFAULT)
+
+
settings = None
interface_settings = None
meldsettings = None
diff --git a/meld/sourceview.py b/meld/sourceview.py
index 1985a74..6a1daeb 100644
--- a/meld/sourceview.py
+++ b/meld/sourceview.py
@@ -20,6 +20,8 @@ from gi.repository import GLib
from gi.repository import Gtk
from gi.repository import GtkSource
+from meld.settings import bind_settings
+
class LanguageManager(object):
@@ -46,6 +48,14 @@ class MeldSourceView(GtkSource.View):
__gtype_name__ = "MeldSourceView"
+ __gsettings_bindings__ = (
+ ('indent-width', 'indent-width'),
+ ('insert-spaces-instead-of-tabs', 'insert-spaces-instead-of-tabs'),
+ ('show-line-numbers', 'show-line-numbers'),
+ ('draw-spaces', 'draw-spaces'),
+ ('wrap-mode', 'wrap-mode'),
+ )
+
replaced_entries = (
# We replace the default GtkSourceView undo mechanism
(Gdk.KEY_z, Gdk.ModifierType.CONTROL_MASK),
@@ -61,6 +71,7 @@ class MeldSourceView(GtkSource.View):
def __init__(self, *args, **kwargs):
super(MeldSourceView, self).__init__(*args, **kwargs)
+ bind_settings(self)
binding_set = Gtk.binding_set_find('GtkSourceView')
for key, modifiers in self.replaced_entries:
diff --git a/meld/vcview.py b/meld/vcview.py
index 924d7f1..1269b6b 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -43,7 +43,7 @@ from .ui import gnomeglade
from .ui import vcdialogs
from meld.conf import _
-from meld.settings import settings
+from meld.settings import settings, bind_settings
from meld.vc import _null
log = logging.getLogger(__name__)
@@ -139,6 +139,12 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
__gtype_name__ = "VcView"
+ __gsettings_bindings__ = (
+ ('vc-status-filters', 'status-filters'),
+ ('vc-left-is-local', 'left-is-local'),
+ ('vc-merge-file-order', 'merge-file-order'),
+ )
+
status_filters = GObject.property(
type=GObject.TYPE_STRV,
nick="File status filters",
@@ -175,6 +181,7 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
melddoc.MeldDoc.__init__(self)
gnomeglade.Component.__init__(self, "vcview.ui", "vcview",
["VcviewActions", 'liststore_vcs'])
+ bind_settings(self)
self.ui_file = gnomeglade.ui_file("vcview-ui.xml")
self.actiongroup = self.VcviewActions
@@ -240,12 +247,6 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
self.combobox_vcs.add_attribute(cell, 'sensitive', 2)
self.combobox_vcs.lock = False
- settings.bind('vc-status-filters', self, 'status-filters',
- Gio.SettingsBindFlags.DEFAULT)
- settings.bind('vc-left-is-local', self, 'left-is-local',
- Gio.SettingsBindFlags.DEFAULT)
- settings.bind('vc-merge-file-order', self, 'merge-file-order',
- Gio.SettingsBindFlags.DEFAULT)
settings.bind('vc-console-visible',
self.actiongroup.get_action('VcConsoleVisible'),
'active', Gio.SettingsBindFlags.DEFAULT)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]