Bug 1668612 - Remove the Customize entry in the App Menu and reorganize items under View. r=mkmelin draft
authorAlessandro Castellani <alessandro@thunderbird.net>
Fri, 27 Nov 2020 10:07:32 -0800
changeset 95756 5eefd7090060826c39c79ea62a81c8ad76e5f6f5
parent 95755 3a8db8b969124bf38f4b090a8a6adb9ea03b28f8
child 95757 8c7cdfd510a28ff7debf8efde19f211f909269bc
push id12266
push useralessandro@thunderbird.net
push dateFri, 27 Nov 2020 18:08:17 +0000
treeherdertry-comm-central@8c7cdfd510a2 [default view] [failures only]
reviewersmkmelin
bugs1668612
Bug 1668612 - Remove the Customize entry in the App Menu and reorganize items under View. r=mkmelin
mail/base/content/mailCore.js
mail/components/customizableui/content/panelUI.inc.xhtml
mail/components/customizableui/content/panelUI.js
--- a/mail/base/content/mailCore.js
+++ b/mail/base/content/mailCore.js
@@ -367,104 +367,110 @@ function MailToolboxCustomizeDone(aEvent
   }
 }
 
 /**
  * Sets up the menu popup that lets the user hide or display toolbars. For
  * example, in the appmenu / Preferences view.  Adds toolbar items to the popup
  * and sets their attributes.
  *
- * @param {Event} event                 Event causing the menu popup to appear.
- * @param {string|string[]} toolboxIds  IDs of toolboxes that contain toolbars.
- * @param {Element} insertPoint         Where to insert menu items.
- * @param {string} [elementName]        What kind of menu item element to use.
- *                                      E.g. "toolbarbutton" for the appmenu.
- * @param {string} [classes]            Classes to set on menu items.
+ * @param {Event} event - Event causing the menu popup to appear.
+ * @param {string|string[]} toolboxIds - IDs of toolboxes that contain toolbars.
+ * @param {Element} insertPoint - Where to insert menu items.
+ * @param {string} elementName - What kind of menu item element to use. E.g.
+ *   "toolbarbutton" for the appmenu.
+ * @param {string} classes - Classes to set on menu items.
+ * @param {boolean} keepOpen - If to force the menu to stay open when clicking
+ *   on this element.
  */
 function onViewToolbarsPopupShowing(
   event,
   toolboxIds,
   insertPoint,
   elementName = "menuitem",
-  classes
+  classes,
+  keepOpen = false
 ) {
   if (!Array.isArray(toolboxIds)) {
     toolboxIds = [toolboxIds];
   }
 
-  const popup =
-    event.target.querySelector(".panel-subview-body") || event.target;
+  let popup = event.target.querySelector(".panel-subview-body") || event.target;
 
   // Remove all collapsible nodes from the menu.
   for (let i = popup.children.length - 1; i >= 0; --i) {
-    const deadItem = popup.children[i];
+    let deadItem = popup.children[i];
 
     if (deadItem.hasAttribute("iscollapsible")) {
       deadItem.remove();
     }
   }
 
   // We insert menuitems before the first child if no insert point is given.
-  const firstMenuItem = insertPoint || popup.firstElementChild;
+  let firstMenuItem = insertPoint || popup.firstElementChild;
 
-  for (const toolboxId of toolboxIds) {
-    const toolbox = document.getElementById(toolboxId);
+  for (let toolboxId of toolboxIds) {
+    let toolbox = document.getElementById(toolboxId);
 
     // We consider child nodes that have a toolbarname attribute.
-    const toolbars = Array.from(toolbox.querySelectorAll("[toolbarname]"));
+    let toolbars = Array.from(toolbox.querySelectorAll("[toolbarname]"));
 
     // Add the folder pane toolbar to the list of toolbars that can be shown and
     // hidden.
     if (toolbox.getAttribute("id") === "mail-toolbox") {
       if (
         AppConstants.platform != "macosx" &&
         document.getElementById("mail-toolbar-menubar2")
       ) {
         toolbars.push(document.getElementById("mail-toolbar-menubar2"));
       }
       if (document.getElementById("folderPane-toolbar")) {
         toolbars.push(document.getElementById("folderPane-toolbar"));
       }
     }
 
-    for (const toolbar of toolbars) {
-      const toolbarName = toolbar.getAttribute("toolbarname");
-      if (toolbarName) {
-        const menuItem = document.createXULElement(elementName);
+    for (let toolbar of toolbars) {
+      let toolbarName = toolbar.getAttribute("toolbarname");
+      if (!toolbarName) {
+        continue;
+      }
 
-        const hidingAttribute =
-          toolbar.getAttribute("type") == "menubar" ? "autohide" : "collapsed";
+      let menuItem = document.createXULElement(elementName);
+      let hidingAttribute =
+        toolbar.getAttribute("type") == "menubar" ? "autohide" : "collapsed";
 
-        menuItem.setAttribute("type", "checkbox");
-        // Mark this menuitem with an iscollapsible attribute, so we
-        // know we can wipe it out later on.
-        menuItem.setAttribute("iscollapsible", true);
-        menuItem.setAttribute("toolbarid", toolbar.id);
-        menuItem.setAttribute("label", toolbarName);
-        menuItem.setAttribute("accesskey", toolbar.getAttribute("accesskey"));
-        menuItem.setAttribute(
-          "checked",
-          toolbar.getAttribute(hidingAttribute) != "true"
-        );
-        if (classes) {
-          menuItem.setAttribute("class", classes);
+      menuItem.setAttribute("type", "checkbox");
+      // Mark this menuitem with an iscollapsible attribute, so we
+      // know we can wipe it out later on.
+      menuItem.setAttribute("iscollapsible", true);
+      menuItem.setAttribute("toolbarid", toolbar.id);
+      menuItem.setAttribute("label", toolbarName);
+      menuItem.setAttribute("accesskey", toolbar.getAttribute("accesskey"));
+      menuItem.setAttribute(
+        "checked",
+        toolbar.getAttribute(hidingAttribute) != "true"
+      );
+      if (classes) {
+        menuItem.setAttribute("class", classes);
+      }
+      if (keepOpen) {
+        menuItem.setAttribute("closemenu", "none");
+      }
+      popup.insertBefore(menuItem, firstMenuItem);
+
+      menuItem.addEventListener("command", () => {
+        if (toolbar.getAttribute(hidingAttribute) != "true") {
+          toolbar.setAttribute(hidingAttribute, "true");
+          menuItem.removeAttribute("checked");
+        } else {
+          menuItem.setAttribute("checked", true);
+          toolbar.removeAttribute(hidingAttribute);
         }
-        popup.insertBefore(menuItem, firstMenuItem);
-
-        menuItem.addEventListener("command", () => {
-          const hidden = toolbar.getAttribute(hidingAttribute) != "true";
-
-          if (hidden) {
-            toolbar.setAttribute(hidingAttribute, "true");
-          } else {
-            toolbar.removeAttribute(hidingAttribute);
-          }
-          Services.xulStore.persist(toolbar, hidingAttribute);
-        });
-      }
+        Services.xulStore.persist(toolbar, hidingAttribute);
+      });
     }
   }
 }
 
 function toJavaScriptConsole() {
   BrowserConsoleManager.openBrowserConsoleOrFocus();
 }
 
--- a/mail/components/customizableui/content/panelUI.inc.xhtml
+++ b/mail/components/customizableui/content/panelUI.inc.xhtml
@@ -101,21 +101,16 @@
                        class="subviewbutton subviewbutton-iconic"
 #ifdef XP_WIN
                        label="&preferencesCmd2.label;"
 #else
                        label="&preferencesCmdUnix.label;"
 #endif
                        closemenu="none"
                        oncommand="openOptionsDialog();"/>
-        <toolbarbutton id="appmenu_customize"
-                       class="subviewbutton subviewbutton-iconic subviewbutton-nav"
-                       label="&customizeCmd.label;"
-                       closemenu="none"
-                       oncommand="PanelUI.showSubView('appMenu-customizeView', this)"/>
         <toolbarseparator/>
         <toolbarbutton id="appmenu_File"
                        class="subviewbutton subviewbutton-nav"
                        label="&fileMenu.label;"
                        closemenu="none"
                        oncommand="PanelUI.showSubView('appMenu-fileView', this)"/>
         <toolbarbutton id="appmenu_View"
                        class="subviewbutton subviewbutton-nav"
@@ -394,48 +389,44 @@
                        command="cmd_saveAsFile"/>
         <toolbarbutton id="appmenu_saveAsTemplate"
                        class="subviewbutton subviewbutton-iconic"
                        label="&saveAsTemplateCmd.label;"
                        command="cmd_saveAsTemplate"/>
       </vbox>
     </panelview>
 
-    <!-- Customize -->
-    <panelview id="appMenu-customizeView"
-               title="&customizeCmd.label;"
+    <!-- View / Toolbars -->
+    <panelview id="appMenu-toolbarsView"
+               title="&viewToolbarsMenu.label;"
                class="PanelUI-subView">
       <vbox class="panel-subview-body">
-        <toolbarbutton id="appmenu_MessagePaneLayout"
-                       class="subviewbutton subviewbutton-nav"
-                       label="&messagePaneLayoutStyle.label;"
-                       closemenu="none"
-                       oncommand="PanelUI.showSubView('appMenu-preferencesLayoutView', this)"/>
-        <toolbarseparator/>
         <toolbarbutton id="appmenu_quickFilterBar"
                        class="subviewbutton subviewbutton-iconic"
                        type="checkbox"
                        label="&quickFilterBar.toggleBarVisibility.appmenu.label;"
+                       closemenu="none"
                        command="cmd_toggleQuickFilterBar"/>
         <toolbarbutton id="appmenu_showStatusbar"
                        class="subviewbutton subviewbutton-iconic"
                        type="checkbox"
                        label="&showTaskbarCmd.label;"
                        oncommand="goToggleToolbar('status-bar', 'menu_showTaskbar')"
+                       closemenu="none"
                        checked="true"
                        observes="menu_showTaskbar"/>
         <toolbarseparator id="appmenu_toggleToolbarsSeparator"/>
         <toolbarbutton id="appmenu_toolbarLayout"
                        class="subviewbutton subviewbutton-iconic"
                        label="&appmenuToolbarLayout.label;"
                        command="cmd_CustomizeMailToolbar"/>
       </vbox>
     </panelview>
 
-    <!-- Preferences / Layout -->
+    <!-- View / Layout -->
     <panelview id="appMenu-preferencesLayoutView"
                title="&messagePaneLayoutStyle.label;"
                class="PanelUI-subView">
       <vbox class="panel-subview-body">
         <toolbarbutton id="appmenu_messagePaneClassic"
                        class="subviewbutton subviewbutton-iconic"
                        type="radio"
                        label="&messagePaneClassic.label;"
@@ -607,16 +598,29 @@
     </panelview>
 
     <!-- View -->
     <panelview id="appMenu-viewView"
                title="&viewMenu.label;"
                class="PanelUI-subView">
       <vbox id="appMenu-viewViewItems"
             class="panel-subview-body">
+        <toolbarbutton id="appmenu_Toolbars"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&viewToolbarsMenu.label;"
+                       accesskey="&viewToolbarsMenu.accesskey;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-toolbarsView', this)"/>
+        <toolbarseparator/>
+        <toolbarbutton id="appmenu_MessagePaneLayout"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&messagePaneLayoutStyle.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-preferencesLayoutView', this)"/>
+        <toolbarseparator/>
         <toolbarbutton id="appmenu_FolderViews"
                        class="subviewbutton subviewbutton-nav"
                        label="&folderView.label;"
                        closemenu="none"
                        oncommand="PanelUI.showSubView('appMenu-foldersView', this)"/>
 #ifdef MAIN_WINDOW
         <toolbarseparator id="appmenu_calendar-view-menu-separator"
                           class="hide-when-calendar-deactivated"/>
--- a/mail/components/customizableui/content/panelUI.js
+++ b/mail/components/customizableui/content/panelUI.js
@@ -385,23 +385,24 @@ const PanelUI = {
       case "appMenu-addonsView":
         initAddonPrefsMenu(
           event.target.querySelector(".panel-subview-body"),
           "toolbarbutton",
           "subviewbutton subviewbutton-iconic",
           "subviewbutton subviewbutton-iconic"
         );
         break;
-      case "appMenu-customizeView":
+      case "appMenu-toolbarsView":
         onViewToolbarsPopupShowing(
           event,
           "mail-toolbox",
           document.getElementById("appmenu_quickFilterBar"),
           "toolbarbutton",
-          "subviewbutton subviewbutton-iconic"
+          "subviewbutton subviewbutton-iconic",
+          true
         );
         break;
       case "appMenu-preferencesLayoutView":
         PanelUI._onPreferencesLayoutViewShow(event);
         break;
       // View
       case "appMenu-viewSortByView":
         InitAppViewSortByMenu();