Integrate the plugin system into the context menus for Terminal
This commit is contained in:
parent
5dc643a3b2
commit
fe22a9cf47
|
@ -0,0 +1,29 @@
|
||||||
|
# Terminator by Chris Jones <cmsj@tenshu.net?
|
||||||
|
# GPL v2 only
|
||||||
|
"""terminal_menu.py - Default plugins for the terminal menu"""
|
||||||
|
import gtk
|
||||||
|
import plugin
|
||||||
|
|
||||||
|
# Every plugin you want Terminator to load *must* be listed in 'available'
|
||||||
|
|
||||||
|
# This is commented out because we don't want any menu item plugins by default
|
||||||
|
#available = ['MyFirstMenuItem']
|
||||||
|
available = []
|
||||||
|
|
||||||
|
class MenuItem(plugin.Plugin):
|
||||||
|
"""Base class for menu items"""
|
||||||
|
capabilities = ['terminal_menu']
|
||||||
|
|
||||||
|
def callback(self, menuitems, menu, terminal):
|
||||||
|
"""Callback to transform the enclosed URL"""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
class MyFirstMenuItem(MenuItem):
|
||||||
|
"""Simple proof of concept"""
|
||||||
|
capabilities = ['terminal_menu']
|
||||||
|
|
||||||
|
def callback(self, menuitems, menu, terminal):
|
||||||
|
"""Add our menu items to the menu"""
|
||||||
|
item = gtk.MenuItem('Some Menu Text')
|
||||||
|
menuitems.append(item)
|
||||||
|
|
|
@ -9,6 +9,8 @@ import gtk
|
||||||
from version import APP_NAME
|
from version import APP_NAME
|
||||||
from translation import _
|
from translation import _
|
||||||
from encoding import TerminatorEncoding
|
from encoding import TerminatorEncoding
|
||||||
|
from util import err
|
||||||
|
import plugin
|
||||||
|
|
||||||
class TerminalPopupMenu(object):
|
class TerminalPopupMenu(object):
|
||||||
"""Class implementing the Terminal context menu"""
|
"""Class implementing the Terminal context menu"""
|
||||||
|
@ -135,6 +137,18 @@ class TerminalPopupMenu(object):
|
||||||
|
|
||||||
self.add_encoding_items(menu)
|
self.add_encoding_items(menu)
|
||||||
|
|
||||||
|
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)
|
||||||
|
for menuitem in menuitems:
|
||||||
|
menu.append(menuitem)
|
||||||
|
except Exception as ex:
|
||||||
|
err('TerminalPopupMenu::show: %s' % ex)
|
||||||
|
|
||||||
menu.show_all()
|
menu.show_all()
|
||||||
menu.popup(None, None, None, button, time)
|
menu.popup(None, None, None, button, time)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue