Bug 1002006 - Allow to pass a specific filter to select to FilterListDialog. r=mkmelin a=rkent THUNDERBIRD450b3_2016032415_RELBRANCH
authoraceman <acelists@atlas.sk>
Wed, 02 Mar 2016 22:38:05 +0100
branchTHUNDERBIRD450b3_2016032415_RELBRANCH
changeset 26856 fc417f3c934112e4821425edb6163a0d34a5bc8e
parent 26855 a227f3e166c1fdf95f52474ef1899a2adffb3053
child 26857 2660f1194809bfddb5b8754d49148127a8aeb27a
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
bugs1002006
Bug 1002006 - Allow to pass a specific filter to select to FilterListDialog. r=mkmelin a=rkent
mail/base/content/FilterListDialog.js
mail/base/content/mailWindowOverlay.js
mailnews/base/search/content/FilterEditor.js
--- a/mail/base/content/FilterListDialog.js
+++ b/mail/base/content/FilterListDialog.js
@@ -149,16 +149,20 @@ function processWindowArguments(aArgumen
     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();
   }
+
+  // If a specific filter was requested, try to select it.
+  if ("filter" in aArguments)
+    selectFilter(aArguments.filter);
 }
 
 /**
  * This is called from OpenOrFocusWindow() if the dialog is already open.
  * New filters could have been created by operations outside the dialog.
  *
  * @param aArguments  An object of arguments having the same format
  *                    as window.arguments[0].
@@ -272,16 +276,41 @@ function toggleFilter(aFilterItem)
 function selectFolder(aFolder)
 {
   var serverMenu = document.getElementById("serverMenuPopup");
   serverMenu.selectFolder(aFolder);
   setFolder(aFolder);
 }
 
 /**
+ * Selects a specific filter in the filter list.
+ * The listbox view is scrolled to the corresponding item.
+ *
+ * @param aFilter  The nsIMsgFilter to select.
+ *
+ * @return  true/false indicating whether the filter was found and selected.
+ */
+function selectFilter(aFilter) {
+  if (currentFilter() == aFilter)
+    return true;
+
+  resetSearchBox(aFilter);
+
+  let filterCount = gCurrentFilterList.filterCount;
+  for (let i = 0; i < filterCount; i++) {
+    if (gCurrentFilterList.getFilterAt(i) == aFilter) {
+      gFilterListbox.ensureIndexIsVisible(i);
+      gFilterListbox.selectedIndex = i;
+      return true;
+    }
+  }
+  return false;
+}
+
+/**
  * Returns the currently selected filter. If multiple filters are selected,
  * returns the first one. If none are selected, returns null.
  */
 function currentFilter()
 {
   let currentItem = gFilterListbox.selectedItem;
   return currentItem ? currentItem._filter : null;
 }
@@ -324,21 +353,23 @@ function onNewFilter(emailAddress)
   }
 
   let args = {filterList: gCurrentFilterList, filterPosition: position};
 
   window.openDialog("chrome://messenger/content/FilterEditor.xul", "FilterEditor", "chrome,modal,titlebar,resizable,centerscreen", args);
 
   if ("refresh" in args && args.refresh) {
     // On success: reset the search box if necessary!
-    resetSearchBox(gCurrentFilterList.getFilterAt(position));
+    resetSearchBox(args.newFilter);
     rebuildFilterList();
 
     // Select the new filter, it is at the position of previous selection.
     gFilterListbox.selectItem(gFilterListbox.getItemAtIndex(position));
+    if (currentFilter() != args.newFilter)
+      Components.utils.reportError("Filter created at an unexpected position!");
   }
 }
 
 /**
  * Delete selected filters.
  *  'Selected' is not to be confused with active (checkbox checked)
  */
 function onDeleteFilter()
--- a/mail/base/content/mailWindowOverlay.js
+++ b/mail/base/content/mailWindowOverlay.js
@@ -2374,20 +2374,21 @@ function MsgFilters(emailAddress, folder
     // Set the field name to prefill in the filter, if one was specified.
     if (fieldName)
       args.fieldName = fieldName;
 
     window.openDialog("chrome://messenger/content/FilterEditor.xul", "",
                       "chrome, modal, resizable,centerscreen,dialog=yes", args);
 
     // If the user hits ok in the filterEditor dialog we set args.refresh=true
-    // there we check this here in args to show filterList dialog.
+    // there and we check this here in args to show filterList dialog.
+    // We also received the filter created via args.newFilter.
     if ("refresh" in args && args.refresh)
     {
-      args = { refresh: true, folder: folder };
+      args = { refresh: true, folder: folder, filter: args.newFilter };
       MsgFilterList(args);
     }
   }
   else  // just launch filterList dialog
   {
     args = { refresh: false, folder: folder };
     MsgFilterList(args);
   }
--- a/mailnews/base/search/content/FilterEditor.js
+++ b/mailnews/base/search/content/FilterEditor.js
@@ -167,16 +167,17 @@ function onAccept()
     if (!saveFilter())
       return false;
   } catch(e) {Components.utils.reportError(e); return false;}
 
   // parent should refresh filter list..
   // this should REALLY only happen when some criteria changes that
   // are displayed in the filter dialog, like the filter name
   window.arguments[0].refresh = true;
+  window.arguments[0].newFilter = gFilter;
   return true;
 }
 
 // the folderListener object
 var gFolderListener = {
   OnItemAdded: function(parentItem, item) {},
 
   OnItemRemoved: function(parentItem, item){},