diff --git a/terminatorlib/plugin.py b/terminatorlib/plugin.py index fd86f0c1..3d0f912c 100755 --- a/terminatorlib/plugin.py +++ b/terminatorlib/plugin.py @@ -28,16 +28,20 @@ import os import borg from config import Config from util import dbg, err, get_config_dir +from terminator import Terminator class Plugin(object): """Definition of our base plugin class""" capabilities = None - is_permanent = None def __init__(self): """Class initialiser.""" pass + def unload(self): + """Prepare to be unloaded""" + pass + class PluginRegistry(borg.Borg): """Definition of a class to store plugin instances""" available_plugins = None @@ -128,29 +132,18 @@ for %s' % (len(self.instances), capability)) not""" return(self.instances.has_key(plugin)) - def is_permanent(self, plugin): - """Return a boolean value indicating whether a plugin is believed to be - permanent. This is impossible to determine for plugins that haven't - been loaded, so they will report as not being permanent until they are - loaded""" - if plugin not in self.instances: - return(False) - else: - return(self.instances[plugin].is_permanent) - def enable(self, plugin): """Enable a plugin""" + if plugin in self.instances: + err("Cannot enable plugin %s, already enabled" % plugin) dbg("Enabling %s" % plugin) - if plugin not in self.instances: - self.instances[plugin] = self.available_plugins[plugin]() + self.instances[plugin] = self.available_plugins[plugin]() def disable(self, plugin): """Disable a plugin""" - if self.instances[plugin].is_permanent: - dbg("Refusing to disable permanent plugin %s" % plugin) - else: - dbg("Disabling %s" % plugin) - del(self.instances[plugin]) + dbg("Disabling %s" % plugin) + self.instances[plugin].unload() + del(self.instances[plugin]) # This is where we should define a base class for each type of plugin we # support @@ -162,12 +155,28 @@ class URLHandler(Plugin): capabilities = ['url_handler'] handler_name = None match = None - is_permanent = True + + def __init__(self): + """Class initialiser""" + Plugin.__init__(self) + terminator = Terminator() + for terminal in terminator.terminals: + terminal.match_add(self.handler_name, self.match) def callback(self, url): """Callback to transform the enclosed URL""" raise NotImplementedError + def unload(self): + """Handle being removed""" + if not self.match: + err('unload called without self.handler_name being set') + return + terminator = Terminator() + for terminal in terminator.terminals: + print self.handler_name + terminal.match_remove(self.handler_name) + # MenuItem - This is able to execute code during the construction of the # context menu of a Terminal. class MenuItem(Plugin): diff --git a/terminatorlib/preferences.glade b/terminatorlib/preferences.glade index 56081658..74eae78b 100644 --- a/terminatorlib/preferences.glade +++ b/terminatorlib/preferences.glade @@ -2865,51 +2865,32 @@ True - + True + True + PluginListStore + adjustment2 + adjustment3 + 0 - - True - True - PluginListStore - adjustment2 - adjustment3 - 0 + + Plugin + True - - Plugin - True - - - - - - 1 - - - - - - 0 - - + + + + 1 + + + + + + 0 + - - 0 - - - - - True - Plugins will be enabled/disabled after restarting Terminator - - - False - False - 1 - diff --git a/terminatorlib/prefseditor.py b/terminatorlib/prefseditor.py index b8680082..f60259b4 100755 --- a/terminatorlib/prefseditor.py +++ b/terminatorlib/prefseditor.py @@ -1025,6 +1025,13 @@ class PrefsEditor: model = treeview.get_model() plugin = model[path][0] + if not self.plugins[plugin]: + # Plugin is currently disabled, load it + self.registry.enable(plugin) + else: + # Plugin is currently enabled, unload it + self.registry.disable(plugin) + self.plugins[plugin] = not self.plugins[plugin] # Update the treeview model[path][1] = self.plugins[plugin] diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index 93f9b7f3..41056b0b 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -268,12 +268,31 @@ class Terminal(gtk.VBox): for urlplugin in plugins: name = urlplugin.handler_name match = urlplugin.match + if name in self.matches: + dbg('Terminal::update_matches: 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__)) except Exception, ex: err('Terminal::update_url_matches: %s' % ex) - + + def match_add(self, name, match): + """Register a URL match""" + if name in self.matches: + err('Terminal::match_add: Refusing to create duplicate match %s' % name) + return + self.matches[name] = self.vte.match_add(match) + + def match_remove(self, name): + """Remove a previously registered URL match""" + if name not in self.matches: + err('Terminal::match_remove: Unable to remove non-existent match %s' % name) + return + self.vte.match_remove(self.matches[name]) + del(self.matches[name]) + def connect_signals(self): """Connect all the gtk signals and drag-n-drop mechanics"""