[gitg/style-manager: 5/5] Style scheme configurable



commit 1dd1ac87012b9e5ff99e6b926c365043efc6a1ff
Author: Alberto Fanjul <albertofanjul gmail com>
Date:   Wed Jan 2 03:54:37 2019 +0100

    Style scheme configurable
    
    Add combo in preferences to choose style
    Remove dependency from gedit settings
    Configure diff source view and files plugin

 data/org.gnome.gitg.gschema.xml.in               |  5 +++
 gitg/preferences/gitg-preferences-interface.vala | 22 +++++++++++-
 gitg/resources/ui/gitg-preferences-interface.ui  | 44 +++++++++++++++++++++++
 libgitg/gitg-diff-view-file-renderer-text.vala   | 46 ++++++++++++++++++++++--
 plugins/files/gitg-files.vala                    | 11 +++---
 5 files changed, 121 insertions(+), 7 deletions(-)
---
diff --git a/data/org.gnome.gitg.gschema.xml.in b/data/org.gnome.gitg.gschema.xml.in
index b15eed4d..6c04f10c 100644
--- a/data/org.gnome.gitg.gschema.xml.in
+++ b/data/org.gnome.gitg.gschema.xml.in
@@ -68,6 +68,11 @@
          views.
       </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>
   </schema>
   <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.gitg.preferences.history" 
path="/org/gnome/gitg/preferences/history/">
     <key name="collapse-inactive-lanes" type="i">
diff --git a/gitg/preferences/gitg-preferences-interface.vala 
b/gitg/preferences/gitg-preferences-interface.vala
index aea3b695..1c64148f 100644
--- a/gitg/preferences/gitg-preferences-interface.vala
+++ b/gitg/preferences/gitg-preferences-interface.vala
@@ -43,6 +43,12 @@ public class PreferencesInterface : Gtk.Grid, GitgExt.Preferences
        [GtkChild (name = "diff_highlighting_enabled")]
        private Gtk.CheckButton d_diff_highlighting_enabled;
 
+       [GtkChild (name = "default_style_scheme")]
+       private Gtk.ComboBox d_default_style_scheme;
+
+       [GtkChild (name = "syntax_scheme_store")]
+       private Gtk.ListStore d_syntax_scheme_store;
+
        construct
        {
                d_settings = new Settings("org.gnome.gitg.preferences.interface");
@@ -61,12 +67,21 @@ public class PreferencesInterface : Gtk.Grid, GitgExt.Preferences
                        }
                });
 
+               var style_manager = Gtk.SourceStyleSchemeManager.get_default ();
+               Gtk.TreeIter iter;
+
+               foreach (var id in style_manager.get_scheme_ids()) {
+                       var scheme = style_manager.get_scheme(id);
+                       d_syntax_scheme_store.append (out iter);
+                       d_syntax_scheme_store.set (iter, 0, scheme.name, 1, scheme.id);
+               }
+
                d_settings.changed["orientation"].connect(orientation_changed);
 
                d_settings.bind("default-activity",
                                d_default_activity,
                                "active-id",
-                               SettingsBindFlags.GET | SettingsBindFlags.SET);
+                               SettingsBindFlags.GET | SettingsBindFlags.SET);
 
                d_settings.bind("use-gravatar",
                                d_gravatar_enabled,
@@ -82,6 +97,11 @@ public class PreferencesInterface : Gtk.Grid, GitgExt.Preferences
                                d_diff_highlighting_enabled,
                                "active",
                                SettingsBindFlags.GET | SettingsBindFlags.SET);
+
+               d_settings.bind("style-scheme",
+                               d_default_style_scheme,
+                               "active-id",
+                               SettingsBindFlags.GET | SettingsBindFlags.SET);
        }
 
        public override void dispose()
diff --git a/gitg/resources/ui/gitg-preferences-interface.ui b/gitg/resources/ui/gitg-preferences-interface.ui
index 34ea7f74..f8fb8fbc 100644
--- a/gitg/resources/ui/gitg-preferences-interface.ui
+++ b/gitg/resources/ui/gitg-preferences-interface.ui
@@ -242,6 +242,44 @@
                 <property name="top_attach">0</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkGrid" id="grid7">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="margin_start">12</property>
+                <property name="hexpand">True</property>
+                <property name="row_spacing">6</property>
+                <property name="column_spacing">6</property>
+                <child>
+                  <object class="GtkLabel" id="label7">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="halign">start</property>
+                    <property name="label" translatable="yes">Syntax highlighting color scheme:</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkComboBoxText" id="default_style_scheme">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="model">syntax_scheme_store</property>
+                    <property name="halign">start</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">0</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="left_attach">0</property>
@@ -255,4 +293,10 @@
       </packing>
     </child>
   </template>
+  <object class="GtkListStore" id="syntax_scheme_store">
+    <columns>
+      <column type="gchararray"/>
+      <column type="gchararray"/>
+    </columns>
+  </object>
 </interface>
diff --git a/libgitg/gitg-diff-view-file-renderer-text.vala b/libgitg/gitg-diff-view-file-renderer-text.vala
index b6735623..09bf132d 100644
--- a/libgitg/gitg-diff-view-file-renderer-text.vala
+++ b/libgitg/gitg-diff-view-file-renderer-text.vala
@@ -58,6 +58,8 @@ class Gitg.DiffViewFileRendererText : Gtk.SourceView, DiffSelectable, DiffViewFi
        private Region[] d_regions;
        private bool d_constructed;
 
+       private Settings? d_stylesettings;
+
        public bool new_is_workdir { get; construct set; }
 
        public bool wrap_lines
@@ -387,13 +389,24 @@ class Gitg.DiffViewFileRendererText : Gtk.SourceView, DiffSelectable, DiffViewFi
                        return null;
                }
 
-               var buffer = new Gtk.SourceBuffer(this.buffer.tag_table);
+               var buffer = this.buffer as Gtk.SourceBuffer;
 
                var style_scheme_manager = Gtk.SourceStyleSchemeManager.get_default();
 
                buffer.language = language;
                buffer.highlight_syntax = true;
-               buffer.style_scheme = style_scheme_manager.get_scheme("classic");
+
+               d_stylesettings = try_settings("org.gnome.gitg.preferences.interface");
+               if (d_stylesettings != null)
+               {
+                       d_stylesettings.changed["style-scheme"].connect((s, k) => {
+                               update_style();
+                       });
+
+                       update_style();
+               } else {
+                       buffer.style_scheme = style_scheme_manager.get_scheme("classic");
+               }
 
                var sfile = new Gtk.SourceFile();
                sfile.location = location;
@@ -418,6 +431,35 @@ class Gitg.DiffViewFileRendererText : Gtk.SourceView, DiffSelectable, DiffViewFi
                return buffer;
        }
 
+       private void update_style()
+       {
+               var scheme = d_stylesettings.get_string("style-scheme");
+               var manager = Gtk.SourceStyleSchemeManager.get_default();
+               var s = manager.get_scheme(scheme);
+
+               if (s != null)
+               {
+                       (buffer as Gtk.SourceBuffer).style_scheme = s;
+               }
+       }
+
+       private Settings? try_settings(string schema_id)
+       {
+               var source = SettingsSchemaSource.get_default();
+
+               if (source == null)
+               {
+                       return null;
+               }
+
+               if (source.lookup(schema_id, true) != null)
+               {
+                       return new Settings(schema_id);
+               }
+
+               return null;
+       }
+
        private void strip_carriage_returns(Gtk.SourceBuffer buffer)
        {
                var search_settings = new Gtk.SourceSearchSettings();
diff --git a/plugins/files/gitg-files.vala b/plugins/files/gitg-files.vala
index 6c780194..87550868 100644
--- a/plugins/files/gitg-files.vala
+++ b/plugins/files/gitg-files.vala
@@ -92,7 +92,7 @@ namespace GitgFiles
 
                private void update_style()
                {
-                       var scheme = d_stylesettings.get_string("scheme");
+                       var scheme = d_stylesettings.get_string("style-scheme");
                        var manager = Gtk.SourceStyleSchemeManager.get_default();
                        var s = manager.get_scheme(scheme);
 
@@ -155,15 +155,18 @@ namespace GitgFiles
                                update_font();
                        }
 
-                       d_stylesettings = try_settings("org.gnome.gedit.preferences.editor");
-
+                       d_stylesettings = try_settings("org.gnome.gitg.preferences.interface");
                        if (d_stylesettings != null)
                        {
-                               d_stylesettings.changed["scheme"].connect((s, k) => {
+                               d_stylesettings.changed["style-scheme"].connect((s, k) => {
                                        update_style();
                                });
 
                                update_style();
+                       } else {
+                               var buf = d_source.get_buffer() as Gtk.SourceBuffer;
+                               var style_scheme_manager = Gtk.SourceStyleSchemeManager.get_default();
+                               buf.style_scheme = style_scheme_manager.get_scheme("classic");
                        }
 
                        d_whenMapped = new Gitg.WhenMapped(d_paned);


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