Bug 232679 Can't open blank new message when main mail window is not open. r=philringnalda
authorMark Banner <bugzilla@standard8.plus.com>
Tue, 25 Aug 2009 15:57:50 +0100
changeset 3408 477ef62ff985675b8d4ba49efdef75f72f1c75d0
parent 3407 87e25cdb1d5667a874b54cf486de808bf9150a53
child 3409 c43e364dec915a0aa1fec1110ec71241cd093a5a
push idunknown
push userunknown
push dateunknown
reviewersphilringnalda
bugs232679
Bug 232679 Can't open blank new message when main mail window is not open. r=philringnalda
mail/base/content/hiddenWindow.js
mail/base/content/mailCommands.js
mail/base/content/mailWindowOverlay.js
--- a/mail/base/content/hiddenWindow.js
+++ b/mail/base/content/hiddenWindow.js
@@ -31,20 +31,26 @@
 # use your version of this file under the terms of the MPL, indicate your
 # decision by deleting the provisions above and replace them with the notice
 # and other provisions required by the GPL or the LGPL. If you do not delete
 # the provisions above, a recipient may use your version of this file under
 # the terms of any one of the MPL, the GPL or the LGPL.
 #
 # ***** END LICENSE BLOCK *****
 
+// XXX This is needed by mailCommands.js for the new message command, ideally
+// this shouldn't be a global.
+var msgComposeService = Components.classes["@mozilla.org/messengercompose;1"]
+                                  .getService(Components.interfaces.nsIMsgComposeService);
+
 function hiddenWindowStartup()
 {
   // Disable menus which are not appropriate
-  var disabledItems = ['newNewMsgCmd', 'menu_newFolder', 'newAccountMenuItem', 'menu_close', 'menu_saveAs',
+  var disabledItems = ['menu_newFolder', 'newMailAccountMenuItem',
+             'newAccountMenuItem', 'menu_close', 'menu_saveAs',
              'menu_saveAsFile', 'menu_newVirtualFolder', 'menu_find', 'menu_findCmd', 'menu_findAgainCmd',
              'menu_sendunsentmsgs', 'menu_subscribe', 'menu_deleteFolder',
              'menu_renameFolder', 'menu_select',
              'menu_selectAll', 'menu_selectThread',
              'menu_favoriteFolder', 'menu_properties',
              'menu_Toolbars', 'menu_MessagePaneLayout', 'menu_showMessage', 'menu_FolderViews',
              'viewSortMenu', 'groupBySort', 'viewMessageViewMenu', 'mailviewCharsetMenu',
              'viewMessagesMenu', 'menu_expandAllThreads', 'collapseAllThreads',
--- a/mail/base/content/mailCommands.js
+++ b/mail/base/content/mailCommands.js
@@ -208,17 +208,19 @@ function ComposeMessage(type, format, fo
   if (type == msgComposeType.New)
   {
     // New message.
 
     // dump("OpenComposeWindow with " + identity + "\n");
 
     // If the addressbook sidebar panel is open and has focus, get
     // the selected addresses from it.
-    if (document.commandDispatcher.focusedWindow.document.documentElement.hasAttribute("selectedaddresses"))
+    if (document.commandDispatcher.focusedWindow &&
+        document.commandDispatcher.focusedWindow
+                .document.documentElement.hasAttribute("selectedaddresses"))
       NewMessageToSelectedAddresses(type, format, identity);
     else
       msgComposeService.OpenComposeWindow(null, null, null, type, format, identity, msgWindow);
     return;
   }
   else if (type == msgComposeType.NewsPost)
   {
     // dump("OpenComposeWindow with " + identity + " and " + newsgroup + "\n");
--- a/mail/base/content/mailWindowOverlay.js
+++ b/mail/base/content/mailWindowOverlay.js
@@ -86,16 +86,21 @@ var gMarkViewedMessageAsReadTimer = null
 // change during runtime other than through the MsgBody*() functions below.
 var gDisallow_classes_no_html = 1;
 
 // Disable the new account menu item if the account preference is locked.
 // Two other affected areas are the account central and the account manager
 // dialog.
 function menu_new_init()
 {
+  // If we don't have a gFolderDisplay, just get out of here and leave the menu
+  // as it is.
+  if (!gFolderDisplay)
+    return;
+
   let folder = gFolderDisplay.displayedFolder;
   if (!folder)
     return;
 
   if (!gMessengerBundle)
     gMessengerBundle = document.getElementById("bundle_messenger");
 
   if (gPrefBranch.prefIsLocked("mail.disable_new_account_addition"))
@@ -1206,26 +1211,29 @@ function MsgMoveMessage(aDestFolder)
 /**
  * Calls the ComposeMessage function with the desired type, and proper default
  * based on the event that fired it.
  *
  * @param aCompType  the nsIMsgCompType to pass to the function
  * @param aEvent (optional) the event that triggered the call
  */
 function composeMsgByType(aCompType, aEvent) {
+  // If we're the hidden window, then we're not going to have a gFolderDisplay
+  // to work out existing folders, so just use null.
+  let msgFolder = gFolderDisplay ? GetFirstSelectedMsgFolder() : null;
+  let msgUris = gFolderDisplay ? gFolderDisplay.selectedMessageUris : null;
+
   if (aEvent && aEvent.shiftKey) {
     ComposeMessage(aCompType,
                    Components.interfaces.nsIMsgCompFormat.OppositeOfDefault,
-                   GetFirstSelectedMsgFolder(),
-                   gFolderDisplay.selectedMessageUris);
+                   msgFolder, msgUris);
   }
   else {
     ComposeMessage(aCompType, Components.interfaces.nsIMsgCompFormat.Default,
-                   GetFirstSelectedMsgFolder(),
-                   gFolderDisplay.selectedMessageUris);
+                   msgFolder, msgUris);
   }
 }
 
 function MsgNewMessage(event)
 {
   composeMsgByType(Components.interfaces.nsIMsgCompType.New, event);
 }