Skip to content

Commit

Permalink
disable DOM inspector sidebar addon when devtool panel is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
rpl committed May 4, 2014
1 parent 0671c42 commit 9537399
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 37 deletions.
82 changes: 54 additions & 28 deletions firefox/lib/devtool-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,66 @@ var Promise = require("sdk/core/promise");

const Tab = require("sdk/tabs/tab-firefox").Tab;

const { registerInspectorSidebar } = require("register-sidebar-addons");
const {
registerInspectorSidebar,
unregisterInspectorSidebar
} = require("register-sidebar-addons");

const { Cu } = require("chrome");

registerInspectorSidebar({
id: "angular-batarang",
label: "AngularJS",
evaluatedJavascriptFun: function getAngularPanelContents() {
if (window.angular && $0) {
//TODO: can we move this scope export into updateElementProperties
var scope = window.angular.element($0).scope();
// Export $scope to the console
window.$scope = scope;
return (function (scope) {
var panelContents = {
__private__: {}
};

for (prop in scope) {
if (scope.hasOwnProperty(prop)) {
if (prop.substr(0, 2) === '$$') {
panelContents.__private__[prop] = scope[prop];
} else {
panelContents[prop] = scope[prop];
let { get: getPref } = require("sdk/preferences/service")

let prefs = require("sdk/preferences/event-target").PrefsTarget({
});

prefs.on("devtools.angular-batarang.enabled", function (name) {
let enabled = getPref(name);
console.log("DEVTOOLS ANGULAR TOGGLED", enabled);

if (enabled) {
activateSidebar();
} else {
deactivateSidebar();
}
});

function deactivateSidebar() {
unregisterInspectorSidebar("angular-batarang");
}

function activateSidebar() {
registerInspectorSidebar({
id: "angular-batarang",
label: "AngularJS",
evaluatedJavascriptFun: function getAngularPanelContents() {
if (window.angular && $0) {
// TODO: can we move this scope export into
// updateElementProperties
var scope = window.angular.element($0).scope();
// Export $scope to the console
window.$scope = scope;
return (function (scope) {
var panelContents = {
__private__: {}
};

for (prop in scope) {
if (scope.hasOwnProperty(prop)) {
if (prop.substr(0, 2) === '$$') {
panelContents.__private__[prop] = scope[prop];
} else {
panelContents[prop] = scope[prop];
}
}
}
}
return panelContents;
}(scope));
} else {
return {};
return panelContents;
}(scope));
} else {
return {};
}
}
}
});
});
}

exports.devtoolTabDefinition = {
id: "angular-batarang",
Expand Down
40 changes: 31 additions & 9 deletions firefox/lib/register-sidebar-addons.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ var Promise = require("sdk/core/promise");

const addonSidebarsDefs = new Map();

exports.unregisterInspectorSidebar = function (sidebarId) {
addonSidebarsDefs.delete(sidebarId);

for (let toolbox of gDevTools._toolboxes.values()) {
let inspector = toolbox.getPanel("inspector");
if (inspector) {
let tab = inspector.sidebar.getTab(sidebarId);

if (inspector.sidebar.getCurrentTabID() === sidebarId) {
inspector.sidebar.select(inspector.sidebar._tabs.keys().next().value);
}

let tab_header = inspector.sidebar._tabs.get(sidebarId);
let tab_panel = inspector.sidebar.getTab(sidebarId);
tab_header.parentNode.removeChild(tab_header);
tab_panel.parentNode.removeChild(tab_panel);
}
}
};

exports.registerInspectorSidebar = function(sidebarDefinition) {
addonSidebarsDefs.set(sidebarDefinition.id, sidebarDefinition);
};
Expand Down Expand Up @@ -110,15 +130,16 @@ function buildInspectorSidebar(panel, { id, label, evaluatedJavascriptFun }) {
}, false);

function onNewNode() {
webconsoleClient.evaluateJS("(" + evaluatedJavascriptFun.toString() + ")();",
(res) => {
// refresh variables view
console.log("evaluateJS result", res);
let options = { objectActor: res.result };
let view = variablesView;
view.empty();
view.controller.setSingleVariable(options).expanded;
});
webconsoleClient.evaluateJS(
"(" + evaluatedJavascriptFun.toString() + ")();",
(res) => {
// refresh variables view
console.log("evaluateJS result", res);
let options = { objectActor: res.result };
let view = variablesView;
view.empty();
view.controller.setSingleVariable(options).expanded;
});
}
});

Expand All @@ -127,6 +148,7 @@ function buildInspectorSidebar(panel, { id, label, evaluatedJavascriptFun }) {
return panel;
}

// NOTE: needed to support firefox XX
function patchVariablesViewController(controller) {
if (controller.setSingleVariable) {
return;
Expand Down

0 comments on commit 9537399

Please sign in to comment.