Merge branch 'haasn-lastvisible'

This commit is contained in:
Florian Bruhin 2016-08-10 19:58:41 +02:00
commit 08d9243c3e
6 changed files with 34 additions and 1 deletions

View File

@ -58,6 +58,8 @@ Changed
- With `new-instance-open-target` set to a tab option, the tab is now opened in - With `new-instance-open-target` set to a tab option, the tab is now opened in
the most recently focused (instead of the last opened) window. This can be the most recently focused (instead of the last opened) window. This can be
configured with the new `new-instance-open-target.window` setting. configured with the new `new-instance-open-target.window` setting.
It can also be set to `last-visible` to show the pages in the most recently
visible window.
- Word hints now are more clever about getting the element text from some elements. - Word hints now are more clever about getting the element text from some elements.
- Completions for `:help` and `:bind` now also show hidden commands - Completions for `:help` and `:bind` now also show hidden commands
- The `:buffer` completion now also filters using the first column (id). - The `:buffer` completion now also filters using the first column (id).

View File

@ -456,6 +456,7 @@ Valid values:
* +last-opened+: Open new tabs in the last opened window. * +last-opened+: Open new tabs in the last opened window.
* +last-focused+: Open new tabs in the most recently focused window. * +last-focused+: Open new tabs in the most recently focused window.
* +last-visible+: Open new tabs in the most recently visible window.
Default: +pass:[last-focused]+ Default: +pass:[last-focused]+

View File

@ -350,6 +350,9 @@ def on_focus_changed(_old, new):
window = new.window() window = new.window()
if isinstance(window, mainwindow.MainWindow): if isinstance(window, mainwindow.MainWindow):
objreg.register('last-focused-main-window', window, update=True) objreg.register('last-focused-main-window', window, update=True)
# A focused window must also be visible, and in this case we should
# consider it as the most recently looked-at window
objreg.register('last-visible-main-window', window, update=True)
def open_desktopservices_url(url): def open_desktopservices_url(url):

View File

@ -233,7 +233,9 @@ def data(readonly=False):
('last-opened', "Open new tabs in the last opened " ('last-opened', "Open new tabs in the last opened "
"window."), "window."),
('last-focused', "Open new tabs in the most recently " ('last-focused', "Open new tabs in the most recently "
"focused window.") "focused window."),
('last-visible', "Open new tabs in the most recently "
"visible window.")
)), 'last-focused'), )), 'last-focused'),
"Which window to choose when opening links as new tabs."), "Which window to choose when opening links as new tabs."),

View File

@ -74,6 +74,8 @@ def get_window(via_ipc, force_window=False, force_tab=False,
window = objreg.last_focused_window() window = objreg.last_focused_window()
elif win_mode == 'last-opened': elif win_mode == 'last-opened':
window = objreg.last_window() window = objreg.last_window()
elif win_mode == 'last-visible':
window = objreg.last_visible_window()
except objreg.NoWindow: except objreg.NoWindow:
# There is no window left, so we open a new one # There is no window left, so we open a new one
window = MainWindow() window = MainWindow()
@ -458,8 +460,23 @@ class MainWindow(QWidget):
self._downloadview.updateGeometry() self._downloadview.updateGeometry()
self.tabbed_browser.tabBar().refresh() self.tabbed_browser.tabBar().refresh()
def showEvent(self, e):
"""Extend showEvent to register us as the last-visible-main-window.
Args:
e: The QShowEvent
"""
super().showEvent(e)
objreg.register('last-visible-main-window', self, update=True)
def _do_close(self): def _do_close(self):
"""Helper function for closeEvent.""" """Helper function for closeEvent."""
last_visible = objreg.get('last-visible-main-window')
if self is last_visible:
try:
objreg.delete('last-visible-main-window')
except KeyError:
pass
objreg.get('session-manager').save_last_window_session() objreg.get('session-manager').save_last_window_session()
self._save_geometry() self._save_geometry()
log.destroy.debug("Closing window {}".format(self.win_id)) log.destroy.debug("Closing window {}".format(self.win_id))

View File

@ -285,6 +285,14 @@ def dump_objects():
return lines return lines
def last_visible_window():
"""Get the last visible window, or the last focused window if none."""
try:
return get('last-visible-main-window')
except KeyError:
return last_focused_window()
def last_focused_window(): def last_focused_window():
"""Get the last focused window, or the last window if none.""" """Get the last focused window, or the last window if none."""
try: try: