diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index f3bb32513..7588fa424 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1153,8 +1153,8 @@ class CommandDispatcher: mhtml_: Download the current page and all assets as mhtml file. """ if dest_old is not None: - message.warning('current', ":download [url] [dest] is deprecated -" - " use download --dest [dest] [url]") + message.warning(self._win_id, ":download [url] [dest] is deprecated" + " - use download --dest [dest] [url]") if dest is not None: raise cmdexc.CommandError("Can't give two destinations for the" " download.") @@ -1183,6 +1183,7 @@ class CommandDispatcher: Args: dest: The file path to write the download to. """ + tab_id = self._current_index() if dest is None: suggested_fn = self._current_title() + ".mht" q = usertypes.Question() @@ -1190,12 +1191,15 @@ class CommandDispatcher: q.mode = usertypes.PromptMode.text q.completed.connect(q.deleteLater) q.default = downloads.path_suggestion(suggested_fn) - q.answered.connect(mhtml.start_download_checked) + q.answered.connect(functools.partial( + mhtml.start_download_checked, win_id=self._win_id, + tab_id=tab_id)) message_bridge = objreg.get("message-bridge", scope="window", window=self._win_id) message_bridge.ask(q, blocking=False) else: - mhtml.start_download_checked(dest) + mhtml.start_download_checked(dest, win_id=self._win_id, + tab_id=tab_id) @cmdutils.register(instance='command-dispatcher', scope='window', deprecated="Use :download instead.") diff --git a/qutebrowser/browser/mhtml.py b/qutebrowser/browser/mhtml.py index 1ac39be94..e7bdca516 100644 --- a/qutebrowser/browser/mhtml.py +++ b/qutebrowser/browser/mhtml.py @@ -415,39 +415,42 @@ class _NoCloseBytesIO(io.BytesIO): # pylint: disable=no-init super().close() -def start_download(dest): +def _start_download(dest, win_id, tab_id): """Start downloading the current page and all assets to a MHTML file. This will overwrite dest if it already exists. Args: dest: The filename where the resulting file should be saved. + win_id, tab_id: Specify the tab whose page should be loaded. """ + dest = os.path.expanduser(dest) - web_view = objreg.get('webview', scope='tab', tab='current') + web_view = objreg.get('webview', scope='tab', window=win_id, tab=tab_id) loader = _Downloader(web_view, dest) loader.run() - -def start_download_checked(dest): +def start_download_checked(dest, win_id, tab_id): """First check if dest is already a file, then start the download. Args: dest: The filename where the resulting file should be saved. + win_id, tab_id: Specify the tab whose page should be loaded. """ # start_download will call os.path.expanduser on dest too, so no need to # overwrite dest. We just want to make sure that we're checking # the right path here. This also means that the user question will show the # original path, not the expanded. if not os.path.isfile(os.path.expanduser(dest)): - start_download(dest) + _start_download(dest, win_id=win_id, tab_id=tab_id) return q = usertypes.Question() q.mode = usertypes.PromptMode.yesno q.text = "{} exists. Overwrite?".format(dest) q.completed.connect(q.deleteLater) - q.answered_yes.connect(functools.partial(start_download, dest)) + q.answered_yes.connect(functools.partial( + _start_download, dest, win_id=win_id, tab_id=tab_id)) message_bridge = objreg.get('message-bridge', scope='window', - window='current') + window=win_id) message_bridge.ask(q, blocking=False)