From 8ada39ff8bd430bb11e2525478e5adbdd6efca17 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sat, 3 May 2014 00:32:43 +0200 Subject: [PATCH] Add focus_tab command --- TODO | 1 - qutebrowser/config/configdata.py | 9 +++++++++ qutebrowser/widgets/_tabbedbrowser.py | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index e66e90865..a820a8fc5 100644 --- a/TODO +++ b/TODO @@ -48,7 +48,6 @@ somehow unfocus elements (hide blinking cursor) when insert mode is left? tabs: some more padding? exec command for shell custom stylesheet -Alt+N to focus tab N Really fix URL detection properly hints diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 798232bd6..50a615761 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -505,6 +505,15 @@ DATA = OrderedDict([ ('', 'scroll_page 0 -1'), ('', 'scroll_page 0 0.5'), ('', 'scroll_page 0 -0.5'), + ('', 'focus_tab 1'), + ('', 'focus_tab 2'), + ('', 'focus_tab 3'), + ('', 'focus_tab 4'), + ('', 'focus_tab 5'), + ('', 'focus_tab 6'), + ('', 'focus_tab 7'), + ('', 'focus_tab 8'), + ('', 'focus_tab 9'), ('', 'back'), ('', '${h}'), ('', '${j}'), diff --git a/qutebrowser/widgets/_tabbedbrowser.py b/qutebrowser/widgets/_tabbedbrowser.py index c80f3dbcb..5709d7ff0 100644 --- a/qutebrowser/widgets/_tabbedbrowser.py +++ b/qutebrowser/widgets/_tabbedbrowser.py @@ -322,6 +322,23 @@ class TabbedBrowser(TabWidget): """ self.paste(sel, True) + @cmdutils.register(instance='mainwindow.tabs') + def focus_tab(self, arg=None, count=None): + if ((arg is None and count is None) or + (arg is not None and count is not None)): + message.error("Either argument or count must be given!") + return + try: + idx = int(arg) if arg is not None else count + except ValueError: + message.error("Invalid argument: {}".format(arg)) + return + if 1 <= idx <= self.count(): + self.setCurrentIndex(idx - 1) + else: + message.error("Index out of bounds!") + return + @pyqtSlot(str, str) def on_config_changed(self, section, option): """Update tab config when config was changed."""