Implement the features of Clear Aboe Downloads and Open Downloads Folder. draft
authorSean Lee <selee@mozilla.com>
Wed, 13 Jul 2016 11:56:51 +0800
changeset 386947 204406989d6707fb11fc4139e816048901f70732
parent 386946 74d6c91956f60ec74e72aa4b4f72c274f69104d7
child 525257 32c2c31b3ee0093fad042728c6e14d4bfad35522
push id22860
push userbmo:selee@mozilla.com
push dateWed, 13 Jul 2016 03:57:55 +0000
milestone50.0a1
Implement the features of Clear Aboe Downloads and Open Downloads Folder. MozReview-Commit-ID: FWn669ifvNr
browser/components/downloads/content/downloads.js
browser/components/downloads/content/downloadsOverlay.xul
--- a/browser/components/downloads/content/downloads.js
+++ b/browser/components/downloads/content/downloads.js
@@ -518,16 +518,38 @@ const DownloadsPanel = {
       if (DownloadsView.richListBox.itemCount > 0) {
         DownloadsView.richListBox.focus();
       } else {
         DownloadsFooter.focus();
       }
     }
   },
 
+  clearAboveDownloads() {
+    var downloads = DownloadsView._downloads;
+    for (var i = 0; i < downloads.length && i < DownloadsView.kItemCountLimit; i++) {
+      if (downloads[i].succeeded) {
+        DownloadsCommon.removeAndFinalizeDownload(downloads[i]);
+        PlacesUtils.bhistory.removePage(
+                               NetUtil.newURI(downloads[i].source.url));
+
+      }
+    }
+    this.hidePanel();
+  },
+
+  openDownloadsFolder() {
+    const PREF_DOWNLOADS_FOLDER_SETTING = "browser.download.dir";
+    var prefSvc = Cc["@mozilla.org/preferences-service;1"].
+              getService(Ci.nsIPrefBranch);
+    let file = new FileUtils.File(prefSvc.getCharPref(PREF_DOWNLOADS_FOLDER_SETTING));
+    DownloadsCommon.showDownloadedFile(file);
+    this.hidePanel();
+  },
+
   /**
    * Opens the downloads panel when data is ready to be displayed.
    */
   _openPopupIfDataReady() {
     // We don't want to open the popup if we already displayed it, or if we are
     // still loading data.
     if (this._state != this.kStateWaitingData || DownloadsView.loading) {
       return;
--- a/browser/components/downloads/content/downloadsOverlay.xul
+++ b/browser/components/downloads/content/downloadsOverlay.xul
@@ -150,19 +150,21 @@
             <stack class="plain" id="downloadsSimpleSummary">
               <button id="downloadsHistory"
                       class="plain"
                       label="&downloadsHistory.label;"
                       accesskey="&downloadsHistory.accesskey;"
                       oncommand="DownloadsPanel.showDownloadsHistory();"/>
               <menupopup id="downloadSubPanel" position="after_end">
                 <menuitem id="clearAboveDownloadsButton"
+                          oncommand="DownloadsPanel.clearAboveDownloads();"
                           hidden="true"
                           label="&clearAboveDownloadsButton.label;"/>
                 <menuitem id="openDownloadsFolderButton"
+                          oncommand="DownloadsPanel.openDownloadsFolder();"
                           label="&openDownloadsFolderButton.label;"/>
               </menupopup>
 
               <button id="downloadFooterSubPanelButton"
                       accesskey="&downloadsHistory.accesskey;"
                       type="panel"
                       popup="downloadSubPanel"
                       align="center"