Add an --all flag to :download-cancel

This commit is contained in:
Florian Bruhin 2016-03-14 19:05:15 +01:00
parent 42a4c1ce4c
commit 25ee48d28b
3 changed files with 25 additions and 11 deletions

View File

@ -28,6 +28,7 @@ Added
clipboard. clipboard.
- New mode `word` for `hints -> mode` which uses a dictionary and link-texts - New mode `word` for `hints -> mode` which uses a dictionary and link-texts
for hints instead of single characters. for hints instead of single characters.
- New `--all` argument for `:download-cancel` to cancel all running downloads.
Changed Changed
~~~~~~~ ~~~~~~~

View File

@ -161,8 +161,13 @@ The form `:download [url] [dest]` is deprecated, use `:download --dest [dest] [u
[[download-cancel]] [[download-cancel]]
=== download-cancel === download-cancel
Syntax: +:download-cancel [*--all*]+
Cancel the last/[count]th download. Cancel the last/[count]th download.
==== optional arguments
* +*-a*+, +*--all*+: Cancel all running downloads
==== count ==== count
The index of the download to cancel. The index of the download to cancel.

View File

@ -948,22 +948,30 @@ class DownloadManager(QAbstractListModel):
@cmdutils.register(instance='download-manager', scope='window', @cmdutils.register(instance='download-manager', scope='window',
count='count') count='count')
def download_cancel(self, count=0): def download_cancel(self, all_=False, count=0):
"""Cancel the last/[count]th download. """Cancel the last/[count]th download.
Args: Args:
all_: Cancel all running downloads
count: The index of the download to cancel. count: The index of the download to cancel.
""" """
try: if all_:
download = self.downloads[count - 1] # We need to make a copy as we're indirectly mutating
except IndexError: # self.downloads here
self.raise_no_download(count) for download in self.downloads[:]:
if download.done: if not download.done:
if not count: download.cancel()
count = len(self.downloads) else:
raise cmdexc.CommandError("Download {} is already done!" try:
.format(count)) download = self.downloads[count - 1]
download.cancel() except IndexError:
self.raise_no_download(count)
if download.done:
if not count:
count = len(self.downloads)
raise cmdexc.CommandError("Download {} is already done!"
.format(count))
download.cancel()
@cmdutils.register(instance='download-manager', scope='window', @cmdutils.register(instance='download-manager', scope='window',
count='count') count='count')