Commit d78eef06 authored by Kai Willadsen's avatar Kai Willadsen

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.
parent 6d38d8c4
......@@ -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)
......
......@@ -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)
......
......@@ -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
......
......@@ -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
......@@ -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:
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment