diff options
author | mathieui <mathieui@mathieui.net> | 2014-12-09 01:13:14 +0100 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2014-12-09 01:13:14 +0100 |
commit | ed7fe693b4e2a4354a7db58d03bc74f155f1ad71 (patch) | |
tree | ff10ed17bb8975864a1914ab5c0415db00abf3ec /plugins | |
parent | 7b3265c636baef56e0468891cff236a462dad0a2 (diff) | |
download | poezio-ed7fe693b4e2a4354a7db58d03bc74f155f1ad71.tar.gz poezio-ed7fe693b4e2a4354a7db58d03bc74f155f1ad71.tar.bz2 poezio-ed7fe693b4e2a4354a7db58d03bc74f155f1ad71.tar.xz poezio-ed7fe693b4e2a4354a7db58d03bc74f155f1ad71.zip |
Fix #2802 (add a /closeall command, with a new plugin)
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/close_all.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/plugins/close_all.py b/plugins/close_all.py new file mode 100644 index 00000000..1b98213e --- /dev/null +++ b/plugins/close_all.py @@ -0,0 +1,45 @@ +""" +``close_all`` plugin: close all tabs except MUCs and the roster. + +Commands +-------- + +.. glossary:: + + /closeall + **Usage:** ``/closeall`` + + Close all tabs except the roster and MUC tabs. +""" +from plugin import BasePlugin +import tabs +from decorators import command_args_parser + + +class Plugin(BasePlugin): + def init(self): + self.api.add_command('closeall', self.command_closeall, + help='Close all non-muc tabs.') + + @command_args_parser.ignored + def command_closeall(self): + """ + /closeall + """ + current = self.core.current_tab() + if not isinstance(current, (tabs.RosterInfoTab, tabs.MucTab)): + self.core.go_to_roster() + current = self.core.current_tab() + + def filter_func(x): + return not isinstance(x, (tabs.RosterInfoTab, tabs.MucTab)) + + matching_tabs = list(filter(filter_func, self.core.tabs)) + length = len(matching_tabs) + for tab in matching_tabs: + self.core.close_tab(tab) + self.core.current_tab_nb = current.nb + self.api.information('%s tabs closed.' % length, 'Info') + self.core.refresh_window() + + |