Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Copy URI submenu to copy link to clipboard #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion open-uri-context-menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'''

from gettext import gettext as _
from gi.repository import Gtk, Gedit, Gio, GObject, GtkSource
from gi.repository import Gtk, Gdk, Gedit, Gio, GObject, GtkSource
import re
import sys
import os
Expand Down Expand Up @@ -132,16 +132,25 @@ def on_view_populate_popup(self, view, menu):
browse_uri_item.show();

displayed_word = displayed_word.replace('file://', '')

copy_uri_item = Gtk.ImageMenuItem(_("Copy URI '%s'" % (displayed_word)))
copy_uri_item.set_image(Gtk.Image.new_from_stock(Gtk.STOCK_OPEN, Gtk.IconSize.MENU))
copy_uri_item.connect('activate', self.on_copy_uri_activate, word)
copy_uri_item.show()

open_uri_item = Gtk.ImageMenuItem(_("Open '%s'") % (displayed_word))
open_uri_item.set_image(Gtk.Image.new_from_stock(Gtk.STOCK_OPEN, Gtk.IconSize.MENU))
open_uri_item.connect('activate', self.on_open_uri_activate, word);
open_uri_item.show();


separator = Gtk.SeparatorMenuItem()
separator.show();
menu.prepend(separator)
menu.prepend(copy_uri_item)
menu.prepend(open_uri_item)


if browse_to:
menu.prepend(browse_uri_item)
return True
Expand All @@ -150,6 +159,10 @@ def on_open_uri_activate(self, menu_item, uri):
self.open_uri(uri)
return True

def on_copy_uri_activate(self, menu_item, uri):
self.copy_uri(uri)
return True

def validate_uri(self, uri):
m = RE_URI_RFC2396.search(uri);
if not m:
Expand Down Expand Up @@ -212,6 +225,10 @@ def open_uri(self, uri):
GObject.timeout_add(4000, self.on_statusbar_timeout, status,
status.get_context_id("OpenURIContextMenuPlugin"), status_id)

def copy_uri(self, uri):
clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
clipboard.set_text(uri, -1)

def on_statusbar_timeout(self, status, context_id, status_id):
status.remove(context_id, status_id)
return False