Bug 1589892 - Port |Bug 440616 (command cleanup v1) Clean up Thunderbird's global scope a bit more| and |Bug 495242 cmd_close shouldn't be passed through the controllers for menu options| to SeaMonkey. r=frg a=frg DONTBUILD CLOSED TREE
authorIan Neal <iann_cvs@blueyonder.co.uk>
Thu, 14 Nov 2019 21:02:01 +0100
changeset 32366 b05f05a590f40660861152d6e31aa6b618797add
parent 32365 b066b5e8868cfc79d802338e9d03492ac5e8f502
child 32367 c36e650c405d6193471f8f7a3ca338f67afda8a8
push id229
push userfrgrahl@gmx.net
push dateThu, 14 Nov 2019 20:02:28 +0000
treeherdercomm-esr60@b05f05a590f4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrg, frg
bugs1589892, 440616, 495242
Bug 1589892 - Port |Bug 440616 (command cleanup v1) Clean up Thunderbird's global scope a bit more| and |Bug 495242 cmd_close shouldn't be passed through the controllers for menu options| to SeaMonkey. r=frg a=frg DONTBUILD CLOSED TREE
suite/mailnews/content/mail3PaneWindowCommands.js
suite/mailnews/content/mailWindowOverlay.js
suite/mailnews/content/mailWindowOverlay.xul
suite/mailnews/content/messageWindow.js
suite/mailnews/content/messageWindow.xul
suite/mailnews/content/messenger.xul
suite/mailnews/content/tabmail.js
--- a/suite/mailnews/content/mail3PaneWindowCommands.js
+++ b/suite/mailnews/content/mail3PaneWindowCommands.js
@@ -191,17 +191,16 @@ var DefaultController =
       case "cmd_applyFiltersToSelection":
       case "cmd_applyFilters":
       case "cmd_runJunkControls":
       case "cmd_deleteJunk":
       case "button_file":
       case "cmd_emptyTrash":
       case "cmd_compactFolder":
       case "cmd_settingsOffline":
-      case "cmd_close":
       case "cmd_selectAll":
       case "cmd_selectThread":
       case "cmd_selectFlagged":
         return true;
       case "cmd_downloadFlagged":
       case "cmd_downloadSelected":
       case "cmd_synchronizeOffline":
         return !Services.io.offline;
@@ -420,23 +419,25 @@ var DefaultController =
         return IsPropertiesEnabled(command);
       case "button_getNewMessages":
       case "cmd_getNewMessages":
       case "cmd_getMsgsForAuthAccounts":
         return IsGetNewMessagesEnabled();
       case "cmd_getNextNMessages":
         return IsGetNextNMessagesEnabled();
       case "cmd_emptyTrash":
-        return IsEmptyTrashEnabled();
+      {
+        let folder = GetSelectedMsgFolders()[0];
+        return folder && folder.server.canEmptyTrashOnExit ?
+                         IsMailFolderSelected() : false;
+      }
       case "cmd_compactFolder":
         return IsCompactFolderEnabled();
       case "cmd_setFolderCharset":
         return IsFolderCharsetEnabled();
-      case "cmd_close":
-        return true;
       case "cmd_downloadFlagged":
         return !Services.io.offline;
       case "cmd_downloadSelected":
         return IsFolderSelected() && !Services.io.offline &&
                GetNumSelectedMessages() > 0;
       case "cmd_synchronizeOffline":
         return !Services.io.offline;
       case "cmd_settingsOffline":
@@ -451,19 +452,16 @@ var DefaultController =
   {
     // if the user invoked a key short cut then it is possible that we got here for a command which is
     // really disabled. kick out if the command should be disabled.
     if (!this.isCommandEnabled(command))
       return;
 
     switch (command)
     {
-      case "cmd_close":
-        MsgCloseCurrentTab();
-        break;
       case "button_getNewMessages":
       case "cmd_getNewMessages":
         MsgGetMessage();
         break;
       case "cmd_getMsgsForAuthAccounts":
         MsgGetMessagesForAllAuthenticatedAccounts();
         break;
       case "cmd_getNextNMessages":
@@ -736,16 +734,25 @@ var DefaultController =
     if ( event == 'blur' )
     {
       goSetMenuValue('cmd_undo', 'valueDefault');
       goSetMenuValue('cmd_redo', 'valueDefault');
     }
   }
 };
 
+function MsgCloseTabOrWindow()
+{
+  var tabmail = GetTabMail();
+  if (tabmail.tabInfo.length > 1)
+    tabmail.removeCurrentTab();
+  else
+    window.close();
+}
+
 function GetNumSelectedMessages()
 {
   try {
     return gDBView.numSelected;
   }
   catch (ex) {
     return 0;
   }
--- a/suite/mailnews/content/mailWindowOverlay.js
+++ b/suite/mailnews/content/mailWindowOverlay.js
@@ -1432,21 +1432,16 @@ function MsgCreateFilter()
   }
   if (!folder)
     folder = GetFirstSelectedMsgFolder();
 
     if (emailAddress)
      top.MsgFilters(emailAddress, folder);
 }
 
-function MsgHome(url)
-{
-  window.open(url, "_blank", "chrome,dependent=yes,all");
-}
-
 function MsgNewFolder(callBackFunctionName)
 {
     var preselectedFolder = GetFirstSelectedMsgFolder();
     var dualUseFolders = true;
     var server = null;
     var destinationFolder = null;
 
     if (preselectedFolder)
@@ -1572,21 +1567,16 @@ function MsgOpenFromFile()
     let uri = fp.fileURL.QueryInterface(Ci.nsIURL);
     uri.query = "type=application/x-message-display";
 
     window.openDialog("chrome://messenger/content/messageWindow.xul", "_blank",
                     "all,chrome,dialog=no,status,toolbar", uri);
   });
 }
 
-function MsgOpenNewWindowForMsgHdr(hdr)
-{
-  MsgOpenNewWindowForFolder(hdr.folder.URI, hdr.messageKey);
-}
-
 function MsgOpenNewWindowForFolder(uri, key)
 {
   var uriToOpen = uri;
   var keyToSelect = key;
 
   if (!uriToOpen)
     // use GetSelectedFolderURI() to find out which message to open instead of
     // GetLoadedMsgFolder().URI.
@@ -2109,76 +2099,58 @@ function IsGetNextNMessagesEnabled()
         menuItem.removeAttribute("hidden");
         return true;
     }
 
     menuItem.setAttribute("hidden","true");
     return false;
 }
 
-function IsEmptyTrashEnabled()
-{
-  var folderURI = GetSelectedFolderURI();
-  var server = GetServer(folderURI);
-  return (server && server.canEmptyTrashOnExit ? IsMailFolderSelected() : false);
-}
-
 function IsCompactFolderEnabled()
 {
   var server = GetServer(GetSelectedFolderURI());
   return (server &&
       ((server.type != 'imap') || server.canCompactFoldersOnServer) &&
       isCommandEnabled("cmd_compactFolder"));   // checks e.g. if IMAP is offline
 }
 
-var gReplyAllButton = null;
-var gDeleteButton = null;
-
 function SetUpToolbarButtons(uri)
 {
-    // Eventually, we might want to set up the toolbar differently for imap,
-    // pop, and news. For now, just tweak it based on if it is news or not.
-    var forNews = isNewsURI(uri);
-
-    if(!gDeleteButton) gDeleteButton = document.getElementById("button-delete");
-    if (!gReplyAllButton) gReplyAllButton = document.getElementById("button-replyall");
-
-    gDeleteButton.hidden = forNews;
-    if (forNews) {
-        gReplyAllButton.setAttribute("type", "menu-button");
-        gReplyAllButton.setAttribute("tooltiptext", gReplyAllButton.getAttribute("tooltiptextnews"));
-    }
-    else {
-        gReplyAllButton.removeAttribute("type");
-        gReplyAllButton.setAttribute("tooltiptext", gReplyAllButton.getAttribute("tooltiptextmail"));
-    }
+  let deleteButton = document.getElementById("button-delete");
+  let replyAllButton = document.getElementById("button-replyall");
+
+  // Eventually, we might want to set up the toolbar differently for imap,
+  // pop, and news. For now, just tweak it based on if it is news or not.
+  let forNews = isNewsURI(uri);
+
+  deleteButton.hidden = forNews;
+  if (forNews) {
+    replyAllButton.setAttribute("type", "menu-button");
+    replyAllButton.setAttribute("tooltiptext",
+                                replyAllButton.getAttribute("tooltiptextnews"));
+  } else {
+    replyAllButton.removeAttribute("type");
+    replyAllButton.setAttribute("tooltiptext",
+                                replyAllButton.getAttribute("tooltiptextmail"));
+  }
 }
 
-var gMessageBrowser;
-
 function getMessageBrowser()
 {
-  if (!gMessageBrowser)
-    gMessageBrowser = document.getElementById("messagepane");
-  return gMessageBrowser;
+  return document.getElementById("messagepane");
 }
 
 // The zoom manager, view source and possibly some other functions still rely
 // on the getBrowser function.
 function getBrowser()
 {
   return GetTabMail() ? GetTabMail().getBrowserForSelectedTab() :
                         getMessageBrowser();
 }
 
-function getMarkupDocumentViewer()
-{
-  return getMessageBrowser().markupDocumentViewer;
-}
-
 function MsgSynchronizeOffline()
 {
   window.openDialog("chrome://messenger/content/msgSynchronize.xul", "",
                     "centerscreen,chrome,modal,titlebar,resizable",
                     {msgWindow:msgWindow});
 }
 
 function MsgOpenAttachment() {}
--- a/suite/mailnews/content/mailWindowOverlay.xul
+++ b/suite/mailnews/content/mailWindowOverlay.xul
@@ -86,17 +86,16 @@
 </commandset>
 
 <commandset id="mailFileMenuItems"
             commandupdater="true"
             events="create-menu-file, message-header-pane"
             oncommandupdate="goUpdateMailMenuItems(this)">
 
     <command id="cmd_getNewMessages" oncommand="goDoCommand('cmd_getNewMessages')" disabled="true"/>
-    <command id="cmd_close" oncommand="goDoCommand('cmd_close')"/>
     <command id="cmd_open" oncommand="goDoCommand('cmd_open')"/>
 
     <command id="cmd_emptyTrash" oncommand="goDoCommand('cmd_emptyTrash')" disabled="true"/>
     <command id="cmd_compactFolder" oncommand="goDoCommand('cmd_compactFolder')" disabled="true"/>
 
     <command id="cmd_printSetup" oncommand="goDoCommand('cmd_printSetup')" disabled="true"/>
     <command id="cmd_print" oncommand="goDoCommand('cmd_print')" disabled="true"/>
     <command id="cmd_printpreview" oncommand="goDoCommand('cmd_printpreview')" disabled="true"/>
--- a/suite/mailnews/content/messageWindow.js
+++ b/suite/mailnews/content/messageWindow.js
@@ -614,17 +614,16 @@ var MessageWindowController =
       case "cmd_reload":
       case "cmd_saveAsFile":
       case "cmd_getNewMessages":
       case "button_getNewMessages":
       case "button_print":
       case "cmd_print":
       case "cmd_printpreview":
       case "cmd_printSetup":
-      case "cmd_close":
       case "cmd_settingsOffline":
       case "cmd_createFilterFromPopup":
       case "cmd_createFilterFromMenu":
         return true;
       case "cmd_synchronizeOffline":
       case "cmd_downloadFlagged":
       case "cmd_downloadSelected":
         return !Services.io.offline;
@@ -716,17 +715,16 @@ var MessageWindowController =
       case "cmd_getNextNMessages":
         return IsGetNextNMessagesEnabled();
       case "cmd_downloadFlagged":
       case "cmd_downloadSelected":
       case "cmd_synchronizeOffline":
         return !Services.io.offline;
       case "cmd_settingsOffline":
         return IsAccountOfflineEnabled();
-      case "cmd_close":
       case "cmd_nextMsg":
       case "button_next":
       case "cmd_nextUnreadMsg":
       case "cmd_nextFlaggedMsg":
       case "cmd_nextUnreadThread":
       case "cmd_previousMsg":
       case "cmd_previousUnreadMsg":
       case "cmd_previousFlaggedMsg":
@@ -764,19 +762,16 @@ var MessageWindowController =
     // if the user invoked a key short cut then it is possible that we got here for a command which is
     // really disabled. kick out if the command should be disabled.
     if (!this.isCommandEnabled(command)) return;
 
     var navigationType = nsMsgNavigationType.nextUnreadMessage;
 
     switch ( command )
     {
-      case "cmd_close":
-        CloseMailWindow();
-        break;
       case "cmd_getNewMessages":
         MsgGetMessage();
         break;
       case "cmd_undo":
         messenger.undo(msgWindow);
         break;
       case "cmd_redo":
         messenger.redo(msgWindow);
--- a/suite/mailnews/content/messageWindow.xul
+++ b/suite/mailnews/content/messageWindow.xul
@@ -61,16 +61,17 @@
     <commandset id="mailMessageMenuItems"/>
     <commandset id="mailToolbarItems"/>
     <commandset id="mailGetMsgMenuItems"/>
     <commandset id="mailMarkMenuItems"/>
     <commandset id="mailToolsMenuItems"/>
     <commandset id="mailEditContextMenuItems"/>
     <commandset id="tasksCommands"/>
     <commandset id="commandKeys"/>
+    <command id="cmd_close" oncommand="window.close();"/>
   </commandset>
 
   <broadcasterset id="mailBroadcasters">
     <broadcaster id="mailHideMenus" hidden="true"/>
     <broadcaster id="mailDisableKeys" disabled="true"/>
     <!-- File Menu -->
     <broadcaster id="Communicator:WorkMode"/>
     <!-- Edit Menu -->
--- a/suite/mailnews/content/messenger.xul
+++ b/suite/mailnews/content/messenger.xul
@@ -72,16 +72,17 @@
   <commandset id="globalEditMenuItems"/>
   <commandset id="selectEditMenuItems"/>
   <commandset id="clipboardEditMenuItems"/>
   <commandset id="FocusRingUpdate_Mail"
         commandupdater="true"
         events="focus"
         oncommandupdate="FocusRingUpdate_Mail()"/>
   <commandset id="tasksCommands"/>
+  <command id="cmd_close" oncommand="MsgCloseTabOrWindow();"/>
 </commandset>
 
 <broadcasterset id="mailBroadcasters">
   <broadcaster id="mailHideMenus"/>
   <broadcaster id="mailDisableKeys"/>
   <broadcaster id="mailDisableViewsSearch" disabled="true"/>
   <!-- File Menu -->
   <broadcaster id="Communicator:WorkMode"/>
--- a/suite/mailnews/content/tabmail.js
+++ b/suite/mailnews/content/tabmail.js
@@ -547,25 +547,16 @@ function MsgOpenNewTabForMessage()
 
 // A Thunderbird compatibility function called from e.g. newsblog.
 // We ignore aHandlerRegExp as it is not needed by SeaMonkey.
 function openContentTab(aUrl, aWhere, aHandlerRegExp)
 {
   openUILinkIn(aUrl, aWhere);
 }
 
-function MsgCloseCurrentTab()
-{
-  var tabmail = GetTabMail();
-  if (tabmail.tabInfo.length > 1)
-    tabmail.removeCurrentTab();
-  else
-    CloseMailWindow();
-}
-
 function AllowOpenTabOnMiddleClick()
 {
   return Services.prefs.getBoolPref("browser.tabs.opentabfor.middleclick");
 }
 
 function AllowOpenTabOnDoubleClick()
 {
   return Services.prefs.getBoolPref("browser.tabs.opentabfor.doubleclick");