summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2018-07-21 21:36:46 +0200
committermathieui <mathieui@mathieui.net>2018-07-21 21:38:26 +0200
commit534ba14d5c898d50ffcdfd8539eedf10165f7fd9 (patch)
tree5e4a818966ebb55aa3a71925a3a0e0e544138d94
parent784f2d287623d2dbaac16343d5bf10b3a68bd0f7 (diff)
downloadpoezio-534ba14d5c898d50ffcdfd8539eedf10165f7fd9.tar.gz
poezio-534ba14d5c898d50ffcdfd8539eedf10165f7fd9.tar.bz2
poezio-534ba14d5c898d50ffcdfd8539eedf10165f7fd9.tar.xz
poezio-534ba14d5c898d50ffcdfd8539eedf10165f7fd9.zip
Fix /reorder
-rw-r--r--plugins/reorder.py29
-rw-r--r--poezio/core/tabs.py12
2 files changed, 15 insertions, 26 deletions
diff --git a/plugins/reorder.py b/plugins/reorder.py
index 87e87ee6..5ba23c59 100644
--- a/plugins/reorder.py
+++ b/plugins/reorder.py
@@ -80,18 +80,18 @@ TAB_TO_TEXT = {
tabs.GapTab: 'empty'
}
-def parse_config(config):
+def parse_config(tab_config):
result = {}
- for option in config.options('reorder'):
+ for option in tab_config.options('reorder'):
if not option.isdecimal():
continue
pos = int(option)
if pos in result or pos <= 0:
- return
+ return None
- typ, name = config.get(option, default=':').split(':', maxsplit=1)
+ typ, name = tab_config.get(option, default=':').split(':', maxsplit=1)
if typ not in TEXT_TO_TAB:
- return
+ return None
result[pos] = (TEXT_TO_TAB[typ], name)
return result
@@ -132,25 +132,22 @@ class Plugin(BasePlugin):
"""
/reorder
"""
- self.core.go_to_roster()
- self.core.current_tab_nb = 0
-
tabs_spec = parse_config(self.config)
if not tabs_spec:
return self.api.information('Invalid reorder config', 'Error')
- old_tabs = self.core.tabs[1:]
- roster = self.core.tabs[0]
+ old_tabs = self.core.tabs.get_tabs()
+ roster = old_tabs.pop(0)
create_gaps = config.get('create_gaps')
- new_tabs = []
+ new_tabs = [roster]
last = 0
for pos in sorted(tabs_spec):
if create_gaps and pos > last + 1:
- new_tabs += [tabs.GapTab(self.core) for i in range(pos - last)]
+ new_tabs += [tabs.GapTab(self.core) for i in range(pos - last - 1)]
cls, name = tabs_spec[pos]
- tab = self.core.get_tab_by_name(name, typ=cls)
+ tab = self.core.tabs.by_name_and_class(name, cls=cls)
if tab and tab in old_tabs:
new_tabs.append(tab)
old_tabs.remove(tab)
@@ -164,9 +161,5 @@ class Plugin(BasePlugin):
if tab:
new_tabs.append(tab)
- self.core.tabs.clear()
- self.core.tabs.append(roster)
- self.core.tabs += new_tabs
-
+ self.core.tabs.replace_tabs(new_tabs)
self.core.refresh_window()
-
diff --git a/poezio/core/tabs.py b/poezio/core/tabs.py
index 3adaf478..91a10497 100644
--- a/poezio/core/tabs.py
+++ b/poezio/core/tabs.py
@@ -141,20 +141,16 @@ class Tabs:
self._tab_names[tab.name] = tab
self._update_numbers()
- def replace_tabs(self, new_tabs: List[tabs.Tab]):
+ def replace_tabs(self, new_tabs: List[tabs.Tab]) -> bool:
"""
Replace the current tab list with another, and
rebuild the mappings.
"""
+ if self._current_tab not in new_tabs:
+ return False
self._tabs = new_tabs
self._rebuild()
- current_tab = self.current_tab
- try:
- idx = self._tabs.index(current_tab)
- self._current_index = idx
- except ValueError:
- self._current_index = 0
- self._current_tab = self._tabs[0]
+ return True
def _inc_cursor(self):
self._current_index = (self._current_index + 1) % len(self._tabs)