[gitg/wip/gaurav/clickable-links-subject-textview: 3/15] Parse URI on subject



commit c811606e985dc0389472ddca1b2cf045dcbb596a
Author: Alberto Fanjul <albertofanjul gmail com>
Date:   Sat Jan 19 10:50:04 2019 +0100

    Parse URI on subject

 libgitg/gitg-diff-view-commit-details.vala         | 24 +++++++++++++++++++++-
 .../resources/ui/gitg-diff-view-commit-details.ui  |  1 +
 2 files changed, 24 insertions(+), 1 deletion(-)
---
diff --git a/libgitg/gitg-diff-view-commit-details.vala b/libgitg/gitg-diff-view-commit-details.vala
index 254844e9..842bf780 100644
--- a/libgitg/gitg-diff-view-commit-details.vala
+++ b/libgitg/gitg-diff-view-commit-details.vala
@@ -186,7 +186,7 @@ class Gitg.DiffViewCommitDetails : Gtk.Grid
                        return;
                }
 
-               d_label_subject.label = commit.get_subject();
+               d_label_subject.label = parse_links_on_subject(commit.get_subject());
                d_label_sha1.label = commit.get_id().to_string();
 
                var author = commit.get_author();
@@ -257,6 +257,28 @@ class Gitg.DiffViewCommitDetails : Gtk.Grid
                update_avatar();
        }
 
+       private string parse_links_on_subject(string subject_text)
+       {
+               string result = subject_text.dup();
+               try
+               {
+                       GLib.MatchInfo matchInfo;
+                       GLib.Regex regex = /\w+:(\/?\/?)[^\s]+/;
+                       regex.match (subject_text, 0, out matchInfo);
+
+                       while (matchInfo.matches ())
+                       {
+                               string text = matchInfo.fetch(0);
+                               result = result.replace(text, "<a href=\"%s\">%s</a>".printf(text, text));
+                               matchInfo.next();
+                       }
+               }
+               catch(Error e)
+               {
+               }
+               return result;
+       }
+
        private void update_avatar()
        {
                if (commit == null)
diff --git a/libgitg/resources/ui/gitg-diff-view-commit-details.ui 
b/libgitg/resources/ui/gitg-diff-view-commit-details.ui
index 70c3a368..dee13bea 100644
--- a/libgitg/resources/ui/gitg-diff-view-commit-details.ui
+++ b/libgitg/resources/ui/gitg-diff-view-commit-details.ui
@@ -130,6 +130,7 @@
             <property name="wrap">True</property>
             <property name="selectable">True</property>
             <property name="ellipsize">end</property>
+            <property name="use_markup">True</property>
           </object>
           <packing>
             <property name="left_attach">0</property>


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