From 4e7eb41cb9d67a427c531d461456d73dbc967cad Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 9 May 2014 11:45:20 +0200 Subject: [PATCH] Add command tab_move (gm/gl/gr) --- TODO | 9 ------ qutebrowser/config/configdata.py | 3 ++ qutebrowser/widgets/_tabbedbrowser.py | 41 +++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/TODO b/TODO index 0508bf61a..18950e39f 100644 --- a/TODO +++ b/TODO @@ -287,15 +287,6 @@ tab-handling C-Tab Toggle between current and last focused tab (command toggle_tab, aliases: ttab) -[n]gm -Move current tab to position [n] or to first position if n is omitted. (command tab_move, aliases: tabm). - -[n]gl -Move current tab [n] positions left. (command tab_move_left, aliases: tabl). - -[n]gr -Move current tab [n] positions right. (command tab_move_right, aliases: tabr). - gt Show all open tabs. (command buffers, aliases: bu). diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index c6d55023a..9df420fcd 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -549,6 +549,9 @@ DATA = OrderedDict([ ('d', 'tabclose'), ('co', 'only'), ('T', 'focus_tab'), + ('gm', 'tab_move'), + ('gl', 'tab_move -'), + ('gr', 'tab_move +'), ('J', 'tabnext'), ('K', 'tabprev'), ('r', 'reload'), diff --git a/qutebrowser/widgets/_tabbedbrowser.py b/qutebrowser/widgets/_tabbedbrowser.py index b1ccc1917..76f0e1bcd 100644 --- a/qutebrowser/widgets/_tabbedbrowser.py +++ b/qutebrowser/widgets/_tabbedbrowser.py @@ -387,6 +387,47 @@ class TabbedBrowser(TabWidget): message.error("There's no tab with index {}!".format(idx)) return + @cmdutils.register(instance='mainwindow.tabs') + def tab_move(self, direction=None, count=None): + """Move the current tab. + + Args: + direction: + or - for relative moving, None for absolute. + count: If moving absolutely: New position (or first). + If moving relatively: Offset. + """ + cur_idx = self.currentIndex() + if direction is None: + # absolute move + if count is None: + new_idx = 0 + elif count == 0: + new_idx = self.count() - 1 + else: + new_idx = count - 1 + elif direction in '+-': + # relative move + if count is None: + message.error("Count must be given for relative moving!") + return + if direction == '-': + new_idx = cur_idx - count + elif direction == '+': + new_idx = cur_idx + count + else: + message.error("Invalid direction '{}'!".format(direction)) + return + if not 0 <= new_idx < self.count(): + message.error("Can't move tab to position {}!".format(new_idx)) + return + tab = self.currentWidget() + icon = self.tabIcon(cur_idx) + label = self.tabText(cur_idx) + self.removeTab(cur_idx) + self.insertTab(new_idx, tab, icon, label) + self.setCurrentIndex(new_idx) + + @pyqtSlot(str, str) def on_config_changed(self, section, option): """Update tab config when config was changed."""