Add new-instance-open-target.window setting

This adds the ability to open new tabs in the last-focused window
instead, which fixes #1801.

Right now the only other option is probably not that useful for human
users but it's required to make tests behave deterministically and
consistently. (But with #881 on the roadmap, I would implement this as
another choice)

To this end, also make the test framework set this option to preserve
the invariant against which existing tests are written: that spawning a
new window would effectively also focus it.
This commit is contained in:
Niklas Haas 2016-08-09 20:23:56 +02:00
parent 2223a285ef
commit 6d181e5c6f
No known key found for this signature in database
GPG Key ID: 9A09076581B27402
4 changed files with 25 additions and 5 deletions

View File

@ -227,6 +227,16 @@ def data(readonly=False):
"How to open links in an existing instance if a new one is "
"launched."),
('new-instance-open-target.window',
SettingValue(typ.String(
valid_values=typ.ValidValues(
('last-opened', "Open new tabs in the last"
"opened window."),
('last-focused', "Open new tabs in the most"
"recently focused window.")
)), 'last-focused'),
"Which window to choose when opening links as new tabs."),
('log-javascript-console',
SettingValue(typ.String(
valid_values=typ.ValidValues(

View File

@ -69,7 +69,11 @@ def get_window(via_ipc, force_window=False, force_tab=False,
window_to_raise = window
else:
try:
window = objreg.last_window()
win_mode = config.get('general', 'new-instance-open-target.window')
if win_mode == 'last-focused':
window = objreg.last_focused_window()
elif win_mode == 'last-opened':
window = objreg.last_window()
except objreg.NoWindow:
# There is no window left, so we open a new one
window = MainWindow()

View File

@ -178,10 +178,7 @@ def _get_window_registry(window):
app = get('app')
win = app.activeWindow()
elif window == 'last-focused':
try:
win = get('last-focused-main-window')
except KeyError:
win = last_window()
win = last_focused_window()
else:
win = window_registry[window]
except (KeyError, NoWindow):
@ -276,6 +273,14 @@ def dump_objects():
return lines
def last_focused_window():
"""Get the last focused window, or the last window if none."""
try:
return get('last-focused-main-window')
except KeyError:
return last_window()
def last_window():
"""Get the last opened window object."""
if not window_registry:

View File

@ -330,6 +330,7 @@ class QuteProc(testprocess.Process):
settings = [
('ui', 'message-timeout', '0'),
('general', 'auto-save-interval', '0'),
('general', 'new-instance-open-target.window', 'last-opened')
]
if not self._webengine:
settings.append(('network', 'ssl-strict', 'false'))