Bug 1890374 - Hide empty submenus in mail context menu. r=aleca

Differential Revision: https://phabricator.services.mozilla.com/D211626

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Martin Giger 2024-05-27 22:03:17 +00:00
Родитель cec3c7f37f
Коммит 08220884e0
2 изменённых файлов: 28 добавлений и 10 удалений

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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();
}