| Index: lib/inspectorObserver.js |
| =================================================================== |
| --- a/lib/inspectorObserver.js |
| +++ b/lib/inspectorObserver.js |
| @@ -4,26 +4,16 @@ |
| * http://mozilla.org/MPL/2.0/. |
| */ |
| -Cu.import("resource://gre/modules/Services.jsm"); |
| -Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
| +Cu.import("resource:///modules/devtools/gDevTools.jsm"); |
|
Wladimir Palant
2014/04/11 11:06:08
While you are at it, please don't use a blind impo
saroyanm
2014/04/11 16:09:10
Got it.
|
| let InspectorObserver = |
| { |
| init: function() |
| { |
| - Services.obs.addObserver(this, "inspector-opened", true); |
| + gDevTools.on("inspector-ready", this.inspectorReady); |
| onShutdown.add(function() |
| { |
| - Services.obs.removeObserver(this, "inspector-opened"); |
| - |
| - let e = Services.ww.getWindowEnumerator(); |
| - while (e.hasMoreElements()) |
| - { |
| - let window = e.getNext().QueryInterface(Ci.nsIDOMWindow); |
| - let button = window.document.getElementById("inspector-abp-elemhide-toolbutton"); |
| - if (button) |
| - button.parentNode.removeChild(button); |
| - } |
| + gDevTools.off("inspector-ready", this.inspectorReady); |
| }.bind(this)); |
| }, |
| @@ -37,27 +27,24 @@ |
| this.__defineGetter__("inspectorButton", function() result); |
| return this.inspectorButton; |
| }, |
| - |
| - observe: function(subject, topic, data) |
| + |
| + inspectorReady: function(eventName, listener) |
|
Wladimir Palant
2014/04/11 11:06:08
The second parameter here isn't listener but panel
saroyanm
2014/04/11 16:09:10
Good catch, actually I've tested and seams like th
|
| { |
| - if (topic != "inspector-opened") |
| + let toolbox = gDevTools.getToolbox(listener.target); |
|
Wladimir Palant
2014/04/11 11:06:08
I checked why the documentation mentions getToolbo
saroyanm
2014/04/11 16:09:10
Good point: I've tested with FF19 and there is an
|
| + if (!toolbox) |
| return; |
| - |
| - let InspectorUI = subject.wrappedJSObject; |
| - let window = InspectorUI.chromeWin; |
| - let button = window.document.getElementById("inspector-abp-elemhide-toolbutton"); |
| - if (button) |
| - button.parentNode.removeChild(button); |
| - |
| - if (!("@adblockplus.org/abp/public;1" in Cc) || !window._ehhWrapper || !require("aardvark").Aardvark.canSelect(window._ehhWrapper.browser)) |
| + |
| + let panel = toolbox.getToolPanels().get("inspector"); |
| + if (!panel) |
| return; |
|
Wladimir Palant
2014/04/11 11:06:08
So you are going from the panel to the toolbox to
saroyanm
2014/04/11 16:09:10
Lol :)
|
| - |
| - let parent = window.document.getElementById("inspector-tools"); |
| + |
| + let panelWindow = panel.panelWin; |
| + let parent = panelWindow.document.getElementById("inspector-toolbar"); |
| if (!parent) |
| return; |
| - |
| - let [label, accesskey, tooltiptext] = this.inspectorButton; |
| - button = window.document.createElement("toolbarbutton"); |
| + |
| + let [label, accesskey, tooltiptext] = InspectorObserver.inspectorButton; |
| + button = panelWindow.document.createElement("toolbarbutton"); |
| button.setAttribute("id", "inspector-abp-elemhide-toolbutton"); |
| button.setAttribute("label", label); |
| button.setAttribute("class", "devtools-toolbarbutton"); |
| @@ -66,14 +53,11 @@ |
| button.setAttribute("tabindex", "0"); |
| button.addEventListener("command", function() |
| { |
| - InspectorUI.chromeWin.openDialog("chrome://elemhidehelper/content/composer.xul", "_blank", |
| - "chrome,centerscreen,resizable,dialog=no", InspectorUI.selection); |
| - InspectorUI.closeInspectorUI(); |
| + panelWindow.openDialog("chrome://elemhidehelper/content/composer.xul", "_blank", |
| + "chrome,centerscreen,resizable,dialog=no", panel.selection.node); |
| }, false); |
| parent.appendChild(button); |
|
Wladimir Palant
2014/04/11 11:06:08
Adding the button at the end probably isn't the be
saroyanm
2014/04/11 16:09:10
Good point changed. Thanks for pointing.
|
| - }, |
| - |
| - QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObserver]) |
| + } |
| }; |
| InspectorObserver.init(); |