Bug 1460392 - Port bug 1457027 to TB: Part 1 - Don't persist the last selected handler. r=aceman
authorRichard Marti <richard.marti@gmail.com>
Sat, 22 Sep 2018 09:17:38 +0200
changeset 33261 1dfd8879d65bea1103a01da0ef8edbd378925677
parent 33260 4568dcf1dd5700335d893b7ce077eabf085f013e
child 33262 e490dff436ddb355e7c6532e01adee7725d5aaf8
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersaceman
bugs1460392, 1457027
Bug 1460392 - Port bug 1457027 to TB: Part 1 - Don't persist the last selected handler. r=aceman
mail/components/preferences/applications.inc.xul
mail/components/preferences/applications.js
--- a/mail/components/preferences/applications.inc.xul
+++ b/mail/components/preferences/applications.inc.xul
@@ -97,19 +97,18 @@
                      type="search"
                      placeholder="&filter.placeholder;"
                      aria-controls="handlersView"
                      oncommand="gApplicationsPane.rebuildView();"/>
           </hbox>
 
           <separator class="thin"/>
 
-          <richlistbox id="handlersView" orient="vertical" persist="lastSelectedType"
-                       preference="pref.downloads.disable_button.edit_actions"
-                       onselect="gApplicationsPane.onSelectionChanged();">
+          <richlistbox id="handlersView"
+                       preference="pref.downloads.disable_button.edit_actions">
             <listheader equalsize="always" style="border: 0; padding: 0; -moz-appearance: none;">
               <treecol id="typeColumn" label="&typeColumn.label;" value="type"
                        accesskey="&typeColumn.accesskey;" persist="sortDirection"
                        flex="1" onclick="gApplicationsPane.sort(event);"
                        sortDirection="ascending" sort="typeDescription"/>
               <treecol id="actionColumn" label="&actionColumn2.label;" value="action"
                        accesskey="&actionColumn2.accesskey;" persist="sortDirection"
                        flex="1" onclick="gApplicationsPane.sort(event);"/>
--- a/mail/components/preferences/applications.js
+++ b/mail/components/preferences/applications.js
@@ -1044,16 +1044,19 @@ var gApplicationsPane = {
 
       let descCount = this._visibleTypeDescriptionCount.has(handlerInfo.description) ?
         (this._visibleTypeDescriptionCount.get(handlerInfo.description) + 1) : 1;
       this._visibleTypeDescriptionCount.set(handlerInfo.description, descCount);
     }
   },
 
   rebuildView() {
+    let lastSelectedType = this._list.selectedItem &&
+                           this._list.selectedItem.getAttribute("type");
+
     // Clear the list of entries.
     while (this._list.childNodes.length > 1)
       this._list.lastChild.remove();
     var visibleTypes = this._visibleTypes;
 
     // If the user is filtering the list, then only show matching types.
     if (this._filter.value)
       visibleTypes = visibleTypes.filter(this._matchesFilter, this);
@@ -1070,19 +1073,21 @@ var gApplicationsPane = {
                         this._describePreferredAction(visibleType));
 
       if (!this._setIconClassForPreferredAction(visibleType, item)) {
         item.setAttribute("actionIcon",
                           this._getIconURLForPreferredAction(visibleType));
       }
 
       this._list.appendChild(item);
+
+      if (visibleType.type === lastSelectedType) {
+        this._list.selectedItem = item;
+      }
     }
-
-    this._selectLastSelectedType();
   },
 
   _matchesFilter(aType) {
     var filterValue = this._filter.value.toLowerCase();
     return this._describeType(aType).toLowerCase().includes(filterValue) ||
            this._describePreferredAction(aType).toLowerCase().includes(filterValue);
   },
 
@@ -1194,35 +1199,16 @@ var gApplicationsPane = {
                                                      this._brandShortName]);
       default:
         // Hopefully this never happens.
         Cu.reportError("No description for action " + aHandlerInfo.preferredAction + " found!");
         return "";
     }
   },
 
-  _selectLastSelectedType() {
-    // If the list is disabled by the pref.downloads.disable_button.edit_actions
-    // preference being locked, then don't select the type, as that would cause
-    // it to appear selected, with a different background and an actions menu
-    // that makes it seem like you can choose an action for the type.
-    if (this._list.disabled)
-      return;
-
-    var lastSelectedType = this._list.getAttribute("lastSelectedType");
-    if (!lastSelectedType)
-      return;
-
-    let item = this._list.querySelector('[type="' + lastSelectedType + '"]');
-    if (!item)
-      return;
-
-    this._list.selectedItem = item;
-  },
-
   /**
    * Whether or not the given handler app is valid.
    * @param aHandlerApp {nsIHandlerApp} the handler app in question
    * @return {boolean} whether or not it's valid
    */
   isValidHandlerApp(aHandlerApp) {
     if (!aHandlerApp)
       return false;
@@ -1654,24 +1640,16 @@ var gApplicationsPane = {
           let handlerInfo = this._handledTypes[this._list.selectedItem.type];
           handlerInfo.addPossibleApplicationHandler(handlerApp);
         }
         onSelectionDone();
       });
     }
   },
 
-  // Mark which item in the list was last selected so we can reselect it
-  // when we rebuild the list or when the user returns to the prefpane.
-  onSelectionChanged() {
-    if (this._list.selectedItem)
-      this._list.setAttribute("lastSelectedType",
-                              this._list.selectedItem.getAttribute("type"));
-  },
-
   confirmDelete(aEvent) {
     aEvent.stopPropagation();
     if (Services.prompt.confirm(null,
                                 this._prefsBundle.getString("confirmDeleteTitle"),
                                 this._prefsBundle.getString("confirmDeleteText")))
       this.onDelete(aEvent);
     else {
       // They hit cancel, so return them to the previously selected item.