2009-10-08 19:27:49 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# Terminator by Chris Jones <cmsj@tenshu.net>
|
|
|
|
# GPL v2 only
|
|
|
|
"""terminal_popup_menu.py - classes necessary to provide a terminal context
|
|
|
|
menu"""
|
|
|
|
|
|
|
|
import gtk
|
|
|
|
|
|
|
|
from version import APP_NAME
|
|
|
|
from translation import _
|
2009-10-08 20:27:00 +00:00
|
|
|
from encoding import TerminatorEncoding
|
2010-03-11 14:30:07 +00:00
|
|
|
from terminator import Terminator
|
2009-12-18 00:45:08 +00:00
|
|
|
from util import err
|
2009-12-26 20:09:16 +00:00
|
|
|
from config import Config
|
2010-01-03 17:53:25 +00:00
|
|
|
from prefseditor import PrefsEditor
|
2009-12-18 00:45:08 +00:00
|
|
|
import plugin
|
2009-10-08 19:27:49 +00:00
|
|
|
|
|
|
|
class TerminalPopupMenu(object):
|
|
|
|
"""Class implementing the Terminal context menu"""
|
|
|
|
terminal = None
|
2010-03-11 14:30:07 +00:00
|
|
|
terminator = None
|
2010-05-15 13:30:13 +00:00
|
|
|
config = None
|
2009-10-08 19:27:49 +00:00
|
|
|
|
|
|
|
def __init__(self, terminal):
|
|
|
|
"""Class initialiser"""
|
|
|
|
self.terminal = terminal
|
2010-03-11 14:30:07 +00:00
|
|
|
self.terminator = Terminator()
|
2010-05-15 13:30:13 +00:00
|
|
|
self.config = Config()
|
2009-10-08 19:27:49 +00:00
|
|
|
|
|
|
|
def show(self, widget, event=None):
|
|
|
|
"""Display the context menu"""
|
|
|
|
terminal = self.terminal
|
|
|
|
|
|
|
|
menu = gtk.Menu()
|
|
|
|
url = None
|
|
|
|
button = None
|
|
|
|
time = None
|
|
|
|
|
2010-05-15 13:30:13 +00:00
|
|
|
self.config.set_profile(terminal.get_profile())
|
|
|
|
|
2009-10-08 19:27:49 +00:00
|
|
|
if event:
|
|
|
|
url = terminal.check_for_url(event)
|
|
|
|
button = event.button
|
|
|
|
time = event.time
|
2010-01-25 12:26:32 +00:00
|
|
|
else:
|
|
|
|
time = 0
|
|
|
|
button = 3
|
2009-10-08 19:27:49 +00:00
|
|
|
|
|
|
|
if url:
|
|
|
|
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:
|
|
|
|
nameopen = _('_Open link')
|
|
|
|
namecopy = _('_Copy address')
|
|
|
|
|
|
|
|
icon = gtk.image_new_from_stock(gtk.STOCK_JUMP_TO,
|
|
|
|
gtk.ICON_SIZE_MENU)
|
|
|
|
item = gtk.ImageMenuItem(nameopen)
|
|
|
|
item.set_property('image', icon)
|
|
|
|
item.connect('activate', lambda x: terminal.open_url(url, True))
|
|
|
|
menu.append(item)
|
|
|
|
|
|
|
|
item = gtk.MenuItem(namecopy)
|
|
|
|
item.connect('activate',
|
|
|
|
lambda x: terminal.clipboard.set_text(url[0]))
|
|
|
|
menu.append(item)
|
|
|
|
|
|
|
|
menu.append(gtk.MenuItem())
|
|
|
|
|
|
|
|
item = gtk.ImageMenuItem(gtk.STOCK_COPY)
|
|
|
|
item.connect('activate', lambda x: terminal.vte.copy_clipboard())
|
|
|
|
item.set_sensitive(terminal.vte.get_has_selection())
|
|
|
|
menu.append(item)
|
|
|
|
|
|
|
|
item = gtk.ImageMenuItem(gtk.STOCK_PASTE)
|
|
|
|
item.connect('activate', lambda x: terminal.paste_clipboard())
|
|
|
|
menu.append(item)
|
|
|
|
|
|
|
|
menu.append(gtk.MenuItem())
|
|
|
|
|
|
|
|
if not terminal.is_zoomed():
|
2010-07-03 20:46:41 +00:00
|
|
|
item = gtk.ImageMenuItem(_('Split H_orizontally'))
|
2009-10-08 19:27:49 +00:00
|
|
|
image = gtk.Image()
|
|
|
|
image.set_from_icon_name(APP_NAME + '_horiz', gtk.ICON_SIZE_MENU)
|
|
|
|
item.set_image(image)
|
|
|
|
if hasattr(item, 'set_always_show_image'):
|
|
|
|
item.set_always_show_image(True)
|
2010-03-11 14:30:07 +00:00
|
|
|
item.connect('activate', lambda x: terminal.emit('split-horiz',
|
|
|
|
self.terminator.pid_cwd(self.terminal.pid)))
|
2009-10-08 19:27:49 +00:00
|
|
|
menu.append(item)
|
|
|
|
|
2010-07-03 20:46:41 +00:00
|
|
|
item = gtk.ImageMenuItem(_('Split V_ertically'))
|
2009-10-08 19:27:49 +00:00
|
|
|
image = gtk.Image()
|
|
|
|
image.set_from_icon_name(APP_NAME + '_vert', gtk.ICON_SIZE_MENU)
|
|
|
|
item.set_image(image)
|
|
|
|
if hasattr(item, 'set_always_show_image'):
|
|
|
|
item.set_always_show_image(True)
|
2010-03-11 14:30:07 +00:00
|
|
|
item.connect('activate', lambda x: terminal.emit('split-vert',
|
|
|
|
self.terminator.pid_cwd(self.terminal.pid)))
|
2009-10-08 19:27:49 +00:00
|
|
|
menu.append(item)
|
|
|
|
|
|
|
|
item = gtk.MenuItem(_('Open _Tab'))
|
2010-04-02 15:45:32 +00:00
|
|
|
item.connect('activate', lambda x: terminal.emit('tab-new', False,
|
|
|
|
terminal))
|
2009-10-08 19:27:49 +00:00
|
|
|
menu.append(item)
|
|
|
|
|
2010-04-02 15:45:32 +00:00
|
|
|
if self.terminator.debug_address is not None:
|
2010-03-19 22:16:08 +00:00
|
|
|
item = gtk.MenuItem(_('Open _Debug Tab'))
|
|
|
|
item.connect('activate', lambda x:
|
2010-04-02 15:45:32 +00:00
|
|
|
terminal.emit('tab-new', True, terminal))
|
2010-03-19 22:16:08 +00:00
|
|
|
menu.append(item)
|
|
|
|
|
2009-10-08 19:27:49 +00:00
|
|
|
menu.append(gtk.MenuItem())
|
|
|
|
|
|
|
|
item = gtk.ImageMenuItem(gtk.STOCK_CLOSE)
|
2011-08-22 18:58:24 +00:00
|
|
|
item.connect('activate', lambda x: terminal.close())
|
2009-10-08 19:27:49 +00:00
|
|
|
menu.append(item)
|
|
|
|
|
|
|
|
menu.append(gtk.MenuItem())
|
|
|
|
|
|
|
|
if not terminal.is_zoomed():
|
|
|
|
item = gtk.MenuItem(_('_Zoom terminal'))
|
|
|
|
item.connect('activate', terminal.zoom)
|
|
|
|
menu.append(item)
|
|
|
|
|
|
|
|
item = gtk.MenuItem(_('Ma_ximise terminal'))
|
|
|
|
item.connect('activate', terminal.maximise)
|
|
|
|
menu.append(item)
|
2009-11-14 18:56:34 +00:00
|
|
|
|
|
|
|
menu.append(gtk.MenuItem())
|
|
|
|
else:
|
|
|
|
item = gtk.MenuItem(_('_Restore all terminals'))
|
|
|
|
item.connect('activate', terminal.unzoom)
|
|
|
|
menu.append(item)
|
2009-10-08 19:27:49 +00:00
|
|
|
|
|
|
|
menu.append(gtk.MenuItem())
|
|
|
|
|
2010-05-15 13:30:13 +00:00
|
|
|
if self.config['show_titlebar'] == False:
|
|
|
|
item = gtk.MenuItem(_('Grouping'))
|
|
|
|
submenu = self.terminal.populate_group_menu()
|
|
|
|
submenu.show_all()
|
|
|
|
item.set_submenu(submenu)
|
|
|
|
menu.append(item)
|
|
|
|
menu.append(gtk.MenuItem())
|
|
|
|
|
2009-10-08 19:27:49 +00:00
|
|
|
item = gtk.CheckMenuItem(_('Show _scrollbar'))
|
|
|
|
item.set_active(terminal.scrollbar.get_property('visible'))
|
|
|
|
item.connect('toggled', lambda x: terminal.do_scrollbar_toggle())
|
|
|
|
menu.append(item)
|
|
|
|
|
2010-07-02 10:09:21 +00:00
|
|
|
if hasattr(gtk, 'Builder'):
|
|
|
|
item = gtk.MenuItem(_('_Preferences'))
|
|
|
|
item.connect('activate', lambda x: PrefsEditor(self.terminal))
|
|
|
|
menu.append(item)
|
2009-12-26 20:09:16 +00:00
|
|
|
|
2010-05-15 13:30:13 +00:00
|
|
|
profilelist = self.config.list_profiles()
|
2009-12-26 20:09:16 +00:00
|
|
|
|
2010-01-03 17:53:25 +00:00
|
|
|
if len(profilelist) > 1:
|
|
|
|
item = gtk.MenuItem(_('Profiles'))
|
|
|
|
submenu = gtk.Menu()
|
|
|
|
item.set_submenu(submenu)
|
|
|
|
menu.append(item)
|
2009-12-26 20:09:16 +00:00
|
|
|
|
2010-01-03 17:53:25 +00:00
|
|
|
current = terminal.get_profile()
|
2009-12-26 20:09:16 +00:00
|
|
|
|
2010-01-03 17:53:25 +00:00
|
|
|
group = None
|
2009-12-26 20:09:16 +00:00
|
|
|
|
2010-01-08 01:04:06 +00:00
|
|
|
for profile in profilelist:
|
2010-01-03 17:53:25 +00:00
|
|
|
item = gtk.RadioMenuItem(group, profile.capitalize())
|
|
|
|
if profile == current:
|
|
|
|
item.set_active(True)
|
2010-05-15 13:51:20 +00:00
|
|
|
item.connect('activate', terminal.force_set_profile, profile)
|
2010-01-03 17:53:25 +00:00
|
|
|
submenu.append(item)
|
2009-10-08 20:27:00 +00:00
|
|
|
|
|
|
|
self.add_encoding_items(menu)
|
2009-10-08 19:27:49 +00:00
|
|
|
|
2009-12-18 00:45:08 +00:00
|
|
|
try:
|
|
|
|
menuitems = []
|
|
|
|
registry = plugin.PluginRegistry()
|
|
|
|
registry.load_plugins()
|
|
|
|
plugins = registry.get_plugins_by_capability('terminal_menu')
|
|
|
|
for menuplugin in plugins:
|
|
|
|
menuplugin.callback(menuitems, menu, terminal)
|
2010-01-05 22:28:14 +00:00
|
|
|
|
|
|
|
if len(menuitems) > 0:
|
|
|
|
menu.append(gtk.MenuItem())
|
|
|
|
|
2009-12-18 00:45:08 +00:00
|
|
|
for menuitem in menuitems:
|
|
|
|
menu.append(menuitem)
|
2009-12-30 01:50:47 +00:00
|
|
|
except Exception, ex:
|
2009-12-18 00:45:08 +00:00
|
|
|
err('TerminalPopupMenu::show: %s' % ex)
|
|
|
|
|
2009-10-08 19:27:49 +00:00
|
|
|
menu.show_all()
|
|
|
|
menu.popup(None, None, None, button, time)
|
|
|
|
|
|
|
|
return(True)
|
|
|
|
|
2009-10-08 20:27:00 +00:00
|
|
|
|
|
|
|
def add_encoding_items(self, menu):
|
|
|
|
"""Add the encoding list to the menu"""
|
|
|
|
terminal = self.terminal
|
|
|
|
active_encodings = terminal.config['active_encodings']
|
|
|
|
item = gtk.MenuItem (_("Encodings"))
|
|
|
|
menu.append (item)
|
|
|
|
submenu = gtk.Menu ()
|
|
|
|
item.set_submenu (submenu)
|
|
|
|
encodings = TerminatorEncoding ().get_list ()
|
|
|
|
encodings.sort (lambda x, y: cmp (x[2].lower (), y[2].lower ()))
|
|
|
|
|
|
|
|
current_encoding = terminal.vte.get_encoding ()
|
|
|
|
group = None
|
|
|
|
|
|
|
|
if current_encoding not in active_encodings:
|
|
|
|
active_encodings.insert (0, _(current_encoding))
|
|
|
|
|
|
|
|
for encoding in active_encodings:
|
|
|
|
if encoding == terminal.default_encoding:
|
|
|
|
extratext = " (%s)" % _("Default")
|
2009-12-10 11:36:46 +00:00
|
|
|
elif encoding == current_encoding and \
|
|
|
|
terminal.custom_encoding == True:
|
2009-10-08 20:27:00 +00:00
|
|
|
extratext = " (%s)" % _("User defined")
|
|
|
|
else:
|
|
|
|
extratext = ""
|
|
|
|
|
|
|
|
radioitem = gtk.RadioMenuItem (group, _(encoding) + extratext)
|
|
|
|
|
|
|
|
if encoding == current_encoding:
|
|
|
|
radioitem.set_active (True)
|
|
|
|
|
|
|
|
if group is None:
|
|
|
|
group = radioitem
|
|
|
|
|
2009-12-10 11:36:46 +00:00
|
|
|
radioitem.connect ('activate', terminal.on_encoding_change,
|
|
|
|
encoding)
|
2009-10-08 20:27:00 +00:00
|
|
|
submenu.append (radioitem)
|
|
|
|
|
2009-10-08 20:29:45 +00:00
|
|
|
item = gtk.MenuItem (_("Other Encodings"))
|
|
|
|
submenu.append (item)
|
|
|
|
#second level
|
2009-10-08 20:27:00 +00:00
|
|
|
|
2009-10-08 20:29:45 +00:00
|
|
|
submenu = gtk.Menu ()
|
|
|
|
item.set_submenu (submenu)
|
|
|
|
group = None
|
2009-10-08 20:27:00 +00:00
|
|
|
|
2009-10-08 20:29:45 +00:00
|
|
|
for encoding in encodings:
|
|
|
|
if encoding[1] in active_encodings:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if encoding[1] is None:
|
2009-12-10 11:37:53 +00:00
|
|
|
label = "%s %s" % (encoding[2], terminal.vte.get_encoding ())
|
2009-10-08 20:29:45 +00:00
|
|
|
else:
|
2009-12-10 11:37:53 +00:00
|
|
|
label = "%s %s" % (encoding[2], encoding[1])
|
2009-10-08 20:27:00 +00:00
|
|
|
|
2009-10-08 20:29:45 +00:00
|
|
|
radioitem = gtk.RadioMenuItem (group, label)
|
|
|
|
if group is None:
|
|
|
|
group = radioitem
|
2009-10-08 20:27:00 +00:00
|
|
|
|
2009-10-08 20:29:45 +00:00
|
|
|
if encoding[1] == current_encoding:
|
|
|
|
radioitem.set_active (True)
|
2009-10-08 20:27:00 +00:00
|
|
|
|
2009-12-10 11:36:46 +00:00
|
|
|
radioitem.connect ('activate', terminal.on_encoding_change,
|
|
|
|
encoding[1])
|
2009-10-08 20:29:45 +00:00
|
|
|
submenu.append (radioitem)
|
2009-10-08 20:27:00 +00:00
|
|
|
|