Bug 702201 - Clicking the "Delete" toolbar button with an attachment focused should delete the message, not the attachment; r=bwinton, ui-r=bwinton, a=Standard8
authorJim Porter <squibblyflabbetydoo@gmail.com>
Fri, 18 Nov 2011 01:43:40 -0600
changeset 9694 a5b1789406ad6ae9f8af8683d8eb441f62e9b715
parent 9693 91945160ae4f5fc36c89989fb0fa5a3cf29ca9b3
child 9695 7006d9f54b82df76c0a3403e0e6d6f88355ac4e9
push id281
push userbugzilla@standard8.plus.com
push dateWed, 21 Dec 2011 12:08:36 +0000
treeherdercomm-beta@6d973fa5c2e8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbwinton, bwinton, Standard8
bugs702201
Bug 702201 - Clicking the "Delete" toolbar button with an attachment focused should delete the message, not the attachment; r=bwinton, ui-r=bwinton, a=Standard8
mail/base/content/mail3PaneWindowCommands.js
mail/base/content/mailWindowOverlay.xul
mail/base/content/messageWindow.js
mail/base/content/msgHdrViewOverlay.js
mail/base/content/msgHdrViewOverlay.xul
mail/test/mozmill/attachment/test-attachment.js
--- a/mail/base/content/mail3PaneWindowCommands.js
+++ b/mail/base/content/mail3PaneWindowCommands.js
@@ -43,16 +43,17 @@ var FolderPaneController =
 {
   supportsCommand: function(command)
   {
     switch ( command )
     {
       case "cmd_delete":
       case "cmd_shiftDelete":
       case "button_delete":
+      case "button_shiftDelete":
         // Even if the folder pane has focus, don't do a folder delete if
         // we have a selected message, but do a message delete instead.
         // Return false here supportsCommand and let the command fall back
         // to the DefaultController.
         if (GetNumSelectedMessages() != 0)
           return false;
         // else fall through
       case "cmd_cut":
@@ -71,16 +72,17 @@ var FolderPaneController =
     {
       case "cmd_cut":
       case "cmd_copy":
       case "cmd_paste":
         return false;
       case "cmd_delete":
       case "cmd_shiftDelete":
       case "button_delete":
+      case "button_shiftDelete":
       {
         // Make sure the button doesn't show "Undelete" for folders.
         UpdateDeleteToolbarButton();
         let folders = gFolderTreeView.getSelectedFolders();
         if (folders.length) {
           // XXX Figure out some better way/place to update the folder labels.
           UpdateDeleteLabelsFromFolderCommand(folders[0], command);
           return CanDeleteFolder(folders[0]) && folders[0].isCommandEnabled(command);
@@ -99,16 +101,17 @@ var FolderPaneController =
     // really disabled. kick out if the command should be disabled.
     if (!this.isCommandEnabled(command)) return;
 
     switch ( command )
     {
       case "cmd_delete":
       case "cmd_shiftDelete":
       case "button_delete":
+      case "button_shiftDelete":
       case "cmd_deleteFolder":
         gFolderTreeController.deleteFolder();
         break;
     }
   },
 
   onEvent: function(event)
   {
@@ -153,16 +156,17 @@ var DefaultController =
       case "cmd_forwardAttachment":
       case "cmd_editAsNew":
       case "cmd_createFilterFromMenu":
       case "cmd_delete":
       case "cmd_deleteFolder":
       case "button_delete":
       case "button_junk":
       case "cmd_shiftDelete":
+      case "button_shiftDelete":
       case "cmd_nextMsg":
       case "button_next":
       case "button_previous":
       case "cmd_nextUnreadMsg":
       case "cmd_nextFlaggedMsg":
       case "cmd_nextUnreadThread":
       case "cmd_previousMsg":
       case "cmd_previousUnreadMsg":
@@ -279,16 +283,17 @@ var DefaultController =
     {
       case "cmd_delete":
         UpdateDeleteCommand();
         // fall through
       case "button_delete":
         UpdateDeleteToolbarButton();
         return gFolderDisplay.getCommandStatus(nsMsgViewCommandType.deleteMsg);
       case "cmd_shiftDelete":
+      case "button_shiftDelete":
         return gFolderDisplay.getCommandStatus(nsMsgViewCommandType.deleteNoTrash);
       case "cmd_cancel": {
         let selectedMessages = gFolderDisplay.selectedMessages;
         return selectedMessages.length == 1 && selectedMessages[0].folder &&
                selectedMessages[0].folder.server.type == "nntp";
       }
       case "cmd_deleteFolder":
         var folders = gFolderTreeView.getSelectedFolders();
@@ -650,16 +655,17 @@ var DefaultController =
           gFolderDisplay.hintAboutToDeleteMessages();
         gFolderDisplay.doCommand(nsMsgViewCommandType.deleteMsg);
         break;
       case "cmd_cancel":
         let message = gFolderDisplay.selectedMessages[0];
         message.folder.QueryInterface(Components.interfaces.nsIMsgNewsFolder)
                       .cancelMessage(message, msgWindow);
         break;
+      case "button_shiftDelete":
       case "cmd_shiftDelete":
         MarkSelectedMessagesRead(true);
         gFolderDisplay.hintAboutToDeleteMessages();
         gFolderDisplay.doCommand(nsMsgViewCommandType.deleteNoTrash);
         break;
       case "cmd_deleteFolder":
         gFolderTreeController.deleteFolder();
         break;
--- a/mail/base/content/mailWindowOverlay.xul
+++ b/mail/base/content/mailWindowOverlay.xul
@@ -1824,23 +1824,23 @@
     </toolbaritem>
     <toolbaritem id="button-delete" title="&deleteItem.title;">
       <deck id="delete-deck" observes="button_delete">
          <toolbarbutton id="button-mark-deleted"
                         class="toolbarbutton-1 delete-button"
                         label="&deleteButton.label;"
                         tooltiptext="&deleteButton.tooltip;"
                         observes="button_delete"
-                        oncommand="goDoCommand(event.shiftKey ? 'cmd_shiftDelete' : 'cmd_delete')"/>
+                        oncommand="goDoCommand(event.shiftKey ? 'button_shiftDelete' : 'button_delete')"/>
          <toolbarbutton id="button-mark-undelete"
                         class="toolbarbutton-1 delete-button"
                         label="&undeleteButton.label;"
                         tooltiptext="&undeleteButton.tooltip;"
                         observes="button_delete"
-                        oncommand="goDoCommand('cmd_delete')"/>
+                        oncommand="goDoCommand('button_delete')"/>
       </deck>
     </toolbaritem>
 #ifdef XP_MACOSX
     <toolbarbutton id="button-print"
                    class="toolbarbutton-1"
                    label="&printButton.label;"
                    observes="button_print"
                    oncommand="goDoCommand('cmd_print')"
--- a/mail/base/content/messageWindow.js
+++ b/mail/base/content/messageWindow.js
@@ -676,46 +676,32 @@ function ReloadMessage()
   // If the current message was loaded from a file or attachment, so the dbView
   // can't handle reloading it. Let's do it ourselves, instead.
   if (window.arguments[0] instanceof Components.interfaces.nsIURI)
     gMessageDisplay.displayExternalMessage(window.arguments[0].spec);
   else
     gFolderDisplay.view.dbView.reloadMessage();
 }
 
-function MsgDeleteMessageFromMessageWindow(reallyDelete, fromToolbar)
-{
-  // if from the toolbar, return right away if this is a news message
-  // only allow cancel from the menu:  "Edit | Cancel / Delete Message"
-  if (fromToolbar && gFolderDisplay.view.isNewsFolder)
-      return;
-
-  gFolderDisplay.hintAboutToDeleteMessages();
-
-  if (reallyDelete)
-    gFolderDisplay.doCommand(nsMsgViewCommandType.deleteNoTrash);
-  else
-    gFolderDisplay.doCommand(nsMsgViewCommandType.deleteMsg);
-}
-
 // MessageWindowController object (handles commands when one of the trees does not have focus)
 var MessageWindowController =
 {
    supportsCommand: function(command)
   {
     switch ( command )
     {
       // external messages cannot be deleted, mutated, or subjected to filtering
       case "cmd_delete":
       case "cmd_killThread":
       case "cmd_killSubthread":
       case "cmd_watchThread":
       case "button_delete":
       case "button_junk":
       case "cmd_shiftDelete":
+      case "button_shiftDelete":
       case "cmd_tag":
       case "cmd_removeTags":
       case "cmd_tag1":
       case "cmd_tag2":
       case "cmd_tag3":
       case "cmd_tag4":
       case "cmd_tag5":
       case "cmd_tag6":
@@ -820,16 +806,17 @@ var MessageWindowController =
           return false;
       case "cmd_delete":
         UpdateDeleteCommand();
         // fall through
       case "button_delete":
         UpdateDeleteToolbarButton();
         return gFolderDisplay.getCommandStatus(nsMsgViewCommandType.deleteMsg);
       case "cmd_shiftDelete":
+      case "button_shiftDelete":
         return gFolderDisplay.getCommandStatus(nsMsgViewCommandType.deleteNoTrash);
       case "button_junk":
         UpdateJunkToolbarButton();
         // fall through
       case "cmd_markAsJunk":
       case "cmd_markAsNotJunk":
         return gFolderDisplay.getCommandStatus(nsMsgViewCommandType.junk);
       case "cmd_recalculateJunkScore":
@@ -1020,28 +1007,27 @@ var MessageWindowController =
         else
           MsgCopyMessage(GetMsgFolderFromUri(folderId));
         break;
       case "cmd_createFilterFromPopup":
         break;// This does nothing because the createfilter is invoked from the popupnode oncommand.
       case "cmd_createFilterFromMenu":
         MsgCreateFilter();
         break;
+      case "button_delete":
       case "cmd_delete":
-        MsgDeleteMessageFromMessageWindow(false, false);
+        gFolderDisplay.doCommand(nsMsgViewCommandType.deleteMsg);
         break;
+      case "button_shiftDelete":
       case "cmd_shiftDelete":
-        MsgDeleteMessageFromMessageWindow(true, false);
+        gFolderDisplay.doCommand(nsMsgViewCommandType.deleteNoTrash);
         break;
       case "button_junk":
         MsgJunk();
         break;
-      case "button_delete":
-        MsgDeleteMessageFromMessageWindow(false, true);
-        break;
       case "cmd_printSetup":
         PrintUtils.showPageSetup();
         break;
       case "cmd_print":
         PrintEnginePrint();
         break;
       case "cmd_printpreview":
         PrintEnginePrintPreview();
--- a/mail/base/content/msgHdrViewOverlay.js
+++ b/mail/base/content/msgHdrViewOverlay.js
@@ -1940,32 +1940,30 @@ var AttachmentListController =
 {
   supportsCommand: function(command)
   {
     switch (command)
     {
       case "cmd_selectAll":
       case "cmd_delete":
       case "cmd_shiftDelete":
-      case "button_delete":
       case "cmd_saveAsFile":
         return true;
       default:
         return false;
     }
   },
 
   isCommandEnabled: function(command)
   {
     switch (command)
     {
       case "cmd_selectAll":
       case "cmd_delete":
       case "cmd_shiftDelete":
-      case "button_delete":
       case "cmd_saveAsFile":
         return true;
       default:
         return false;
     }
   },
 
   doCommand: function(command)
@@ -1979,17 +1977,16 @@ var AttachmentListController =
 
     switch (command)
     {
       case "cmd_selectAll":
         attachmentList.selectAll();
         return;
       case "cmd_delete":
       case "cmd_shiftDelete":
-      case "button_delete":
         HandleSelectedAttachments('delete');
         return;
       case "cmd_saveAsFile":
         HandleSelectedAttachments('saveAs');
         return;
     }
   },
 
--- a/mail/base/content/msgHdrViewOverlay.xul
+++ b/mail/base/content/msgHdrViewOverlay.xul
@@ -204,18 +204,18 @@
                              observes="button_junk"
                              class="toolbarbutton-1 msgHeaderView-button hdrJunkButton"
                              oncommand="goDoCommand('button_junk');RestoreFocusAfterHdrButton();"/>
               <toolbarbutton id="hdrTrashButton"
                              label="&hdrTrashButton1.label;"
                              tooltiptext="&hdrTrashButton1.tooltip;"
                              observes="button_delete"
                              class="toolbarbutton-1 msgHeaderView-button hdrTrashButton"
-                             oncommand="goDoCommand(event.shiftKey ? 'cmd_shiftDelete' :
-                                                    'cmd_delete');RestoreFocusAfterHdrButton();"/>
+                             oncommand="goDoCommand(event.shiftKey ? 'button_shiftDelete' :
+                                                    'button_delete');RestoreFocusAfterHdrButton();"/>
               <toolbarbutton id="hdrReplyToSenderButton" label="&hdrReplyButton1.label;"
                              tooltiptext="&hdrReplyButton1.tooltip;"
                              oncommand="MsgReplyMessage(event);RestoreFocusAfterHdrButton();"
                              observes="button_reply"
                              class="toolbarbutton-1 msgHeaderView-button hdrReplyToSenderButton"/>
               <toolbaritem id="hdrSmartReplyButton" label="&hdrSmartReplyButton1.label;">
                 <!-- This button is a dummy and should only be shown when
                      customizing the toolbar to distinguish the smart reply
--- a/mail/test/mozmill/attachment/test-attachment.js
+++ b/mail/test/mozmill/attachment/test-attachment.js
@@ -443,9 +443,29 @@ function test_attachments_compose_menu()
                 "attachmentBucket is not focused!");
 
   // Focus back to the attachmentBucket
   attachment.focus();
   assert_equals(cwc.e("cmd_delete").getAttribute("label"), "Remove Attachments",
                 "Multiple attachments are selected!");
 
   close_compose_window(cwc);
-}
\ No newline at end of file
+}
+
+function test_delete_from_toolbar() {
+  be_in_folder(folder);
+
+  // First, select the message with two attachments.
+  select_none();
+  select_click_row(3);
+
+  // Expand the attachment list.
+  mc.click(mc.eid("attachmentToggle"));
+
+  let firstAttachment = new elib.Elem(mc.e("attachmentList").firstChild);
+  mc.click(firstAttachment, 5, 5);
+
+  // Make sure clicking the "Delete" toolbar button with an attachment focused
+  // deletes the *message*.
+  plan_to_wait_for_folder_events("DeleteOrMoveMsgCompleted");
+  mc.click(mc.eid("hdrTrashButton"));
+  wait_for_folder_events();
+}