Add multi window support to :restore/:restart.

This commit is contained in:
Florian Bruhin 2014-09-29 22:37:46 +02:00
parent 6aeecb3803
commit ce8409feb2
2 changed files with 15 additions and 8 deletions

View File

@ -328,10 +328,12 @@ class Application(QApplication):
forgiving: Whether to ignore exceptions. forgiving: Whether to ignore exceptions.
Return: Return:
A list of open pages, or an empty list. A list containing a list for each window, which in turn contain the
opened URLs.
""" """
pages = [] pages = []
for win_id in objreg.window_registry: for win_id in objreg.window_registry:
win_pages = []
tabbed_browser = objreg.get('tabbed-browser', scope='window', tabbed_browser = objreg.get('tabbed-browser', scope='window',
window=win_id) window=win_id)
for tab in tabbed_browser.widgets(): for tab in tabbed_browser.widgets():
@ -339,12 +341,13 @@ class Application(QApplication):
urlstr = tab.cur_url.toString( urlstr = tab.cur_url.toString(
QUrl.RemovePassword | QUrl.FullyEncoded) QUrl.RemovePassword | QUrl.FullyEncoded)
if urlstr: if urlstr:
pages.append(urlstr) win_pages.append(urlstr)
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
if forgiving: if forgiving:
log.destroy.exception("Error while recovering tab") log.destroy.exception("Error while recovering tab")
else: else:
raise raise
pages.append(win_pages)
return pages return pages
def _save_geometry(self): def _save_geometry(self):
@ -444,7 +447,6 @@ class Application(QApplication):
@cmdutils.register(instance='app', ignore_args=True) @cmdutils.register(instance='app', ignore_args=True)
def restart(self, shutdown=True, pages=None): def restart(self, shutdown=True, pages=None):
"""Restart qutebrowser while keeping existing tabs open.""" """Restart qutebrowser while keeping existing tabs open."""
# FIXME handle multiple windows correctly here
if pages is None: if pages is None:
pages = self._recover_pages() pages = self._recover_pages()
log.destroy.debug("sys.executable: {}".format(sys.executable)) log.destroy.debug("sys.executable: {}".format(sys.executable))
@ -467,7 +469,12 @@ class Application(QApplication):
# We only want to preserve options on a restart. # We only want to preserve options on a restart.
args.append(arg) args.append(arg)
# Add all open pages so they get reopened. # Add all open pages so they get reopened.
args += pages page_args = []
for win in pages:
page_args.extend(win)
page_args.append('')
if page_args:
args.extend(page_args[:-1])
log.destroy.debug("args: {}".format(args)) log.destroy.debug("args: {}".format(args))
log.destroy.debug("cwd: {}".format(cwd)) log.destroy.debug("cwd: {}".format(cwd))
# Open a new process and immediately shutdown the existing one # Open a new process and immediately shutdown the existing one

View File

@ -113,7 +113,7 @@ class _CrashDialog(QDialog):
"""Gather crash information to display. """Gather crash information to display.
Args: Args:
pages: A list of the open pages (URLs as strings) pages: A list of lists of the open pages (URLs as strings)
cmdhist: A list with the command history (as strings) cmdhist: A list with the command history (as strings)
exc: An exception tuple (type, value, traceback) exc: An exception tuple (type, value, traceback)
""" """
@ -172,7 +172,7 @@ class ExceptionCrashDialog(_CrashDialog):
_btn_quit: The quit button _btn_quit: The quit button
_btn_restore: the restore button _btn_restore: the restore button
_btn_pastebin: the pastebin button _btn_pastebin: the pastebin button
_pages: A list of the open pages (URLs as strings) _pages: A list of lists of the open pages (URLs as strings)
_cmdhist: A list with the command history (as strings) _cmdhist: A list with the command history (as strings)
_exc: An exception tuple (type, value, traceback) _exc: An exception tuple (type, value, traceback)
_objects: A list of all QObjects as string. _objects: A list of all QObjects as string.
@ -220,7 +220,7 @@ class ExceptionCrashDialog(_CrashDialog):
self._crash_info += [ self._crash_info += [
("Exception", ''.join(traceback.format_exception(*self._exc))), ("Exception", ''.join(traceback.format_exception(*self._exc))),
("Commandline args", ' '.join(sys.argv[1:])), ("Commandline args", ' '.join(sys.argv[1:])),
("Open Pages", '\n'.join(self._pages)), ("Open Pages", '\n\n'.join('\n'.join(e) for e in self._pages)),
("Command history", '\n'.join(self._cmdhist)), ("Command history", '\n'.join(self._cmdhist)),
("Objects", self._objects), ("Objects", self._objects),
] ]
@ -316,7 +316,7 @@ class ReportDialog(_CrashDialog):
super()._gather_crash_info() super()._gather_crash_info()
self._crash_info += [ self._crash_info += [
("Commandline args", ' '.join(sys.argv[1:])), ("Commandline args", ' '.join(sys.argv[1:])),
("Open Pages", '\n'.join(self._pages)), ("Open Pages", '\n\n'.join('\n'.join(e) for e in self._pages)),
("Command history", '\n'.join(self._cmdhist)), ("Command history", '\n'.join(self._cmdhist)),
("Objects", self._objects), ("Objects", self._objects),
] ]