Bug 1767050 - Fix menu initialization for a bunch of menus when opened standalone .eml file. r=darktrojan
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Mon, 23 May 2022 13:40:59 +0300
changeset 35797 8524c8e1591c008c2161af5d0b084176d559deb4
parent 35796 6264cbd928a2e14b5bcf6b0f683e213dc8f8cfcc
child 35798 9efac24bfc1e3e56ea504e5135ef46725889cace
push id19944
push usermkmelin@iki.fi
push dateMon, 23 May 2022 10:48:04 +0000
treeherdercomm-central@fd96d53b82ac [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdarktrojan
bugs1767050
Bug 1767050 - Fix menu initialization for a bunch of menus when opened standalone .eml file. r=darktrojan Differential Revision: https://phabricator.services.mozilla.com/D146900
mail/base/content/mailWindowOverlay.js
--- a/mail/base/content/mailWindowOverlay.js
+++ b/mail/base/content/mailWindowOverlay.js
@@ -152,16 +152,18 @@ function goUpdateMailMenuItems(commandse
 function updateCheckedStateForIgnoreAndWatchThreadCmds() {
   let message;
 
   let tab = document.getElementById("tabmail")?.currentTabInfo;
   if (["mail3PaneTab", "mailMessageTab"].includes(tab?.mode.name)) {
     message = tab.message;
   } else if (tab?.folderDisplay) {
     message = tab.folderDisplay.selectedMessage;
+  } else {
+    message = gFolderDisplay.selectedMessage;
   }
 
   let folder = message?.folder;
 
   document
     .getElementById("cmd_killThread")
     .setAttribute("checked", folder?.msgDatabase.IsIgnored(message.messageKey));
   document
@@ -816,56 +818,57 @@ function InitAppmenuViewMessagesMenu() {
     );
 
   document
     .getElementById("appmenu_viewIgnoredThreadsMenuItem")
     .setAttribute("checked", gFolderDisplay.view.showIgnored);
 }
 
 function InitMessageMenu() {
-  let selectedMsg;
+  let message;
 
   let tab = document.getElementById("tabmail")?.currentTabInfo;
   if (["mail3PaneTab", "mailMessageTab"].includes(tab?.mode.name)) {
-    selectedMsg = tab.message;
+    message = tab.message;
   } else if (tab?.mode.tabType.name == "mail") {
-    selectedMsg = tab.folderDisplay.selectedMessage;
+    message = tab.folderDisplay.selectedMessage;
+  } else {
+    message = gFolderDisplay.selectedMessage;
   }
 
-  let isNews = selectedMsg?.folder?.flags & Ci.nsMsgFolderFlags.Newsgroup;
-  let isFeed = selectedMsg && FeedUtils.isFeedMessage(selectedMsg);
-  let isDummy = selectedMsg?.folder == null;
+  let isNews = message?.folder?.flags & Ci.nsMsgFolderFlags.Newsgroup;
+  let isFeed = message && FeedUtils.isFeedMessage(message);
+  let isDummy = message?.folder == null;
 
   // We show reply to Newsgroups only for news messages.
   document.getElementById("replyNewsgroupMainMenu").hidden = !isNews;
 
   // For mail messages we say reply. For news we say ReplyToSender.
   document.getElementById("replyMainMenu").hidden = isNews;
   document.getElementById("replySenderMainMenu").hidden = !isNews;
 
   document.getElementById("menu_cancel").hidden = !isNews;
 
   // Disable the move and copy menus if there are no messages selected or if
   // the message is a dummy - e.g. opening a message in the standalone window.
-  let messageStoredInternally = selectedMsg && !isDummy;
+  let messageStoredInternally = message && !isDummy;
   // Disable the move menu if we can't delete msgs from the folder.
   let canMove =
-    messageStoredInternally && !isNews && selectedMsg.folder.canDeleteMessages;
+    messageStoredInternally && !isNews && message.folder.canDeleteMessages;
 
   document.getElementById("moveMenu").disabled = !canMove;
 
   // Also disable copy when no folder is loaded (like for .eml files).
-  let canCopy =
-    selectedMsg && (!isDummy || window.arguments[0].scheme == "file");
+  let canCopy = message && (!isDummy || window.arguments[0].scheme == "file");
   document.getElementById("copyMenu").disabled = !canCopy;
 
   initMoveToFolderAgainMenu(document.getElementById("moveToFolderAgain"));
 
   // Disable the Forward As menu item if no message is selected.
-  document.getElementById("forwardAsMenu").disabled = !selectedMsg;
+  document.getElementById("forwardAsMenu").disabled = !message;
 
   // Disable the Tag menu item if no message is selected or when we're
   // not in a folder.
   document.getElementById("tagMenu").disabled = !messageStoredInternally;
 
   // Show "Edit Draft Message" menus only in a drafts folder; otherwise hide them.
   showCommandInSpecialFolder("cmd_editDraftMsg", Ci.nsMsgFolderFlags.Drafts);
   // Show "New Message from Template" and "Edit Template" menus only in a
@@ -1067,16 +1070,18 @@ function AdjustHeaderView(headermode) {
 function InitViewBodyMenu() {
   let message;
 
   let tab = document.getElementById("tabmail")?.currentTabInfo;
   if (["mail3PaneTab", "mailMessageTab"].includes(tab?.mode.name)) {
     message = tab.message;
   } else if (tab?.mode.tabType.name == "mail") {
     message = tab.folderDisplay.selectedMessage;
+  } else {
+    message = gFolderDisplay.selectedMessage;
   }
 
   // Separate render prefs not implemented for feeds, bug 458606.  Show the
   // checked item for feeds as for the regular pref.
   //  let html_as = Services.prefs.getIntPref("rss.display.html_as");
   //  let prefer_plaintext = Services.prefs.getBoolPref("rss.display.prefer_plaintext");
   //  let disallow_classes = Services.prefs.getIntPref("rss.display.disallow_mime_handlers");
   let html_as = Services.prefs.getIntPref("mailnews.display.html_as");
@@ -1480,16 +1485,18 @@ function SetMessageTagLabel(menuitem, in
 function InitMessageTags(parent, elementName = "menuitem", classes) {
   let message;
 
   let tab = document.getElementById("tabmail")?.currentTabInfo;
   if (["mail3PaneTab", "mailMessageTab"].includes(tab?.mode.name)) {
     message = tab.message;
   } else if (tab?.mode.tabType.name == "mail") {
     message = tab.folderDisplay.selectedMessage;
+  } else {
+    message = gFolderDisplay.selectedMessage;
   }
 
   const tagArray = MailServices.tags.getAllTags();
   const elementNameUpperCase = elementName.toUpperCase();
 
   // Remove any existing non-static items (clear tags list before rebuilding it).
   // There is a separator element above the dynamically added tag elements, so
   // remove dynamically added elements below the separator.
@@ -2006,16 +2013,18 @@ function SelectedMessagesAreRead() {
 function SelectedMessagesAreFlagged() {
   let message;
 
   let tab = document.getElementById("tabmail")?.currentTabInfo;
   if (["mail3PaneTab", "mailMessageTab"].includes(tab?.mode.name)) {
     message = tab.message;
   } else if (tab?.mode.tabType.name == "mail") {
     message = tab.folderDisplay.selectedMessage;
+  } else {
+    message = gFolderDisplay.selectedMessage;
   }
 
   return message?.isFlagged;
 }
 
 function GetFirstSelectedMsgFolder() {
   try {
     var selectedFolders = GetSelectedMsgFolders();