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.
- New mode `word` for `hints -> mode` which uses a dictionary and link-texts
for hints instead of single characters.
- New `--all` argument for `:download-cancel` to cancel all running downloads.
Changed
~~~~~~~

View File

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

View File

@ -948,22 +948,30 @@ class DownloadManager(QAbstractListModel):
@cmdutils.register(instance='download-manager', scope='window',
count='count')
def download_cancel(self, count=0):
def download_cancel(self, all_=False, count=0):
"""Cancel the last/[count]th download.
Args:
all_: Cancel all running downloads
count: The index of the download to cancel.
"""
try:
download = self.downloads[count - 1]
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()
if all_:
# We need to make a copy as we're indirectly mutating
# self.downloads here
for download in self.downloads[:]:
if not download.done:
download.cancel()
else:
try:
download = self.downloads[count - 1]
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',
count='count')