Add focus_tab command

This commit is contained in:
Florian Bruhin 2014-05-03 00:32:43 +02:00
parent 0d1ada27fd
commit 8ada39ff8b
3 changed files with 26 additions and 1 deletions

1
TODO
View File

@ -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

View File

@ -505,6 +505,15 @@ DATA = OrderedDict([
('<Ctrl-B>', 'scroll_page 0 -1'),
('<Ctrl-D>', 'scroll_page 0 0.5'),
('<Ctrl-U>', 'scroll_page 0 -0.5'),
('<Alt-1>', 'focus_tab 1'),
('<Alt-2>', 'focus_tab 2'),
('<Alt-3>', 'focus_tab 3'),
('<Alt-4>', 'focus_tab 4'),
('<Alt-5>', 'focus_tab 5'),
('<Alt-6>', 'focus_tab 6'),
('<Alt-7>', 'focus_tab 7'),
('<Alt-8>', 'focus_tab 8'),
('<Alt-9>', 'focus_tab 9'),
('<Backspace>', 'back'),
('<Left>', '${h}'),
('<Down>', '${j}'),

View File

@ -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."""