Allow plugins to override the open/copy menu items in the terminal context menu. Also set these values for all of the default plugins. When copying a URL, run it through the URL preparer - this means wusers will get the resulting URI on their clipboard, rather than the original text sometimes and the URI some other times, depending on the type of URI

This commit is contained in:
Chris Jones 2012-01-14 20:09:25 +00:00
parent 8c0f30fd80
commit cd5c4c1056
5 changed files with 48 additions and 9 deletions

View File

@ -1,5 +1,9 @@
terminator 0.97:
* Allow font dimming in inactive terminals
* Allow URL handler plugins to override label text for URL context
menus
* When copying a URL, run it through the URL handler first so the
resulting URL is copied, rather than the original text
terminator 0.96:
* Unity support for opening new windows (Lucian Adrian Grijincu)

View File

@ -155,6 +155,8 @@ class URLHandler(Plugin):
capabilities = ['url_handler']
handler_name = None
match = None
nameopen = None
namecopy = None
def __init__(self):
"""Class initialiser"""

View File

@ -14,6 +14,8 @@ class LaunchpadBugURLHandler(plugin.URLHandler):
capabilities = ['url_handler']
handler_name = 'launchpad_bug'
match = '\\b(lp|LP):?\s?#?[0-9]+(,\s*#?[0-9]+)*\\b'
nameopen = "Open Launchpad bug"
namecopy = "Copy bug URL"
def callback(self, url):
"""Look for the number in the supplied string and return it as a URL"""
@ -26,6 +28,8 @@ class LaunchpadCodeURLHandler(plugin.URLHandler):
branch entry then it should be transformed into a code.launchpad.net URL"""
capabilities = ['url_handler']
handler_name = 'launchpad_code'
nameopen = "Open Launchpad branch"
namecopy = "Copy branch URL"
lpfilters = {}
lpfilters['project'] = '[a-z0-9]{1}[a-z0-9\.\-\+]+'
lpfilters['group'] = '~%s' % lpfilters['project']
@ -45,6 +49,8 @@ class APTURLHandler(plugin.URLHandler):
it appropriately"""
capabilities = ['url_handler']
handler_name = 'apturl'
nameopen = "Open software manager"
namecopy = "Copy package URI"
match = '\\bapt:.*\\b'
def callback(self, url):

View File

@ -284,14 +284,14 @@ class Terminal(gtk.VBox):
name = urlplugin.handler_name
match = urlplugin.match
if name in self.matches:
dbg('Terminal::update_matches: refusing to add \
duplicate match %s' % name)
dbg('refusing to add duplicate match %s' % name)
continue
self.matches[name] = self.vte.match_add(match)
dbg('Terminal::update_matches: added plugin URL handler \
for %s (%s)' % (name, urlplugin.__class__.__name__))
dbg('added plugin URL handler for %s (%s) as %d' %
(name, urlplugin.__class__.__name__,
self.matches[name]))
except Exception, ex:
err('Terminal::update_url_matches: %s' % ex)
err('Exception occurred adding plugin URL match: %s' % ex)
def match_add(self, name, match):
"""Register a URL match"""
@ -1293,7 +1293,7 @@ for %s (%s)' % (name, urlplugin.__class__.__name__))
url = newurl
break
except Exception, ex:
err('Terminal::prepare_url: %s' % ex)
err('Exception occurred preparing URL: %s' % ex)
return(url)

View File

@ -10,7 +10,7 @@ from version import APP_NAME
from translation import _
from encoding import TerminatorEncoding
from terminator import Terminator
from util import err
from util import err, dbg
from config import Config
from prefseditor import PrefsEditor
import plugin
@ -47,14 +47,41 @@ class TerminalPopupMenu(object):
button = 3
if url:
dbg("URL matches id: %d" % url[1])
if not url[1] in terminal.matches.values():
err("Unknown URL match id: %d" % url[1])
dbg("Available matches: %s" % terminal.matches)
nameopen = None
namecopy = None
if url[1] == terminal.matches['email']:
nameopen = _('_Send email to...')
namecopy = _('_Copy email address')
elif url[1] == terminal.matches['voip']:
nameopen = _('Ca_ll VoIP address')
namecopy = _('_Copy VoIP address')
else:
elif url[1] in terminal.matches.values():
# This is a plugin match
for pluginname in terminal.matches:
if terminal.matches[pluginname] == url[1]:
break
dbg("Found match ID (%d) in terminal.matches plugin %s" %
(url[1], pluginname))
registry = plugin.PluginRegistry()
registry.load_plugins()
plugins = registry.get_plugins_by_capability('url_handler')
for urlplugin in plugins:
if urlplugin.handler_name == pluginname:
dbg("Identified matching plugin: %s" %
urlplugin.handler_name)
nameopen = _(urlplugin.nameopen)
namecopy = _(urlplugin.namecopy)
break
if not nameopen:
nameopen = _('_Open link')
if not namecopy:
namecopy = _('_Copy address')
icon = gtk.image_new_from_stock(gtk.STOCK_JUMP_TO,
@ -66,7 +93,7 @@ class TerminalPopupMenu(object):
item = gtk.MenuItem(namecopy)
item.connect('activate',
lambda x: terminal.clipboard.set_text(url[0]))
lambda x: terminal.clipboard.set_text(terminal.prepare_url(url)))
menu.append(item)
menu.append(gtk.MenuItem())