[meld] filediff/preferences: Port several editor preferences to GSettings
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] filediff/preferences: Port several editor preferences to GSettings
- Date: Sat, 23 Nov 2013 02:56:01 +0000 (UTC)
commit 74a105ff41f3b59004fbe14a9db4cc535b386559
Author: Kai Willadsen <kai willadsen gmail com>
Date: Wed Oct 9 05:12:27 2013 +1000
filediff/preferences: Port several editor preferences to GSettings
data/org.gnome.meld.gschema.xml | 49 +++++++++++++++++++++++++++++++++++++++
data/ui/preferences.ui | 5 ----
meld/filediff.py | 44 ++++++++++++++++++----------------
meld/preferences.py | 44 ++++++++++++----------------------
meld/settings.py | 28 ++++++++++++++++++++++
5 files changed, 116 insertions(+), 54 deletions(-)
---
diff --git a/data/org.gnome.meld.gschema.xml b/data/org.gnome.meld.gschema.xml
new file mode 100644
index 0000000..6e86c87
--- /dev/null
+++ b/data/org.gnome.meld.gschema.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schemalist>
+
+ <flags id="org.gnome.meld.spacesflags">
+ <value nick="space" value="1"/>
+ <value nick="tab" value="2"/>
+ <value nick="newline" value="4"/>
+ <value nick="nbsp" value="8"/>
+ </flags>
+
+ <schema id="org.gnome.meld" path="/org/gnome/meld/">
+ <!-- Settings corresponding directly to GtkSourceView properties -->
+ <key name="indent-width" type="i">
+ <default>8</default>
+ <summary>Width of an indentation step</summary>
+ <description>The number of spaces to use for a single indent step</description>
+ </key>
+ <key name="insert-spaces-instead-of-tabs" type="b">
+ <default>false</default>
+ <summary>Whether to indent using spaces or tabs</summary>
+ <description>If true, any new indentation will use spaces instead of tabs.</description>
+ </key>
+ <key name="show-line-numbers" type="b">
+ <default>false</default>
+ <summary>Show line numbers</summary>
+ <description>If true, line numbers will be shown in the gutter of file comparisons.</description>
+ </key>
+ <key name="highlight-syntax" type='b'>
+ <default>false</default>
+ <summary>Highlight syntax</summary>
+ <description>Whether to highlight syntax in comparisons. Because of Meld's own color highlighting,
this is off by default.</description>
+ </key>
+
+
+ <key name="show-whitespace" flags='org.gnome.meld.spacesflags'>
+ <default>["space", "tab"]</default>
+ <summary>Displayed whitespace</summary>
+ <description>Selector for individual whitespace character types to be shown. Possible values are
'space', 'tab', 'newline' and 'nbsp'.</description>
+ </key>
+
+
+ <!-- Non-GtkSourceView editor properties -->
+ <key name="highlight-current-line" type="b">
+ <default>false</default>
+ <summary>Highlight current line</summary>
+ <description>If true, the line containing the cursor will be highlighted in file
comparisons.</description>
+ </key>
+ </schema>
+</schemalist>
diff --git a/data/ui/preferences.ui b/data/ui/preferences.ui
index 83f8131..7cd9d8b 100644
--- a/data/ui/preferences.ui
+++ b/data/ui/preferences.ui
@@ -292,7 +292,6 @@
<property name="can_focus">True</property>
<property name="adjustment">adjustment1</property>
<property name="climb_rate">1</property>
- <signal name="value-changed" handler="on_spinbutton_tabsize_changed"
swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
@@ -316,7 +315,6 @@
<property name="use_underline">True</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
- <signal name="toggled"
handler="on_checkbutton_spaces_instead_of_tabs_toggled" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
@@ -376,7 +374,6 @@
<property name="use_underline">True</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
- <signal name="toggled"
handler="on_checkbutton_highlight_current_line_toggled" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
@@ -393,7 +390,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_line_numbers_toggled"
swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
@@ -427,7 +423,6 @@
<property name="use_underline">True</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
- <signal name="toggled"
handler="on_checkbutton_use_syntax_highlighting_toggled" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
diff --git a/meld/filediff.py b/meld/filediff.py
index 2632587..9c3d139 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -46,6 +46,7 @@ from . import undo
from .ui import findbar
from .ui import gnomeglade
+from meld.settings import settings
from .meldapp import app
from .util.compat import text_type
from .util.sourceviewer import LanguageManager
@@ -135,8 +136,11 @@ class TextviewLineAnimation(object):
class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
- """Two or three way diff of text files.
- """
+ """Two or three way comparison of text files"""
+
+ __gtype_name__ = "FileDiff"
+
+ highlight_current_line = GObject.property(type=bool, default=False)
differ = diffutil.Differ
@@ -179,11 +183,8 @@ 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_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(self.prefs.show_whitespace)
- v.set_tab_width(self.prefs.tab_size)
buf.data.connect('file-changed', self.notify_file_changed)
self._keymask = 0
self.load_font()
@@ -345,6 +346,21 @@ 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)
+ 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)
def get_keymask(self):
return self._keymask
@@ -806,20 +822,11 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
self.linkmap[i].queue_draw()
def on_preference_changed(self, key, value):
- if key == "tab_size":
- for t in self.textview:
- t.set_tab_width(value)
- elif key == "use_custom_font" or key == "custom_font":
+ if key == "use_custom_font" or key == "custom_font":
self.load_font()
- elif key == "show_line_numbers":
- for t in self.textview:
- t.set_show_line_numbers( value )
elif key == "show_whitespace":
for v in self.textview:
v.set_draw_spaces(value)
- elif key == "use_syntax_highlighting":
- for i in range(self.num_panes):
- self.textbuffer[i].set_highlight_syntax(value)
elif key == "edit_wrap_lines":
for t in self.textview:
t.set_wrap_mode(self.prefs.edit_wrap_lines)
@@ -828,9 +835,6 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
# correct coordinates. Overly-aggressive textview lazy calculation?
self.diffmap0.queue_draw()
self.diffmap1.queue_draw()
- elif key == "spaces_instead_of_tabs":
- for t in self.textview:
- t.set_insert_spaces_instead_of_tabs(value)
elif key == "ignore_blank_lines":
self.linediffer.ignore_blanks = self.prefs.ignore_blank_lines
self.refresh_comparison()
@@ -1219,8 +1223,6 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
for i in range(self.num_panes):
self.textbuffer[i].set_language(langs[i])
- self.textbuffer[i].set_highlight_syntax(
- self.prefs.use_syntax_highlighting)
def _set_files_internal(self, files):
for i in self._load_files(files, self.textbuffer):
@@ -1504,7 +1506,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
context.set_source_rgba(*self.line_colors[change[0]])
context.stroke()
- if (self.prefs.highlight_current_line and textview.is_focus() and
+ if (self.props.highlight_current_line and textview.is_focus() and
self.cursor.line is not None):
it = textbuffer.get_iter_at_line(self.cursor.line)
ypos, line_height = textview.get_line_yrange(it)
diff --git a/meld/preferences.py b/meld/preferences.py
index 1029961..e65be89 100644
--- a/meld/preferences.py
+++ b/meld/preferences.py
@@ -22,6 +22,7 @@ import string
from gettext import gettext as _
+from gi.repository import Gio
from gi.repository import Gtk
from . import filters
@@ -31,6 +32,8 @@ from .ui import gnomeglade
from .ui import listwidget
from .util import prefs
+from meld.settings import settings
+
TIMESTAMP_RESOLUTION_PRESETS = [('1ns (ext4)', 1),
('100ns (NTFS)', 100),
@@ -144,6 +147,19 @@ class PreferencesDialog(gnomeglade.Component):
["adjustment1", "adjustment2", "fileorderstore"])
self.widget.set_transient_for(parent)
self.prefs = prefs
+
+ bindings = [
+ ('indent-width', self.spinbutton_tabsize, 'value'),
+ ('insert-spaces-instead-of-tabs', self.checkbutton_spaces_instead_of_tabs, 'active'),
+ ('highlight-current-line', self.checkbutton_highlight_current_line, 'active'),
+ ('show-line-numbers', self.checkbutton_show_line_numbers, 'active'),
+ ('highlight-syntax', self.checkbutton_use_syntax_highlighting, 'active'),
+ ]
+
+ for key, obj, attribute in bindings:
+ settings.bind(key, obj, attribute, Gio.SettingsBindFlags.DEFAULT)
+
+
if not self.prefs.use_custom_font:
self.checkbutton_default_font.set_active(True)
self.fontpicker.set_sensitive(False)
@@ -152,17 +168,8 @@ class PreferencesDialog(gnomeglade.Component):
self.fontpicker.set_sensitive(True)
self.fontpicker.set_font_name(self.prefs.custom_font)
self.fontpicker.set_font_name( self.prefs.custom_font )
- self.spinbutton_tabsize.set_value( self.prefs.tab_size )
- self.checkbutton_highlight_current_line.set_active(
- self.prefs.highlight_current_line)
- 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)
# 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:
@@ -236,11 +243,6 @@ class PreferencesDialog(gnomeglade.Component):
self.fontpicker.set_sensitive(use_custom)
self.prefs.use_custom_font = use_custom
- def on_spinbutton_tabsize_changed(self, spin):
- self.prefs.tab_size = int(spin.get_value())
- def on_checkbutton_spaces_instead_of_tabs_toggled(self, check):
- self.prefs.spaces_instead_of_tabs = check.get_active()
-
def on_checkbutton_wrap_text_toggled(self, button):
if not self.checkbutton_wrap_text.get_active():
self.prefs.edit_wrap_lines = 0
@@ -252,18 +254,9 @@ class PreferencesDialog(gnomeglade.Component):
else:
self.prefs.edit_wrap_lines = 1
- def on_checkbutton_highlight_current_line_toggled(self, check):
- self.prefs.highlight_current_line = 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()
-
def on_system_editor_checkbutton_toggled(self, check):
use_default = check.get_active()
self.custom_edit_command_entry.set_sensitive(not use_default)
@@ -321,12 +314,7 @@ class MeldPreferences(prefs.Preferences):
"window_size_y": prefs.Value(prefs.INT, 600),
"use_custom_font": prefs.Value(prefs.BOOL,0),
"custom_font": prefs.Value(prefs.STRING,"monospace, 14"),
- "tab_size": prefs.Value(prefs.INT, 4),
- "spaces_instead_of_tabs": prefs.Value(prefs.BOOL, False),
- "highlight_current_line": 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
"edit_command_custom" : prefs.Value(prefs.STRING, "gedit"),
diff --git a/meld/settings.py b/meld/settings.py
new file mode 100644
index 0000000..3ae36f5
--- /dev/null
+++ b/meld/settings.py
@@ -0,0 +1,28 @@
+# Copyright (C) 2013 Kai Willadsen <kai willadsen gmail com>
+
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 2 of the License, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 51
+# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+from gi.repository import Gio
+
+import meld.conf
+
+
+schema_source = Gio.SettingsSchemaSource.new_from_directory(
+ meld.conf.DATADIR,
+ Gio.SettingsSchemaSource.get_default(),
+ False,
+)
+schema = schema_source.lookup('org.gnome.meld', False)
+settings = Gio.Settings.new_full(schema, None, None)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]