Bug 1526902 - MozTreecolPicker buildPopup should not hardcode having one menuitem and separator, but instead remove based on attribute, to allow easier extensability. r=vporof
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Tue, 12 Feb 2019 14:57:28 +0200
changeset 458723 5564f0314b98
parent 458722 aca48f57fb21
child 458724 6f86eefc83a5
push id35546
push userrmaries@mozilla.com
push dateWed, 13 Feb 2019 04:27:59 +0000
treeherdermozilla-central@636d2c00234d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvporof
bugs1526902
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1526902 - MozTreecolPicker buildPopup should not hardcode having one menuitem and separator, but instead remove based on attribute, to allow easier extensability. r=vporof
toolkit/content/widgets/tree.js
--- a/toolkit/content/widgets/tree.js
+++ b/toolkit/content/widgets/tree.js
@@ -205,19 +205,19 @@
         <menupopup anonid="popup">
           <menuseparator anonid="menuseparator"></menuseparator>
           <menuitem anonid="menuitem" label="&restoreColumnOrder.label;"></menuitem>
         </menupopup>
       `, ["chrome://global/locale/tree.dtd"]));
     }
 
     buildPopup(aPopup) {
-      // We no longer cache the picker content, remove the old content.
-      while (aPopup.childNodes.length > 2)
-        aPopup.firstChild.remove();
+      // We no longer cache the picker content, remove the old content related to
+      // the cols - menuitem and separator should stay.
+      aPopup.querySelectorAll("[colindex]").forEach((e) => { e.remove(); });
 
       var refChild = aPopup.firstChild;
 
       var tree = this.parentNode.parentNode;
       for (var currCol = tree.columns.getFirstColumn(); currCol; currCol = currCol.getNext()) {
         // Construct an entry for each column in the row, unless
         // it is not being shown.
         var currElement = currCol.element;
@@ -232,21 +232,17 @@
             popupChild.setAttribute("checked", "true");
           if (currCol.primary)
             popupChild.setAttribute("disabled", "true");
           aPopup.insertBefore(popupChild, refChild);
         }
       }
 
       var hidden = !tree.enableColumnDrag;
-      const anonids = ["menuseparator", "menuitem"];
-      for (var i = 0; i < anonids.length; i++) {
-        var element = this.querySelector(`[anonid=\"${anonids[i]}\"]`);
-        element.hidden = hidden;
-      }
+      aPopup.querySelectorAll(":not([colindex])").forEach((e) => { e.hidden = hidden; });
     }
   }
 
   customElements.define("treecolpicker", MozTreecolPicker);
 
   class MozTreecol extends MozElements.BaseControl {
     static get observedAttributes() {
       return [