Bug 1444392 - Part 3 - Simplify the PanelUI.show method. r=Gijs

In addition to removing the unnecessary return value and the logic that may anchor the panel to anything other than the main menu button, this also fixes the asynchronous error handling.

MozReview-Commit-ID: KaUKYUhrUoc
This commit is contained in:
Paolo Amadini
2018-04-04 11:34:49 +01:00
parent 27081c7b37
commit 959218fdcb
2 changed files with 15 additions and 27 deletions

View File

@@ -194,36 +194,24 @@ const PanelUI = {
*/
show(aEvent) {
this._ensureShortcutsShown();
return new Promise(resolve => {
this.ensureReady().then(() => {
if (this.panel.state == "open" ||
document.documentElement.hasAttribute("customizing")) {
resolve();
return;
}
(async () => {
await this.ensureReady();
let anchor;
let domEvent = null;
if (!aEvent ||
aEvent.type == "command") {
anchor = this.menuButton;
} else {
domEvent = aEvent;
anchor = aEvent.target;
}
if (this.panel.state == "open" ||
document.documentElement.hasAttribute("customizing")) {
return;
}
this.panel.addEventListener("popupshown", function() {
resolve();
}, {once: true});
let domEvent = null;
if (aEvent && aEvent.type != "command") {
domEvent = aEvent;
}
anchor = this._getPanelAnchor(anchor);
PanelMultiView.openPopup(this.panel, anchor, {
triggerEvent: domEvent,
}).catch(Cu.reportError);
}, (reason) => {
console.error("Error showing the PanelUI menu", reason);
let anchor = this._getPanelAnchor(this.menuButton);
await PanelMultiView.openPopup(this.panel, anchor, {
triggerEvent: domEvent,
});
});
})().catch(Cu.reportError);
},
/**