Use object registry for last focused tab.

This commit is contained in:
Florian Bruhin 2014-09-24 06:41:51 +02:00
parent 6090bf418d
commit b121ceef21
2 changed files with 11 additions and 10 deletions

View File

@ -38,7 +38,7 @@ from qutebrowser.commands import userscripts, cmdexc, cmdutils
from qutebrowser.config import config from qutebrowser.config import config
from qutebrowser.browser import hints, quickmarks, webelem from qutebrowser.browser import hints, quickmarks, webelem
from qutebrowser.utils import (message, editor, usertypes, log, qtutils, from qutebrowser.utils import (message, editor, usertypes, log, qtutils,
urlutils) urlutils, utils)
class CommandDispatcher: class CommandDispatcher:
@ -52,7 +52,6 @@ class CommandDispatcher:
cmdutils.register() decorators are run, currentWidget() will return None. cmdutils.register() decorators are run, currentWidget() will return None.
Attributes: Attributes:
_tabs: The TabbedBrowser object.
_editor: The ExternalEditor object. _editor: The ExternalEditor object.
""" """
@ -143,9 +142,11 @@ class CommandDispatcher:
def _tab_focus_last(self): def _tab_focus_last(self):
"""Select the tab which was last focused.""" """Select the tab which was last focused."""
if self._tabs.last_focused is None: try:
tab = utils.get_object('last-focused-tab')
except KeyError:
raise cmdexc.CommandError("No last focused tab!") raise cmdexc.CommandError("No last focused tab!")
idx = self._tabs.indexOf(self._tabs.last_focused) idx = self._tabs.indexOf(tab)
if idx == -1: if idx == -1:
raise cmdexc.CommandError("Last focused tab vanished!") raise cmdexc.CommandError("Last focused tab vanished!")
self._tabs.setCurrentIndex(idx) self._tabs.setCurrentIndex(idx)

View File

@ -54,7 +54,6 @@ class TabbedBrowser(tabwidget.TabWidget):
tabbar -> new-tab-position set to 'left'. tabbar -> new-tab-position set to 'left'.
_tab_insert_idx_right: Same as above, for 'right'. _tab_insert_idx_right: Same as above, for 'right'.
url_stack: Stack of URLs of closed tabs. url_stack: Stack of URLs of closed tabs.
last_focused: The tab which was focused last.
Signals: Signals:
cur_progress: Progress of the current tab changed (loadProgress). cur_progress: Progress of the current tab changed (loadProgress).
@ -111,7 +110,6 @@ class TabbedBrowser(tabwidget.TabWidget):
self._filter = signalfilter.SignalFilter(self) self._filter = signalfilter.SignalFilter(self)
dispatcher = commands.CommandDispatcher(self) dispatcher = commands.CommandDispatcher(self)
utils.register_object('command-dispatcher', dispatcher) utils.register_object('command-dispatcher', dispatcher)
self.last_focused = None
self._now_focused = None self._now_focused = None
# FIXME adjust this to font size # FIXME adjust this to font size
self.setIconSize(QSize(12, 12)) self.setIconSize(QSize(12, 12))
@ -263,8 +261,8 @@ class TabbedBrowser(tabwidget.TabWidget):
tab)) tab))
if tab is self._now_focused: if tab is self._now_focused:
self._now_focused = None self._now_focused = None
if tab is self.last_focused: if tab is utils.get_object('last-focused-tab', None):
self.last_focused = None utils.delete_object('last-focused-tab')
if not tab.cur_url.isEmpty(): if not tab.cur_url.isEmpty():
qtutils.ensure_valid(tab.cur_url) qtutils.ensure_valid(tab.cur_url)
self.url_stack.append(tab.cur_url) self.url_stack.append(tab.cur_url)
@ -522,11 +520,13 @@ class TabbedBrowser(tabwidget.TabWidget):
@pyqtSlot(int) @pyqtSlot(int)
def on_current_changed(self, idx): def on_current_changed(self, idx):
"""Set last_focused and leave hinting mode when focus changed.""" """Set last-focused-tab and leave hinting mode when focus changed."""
tab = self.widget(idx) tab = self.widget(idx)
tab.setFocus() tab.setFocus()
modeman.maybe_leave(usertypes.KeyMode.hint, 'tab changed') modeman.maybe_leave(usertypes.KeyMode.hint, 'tab changed')
self.last_focused = self._now_focused if self._now_focused is not None:
utils.register_object('last-focused-tab', self._now_focused,
update=True)
self._now_focused = tab self._now_focused = tab
self.current_tab_changed.emit(tab) self.current_tab_changed.emit(tab)
self.title_changed.emit('{} - qutebrowser'.format(self.tabText(idx))) self.title_changed.emit('{} - qutebrowser'.format(self.tabText(idx)))