Don't open a new window if only commands are sent via IPC.

Fixes #237.
This commit is contained in:
Florian Bruhin 2014-11-11 22:42:45 +01:00
parent d30ec95f72
commit e23360bb88

View File

@ -210,19 +210,23 @@ class Application(QApplication):
self._open_startpage()
self._open_quickstart()
def _get_window(self, via_ipc, args_empty):
def _get_window(self, via_ipc, force_window=False, force_tab=False):
"""Helper function for process_args to get a window id.
Args:
via_ipc: Whether the request was made via IPC.
args_empty: Whether there are no arguments.
force_window: Whether to force opening in a window.
force_tab: Whether to force opening in a tab.
"""
if force_window and force_tab:
raise ValueError("force_window and force_tab are mutually "
"exclusive!")
if not via_ipc:
# Initial main window
return 0
window_to_raise = None
open_target = config.get('general', 'new-instance-open-target')
if open_target == 'window' or args_empty:
if (open_target == 'window' or force_window) and not force_tab:
win_id = mainwindow.MainWindow.spawn()
window = objreg.get('main-window', scope='window', window=win_id)
window_to_raise = window
@ -256,18 +260,23 @@ class Application(QApplication):
args: A list of arguments to process.
via_ipc: Whether the arguments were transmitted over IPC.
"""
win_id = self._get_window(via_ipc, not args)
if ipc and not args:
win_id = self._get_window(via_ipc, force_window=True)
self._open_startpage(win_id)
return
win_id = None
for cmd in args:
if cmd.startswith(':'):
if win_id is None:
win_id = self._get_window(via_ipc, force_tab=True)
log.init.debug("Startup cmd {}".format(cmd))
commandrunner = runners.CommandRunner(win_id)
commandrunner.run_safely_init(cmd.lstrip(':'))
elif not cmd:
log.init.debug("Empty argument")
win_id = mainwindow.MainWindow.spawn()
win_id = self._get_window(via_ipc, force_window=True)
else:
win_id = self._get_window(via_ipc)
tabbed_browser = objreg.get('tabbed-browser', scope='window',
window=win_id)
log.init.debug("Startup URL {}".format(cmd))
@ -743,7 +752,7 @@ class Application(QApplication):
@pyqtSlot(QUrl)
def open_desktopservices_url(self, url):
"""Handler to open an URL via QDesktopServices."""
win_id = self._get_window(True, False)
win_id = self._get_window(via_ipc=True, force_window=False)
tabbed_browser = objreg.get('tabbed-browser', scope='window',
window=win_id)
tabbed_browser.tabopen(url)