Bug 682291 / Bug 682406 - Update button with number of tabs on TabOpen/TabRemove events (r=mfinkle)
authorLucas Rocha <lucasr@mozilla.com>
Thu, 15 Sep 2011 21:33:20 +0100
changeset 77025 5f5dc93ba0a8211d11f75a39e4fa51feef05be49
parent 77024 67ad7402608f9b605818c751ef116e02723a662c
child 77026 5131fb5635b54a42a68f6582f5bbea0891c5cc17
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersmfinkle
bugs682291, 682406
milestone9.0a1
Bug 682291 / Bug 682406 - Update button with number of tabs on TabOpen/TabRemove events (r=mfinkle)
mobile/chrome/content/TabsPopup.js
mobile/chrome/content/browser-ui.js
mobile/chrome/content/browser.js
--- a/mobile/chrome/content/TabsPopup.js
+++ b/mobile/chrome/content/TabsPopup.js
@@ -31,16 +31,23 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 var TabsPopup = {
+  init: function() {
+    Elements.tabs.addEventListener("TabOpen", this, true);
+    Elements.tabs.addEventListener("TabRemove", this, true);
+
+    this._updateTabsCount();
+  },
+
   get box() {
     delete this.box;
     return this.box = document.getElementById("tabs-sidebar");
   },
 
   get list() {
     delete this.list;
     return this.list = document.getElementById("tabs");
@@ -63,10 +70,19 @@ var TabsPopup = {
     BrowserUI.pushPopup(this, [this.box, this.button]);
   },
 
   toggle: function toggle() {
     if (this.box.hasAttribute("open"))
       this.hide();
     else
       this.show();
+  },
+
+  _updateTabsCount: function() {
+    let cmd = document.getElementById("cmd_showTabs");
+    cmd.setAttribute("label", Browser.tabs.length);
+  },
+
+  handleEvent: function handleEvent(aEvent) {
+    this._updateTabsCount();
   }
 };
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -426,16 +426,19 @@ var BrowserUI = {
     window.addEventListener("mousedown", this, true);
 
     // listening escape to dismiss dialog on VK_ESCAPE
     window.addEventListener("keypress", this, true);
 
     // listening AppCommand to handle special keys
     window.addEventListener("AppCommand", this, true);
 
+    // Initialize the number of tabs in toolbar
+    TabsPopup.init();
+
     // We can delay some initialization until after startup.  We wait until
     // the first page is shown, then dispatch a UIReadyDelayed event.
     messageManager.addMessageListener("pageshow", function() {
       if (getBrowser().currentURI.spec == "about:blank")
         return;
 
       messageManager.removeMessageListener("pageshow", arguments.callee, true);
 
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -726,36 +726,30 @@ var Browser = {
       this.selectedTab = newTab;
 
     let getAttention = ("getAttention" in params ? params.getAttention : !aBringFront);
     let event = document.createEvent("UIEvents");
     event.initUIEvent("TabOpen", true, false, window, getAttention);
     newTab.chromeTab.dispatchEvent(event);
     newTab.browser.messageManager.sendAsyncMessage("Browser:TabOpen");
 
-    let cmd = document.getElementById("cmd_showTabs");
-    cmd.setAttribute("label", this._tabs.length - 1);
-
     return newTab;
   },
 
   closeTab: function closeTab(aTab, aOptions) {
     let tab = aTab instanceof XULElement ? this.getTabFromChrome(aTab) : aTab;
     if (!tab || !this._getNextTab(tab))
       return;
 
     if (aOptions && "forceClose" in aOptions && aOptions.forceClose) {
       this._doCloseTab(aTab);
       return;
     }
 
     tab.browser.messageManager.sendAsyncMessage("Browser:CanUnload", {});
-
-    let cmd = document.getElementById("cmd_showTabs");
-    cmd.setAttribute("label", this._tabs.length - 1);
   },
 
   _doCloseTab: function _doCloseTab(aTab) {
     let nextTab = this._getNextTab(aTab);
     if (!nextTab)
        return;
 
     // Make sure we leave the toolbar in an unlocked state