From 8cbb06204116267a6000965cd970b06603f43fec Mon Sep 17 00:00:00 2001 From: Alexandre Poirot Date: Tue, 3 May 2016 09:06:30 -0700 Subject: [PATCH] Bug 1265599 - Fix gcli toolbox button status when toolbox goes on and off. r=jwalker --- devtools/client/framework/devtools-browser.js | 6 +++--- devtools/client/shared/developer-toolbar.js | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/devtools/client/framework/devtools-browser.js b/devtools/client/framework/devtools-browser.js index d80ca20e4e2b..782b38baed63 100644 --- a/devtools/client/framework/devtools-browser.js +++ b/devtools/client/framework/devtools-browser.js @@ -584,11 +584,11 @@ var gDevToolsBrowser = exports.gDevToolsBrowser = { let hasToolbox = gDevToolsBrowser.hasToolboxOpened(win); - let broadcaster = win.document.getElementById("menu_devToolbox"); + let menu = win.document.getElementById("menu_devToolbox"); if (hasToolbox) { - broadcaster.setAttribute("checked", "true"); + menu.setAttribute("checked", "true"); } else { - broadcaster.removeAttribute("checked"); + menu.removeAttribute("checked"); } } }, diff --git a/devtools/client/shared/developer-toolbar.js b/devtools/client/shared/developer-toolbar.js index 50be63148072..42cd9fa157c0 100644 --- a/devtools/client/shared/developer-toolbar.js +++ b/devtools/client/shared/developer-toolbar.js @@ -28,6 +28,7 @@ loader.lazyGetter(this, "toolboxStrings", function () { loader.lazyRequireGetter(this, "gcliInit", "devtools/shared/gcli/commands/index"); loader.lazyRequireGetter(this, "util", "gcli/util/util"); loader.lazyRequireGetter(this, "ConsoleServiceListener", "devtools/shared/webconsole/utils", true); +loader.lazyRequireGetter(this, "gDevTools", "devtools/client/framework/devtools", true); loader.lazyRequireGetter(this, "gDevToolsBrowser", "devtools/client/framework/devtools-browser", true); /** @@ -240,6 +241,9 @@ function DeveloperToolbar(aChromeWindow) this._warningsCount = {}; this._errorListeners = {}; + this._onToolboxReady = this._onToolboxReady.bind(this); + this._onToolboxDestroyed = this._onToolboxDestroyed.bind(this); + EventEmitter.decorate(this); } exports.DeveloperToolbar = DeveloperToolbar; @@ -496,6 +500,9 @@ DeveloperToolbar.prototype.show = function(focus) { tabbrowser.addEventListener("load", this, true); tabbrowser.addEventListener("beforeunload", this, true); + gDevTools.on("toolbox-ready", this._onToolboxReady); + gDevTools.on("toolbox-destroyed", this._onToolboxDestroyed); + this._initErrorsCount(tabbrowser.selectedTab); this._element.hidden = false; @@ -634,6 +641,9 @@ DeveloperToolbar.prototype.destroy = function() { tabbrowser.removeEventListener("load", this, true); tabbrowser.removeEventListener("beforeunload", this, true); + gDevTools.off("toolbox-ready", this._onToolboxReady); + gDevTools.off("toolbox-destroyed", this._onToolboxDestroyed); + Array.prototype.forEach.call(tabbrowser.tabs, this._stopErrorsCount, this); this.focusManager.removeMonitoredElement(this.outputPanel._frame); @@ -708,6 +718,16 @@ DeveloperToolbar.prototype.handleEvent = function(ev) { } }; +/** + * Update toolbox toggle button when toolbox goes on and off + */ +DeveloperToolbar.prototype._onToolboxReady = function() { + this._errorCounterButton.setAttribute("checked", "true"); +} +DeveloperToolbar.prototype._onToolboxDestroyed = function() { + this._errorCounterButton.setAttribute("checked", "false"); +} + /** * Count a page error received for the currently selected tab. This * method counts the JavaScript exceptions received and CSS errors/warnings.