Fixing osx menus. Also refresh context and file menus when a custom container is created. Fixes #127
This commit is contained in:
parent
fe1decef4c
commit
885b90709b
1 changed files with 38 additions and 37 deletions
75
index.js
75
index.js
|
@ -1027,62 +1027,63 @@ ContainerWindow.prototype = {
|
||||||
// Generic menu configuration.
|
// Generic menu configuration.
|
||||||
_configureMenu(menuId, excludedContainerCb, clickCb, arrayName) {
|
_configureMenu(menuId, excludedContainerCb, clickCb, arrayName) {
|
||||||
const menu = this._window.document.getElementById(menuId);
|
const menu = this._window.document.getElementById(menuId);
|
||||||
|
this._disableElement(menu, arrayName);
|
||||||
if (!this._disableElement(menu, arrayName)) {
|
if (!this._disableElement(menu, arrayName)) {
|
||||||
return Promise.resolve(null);
|
// Delete stale menu that isn't native elements
|
||||||
|
while (menu.firstChild) {
|
||||||
|
menu.removeChild(menu.firstChild);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const menupopup = this._window.document.createElementNS(XUL_NS, "menupopup");
|
const menupopup = this._window.document.createElementNS(XUL_NS, "menupopup");
|
||||||
menu.appendChild(menupopup);
|
menu.appendChild(menupopup);
|
||||||
|
|
||||||
menupopup.addEventListener("command", clickCb);
|
menupopup.addEventListener("command", clickCb);
|
||||||
menupopup.addEventListener("popupshowing", e => {
|
return this._createMenu(menupopup, excludedContainerCb);
|
||||||
return this._createMenu(e, excludedContainerCb);
|
|
||||||
});
|
|
||||||
|
|
||||||
return Promise.resolve(null);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_createMenu(event, excludedContainerCb) {
|
_createMenu(target, excludedContainerCb) {
|
||||||
while (event.target.hasChildNodes()) {
|
while (target.hasChildNodes()) {
|
||||||
event.target.removeChild(event.target.firstChild);
|
target.removeChild(target.firstChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
ContainerService.queryIdentities().then(identities => {
|
return new Promise((resolve, reject) => {
|
||||||
const fragment = this._window.document.createDocumentFragment();
|
ContainerService.queryIdentities().then(identities => {
|
||||||
|
const fragment = this._window.document.createDocumentFragment();
|
||||||
|
|
||||||
const excludedUserContextId = excludedContainerCb ? excludedContainerCb() : 0;
|
const excludedUserContextId = excludedContainerCb ? excludedContainerCb() : 0;
|
||||||
if (excludedUserContextId) {
|
if (excludedUserContextId) {
|
||||||
const bundle = this._window.document.getElementById("bundle_browser");
|
const bundle = this._window.document.getElementById("bundle_browser");
|
||||||
|
|
||||||
const menuitem = this._window.document.createElementNS(XUL_NS, "menuitem");
|
const menuitem = this._window.document.createElementNS(XUL_NS, "menuitem");
|
||||||
menuitem.setAttribute("data-usercontextid", "0");
|
menuitem.setAttribute("data-usercontextid", "0");
|
||||||
menuitem.setAttribute("label", bundle.getString("userContextNone.label"));
|
menuitem.setAttribute("label", bundle.getString("userContextNone.label"));
|
||||||
menuitem.setAttribute("accesskey", bundle.getString("userContextNone.accesskey"));
|
menuitem.setAttribute("accesskey", bundle.getString("userContextNone.accesskey"));
|
||||||
|
|
||||||
fragment.appendChild(menuitem);
|
fragment.appendChild(menuitem);
|
||||||
|
|
||||||
const menuseparator = this._window.document.createElementNS(XUL_NS, "menuseparator");
|
const menuseparator = this._window.document.createElementNS(XUL_NS, "menuseparator");
|
||||||
fragment.appendChild(menuseparator);
|
fragment.appendChild(menuseparator);
|
||||||
}
|
|
||||||
|
|
||||||
identities.forEach(identity => {
|
|
||||||
if (identity.userContextId === excludedUserContextId) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const menuitem = this._window.document.createElementNS(XUL_NS, "menuitem");
|
identities.forEach(identity => {
|
||||||
menuitem.setAttribute("label", identity.name);
|
if (identity.userContextId === excludedUserContextId) {
|
||||||
menuitem.classList.add("menuitem-iconic");
|
return;
|
||||||
menuitem.setAttribute("data-usercontextid", identity.userContextId);
|
}
|
||||||
menuitem.setAttribute("data-identity-color", identity.color);
|
|
||||||
menuitem.setAttribute("data-identity-icon", identity.image);
|
|
||||||
fragment.appendChild(menuitem);
|
|
||||||
});
|
|
||||||
|
|
||||||
event.target.appendChild(fragment);
|
const menuitem = this._window.document.createElementNS(XUL_NS, "menuitem");
|
||||||
}).catch(() => {});
|
menuitem.setAttribute("label", identity.name);
|
||||||
|
menuitem.classList.add("menuitem-iconic");
|
||||||
|
menuitem.setAttribute("data-usercontextid", identity.userContextId);
|
||||||
|
menuitem.setAttribute("data-identity-color", identity.color);
|
||||||
|
menuitem.setAttribute("data-identity-icon", identity.image);
|
||||||
|
fragment.appendChild(menuitem);
|
||||||
|
});
|
||||||
|
|
||||||
return true;
|
target.appendChild(fragment);
|
||||||
|
resolve();
|
||||||
|
}).catch(() => {reject();});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// This timer is used to hide the panel auto-magically if it's not used in
|
// This timer is used to hide the panel auto-magically if it's not used in
|
||||||
|
|
Loading…
Add table
Reference in a new issue