diff --git a/mail/base/content/mailContext.js b/mail/base/content/mailContext.js index 2dedceec38..c709669bae 100644 --- a/mail/base/content/mailContext.js +++ b/mail/base/content/mailContext.js @@ -326,9 +326,7 @@ var mailContextMenu = { this.context?.onVideo || this.context?.onTextInput; - for (const id of ["mailContext-tags", "mailContext-mark"]) { - showItem(id, !onSpecialItem); - } + showItem("mailContext-tags", !onSpecialItem); // Ask commandController about the commands it controls. for (const [id, command] of Object.entries(this._commands)) { @@ -393,7 +391,6 @@ var mailContextMenu = { this._initMessageTags(); } - showItem("mailContext-mark", !isDummyMessage); checkItem("mailContext-markFlagged", message?.isFlagged); setSingleSelection("mailContext-copyMessageUrl", !!isNewsgroup); @@ -447,6 +444,12 @@ var mailContextMenu = { window.threadTree && numSelectedMessages > 1 ); + this._ensureSubmenuVisibility(); + // Special case: mark menu shouldn't be shown on external messages. + if (isDummyMessage) { + showItem("mailContext-mark", false); + } + let lastItem; for (const child of document.getElementById("mailContext").children) { if (child.localName == "menuseparator") { @@ -498,6 +501,21 @@ var mailContextMenu = { Services.obs.notifyObservers(subject, "on-build-contextmenu"); }, + /** + * Hide all top level submenus of the context menu that have no visibile items. + * Ignores separators since they are only a visual aid for the user and not + * actual features making the menu worth showing. Excludes generated submenus. + */ + _ensureSubmenuVisibility() { + for (const menu of document.querySelectorAll( + "#mailContext > menu:not(#mailContext-tags,#mailContext-moveMenu,#mailContext-copyMenu)" + )) { + menu.hidden = Array.from(menu.menupopup.children).every( + child => child.hidden || child.localName === "menuseparator" + ); + } + }, + onMailContextMenuCommand(event) { // If commandController handles this command, ask it to do so. if (event.target.id in this._commands) { diff --git a/mail/base/test/browser/browser_mailContext.js b/mail/base/test/browser/browser_mailContext.js index 9b1b22a78b..dc2b6c94b3 100644 --- a/mail/base/test/browser/browser_mailContext.js +++ b/mail/base/test/browser/browser_mailContext.js @@ -141,16 +141,16 @@ const mailContextData = { "templatesFolderTree", "multipleTemplatesFolderTree", ], - "mailContext-open": true, - "mailContext-reply": true, - "mailContext-forwardRedirect": true, + "mailContext-open": [...singleNotExternal, "collapsedThreadTree"], + "mailContext-reply": noCollapsedThreads, + "mailContext-forwardRedirect": noCollapsedThreads, "mailContext-editAsNew": noCollapsedThreads, "mailContext-moveMenu": notExternal, "mailContext-copyMenu": true, "mailContext-tags": notExternal, "mailContext-mark": notExternal, - "mailContext-organize": true, - "mailContext-threads": true, + "mailContext-organize": notExternal, + "mailContext-threads": [...notSynthetic, ...onePane], "mailContext-saveAs": true, "mailContext-print": true, "mailContext-downloadSelected": [ @@ -206,7 +206,7 @@ function checkMenuitems(menu, mode) { ); } - Assert.deepEqual(actualItems, expectedItems); + Assert.deepEqual(actualItems, expectedItems, `Mode: ${mode}`); menu.hidePopup(); }