Пример #1
0
    def command_reorder(self) -> None:
        """
        /reorder
        """
        tabs_spec = parse_config(self.config)
        if not tabs_spec:
            self.api.information('Invalid reorder config', 'Error')
            return None

        old_tabs = self.core.tabs.get_tabs()
        roster = old_tabs.pop(0)

        create_gaps = config.get('create_gaps')

        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 - 1)
                ]
            cls, jid = tabs_spec[pos]
            try:
                jid = JID(jid)
                tab = self.core.tabs.by_name_and_class(str(jid), cls=cls)
                if tab and tab in old_tabs:
                    new_tabs.append(tab)
                    old_tabs.remove(tab)
                else:
                    self.api.information('Tab %s not found. Creating it' % jid,
                                         'Warning')
                    # TODO: Add support for MucTab. Requires nickname.
                    if cls in (tabs.DynamicConversationTab,
                               tabs.StaticConversationTab):
                        new_tab = cls(self.core, jid)
                        new_tabs.append(new_tab)
                    else:
                        new_tabs.append(tabs.GapTab(self.core))
            except:
                self.api.information('Failed to create tab \'%s\'.' % jid,
                                     'Error')
                if create_gaps:
                    new_tabs.append(tabs.GapTab(self.core))
            finally:
                last = pos

        for tab in old_tabs:
            if tab:
                new_tabs.append(tab)

        # TODO: Ensure we don't break poezio and call this with whatever
        # tablist we have. The roster tab at least needs to be in there.
        self.core.tabs.replace_tabs(new_tabs)
        self.core.refresh_window()

        return None
Пример #2
0
    def delete(self, tab: tabs.Tab, gap=False):
        """Remove a tab"""
        if isinstance(tab, tabs.RosterInfoTab):
            return

        if gap:
            self._tabs[tab.nb] = tabs.GapTab(None)
        else:
            self._tabs.remove(tab)

        is_current = tab is self.current_tab

        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:
            self._collect_trailing_gaptabs()
        else:
            self._update_numbers()

        if tab is self._previous_tab:
            self._previous_tab = None
        if is_current:
            self.restore_previous_tab()
            self._previous_tab = None
        self._validate_current_index()
Пример #3
0
    def command_reorder(self):
        """
        /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]

        create_gaps = config.get('create_gaps')

        new_tabs = []
        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)]
            cls, name = tabs_spec[pos]
            tab = self.core.get_tab_by_name(name, typ=cls)
            if tab and tab in old_tabs:
                new_tabs.append(tab)
                old_tabs.remove(tab)
            else:
                self.api.information('Tab %s not found' % name, 'Warning')
                if create_gaps:
                    new_tabs.append(tabs.GapTab(self.core))
            last = pos

        for tab in old_tabs:
            if tab:
                new_tabs.append(tab)

        self.core.tabs.clear()
        self.core.tabs.append(roster)
        self.core.tabs += new_tabs

        self.core.refresh_window()
Пример #4
0
 def _insert_gaps(self, old_pos: int, new_pos: int) -> bool:
     """
     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(None)
         else:
             self._tabs.append(self._tabs[old_pos])
             self._tabs[old_pos] = tabs.GapTab(None)
     else:
         if new_pos > old_pos:
             self._tabs.insert(new_pos, tab)
             self._tabs[old_pos] = tabs.GapTab(None)
         elif new_pos < old_pos:
             self._tabs[old_pos] = tabs.GapTab(None)
             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
     self._collect_trailing_gaptabs()
     return True
Пример #5
0
    def command_reorder(self):
        """
        /reorder
        """
        tabs_spec = parse_config(self.config)
        if not tabs_spec:
            return self.api.information('Invalid reorder config', 'Error')

        old_tabs = self.core.tabs.get_tabs()
        roster = old_tabs.pop(0)

        create_gaps = config.get('create_gaps')

        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 - 1)
                ]
            cls, name = tabs_spec[pos]
            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)
            else:
                self.api.information('Tab %s not found' % name, 'Warning')
                if create_gaps:
                    new_tabs.append(tabs.GapTab(self.core))
            last = pos

        for tab in old_tabs:
            if tab:
                new_tabs.append(tab)

        self.core.tabs.replace_tabs(new_tabs)
        self.core.refresh_window()