Fix #2802 (add a /closeall command, with a new plugin)
This commit is contained in:
parent
7b3265c636
commit
ed7fe693b4
4 changed files with 64 additions and 4 deletions
6
doc/source/plugins/close_all.rst
Normal file
6
doc/source/plugins/close_all.rst
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
.. _closeall-plugin:
|
||||||
|
|
||||||
|
Close all
|
||||||
|
=========
|
||||||
|
|
||||||
|
.. automodule:: close_all
|
|
@ -82,6 +82,11 @@ Plugin index
|
||||||
Allows a message to be broadcasted on all the rooms your are in.
|
Allows a message to be broadcasted on all the rooms your are in.
|
||||||
Caution: do not overuse.
|
Caution: do not overuse.
|
||||||
|
|
||||||
|
Close all
|
||||||
|
:ref:`Documentation <closeall-plugin>`
|
||||||
|
|
||||||
|
Close all tabs except MUCs and the roster.
|
||||||
|
|
||||||
Day Change
|
Day Change
|
||||||
:ref:`Documentation <daychange-plugin>`
|
:ref:`Documentation <daychange-plugin>`
|
||||||
|
|
||||||
|
@ -285,3 +290,4 @@ Plugin index
|
||||||
irc
|
irc
|
||||||
change_title
|
change_title
|
||||||
pipe_cmd
|
pipe_cmd
|
||||||
|
close_all
|
||||||
|
|
45
plugins/close_all.py
Normal file
45
plugins/close_all.py
Normal file
|
@ -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()
|
||||||
|
|
||||||
|
|
|
@ -1286,6 +1286,7 @@ class Core(object):
|
||||||
"""
|
"""
|
||||||
Close the given tab. If None, close the current one
|
Close the given tab. If None, close the current one
|
||||||
"""
|
"""
|
||||||
|
was_current = tab is None
|
||||||
tab = tab or self.current_tab()
|
tab = tab or self.current_tab()
|
||||||
if isinstance(tab, tabs.RosterInfoTab):
|
if isinstance(tab, tabs.RosterInfoTab):
|
||||||
return # The tab 0 should NEVER be closed
|
return # The tab 0 should NEVER be closed
|
||||||
|
@ -1293,6 +1294,7 @@ class Core(object):
|
||||||
del tab.commands # and make the object collectable
|
del tab.commands # and make the object collectable
|
||||||
tab.on_close()
|
tab.on_close()
|
||||||
nb = tab.nb
|
nb = tab.nb
|
||||||
|
if was_current:
|
||||||
if self.previous_tab_nb != nb:
|
if self.previous_tab_nb != nb:
|
||||||
self.current_tab_nb = self.previous_tab_nb
|
self.current_tab_nb = self.previous_tab_nb
|
||||||
self.previous_tab_nb = 0
|
self.previous_tab_nb = 0
|
||||||
|
@ -1315,6 +1317,7 @@ class Core(object):
|
||||||
self.current_tab_nb = len(self.tabs) - 1
|
self.current_tab_nb = len(self.tabs) - 1
|
||||||
while not self.tabs[self.current_tab_nb]:
|
while not self.tabs[self.current_tab_nb]:
|
||||||
self.current_tab_nb -= 1
|
self.current_tab_nb -= 1
|
||||||
|
if was_current:
|
||||||
self.current_tab().on_gain_focus()
|
self.current_tab().on_gain_focus()
|
||||||
self.refresh_window()
|
self.refresh_window()
|
||||||
import gc
|
import gc
|
||||||
|
|
Loading…
Reference in a new issue