From ce8409feb298616e561e24fdeca747fc0daa8a6e Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 29 Sep 2014 22:37:46 +0200 Subject: [PATCH] Add multi window support to :restore/:restart. --- qutebrowser/app.py | 15 +++++++++++---- qutebrowser/widgets/crash.py | 8 ++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 792d716c5..cf0b74151 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -328,10 +328,12 @@ class Application(QApplication): forgiving: Whether to ignore exceptions. 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 = [] for win_id in objreg.window_registry: + win_pages = [] tabbed_browser = objreg.get('tabbed-browser', scope='window', window=win_id) for tab in tabbed_browser.widgets(): @@ -339,12 +341,13 @@ class Application(QApplication): urlstr = tab.cur_url.toString( QUrl.RemovePassword | QUrl.FullyEncoded) if urlstr: - pages.append(urlstr) + win_pages.append(urlstr) except Exception: # pylint: disable=broad-except if forgiving: log.destroy.exception("Error while recovering tab") else: raise + pages.append(win_pages) return pages def _save_geometry(self): @@ -444,7 +447,6 @@ class Application(QApplication): @cmdutils.register(instance='app', ignore_args=True) def restart(self, shutdown=True, pages=None): """Restart qutebrowser while keeping existing tabs open.""" - # FIXME handle multiple windows correctly here if pages is None: pages = self._recover_pages() log.destroy.debug("sys.executable: {}".format(sys.executable)) @@ -467,7 +469,12 @@ class Application(QApplication): # We only want to preserve options on a restart. args.append(arg) # 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("cwd: {}".format(cwd)) # Open a new process and immediately shutdown the existing one diff --git a/qutebrowser/widgets/crash.py b/qutebrowser/widgets/crash.py index 1c80dfe36..a98791e78 100644 --- a/qutebrowser/widgets/crash.py +++ b/qutebrowser/widgets/crash.py @@ -113,7 +113,7 @@ class _CrashDialog(QDialog): """Gather crash information to display. 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) exc: An exception tuple (type, value, traceback) """ @@ -172,7 +172,7 @@ class ExceptionCrashDialog(_CrashDialog): _btn_quit: The quit button _btn_restore: the restore 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) _exc: An exception tuple (type, value, traceback) _objects: A list of all QObjects as string. @@ -220,7 +220,7 @@ class ExceptionCrashDialog(_CrashDialog): self._crash_info += [ ("Exception", ''.join(traceback.format_exception(*self._exc))), ("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)), ("Objects", self._objects), ] @@ -316,7 +316,7 @@ class ReportDialog(_CrashDialog): super()._gather_crash_info() self._crash_info += [ ("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)), ("Objects", self._objects), ]