summaryrefslogtreecommitdiffstats
path: root/devtools/client/framework/browser-menus.js
diff options
context:
space:
mode:
Diffstat (limited to 'devtools/client/framework/browser-menus.js')
-rw-r--r--devtools/client/framework/browser-menus.js98
1 files changed, 83 insertions, 15 deletions
diff --git a/devtools/client/framework/browser-menus.js b/devtools/client/framework/browser-menus.js
index 3d6c4def6..e62afddac 100644
--- a/devtools/client/framework/browser-menus.js
+++ b/devtools/client/framework/browser-menus.js
@@ -133,10 +133,11 @@ function attachKeybindingsToBrowser(doc, keys) {
*/
function createToolMenuElements(toolDefinition, doc) {
let id = toolDefinition.id;
+ let appmenuId = "appmenuitem_" + id;
let menuId = "menuitem_" + id;
// Prevent multiple entries for the same tool.
- if (doc.getElementById(menuId)) {
+ if (doc.getElementById(appmenuId) || doc.getElementById(menuId)) {
return;
}
@@ -156,6 +157,13 @@ function createToolMenuElements(toolDefinition, doc) {
});
}
+ let appmenuitem = createMenuItem({
+ doc,
+ id: "appmenuitem_" + id,
+ label: toolDefinition.menuLabel || toolDefinition.label,
+ accesskey: null
+ });
+
let menuitem = createMenuItem({
doc,
id: "menuitem_" + id,
@@ -166,10 +174,12 @@ function createToolMenuElements(toolDefinition, doc) {
// Refer to the key in order to display the key shortcut at menu ends
menuitem.setAttribute("key", key.id);
}
+ appmenuitem.addEventListener("command", oncommand);
menuitem.addEventListener("command", oncommand);
return {
key,
+ appmenuitem,
menuitem
};
}
@@ -186,22 +196,34 @@ function createToolMenuElements(toolDefinition, doc) {
* The tool definition after which the tool menu item is to be added.
*/
function insertToolMenuElements(doc, toolDefinition, prevDef) {
- let { key, menuitem } = createToolMenuElements(toolDefinition, doc);
+ let { key, appmenuitem, menuitem } = createToolMenuElements(toolDefinition, doc);
if (key) {
attachKeybindingsToBrowser(doc, key);
}
- let ref;
+ let amp;
+ if (prevDef) {
+ let appmenuitem = doc.getElementById("appmenuitem_" + prevDef.id);
+ amp = appmenuitem && appmenuitem.nextSibling ? appmenuitem.nextSibling : null;
+ } else {
+ amp = doc.getElementById("appmenu_devtools_separator");
+ }
+
+ if (amp) {
+ amp.parentNode.insertBefore(appmenuitem, amp);
+ }
+
+ let mp;
if (prevDef) {
let menuitem = doc.getElementById("menuitem_" + prevDef.id);
- ref = menuitem && menuitem.nextSibling ? menuitem.nextSibling : null;
+ mp = menuitem && menuitem.nextSibling ? menuitem.nextSibling : null;
} else {
- ref = doc.getElementById("menu_devtools_separator");
+ mp = doc.getElementById("menu_devtools_separator");
}
- if (ref) {
- ref.parentNode.insertBefore(menuitem, ref);
+ if (mp) {
+ mp.parentNode.insertBefore(menuitem, mp);
}
}
exports.insertToolMenuElements = insertToolMenuElements;
@@ -220,6 +242,11 @@ function removeToolFromMenu(toolId, doc) {
key.remove();
}
+ let appmenuitem = doc.getElementById("appmenuitem_" + toolId);
+ if (appmenuitem) {
+ appmenuitem.remove();
+ }
+
let menuitem = doc.getElementById("menuitem_" + toolId);
if (menuitem) {
menuitem.remove();
@@ -235,6 +262,7 @@ exports.removeToolFromMenu = removeToolFromMenu;
*/
function addAllToolsToMenu(doc) {
let fragKeys = doc.createDocumentFragment();
+ let fragAppMenuItems = doc.createDocumentFragment();
let fragMenuItems = doc.createDocumentFragment();
for (let toolDefinition of gDevTools.getToolDefinitionArray()) {
@@ -251,11 +279,17 @@ function addAllToolsToMenu(doc) {
if (elements.key) {
fragKeys.appendChild(elements.key);
}
+ fragAppMenuItems.appendChild(elements.appmenuitem);
fragMenuItems.appendChild(elements.menuitem);
}
attachKeybindingsToBrowser(doc, fragKeys);
+ let amps = doc.getElementById("appmenu_devtools_separator");
+ if (amps) {
+ amps.parentNode.insertBefore(fragAppMenuItems, amps);
+ }
+
let mps = doc.getElementById("menu_devtools_separator");
if (mps) {
mps.parentNode.insertBefore(fragMenuItems, mps);
@@ -270,18 +304,29 @@ function addAllToolsToMenu(doc) {
*/
function addTopLevelItems(doc) {
let keys = doc.createDocumentFragment();
+ let appmenuItems = doc.createDocumentFragment();
let menuItems = doc.createDocumentFragment();
let { menuitems } = require("../menus");
for (let item of menuitems) {
if (item.separator) {
+ let appseparator = doc.createElement("menuseparator");
+ appseparator.id = "app" + item.id;
let separator = doc.createElement("menuseparator");
separator.id = item.id;
+ appmenuItems.appendChild(appseparator);
menuItems.appendChild(separator);
} else {
let { id, l10nKey } = item;
// Create a <menuitem>
+ let appmenuitem = createMenuItem({
+ doc,
+ id: "app" + id,
+ label: l10n(l10nKey + ".label"),
+ accesskey: null,
+ isCheckbox: item.checkbox
+ });
let menuitem = createMenuItem({
doc,
id,
@@ -289,7 +334,9 @@ function addTopLevelItems(doc) {
accesskey: l10n(l10nKey + ".accesskey"),
isCheckbox: item.checkbox
});
+ appmenuitem.addEventListener("command", item.oncommand);
menuitem.addEventListener("command", item.oncommand);
+ appmenuItems.appendChild(appmenuitem);
menuItems.appendChild(menuitem);
if (item.key && l10nKey) {
@@ -330,6 +377,9 @@ function addTopLevelItems(doc) {
for (let node of keys.children) {
nodes.push(node);
}
+ for (let node of appmenuItems.children) {
+ nodes.push(node);
+ }
for (let node of menuItems.children) {
nodes.push(node);
}
@@ -337,15 +387,33 @@ function addTopLevelItems(doc) {
attachKeybindingsToBrowser(doc, keys);
+ // There are hardcoded menu items in the Web Developer menus plus it is a
+ // location of menu items via overlays from extensions so we want to make
+ // sure the last seperator and the "Get More Tools..." items are last.
+ // This will emulate the behavior when devtools menu items were actually
+ // physically present in browser.xul
+
+ // Tools > Web Developer
let menu = doc.getElementById("menuWebDeveloperPopup");
- menu.appendChild(menuItems);
-
- // There is still "Page Source" menuitem hardcoded into browser.xul. Instead
- // of manually inserting everything around it, move it to the expected
- // position.
- let pageSource = doc.getElementById("menu_pageSource");
- let endSeparator = doc.getElementById("devToolsEndSeparator");
- menu.insertBefore(pageSource, endSeparator);
+ // Insert the Devtools Menu Items before everything else
+ menu.insertBefore(menuItems, menu.firstChild);
+ // Move the devtools last seperator and Get More Tools menu items to the bottom
+ let menu_endSeparator = doc.getElementById("menu_devToolsEndSeparator");
+ let menu_getMoreDevtools = doc.getElementById("menu_getMoreDevtools");
+ menu.insertBefore(menu_getMoreDevtools, null);
+ menu.insertBefore(menu_endSeparator, menu_getMoreDevtools);
+
+ // Application Menu > Web Developer (If existant)
+ let appmenu = doc.getElementById("appmenu_webDeveloper_popup");
+ if (appmenu) {
+ // Insert the Devtools Menu Items after the hardcoded idless seperator
+ appmenu.insertBefore(appmenuItems, appmenu.childNodes[2].nextSibling);
+ // Move the devtools last seperator and Get More Tools menu items to the bottom
+ let appmenu_endSeparator = doc.getElementById("appmenu_devToolsEndSeparator");
+ let appmenu_getMoreDevtools = doc.getElementById("appmenu_getMoreDevtools");
+ appmenu.insertBefore(appmenu_getMoreDevtools, null);
+ appmenu.insertBefore(appmenu_endSeparator, appmenu_getMoreDevtools);
+ }
}
/**