Backout changeset 25f87dd2453f due to test bustage in test-attachment.js
authorJim Porter <squibblyflabbetydoo@gmail.com>
Sun, 15 Jan 2012 13:48:54 -0600
changeset 10426 74aaf5c6fa4840a652ce0097399756e70f168388
parent 10425 8bdd5d2f7ecef0f21f583a9307ba0ec9be90dfb6
child 10427 322e170393850091a447b93cd34f5a8603437783
push id402
push userbugzilla@standard8.plus.com
push dateTue, 13 Mar 2012 21:17:18 +0000
treeherdercomm-beta@d080a8ebf16a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
backs out25f87dd2453f478a05b64e21e4d24cf5f1efc5b3
Backout changeset 25f87dd2453f due to test bustage in test-attachment.js
mail/components/compose/content/MsgComposeCommands.js
mail/components/compose/content/messengercompose.xul
mail/locales/en-US/chrome/messenger/messengercompose/messengercompose.dtd
--- a/mail/components/compose/content/MsgComposeCommands.js
+++ b/mail/components/compose/content/MsgComposeCommands.js
@@ -416,276 +416,179 @@ var progressListener = {
           iid.equals(Components.interfaces.nsISupportsWeakReference) ||
           iid.equals(Components.interfaces.nsISupports))
         return this;
 
       throw Components.results.NS_NOINTERFACE;
     }
 };
 
-var defaultController = {
-  commands: {
-    cmd_attachFile: {
-      isEnabled: function() {
-        return !gWindowLocked;
-      },
-      doCommand: function() {
-        AttachFile();
-      }
-    },
-
-    cmd_attachPage: {
-      isEnabled: function() {
-        return !gWindowLocked;
-      },
-      doCommand: function() {
-        AttachPage();
-      }
-    },
-
-    cmd_close: {
-      isEnabled: function() {
-        return !gWindowLocked;
-      },
-      doCommand: function() {
-        DoCommandClose();
-      }
-    },
-
-    cmd_saveDefault: {
-      isEnabled: function() {
-        return !gWindowLocked;
-      },
-      doCommand: function() {
-        Save();
-      }
-    },
-
-    cmd_saveAsFile: {
-      isEnabled: function() {
-        return !gWindowLocked;
-      },
-      doCommand: function() {
-        SaveAsFile(true);
-      }
-    },
-
-    cmd_saveAsDraft: {
-      isEnabled: function() {
-        return !gWindowLocked;
-      },
-      doCommand: function() {
-        SaveAsDraft();
-      }
-    },
-
-    cmd_saveAsTemplate: {
-      isEnabled: function() {
+var defaultController =
+{
+  supportsCommand: function(command)
+  {
+    switch (command)
+    {
+      //File Menu
+      case "cmd_attachFile":
+      case "cmd_attachPage":
+      case "cmd_close":
+      case "cmd_saveDefault":
+      case "cmd_saveAsFile":
+      case "cmd_saveAsDraft":
+      case "cmd_saveAsTemplate":
+      case "cmd_sendButton":
+      case "cmd_sendNow":
+      case "cmd_sendWithCheck":
+      case "cmd_sendLater":
+      case "cmd_printSetup":
+      case "cmd_print":
+      case "cmd_quit":
+
+      //Edit Menu
+      case "cmd_delete":
+      case "cmd_renameAttachment":
+      case "cmd_selectAll":
+      case "cmd_openAttachment":
+      case "cmd_account":
+
+      //View Menu
+      case "cmd_showFormatToolbar":
+
+      //Options Menu
+      case "cmd_outputFormat":
+      case "cmd_quoteMessage":
+        return true;
+
+      default:
+//        dump("##MsgCompose: command " + command + "no supported!\n");
+        return false;
+    }
+  },
+  isCommandEnabled: function(command)
+  {
+    var composeHTML = gMsgCompose && gMsgCompose.composeHTML;
+
+    switch (command)
+    {
+      //File Menu
+      case "cmd_attachFile":
+      case "cmd_attachPage":
+      case "cmd_close":
+      case "cmd_saveDefault":
+      case "cmd_saveAsFile":
+      case "cmd_saveAsDraft":
+      case "cmd_saveAsTemplate":
+      case "cmd_sendButton":
+      case "cmd_sendLater":
+      case "cmd_printSetup":
+      case "cmd_print":
+      case "cmd_sendWithCheck":
         return !gWindowLocked;
-      },
-      doCommand: function() {
-        SaveAsTemplate();
-      }
-    },
-
-    cmd_sendButton: {
-      isEnabled: function() {
-        return !gWindowLocked;
-      },
-      doCommand: function() {
-        if (gIOService && gIOService.offline)
-          SendMessageLater();
-        else
-          SendMessage();
-      }
-    },
-
-    cmd_sendNow: {
-      isEnabled: function() {
-        return !gWindowLocked && !gIsOffline;
-      },
-      doCommand: function() {
-        SendMessage();
-      }
-    },
-
-    cmd_sendLater: {
-      isEnabled: function() {
-        return !gWindowLocked;
-      },
-      doCommand: function() {
-        SendMessageLater();
-      }
-    },
-
-    cmd_sendWithCheck: {
-      isEnabled: function() {
-        return !gWindowLocked;
-      },
-      doCommand: function() {
-        SendMessageWithCheck();
-      }
-    },
-
-    cmd_printSetup: {
-      isEnabled: function() {
-        return !gWindowLocked;
-      },
-      doCommand: function() {
-        PrintUtils.showPageSetup();
-      }
-    },
-
-    cmd_print: {
-      isEnabled: function() {
-        return !gWindowLocked;
-      },
-      doCommand: function() {
-        DoCommandPrint();
-      }
-    },
-
-    cmd_delete: {
-      isEnabled: function() {
-        let cmdDelete = document.getElementById("cmd_delete");
-        let textValue = cmdDelete.getAttribute("valueDefault");
-        let accesskeyValue = cmdDelete.getAttribute("valueDefaultAccessKey");
+      case "cmd_sendNow":
+        return !(gWindowLocked || gIsOffline);
+      case "cmd_quit":
+        return true;
+
+      //Edit Menu
+      case "cmd_delete":
+        var numSelectedAttachments = MessageGetNumSelectedAttachments();
+
+        var cmdDelete = document.getElementById("cmd_delete");
+        var textValue = cmdDelete.getAttribute("valueDefault");
+        var accesskeyValue = cmdDelete.getAttribute("valueDefaultAccessKey");
+
+        var hasAttachments = MessageHasAttachments();
+        if (hasAttachments) {
+          textValue = getComposeBundle().getString("removeAttachmentMsgs");
+          textValue = PluralForm.get(numSelectedAttachments, textValue);
+          accesskeyValue = cmdDelete.getAttribute("valueRemoveAttachmentAccessKey");
+        }
 
         cmdDelete.setAttribute("label", textValue);
         cmdDelete.setAttribute("accesskey", accesskeyValue);
 
+        return hasAttachments ? numSelectedAttachments : 0;
+      case "cmd_selectAll":
+        return MessageHasAttachments();
+      case "cmd_openAttachment":
+        return MessageGetNumSelectedAttachments() == 1;
+      case "cmd_renameAttachment":
+        return MessageGetNumSelectedAttachments() == 1;
+      case "cmd_account":
+
+      //View Menu
+      case "cmd_showFormatToolbar":
+        return composeHTML;
+
+      //Options Menu
+      case "cmd_outputFormat":
+        return composeHTML;
+      case "cmd_quoteMessage":
+        var selectedURIs = GetSelectedMessages();
+        if (selectedURIs && selectedURIs.length > 0)
+          return true;
         return false;
-      },
-      doCommand: function() {
-      }
-    },
-
-    cmd_account: {
-      isEnabled: function() {
-        return true;
-      },
-      doCommand: function() {
-        MsgAccountManager(null);
-      }
-    },
-
-    cmd_showFormatToolbar: {
-      isEnabled: function() {
-        return gMsgCompose && gMsgCompose.composeHTML;
-      },
-      doCommand: function() {
-        goToggleToolbar("FormatToolbar", "menu_showFormatToolbar");
-      }
-    },
-
-    cmd_quoteMessage: {
-      isEnabled: function() {
-        let selectedURIs = GetSelectedMessages();
-        return (selectedURIs && selectedURIs.length > 0)
-      },
-      doCommand: function() {
-        QuoteSelectedMessage();
-      }
-    },
-  },
-
-  supportsCommand: function(aCommand) {
-    return (aCommand in this.commands);
-  },
-
-  isCommandEnabled: function(aCommand) {
-    if (!this.supportsCommand(aCommand))
-      return false;
-    return this.commands[aCommand].isEnabled();
-  },
-
-  doCommand: function(aCommand) {
-    if (!this.supportsCommand(aCommand))
-      return;
-    var cmd = this.commands[aCommand];
-    if (!cmd.isEnabled())
-      return;
-    cmd.doCommand();
+
+      default:
+//        dump("##MsgCompose: command " + command + " disabled!\n");
+        return false;
+    }
   },
 
-  onEvent: function(event) {},
-};
-
-var attachmentBucketController = {
-  commands: {
-    cmd_selectAll: {
-      isEnabled: function() {
-        return true;
-      },
-      doCommand: function() {
-        document.getElementById("attachmentBucket").selectAll();
-      }
-    },
-
-    cmd_delete: {
-      isEnabled: function() {
-        let selectedCount = MessageGetNumSelectedAttachments();
-        if (selectedCount > 0) {
-          let cmdDelete = document.getElementById("cmd_delete");
-          let textValue = getComposeBundle().getString("removeAttachmentMsgs");
-          textValue = PluralForm.get(selectedCount, textValue);
-          let accesskeyValue = cmdDelete.getAttribute("valueRemoveAttachmentAccessKey");
-          cmdDelete.setAttribute("label", textValue);
-          cmdDelete.setAttribute("accesskey", accesskeyValue);
-
-          return true;
+  doCommand: function(command)
+  {
+    switch (command)
+    {
+      //File Menu
+      case "cmd_attachFile"         : if (defaultController.isCommandEnabled(command)) AttachFile();           break;
+      case "cmd_attachPage"         : AttachPage();           break;
+      case "cmd_close"              : DoCommandClose();       break;
+      case "cmd_saveDefault"        : Save();                 break;
+      case "cmd_saveAsFile"         : SaveAsFile(true);       break;
+      case "cmd_saveAsDraft"        : SaveAsDraft();          break;
+      case "cmd_saveAsTemplate"     : SaveAsTemplate();       break;
+      case "cmd_sendButton"         :
+        if (defaultController.isCommandEnabled(command))
+        {
+          if (gIOService && gIOService.offline)
+            SendMessageLater();
+          else
+            SendMessage();
         }
-
-        return false;
-      },
-      doCommand: function() {
-        RemoveSelectedAttachment();
-      }
-    },
-
-    cmd_openAttachment: {
-      isEnabled: function() {
-        return MessageGetNumSelectedAttachments() == 1;
-      },
-      doCommand: function() {
-        OpenSelectedAttachment();
-      }
-    },
-
-    cmd_renameAttachment: {
-      isEnabled: function() {
-        return MessageGetNumSelectedAttachments() == 1;
-      },
-      doCommand: function() {
-        RenameSelectedAttachment();
-      }
-    },
+        break;
+      case "cmd_sendNow"            : if (defaultController.isCommandEnabled(command)) SendMessage();          break;
+      case "cmd_sendWithCheck"   : if (defaultController.isCommandEnabled(command)) SendMessageWithCheck();          break;
+      case "cmd_sendLater"          : if (defaultController.isCommandEnabled(command)) SendMessageLater();     break;
+      case "cmd_printSetup"         : PrintUtils.showPageSetup(); break;
+      case "cmd_print"              : DoCommandPrint(); break;
+
+      //Edit Menu
+      case "cmd_delete"             : if (MessageGetNumSelectedAttachments()) RemoveSelectedAttachment();         break;
+      case "cmd_renameAttachment"   : if (MessageGetNumSelectedAttachments() == 1) RenameSelectedAttachment(); break;
+      case "cmd_selectAll"          : if (MessageHasAttachments()) SelectAllAttachments();                     break;
+      case "cmd_openAttachment"     : if (MessageGetNumSelectedAttachments() == 1) OpenSelectedAttachment();          break;
+      case "cmd_account"            : MsgAccountManager(null); break;
+
+      //View Menu
+      case "cmd_showFormatToolbar"  : goToggleToolbar('FormatToolbar', 'menu_showFormatToolbar');   break;
+
+      //Options Menu
+      case "cmd_quoteMessage"       : if (defaultController.isCommandEnabled(command)) QuoteSelectedMessage();  break;
+      default:
+//        dump("##MsgCompose: don't know what to do with command " + command + "!\n");
+        return;
+    }
   },
 
-  supportsCommand: function(aCommand) {
-    return (aCommand in this.commands);
-  },
-
-  isCommandEnabled: function(aCommand) {
-    if (!this.supportsCommand(aCommand))
-      return false;
-    return this.commands[aCommand].isEnabled();
-  },
-
-  doCommand: function(aCommand) {
-    if (!this.supportsCommand(aCommand))
-      return;
-    var cmd = this.commands[aCommand];
-    if (!cmd.isEnabled())
-      return;
-    cmd.doCommand();
-  },
-
-  onEvent: function(event) {},
-};
+  onEvent: function(event)
+  {
+//    dump("DefaultController:onEvent\n");
+  }
+}
 
 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) {
@@ -720,33 +623,27 @@ function GetSelectedMessages()
     }
   }
 
   return null;
 }
 
 function SetupCommandUpdateHandlers()
 {
-  let attachmentBucket = document.getElementById("attachmentBucket");
-
-  top.controllers.appendController(defaultController);
-  attachmentBucket.controllers.appendController(attachmentBucketController);
+  top.controllers.insertControllerAt(0, defaultController);
 
   document.getElementById("optionsMenuPopup")
           .addEventListener("popupshowing", updateOptionItems, true);
 }
 
 function UnloadCommandUpdateHandlers()
 {
-  let attachmentBucket = document.getElementById("attachmentBucket");
-
   document.getElementById("optionsMenuPopup")
           .removeEventListener("popupshowing", updateOptionItems, true);
 
-  attachmentBucket.controllers.removeController(attachmentBucketController);
   top.controllers.removeController(defaultController);
 }
 
 function CommandUpdate_MsgCompose()
 {
   var focusedWindow = top.document.commandDispatcher.focusedWindow;
 
   // we're just setting focus to where it was before
@@ -3109,16 +3006,32 @@ function AddFileAttachment(file)
  *
  * @param attachment the nsIMsgAttachment object to add as attachment
  */
 function AddUrlAttachment(attachment)
 {
   AddAttachments([attachment]);
 }
 
+function SelectAllAttachments()
+{
+  var bucketList = document.getElementById("attachmentBucket");
+  if (bucketList)
+    bucketList.selectAll();
+}
+
+function MessageHasAttachments()
+{
+  var bucketList = document.getElementById("attachmentBucket");
+  if (bucketList) {
+    return (bucketList && bucketList.getRowCount() && (bucketList == top.document.commandDispatcher.focusedElement));
+  }
+  return false;
+}
+
 function MessageGetNumSelectedAttachments()
 {
   var bucketList = document.getElementById("attachmentBucket");
   return (bucketList) ? bucketList.selectedItems.length : 0;
 }
 
 function AttachPage()
 {
--- a/mail/components/compose/content/messengercompose.xul
+++ b/mail/components/compose/content/messengercompose.xul
@@ -152,19 +152,19 @@
   <!--command id="cmd_findNext"/-->
   <command id="cmd_undo" oncommand="goDoCommand('cmd_undo')" disabled="true"/>
   <command id="cmd_redo" oncommand="goDoCommand('cmd_redo')" disabled="true"/>
   <command id="cmd_cut" oncommand="goDoCommand('cmd_cut')" disabled="true"/>
   <command id="cmd_copy" oncommand="goDoCommand('cmd_copy')" disabled="true"/>
   <command id="cmd_paste" oncommand="goDoCommand('cmd_paste')" disabled="true"/>
   <command id="cmd_rewrap" oncommand="goDoCommand('cmd_rewrap')"/>
   <command id="cmd_delete" oncommand="goDoCommand('cmd_delete')" valueDefault="&deleteCmd.label;" valueDefaultAccessKey="&deleteCmd.accesskey;" valueRemoveAttachmentAccessKey="&removeAttachment.accesskey;" disabled="true"/>
+  <command id="cmd_renameAttachment" oncommand="goDoCommand('cmd_renameAttachment')" disabled="true"/>
   <command id="cmd_selectAll" oncommand="goDoCommand('cmd_selectAll')" disabled="true"/>
-  <command id="cmd_openAttachment" oncommand="goDoCommand('cmd_openAttachment')" disabled="true"/>
-  <command id="cmd_renameAttachment" oncommand="goDoCommand('cmd_renameAttachment')" disabled="true"/>
+  <command id="cmd_openAttachment" oncommand="goDoCommand('cmd_openAttachment')" disabled="true"/>  
   <command id="cmd_account" oncommand="goDoCommand('cmd_account')"/>
 
   <!-- View Menu -->
   <command id="cmd_showFormatToolbar" oncommand="goDoCommand('cmd_showFormatToolbar')"/>
 
   <!-- Options Menu -->
   <command id="cmd_quoteMessage" oncommand="goDoCommand('cmd_quoteMessage')"/>
   <command id="cmd_insert"/>
@@ -217,21 +217,20 @@
   <key id="key_copy" key="&copyCmd.key;" modifiers="accel"/>
   <key id="key_paste" key="&pasteCmd.key;" modifiers="accel"/>
   <key id="pastequotationkb" key="&pasteAsQuotationCmd.key;"
        observes="cmd_pasteQuote" modifiers="accel, shift"/>
   <key id="pastenoformattingkb" key="&pasteNoFormattingCmd.key;"
        modifiers="accel, shift" observes="cmd_pasteNoFormatting"/>
   <key id="key_rewrap" key="&editRewrapCmd.key;" command="cmd_rewrap" modifiers="accel"/>
 #ifdef XP_MACOSX
-  <key id="key_delete" keycode="VK_BACK" command="cmd_delete"/>
-  <key id="key_delete2" keycode="VK_DELETE" command="cmd_delete"/>
+  <key id="key_delete" keycode="VK_BACK"/>
+  <key id="key_delete2" keycode="VK_DELETE"/>
 #else
-  <key id="key_delete" keycode="VK_DELETE" command="cmd_delete"/>
-  <key id="key_renameAttachment" keycode="VK_F2" oncommand="goDoCommand('cmd_renameAttachment');"/>
+  <key id="key_delete" keycode="VK_DELETE"/>
 #endif
   <key id="key_selectAll" key="&selectAllCmd.key;" modifiers="accel"/>
   <key id="key_find" key="&findCmd.key;" command="cmd_find" modifiers="accel"/>
   <key id="key_findNext" key="&findAgainCmd.key;" command="cmd_findNext" modifiers="accel"/>
   <key id="key_findPrev" key="&findPrevCmd.key;" command="cmd_findPrev" modifiers="accel, shift"/>
   <key keycode="&findAgainCmd.key2;" command="cmd_findNext"/>
   <key keycode="&findPrevCmd.key2;"  command="cmd_findPrev" modifiers="shift"/>
 
@@ -441,23 +440,19 @@
           <menuitem id="menu_redo" label="&redoCmd.label;" key="key_redo" accesskey="&redoCmd.accesskey;" command="cmd_redo"/>
           <menuseparator/>
           <menuitem id="menu_cut" label="&cutCmd.label;" key="key_cut" accesskey="&cutCmd.accesskey;" command="cmd_cut"/>
           <menuitem id="menu_copy" label="&copyCmd.label;" key="key_copy" accesskey="&copyCmd.accesskey;" command="cmd_copy"/>
           <menuitem id="menu_paste" label="&pasteCmd.label;" key="key_paste" accesskey="&pasteCmd.accesskey;" command="cmd_paste"/>
           <menuitem id="menu_pasteNoFormatting" command="cmd_pasteNoFormatting"
                     key="pastenoformattingkb"/>
           <menuitem id="menu_pasteQuote"/>
+          <menuitem id="menu_rewrap" label="&editRewrapCmd.label;" key="key_rewrap" accesskey="&editRewrapCmd.accesskey;" command="cmd_rewrap"/>
           <menuitem id="menu_delete" label="&deleteCmd.label;" key="key_delete" accesskey="&deleteCmd.accesskey;" command="cmd_delete"/>
           <menuseparator/>
-          <menuitem id="menu_rewrap" label="&editRewrapCmd.label;" key="key_rewrap" accesskey="&editRewrapCmd.accesskey;" command="cmd_rewrap"/>
-          <menuitem id="menu_RenameAttachment" label="&renameAttachment.label;"
-                    accesskey="&renameAttachment.accesskey;"
-                    key="key_renameAttachment" command="cmd_renameAttachment"/>
-          <menuseparator/>
           <menuitem id="menu_selectAll" label="&selectAllCmd.label;" key="key_selectAll" accesskey="&selectAllCmd.accesskey;" command="cmd_selectAll"/>
           <menuseparator/>
           <menuitem label="&findCmd.label;"      key="key_find"      accesskey="&findCmd.accesskey;"      command="cmd_find"/>
           <menuitem label="&findAgainCmd.label;" key="key_findNext" accesskey="&findAgainCmd.accesskey;" command="cmd_findNext"/>
           <menuitem label="&findPrevCmd.label;"  key="key_findPrev" accesskey="&findPrevCmd.accesskey;"  command="cmd_findPrev"/>
 #ifdef XP_UNIX
 #ifndef XP_MACOSX
           <menuseparator id="prefSep"/>
@@ -790,16 +785,17 @@
             <label id="attachmentBucketCount" control="attachmentBucket"
                    crop="right" accesskey="&attachments.accesskey;"/>
             <label id="attachmentBucketSize"/>
           </hbox>
           <attachmentlist orient="vertical" id="attachmentBucket"
                           seltype="multiple" flex="1" height="0"
                           context="msgComposeAttachmentListContext"
                           itemcontext="msgComposeAttachmentItemContext"
+                          onkeypress="if (event.keyCode == 8 || event.keyCode == 46) RemoveSelectedAttachment();"
                           onclick="AttachmentBucketClicked(event);"
                           ondraggesture="nsDragAndDrop.startDrag(event, attachmentBucketDNDObserver);"/>
         </vbox>
       </hbox>
     </toolbar>
   </toolbox>
 
   <splitter id="compose-toolbar-sizer" onmousedown="awSizerListen()"/>
--- a/mail/locales/en-US/chrome/messenger/messengercompose/messengercompose.dtd
+++ b/mail/locales/en-US/chrome/messenger/messengercompose/messengercompose.dtd
@@ -63,23 +63,21 @@
 <!ENTITY copyCmd.label "Copy">
 <!ENTITY copyCmd.key "C">
 <!ENTITY copyCmd.accesskey "c"> 
 <!ENTITY pasteCmd.label "Paste">
 <!ENTITY pasteCmd.key "V">
 <!ENTITY pasteCmd.accesskey "p">
 <!ENTITY pasteNoFormattingCmd.key "V">
 <!ENTITY pasteAsQuotationCmd.key "o">
+<!ENTITY editRewrapCmd.label "Rewrap">
+<!ENTITY editRewrapCmd.key "R">
 <!ENTITY editRewrapCmd.accesskey "w">
 <!ENTITY deleteCmd.label "Delete">
 <!ENTITY deleteCmd.accesskey "d">
-<!ENTITY editRewrapCmd.label "Rewrap">
-<!ENTITY editRewrapCmd.key "R">
-<!ENTITY renameAttachment.label "Rename Attachment…">
-<!ENTITY renameAttachment.accesskey "e">
 <!ENTITY selectAllCmd.label "Select All">
 <!ENTITY selectAllCmd.key "A">
 <!ENTITY selectAllCmd.accesskey "a"> 
 <!ENTITY findCmd.label "Find and Replace…">
 <!ENTITY findCmd.key "F">
 <!ENTITY findCmd.accesskey "F">
 <!ENTITY findAgainCmd.label "Find Again">
 <!ENTITY findAgainCmd.key "G">