Commit 8f1f877c authored by mathieui's avatar mathieui

Add /save_order to the reorder plugin

And fix a breakage due to the recent change in tab creation.
parent b685df50
......@@ -11,6 +11,10 @@ Commands
Reorder the tabs according to the configuration.
**Usage:** ``/save_order``
Save the current tab order to the configuration.
......@@ -54,11 +58,12 @@ And finally, the ``[tab name]`` must be:
- For a type ``dynamic``, the bare JID of the contact
- For a type ``static``, the full JID of the contact
from poezio.plugin import BasePlugin
from poezio import tabs
from poezio.decorators import command_args_parser
from poezio.plugin import BasePlugin
mapping = {
'muc': tabs.MucTab,
'private': tabs.PrivateTab,
'dynamic': tabs.DynamicConversationTab,
......@@ -66,6 +71,14 @@ mapping = {
'empty': tabs.GapTab
tabs.MucTab: 'muc',
tabs.DynamicConversationTab: 'dynamic',
tabs.PrivateTab: 'private',
tabs.StaticConversationTab: 'static',
tabs.GapTab: 'empty'
def parse_config(config):
result = {}
for option in config.options('reorder'):
......@@ -76,17 +89,42 @@ def parse_config(config):
typ, name = config.get(option, default=':').split(':', maxsplit=1)
if typ not in mapping:
if typ not in TEXT_TO_TAB:
result[pos] = (mapping[typ], name)
result[pos] = (TEXT_TO_TAB[typ], name)
return result
def check_tab(tab):
for cls, rep in TAB_TO_TEXT.items():
if isinstance(tab, cls):
return rep
return ''
def parse_runtime_tablist(tablist):
props = []
i = 0
for tab in tablist[1:]:
i += 1
result = check_tab(tab)
if result:
props.append((i, '%s:%s' % (result,
return props
class Plugin(BasePlugin):
def init(self):
self.api.add_command('reorder', self.command_reorder,
help='Reorder all tabs using the pre-defined'
' layout from the configuration file.')
self.api.add_command('save_order', self.command_save_order,
help='Save the current tab layout')
def command_save_order(self):
conf = parse_runtime_tablist(self.core.tabs)
for key, value in conf:
self.config.set(key, value)
self.api.information('Tab order saved', 'Info')
def command_reorder(self):
......@@ -107,7 +145,7 @@ class Plugin(BasePlugin):
last = 0
for pos in sorted(tabs_spec):
if pos > last + 1:
new_tabs += [tabs.GapTab() for i in range(pos - last)]
new_tabs += [tabs.GapTab(self.core) for i in range(pos - last)]
cls, name = tabs_spec[pos]
tab = self.core.get_tab_by_name(name, typ=cls)
if tab and tab in old_tabs:
......@@ -115,7 +153,7 @@ class Plugin(BasePlugin):
self.api.information('Tab %s not found' % name, 'Warning')
last = pos
for tab in old_tabs:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment