On 7 October 2014 20:32, Mark R. Pariente <[email protected]> wrote:
> This commit adds a "color scheme" entry to preferences which controls
> the GtkSourceView scheme-style property to allow the user toggle between
> different color schemes installed in the system. This is particularly
> relevant for syntax highlighting since the default scheme (classic) is
> not great in all circumstances such as dark theme usage. In general this
> is heavily user preference driven so this commit allows users to select a
> scheme they like.
Awesome, thanks! While I have some reservations about this feature,
it's definitely something that there have been requests for, so it'll
be great to get it in.
The reason I'm worried about doing this is that of the five
GtkSourceView schemes I have installed, two are basically unreadable
with our colours, and we don't (and I think can't) change those with a
GtkSourceView theme. So I'm worried that we're sending a signal that
we're supporting something that we really can't.
On the UI front, I think I'd prefer to have the scheme combo box below
the current syntax highlighting preference, in the same way that we do
with other preferences. It also needs to be labelled 'Syntax
highlighting color scheme' or something, to try and indicate that this
*won't* change the diff highlight colours.
I've attached a patch on top of yours to make the preferences combo
box use our existing GSettingsStringComboBox helper, and move some of
the UI creation back into the .ui file.
> diff --git a/meld/filediff.py b/meld/filediff.py
> index 5ebe330..5e1f308 100644
> --- a/meld/filediff.py
> +++ b/meld/filediff.py
> @@ -850,6 +850,9 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
> def on_setting_changed(self, settings, key):
> if key == 'font':
> self.load_font()
> + elif key == 'style-scheme':
> + for i in range(3):
> +
> self.textview[i].get_buffer().change_style_scheme(meldsettings.style_scheme)
FileDiff shouldn't really need to handle this logic at all. I think it
would be neater to have it all in MeldBuffer, where you have most of
the relevant stuff already (see below).
<snip>
> @@ -41,6 +41,12 @@ class MeldBuffer(GtkSource.Buffer):
> bind_settings(self)
> self.data = MeldBufferData(filename)
> self.user_action_count = 0
> + self.change_style_scheme(settings.get_string('style-scheme'))
> +
> + def change_style_scheme(self, scheme):
> + manager = GtkSource.StyleSchemeManager.get_default()
> + style = GtkSource.StyleSchemeManager.get_scheme(manager, scheme)
> + GtkSource.Buffer.set_style_scheme(self, style)
I think this would be nicer if we used MeldSettings (which is
basically a settings adaptor class) to update the actual scheme for
us, and just make MeldBuffer connect to the MeldSettings changed
signal. That way, almost all of the settings handling logic ends up in
meld.settings.
<snip>
> --- a/meld/settings.py
> +++ b/meld/settings.py
> @@ -55,6 +55,9 @@ class MeldSettings(GObject.GObject):
> elif key in ('use-system-font', 'custom-font'):
> self.font = self._current_font_from_gsetting()
> self.emit('changed', 'font')
> + elif key in ('style-scheme'):
> + self.style_scheme = settings.get_string('style-scheme')
> + self.emit('changed', 'style-scheme')
So you've set self.style_scheme here, which is cool, but isn't
actually used. We *should* set self.style_scheme to just be the actual
scheme (i.e., do the StyleSchemeManager stuff there) and then retrieve
that in MeldBuffer.
For a bit of context, things handled by MeldSettings should (I think)
all be g_settings_bind_with_mapping() calls, but that isn't supported
by our required PyGObject version.
Again, thanks for this. I'm looking forward to getting it in.
cheers,
Kai
From c4a2e7aa4f08f3c354b1a04c74a4976c89e04d89 Mon Sep 17 00:00:00 2001
From: Kai Willadsen <[email protected]>
Date: Wed, 8 Oct 2014 05:50:58 +1000
Subject: [PATCH] preferences: Update syntax scheme preference to use combo
helper
---
data/ui/preferences.ui | 18 +++++++++++++++++-
meld/preferences.py | 30 ++++++++++--------------------
2 files changed, 27 insertions(+), 21 deletions(-)
diff --git a/data/ui/preferences.ui b/data/ui/preferences.ui
index 8452ab0..b246af7 100644
--- a/data/ui/preferences.ui
+++ b/data/ui/preferences.ui
@@ -15,6 +15,14 @@
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
+ <object class="GtkListStore" id="syntaxschemestore">
+ <columns>
+ <!-- column-name id -->
+ <column type="gchararray"/>
+ <!-- column-name name -->
+ <column type="gchararray"/>
+ </columns>
+ </object>
<object class="GtkListStore" id="fileorderstore">
<columns>
<!-- column-name id -->
@@ -494,9 +502,17 @@
</packing>
</child>
<child>
- <object class="GtkComboBox" id="combobox_style_scheme">
+ <object class="GSettingsStringComboBox" id="combobox_style_scheme">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="model">syntaxschemestore</property>
+ <property name="gsettings-column">0</property>
+ <child>
+ <object class="GtkCellRendererText" id="syntax_scheme_renderer"/>
+ <attributes>
+ <attribute name="text">1</attribute>
+ </attributes>
+ </child>
</object>
<packing>
<property name="expand">True</property>
diff --git a/meld/preferences.py b/meld/preferences.py
index 16c7f42..1c0cd1a 100644
--- a/meld/preferences.py
+++ b/meld/preferences.py
@@ -145,8 +145,11 @@ class GSettingsComboBox(Gtk.ComboBox):
self.set_property('active', idx)
def _active_changed(self, obj, val):
+ active_iter = self.get_active_iter()
+ if active_iter is None:
+ return
column = self.get_property('gsettings-column')
- value = self.get_model()[self.get_active_iter()][column]
+ value = self.get_model()[active_iter][column]
self.set_property('gsettings-value', value)
@@ -181,7 +184,8 @@ class PreferencesDialog(Component):
["adjustment1", "adjustment2", "fileorderstore",
"sizegroup_editor", "timestampstore",
"mergeorderstore", "sizegroup_file_order_labels",
- "sizegroup_file_order_combos"])
+ "sizegroup_file_order_combos",
+ 'syntaxschemestore'])
self.widget.set_transient_for(parent)
bindings = [
@@ -241,28 +245,14 @@ class PreferencesDialog(Component):
self.combo_merge_order.bind_to('vc-merge-file-order')
# Fill color schemes
- liststore = Gtk.ListStore(str)
manager = GtkSource.StyleSchemeManager.get_default()
- scheme_ids = GtkSource.StyleSchemeManager.get_scheme_ids(manager)
- for scheme in scheme_ids:
- liststore.append([scheme])
- self.combobox_style_scheme.set_model(liststore)
- cell = Gtk.CellRendererText()
- self.combobox_style_scheme.pack_start(cell, True)
- self.combobox_style_scheme.add_attribute(cell, 'text',0)
-
- style_scheme = settings.get_string('style-scheme')
- for idx,scheme in enumerate(scheme_ids):
- if scheme == style_scheme:
- self.combobox_style_scheme.set_active(idx)
-
- self.combobox_style_scheme.connect("changed", self.on_combobox_style_scheme_changed)
+ for scheme_id in manager.get_scheme_ids():
+ scheme = manager.get_scheme(scheme_id)
+ self.syntaxschemestore.append([scheme_id, scheme.get_name()])
+ self.combobox_style_scheme.bind_to('style-scheme')
self.widget.show()
- def on_combobox_style_scheme_changed(self, combobox):
- settings.set_string('style-scheme', combobox.get_model()[combobox.get_active()][0])
-
def on_checkbutton_wrap_text_toggled(self, button):
if not self.checkbutton_wrap_text.get_active():
wrap_mode = Gtk.WrapMode.NONE
--
1.8.3.1
_______________________________________________
meld-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/meld-list