Bug 781762 - Add the ability to delete all downloaded files at one time, r=margaret

This commit is contained in:
Mark Capella 2012-09-28 01:52:43 -04:00
parent 04bd3392ee
commit 7515eb58a9
2 changed files with 36 additions and 0 deletions

View File

@ -7,6 +7,7 @@ let Ci = Components.interfaces, Cc = Components.classes, Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/DownloadUtils.jsm"); Cu.import("resource://gre/modules/DownloadUtils.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/PluralForm.jsm");
let gStrings = Services.strings.createBundle("chrome://browser/locale/aboutDownloads.properties"); let gStrings = Services.strings.createBundle("chrome://browser/locale/aboutDownloads.properties");
@ -111,6 +112,14 @@ let Downloads = {
Downloads.cancelDownload(aTarget); Downloads.cancelDownload(aTarget);
} }
); );
// Delete All shown when item is finished, canceled, or failed
Downloads.deleteAllMenuItem = contextmenus.add(gStrings.GetStringFromName("downloadAction.deleteAll"),
contextmenus.SelectorContext("li[state='" + this._dlmgr.DOWNLOAD_FINISHED + "']," +
"li[state='" + this._dlmgr.DOWNLOAD_CANCELED + "']," +
"li[state='" + this._dlmgr.DOWNLOAD_FAILED + "']"),
this.deleteAll.bind(this)
);
}, },
uninit: function dl_uninit() { uninit: function dl_uninit() {
@ -121,6 +130,7 @@ let Downloads = {
contextmenus.remove(this.resumeMenuItem); contextmenus.remove(this.resumeMenuItem);
contextmenus.remove(this.retryMenuItem); contextmenus.remove(this.retryMenuItem);
contextmenus.remove(this.cancelMenuItem); contextmenus.remove(this.cancelMenuItem);
contextmenus.remove(this.deleteAllMenuItem);
Services.obs.removeObserver(this, "dl-start"); Services.obs.removeObserver(this, "dl-start");
Services.obs.removeObserver(this, "dl-failed"); Services.obs.removeObserver(this, "dl-failed");
@ -410,6 +420,25 @@ let Downloads = {
} catch(ex) { } } catch(ex) { }
}, },
deleteAll: function dl_deleteAll() {
let title = gStrings.GetStringFromName("downloadAction.deleteAll");
let messageForm = gStrings.GetStringFromName("downloadMessage.deleteAll");
let elements = this._list.querySelectorAll("li[state='" + this._dlmgr.DOWNLOAD_FINISHED + "']," +
"li[state='" + this._dlmgr.DOWNLOAD_CANCELED + "']," +
"li[state='" + this._dlmgr.DOWNLOAD_FAILED + "']");
let message = PluralForm.get(elements.length, messageForm)
.replace("#1", elements.length);
let flags = Services.prompt.BUTTON_POS_0 * Services.prompt.BUTTON_TITLE_OK +
Services.prompt.BUTTON_POS_1 * Services.prompt.BUTTON_TITLE_CANCEL;
let choice = Services.prompt.confirmEx(null, title, message, flags,
null, null, null, null, {});
if (choice == 0) {
for (let i = 0; i < elements.length; i++) {
this.removeDownload(elements[i]);
}
}
},
pauseDownload: function dl_pauseDownload(aItem) { pauseDownload: function dl_pauseDownload(aItem) {
try { try {
let download = this._getDownloadForElement(aItem); let download = this._getDownloadForElement(aItem);

View File

@ -4,6 +4,13 @@
downloadAction.open=Open downloadAction.open=Open
downloadAction.remove=Delete downloadAction.remove=Delete
downloadAction.deleteAll=Delete All
# LOCALIZATION NOTE (downloadMessage.deleteAll):
# Semi-colon list of plural forms. See:
# http://developer.mozilla.org/en/docs/Localization_and_Plurals
downloadMessage.deleteAll=Delete this download?;Delete #1 downloads?
downloadAction.pause=Pause downloadAction.pause=Pause
downloadAction.resume=Resume downloadAction.resume=Resume
downloadAction.cancel=Cancel downloadAction.cancel=Cancel