summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNew Tobin Paradigm <email@mattatobin.com>2018-04-08 01:10:26 -0400
committerGitHub <noreply@github.com>2018-04-08 01:10:26 -0400
commit309d1ca1f297e5ccf2309d6d90b82d558e5d426c (patch)
tree56185d62ec9c1423c85f83637e19f5af77d9d0ff
parentd164660412fa4c577af9947c96c7111be081f1e4 (diff)
parent1a36001469f1fa0746314fce6e20d423b2ce8ef8 (diff)
downloadUXP-309d1ca1f297e5ccf2309d6d90b82d558e5d426c.tar
UXP-309d1ca1f297e5ccf2309d6d90b82d558e5d426c.tar.gz
UXP-309d1ca1f297e5ccf2309d6d90b82d558e5d426c.tar.lz
UXP-309d1ca1f297e5ccf2309d6d90b82d558e5d426c.tar.xz
UXP-309d1ca1f297e5ccf2309d6d90b82d558e5d426c.zip
Merge pull request #100 from janekptacijarabaci/devtools_appmenu_1
Added support of the appmenu for DevTools menuitems (optional)
-rw-r--r--devtools/client/framework/browser-menus.js66
-rw-r--r--devtools/client/menus.js4
2 files changed, 64 insertions, 6 deletions
diff --git a/devtools/client/framework/browser-menus.js b/devtools/client/framework/browser-menus.js
index 3d6c4def6..15d2ec1b6 100644
--- a/devtools/client/framework/browser-menus.js
+++ b/devtools/client/framework/browser-menus.js
@@ -156,6 +156,12 @@ function createToolMenuElements(toolDefinition, doc) {
});
}
+ let appmenuitem = createMenuItem({
+ doc,
+ id: "appmenuitem_" + id,
+ label: toolDefinition.menuLabel || toolDefinition.label
+ });
+
let menuitem = createMenuItem({
doc,
id: "menuitem_" + id,
@@ -170,6 +176,7 @@ function createToolMenuElements(toolDefinition, doc) {
return {
key,
+ appmenuitem,
menuitem
};
}
@@ -186,12 +193,24 @@ 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 amp;
+ if (prevDef) {
+ let menuitem = doc.getElementById("appmenuitem_" + prevDef.id);
+ ref = menuitem && menuitem.nextSibling ? menuitem.nextSibling : null;
+ } else {
+ ref = doc.getElementById("appmenu_devtools_separator");
+ }
+
+ if (ref) {
+ amp.parentNode.insertBefore(menuitem, ref);
+ }
+
let ref;
if (prevDef) {
let menuitem = doc.getElementById("menuitem_" + prevDef.id);
@@ -220,6 +239,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 +259,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 +276,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 +301,28 @@ 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"),
+ isCheckbox: item.checkbox
+ });
let menuitem = createMenuItem({
doc,
id,
@@ -289,7 +330,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 +373,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 +383,27 @@ function addTopLevelItems(doc) {
attachKeybindingsToBrowser(doc, keys);
+ let appmenu = doc.getElementById("appmenu_webDeveloper_popup");
+ if (appmenu) {
+ appmenu.appendChild(appmenuItems);
+
+ // There is still "Page Source" menuitem hardcoded into browser.xul. Instead
+ // of manually inserting everything around it, move it to the expected
+ // position.
+ let appmenu_pageSource = doc.getElementById("appmenu_pageSource");
+ let appmenu_endSeparator = doc.getElementById("appmenu_devToolsEndSeparator");
+ appmenu.insertBefore(appmenu_pageSource, appmenu_endSeparator);
+ }
+
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);
+ let menu_pageSource = doc.getElementById("menu_pageSource");
+ let menu_endSeparator = doc.getElementById("menu_devToolsEndSeparator");
+ menu.insertBefore(menu_pageSource, menu_endSeparator);
}
/**
diff --git a/devtools/client/menus.js b/devtools/client/menus.js
index 7e36839da..1d2168967 100644
--- a/devtools/client/menus.js
+++ b/devtools/client/menus.js
@@ -183,9 +183,9 @@ exports.menuitems = [
}
},
{ separator: true,
- id: "devToolsEndSeparator"
+ id: "menu_devToolsEndSeparator"
},
- { id: "getMoreDevtools",
+ { id: "menu_getMoreDevtools",
l10nKey: "getMoreDevtoolsCmd",
oncommand(event) {
let window = event.target.ownerDocument.defaultView;