Bug 767118 - Part 1 - File > New menuitems in mail:3pane now use XUL commands properly. r=florian,squib.
authorMike Conley <mconley@mozilla.com>
Wed, 11 Jul 2012 10:14:39 -0400
changeset 12839 f80dc5c5d591398d882181cd5611656c55ca3512
parent 12838 a704b9b6944c869f605ded4a19546c842002cb59
child 12840 06898b5bcf86ff66cfecaf5c4538244246e3f11b
push idunknown
push userunknown
push dateunknown
reviewersflorian, squib
bugs767118
Bug 767118 - Part 1 - File > New menuitems in mail:3pane now use XUL commands properly. r=florian,squib.
mail/base/content/mail3PaneWindowCommands.js
mail/base/content/mailCommands.js
mail/base/content/mailOverlay.xul
mail/base/content/mailWindowOverlay.js
mail/base/content/mailWindowOverlay.xul
mail/components/compose/content/MsgComposeCommands.js
mail/components/compose/content/messengercompose.xul
mail/components/im/content/chat-messenger-overlay.js
mail/components/im/content/chat-messenger-overlay.xul
--- a/mail/base/content/mail3PaneWindowCommands.js
+++ b/mail/base/content/mail3PaneWindowCommands.js
@@ -105,16 +105,23 @@ function UpdateDeleteLabelsFromFolderCom
 
 // DefaultController object (handles commands when one of the trees does not have focus)
 var DefaultController =
 {
   supportsCommand: function(command)
   {
     switch ( command )
     {
+      case "cmd_newFolder":
+      case "cmd_newVirtualFolder":
+      case "cmd_newMailAccount":
+      case "cmd_newExistingAccount":
+      case "cmd_newIMAccount":
+      case "cmd_newOtherAccount":
+      case "cmd_newIMContact":
       case "cmd_createFilterFromPopup":
       case "cmd_archive":
       case "button_archive":
       case "cmd_reply":
       case "button_reply":
       case "cmd_replySender":
       case "cmd_replyGroup":
       case "button_followup":
@@ -252,16 +259,27 @@ var DefaultController =
   isCommandEnabled: function(command)
   {
     var enabled = new Object();
     enabled.value = false;
     var checkStatus = new Object();
 
     switch ( command )
     {
+      case "cmd_newFolder":
+      case "cmd_newVirtualFolder":
+        if (!gFolderDisplay || !gFolderDisplay.displayedFolder)
+          return false;
+
+        let selectedFolder = gFolderDisplay.displayedFolder;
+        let isInbox = selectedFolder.isSpecialFolder(nsMsgFolderFlags.Inbox);
+        let result = selectedFolder.canCreateSubfolders ||
+                     (isInbox &&
+                      !(selectedFolder.flags & nsMsgFolderFlags.Virtual));
+        return result;
       case "cmd_delete":
         UpdateDeleteCommand();
         // fall through
       case "button_delete":
         UpdateDeleteToolbarButton();
         return gFolderDisplay.getCommandStatus(nsMsgViewCommandType.deleteMsg);
       case "cmd_shiftDelete":
       case "button_shiftDelete":
@@ -356,20 +374,32 @@ var DefaultController =
             return IsReplyListEnabled();
           return true;
         }
         return false;
       case "cmd_printpreview":
         if (GetNumSelectedMessages() == 1)
           return gFolderDisplay.getCommandStatus(nsMsgViewCommandType.cmdRequiringMsgBody);
         return false;
+      case "cmd_newMailAccount":
+      case "cmd_newExistingAccount":
+      case "cmd_newIMAccount":
+      case "cmd_newOtherAccount":
       case "cmd_printSetup":
       case "cmd_viewAllHeader":
       case "cmd_viewNormalHeader":
         return true;
+
+      case "cmd_newIMContact":
+        for (let account in fixIterator(imServices.accounts.getAccounts()))
+          if (account.connected)
+            return true;
+
+        return false;
+
       case "cmd_markAsFlagged":
       case "button_file":
 	return GetNumSelectedMessages() > 0;
       case "cmd_archive":
       case "button_archive":
         return gFolderDisplay.canArchiveSelectedMessages;
       case "cmd_markAsJunk":
       case "cmd_markAsNotJunk":
@@ -571,16 +601,37 @@ var DefaultController =
   doCommand: function(command, aTab)
   {
     // 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_newFolder":
+        gFolderTreeController.newFolder();
+        break;
+      case "cmd_newVirtualFolder":
+        gFolderTreeController.newVirtualFolder();
+        break;
+      case "cmd_newMailAccount":
+        NewMailAccountProvisioner(msgWindow);
+        break;
+      case "cmd_newExistingAccount":
+        NewMailAccount(msgWindow);
+        break;
+      case "cmd_newIMAccount":
+        openIMAccountWizard();
+        break;
+      case "cmd_newOtherAccount":
+        MsgAccountWizard();
+        break;
+      case "cmd_newIMContact":
+        chatHandler.addBuddy();
+        break;
       case "button_getNewMessages":
       case "cmd_getNewMessages":
         MsgGetMessage();
         break;
       case "cmd_getMsgsForAuthAccounts":
         MsgGetMessagesForAllAuthenticatedAccounts();
         break;
       case "cmd_getNextNMessages":
--- a/mail/base/content/mailCommands.js
+++ b/mail/base/content/mailCommands.js
@@ -211,16 +211,73 @@ function ComposeMessage(type, format, fo
                                          format, identity, msgWindow);
         else
           MailServices.compose.OpenComposeWindow(null, hdr, messageUri, type,
                                                  format, identity, msgWindow);
       }
   }
 }
 
+/**
+ * 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,
+                   msgFolder, msgUris);
+  }
+  else {
+    ComposeMessage(aCompType, Components.interfaces.nsIMsgCompFormat.Default,
+                   msgFolder, msgUris);
+  }
+}
+
+function MsgNewMessage(event)
+{
+  composeMsgByType(Components.interfaces.nsIMsgCompType.New, event);
+}
+
+function MsgReplyMessage(event)
+{
+  if (gFolderDisplay.selectedMessageIsNews)
+    MsgReplyGroup(event);
+  else
+    MsgReplySender(event);
+}
+
+function MsgReplySender(event)
+{
+  composeMsgByType(Components.interfaces.nsIMsgCompType.ReplyToSender, event);
+}
+
+function MsgReplyGroup(event)
+{
+  composeMsgByType(Components.interfaces.nsIMsgCompType.ReplyToGroup, event);
+}
+
+function MsgReplyToAllMessage(event)
+{
+  composeMsgByType(Components.interfaces.nsIMsgCompType.ReplyAll, event);
+}
+
+function MsgReplyToListMessage(event)
+{
+  composeMsgByType(Components.interfaces.nsIMsgCompType.ReplyToList, event);
+}
+
 function NewMessageToSelectedAddresses(type, format, identity) {
   var abSidebarPanel = document.commandDispatcher.focusedWindow;
   var abResultsTree = abSidebarPanel.document.getElementById("abResultsTree");
   var abResultsBoxObject = abResultsTree.treeBoxObject;
   var abView = abResultsBoxObject.view;
   abView = abView.QueryInterface(Components.interfaces.nsIAbView);
   var addresses = abView.selectedAddresses;
   var params = Components.classes["@mozilla.org/messengercompose/composeparams;1"].createInstance(Components.interfaces.nsIMsgComposeParams);
--- a/mail/base/content/mailOverlay.xul
+++ b/mail/base/content/mailOverlay.xul
@@ -5,46 +5,26 @@
 
 
 <!DOCTYPE overlay SYSTEM "chrome://messenger/locale/mailOverlay.dtd">
 <overlay id="mailOverlay.xul"
          xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
   <script type="application/javascript">
   <![CDATA[
-    Components.utils.import("resource:///modules/mailServices.js");
     function openNewCardDialog()
       {
         window.openDialog("chrome://messenger/content/addressbook/abNewCardDialog.xul",
                           "", "chrome,modal,resizable=no,centerscreen");
       }
-
-    function goOpenNewMessage()
-      {
-        // if there is a MsgNewMessage function in scope
-        // and we should use it, so that we choose the proper
-        // identity, based on the selected message or folder
-        // if not, bring up the compose window to the default identity
-        if ("MsgNewMessage" in window) {
-          MsgNewMessage(null);
-          return;
-        }
-
-        MailServices.compose.OpenComposeWindow(null, null, null,
-          Components.interfaces.nsIMsgCompType.New,
-          Components.interfaces.nsIMsgCompFormat.Default,
-          null, null);
-      }
-
   ]]>
   </script>
 
   <!-- generic commands -->
   <commandset id="tasksCommands">
-    <command id="cmd_newMessage" oncommand="goOpenNewMessage();"/>
     <command id="cmd_newCard" oncommand="openNewCardDialog()"/>
   </commandset>
   <menuitem id="menu_newCard" label="&newContactCmd.label;"
             accesskey="&newContactCmd.accesskey;" command="cmd_newCard"/>
   <menuitem id="menu_newMessage" label="&newMessageCmd.label;"
             accesskey="&newMessageCmd.accesskey;" key="key_newMessage"
             command="cmd_newMessage"/>
   <keyset id="tasksKeys">
--- a/mail/base/content/mailWindowOverlay.js
+++ b/mail/base/content/mailWindowOverlay.js
@@ -1282,72 +1282,16 @@ function MsgCopyMessage(aDestFolder)
 function MsgMoveMessage(aDestFolder)
 {
   gFolderDisplay.hintAboutToDeleteMessages();
   gDBView.doCommandWithFolder(nsMsgViewCommandType.moveMessages, aDestFolder);
   pref.setCharPref("mail.last_msg_movecopy_target_uri", aDestFolder.URI);
   pref.setBoolPref("mail.last_msg_movecopy_was_move", true);
 }
 
-/**
- * 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,
-                   msgFolder, msgUris);
-  }
-  else {
-    ComposeMessage(aCompType, Components.interfaces.nsIMsgCompFormat.Default,
-                   msgFolder, msgUris);
-  }
-}
-
-function MsgNewMessage(event)
-{
-  composeMsgByType(Components.interfaces.nsIMsgCompType.New, event);
-}
-
-function MsgReplyMessage(event)
-{
-  if (gFolderDisplay.selectedMessageIsNews)
-    MsgReplyGroup(event);
-  else
-    MsgReplySender(event);
-}
-
-function MsgReplySender(event)
-{
-  composeMsgByType(Components.interfaces.nsIMsgCompType.ReplyToSender, event);
-}
-
-function MsgReplyGroup(event)
-{
-  composeMsgByType(Components.interfaces.nsIMsgCompType.ReplyToGroup, event);
-}
-
-function MsgReplyToAllMessage(event)
-{
-  composeMsgByType(Components.interfaces.nsIMsgCompType.ReplyAll, event);
-}
-
-function MsgReplyToListMessage(event)
-{
-  composeMsgByType(Components.interfaces.nsIMsgCompType.ReplyToList, event);
-}
 
 // Message Archive function
 
 function BatchMessageMover()
 {
   this._batches = {};
   this._currentKey = null;
 }
--- a/mail/base/content/mailWindowOverlay.xul
+++ b/mail/base/content/mailWindowOverlay.xul
@@ -74,19 +74,25 @@
 
 <!-- End command set merging -->
 
 <commandset id="mailFileMenuItems"
             commandupdater="true"
             events="create-menu-file"
             oncommandupdate="goUpdateMailMenuItems(this)">
 
+    <command id="cmd_newFolder" oncommand="goDoCommand('cmd_newFolder')" disabled="true"/>
+    <command id="cmd_newVirtualFolder" oncommand="goDoCommand('cmd_newVirtualFolder')" disabled="true"/>
+    <command id="cmd_newMailAccount" oncommand="goDoCommand('cmd_newMailAccount')" disabled="true"/>
+    <command id="cmd_newExistingAccount" oncommand="goDoCommand('cmd_newExistingAccount')" disabled="true"/>
+    <command id="cmd_newIMAccount" oncommand="goDoCommand('cmd_newIMAccount')" disabled="true"/>
+    <command id="cmd_newOtherAccount" oncommand="goDoCommand('cmd_newOtherAccount')" disabled="true"/>
+    <command id="cmd_newIMContact" oncommand="goDoCommand('cmd_newIMContact')" disabled="true"/>
     <command id="cmd_getNewMessages" oncommand="goDoCommand('cmd_getNewMessages')" disabled="true"/>
     <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"/>
     <command id="cmd_saveAsFile" oncommand="goDoCommand('cmd_saveAsFile')" disabled="true"/>
     <command id="cmd_saveAsTemplate" oncommand="goDoCommand('cmd_saveAsTemplate')" disabled="true"/>
     <command id="cmd_getNextNMessages" oncommand="goDoCommand('cmd_getNextNMessages')" disabled="true"/>
@@ -95,16 +101,17 @@
     <command id="cmd_sendUnsentMsgs" oncommand="goDoCommand('cmd_sendUnsentMsgs')" />
     <command id="cmd_synchronizeOffline" oncommand="goDoCommand('cmd_synchronizeOffline')" disabled="true"/>
     <command id="cmd_downloadFlagged" oncommand="goDoCommand('cmd_downloadFlagged')" disabled="true"/>
     <command id="cmd_downloadSelected" oncommand="goDoCommand('cmd_downloadSelected')" disabled="true"/>
     <command id="cmd_settingsOffline" oncommand="goDoCommand('cmd_settingsOffline')" disabled="true"/>
 </commandset>
 
 <commandset id="mailCommands">
+  <command id="cmd_newMessage" oncommand="MsgNewMessage(event);"/>
   <command id="cmd_quit"/>
   <!--The cmd_createFilterFromPopup is used to notify the email context popup -->
   <command id="cmd_createFilterFromPopup"/>
   <command id="cmd_pageSetup"/>
   <command id="cmd_CustomizeMailToolbar"
            oncommand="CustomizeMailToolbar('mail-toolbox', 'CustomizeMailToolbar')"/>
 </commandset>
 
@@ -965,46 +972,46 @@
         <!-- File -->
         <menu id="menu_File">
           <menupopup id="menu_FilePopup" onpopupshowing="file_init();">
           <menu id="menu_New">
             <menupopup id="menu_NewPopup" onpopupshowing="menu_new_init();">
               <menuitem id="newNewMsgCmd" label="&newNewMsgCmd.label;"
                         accesskey="&newNewMsgCmd.accesskey;"
                         key="key_newMessage2"
-                        oncommand="MsgNewMessage(null);"/>
+                        command="cmd_newMessage"/>
               <menuitem id="menu_newFolder" label="&newFolderCmd.label;"
-                         oncommand="gFolderTreeController.newFolder();"
-                         accesskey="&newFolderCmd.accesskey;"/>
+                        command="cmd_newFolder"
+                        accesskey="&newFolderCmd.accesskey;"/>
               <menuitem id="menu_newVirtualFolder" label="&newVirtualFolderCmd.label;"
-                         oncommand="gFolderTreeController.newVirtualFolder();"
-                         accesskey="&newVirtualFolderCmd.accesskey;"/>
+                        command="cmd_newVirtualFolder"
+                        accesskey="&newVirtualFolderCmd.accesskey;"/>
               <menuseparator id="newAccountPopupMenuSeparator"/>
               <menuitem id="newCreateEmailAccountMenuItem"
                         label="&newCreateEmailAccountCmd.label;"
                         accesskey="&newCreateEmailAccountCmd.accesskey;"
-                        oncommand="NewMailAccountProvisioner(msgWindow);"/>
+                        command="cmd_newMailAccount"/>
               <menuitem id="newMailAccountMenuItem"
                         label="&newExistingEmailAccountCmd.label;"
                         accesskey="&newExistingEmailAccountCmd.accesskey;"
-                        oncommand="NewMailAccount(msgWindow);"/>
+                        command="cmd_newExistingAccount"/>
               <menuitem id="newIMAccountMenuItem"
                         label="&newIMAccountCmd.label;"
                         accesskey="&newIMAccountCmd.accesskey;"
-                        oncommand="openIMAccountWizard();"/>
+                        command="cmd_newIMAccount"/>
               <menuitem id="newAccountMenuItem"
                         label="&newOtherAccountsCmd.label;"
                         accesskey="&newOtherAccountsCmd.accesskey;"
-                        oncommand="MsgAccountWizard();"/>
+                        command="cmd_newOtherAccount"/>
               <menuseparator id="newPopupMenuSeparator"/>
               <menuitem id="menu_newCard"/>
               <menuitem id="newIMContactMenuItem"
                         label="&newIMContactCmd.label;"
                         accesskey="&newIMContactCmd.accesskey;"
-                        oncommand="chatHandler.addBuddy();"/>
+                        command="cmd_newIMContact"/>
             </menupopup>
           </menu>
           <menuitem id="openMessageFileMenuitem" label="&openMessageFileCmd.label;"
             accesskey="&openMessageFileCmd.accesskey;"
             oncommand="MsgOpenFromFile();"/>
           <menu id="fileAttachmentMenu" label="&openAttachmentCmd.label;" accesskey="&openAttachmentCmd.accesskey;" disabled="true" persist="hidden">
             <menupopup id="attachmentMenuList" onpopupshowing="FillAttachmentListPopup(this);"/>
           </menu>
@@ -1760,17 +1767,17 @@
                   command="cmd_getMsgsForAuthAccounts"/>
         <menuseparator id="button-getAllNewMsgSeparator"/>
       </menupopup>
     </toolbarbutton>
     <toolbarbutton id="button-newmsg"
                    class="toolbarbutton-1"
                    label="&newMsgButton.label;"
                    tooltiptext="&newMsgButton.tooltip;"
-                   oncommand="MsgNewMessage(event)"/>
+                   command="cmd_newMessage"/>
     <toolbarbutton id="button-reply"
                    class="toolbarbutton-1"
                    label="&replyButton.label;"
                    tooltiptext="&replyButton.tooltip;"
                    observes="button_reply"
                    oncommand="MsgReplyMessage(event)"/>
     <toolbarbutton id="button-replyall"
                    class="toolbarbutton-1"
--- a/mail/components/compose/content/MsgComposeCommands.js
+++ b/mail/components/compose/content/MsgComposeCommands.js
@@ -392,16 +392,32 @@ var progressListener = {
         return this;
 
       throw Components.results.NS_NOINTERFACE;
     }
 };
 
 var defaultController = {
   commands: {
+    cmd_newMessage: {
+      isEnabled: function() {
+        return true;
+      },
+      doCommand: function() {
+        MailServices.compose.OpenComposeWindow(null, null, null,
+                                               Components.interfaces
+                                                         .nsIMsgCompType
+                                                         .New,
+                                               Components.interfaces
+                                                         .nsIMsgCompFormat
+                                                         .Default,
+                                               null, null);
+      }
+    },
+
     cmd_attachFile: {
       isEnabled: function() {
         return !gWindowLocked;
       },
       doCommand: function() {
         AttachFile();
       }
     },
@@ -744,27 +760,16 @@ var attachmentBucketController = {
     if (!cmd.isEnabled())
       return;
     cmd.doCommand();
   },
 
   onEvent: function(event) {},
 };
 
-/**
- * Start composing a new message.
- */
-function goOpenNewMessage()
-{
-  let identity = getCurrentIdentity();
-  MailServices.compose.OpenComposeWindow(null, null, null,
-    Components.interfaces.nsIMsgCompType.New,
-    Components.interfaces.nsIMsgCompFormat.Default, identity, null);
-}
-
 function QuoteSelectedMessage()
 {
   var selectedURIs = GetSelectedMessages();
   if (selectedURIs)
     for (let i = 0; i < selectedURIs.length; i++)
       gMsgCompose.quoteMessage(selectedURIs[i]);
 }
 
--- a/mail/components/compose/content/messengercompose.xul
+++ b/mail/components/compose/content/messengercompose.xul
@@ -92,17 +92,17 @@
 
   <commandset id="commonEditorMenuItems"/>
   <commandset id="composerMenuItems"/>
   <commandset id="composerEditMenuItems"/> 
   <commandset id="composerStyleMenuItems"/>
   <commandset id="composerTableMenuItems"/>
   <commandset id="composerListMenuItems"/>
   <!-- File Menu -->
-  <command id="cmd_new" oncommand="goDoCommand('cmd_newMessage')"/>
+  <command id="cmd_newMessage" oncommand="goDoCommand('cmd_newMessage')"/>
   <command id="cmd_attachFile" oncommand="goDoCommand('cmd_attachFile')"/>
   <command id="cmd_attachCloud" oncommand="attachToCloud(event.target.cloudProvider); event.stopPropagation();"/>
   <command id="cmd_attachPage" oncommand="goDoCommand('cmd_attachPage')"/>
   <command id="cmd_attachVCard" checked="false" oncommand="ToggleAttachVCard(event.target)"/>
   <command id="cmd_close" oncommand="goDoCommand('cmd_close')"/>
   <command id="cmd_saveDefault" oncommand="goDoCommand('cmd_saveDefault')"/>
   <command id="cmd_saveAsFile" oncommand="goDoCommand('cmd_saveAsFile')"/>
   <command id="cmd_saveAsDraft" oncommand="goDoCommand('cmd_saveAsDraft')"/>
@@ -156,21 +156,21 @@
 <broadcasterset id="composeBroadcasters">
   <broadcaster id="args" value="editorType=default"/>
   <broadcaster id="viewAddressPicker" autoCheck="false" type="checkbox" oncommand="toggleAddressPicker();"/>
 </broadcasterset>
 
 <keyset id="tasksKeys">
   <!-- File Menu -->
 #ifdef XP_MACOSX
-  <key id="key_newMessage" key="&newMessage.key;" oncommand="goOpenNewMessage();" modifiers="accel,shift"/>
-  <key id="key_newMessage2" key="&newMessageCmd2.key;" oncommand="goOpenNewMessage();" modifiers="accel"/>
+  <key id="key_newMessage" key="&newMessage.key;" command="cmd_newMessage" modifiers="accel,shift"/>
+  <key id="key_newMessage2" key="&newMessageCmd2.key;" command="cmd_newMessage" modifiers="accel"/>
 #else
-  <key id="key_newMessage" key="&newMessage.key;" oncommand="goOpenNewMessage();" modifiers="accel"/>
-  <key id="key_newMessage2" key="&newMessageCmd2.key;" oncommand="goOpenNewMessage();" modifiers="accel"/>
+  <key id="key_newMessage" key="&newMessage.key;" command="cmd_newMessage" modifiers="accel"/>
+  <key id="key_newMessage2" key="&newMessageCmd2.key;" command="cmd_newMessage" modifiers="accel"/>
 #endif
   <key id="key_attachFile" key="&attachFileCmd.key;" command="cmd_attachFile"
        modifiers="accel,shift"/>
   <key id="key_close" key="&closeCmd.key;" command="cmd_close"  modifiers="accel"/>
   <key id="key_save" key="&saveCmd.key;" command="cmd_saveDefault" modifiers="accel"/>
   <key id="key_send" keycode="&sendCmd.keycode;" observes="cmd_sendWithCheck" modifiers="accel"/>
   <key id="key_sendLater" keycode="&sendLaterCmd.keycode;" observes="cmd_sendLater" modifiers="accel, shift"/>
   <key id="key_print" key="&printCmd.key;" command="cmd_print" modifiers="accel"/>
@@ -379,17 +379,17 @@
      <toolbaritem id="menubar-items" align="center">
       <menubar id="mail-menubar" style="border:0px;padding:0px;margin:0px;-moz-appearance:none">
       <menu id="menu_File" label="&fileMenu.label;" accesskey="&fileMenu.accesskey;">
         <menupopup id="menu_FilePopup">
           <menu id="menu_New" label="&newMenu.label;" accesskey="&newMenu.accesskey;">
             <menupopup id="menu_NewPopup">
               <menuitem id="menu_NewMessage"
                         label="&newMessage.label;" accesskey="&newMessage.accesskey;"
-                        key="key_newMessage2" oncommand="goOpenNewMessage();"/>
+                        key="key_newMessage2" command="cmd_newMessage"/>
               <menuseparator/>
               <menuitem id="menu_NewContact" label="&newContact.label;"
                         accesskey="&newContact.accesskey;"
                         oncommand="window.openDialog('chrome://messenger/content/addressbook/abNewCardDialog.xul', '', 'chrome,modal,resizable=no,centerscreen');"/>
             </menupopup>
           </menu>
           <menu id="menu_Attach" label="&attachMenu.label;" accesskey="&attachMenu.accesskey;">
             <menupopup id="menu_AttachPopup" onpopupshowing="updateAttachmentItems();">
--- a/mail/components/im/content/chat-messenger-overlay.js
+++ b/mail/components/im/content/chat-messenger-overlay.js
@@ -688,21 +688,16 @@ var chatHandler = {
       connected || !hasAccount;
     if (connected) {
       delete this._placeHolderButtonId;
     }
     else {
       this._placeHolderButtonId =
         hasAccount ? "openIMAccountManagerButton" : "openIMAccountWizardButton";
     }
-    for each (let id in ["button-add-buddy", "newIMContactMenuItem"]) {
-      let elt = document.getElementById(id);
-      if (elt)
-        elt.disabled = !connected;
-    }
     for each (let id in ["button-join-chat", "joinChatMenuItem"]) {
       let elt = document.getElementById(id);
       if (elt)
         elt.disabled = !canJoinChat;
     }
     let groupIds = ["conversations", "onlinecontacts", "offlinecontacts"];
     let contactlist = document.getElementById("contactlistbox");
     if (!hasAccount || !connected && groupIds.every(function(id)
--- a/mail/components/im/content/chat-messenger-overlay.xul
+++ b/mail/components/im/content/chat-messenger-overlay.xul
@@ -108,17 +108,17 @@
                  iconsize="small"
 #endif
                  defaultset="button-add-buddy,button-join-chat,spacer,chat-status-selector,button-chat-accounts,spacer,gloda-im-search"/>
 
         <toolbarpalette id="ChatToolbarPalette">
           <toolbarbutton id="button-add-buddy"
                          class="toolbarbutton-1"
                          label="&addBuddyButton.label;"
-                         oncommand="chatHandler.addBuddy()"/>
+                         command="cmd_newIMContact"/>
           <toolbarbutton id="button-join-chat"
                          class="toolbarbutton-1"
                          label="&joinChatButton.label;"
                          oncommand="chatHandler.joinChat()"/>
           <toolbaritem id="chat-status-selector"
                        orient="horizontal"
                        class="toolbarbutton-1"
                        align="center" flex="1">