Bug 464653 Toolbar context menu improvements and fixes. r=Neil.
authorPhilip Chee <philip.chee@gmail.com>
Fri, 18 Mar 2011 22:54:01 +0800
changeset 7372 b8d6fb8e050acf9a9e86e60402e8157fa52f310a
parent 7371 f7715f57e4d3785200161ada08f312437f46601f
child 7373 1e62cbf1840c43eaf2f2248e3943a28879d44297
push idunknown
push userunknown
push dateunknown
reviewersNeil
bugs464653
Bug 464653 Toolbar context menu improvements and fixes. r=Neil.
suite/browser/linkToolbarOverlay.xul
suite/browser/navigator.js
suite/browser/navigator.xul
suite/browser/navigatorOverlay.xul
suite/common/utilityOverlay.js
suite/common/utilityOverlay.xul
suite/mailnews/addrbook/addressbook.xul
suite/mailnews/compose/messengercompose.xul
suite/mailnews/mailWindowOverlay.xul
suite/mailnews/messenger.xul
--- a/suite/browser/linkToolbarOverlay.xul
+++ b/suite/browser/linkToolbarOverlay.xul
@@ -60,20 +60,21 @@
   </script>
 
   <stringbundleset>
     <stringbundle id="languageBundle"
                   src="chrome://global/locale/languageNames.properties"/>
   </stringbundleset>
 
   <menupopup id="view_toolbars_popup">
-    <menu label="&linkToolbar.label;" position="3"
+    <menu label="&linkToolbar.label;"
           accesskey="&linkToolbar.accesskey;"
-          oncommand="linkToolbarUI.toggleLinkToolbar(event.target)"
-          onpopupshowing="linkToolbarUI.initLinkbarVisibilityMenu()">
+          insertbefore="menuitem_showhide_tabbar"
+          onpopupshowing="linkToolbarUI.initLinkbarVisibilityMenu();"
+          oncommand="linkToolbarUI.toggleLinkToolbar(event.target);">
       <menupopup>
         <menuitem label="&linkToolbarAlways.label;"
                   accesskey="&linkToolbarAlways.accesskey;"
                   class="menuitem-iconic" type="radio" value="false"
                   name="cmd_viewlinktoolbar" id="cmd_viewlinktoolbar_false" />
         <menuitem label="&linkToolbarAsNeeded.label;"
                   accesskey="&linkToolbarAsNeeded.accesskey;"
                   class="menuitem-iconic" type="radio" value="maybe"
--- a/suite/browser/navigator.js
+++ b/suite/browser/navigator.js
@@ -2373,18 +2373,19 @@ function updateComponentBarBroadcaster()
       compBarBroadcaster.setAttribute('checked', 'true');
   }
   else {
     compBarBroadcaster.setAttribute('disabled', 'true');
     compBarBroadcaster.removeAttribute('checked');
   }
 }
 
-function updateToolbarStates(toolbarMenuElt)
+function updateToolbarStates(aEvent)
 {
+  onViewToolbarsPopupShowing(aEvent);
   updateComponentBarBroadcaster();
 
   const tabbarMenuItem = document.getElementById("menuitem_showhide_tabbar");
   // Make show/hide menu item reflect current state
   const visibility = gBrowser.getStripVisibility();
   tabbarMenuItem.setAttribute("checked", visibility);
 
   // Don't allow the tab bar to be shown/hidden when more than one tab is open
--- a/suite/browser/navigator.xul
+++ b/suite/browser/navigator.xul
@@ -196,17 +196,16 @@
         <menubar id="main-menubar"/>
       </toolbaritem>
     </toolbar>
 
     <toolbar class="toolbar-primary chromeclass-toolbar" id="nav-bar" persist="collapsed" 
              grippytooltiptext="&navigationToolbar.tooltip;"
              fullscreentoolbar="true" customizable="true"
              toolbarname="&navbarCmd.label;" accesskey="&navbarCmd.accesskey;"
-             togglemenuitem="cmd_viewnavbar"
              defaultset="back-button,forward-button,reload-button,stop-button,nav-bar-inner,search-button-container,print-button,throbber-box,window-controls"
              context="toolbar-context-menu">
 
       <hbox id="window-controls" hidden="true" fullscreencontrol="true">
         <toolbarbutton id="minimize-button"
                        tooltiptext="&minimizeButton.tooltip;"
                        oncommand="window.minimize();"/>
 
@@ -224,17 +223,16 @@
 
     <toolbar id="PersonalToolbar"
              accesskey="&personalbarCmd.accesskey;"
              class="chromeclass-directories"
              persist="collapsed"
              grippytooltiptext="&personalToolbar.tooltip;"
              toolbarname="&personalbarCmd.label;"
              nowindowdrag="true"
-             togglemenuitem="cmd_viewpersonaltoolbar"
              customizable="true"
              defaultset="home-button,separator,bookmarks-button,personal-bookmarks"
              mode="full"
              iconsize="small"
              labelalign="end"
              defaultmode="full"
              defaulticonsize="small"
              defaultlabelalign="end"
--- a/suite/browser/navigatorOverlay.xul
+++ b/suite/browser/navigatorOverlay.xul
@@ -217,18 +217,16 @@
 
   </commandset>
 
   <broadcasterset id="navBroadcasters">
     <broadcaster id="canGoBack"    disabled="true"/>
     <broadcaster id="canGoForward" disabled="true"/>
     <broadcaster id="canGoUp"      disabled="true"/>
     <broadcaster id="Communicator:WorkMode"/>
-    <broadcaster id="cmd_viewnavbar" oncommand="goToggleToolbar( 'nav-bar','cmd_viewnavbar');" checked="true"/>
-    <broadcaster id="cmd_viewpersonaltoolbar" oncommand="goToggleToolbar('PersonalToolbar','cmd_viewpersonaltoolbar');" checked="true"/>
     <broadcaster id="cmd_viewtaskbar" oncommand="goToggleToolbar('status-bar','cmd_viewtaskbar'); updateWindowResizer();" checked="true"/>
     <broadcaster id="cmd_viewcomponentbar" oncommand="goToggleToolbar('component-bar', 'cmd_viewcomponentbar');" checked="true"/>
     <broadcaster id="isImage"/>
   </broadcasterset>
          
   <!-- bookmarks context menu -->
   <popupset id="bookmarksPopupset">
     <menupopup id="bookmarks-context-menu" 
@@ -312,19 +310,19 @@
         <menuseparator id="menu_PrefsSeparator"/> 
         <menuitem id="menu_preferences" oncommand="goPreferences('navigator_pane')"/>
       </menupopup>
     </menu>
 
     <menu id="menu_View" accesskey="&viewMenu.accesskey;" label="&viewMenu.label;">
       <menupopup id="menu_View_Popup">
         <menu label="&toolbarsCmd.label;" accesskey="&toolbarsCmd.accesskey;" id="menu_Toolbars">
-          <menupopup id="view_toolbars_popup" onpopupshowing="updateToolbarStates(this);"> 
-            <menuitem label="&navbarCmd.label;" accesskey="&navbarCmd.accesskey;" class="menuitem-iconic" type="checkbox" observes="cmd_viewnavbar"  />
-            <menuitem label="&personalbarCmd.label;" accesskey="&personalbarCmd.accesskey;" class="menuitem-iconic" type="checkbox" observes="cmd_viewpersonaltoolbar" />
+          <menupopup id="view_toolbars_popup"
+                     onpopupshowing="updateToolbarStates(event);"
+                     oncommand="onViewToolbarCommand(event);">
             <menuitem id="menuitem_showhide_tabbar" label="&tabbarCmd.label;" accesskey="&tabbarCmd.accesskey;" class="menuitem-iconic" type="checkbox" oncommand="showHideTabbar();" checked="true"/>
             <menuitem label="&taskbarCmd.label;" accesskey="&taskbarCmd.accesskey;" class="menuitem-iconic" type="checkbox" observes="cmd_viewtaskbar" />
             <menuitem label="&componentbarCmd.label;" accesskey="&componentbarCmd.accesskey;" class="menuitem-iconic" type="checkbox" observes="cmd_viewcomponentbar"/>
           </menupopup>
         </menu>   
         <menuitem id="menuitem_fullScreen"
                   label="&fullScreenCmd.label;"
                   accesskey="&fullScreenCmd.accesskey;"
--- a/suite/common/utilityOverlay.js
+++ b/suite/common/utilityOverlay.js
@@ -313,46 +313,60 @@ function goCustomizeToolbar(toolbox)
   else {
     return window.openDialog(customizeURL,
                              "",
                              "chrome,all,dependent",
                              toolbox);
   }
 }
 
-function onViewToolbarsPopupShowing(aEvent)
+function onViewToolbarsPopupShowing(aEvent, aInsertPoint)
 {
   var popup = aEvent.target;
+  if (popup != aEvent.currentTarget)
+    return;
 
   // Empty the menu
   var deadItems = popup.getElementsByAttribute("toolbarid", "*");
   for (let i = deadItems.length - 1; i >= 0; --i)
     popup.removeChild(deadItems[i]);
 
-  var firstMenuItem = popup.firstChild;
+  var firstMenuItem = aInsertPoint || popup.firstChild;
 
-  var toolbar = document.popupNode;
+  var toolbar = document.popupNode || popup;
   while (toolbar.localName != "toolbar")
     toolbar = toolbar.parentNode;
-  var toolbox = toolbar.parentNode;
+  var toolbox = toolbar.toolbox;
 
-  var toolbars = toolbox.getElementsByAttribute("toolbarname", "*");
-  for (let i = 0; i < toolbars.length; ++i) {
-    let bar = toolbars[i];
+  var toolbars = Array.slice(toolbox.getElementsByAttribute("toolbarname", "*"));
+  toolbars = toolbars.concat(toolbox.externalToolbars);
+
+  toolbars.forEach(function(bar) {
     let menuItem = document.createElement("menuitem");
+    menuItem.setAttribute("id", "toggle_" + bar.id);
     menuItem.setAttribute("toolbarid", bar.id);
     menuItem.setAttribute("type", "checkbox");
     menuItem.setAttribute("label", bar.getAttribute("toolbarname"));
     menuItem.setAttribute("accesskey", bar.getAttribute("accesskey"));
     menuItem.setAttribute("checked", !bar.hidden);
     popup.insertBefore(menuItem, firstMenuItem);
-  }
+  });
+}
+
+function onToolbarModePopupShowing(aEvent)
+{
+  var popup = aEvent.target;
+
+  var toolbar = document.popupNode;
+  while (toolbar.localName != "toolbar")
+    toolbar = toolbar.parentNode;
+  var toolbox = toolbar.toolbox;
 
   var mode = toolbar.getAttribute("mode") || "full";
-  var modePopup = document.getElementById("toolbarmodePopup");
+  var modePopup = document.getElementById("toolbarModePopup");
   var radio = modePopup.getElementsByAttribute("value", mode);
   radio[0].setAttribute("checked", "true");
 
   var small = toolbar.getAttribute("iconsize") == "small";
   var smallicons = document.getElementById("toolbarmode-smallicons");
   smallicons.setAttribute("checked", small);
   smallicons.setAttribute("disabled", mode == "text");
 
@@ -384,18 +398,18 @@ function onViewToolbarsPopupShowing(aEve
   var menuitem  = document.getElementById("customize_toolbars");
   menuitem.hidden = !command;
   menuitem.previousSibling.hidden = !command;
 }
 
 function onViewToolbarCommand(aEvent)
 {
   var toolbar = aEvent.originalTarget.getAttribute("toolbarid");
-  var menuitem = document.getElementById(toolbar).getAttribute("togglemenuitem");
-  goToggleToolbar(toolbar, menuitem);
+  if (toolbar)
+    goToggleToolbar(toolbar);
 }
 
 function goSetToolbarState(aEvent)
 {
   aEvent.stopPropagation();
   var toolbar = document.popupNode;
   while (toolbar.localName != "toolbar")
     toolbar = toolbar.parentNode;
--- a/suite/common/utilityOverlay.xul
+++ b/suite/common/utilityOverlay.xul
@@ -76,18 +76,18 @@
 
   <menupopup id="toolbar-context-menu"
          onpopupshowing="onViewToolbarsPopupShowing(event);"
          oncommand="onViewToolbarCommand(event);">
     <menuseparator id="toolbarmode-sep"/>
     <menu id="toolbarmode-context-menu"
           label="&customizeToolbar.toolbarmode.label;"
           accesskey="&customizeToolbar.toolbarmode.accesskey;">
-      <menupopup id="toolbarmodePopup"
-                 onpopupshowing="event.stopPropagation();"
+      <menupopup id="toolbarModePopup"
+                 onpopupshowing="onToolbarModePopupShowing(event);"
                  oncommand="goSetToolbarState(event);">
         <menuitem type="radio" name="mode" value="icons"
                   label="&customizeToolbar.icons.label;"
                   accesskey="&customizeToolbar.icons.accesskey;"/>
         <menuitem type="radio" name="mode" value="full"
                   label="&customizeToolbar.iconsAndText.label;"
                   accesskey="&customizeToolbar.iconsAndText.accesskey;"/>
         <menuitem type="radio" name="mode" value="text"
--- a/suite/mailnews/addrbook/addressbook.xul
+++ b/suite/mailnews/addrbook/addressbook.xul
@@ -284,22 +284,19 @@
                       command="cmd_properties"/>
             <menuitem id="menu_preferences"
                       oncommand="goPreferences('addressing_pane')"/>
           </menupopup>
         </menu>
         <menu id="menu_View">
             <menupopup id="menu_View_Popup">
                 <menu id="menu_Toolbars">
-                    <menupopup id="view_toolbars_popup">
-                        <menuitem id="menu_showAbToolbar"
-                                  label="&showAbToolbarCmd.label;"
-                                  accesskey="&showAbToolbarCmd.accesskey;"
-                                  oncommand="goToggleToolbar('ab-bar2', 'menu_showAbToolbar')"
-                                  checked="true" type="checkbox"/>
+                    <menupopup id="view_toolbars_popup"
+                               onpopupshowing="onViewToolbarsPopupShowing(event)"
+                               oncommand="onViewToolbarCommand(event);">
                         <menuitem id="menu_showTaskbar"/>
                         <menuseparator/>
                         <menuitem id="menu_showCardPane"
                                   label="&showCardPane.label;"
                                   accesskey="&showCardPane.accesskey;"
                                   oncommand="goToggleSplitter('results-splitter', 'menu_showCardPane')"
                                   checked="true" type="checkbox"/>
                     </menupopup>
@@ -415,17 +412,16 @@
   <toolbar class="chromeclass-toolbar toolbar-primary"
            id="ab-bar2"
            persist="collapsed"
            customizable="true"
            grippytooltiptext="&addressbookToolbar.tooltip;"
            toolbarname="&showAbToolbarCmd.label;"
            accesskey="&showAbToolbarCmd.accesskey;"
            defaultset="button-newcard,button-newlist,separator,button-editcard,button-newmessage,button-newim,button-abdelete,spring,searchBox,throbber-box"
-           togglemenuitem="menu_showAbToolbar"
            context="toolbar-context-menu">
     <toolbarbutton id="button-newcard"
                    class="toolbarbutton-1"
                    label="&newContactButton.label;"
                    tooltiptext="&newContactButton.tooltip;"
                    removable="true"
                    oncommand="AbNewCard();"/>
     <toolbarbutton id="button-newlist"
--- a/suite/mailnews/compose/messengercompose.xul
+++ b/suite/mailnews/compose/messengercompose.xul
@@ -134,21 +134,16 @@
   <!--command id="cmd_pasteQuote"/  DO NOT INCLUDE THOSE COMMANDS ELSE THE EDIT MENU WILL BE BROKEN! -->
   <!--command id="cmd_find"/-->
   <!--command id="cmd_findNext"/-->
   <command id="cmd_rewrap"  oncommand="goDoCommand('cmd_rewrap')"/>
   <command id="cmd_renameAttachment" oncommand="goDoCommand('cmd_renameAttachment')" disabled="true"/>
   <command id="cmd_openAttachment" oncommand="goDoCommand('cmd_openAttachment')"/>
   <command id="cmd_account" oncommand="goDoCommand('cmd_account')"/>
 
-  <!-- View Menu -->
-  <command id="cmd_viewComposeToolbar"
-           oncommand="goToggleToolbar('composeToolbar', 'cmd_viewComposeToolbar');"
-           checked="true"/>
-
   <!-- Options Menu -->
   <command id="cmd_selectAddress" oncommand="goDoCommand('cmd_selectAddress')"/>
   <command id="cmd_outputFormat" oncommand="OutputFormatMenuSelect(event.target)"/>
   <command id="cmd_quoteMessage" oncommand="goDoCommand('cmd_quoteMessage')"/>
 
   <command id="cmd_CustomizeToolbars" oncommand="goCustomizeToolbar(getMailToolbox());"/>
 </commandset>
 
@@ -411,22 +406,19 @@
                         command="cmd_account"/>
               <menuitem id="menu_preferences"
                         oncommand="goDoCommand('cmd_preferences')"/>
             </menupopup>
           </menu>
           <menu id="menu_View">
             <menupopup id="menu_View_Popup">
               <menu id="menu_Toolbars">
-                <menupopup id="view_toolbars_popup">
-                  <menuitem id="menu_showComposeToolbar"
-                            type="checkbox"
-                            label="&showComposeToolbarCmd.label;"
-                            accesskey="&showComposeToolbarCmd.accesskey;"
-                            command="cmd_viewComposeToolbar"/>
+                <menupopup id="view_toolbars_popup"
+                           onpopupshowing="onViewToolbarsPopupShowing(event)"
+                           oncommand="onViewToolbarCommand(event);">
                   <menuitem id="menu_showFormatToolbar"
                             type="checkbox"
                             label="&showFormatToolbarCmd.label;"
                             accesskey="&showFormatToolbarCmd.accesskey;"
                             command="cmd_viewFormatToolbar"/>
                   <menuitem id="menu_showTaskbar"/>
                 </menupopup>
               </menu>
@@ -575,17 +567,16 @@
     <toolbar id="composeToolbar"
              class="toolbar-primary chromeclass-toolbar"
              persist="collapsed"
              grippytooltiptext="&mailToolbar.tooltip;"
              toolbarname="&showComposeToolbarCmd.label;"
              accesskey="&showComposeToolbarCmd.accesskey;"
              customizable="true"
              defaultset="button-send,separator,button-address,button-attach,spellingButton,button-security,separator,button-save,spring,throbber-box"
-             togglemenuitem="cmd_viewComposeToolbar"
              context="toolbar-context-menu">
     </toolbar>
 
     <toolbarset id="customToolbars" context="toolbar-context-menu"/>
 
     <toolbar id="MsgHeadersToolbar"
              persist="collapsed"
              flex="1"
--- a/suite/mailnews/mailWindowOverlay.xul
+++ b/suite/mailnews/mailWindowOverlay.xul
@@ -1147,30 +1147,19 @@
                 oncommand="MsgAccountManager(null);"/>
       <menuitem id="menu_preferences" oncommand="goPreferences('mailnews_pane')"/>
     </menupopup>
   </menu>
 
   <menu id="menu_View">
     <menupopup id="menu_View_Popup" onpopupshowing="view_init()">
       <menu id="menu_Toolbars">
-        <menupopup id="view_toolbars_popup">
-          <menuitem id="menu_showMessengerToolbar"
-                    type="checkbox"
-                    checked="true"
-                    label="&showMessengerToolbarCmd.label;"
-                    accesskey="&showMessengerToolbarCmd.accesskey;"
-                    oncommand="goToggleToolbar('msgToolbar', 'menu_showMessengerToolbar');"/>
-          <menuitem id="menu_showSearchToolbar"
-                    type="checkbox"
-                    checked="true"
-                    label="&showSearchToolbarCmd.label;"
-                    accesskey="&showSearchToolbarCmd.accesskey;"
-                    observes="mailHideMenus"
-                    oncommand="goToggleToolbar('searchToolbar', 'menu_showSearchToolbar');"/>
+        <menupopup id="view_toolbars_popup"
+                   onpopupshowing="onViewToolbarsPopupShowing(event)"
+                   oncommand="onViewToolbarCommand(event);">
           <menuitem id="menu_showTaskbar"/>
         </menupopup>
       </menu>
       <menu id="menu_MessagePaneLayout" label="&messagePaneLayoutStyle.label;"
             accesskey="&messagePaneLayoutStyle.accesskey;" observes="mailHideMenus">
         <menupopup id="view_layout_popup" onpopupshowing="InitViewLayoutStyleMenu(event)">
           <menuitem id="messagePaneClassic" type="radio" label="&messagePaneClassic.label;" name="viewlayoutgroup"
                     accesskey="&messagePaneClassic.accesskey;" oncommand="ChangeMailLayout(kClassicMailLayout);"/>
@@ -1932,17 +1921,16 @@
   <toolbar class="toolbar-primary chromeclass-toolbar"
            id="msgToolbar"
            persist="collapsed"
            grippytooltiptext="&mailToolbar.tooltip;"
            toolbarname="&showMessengerToolbarCmd.label;"
            accesskey="&showMessengerToolbarCmd.accesskey;"
            customizable="true"
            defaultset="button-getmsg,button-newmsg,separator,button-reply,button-replyall,button-forward,separator,button-goback,button-goforward,button-next,button-junk,button-delete,button-mark,spring,throbber-box"
-           togglemenuitem="menu_showMessengerToolbar"
            context="toolbar-context-menu">
   </toolbar>
   <toolbarset id="customToolbars" context="toolbar-context-menu"/>
 
   <toolbarpalette id="MailToolbarPalette">
     <toolbarbutton id="button-getmsg"
                    class="toolbarbutton-1"
                    type="menu-button"
--- a/suite/mailnews/messenger.xul
+++ b/suite/mailnews/messenger.xul
@@ -163,17 +163,16 @@
              nowindowdrag="true"
              mode="full"
              iconsize="small"
              labelalign="end"
              defaultmode="full"
              defaulticonsize="small"
              defaultlabelalign="end"
              defaultset="mailviews-container,spring,search-container,button-search-container"
-             togglemenuitem="menu_showSearchToolbar"
              context="toolbar-context-menu"/>
   </toolbox>
 
   <!-- XXX This extension point (tabmail-container) is only temporary!
            (See bug 460252 for details.)
            We will readd a mechanism for sidebar panes in bug 178003.
     -->
   <hbox id="tabmail-container" flex="1">