Commit 1dd1ac87 authored by Alberto Fanjul's avatar Alberto Fanjul

Style scheme configurable

Add combo in preferences to choose style
Remove dependency from gedit settings
Configure diff source view and files plugin
parent 41c647fd
Pipeline #48785 passed with stages
in 7 minutes and 49 seconds
......@@ -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">
......
......@@ -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()
......
......@@ -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>
......@@ -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();
......
......@@ -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);
......
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