[gitg/wip/gaurav/clickable-links-subject-textview: 6/15] Read custom link config from ini file
- From: Alberto Fanjul <albfan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg/wip/gaurav/clickable-links-subject-textview: 6/15] Read custom link config from ini file
- Date: Fri, 12 Apr 2019 11:17:31 +0000 (UTC)
commit 57acd9bc76d76df3c7fcc266151eb1b88a8cc7b4
Author: Alberto Fanjul <albertofanjul gmail com>
Date: Sat Jan 19 11:31:12 2019 +0100
Read custom link config from ini file
libgitg/gitg-diff-view.vala | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
---
diff --git a/libgitg/gitg-diff-view.vala b/libgitg/gitg-diff-view.vala
index e0e6a1cd..4b1d9149 100644
--- a/libgitg/gitg-diff-view.vala
+++ b/libgitg/gitg-diff-view.vala
@@ -553,6 +553,11 @@ public class Gitg.DiffView : Gtk.Grid
load_colors_from_theme(d_text_view_message);
apply_link_tags(buffer, /\w+:(\/?\/?)[^\s]+/, null, d_color_link,
is_custom_d_color_link);
+
+ //TODO: locate from repo it can be GIT_DIR env, a worktree...
+ var ini_file = ".git/config";
+ read_ini_file(buffer, ini_file);
+
d_text_view_message.visible = (message != "");
}
else
@@ -569,6 +574,38 @@ public class Gitg.DiffView : Gtk.Grid
}
}
+ private void read_ini_file(Gtk.TextBuffer buffer, string config_file)
+ {
+ GLib.KeyFile file = new GLib.KeyFile();
+
+ try
+ {
+ if (file.load_from_file(config_file , GLib.KeyFileFlags.NONE))
+ {
+ foreach (string group in file.get_groups())
+ {
+ if (group.has_prefix("gitg.custom-link"))
+ {
+ string custom_link_regexp = file.get_string (group, "regexp");
+ string custom_link_replacement = file.get_string (group,
"replacement");
+ bool custom_color = file.has_key (group, "color");
+ Gdk.RGBA color = d_color_link;
+ if (custom_color)
+ {
+ string custom_link_color = file.get_string (group,
"color");
+ color = Gdk.RGBA();
+ color.parse(custom_link_color);
+ }
+ apply_link_tags(buffer, new Regex (custom_link_regexp),
custom_link_replacement, color, custom_color);
+ }
+ }
+ }
+ } catch (Error e)
+ {
+ message("Cannot read custom.ini %s", e.message);
+ }
+ }
+
private void auto_change_expanded(bool expanded)
{
SignalHandler.block(d_commit_details, d_expanded_notify);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]