[gitg] Make links in commit messages clickable



commit 355e70a2a6b80069c7f8fb2be5395f3b123c212c
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Mon Mar 9 08:02:17 2015 +0100

    Make links in commit messages clickable

 libgitg/gitg-diff-view.vala                 |   11 +++++++++++
 libgitg/resources/ui/diff-view/diff-view.js |   14 ++++++++++++--
 2 files changed, 23 insertions(+), 2 deletions(-)
---
diff --git a/libgitg/gitg-diff-view.vala b/libgitg/gitg-diff-view.vala
index 7bab5b8..d340e0e 100644
--- a/libgitg/gitg-diff-view.vala
+++ b/libgitg/gitg-diff-view.vala
@@ -45,6 +45,9 @@ namespace Gitg
                                                case "select-parent":
                                                        d_view.select_parent(parameter("value"));
                                                        break;
+                                               case "open-url":
+                                                       d_view.open_url(parameter("url"));
+                                                       break;
                                        }
 
                                        return false;
@@ -574,6 +577,14 @@ namespace Gitg
                        update();
                }
 
+               public void open_url(string url)
+               {
+                       try
+                       {
+                               Gtk.show_uri(null, url, 0);
+                       } catch {}
+               }
+
                private PatchSet parse_patchset(Json.Node node)
                {
                        PatchSet ret = new PatchSet();
diff --git a/libgitg/resources/ui/diff-view/diff-view.js b/libgitg/resources/ui/diff-view/diff-view.js
index 9ce9839..7de845b 100644
--- a/libgitg/resources/ui/diff-view/diff-view.js
+++ b/libgitg/resources/ui/diff-view/diff-view.js
@@ -108,6 +108,12 @@ function write_avatar(avatar, commit)
        loader.attr('src', gravatar);
 }
 
+function open_url(target)
+{
+       xhr_get('internal', {'action': 'open-url', 'url': target.getAttribute("href")});
+       return false;
+}
+
 function prettify_message(message)
 {
        var lines = message.split(/\n/);
@@ -136,7 +142,11 @@ function prettify_message(message)
                isempty = (l.length == 0);
        }
 
-       return ret;
+       var escaped = html_escape(ret);
+
+       escaped = ret.replace(/(https?:[^\s]*[^.])/g, "<a href=\"$1\" onclick=\"javascript:return 
open_url(this);\">$1</a>");
+
+       return escaped;
 }
 
 function write_commit(content, commit)
@@ -152,7 +162,7 @@ function write_commit(content, commit)
        elems.date.text(commit.author.time);
 
        // Message
-       elems.message.text(prettify_message(commit.message));
+       elems.message.html(prettify_message(commit.message));
 
        // Notes
        if (commit.hasOwnProperty('note'))


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