New command: tab_focus_last / Ctrl-Tab

This commit is contained in:
Florian Bruhin 2014-05-09 11:57:58 +02:00
parent 4e7eb41cb9
commit 96d456fdee
3 changed files with 22 additions and 5 deletions

3
TODO
View File

@ -284,9 +284,6 @@ Open quickmark in a new tab (command tab_quickmark, aliases: tabqmarks).
tab-handling
------------
C-Tab
Toggle between current and last focused tab (command toggle_tab, aliases: ttab)
gt
Show all open tabs. (command buffers, aliases: bu).

View File

@ -593,6 +593,7 @@ DATA = OrderedDict([
(']]', 'nextpage'),
('{{', 'tabprevpage'),
('}}', 'tabnextpage'),
('<Ctrl-Tab>', 'tab_focus_last'),
('<Ctrl-V>', 'enter_mode passthrough'),
('<Ctrl-Q>', 'quit'),
('<Ctrl-Shift-T>', 'undo'),

View File

@ -54,6 +54,8 @@ class TabbedBrowser(TabWidget):
_filter: A SignalFilter instance.
cur: A CurCommandDispatcher instance to dispatch commands to the
current tab.
last_focused: The tab which was focused last.
now_focused: The tab which is focused now.
Signals:
cur_progress: Progress of the current tab changed (loadProgress).
@ -89,13 +91,14 @@ class TabbedBrowser(TabWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.currentChanged.connect(lambda idx:
self.widget(idx).signal_cache.replay())
self.currentChanged.connect(self.on_current_changed)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self._tabs = []
self._url_stack = []
self._filter = SignalFilter(self)
self.cur = CurCommandDispatcher(self)
self.last_focused = None
self.now_focused = None
# FIXME adjust this to font size
self.setIconSize(QSize(12, 12))
@ -427,6 +430,14 @@ class TabbedBrowser(TabWidget):
self.insertTab(new_idx, tab, icon, label)
self.setCurrentIndex(new_idx)
@cmdutils.register(instance='mainwindow.tabs')
def tab_focus_last(self):
"""Focus the tab which was last focused."""
idx = self.indexOf(self.last_focused)
if idx == -1:
message.error("Last focused tab vanished!")
return
self.setCurrentIndex(idx)
@pyqtSlot(str, str)
def on_config_changed(self, section, option):
@ -482,6 +493,14 @@ class TabbedBrowser(TabWidget):
if mode == "command":
self.setFocus()
@pyqtSlot(int)
def on_current_changed(self, idx):
"""Set last_focused and replay signal cache if focus changed."""
tab = self.widget(idx)
tab.signal_cache.replay()
self.last_focused = self.now_focused
self.now_focused = tab
def resizeEvent(self, e):
"""Extend resizeEvent of QWidget to emit a resized signal afterwards.