[meld] Make GtkSourceView scheme-style configurable



commit 13544e801029196e8101d547bb000bdb00e1ecff
Author: Mark Pariente <markpariente gmail com>
Date:   Tue Oct 7 03:12:22 2014 -0700

    Make GtkSourceView scheme-style configurable
    
    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.

 data/org.gnome.meld.gschema.xml |    5 +++
 data/ui/preferences.ui          |   53 +++++++++++++++++++++++++++++++++-----
 meld/filediff.py                |    3 ++
 meld/meldbuffer.py              |    8 +++++-
 meld/preferences.py             |   21 +++++++++++++++
 meld/settings.py                |    3 ++
 6 files changed, 85 insertions(+), 8 deletions(-)
---
diff --git a/data/org.gnome.meld.gschema.xml b/data/org.gnome.meld.gschema.xml
index 7613914..82c1061 100644
--- a/data/org.gnome.meld.gschema.xml
+++ b/data/org.gnome.meld.gschema.xml
@@ -80,6 +80,11 @@
           <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="style-scheme" type="s">
+          <default>"classic"</default>
+          <summary>Color scheme to use for syntax highlighting</summary>
+          <description>Used by GtkSourceView to determine colors for syntax highlighting</description>
+      </key>
       <key name="draw-spaces" flags='org.gnome.meld.spacesflags'>
           <default>[]</default>
           <summary>Displayed whitespace</summary>
diff --git a/data/ui/preferences.ui b/data/ui/preferences.ui
index 1d672da..8452ab0 100644
--- a/data/ui/preferences.ui
+++ b/data/ui/preferences.ui
@@ -457,14 +457,53 @@
                               </packing>
                             </child>
                             <child>
-                              <object class="GtkCheckButton" id="checkbutton_use_syntax_highlighting">
-                                <property name="label" translatable="yes">Use s_yntax highlighting</property>
+                              <object class="GtkHBox" id="hbox11">
                                 <property name="visible">True</property>
-                                <property name="can_focus">True</property>
-                                <property name="receives_default">False</property>
-                                <property name="use_underline">True</property>
-                                <property name="xalign">0</property>
-                                <property name="draw_indicator">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="spacing">6</property>
+                                <child>
+                                  <object class="GtkCheckButton" id="checkbutton_use_syntax_highlighting">
+                                    <property name="label" translatable="yes">Use s_yntax 
highlighting</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">False</property>
+                                    <property name="use_underline">True</property>
+                                    <property name="xalign">0</property>
+                                    <property name="draw_indicator">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">False</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkLabel" id="label16">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="label" translatable="yes">Color Scheme:</property>
+                                    <attributes>
+                                      <attribute name="weight" value="bold"/>
+                                    </attributes>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">True</property>
+                                    <property name="fill">True</property>
+                                    <property name="padding">8</property>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkComboBox" id="combobox_style_scheme">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">True</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">2</property>
+                                  </packing>
+                                </child>
                               </object>
                               <packing>
                                 <property name="expand">False</property>
diff --git a/meld/filediff.py b/meld/filediff.py
index 162c509..05ba6b6 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -852,6 +852,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)
 
     def check_save_modified(self, label=None):
         response = Gtk.ResponseType.OK
diff --git a/meld/meldbuffer.py b/meld/meldbuffer.py
index 1ba2bb2..d3fe665 100644
--- a/meld/meldbuffer.py
+++ b/meld/meldbuffer.py
@@ -24,7 +24,7 @@ from gi.repository import GObject
 from gi.repository import GtkSource
 
 from meld.conf import _
-from meld.settings import bind_settings
+from meld.settings import bind_settings,settings
 from meld.util.compat import text_type
 
 
@@ -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)
 
     def do_begin_user_action(self, *args):
         self.user_action_count += 1
diff --git a/meld/preferences.py b/meld/preferences.py
index f3ead6d..16c7f42 100644
--- a/meld/preferences.py
+++ b/meld/preferences.py
@@ -240,8 +240,29 @@ class PreferencesDialog(Component):
         self.combo_file_order.bind_to('vc-left-is-local')
         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)
+
         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
diff --git a/meld/settings.py b/meld/settings.py
index 8cff34e..d147e31 100644
--- 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')
 
     def _filters_from_gsetting(self, key, filt_type):
         filter_params = settings.get_value(key)


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