Bug 1198744 - Filters run on a different folder than selected. r=mkmelin, a=rkent
authoralta88
Tue, 24 Nov 2015 07:13:39 -0700
changeset 26534 3f9bc9fae33f3b1cfb7faa17f19499d44e152de7
parent 26533 8206a6dab914ea80d71e44384759c6c4b50c2d43
child 26535 b96e4ccbd174f3d1d0356a0fc60f24c62c5399f0
push id1850
push userclokep@gmail.com
push dateWed, 08 Mar 2017 19:29:12 +0000
treeherdercomm-esr52@028df196b2d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin, rkent
bugs1198744
Bug 1198744 - Filters run on a different folder than selected. r=mkmelin, a=rkent
mail/base/content/FilterListDialog.js
--- a/mail/base/content/FilterListDialog.js
+++ b/mail/base/content/FilterListDialog.js
@@ -140,16 +140,20 @@ function processWindowArguments(aArgumen
     // If the selected server cannot have filters, get the default server
     // If the default server cannot have filters, check all accounts
     // and get a server that can have filters.
     if (!firstItem)
       firstItem = getServerThatCanHaveFilters().rootFolder;
 
     if (firstItem)
       selectFolder(firstItem);
+
+    if (gSelectedFolder)
+      setRunFolder(gSelectedFolder);
+
   } else {
     // If we didn't change folder still redraw the list
     // to show potential new filters if we were called for refresh.
     rebuildFilterList();
   }
 }
 
 /**
@@ -231,20 +235,22 @@ function setFolder(msgFolder)
    runMenu._ensureInitialized();
 
    let canFilterAfterTheFact = CanRunFiltersAfterTheFact(msgFolder.server);
    gRunFiltersFolder.hidden = !canFilterAfterTheFact;
    gRunFiltersButton.hidden = !canFilterAfterTheFact;
    document.getElementById("folderPickerPrefix").hidden = !canFilterAfterTheFact;
 
    if (canFilterAfterTheFact) {
-     // Get the first folder for this server. INBOX for
-     // IMAP and POP3 accounts and 1st news group for news.
+     // Get the first folder for this server. INBOX for IMAP and POP3 accounts
+     // and 1st news group for news. Disable the button for Choose Folder, if
+     // no folder is selected and the server is not imap/pop3/nntp.
      gRunFiltersFolder.selectedIndex = 0;
      runMenu.selectFolder(getFirstFolder(gSelectedFolder || msgFolder));
+     updateButtons();
    }
 }
 
 /**
  * Toggle enabled state of a filter, in both the filter properties and the UI.
  *
  * @param aFilterItem  an item (row) of the filter list to be toggled
  */
@@ -708,17 +714,17 @@ function updateButtons()
 
     // "delete" only disabled when no filters are selected
     gDeleteButton.disabled = !numFiltersSelected;
 
     // we can run multiple filters on a folder
     // so only disable this UI if no filters are selected
     document.getElementById("folderPickerPrefix").disabled = !numFiltersSelected;
     gRunFiltersFolder.disabled = !numFiltersSelected;
-    gRunFiltersButton.disabled = !numFiltersSelected;
+    gRunFiltersButton.disabled = !numFiltersSelected || !gRunFiltersFolder.value;
     // "up" and "top" enabled only if one filter is selected, and it's not the first
     // don't use gFilterListbox.currentIndex here, it's buggy when we've just changed the
     // children in the list (via rebuildFilterList)
     disabled = !(oneFilterSelected &&
                  gFilterListbox.getSelectedItem(0) != gFilterListbox.getItemAtIndex(0));
     gUpButton.disabled = disabled;
     gTopButton.disabled = disabled;
 
@@ -826,18 +832,23 @@ function onFilterListKeyPress(aEvent)
       default:
         gSearchBox.focus();
         gSearchBox.value = String.fromCharCode(aEvent.charCode);
     }
   }
 }
 
 function onTargetSelect(event) {
-  gRunFiltersFolder._folder = event.target._folder;
+  setRunFolder(event.target._folder);
+}
+
+function setRunFolder(aFolder) {
+  gRunFiltersFolder._folder = aFolder;
   gRunFiltersFolder.menupopup.selectFolder(gRunFiltersFolder._folder);
+  updateButtons();
 }
 
 /**
  * For a given server folder, get the default run target selected folder or show
  * Choose Folder.
  */
 function getFirstFolder(msgFolder)
 {