Ask for filename when none is given

This commit is contained in:
Daniel 2015-09-22 13:37:03 +02:00
parent 679ab65b5f
commit 6b086d159d
2 changed files with 18 additions and 2 deletions

View File

@ -43,6 +43,8 @@ from qutebrowser.utils import (message, usertypes, log, qtutils, urlutils,
objreg, utils) objreg, utils)
from qutebrowser.utils.usertypes import KeyMode from qutebrowser.utils.usertypes import KeyMode
from qutebrowser.misc import editor, guiprocess, mhtml from qutebrowser.misc import editor, guiprocess, mhtml
from qutebrowser.browser.downloads import (_path_suggestion as
download_path_suggestion)
class CommandDispatcher: class CommandDispatcher:
@ -1158,13 +1160,25 @@ class CommandDispatcher:
download_manager.get(self._current_url(), page=page) download_manager.get(self._current_url(), page=page)
@cmdutils.register(instance='command-dispatcher', scope='window') @cmdutils.register(instance='command-dispatcher', scope='window')
def download_whole(self, dest): def download_whole(self, dest=None):
"""Download the current page as a MHTML file, including all assets. """Download the current page as a MHTML file, including all assets.
Args: Args:
dest: The file path to write the download to. dest: The file path to write the download to.
""" """
mhtml.start_download(dest) if dest is None:
suggested_fn = self._current_title() + ".mht"
q = usertypes.Question()
q.text = "Save page to: "
q.mode = usertypes.PromptMode.text
q.completed.connect(q.deleteLater)
q.default = download_path_suggestion(suggested_fn)
q.answered.connect(mhtml.start_download)
message_bridge = objreg.get("message-bridge", scope="window",
window=self._win_id)
message_bridge.ask(q, blocking=False)
else:
mhtml.start_download(dest)
@cmdutils.register(instance='command-dispatcher', scope='window', @cmdutils.register(instance='command-dispatcher', scope='window',
deprecated="Use :download instead.") deprecated="Use :download instead.")

View File

@ -21,6 +21,7 @@
import functools import functools
import io import io
import os
from collections import namedtuple from collections import namedtuple
from base64 import b64encode from base64 import b64encode
@ -285,6 +286,7 @@ def start_download(dest):
Args: Args:
dest: The filename where the resulting file should be saved. dest: The filename where the resulting file should be saved.
""" """
dest = os.path.expanduser(dest)
web_view = objreg.get("webview", scope="tab", tab="current") web_view = objreg.get("webview", scope="tab", tab="current")
loader = _Downloader(web_view, dest) loader = _Downloader(web_view, dest)
loader.run() loader.run()