Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/inspectorObserver.js

Issue 4780225334345728: Element Hiding Helper inspector tool fix (Closed)
Patch Set: fix after Wladimir comments Created April 11, 2014, 3:53 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This Source Code is subject to the terms of the Mozilla Public License 2 * This Source Code is subject to the terms of the Mozilla Public License
3 * version 2.0 (the "License"). You can obtain a copy of the License at 3 * version 2.0 (the "License"). You can obtain a copy of the License at
4 * http://mozilla.org/MPL/2.0/. 4 * http://mozilla.org/MPL/2.0/.
5 */ 5 */
6 6
7 Cu.import("resource:///modules/devtools/gDevTools.jsm"); 7 let {gDevTools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", null);
8 8
9 let InspectorObserver = 9 let InspectorObserver =
10 { 10 {
11 init: function() 11 init: function()
12 { 12 {
13 gDevTools.on("inspector-ready", this.inspectorReady); 13 gDevTools.on("inspector-ready", this.inspectorReady);
14 onShutdown.add(function() 14 onShutdown.add(function()
15 { 15 {
16 gDevTools.off("inspector-ready", this.inspectorReady); 16 gDevTools.off("inspector-ready", this.inspectorReady);
17 }.bind(this)); 17 }.bind(this));
18 }, 18 },
19 19
20 get inspectorButton() 20 get inspectorButton()
21 { 21 {
22 // Randomize URI to work around bug 719376 22 // Randomize URI to work around bug 719376
23 let stringBundle = Services.strings.createBundle("chrome://elemhidehelper/lo cale/global.properties?" + Math.random()); 23 let stringBundle = Services.strings.createBundle("chrome://elemhidehelper/lo cale/global.properties?" + Math.random());
24 let result = [stringBundle.GetStringFromName("inspector.button.label"), stri ngBundle.GetStringFromName("inspector.button.accesskey"), stringBundle.GetString FromName("inspector.button.tooltiptext")]; 24 let result = [stringBundle.GetStringFromName("inspector.button.accesskey"), stringBundle.GetStringFromName("inspector.button.tooltiptext")];
Wladimir Palant 2014/04/11 18:39:10 An access key only makes sense in combination with
saroyanm 2014/04/12 10:39:35 Wladimir why we need to remove accesskey ? Isn't i
Wladimir Palant 2014/04/12 18:14:11 You probably don't know what access keys are - see
saroyanm 2014/04/12 20:23:20 Thanks for the reference Wladimir, actually I feel
Wladimir Palant 2014/04/12 20:51:26 An access key is not the same thing as a shortcut
saroyanm 2014/04/12 20:59:38 I thought again regarding your notes Wladimir I gu
saroyanm 2014/04/12 21:03:22 Got it. Thanks.
25 25
26 delete this.inspectorButton; 26 delete this.inspectorButton;
27 this.__defineGetter__("inspectorButton", function() result); 27 this.__defineGetter__("inspectorButton", function() result);
28 return this.inspectorButton; 28 return this.inspectorButton;
29 }, 29 },
30 30
31 inspectorReady: function(eventName, listener) 31 inspectorReady: function(eventName, toolbox, panel)
32 { 32 {
33 let toolbox = gDevTools.getToolbox(listener.target); 33 let panelWindow = panel.panelWin;
34 if (!toolbox) 34 let inspectBtn = panelWindow.document.getElementById("inspector-inspect-tool button");
35 if (!inspectBtn)
35 return; 36 return;
36 37
37 let panel = toolbox.getToolPanels().get("inspector"); 38 let [accesskey, tooltiptext] = InspectorObserver.inspectorButton;
38 if (!panel)
39 return;
40
41 let panelWindow = panel.panelWin;
42 let parent = panelWindow.document.getElementById("inspector-toolbar");
43 if (!parent)
44 return;
45
46 let [label, accesskey, tooltiptext] = InspectorObserver.inspectorButton;
47 button = panelWindow.document.createElement("toolbarbutton"); 39 button = panelWindow.document.createElement("toolbarbutton");
48 button.setAttribute("id", "inspector-abp-elemhide-toolbutton"); 40 button.setAttribute("id", "inspector-abp-elemhide-toolbutton");
49 button.setAttribute("label", label); 41 button.style.listStyleImage = "url('chrome://adblockplus/skin/abp-status-16. png')";
saroyanm 2014/04/11 16:09:11 Not sure if I need to copy icon to elemhidehelper/
Wladimir Palant 2014/04/11 18:39:10 No, it's fine like that - Element Hiding Helper ca
42 button.style.MozImageRegion = "rect(0px, 16px, 16px, 0px)";
43 button.style.paddingTop = "4px";
50 button.setAttribute("class", "devtools-toolbarbutton"); 44 button.setAttribute("class", "devtools-toolbarbutton");
51 button.setAttribute("accesskey", accesskey); 45 button.setAttribute("accesskey", accesskey);
52 button.setAttribute("tooltiptext", tooltiptext); 46 button.setAttribute("tooltiptext", tooltiptext);
53 button.setAttribute("tabindex", "0"); 47 button.setAttribute("tabindex", "0");
54 button.addEventListener("command", function() 48 button.addEventListener("command", function()
55 { 49 {
56 panelWindow.openDialog("chrome://elemhidehelper/content/composer.xul", "_b lank", 50 panelWindow.openDialog("chrome://elemhidehelper/content/composer.xul", "_b lank",
57 "chrome,centerscreen,resizable,dialog=no", panel.se lection.node); 51 "chrome,centerscreen,resizable,dialog=no", panel.se lection.node);
58 }, false); 52 }, false);
59 parent.appendChild(button); 53 inspectBtn.parentNode.insertBefore(button, inspectBtn.nextSibling);
60 } 54 }
61 }; 55 };
62 56
63 InspectorObserver.init(); 57 InspectorObserver.init();
OLDNEW

Powered by Google App Engine
This is Rietveld