From a0da660486776958e405ce0ffc0f02b0aa8ad076 Mon Sep 17 00:00:00 2001 From: Ian Neal Date: Mon, 11 Nov 2019 20:45:13 +0100 Subject: [PATCH] Bug 1589892 - Port |Bug 440616 (part 1 v2) Clean up Thunderbird's global scope a bit more (mail session and 3pane commands)| to SeaMonkey. r=frg DONTBUILD --- suite/mailnews/content/commandglue.js | 5 -- .../content/mail3PaneWindowCommands.js | 71 ++++--------------- suite/mailnews/content/mailContextMenus.js | 8 +-- suite/mailnews/content/mailWindow.js | 14 ++-- suite/mailnews/content/messageWindow.js | 11 ++- suite/mailnews/content/msgMail3PaneWindow.js | 13 ++-- 6 files changed, 26 insertions(+), 96 deletions(-) diff --git a/suite/mailnews/content/commandglue.js b/suite/mailnews/content/commandglue.js index ae4041ab93..130ac37118 100644 --- a/suite/mailnews/content/commandglue.js +++ b/suite/mailnews/content/commandglue.js @@ -919,8 +919,6 @@ var gMessengerBundle = null; var gDataSourceSearchListener; var gViewSearchListener; -var gMailSession; - function GetScopeForFolder(folder) { return folder.server.searchScope; @@ -933,9 +931,6 @@ function setupXFVirtualFolderSearch(folderUrisToSearch, searchTerms, searchOnlin gSearchSession = Cc[searchSessionContractID].createInstance(Ci.nsIMsgSearchSession); - gMailSession = Cc["@mozilla.org/messenger/services/session;1"] - .getService(Ci.nsIMsgMailSession); - for (i in folderUrisToSearch) { let realFolder = GetMsgFolderFromUri(folderUrisToSearch[i]); diff --git a/suite/mailnews/content/mail3PaneWindowCommands.js b/suite/mailnews/content/mail3PaneWindowCommands.js index ac6b8f4a11..312cc79a02 100644 --- a/suite/mailnews/content/mail3PaneWindowCommands.js +++ b/suite/mailnews/content/mail3PaneWindowCommands.js @@ -538,33 +538,33 @@ var DefaultController = break; case "button_next": case "cmd_nextUnreadMsg": - MsgNextUnreadMessage(); + GoNextMessage(nsMsgNavigationType.nextUnreadMessage, true); break; case "cmd_nextUnreadThread": - MsgNextUnreadThread(); + GoNextMessage(nsMsgNavigationType.nextUnreadThread, true); break; case "cmd_nextMsg": - MsgNextMessage(); + GoNextMessage(nsMsgNavigationType.nextMessage, false); break; case "cmd_nextFlaggedMsg": - MsgNextFlaggedMessage(); + GoNextMessage(nsMsgNavigationType.nextFlagged, true); break; case "cmd_previousMsg": - MsgPreviousMessage(); + GoNextMessage(nsMsgNavigationType.previousMessage, false); break; case "cmd_previousUnreadMsg": - MsgPreviousUnreadMessage(); + GoNextMessage(nsMsgNavigationType.previousUnreadMessage, true); break; case "cmd_previousFlaggedMsg": - MsgPreviousFlaggedMessage(); + GoNextMessage(nsMsgNavigationType.previousFlagged, true); + break; + case "button_goForward": + case "cmd_goForward": + GoNextMessage(nsMsgNavigationType.forward, true); break; case "button_goBack": case "cmd_goBack": - MsgGoBack(); - break; - case "button_goForward": - case "cmd_goForward": - MsgGoForward(); + GoNextMessage(nsMsgNavigationType.back, true); break; case "cmd_goStartPage": HideMessageHeaderPane(); @@ -658,7 +658,7 @@ var DefaultController = MsgJunk(); return; case "cmd_stop": - MsgStop(); + msgWindow.StopUrls(); return; case "cmd_markAsFlagged": MsgMarkAsFlagged(null); @@ -1003,51 +1003,6 @@ function SetFocusThreadPaneIfNotOnMessagePane() SetFocusThreadPane(); } -// 3pane related commands. Need to go in own file. Putting here for the moment. -function MsgNextMessage() -{ - GoNextMessage(nsMsgNavigationType.nextMessage, false); -} - -function MsgNextUnreadMessage() -{ - GoNextMessage(nsMsgNavigationType.nextUnreadMessage, true); -} -function MsgNextFlaggedMessage() -{ - GoNextMessage(nsMsgNavigationType.nextFlagged, true); -} - -function MsgNextUnreadThread() -{ - GoNextMessage(nsMsgNavigationType.nextUnreadThread, true); -} - -function MsgPreviousMessage() -{ - GoNextMessage(nsMsgNavigationType.previousMessage, false); -} - -function MsgPreviousUnreadMessage() -{ - GoNextMessage(nsMsgNavigationType.previousUnreadMessage, true); -} - -function MsgPreviousFlaggedMessage() -{ - GoNextMessage(nsMsgNavigationType.previousFlagged, true); -} - -function MsgGoBack() -{ - GoNextMessage(nsMsgNavigationType.back, true); -} - -function MsgGoForward() -{ - GoNextMessage(nsMsgNavigationType.forward, true); -} - function SwitchPaneFocus(event) { var folderTree = GetFolderTree(); diff --git a/suite/mailnews/content/mailContextMenus.js b/suite/mailnews/content/mailContextMenus.js index 4d07f27897..d902111b9f 100644 --- a/suite/mailnews/content/mailContextMenus.js +++ b/suite/mailnews/content/mailContextMenus.js @@ -679,14 +679,8 @@ function CheckForMessageIdInFolder(folder, messageId) dump("Failed to find message-id in folder!"); } - if (!gMailSession) - { - gMailSession = Cc["@mozilla.org/messenger/services/session;1"] - .getService(Ci.nsIMsgMailSession); - } - const nsMsgFolderFlags = Ci.nsMsgFolderFlags; - if (!gMailSession.IsFolderOpenInWindow(folder) && + if (!MailServices.mailSession.IsFolderOpenInWindow(folder) && !(folder.flags & (nsMsgFolderFlags.Trash | nsMsgFolderFlags.Inbox))) { folder.msgDatabase = null; diff --git a/suite/mailnews/content/mailWindow.js b/suite/mailnews/content/mailWindow.js index 1eb7c9bbe0..af41a12fbb 100644 --- a/suite/mailnews/content/mailWindow.js +++ b/suite/mailnews/content/mailWindow.js @@ -15,8 +15,6 @@ var RDF; var msgComposeType; var msgComposeFormat; -var mailSession; - var gMessengerBundle; var gBrandBundle; @@ -48,11 +46,9 @@ function OnMailWindowUnload() dbview.close(); } - var mailSession = Cc["@mozilla.org/messenger/services/session;1"] - .getService(); - if (mailSession instanceof Ci.nsIMsgMailSession) - mailSession.RemoveFolderListener(folderListener); - mailSession.RemoveMsgWindow(msgWindow); + MailServices.mailSession.RemoveFolderListener(folderListener); + + MailServices.mailSession.RemoveMsgWindow(msgWindow); messenger.setWindow(null, null); msgWindow.closeWindow(); @@ -186,8 +182,6 @@ function CreateMailWindowGlobals() msgComposeService = Cc['@mozilla.org/messengercompose;1'] .getService(Ci.nsIMsgComposeService); - mailSession = Cc["@mozilla.org/messenger/services/session;1"].getService(Ci.nsIMsgMailSession); - accountManager = Cc["@mozilla.org/messenger/account-manager;1"].getService(Ci.nsIMsgAccountManager); RDF = Cc['@mozilla.org/rdf/rdf-service;1'] @@ -218,7 +212,7 @@ function InitMsgWindow() msgWindow.domWindow = window; msgWindow.statusFeedback = statusFeedback; msgWindow.msgHeaderSink = messageHeaderSink; - mailSession.AddMsgWindow(msgWindow); + MailServices.mailSession.AddMsgWindow(msgWindow); var messagepane = getMessageBrowser(); messagepane.docShell.allowAuth = false; diff --git a/suite/mailnews/content/messageWindow.js b/suite/mailnews/content/messageWindow.js index 66c4742ab6..4036e379d9 100644 --- a/suite/mailnews/content/messageWindow.js +++ b/suite/mailnews/content/messageWindow.js @@ -219,13 +219,10 @@ function OnLoadMessageWindow() // FIX ME - later we will be able to use onload from the overlay OnLoadMsgHeaderPane(); - try { - var nsIFolderListener = Ci.nsIFolderListener; - var notifyFlags = nsIFolderListener.removed | nsIFolderListener.event | nsIFolderListener.intPropertyChanged; - mailSession.AddFolderListener(folderListener, notifyFlags); - } catch (ex) { - dump("Error adding to session: " +ex + "\n"); - } + var nsIFolderListener = Ci.nsIFolderListener; + var notifyFlags = nsIFolderListener.removed | nsIFolderListener.event | + nsIFolderListener.intPropertyChanged; + MailServices.mailSession.AddFolderListener(folderListener, notifyFlags); var originalView = null; var folder = null; diff --git a/suite/mailnews/content/msgMail3PaneWindow.js b/suite/mailnews/content/msgMail3PaneWindow.js index 4a3d1609aa..81feb47d1c 100644 --- a/suite/mailnews/content/msgMail3PaneWindow.js +++ b/suite/mailnews/content/msgMail3PaneWindow.js @@ -962,15 +962,10 @@ function loadStartFolder(initialUri) function AddToSession() { - try { - var mailSession = Cc["@mozilla.org/messenger/services/session;1"] - .getService(Ci.nsIMsgMailSession); - var nsIFolderListener = Ci.nsIFolderListener; - var notifyFlags = nsIFolderListener.intPropertyChanged | nsIFolderListener.event; - mailSession.AddFolderListener(folderListener, notifyFlags); - } catch (ex) { - dump("Error adding to session\n"); - } + var nsIFolderListener = Ci.nsIFolderListener; + var notifyFlags = nsIFolderListener.intPropertyChanged | + nsIFolderListener.event; + MailServices.mailSession.AddFolderListener(folderListener, notifyFlags); } function InitPanes()