[polari] chatView: Add context menu to URLs



commit 82b9fe8758abf3780da47c3b13669aa0b82e59b9
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Jul 3 14:20:08 2014 +0200

    chatView: Add context menu to URLs
    
    We currently only handle left clicks on URLs, so right clicks open
    the default GtkTextView context menu instead of a context menu for
    the clicked link as one would expect. Fix this by opening a simple
    Open/Copy context menu when right-clicking URLs.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=712163

 src/chatView.js |   40 ++++++++++++++++++++++++++++++++++------
 1 files changed, 34 insertions(+), 6 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index e821baa..c26ed91 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -3,6 +3,7 @@ const GLib = imports.gi.GLib;
 const Gio = imports.gi.Gio;
 const Gtk = imports.gi.Gtk;
 const Pango = imports.gi.Pango;
+const Polari = imports.gi.Polari;
 const Tp = imports.gi.TelepathyGLib;
 const Tpl = imports.gi.TelepathyLogger;
 
@@ -392,13 +393,36 @@ const ChatView = new Lang.Class({
         delete this._pending[id];
     },
 
+    _showUrlContextMenu: function(url, button, time) {
+        let menu = new Gtk.Menu();
+
+        let item = new Gtk.MenuItem({ label: _("Open Link") });
+        item.connect('activate',
+            function() {
+                Gio.AppInfo.launch_default_for_uri(url, null);
+            });
+        menu.append(item);
+
+        item = new Gtk.MenuItem({ label: _("Copy Link Address") });
+        item.connect('activate',
+            function() {
+                let clipboard = Polari.util_get_clipboard_for_widget(item);
+                clipboard.set_text(url, -1);
+            });
+        menu.append(item);
+
+        menu.show_all();
+        menu.popup(null, null, null, button, time);
+    },
+
     _handleLinkClicks: function(view, event) {
+        let isPress = event.get_event_type() == Gdk.EventType.BUTTON_PRESS;
+
         let [, button] = event.get_button();
-        if (button != Gdk.BUTTON_PRIMARY)
+        if (button != Gdk.BUTTON_PRIMARY &&
+            (button != Gdk.BUTTON_SECONDARY || !isPress))
             return Gdk.EVENT_PROPAGATE;
 
-        let isPress = event.get_event_type() == Gdk.EventType.BUTTON_PRESS;
-
         if (isPress)
             this._clickedUrl = null;
 
@@ -411,12 +435,16 @@ const ChatView = new Lang.Class({
         for (let i = 0; i < tags.length; i++) {
             let url = tags[i]._url;
             if (url) {
+                if (url.indexOf(':') == -1)
+                    url = 'http://' + url;
+
                 if (isPress) {
-                    this._clickedUrl = url;
+                    if (button == Gdk.BUTTON_PRIMARY)
+                        this._clickedUrl = url;
+                    else
+                        this._showUrlContextMenu(url, button, event.get_time());
                     return Gdk.EVENT_STOP;
                 } else if (this._clickedUrl == url) {
-                    if (url.indexOf(':') == -1)
-                        url = 'http://' + url;
                     Gio.AppInfo.launch_default_for_uri(url, null);
                     return Gdk.EVENT_STOP;
                 }


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