2014-12-09 00:13:14 +00:00
|
|
|
"""
|
2016-10-03 22:54:57 +00:00
|
|
|
``close_all`` plugin: close all tabs except chatrooms and the contact list.
|
2014-12-09 00:13:14 +00:00
|
|
|
|
|
|
|
Commands
|
|
|
|
--------
|
|
|
|
|
|
|
|
.. glossary::
|
|
|
|
|
|
|
|
/closeall
|
|
|
|
**Usage:** ``/closeall``
|
|
|
|
|
2016-10-03 22:26:54 +00:00
|
|
|
Close all tabs except the roster and chatroom tabs.
|
2014-12-09 00:13:14 +00:00
|
|
|
"""
|
2016-06-27 23:10:52 +00:00
|
|
|
from poezio.plugin import BasePlugin
|
|
|
|
from poezio import tabs
|
|
|
|
from poezio.decorators import command_args_parser
|
2014-12-09 00:13:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Plugin(BasePlugin):
|
|
|
|
def init(self):
|
|
|
|
self.api.add_command('closeall', self.command_closeall,
|
2016-10-03 22:26:54 +00:00
|
|
|
help='Close all non-chatroom tabs.')
|
2014-12-09 00:13:14 +00:00
|
|
|
|
|
|
|
@command_args_parser.ignored
|
|
|
|
def command_closeall(self):
|
|
|
|
"""
|
|
|
|
/closeall
|
|
|
|
"""
|
2018-07-22 14:17:06 +00:00
|
|
|
current = self.api.current_tab()
|
2014-12-09 00:13:14 +00:00
|
|
|
if not isinstance(current, (tabs.RosterInfoTab, tabs.MucTab)):
|
|
|
|
self.core.go_to_roster()
|
2018-07-22 14:17:06 +00:00
|
|
|
current = self.api.current_tab()
|
2014-12-09 00:13:14 +00:00
|
|
|
|
|
|
|
def filter_func(x):
|
|
|
|
return not isinstance(x, (tabs.RosterInfoTab, tabs.MucTab))
|
|
|
|
|
2018-07-22 14:17:06 +00:00
|
|
|
matching_tabs = list(filter(filter_func, self.core.tabs.get_tabs()))
|
2014-12-09 00:13:14 +00:00
|
|
|
length = len(matching_tabs)
|
|
|
|
for tab in matching_tabs:
|
|
|
|
self.core.close_tab(tab)
|
|
|
|
self.api.information('%s tabs closed.' % length, 'Info')
|
|
|
|
self.core.refresh_window()
|
|
|
|
|
|
|
|
|