diff --git a/terminatorlib/plugin.py b/terminatorlib/plugin.py index d664f86b..f1e0752d 100755 --- a/terminatorlib/plugin.py +++ b/terminatorlib/plugin.py @@ -105,6 +105,31 @@ for %s' % (len(self.instances), capability)) """Return all plugins""" return(self.instances) +# This is where we should define a base class for each type of plugin we +# support + +# URLHandler - This adds a regex match to the Terminal widget and provides a +# callback to turn that into a URL. +class URLHandler(Plugin): + """Base class for URL handlers""" + capabilities = ['url_handler'] + handler_name = None + match = None + + def callback(self, url): + """Callback to transform the enclosed URL""" + raise NotImplementedError + +# MenuItem - This is able to execute code during the construction of the +# context menu of a Terminal. +class MenuItem(Plugin): + """Base class for menu items""" + capabilities = ['terminal_menu'] + + def callback(self, menuitems, menu, terminal): + """Callback to transform the enclosed URL""" + raise NotImplementedError + if __name__ == '__main__': import sys import doctest diff --git a/terminatorlib/plugins/terminal_menu.py b/terminatorlib/plugins/terminal_menu.py index 575a5c74..93b5e62e 100644 --- a/terminatorlib/plugins/terminal_menu.py +++ b/terminatorlib/plugins/terminal_menu.py @@ -10,15 +10,7 @@ import terminatorlib.plugin as plugin #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): +class MyFirstMenuItem(plugin.MenuItem): """Simple proof of concept""" capabilities = ['terminal_menu'] diff --git a/terminatorlib/plugins/url_handlers.py b/terminatorlib/plugins/url_handlers.py index a7da4393..edea9457 100644 --- a/terminatorlib/plugins/url_handlers.py +++ b/terminatorlib/plugins/url_handlers.py @@ -7,17 +7,7 @@ import terminatorlib.plugin as plugin # Every plugin you want Terminator to load *must* be listed in 'available' available = ['LaunchpadBugURLHandler', 'LaunchpadCodeURLHandler', 'APTURLHandler'] -class URLHandler(plugin.Plugin): - """Base class for URL handlers""" - capabilities = ['url_handler'] - handler_name = None - match = None - - def callback(self, url): - """Callback to transform the enclosed URL""" - raise NotImplementedError - -class LaunchpadBugURLHandler(URLHandler): +class LaunchpadBugURLHandler(plugin.URLHandler): """Launchpad Bug URL handler. If the URL looks like a Launchpad changelog closure entry... 'LP: #12345' then it should be transformed into a Launchpad Bug URL""" @@ -31,7 +21,7 @@ class LaunchpadBugURLHandler(URLHandler): url = 'https://bugs.launchpad.net/bugs/%s' % item return(url) -class LaunchpadCodeURLHandler(URLHandler): +class LaunchpadCodeURLHandler(plugin.URLHandler): """Launchpad Code URL handler. If the URL looks like a Launchpad project or branch entry then it should be transformed into a code.launchpad.net URL""" capabilities = ['url_handler'] @@ -50,7 +40,7 @@ class LaunchpadCodeURLHandler(URLHandler): url = url[3:] return('https://code.launchpad.net/+branch/%s' % url) -class APTURLHandler(URLHandler): +class APTURLHandler(plugin.URLHandler): """APT URL handler. If there is a URL that looks like an apturl, handle it appropriately""" capabilities = ['url_handler']