summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime “pep” Buquet <pep@bouah.net>2019-12-30 17:03:57 +0100
committerMaxime “pep” Buquet <pep@bouah.net>2019-12-31 11:54:52 +0100
commit323d39f932a79915ffd45ff5ab6ab70658d1bd6a (patch)
treeaf5522ee528dd4ffd1f4a3f9b58cf3281ed884fb
parent28be8ab0cdd8939f5aed05a4d9688a9f62afc910 (diff)
downloadpoezio-323d39f932a79915ffd45ff5ab6ab70658d1bd6a.tar.gz
poezio-323d39f932a79915ffd45ff5ab6ab70658d1bd6a.tar.bz2
poezio-323d39f932a79915ffd45ff5ab6ab70658d1bd6a.tar.xz
poezio-323d39f932a79915ffd45ff5ab6ab70658d1bd6a.zip
Tabs: add by_jid search method for tabs who have a jid attr
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
-rw-r--r--poezio/core/tabs.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/poezio/core/tabs.py b/poezio/core/tabs.py
index 3d4db8b0..abea7313 100644
--- a/poezio/core/tabs.py
+++ b/poezio/core/tabs.py
@@ -26,6 +26,7 @@ disabled.
from typing import List, Dict, Type, Optional, Union
from collections import defaultdict
+from slixmpp import JID
from poezio import tabs
from poezio.events import EventHandler
@@ -38,6 +39,7 @@ class Tabs:
'_current_index',
'_current_tab',
'_tabs',
+ '_tab_jids',
'_tab_types',
'_tab_names',
'_previous_tab',
@@ -56,6 +58,7 @@ class Tabs:
self._previous_tab = None # type: Optional[tabs.Tab]
self._tabs = [] # type: List[tabs.Tab]
+ self._tab_jids = dict() # type: Dict[JID, tabs.Tab]
self._tab_types = defaultdict(
list) # type: Dict[Type[tabs.Tab], List[tabs.Tab]]
self._tab_names = dict() # type: Dict[str, tabs.Tab]
@@ -111,6 +114,10 @@ class Tabs:
"""Return the tab list"""
return self._tabs
+ def by_jid(self, jid: JID) -> Optional[tabs.Tab]:
+ """Get a tab with a specific jid"""
+ return self._tab_jids.get(jid)
+
def by_name(self, name: str) -> Optional[tabs.Tab]:
"""Get a tab with a specific name"""
return self._tab_names.get(name)
@@ -142,11 +149,14 @@ class Tabs:
return None
def _rebuild(self):
+ self._tab_jids = dict()
self._tab_types = defaultdict(list)
self._tab_names = dict()
for tab in self._tabs:
for cls in _get_tab_types(tab):
self._tab_types[cls].append(tab)
+ if hasattr(tab, 'jid'):
+ self._tab_jids[tab.jid] = tab
self._tab_names[tab.name] = tab
self._update_numbers()
@@ -206,6 +216,8 @@ class Tabs:
self._tabs.append(tab)
for cls in _get_tab_types(tab):
self._tab_types[cls].append(tab)
+ if hasattr(tab, 'jid'):
+ self._tab_jids[tab.jid] = tab
self._tab_names[tab.name] = tab
def delete(self, tab: tabs.Tab, gap=False):
@@ -222,6 +234,8 @@ class Tabs:
for cls in _get_tab_types(tab):
self._tab_types[cls].remove(tab)
+ if hasattr(tab, 'jid'):
+ del self._tab_jids[tab.jid]
del self._tab_names[tab.name]
if gap: