diff options
author | mathieui <mathieui@mathieui.net> | 2018-06-29 21:18:09 +0200 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2018-07-21 20:20:13 +0200 |
commit | a28b9c4422317c6fed4a430dad4a478f462d3854 (patch) | |
tree | a664c2168a4e04e9bf5466868e0e899d0fc799d1 | |
parent | 7d9afc6ad40348fb21bf54ec55e14e22d023400e (diff) | |
download | poezio-a28b9c4422317c6fed4a430dad4a478f462d3854.tar.gz poezio-a28b9c4422317c6fed4a430dad4a478f462d3854.tar.bz2 poezio-a28b9c4422317c6fed4a430dad4a478f462d3854.tar.xz poezio-a28b9c4422317c6fed4a430dad4a478f462d3854.zip |
Update poezio for the new tabs module
-rw-r--r-- | poezio/core/commands.py | 100 | ||||
-rw-r--r-- | poezio/core/completions.py | 13 | ||||
-rw-r--r-- | poezio/core/core.py | 278 | ||||
-rw-r--r-- | poezio/core/handlers.py | 78 | ||||
-rw-r--r-- | poezio/plugin.py | 4 | ||||
-rw-r--r-- | poezio/tabs/adhoc_commands_list.py | 2 | ||||
-rw-r--r-- | poezio/tabs/basetabs.py | 8 | ||||
-rw-r--r-- | poezio/tabs/muclisttab.py | 2 | ||||
-rw-r--r-- | poezio/tabs/muctab.py | 20 | ||||
-rw-r--r-- | poezio/tabs/privatetab.py | 15 | ||||
-rw-r--r-- | poezio/tabs/rostertab.py | 2 | ||||
-rw-r--r-- | poezio/tabs/xmltab.py | 2 | ||||
-rw-r--r-- | poezio/windows/info_bar.py | 8 |
13 files changed, 190 insertions, 342 deletions
diff --git a/poezio/core/commands.py b/poezio/core/commands.py index 88bcb753..df06c41f 100644 --- a/poezio/core/commands.py +++ b/poezio/core/commands.py @@ -52,7 +52,7 @@ class CommandCore: buff.extend(acc) acc = [] buff.append('Tab-specific commands:') - tab_commands = self.core.current_tab().commands + tab_commands = self.core.tabs.current_tab.commands for name, command in tab_commands.items(): if isinstance(command, Command): acc.append(' \x19%s}%s\x19o - %s' % (color, name, @@ -67,7 +67,7 @@ class CommandCore: else: command = args[0].lstrip('/').strip() - tab_commands = self.core.current_tab().commands + tab_commands = self.core.tabs.current_tab.commands if command in tab_commands: tup = tab_commands[command] elif command in self.core.commands: @@ -125,7 +125,7 @@ class CommandCore: pres['type'] = show self.core.events.trigger('send_normal_presence', pres) pres.send() - current = self.core.current_tab() + current = self.core.tabs.current_tab is_muctab = isinstance(current, tabs.MucTab) if is_muctab and current.joined and show in ('away', 'xa'): current.send_chat_state('inactive') @@ -148,8 +148,8 @@ class CommandCore: return self.help('presence') jid, ptype, status = args[0], args[1], args[2] - if jid == '.' and isinstance(self.core.current_tab(), tabs.ChatTab): - jid = self.core.current_tab().name + if jid == '.' and isinstance(self.core.tabs.current_tab, tabs.ChatTab): + jid = self.core.tabs.current_tab.name if ptype == 'available': ptype = None try: @@ -162,7 +162,7 @@ class CommandCore: log.debug( 'Could not send directed presence to %s', jid, exc_info=True) return - tab = self.core.get_tab_by_name(jid) + tab = self.core.tabs.by_name_and_class(jid) if tab: if ptype in ('xa', 'away'): tab.directed_presence = False @@ -170,13 +170,13 @@ class CommandCore: else: tab.directed_presence = True chatstate = 'active' - if tab == self.core.current_tab(): + if tab == self.core.tabs.current_tab: tab.send_chat_state(chatstate, True) if isinstance(tab, tabs.MucTab): for private in tab.privates: private.directed_presence = tab.directed_presence - if self.core.current_tab() in tab.privates: - self.core.current_tab().send_chat_state(chatstate, True) + if self.core.tabs.current_tab in tab.privates: + self.core.tabs.current_tab.send_chat_state(chatstate, True) @command_args_parser.quoted(1) def theme(self, args=None): @@ -199,33 +199,23 @@ class CommandCore: except ValueError: number = -1 name = name.lower() - if number != -1 and self.core.current_tab_nb == number: + if number != -1 and self.core.tabs.current_tab == number: return prev_nb = self.core.previous_tab_nb - self.core.previous_tab_nb = self.core.current_tab_nb - old_tab = self.core.current_tab() + self.core.previous_tab_nb = self.core.tabs.current_tab + old_tab = self.core.tabs.current_tab if 0 <= number < len(self.core.tabs): if not self.core.tabs[number]: self.core.previous_tab_nb = prev_nb return - self.core.current_tab_nb = number + self.core.tabs.set_current_index(number) else: - match = None - target_tabs = self.core.tabs[self.core.current_tab_nb+1:] \ - + self.core.tabs[:self.core.current_tab_nb] - for tab in target_tabs: - for tab_name in tab.matching_names(): - if tab_name[1] and name in tab_name[1].lower(): - match = tab - break - if match: - break + match = self.core.tabs.find_match(name) if match is None: - self.core.previous_tab_nb = prev_nb return - self.core.current_tab_nb = match.nb + self.core.tabs.set_current_tab(match) old_tab.on_lose_focus() - self.core.current_tab().on_gain_focus() + self.core.tabs.current_tab.on_gain_focus() self.core.refresh_window() @command_args_parser.quoted(2) @@ -236,7 +226,7 @@ class CommandCore: if args is None: return self.help('move_tab') - current_tab = self.core.current_tab() + current_tab = self.core.tabs.current_tab if args[0] == '.': args[0] = current_tab.nb if args[1] == '.': @@ -266,8 +256,6 @@ class CommandCore: result = self.core.insert_tab(old, new) if not result: self.core.information('Unable to move the tab.', 'Info') - else: - self.core.current_tab_nb = self.core.tabs.index(current_tab) self.core.refresh_window() @command_args_parser.quoted(0, 1) @@ -281,10 +269,10 @@ class CommandCore: elif args: jid = safeJID(args[0]) else: - if not isinstance(self.core.current_tab(), tabs.MucTab): + if not isinstance(self.core.tabs.current_tab, tabs.MucTab): return self.core.information('Please provide a server', 'Error') - jid = safeJID(self.core.current_tab().name) + jid = safeJID(self.core.tabs.current_tab.name) list_tab = tabs.MucListTab(self.core, jid) self.core.add_tab(list_tab, True) cb = list_tab.on_muc_list_item_received @@ -307,7 +295,7 @@ class CommandCore: resource.jid, callback=self.core.handler.on_version_result) def _empty_join(self): - tab = self.core.current_tab() + tab = self.core.tabs.current_tab if not isinstance(tab, (tabs.MucTab, tabs.PrivateTab)): return (None, None) room = safeJID(tab.name).bare @@ -331,7 +319,7 @@ class CommandCore: # happens with /join /nickname, which is OK if info.bare == '': - tab = self.core.current_tab() + tab = self.core.tabs.current_tab if not isinstance(tab, tabs.MucTab): room, set_nick = (None, None) else: @@ -344,7 +332,7 @@ class CommandCore: # use the server of the current room if available # check if the current room's name has a server if room.find('@') == -1 and not server_root: - tab = self.core.current_tab() + tab = self.core.tabs.current_tab if isinstance(tab, tabs.MucTab): if tab.name.find('@') != -1: domain = safeJID(tab.name).domain @@ -376,13 +364,13 @@ class CommandCore: if room in self.core.pending_invites: del self.core.pending_invites[room] - tab = self.core.get_tab_by_name(room, tabs.MucTab) + tab = self.core.tabs.by_name_and_class(room, tabs.MucTab) # New tab if tab is None: tab = self.core.open_new_room(room, nick, password=password) tab.join() else: - self.core.focus_tab_named(tab.name) + self.core.focus_tab(tab) if tab.own_nick == nick and tab.joined: self.core.information('/join: Nothing to do.', 'Info') else: @@ -396,7 +384,7 @@ class CommandCore: 'use_remote_bookmarks') else 'local' self._add_bookmark('%s/%s' % (room, nick), True, password, method) - if tab == self.core.current_tab(): + if tab == self.core.tabs.current_tab: tab.refresh() self.core.doupdate() @@ -405,7 +393,8 @@ class CommandCore: """ /bookmark_local [room][/nick] [password] """ - if not args and not isinstance(self.core.current_tab(), tabs.MucTab): + if not args and not isinstance(self.core.tabs.current_tab, + tabs.MucTab): return password = args[1] if len(args) > 1 else None jid = args[0] if args else None @@ -417,7 +406,8 @@ class CommandCore: """ /bookmark [room][/nick] [autojoin] [password] """ - if not args and not isinstance(self.core.current_tab(), tabs.MucTab): + if not args and not isinstance(self.core.tabs.current_tab, + tabs.MucTab): return jid = args[0] if args else '' password = args[2] if len(args) > 2 else None @@ -435,7 +425,7 @@ class CommandCore: def _add_bookmark(self, jid, autojoin, password, method): nick = None if not jid: - tab = self.core.current_tab() + tab = self.core.tabs.current_tab roomname = tab.name if tab.joined and tab.own_nick != self.core.own_nick: nick = tab.own_nick @@ -447,7 +437,7 @@ class CommandCore: info = safeJID(jid) roomname, nick = info.bare, info.resource if roomname == '': - tab = self.core.current_tab() + tab = self.core.tabs.current_tab if not isinstance(tab, tabs.MucTab): return roomname = tab.name @@ -498,14 +488,14 @@ class CommandCore: @command_args_parser.ignored def bookmarks(self): """/bookmarks""" - tab = self.core.get_tab_by_name('Bookmarks', tabs.BookmarksTab) - old_tab = self.core.current_tab() + tab = self.core.tabs.by_name_and_class('Bookmarks', tabs.BookmarksTab) + old_tab = self.core.tabs.current_tab if tab: - self.core.current_tab_nb = tab.nb + self.core.tabs.set_current_tab(tab) else: tab = tabs.BookmarksTab(self.core, self.core.bookmarks) self.core.tabs.append(tab) - self.core.current_tab_nb = tab.nb + self.core.tabs.set_current_tab(tab) old_tab.on_lose_focus() tab.on_gain_focus() self.core.refresh_window() @@ -522,7 +512,7 @@ class CommandCore: 'Error') if not args: - tab = self.core.current_tab() + tab = self.core.tabs.current_tab if isinstance(tab, tabs.MucTab) and self.core.bookmarks[tab.name]: self.core.bookmarks.remove(tab.name) self.core.bookmarks.save(self.core.xmpp, callback=cb) @@ -607,7 +597,7 @@ class CommandCore: info = plugin_config.set_and_save(option, value, section) else: if args[0] == '.': - name = safeJID(self.core.current_tab().name).bare + name = safeJID(self.core.tabs.current_tab.name).bare if not name: self.core.information( 'Invalid tab to use the "." argument.', 'Error') @@ -661,7 +651,7 @@ class CommandCore: Do a /cycle on each room of the given server. If none, do it on the current tab """ - tab = self.core.current_tab() + tab = self.core.tabs.current_tab message = "" if args: domain = args[0] @@ -850,9 +840,10 @@ class CommandCore: room = safeJID(args[0]).bare if room: muc.destroy_room(self.core.xmpp, room) - elif isinstance(self.core.current_tab(), tabs.MucTab) and not args[0]: + elif isinstance(self.core.tabs.current_tab, + tabs.MucTab) and not args[0]: muc.destroy_room(self.core.xmpp, - self.core.current_tab().general_jid) + self.core.tabs.current_tab.general_jid) else: self.core.information('Invalid JID: "%s"' % args[0], 'Error') @@ -948,20 +939,21 @@ class CommandCore: return self.core.information('Invalid JID.', 'Error') tab = self.core.get_conversation_by_jid( jid.full, False, fallback_barejid=False) - muc = self.core.get_tab_by_name(jid.bare, typ=tabs.MucTab) + muc = self.core.tabs.by_name_and_class(jid.bare, typ=tabs.MucTab) if not tab and not muc: tab = self.core.open_conversation_window(jid.full, focus=True) elif muc: if jid.resource: - tab = self.core.get_tab_by_name(jid.full, typ=tabs.PrivateTab) + tab = self.core.tabs.by_name_and_class( + jid.full, typ=tabs.PrivateTab) if tab: - self.core.focus_tab_named(tab.name) + self.core.focus_tab(tab) else: tab = self.core.open_private_window(jid.bare, jid.resource) else: tab = muc else: - self.core.focus_tab_named(tab.name) + self.core.focus_tab(tab) if len(args) == 2: tab.command_say(args[1]) diff --git a/poezio/core/completions.py b/poezio/core/completions.py index 0f3b5931..29fcd24e 100644 --- a/poezio/core/completions.py +++ b/poezio/core/completions.py @@ -27,7 +27,7 @@ class CompletionCore: def help(self, the_input): """Completion for /help.""" commands = sorted(self.core.commands.keys()) + sorted( - self.core.current_tab().commands.keys()) + self.core.tabs.current_tab.commands.keys()) return Completion(the_input.new_completion, commands, 1, quotify=False) def status(self, the_input): @@ -49,7 +49,8 @@ class CompletionCore: if arg == 1: to_suggest = [] for bookmark in self.core.bookmarks: - tab = self.core.get_tab_by_name(bookmark.jid, tabs.MucTab) + tab = self.core.tabs.by_name_and_class(bookmark.jid, + tabs.MucTab) if tab is not None and tab.joined: to_suggest.append(bookmark.jid) return Completion( @@ -119,7 +120,7 @@ class CompletionCore: for elem in self.core.bookmarks] to_suggest = [] for bookmark in bookmarks: - tab = self.core.get_tab_by_name(bookmark, tabs.MucTab) + tab = self.core.tabs.by_name_and_class(bookmark, tabs.MucTab) if not tab or (tab and not tab.joined): to_suggest.append(bookmark) relevant_rooms.extend(sorted(to_suggest)) @@ -181,7 +182,7 @@ class CompletionCore: """ list_ = [] list_.extend(self.core.key_func.keys()) - list_.extend(self.core.current_tab().key_func.keys()) + list_.extend(self.core.tabs.current_tab.key_func.keys()) return Completion(the_input.new_completion, list_, 1, quotify=False) def bookmark(self, the_input): @@ -200,7 +201,7 @@ class CompletionCore: jid = safeJID(args[1]) if jid.server and (jid.resource or jid.full.endswith('/')): - tab = self.core.get_tab_by_name(jid.bare, tabs.MucTab) + tab = self.core.tabs.by_name_and_class(jid.bare, tabs.MucTab) nicks = [tab.own_nick] if tab else [] default = os.environ.get('USER') if os.environ.get( 'USER') else 'poezio' @@ -432,7 +433,7 @@ class CompletionCore: jid = safeJID(args[1]) if jid.server and (jid.resource or jid.full.endswith('/')): - tab = self.core.get_tab_by_name(jid.bare, tabs.MucTab) + tab = self.core.tabs.by_name_and_class(jid.bare, tabs.MucTab) nicks = [tab.own_nick] if tab else [] default = os.environ.get('USER') if os.environ.get( 'USER') else 'poezio' diff --git a/poezio/core/core.py b/poezio/core/core.py index 015515c0..f6985a56 100644 --- a/poezio/core/core.py +++ b/poezio/core/core.py @@ -44,6 +44,7 @@ from poezio.theming import get_theme from poezio import keyboard, xdg from poezio.core.completions import CompletionCore +from poezio.core.tabs import Tabs from poezio.core.commands import CommandCore from poezio.core.handlers import HandlerCore from poezio.core.structs import POSSIBLE_SHOW, DEPRECATED_ERRORS, \ @@ -94,8 +95,7 @@ class Core: self.xml_tab = None self.xml_buffer = TextBuffer() - self.tabs = [] - self._current_tab_nb = 0 + self.tabs = Tabs() self.previous_tab_nb = 0 own_nick = config.get('default_nick') @@ -398,8 +398,7 @@ class Core: Called when the option create_gaps is changed. Remove all gaptabs if switching from gaps to nogaps. """ - if value.lower() == "false": - self.tabs = [tab for tab in self.tabs if tab] + self.tabs.update_gaps(value.lower() == "false") def on_request_receipts_config_change(self, option, value): """ @@ -652,7 +651,7 @@ class Core: except ValueError: pass else: - if self.current_tab().nb == nb and config.get( + if self.tabs.current_tab.nb == nb and config.get( 'go_to_previous_tab_on_alt_number'): self.go_to_previous_tab() else: @@ -706,9 +705,9 @@ class Core: Messages are namedtuples of the form ('txt nick_color time str_time nickname user') """ - if not isinstance(self.current_tab(), tabs.ChatTab): + if not isinstance(self.tabs.current_tab, tabs.ChatTab): return None - return self.current_tab().get_conversation_messages() + return self.tabs.current_tab.get_conversation_messages() def insert_input_text(self, text): """ @@ -821,7 +820,7 @@ class Core: keyboard.continuation_keys_callback = None cb(key) else: - self.current_tab().on_input(key, raw) + self.tabs.current_tab.on_input(key, raw) def try_execute(self, line): """ @@ -829,7 +828,7 @@ class Core: """ line = '/' + line try: - self.current_tab().execute_command(line) + self.tabs.current_tab.execute_command(line) except: log.error('Execute failed (%s)', line, exc_info=True) @@ -902,9 +901,9 @@ class Core: conversation. Returns False if the current tab is not a conversation tab """ - if not isinstance(self.current_tab(), tabs.ChatTab): + if not isinstance(self.tabs.current_tab, tabs.ChatTab): return False - self.current_tab().command_say(msg) + self.tabs.current_tab.command_say(msg) return True def invite(self, jid, room, reason=None): @@ -970,15 +969,8 @@ class Core: def get_tabs(self, cls=None): "Get all the tabs of a type" if cls is None: - cls = tabs.Tab - return [tab for tab in self.tabs if isinstance(tab, cls)] - - def current_tab(self): - """ - returns the current room, the one we are viewing - """ - self.current_tab_nb = self.current_tab_nb - return self.tabs[self.current_tab_nb] + return self.tabs.get_tabs() + return self.tabs.by_class(cls) def get_conversation_by_jid(self, jid, create=True, fallback_barejid=True): """ @@ -992,16 +984,16 @@ class Core: jid = safeJID(jid) # We first check if we have a static conversation opened # with this precise resource - conversation = self.get_tab_by_name(jid.full, - tabs.StaticConversationTab) + conversation = self.tabs.by_name_and_class(jid.full, + tabs.StaticConversationTab) if jid.bare == jid.full and not conversation: - conversation = self.get_tab_by_name(jid.full, - tabs.DynamicConversationTab) + conversation = self.tabs.by_name_and_class( + jid.full, tabs.DynamicConversationTab) if not conversation and fallback_barejid: # If not, we search for a conversation with the bare jid - conversation = self.get_tab_by_name(jid.bare, - tabs.DynamicConversationTab) + conversation = self.tabs.by_name_and_class( + jid.bare, tabs.DynamicConversationTab) if not conversation: if create: # We create a dynamic conversation with the bare Jid if @@ -1013,23 +1005,6 @@ class Core: conversation = None return conversation - def get_tab_by_name(self, name, typ=None): - """ - Get the tab with the given name. - If typ is provided, return a tab of this type only - """ - for tab in self.tabs: - if tab.name == name: - if (typ and isinstance(tab, typ)) or\ - not typ: - return tab - return None - - def get_tab_by_number(self, number): - if 0 <= number < len(self.tabs): - return self.tabs[number] - return None - def add_tab(self, new_tab, focus=False): """ Appends the new_tab in the tab list and @@ -1039,82 +1014,12 @@ class Core: if focus: self.command.win("%s" % new_tab.nb) - def insert_tab_nogaps(self, old_pos, new_pos): - """ - Move tabs without creating gaps - old_pos: old position of the tab - new_pos: desired position of the tab - """ - tab = self.tabs[old_pos] - if new_pos < old_pos: - self.tabs.pop(old_pos) - self.tabs.insert(new_pos, tab) - elif new_pos > old_pos: - self.tabs.insert(new_pos, tab) - self.tabs.remove(tab) - else: - return False - return True - - def insert_tab_gaps(self, old_pos, new_pos): - """ - Move tabs and create gaps in the eventual remaining space - old_pos: old position of the tab - new_pos: desired position of the tab - """ - tab = self.tabs[old_pos] - target = None if new_pos >= len(self.tabs) else self.tabs[new_pos] - if not target: - if new_pos < len(self.tabs): - old_tab = self.tabs[old_pos] - self.tabs[new_pos], self.tabs[old_pos] = old_tab, tabs.GapTab( - self) - else: - self.tabs.append(self.tabs[old_pos]) - self.tabs[old_pos] = tabs.GapTab(self) - else: - if new_pos > old_pos: - self.tabs.insert(new_pos, tab) - self.tabs[old_pos] = tabs.GapTab(self) - elif new_pos < old_pos: - self.tabs[old_pos] = tabs.GapTab(self) - self.tabs.insert(new_pos, tab) - else: - return False - i = self.tabs.index(tab) - done = False - # Remove the first Gap on the right in the list - # in order to prevent global shifts when there is empty space - while not done: - i += 1 - if i >= len(self.tabs): - done = True - elif not self.tabs[i]: - self.tabs.pop(i) - done = True - # Remove the trailing gaps - i = len(self.tabs) - 1 - while isinstance(self.tabs[i], tabs.GapTab): - self.tabs.pop() - i -= 1 - return True - def insert_tab(self, old_pos, new_pos=99999): """ Insert a tab at a position, changing the number of the following tabs returns False if it could not move the tab, True otherwise """ - if old_pos <= 0 or old_pos >= len(self.tabs): - return False - elif new_pos <= 0: - return False - elif new_pos == old_pos: - return False - elif not self.tabs[old_pos]: - return False - if config.get('create_gaps'): - return self.insert_tab_gaps(old_pos, new_pos) - return self.insert_tab_nogaps(old_pos, new_pos) + self.tabs.insert_tab(old_pos, new_pos, config.get('create_gaps')) ### Move actions (e.g. go to next room) ### @@ -1122,22 +1027,18 @@ class Core: """ rotate the rooms list to the right """ - self.current_tab().on_lose_focus() - self.current_tab_nb += 1 - while not self.tabs[self.current_tab_nb]: - self.current_tab_nb += 1 - self.current_tab().on_gain_focus() + self.tabs.current_tab.on_lose_focus() + self.tabs.next() + self.tabs.current_tab.on_gain_focus() self.refresh_window() def rotate_rooms_left(self, args=None): """ rotate the rooms list to the right """ - self.current_tab().on_lose_focus() - self.current_tab_nb -= 1 - while not self.tabs[self.current_tab_nb]: - self.current_tab_nb -= 1 - self.current_tab().on_gain_focus() + self.tabs.current_tab.on_lose_focus() + self.tabs.prev() + self.tabs.current_tab.on_gain_focus() self.refresh_window() def go_to_room_number(self): @@ -1183,7 +1084,7 @@ class Core: priority = tabs.STATE_PRIORITY tab_refs = {} # put all the active tabs in a dict of lists by state - for tab in self.tabs: + for tab in self.tabs.get_tabs(): if not tab: continue if tab.state not in tab_refs: @@ -1197,8 +1098,8 @@ class Core: for state in states: for tab in tab_refs[state]: - if (tab.nb < self.current_tab_nb - and tab_refs[state][-1].nb > self.current_tab_nb): + if (tab.nb < self.tabs.current_tab_intex and + tab_refs[state][-1].nb > self.tabs.current_tab_index): continue self.command.win(str(tab.nb)) return @@ -1206,33 +1107,14 @@ class Core: def focus_tab_named(self, tab_name, type_=None): """Returns True if it found a tab to focus on""" - for tab in self.tabs: - if tab.name == tab_name: - if (type_ and (isinstance(tab, type_))) or not type_: - self.command.win(str(tab.nb)) - return True - return False - - @property - def current_tab_nb(self): - """Wrapper for the current tab number""" - return self._current_tab_nb - - @current_tab_nb.setter - def current_tab_nb(self, value): - """ - Prevents the tab number from going over the total number of opened - tabs, or under 0 - """ - old = self._current_tab_nb - if value >= len(self.tabs): - self._current_tab_nb = 0 - elif value < 0: - self._current_tab_nb = len(self.tabs) - 1 + if type_ is None: + tab = self.tabs.by_name(tab_name) else: - self._current_tab_nb = value - if old != self._current_tab_nb and self.tabs[self._current_tab_nb]: - self.events.trigger('tab_change', old, self._current_tab_nb) + tab = self.tabs.by_name_and_class(tab_name, type_) + if tab: + self.command_win(str(tab.nb)) + return True + return False ### Opening actions ### @@ -1263,7 +1145,7 @@ class Core: self.command.win(str(tab.nb)) return tab # create the new tab - tab = self.get_tab_by_name(room_name, tabs.MucTab) + tab = self.tabs.by_name_and_class(room_name, tabs.MucTab) if not tab: return None new_tab = tabs.PrivateTab(self, complete_jid, tab.own_nick) @@ -1303,8 +1185,8 @@ class Core: this updates the name of all the opened private conversations with him/her """ - tab = self.get_tab_by_name('%s/%s' % (room_name, old_nick), - tabs.PrivateTab) + tab = self.tabs.by_name_and_class('%s/%s' % (room_name, old_nick), + tabs.PrivateTab) if tab: tab.rename_user(old_nick, user) @@ -1314,8 +1196,8 @@ class Core: The user left the MUC: add a message in the associated private conversation """ - tab = self.get_tab_by_name('%s/%s' % (room_name, user.nick), - tabs.PrivateTab) + tab = self.tabs.by_name_and_class('%s/%s' % (room_name, user.nick), + tabs.PrivateTab) if tab: tab.user_left(status_message, user) @@ -1324,8 +1206,8 @@ class Core: The user joined a MUC: add a message in the associated private conversation """ - tab = self.get_tab_by_name('%s/%s' % (room_name, nick), - tabs.PrivateTab) + tab = self.tabs.by_name_and_class('%s/%s' % (room_name, nick), + tabs.PrivateTab) if tab: tab.user_rejoined(nick) @@ -1350,7 +1232,7 @@ class Core: tab.activate(reason=reason) def on_user_changed_status_in_private(self, jid, status): - tab = self.get_tab_by_name(jid, tabs.ChatTab) + tab = self.tabs.by_name_and_class(jid, tabs.ChatTab) if tab is not None: # display the message in private tab.update_status(status) @@ -1360,35 +1242,16 @@ class Core: """ was_current = tab is None if tab is None: - tab = self.current_tab() + tab = self.tabs.current_tab if isinstance(tab, tabs.RosterInfoTab): return # The tab 0 should NEVER be closed tab.on_close() del tab.key_func # Remove self references del tab.commands # and make the object collectable - nb = tab.nb - if was_current: - if self.previous_tab_nb != nb: - self.current_tab_nb = self.previous_tab_nb - self.previous_tab_nb = 0 - if config.get('create_gaps'): - if nb >= len(self.tabs) - 1: - self.tabs.remove(tab) - nb -= 1 - while not self.tabs[nb]: # remove the trailing gaps - self.tabs.pop() - nb -= 1 - else: - self.tabs[nb] = tabs.GapTab(self) - else: - self.tabs.remove(tab) + self.tabs.delete(tab, gap=config.get('create_gaps')) logger.close(tab.name) - if self.current_tab_nb >= len(self.tabs): - self.current_tab_nb = len(self.tabs) - 1 - while not self.tabs[self.current_tab_nb]: - self.current_tab_nb -= 1 if was_current: - self.current_tab().on_gain_focus() + self.tabs.current_tab.on_gain_focus() self.refresh_window() import gc gc.collect() @@ -1401,10 +1264,10 @@ class Core: Search for a ConversationTab with the given jid (full or bare), if yes, add the given message to it """ - tab = self.get_tab_by_name(jid, tabs.ConversationTab) + tab = self.tabs.by_name_and_class(jid, tabs.ConversationTab) if tab is not None: tab.add_message(msg, typ=2) - if self.current_tab() is tab: + if self.tabs.current_tab is tab: self.refresh_window() ####################### Curses and ui-related stuff ########################### @@ -1437,7 +1300,7 @@ class Core: nb_lines = self.information_buffer.add_message( msg, nickname=typ, nick_color=color) popup_on = config.get('information_buffer_popup_on').split() - if isinstance(self.current_tab(), tabs.RosterInfoTab): + if isinstance(self.tabs.current_tab, tabs.RosterInfoTab): self.refresh_window() elif typ != '' and typ.lower() in popup_on: popup_time = config.get('popup_time') + (nb_lines - 1) * 2 @@ -1445,7 +1308,7 @@ class Core: else: if self.information_win_size != 0: self.information_win.refresh() - self.current_tab().refresh_input() + self.tabs.current_tab.refresh_input() return True def _init_curses(self, stdscr): @@ -1479,8 +1342,8 @@ class Core: Refresh everything """ nocursor = curses.curs_set(0) - self.current_tab().state = 'current' - self.current_tab().refresh() + self.tabs.current_tab.state = 'current' + self.tabs.current_tab.refresh() self.doupdate() curses.curs_set(nocursor) @@ -1488,7 +1351,7 @@ class Core: """ Refresh the window containing the tab list """ - self.current_tab().refresh_tab_win() + self.tabs.current_tab.refresh_tab_win() self.refresh_input() self.doupdate() @@ -1496,8 +1359,8 @@ class Core: """ Refresh the input if it exists """ - if self.current_tab().input: - self.current_tab().input.refresh() + if self.tabs.current_tab.input: + self.tabs.current_tab.input.refresh() self.doupdate() def scroll_page_down(self): @@ -1505,7 +1368,7 @@ class Core: Scroll a page down, if possible. Returns True on success, None on failure. """ - if self.current_tab().on_scroll_down(): + if self.tabs.current_tab.on_scroll_down(): self.refresh_window() return True @@ -1514,7 +1377,7 @@ class Core: Scroll a page up, if possible. Returns True on success, None on failure. """ - if self.current_tab().on_scroll_up(): + if self.tabs.current_tab.on_scroll_up(): self.refresh_window() return True @@ -1523,7 +1386,7 @@ class Core: Scroll a line up, if possible. Returns True on success, None on failure. """ - if self.current_tab().on_line_up(): + if self.tabs.current_tab.on_line_up(): self.refresh_window() return True @@ -1532,7 +1395,7 @@ class Core: Scroll a line down, if possible. Returns True on success, None on failure. """ - if self.current_tab().on_line_down(): + if self.tabs.current_tab.on_line_down(): self.refresh_window() return True @@ -1541,7 +1404,7 @@ class Core: Scroll half a screen down, if possible. Returns True on success, None on failure. """ - if self.current_tab().on_half_scroll_up(): + if self.tabs.current_tab.on_half_scroll_up(): self.refresh_window() return True @@ -1550,7 +1413,7 @@ class Core: Scroll half a screen down, if possible. Returns True on success, None on failure. """ - if self.current_tab().on_half_scroll_down(): + if self.tabs.current_tab.on_half_scroll_down(): self.refresh_window() return True @@ -1558,8 +1421,8 @@ class Core: """ Expand the information win a number of lines """ - if self.information_win_size >= self.current_tab().height -5 or \ - self.information_win_size+nb >= self.current_tab().height-4 or\ + if self.information_win_size >= self.tabs.current_tab.height -5 or \ + self.information_win_size+nb >= self.tabs.current_tab.height-4 or\ self.size.core_degrade_y: return 0 self.information_win_size += nb @@ -1588,10 +1451,10 @@ class Core: Scroll the information buffer up """ self.information_win.scroll_up(self.information_win.height) - if not isinstance(self.current_tab(), tabs.RosterInfoTab): + if not isinstance(self.tabs.current_tab, tabs.RosterInfoTab): self.information_win.refresh() else: - info = self.current_tab().information_win + info = self.tabs.current_tab.information_win info.scroll_up(info.height) self.refresh_window() @@ -1600,10 +1463,10 @@ class Core: Scroll the information buffer down """ self.information_win.scroll_down(self.information_win.height) - if not isinstance(self.current_tab(), tabs.RosterInfoTab): + if not isinstance(self.tabs.current_tab, tabs.RosterInfoTab): self.information_win.refresh() else: - info = self.current_tab().information_win + info = self.tabs.current_tab.information_win info.scroll_down(info.height) self.refresh_window() @@ -1710,7 +1573,8 @@ class Core: tab.need_resize = True else: tab.resize() - if self.tabs: + + if len(self.tabs): self.full_screen_redraw() def read_keyboard(self): @@ -2050,7 +1914,7 @@ class Core: for bm in bookmarks: if not (bm.autojoin or config.get('open_all_bookmarks')): continue - tab = self.get_tab_by_name(bm.jid, tabs.MucTab) + tab = self.tabs.by_name_and_class(bm.jid, tabs.MucTab) nick = bm.nick if bm.nick else self.own_nick if not tab: self.open_new_room( @@ -2093,7 +1957,7 @@ class Core: """ Display the error in the tab """ - tab = self.get_tab_by_name(room_name, tabs.MucTab) + tab = self.tabs.by_name_and_class(room_name, tabs.MucTab) if not tab: return error_message = self.get_error_message(error) diff --git a/poezio/core/handlers.py b/poezio/core/handlers.py index ca5a3ca8..fcc0a07e 100644 --- a/poezio/core/handlers.py +++ b/poezio/core/handlers.py @@ -85,7 +85,8 @@ class HandlerCore: if not iq: return features = iq['disco_info']['features'] - rostertab = self.core.get_tab_by_name('Roster', tabs.RosterInfoTab) + rostertab = self.core.tabs.by_name_and_class( + 'Roster', tabs.RosterInfoTab) rostertab.check_blocking(features) rostertab.check_saslexternal(features) if (config.get('enable_carbons') @@ -246,8 +247,8 @@ class HandlerCore: self.core.room_error(message, jid_from.bare) else: text = self.core.get_error_message(message) - p_tab = self.core.get_tab_by_name(jid_from.full, - tabs.PrivateTab) + p_tab = self.core.tabs.by_name_and_class( + jid_from.full, tabs.PrivateTab) if p_tab: p_tab.add_error(text) else: @@ -368,7 +369,7 @@ class HandlerCore: if not own and 'private' in config.get('beep_on').split(): if not config.get_by_tabname('disable_beep', conv_jid.bare): curses.beep() - if self.core.current_tab() is not conversation: + if self.core.tabs.current_tab is not conversation: if not own: conversation.state = 'private' self.core.refresh_tab_win() @@ -655,7 +656,7 @@ class HandlerCore: self.core.room_error(message, room_from) return - tab = self.core.get_tab_by_name(room_from, tabs.MucTab) + tab = self.core.tabs.by_name_and_class(room_from, tabs.MucTab) if not tab: self.core.information( "message received for a non-existing room: %s" % (room_from)) @@ -709,14 +710,14 @@ class HandlerCore: if message['from'].resource == tab.own_nick: tab.last_sent_message = message - if tab is self.core.current_tab(): + if tab is self.core.tabs.current_tab: tab.text_win.refresh() tab.info_header.refresh(tab, tab.text_win, user=tab.own_user) tab.input.refresh() self.core.doupdate() elif tab.state != old_state: self.core.refresh_tab_win() - current = self.core.current_tab() + current = self.core.tabs.current_tab if hasattr(current, 'input') and current.input: current.input.refresh() self.core.doupdate() @@ -747,7 +748,7 @@ class HandlerCore: tmp_dir = get_image_cache() body = xhtml.get_body_from_message_stanza( message, use_xhtml=use_xhtml, extract_images_to=tmp_dir) - tab = self.core.get_tab_by_name( + tab = self.core.tabs.by_name_and_class( jid.full, tabs.PrivateTab) # get the tab with the private conversation ignore = config.get_by_tabname('ignore_private', room_from) @@ -804,7 +805,7 @@ class HandlerCore: if not sent and 'private' in config.get('beep_on').split(): if not config.get_by_tabname('disable_beep', jid.full): curses.beep() - if tab is self.core.current_tab(): + if tab is self.core.tabs.current_tab: self.core.refresh_window() else: tab.state = 'normal' if sent else 'private' @@ -830,8 +831,8 @@ class HandlerCore: def _on_chatstate(self, message, state): if message['type'] == 'chat': if not self._on_chatstate_normal_conversation(message, state): - tab = self.core.get_tab_by_name(message['from'].full, - tabs.PrivateTab) + tab = self.core.tabs.by_name_and_class(message['from'].full, + tabs.PrivateTab) if not tab: return self._on_chatstate_private_conversation(message, state) @@ -846,7 +847,7 @@ class HandlerCore: tab.chatstate = state if state == 'gone' and isinstance(tab, tabs.DynamicConversationTab): tab.unlock() - if tab == self.core.current_tab(): + if tab == self.core.tabs.current_tab: tab.refresh_info_header() self.core.doupdate() else: @@ -858,12 +859,13 @@ class HandlerCore: """ Chatstate received in a private conversation from a MUC """ - tab = self.core.get_tab_by_name(message['from'].full, tabs.PrivateTab) + tab = self.core.tabs.by_name_and_class(message['from'].full, + tabs.PrivateTab) if not tab: return self.core.events.trigger('private_chatstate', message, tab) tab.chatstate = state - if tab == self.core.current_tab(): + if tab == self.core.tabs.current_tab: tab.refresh_info_header() self.core.doupdate() else: @@ -876,11 +878,11 @@ class HandlerCore: """ nick = message['mucnick'] room_from = message.get_mucroom() - tab = self.core.get_tab_by_name(room_from, tabs.MucTab) + tab = self.core.tabs.by_name_and_class(room_from, tabs.MucTab) if tab and tab.get_user_by_name(nick): self.core.events.trigger('muc_chatstate', message, tab) tab.get_user_by_name(nick).chatstate = state - if tab == self.core.current_tab(): + if tab == self.core.tabs.current_tab: if not self.core.size.tab_degrade_x: tab.user_win.refresh(tab.users) tab.input.refresh() @@ -927,7 +929,7 @@ class HandlerCore: else: roster.update_contact_groups(jid) roster.update_size() - if isinstance(self.core.current_tab(), tabs.RosterInfoTab): + if isinstance(self.core.tabs.current_tab, tabs.RosterInfoTab): self.core.refresh_window() def on_subscription_request(self, presence): @@ -950,7 +952,7 @@ class HandlerCore: 'tab to accept or reject the query.' % jid, 'Roster') self.core.get_tab_by_number(0).state = 'highlight' roster.modified() - if isinstance(self.core.current_tab(), tabs.RosterInfoTab): + if isinstance(self.core.tabs.current_tab, tabs.RosterInfoTab): self.core.refresh_window() def on_subscription_authorized(self, presence): @@ -965,7 +967,7 @@ class HandlerCore: roster.modified() - if isinstance(self.core.current_tab(), tabs.RosterInfoTab): + if isinstance(self.core.tabs.current_tab, tabs.RosterInfoTab): self.core.refresh_window() def on_subscription_remove(self, presence): @@ -978,7 +980,7 @@ class HandlerCore: self.core.information( '%s does not want to receive your status anymore.' % jid, 'Roster') self.core.get_tab_by_number(0).state = 'highlight' - if isinstance(self.core.current_tab(), tabs.RosterInfoTab): + if isinstance(self.core.tabs.current_tab, tabs.RosterInfoTab): self.core.refresh_window() def on_subscription_removed(self, presence): @@ -997,7 +999,7 @@ class HandlerCore: '%s does not want you to receive his/her/its status anymore.' % jid, 'Roster') self.core.get_tab_by_number(0).state = 'highlight' - if isinstance(self.core.current_tab(), tabs.RosterInfoTab): + if isinstance(self.core.tabs.current_tab, tabs.RosterInfoTab): self.core.refresh_window() ### Presence-related handlers ### @@ -1024,9 +1026,9 @@ class HandlerCore: if tab: tab.update_status( Status(show=presence['show'], message=presence['status'])) - if isinstance(self.core.current_tab(), tabs.RosterInfoTab): + if isinstance(self.core.tabs.current_tab, tabs.RosterInfoTab): self.core.refresh_window() - elif self.core.current_tab() == tab: + elif self.core.tabs.current_tab == tab: tab.refresh() self.core.doupdate() @@ -1037,8 +1039,7 @@ class HandlerCore: return roster.modified() contact.error = presence['error']['type'] + ': ' + presence['error']['condition'] - # reset chat states status on presence error - tab = self.core.get_tab_by_name(jid.full, tabs.ConversationTab) + # TODO: reset chat states status on presence error def on_got_offline(self, presence): """ @@ -1066,7 +1067,7 @@ class HandlerCore: self.core.information('\x193}%s \x195}is \x191}offline' % name, 'Roster') roster.modified() - if isinstance(self.core.current_tab(), tabs.RosterInfoTab): + if isinstance(self.core.tabs.current_tab, tabs.RosterInfoTab): self.core.refresh_window() def on_got_online(self, presence): @@ -1106,7 +1107,7 @@ class HandlerCore: "\x193}%s \x195}is \x194}online\x195}" % name, "Roster") self.core.add_information_message_to_conversation_tab( jid.bare, '\x195}%s is \x194}online' % name) - if isinstance(self.core.current_tab(), tabs.RosterInfoTab): + if isinstance(self.core.tabs.current_tab, tabs.RosterInfoTab): self.core.refresh_window() def on_groupchat_presence(self, presence): @@ -1116,7 +1117,7 @@ class HandlerCore: presence information of the concerned user """ from_room = presence['from'].bare - tab = self.core.get_tab_by_name(from_room, tabs.MucTab) + tab = self.core.tabs.by_name_and_class(from_room, tabs.MucTab) if tab: self.core.events.trigger('muc_presence', presence, tab) tab.handle_presence(presence) @@ -1227,7 +1228,7 @@ class HandlerCore: Those are received when a room configuration change occurs. """ room_from = message['from'] - tab = self.core.get_tab_by_name(room_from, tabs.MucTab) + tab = self.core.tabs.by_name_and_class(room_from, tabs.MucTab) status_codes = { s.attrib['code'] for s in message.xml.findall('{%s}x/{%s}status' % @@ -1321,7 +1322,7 @@ class HandlerCore: """ nick_from = message['mucnick'] room_from = message.get_mucroom() - tab = self.core.get_tab_by_name(room_from, tabs.MucTab) + tab = self.core.tabs.by_name_and_class(room_from, tabs.MucTab) subject = message['subject'] if subject is None or not tab: return @@ -1363,8 +1364,8 @@ class HandlerCore: typ=2) tab.topic = subject tab.topic_from = nick_from - if self.core.get_tab_by_name(room_from, - tabs.MucTab) is self.core.current_tab(): + if self.core.tabs.by_name_and_class( + room_from, tabs.MucTab) is self.core.tabs.current_tab: self.core.refresh_window() def on_receipt(self, message): @@ -1376,8 +1377,9 @@ class HandlerCore: if not msg_id: return - conversation = self.core.get_tab_by_name(jid.full, tabs.OneToOneTab) - conversation = conversation or self.core.get_tab_by_name( + conversation = self.core.tabs.by_name_and_class( + jid.full, tabs.OneToOneTab) + conversation = conversation or self.core.tabs.by_name_and_class( jid.bare, tabs.OneToOneTab) if not conversation: log.error("Received ack from non-existing chat tab: %s", jid) @@ -1437,8 +1439,8 @@ class HandlerCore: except: log.debug('', exc_info=True) - if isinstance(self.core.current_tab(), tabs.XMLTab): - self.core.current_tab().refresh() + if isinstance(self.core.tabs.current_tab, tabs.XMLTab): + self.core.tabs.current_tab.refresh() self.core.doupdate() def incoming_stanza(self, stanza): @@ -1464,8 +1466,8 @@ class HandlerCore: nickname=get_theme().CHAR_XML_IN) except: log.debug('', exc_info=True) - if isinstance(self.core.current_tab(), tabs.XMLTab): - self.core.current_tab().refresh() + if isinstance(self.core.tabs.current_tab, tabs.XMLTab): + self.core.tabs.current_tab.refresh() self.core.doupdate() def ssl_invalid_chain(self, tb): diff --git a/poezio/plugin.py b/poezio/plugin.py index ff675026..78996788 100644 --- a/poezio/plugin.py +++ b/poezio/plugin.py @@ -202,7 +202,7 @@ class PluginAPI: :returns: The current tab. """ - return self.core.current_tab() + return self.core.tabs.current_tab def get_status(self, _): """ @@ -219,7 +219,7 @@ class PluginAPI: :param str line: The command to run. """ - return self.core.current_tab().execute_command(*args, **kwargs) + return self.core.tabs.current_tab.execute_command(*args, **kwargs) def all_tabs(self, _): """ diff --git a/poezio/tabs/adhoc_commands_list.py b/poezio/tabs/adhoc_commands_list.py index a1b186be..fecfc9e2 100644 --- a/poezio/tabs/adhoc_commands_list.py +++ b/poezio/tabs/adhoc_commands_list.py @@ -58,7 +58,7 @@ class AdhocCommandsListTab(ListTab): for item in get_items()] self.listview.set_lines(items) self.info_header.message = 'Ad-hoc commands of JID %s' % self.name - if self.core.current_tab() is self: + if self.core.tabs.current_tab is self: self.refresh() else: self.state = 'highlight' diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py index 9ba8e6e5..34945c27 100644 --- a/poezio/tabs/basetabs.py +++ b/poezio/tabs/basetabs.py @@ -92,6 +92,7 @@ class Tab: def __init__(self, core): self.core = core + self.nb = 0 if not hasattr(self, 'name'): self.name = self.__class__.__name__ self.input = None @@ -108,13 +109,6 @@ class Tab: def size(self): return self.core.size - @property - def nb(self): - for index, tab in enumerate(self.core.tabs): - if tab == self: - return index - return len(self.core.tabs) - @staticmethod def tab_win_height(): """ diff --git a/poezio/tabs/muclisttab.py b/poezio/tabs/muclisttab.py index e12d24ee..6ba7816d 100644 --- a/poezio/tabs/muclisttab.py +++ b/poezio/tabs/muclisttab.py @@ -59,7 +59,7 @@ class MucListTab(ListTab): for item in get_items()] self.listview.set_lines(items) self.info_header.message = 'Chatroom list on server %s' % self.name - if self.core.current_tab() is self: + if self.core.tabs.current_tab is self: self.refresh() else: self.state = 'highlight' diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py index 60d5a64b..246606e3 100644 --- a/poezio/tabs/muctab.py +++ b/poezio/tabs/muctab.py @@ -429,7 +429,7 @@ class MucTab(ChatTab): self.handle_presence_joined(presence, status_codes) except PresenceError: self.core.room_error(presence, presence['from'].bare) - if self.core.current_tab() is self: + if self.core.tabs.current_tab is self: self.text_win.refresh() self.user_win.refresh_if_changed(self.users) self.info_header.refresh(self, self.text_win, user=self.own_user) @@ -453,9 +453,9 @@ class MucTab(ChatTab): # Enable the self ping event, to regularly check if we # are still in the room. self.enable_self_ping_event() - if self.core.current_tab() is not self: + if self.core.tabs.current_tab is not self: self.refresh_tab_win() - self.core.current_tab().refresh_input() + self.core.tabs.current_tab.refresh_input() self.core.doupdate() def handle_presence_unjoined(self, presence, deterministic, own=False): @@ -487,9 +487,9 @@ class MucTab(ChatTab): if self.name in self.core.initial_joins: self.core.initial_joins.remove(self.name) self._state = 'normal' - elif self != self.core.current_tab(): + elif self != self.core.tabs.current_tab: self._state = 'joined' - if (self.core.current_tab() is self + if (self.core.tabs.current_tab is self and self.core.status.show not in ('xa', 'away')): self.send_chat_state('active') new_user.color = get_theme().COLOR_OWN_NICK @@ -721,7 +721,7 @@ class MucTab(ChatTab): self.core.disable_private_tabs(self.name, reason=kick_msg) self.disconnect() self.refresh_tab_win() - self.core.current_tab().refresh_input() + self.core.tabs.current_tab.refresh_input() if config.get_by_tabname('autorejoin', self.general_jid): delay = config.get_by_tabname('autorejoin_delay', self.general_jid) @@ -799,7 +799,7 @@ class MucTab(ChatTab): self.core.disable_private_tabs(self.name, reason=kick_msg) self.disconnect() self.refresh_tab_win() - self.core.current_tab().refresh_input() + self.core.tabs.current_tab.refresh_input() # try to auto-rejoin if config.get_by_tabname('autorejoin', self.general_jid): delay = config.get_by_tabname('autorejoin_delay', @@ -972,7 +972,7 @@ class MucTab(ChatTab): """ self.presence_buffer = [] self.users = [] - if self is not self.core.current_tab(): + if self is not self.core.tabs.current_tab: self.state = 'disconnected' self.joined = False self.disable_self_ping_event() @@ -1376,7 +1376,7 @@ class MucTab(ChatTab): """ message = args[0] self.leave_room(message) - if self == self.core.current_tab(): + if self == self.core.tabs.current_tab: self.refresh() self.core.doupdate() @@ -1406,7 +1406,7 @@ class MucTab(ChatTab): r = self.core.open_private_window(self.name, user.nick) if r and len(args) == 2: msg = args[1] - self.core.current_tab().command_say( + self.core.tabs.current_tab.command_say( xhtml.convert_simple_to_full_colors(msg)) if not r: self.core.information("Cannot find user: %s" % nick, 'Error') diff --git a/poezio/tabs/privatetab.py b/poezio/tabs/privatetab.py index d2d2f5ac..bc7f31c7 100644 --- a/poezio/tabs/privatetab.py +++ b/poezio/tabs/privatetab.py @@ -60,7 +60,8 @@ class PrivateTab(OneToOneTab): 'Get the software version of the current interlocutor (usually its XMPP client and Operating System).', shortdesc='Get the software version of a jid.') self.resize() - self.parent_muc = self.core.get_tab_by_name(safeJID(name).bare, MucTab) + self.parent_muc = self.core.tabs.by_name_and_class( + safeJID(name).bare, MucTab) self.on = True self.update_commands() self.update_keys() @@ -275,7 +276,7 @@ class PrivateTab(OneToOneTab): empty_after = self.input.get_text() == '' or ( self.input.get_text().startswith('/') and not self.input.get_text().startswith('//')) - tab = self.core.get_tab_by_name(safeJID(self.name).bare, MucTab) + tab = self.core.tabs.by_name_and_class(safeJID(self.name).bare, MucTab) if tab and tab.joined: self.send_composing_chat_state(empty_after) return False @@ -288,7 +289,7 @@ class PrivateTab(OneToOneTab): self.text_win.remove_line_separator() self.text_win.add_line_separator(self._text_buffer) - tab = self.core.get_tab_by_name(safeJID(self.name).bare, MucTab) + tab = self.core.tabs.by_name_and_class(safeJID(self.name).bare, MucTab) if tab and tab.joined and config.get_by_tabname( 'send_chat_states', self.general_jid) and self.on: self.send_chat_state('inactive') @@ -297,7 +298,7 @@ class PrivateTab(OneToOneTab): def on_gain_focus(self): self.state = 'current' curses.curs_set(1) - tab = self.core.get_tab_by_name(safeJID(self.name).bare, MucTab) + tab = self.core.tabs.by_name_and_class(safeJID(self.name).bare, MucTab) if tab and tab.joined and config.get_by_tabname( 'send_chat_states', self.general_jid, @@ -334,7 +335,7 @@ class PrivateTab(OneToOneTab): typ=2) new_jid = safeJID(self.name).bare + '/' + user.nick self.name = new_jid - return self.core.current_tab() is self + return self.core.tabs.current_tab is self @refresh_wrapper.conditional def user_left(self, status_message, user): @@ -372,7 +373,7 @@ class PrivateTab(OneToOneTab): 'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT) }, typ=2) - return self.core.current_tab() is self + return self.core.tabs.current_tab is self @refresh_wrapper.conditional def user_rejoined(self, nick): @@ -398,7 +399,7 @@ class PrivateTab(OneToOneTab): 'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT) }, typ=2) - return self.core.current_tab() is self + return self.core.tabs.current_tab is self def activate(self, reason=None): self.on = True diff --git a/poezio/tabs/rostertab.py b/poezio/tabs/rostertab.py index 6aba2c15..2941159c 100644 --- a/poezio/tabs/rostertab.py +++ b/poezio/tabs/rostertab.py @@ -1150,7 +1150,7 @@ class RosterInfoTab(Tab): def reset_help_message(self, _=None): self.input = self.default_help_message - if self.core.current_tab() is self: + if self.core.tabs.current_tab is self: curses.curs_set(0) self.input.refresh() self.core.doupdate() diff --git a/poezio/tabs/xmltab.py b/poezio/tabs/xmltab.py index fc04f778..c4a50df8 100644 --- a/poezio/tabs/xmltab.py +++ b/poezio/tabs/xmltab.py @@ -286,7 +286,7 @@ class XMLTab(Tab): def reset_help_message(self, _=None): if self.closed: return True - if self.core.current_tab() is self: + if self.core.tabs.current_tab is self: curses.curs_set(0) self.input = self.default_help_message return True diff --git a/poezio/windows/info_bar.py b/poezio/windows/info_bar.py index 950813f1..6e338a78 100644 --- a/poezio/windows/info_bar.py +++ b/poezio/windows/info_bar.py @@ -26,18 +26,12 @@ class GlobalInfoBar(Win): self.addstr(0, 0, "[", to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) - create_gaps = config.get('create_gaps') show_names = config.get('show_tab_names') show_nums = config.get('show_tab_numbers') use_nicks = config.get('use_tab_nicks') show_inactive = config.get('show_inactive_tabs') - # ignore any remaining gap tabs if the feature is not enabled - if create_gaps: - sorted_tabs = self.core.tabs[:] - else: - sorted_tabs = [tab for tab in self.core.tabs if tab] - for nb, tab in enumerate(sorted_tabs): + for nb, tab in enumerate(self.core.tabs): if not tab: continue color = tab.color if not show_inactive and color is get_theme().COLOR_TAB_NORMAL: |