Bug 677539 - Bookmarking group of tabs greyed out after restart with session restore. r=Neil a=Callek
authorJens Hatlak <jh@junetz.de>
Sat, 13 Aug 2011 12:40:20 +0200
changeset 8368 271501c7d9a22bcaa71db5787d6e5d1c9a3de8d5
parent 8367 a9f91402bf4c67800f271984834bbdc84f5e60a7
child 8369 9c7f4200754d15645795987dc45345d616be9643
push idunknown
push userunknown
push dateunknown
reviewersNeil, Callek
bugs677539
Bug 677539 - Bookmarking group of tabs greyed out after restart with session restore. r=Neil a=Callek
suite/browser/navigator.js
suite/browser/navigator.xul
suite/browser/navigatorOverlay.xul
suite/common/bookmarks/browser-places.js
--- a/suite/browser/navigator.js
+++ b/suite/browser/navigator.js
@@ -710,19 +710,16 @@ function Startup()
 
   // Before and after callbacks for the customizeToolbar code
   getNavToolbox().customizeInit = BrowserToolboxCustomizeInit;
   getNavToolbox().customizeDone = BrowserToolboxCustomizeDone;
   getNavToolbox().customizeChange = BrowserToolboxCustomizeChange;
 
   PlacesToolbarHelper.init();
 
-  // bookmark-all-tabs command
-  gBookmarkAllTabsHandler.init();
-
   gBrowser.mPanelContainer.addEventListener("InstallBrowserTheme", LightWeightThemeWebInstaller, false, true);
   gBrowser.mPanelContainer.addEventListener("PreviewBrowserTheme", LightWeightThemeWebInstaller, false, true);
   gBrowser.mPanelContainer.addEventListener("ResetBrowserThemePreview", LightWeightThemeWebInstaller, false, true);
 
   DownloadTaskbarIntegration.onBrowserWindowLoad(window);
 
   // initialize the sync UI
   gSyncUI.init();
@@ -1032,45 +1029,16 @@ function BrowserReloadSkipCache()
 
 function BrowserHome(aEvent)
 {
   var homePage = getHomePage();
   var where = whereToOpenLink(aEvent, false, true);
   openUILinkArrayIn(homePage, where);
 }
 
-/**
- * This also takes care of updating the command enabled-state when tabs are
- * created or removed.
- */
-var gBookmarkAllTabsHandler = {
-  init: function () {
-    this._command = document.getElementById("Browser:BookmarkAllTabs");
-    gBrowser.tabContainer.addEventListener("TabOpen", this, true);
-    gBrowser.tabContainer.addEventListener("TabClose", this, true);
-  },
-
-  _updateCommandState: function BATH__updateCommandState(aTabClose) {
-    // The TabClose event is fired before the tab is removed from the DOM.
-    // So the only interesting cases are when the number of tabs has just
-    // increased to 2, or is just about to decrease from 2.
-    if (getBrowser().tabs.length == 2)
-      this._command.setAttribute("disabled", aTabClose);
-  },
-
-  doCommand: function BATH_doCommand() {
-    PlacesCommandHook.bookmarkCurrentPages();
-  },
-
-  // nsIDOMEventListener
-  handleEvent: function(aEvent) {
-    this._updateCommandState(aEvent.type == "TabClose");
-  }
-};
-
 const BrowserSearch = {
   addEngine: function(engine, targetDoc) {
     if (!this.searchBar)
       return;
 
     var browser = getBrowser().getBrowserForDocument(targetDoc);
     // ignore search engines from subframes (see bug 479408)
     if (!browser)
--- a/suite/browser/navigator.xul
+++ b/suite/browser/navigator.xul
@@ -417,18 +417,17 @@
                      ondrop="PlacesMenuDNDHandler.onDrop(event);">
         <menupopup id="BMB_bookmarksPopup"
                    placespopup="true"
                    context="placesContext"
                    openInTabs="children"
                    oncommand="BookmarksEventHandler.onCommand(event);"
                    onclick="BookmarksEventHandler.onClick(event);"
                    onpopupshowing="BookmarksMenuButton.onPopupShowing(event);
-                                   if (!this.parentNode._placesView)
-                                     new PlacesMenu(event, 'place:folder=BOOKMARKS_MENU');"
+                                   BookmarksEventHandler.onPopupShowing(event);"
                    tooltip="bhTooltip" popupsinherittooltip="true">
           <menuitem command="Browser:AddBookmark"/>
           <menuitem command="Browser:AddBookmarkAs"/>
           <menuitem command="Browser:BookmarkAllTabs"/>
           <menuitem command="Browser:ManageBookmark"/>
           <menuseparator/>
           <menu id="BMB_feedsMenu" class="menu-iconic feedsMenu" command="feedsMenu"
                 label="&feedsMenu.label;" accesskey="&feedsMenu.accesskey;">
@@ -513,17 +512,17 @@
       <!-- this box is temporary, pending XBLified <browser> -->
       <hbox id="browser" flex="1">
         <tabbrowser id="content"
                     flex="1" contenttooltip="aHTMLTooltip"
                     contentcontextmenu="contentAreaContextMenu"
                     onnewtab="BrowserOpenTab();"
                     onnewtabclick="checkForMiddleClick(this, event);"
                     autocompletepopup="PopupAutoComplete"
-                    onbookmarkgroup="gBookmarkAllTabsHandler.doCommand();"
+                    onbookmarkgroup="PlacesCommandHook.bookmarkCurrentPages();"
                     onclick="return contentAreaClick(event);"
                     oncommand="BrowserOnCommand(event);"/>
         <!-- The oncommand listener above lets us fix bugs like 401575 which
              require error page UI to do privileged things, without letting
              error pages have any privilege themselves. -->
       </hbox>
     </vbox>  
   </hbox>
--- a/suite/browser/navigatorOverlay.xul
+++ b/suite/browser/navigatorOverlay.xul
@@ -187,20 +187,20 @@
     <!-- Bookmarks Menu -->
     <command id="Browser:AddBookmark"
              label="&addCurPageCmd.label;" accesskey="&addCurPageCmd.accesskey;"
              oncommand="PlacesCommandHook.bookmarkCurrentPage(false, PlacesUtils.bookmarksMenuFolderId);"/>
     <command id="Browser:AddBookmarkAs"
              label="&addCurPageAsCmd.label;" accesskey="&addCurPageAsCmd.accesskey;"
              oncommand="PlacesCommandHook.bookmarkPageAs(gBrowser.selectedBrowser, PlacesUtils.bookmarksMenuFolderId);"/>
     <!-- The command is disabled for the hidden window. Otherwise its enabled
-         state is handled by gBookmarkAllTabsHandler. -->
+         state is handled by BookmarksEventHandler.onPopupShowing. -->
     <command id="Browser:BookmarkAllTabs"
              label="&addCurTabsAsCmd.label;" accesskey="&addCurTabsAsCmd.accesskey;"
-             oncommand="gBookmarkAllTabsHandler.doCommand();"
+             oncommand="PlacesCommandHook.bookmarkCurrentPages();"
              disabled="true"/>
     <command id="Browser:ManageBookmark"
              label="&manBookmarksCmd.label;" accesskey="&manBookmarksCmd.accesskey;"
              oncommand="PlacesCommandHook.showBookmarksManager('AllBookmarks');"/>
     <command id="feedsMenu" disabled="true"/>
 
     <!-- Go Menu -->  
     <command id="Browser:Home"    oncommand="BrowserHome(event);"/>
@@ -434,18 +434,17 @@
           ondragover="PlacesMenuDNDHandler.onDragOver(event);"
           ondrop="PlacesMenuDNDHandler.onDrop(event);">
       <menupopup id="bookmarksMenuPopup"
                  placespopup="true"
                  context="placesContext"
                  openInTabs="children"
                  oncommand="BookmarksEventHandler.onCommand(event);"
                  onclick="BookmarksEventHandler.onClick(event);"
-                 onpopupshowing="if (!document.getElementById('bookmarksMenu')._placesView)
-                                   new PlacesMenu(event, 'place:folder=BOOKMARKS_MENU');"
+                 onpopupshowing="BookmarksEventHandler.onPopupShowing(event);"
                  tooltip="bhTooltip" popupsinherittooltip="true">
         <menuitem id="menu_bookmarkThisPage"
                   command="Browser:AddBookmark"
                   key="addBookmarkKb"/>
         <menuitem id="menu_bookmarkThisPageAs"
                   command="Browser:AddBookmarkAs"
                   key="addBookmarkAsKb"/>
         <menuitem id="menu_bookmarkAllTabs"
--- a/suite/common/bookmarks/browser-places.js
+++ b/suite/common/bookmarks/browser-places.js
@@ -540,16 +540,24 @@ var BookmarksEventHandler = {
    *        DOMEvent for the command
    */
   onCommand: function BEH_onCommand(aEvent) {
     var target = aEvent.originalTarget;
     if (target._placesNode)
       PlacesUIUtils.openNodeWithEvent(target._placesNode, aEvent);
   },
 
+  onPopupShowing: function BEH_onPopupShowing(aEvent) {
+    if (!document.getElementById('bookmarksMenu')._placesView)
+      new PlacesMenu(aEvent, 'place:folder=BOOKMARKS_MENU');
+
+    document.getElementById("Browser:BookmarkAllTabs")
+            .setAttribute("disabled", getBrowser().tabs.length == 1);
+  },
+  
   fillInBHTooltip: function BEH_fillInBHTooltip(aDocument, aEvent) {
     var node;
     var cropped = false;
     var targetURI;
 
     if (aDocument.tooltipNode.localName == "treechildren") {
       var tree = aDocument.tooltipNode.parentNode;
       var row = {}, column = {};