Bug 1261920 - Register developer button dynamically. r=jryans,gijs
This commit is contained in:
@@ -539,41 +539,12 @@ const CustomizableWidgets = [
|
||||
win.BrowserOpenFileWindow();
|
||||
}
|
||||
}
|
||||
}, {
|
||||
id: "developer-button",
|
||||
type: "view",
|
||||
viewId: "PanelUI-developer",
|
||||
shortcutId: "key_devToolboxMenuItem",
|
||||
tooltiptext: "developer-button.tooltiptext2",
|
||||
defaultArea: AppConstants.MOZ_DEV_EDITION ?
|
||||
CustomizableUI.AREA_NAVBAR :
|
||||
CustomizableUI.AREA_PANEL,
|
||||
onViewShowing: function(aEvent) {
|
||||
// Populate the subview with whatever menuitems are in the developer
|
||||
// menu. We skip menu elements, because the menu panel has no way
|
||||
// of dealing with those right now.
|
||||
let doc = aEvent.target.ownerDocument;
|
||||
let win = doc.defaultView;
|
||||
|
||||
let menu = doc.getElementById("menuWebDeveloperPopup");
|
||||
|
||||
let itemsToDisplay = [...menu.children];
|
||||
// Hardcode the addition of the "work offline" menuitem at the bottom:
|
||||
itemsToDisplay.push({localName: "menuseparator", getAttribute: () => {}});
|
||||
itemsToDisplay.push(doc.getElementById("goOfflineMenuitem"));
|
||||
|
||||
let developerItems = doc.getElementById("PanelUI-developerItems");
|
||||
clearSubview(developerItems);
|
||||
fillSubviewFromMenuItems(itemsToDisplay, developerItems);
|
||||
}
|
||||
}, {
|
||||
id: "sidebar-button",
|
||||
type: "view",
|
||||
viewId: "PanelUI-sidebar",
|
||||
tooltiptext: "sidebar-button.tooltiptext2",
|
||||
onViewShowing: function(aEvent) {
|
||||
// Largely duplicated from the developer-button above with a couple minor
|
||||
// alterations.
|
||||
// Populate the subview with whatever menuitems are in the
|
||||
// sidebar menu. We skip menu elements, because the menu panel has no way
|
||||
// of dealing with those right now.
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
var tmp = {};
|
||||
Cu.import("resource://gre/modules/Promise.jsm", tmp);
|
||||
Cu.import("resource:///modules/CustomizableUI.jsm", tmp);
|
||||
var {Promise, CustomizableUI} = tmp;
|
||||
Cu.import("resource://gre/modules/AppConstants.jsm", tmp);
|
||||
var {Promise, CustomizableUI, AppConstants} = tmp;
|
||||
|
||||
var ChromeUtils = {};
|
||||
Services.scriptloader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js", ChromeUtils);
|
||||
@@ -113,12 +114,8 @@ function resetCustomization() {
|
||||
return CustomizableUI.reset();
|
||||
}
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, 'gDeveloperButtonInNavbar', function() {
|
||||
return getAreaWidgetIds(CustomizableUI.AREA_NAVBAR).indexOf("developer-button") != -1;
|
||||
});
|
||||
|
||||
function isInDevEdition() {
|
||||
return gDeveloperButtonInNavbar;
|
||||
return AppConstants.MOZ_DEV_EDITION;
|
||||
}
|
||||
|
||||
function removeDeveloperButtonIfDevEdition(areaPanelPlacements) {
|
||||
|
||||
@@ -27,6 +27,7 @@ loader.lazyRequireGetter(this, "DebuggerClient", "devtools/shared/client/main",
|
||||
loader.lazyRequireGetter(this, "BrowserMenus", "devtools/client/framework/browser-menus");
|
||||
|
||||
loader.lazyImporter(this, "CustomizableUI", "resource:///modules/CustomizableUI.jsm");
|
||||
loader.lazyImporter(this, "AppConstants", "resource://gre/modules/AppConstants.jsm");
|
||||
|
||||
const bundle = Services.strings.createBundle("chrome://devtools/locale/toolbox.properties");
|
||||
|
||||
@@ -283,6 +284,60 @@ var gDevToolsBrowser = exports.gDevToolsBrowser = {
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Install Developer widget
|
||||
*/
|
||||
installDeveloperWidget: function () {
|
||||
let id = "developer-button";
|
||||
let widget = CustomizableUI.getWidget(id);
|
||||
if (widget && widget.provider == CustomizableUI.PROVIDER_API) {
|
||||
return;
|
||||
}
|
||||
CustomizableUI.createWidget({
|
||||
id: id,
|
||||
type: "view",
|
||||
viewId: "PanelUI-developer",
|
||||
shortcutId: "key_devToolboxMenuItem",
|
||||
tooltiptext: "developer-button.tooltiptext2",
|
||||
defaultArea: AppConstants.MOZ_DEV_EDITION ?
|
||||
CustomizableUI.AREA_NAVBAR :
|
||||
CustomizableUI.AREA_PANEL,
|
||||
onViewShowing: function(aEvent) {
|
||||
// Populate the subview with whatever menuitems are in the developer
|
||||
// menu. We skip menu elements, because the menu panel has no way
|
||||
// of dealing with those right now.
|
||||
let doc = aEvent.target.ownerDocument;
|
||||
let win = doc.defaultView;
|
||||
|
||||
let menu = doc.getElementById("menuWebDeveloperPopup");
|
||||
|
||||
let itemsToDisplay = [...menu.children];
|
||||
// Hardcode the addition of the "work offline" menuitem at the bottom:
|
||||
itemsToDisplay.push({localName: "menuseparator", getAttribute: () => {}});
|
||||
itemsToDisplay.push(doc.getElementById("goOfflineMenuitem"));
|
||||
|
||||
let developerItems = doc.getElementById("PanelUI-developerItems");
|
||||
// Import private helpers from CustomizableWidgets
|
||||
let { clearSubview, fillSubviewFromMenuItems } =
|
||||
Cu.import("resource:///modules/CustomizableWidgets.jsm", {});
|
||||
clearSubview(developerItems);
|
||||
fillSubviewFromMenuItems(itemsToDisplay, developerItems);
|
||||
},
|
||||
onBeforeCreated: function(doc) {
|
||||
// Bug 1223127, CUI should make this easier to do.
|
||||
if (doc.getElementById("PanelUI-developerItems")) {
|
||||
return;
|
||||
}
|
||||
let view = doc.createElement("panelview");
|
||||
view.id = "PanelUI-developerItems";
|
||||
let panel = doc.createElement("vbox");
|
||||
panel.setAttribute("class", "panel-subview-body");
|
||||
view.appendChild(panel);
|
||||
doc.getElementById("PanelUI-multiView").appendChild(view);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Install WebIDE widget
|
||||
*/
|
||||
@@ -353,6 +408,10 @@ var gDevToolsBrowser = exports.gDevToolsBrowser = {
|
||||
|
||||
BrowserMenus.addMenus(win.document);
|
||||
|
||||
// Register the Developer widget in the Hamburger menu or navbar
|
||||
// only once menus are registered as it depends on it.
|
||||
gDevToolsBrowser.installDeveloperWidget();
|
||||
|
||||
// Inject lazily DeveloperToolbar on the chrome window
|
||||
loader.lazyGetter(win, "DeveloperToolbar", function() {
|
||||
let { DeveloperToolbar } = require("devtools/client/shared/developer-toolbar");
|
||||
|
||||
Reference in New Issue
Block a user