Bug 234665: Delete button should re-text to "Undelete" when a deleted message is selected. r=philringnalda
authorMagnus Melin <mkmelin@iki.fi>
Sun, 14 Sep 2008 22:34:31 +0300
changeset 331 ba1576dfde33e9454899f76f33c6309bbbe8ab03
parent 330 6ac5fb23522e368a5934013422c623ea2837d1c0
child 333 f1687a5f35947a1688bdf5bb17b5bdfd3a0296b5
push idunknown
push userunknown
push dateunknown
reviewersphilringnalda
bugs234665
Bug 234665: Delete button should re-text to "Undelete" when a deleted message is selected. r=philringnalda
mail/base/content/mail3PaneWindowCommands.js
mail/base/content/mailWindowOverlay.js
mail/base/content/mailWindowOverlay.xul
mail/base/content/messageWindow.js
mail/locales/en-US/chrome/messenger/messenger.dtd
--- a/mail/base/content/mail3PaneWindowCommands.js
+++ b/mail/base/content/mail3PaneWindowCommands.js
@@ -17,17 +17,18 @@
 #
 # The Initial Developer of the Original Code is
 # Netscape Communications Corporation.
 # Portions created by the Initial Developer are Copyright (C) 1998-2000
 # the Initial Developer. All Rights Reserved.
 #
 # Contributor(s):
 #   Jan Varga <varga@nixcorp.com>
-#   Håkan Waara (hwaara@chello.se)
+#   HÃ¥kan Waara <hwaara@gmail.com>
+#   Magnus Melin <mkmelin+mozilla@iki.fi>
 #
 # Alternatively, the contents of this file may be used under the terms of
 # either the GNU General Public License Version 2 or later (the "GPL"), or
 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 # in which case the provisions of the GPL or the LGPL are applicable instead
 # of those above. If you wish to allow use of your version of this file only
 # under the terms of either the GPL or the LGPL, and not to allow others to
 # use your version of this file under the terms of the MPL, indicate your
@@ -66,16 +67,18 @@ var FolderPaneController =
     switch ( command )
     {
       case "cmd_cut":
       case "cmd_copy":
       case "cmd_paste":
         return false;
       case "cmd_delete":
       case "button_delete":
+        // Make sure the button doesn't show "Undelete" for folders.
+        UpdateDeleteToolbarButton();
       case "button_compact":
       if ( command == "cmd_delete" )
         goSetMenuValue(command, 'valueFolder');
       var folders = GetSelectedMsgFolders();
 
       if (folders.length) {
         var canDeleteThisFolder;
         var specialFolder = null;
@@ -136,17 +139,16 @@ var FolderPaneController =
   }
 };
 
 // DefaultController object (handles commands when one of the trees does not have focus)
 var DefaultController =
 {
    supportsCommand: function(command)
   {
-
     switch ( command )
     {
       case "cmd_createFilterFromPopup":
       case "cmd_close":
       case "cmd_reply":
       case "button_reply":
       case "cmd_replySender":
       case "cmd_replyGroup":
@@ -254,16 +256,17 @@ var DefaultController =
     var checkStatus = new Object();
 
     switch ( command )
     {
       case "cmd_delete":
         UpdateDeleteCommand();
         // fall through
       case "button_delete":
+        UpdateDeleteToolbarButton();
         if (gDBView)
           gDBView.getCommandStatus(nsMsgViewCommandType.deleteMsg, enabled, checkStatus);
         return enabled.value;
       case "cmd_shiftDelete":
         if (gDBView)
           gDBView.getCommandStatus(nsMsgViewCommandType.deleteNoTrash, enabled, checkStatus);
         return enabled.value;
       case "button_junk":
@@ -789,17 +792,16 @@ function WhichPaneHasFocus()
   while (currentNode) {
     if (currentNode === threadTree ||
         currentNode === folderTree ||
         currentNode === messagePane)
       return currentNode;
 
     currentNode = currentNode.parentNode;
   }
-
   return null;
 }
 
 function SetupCommandUpdateHandlers()
 {
   // folder pane
   var widget = GetFolderTree();
   if ( widget )
--- a/mail/base/content/mailWindowOverlay.js
+++ b/mail/base/content/mailWindowOverlay.js
@@ -108,17 +108,16 @@ function menu_new_init()
   EnableMenuItem("menu_newVirtualFolder", true);
   if (showNew)
     SetMenuItemLabel("menu_newFolder", gMessengerBundle.getString((isServer || isInbox) ? "newFolderMenuItem" : "newSubfolderMenuItem"));
 }
 
 function goUpdateMailMenuItems(commandset)
 {
 //  dump("Updating commands for " + commandset.id + "\n");
-
   for (var i = 0; i < commandset.childNodes.length; i++)
   {
     var commandID = commandset.childNodes[i].getAttribute("id");
     if (commandID)
     {
       goUpdateCommand(commandID);
     }
   }
@@ -778,16 +777,29 @@ function InitMessageMark()
 
 function UpdateJunkToolbarButton()
 {
   var junkButtonDeck = document.getElementById("junk-deck");
   if (junkButtonDeck)
     junkButtonDeck.selectedIndex = SelectedMessagesAreJunk() ? 1 : 0;
 }
 
+function UpdateDeleteToolbarButton()
+{
+  var deleteButtonDeck = document.getElementById("delete-deck");
+  if (!deleteButtonDeck)
+    return;
+
+  // Never show "Undelete" for folders.
+  if (WhichPaneHasFocus() == GetFolderTree())
+    deleteButtonDeck.selectedIndex = 0;
+  else
+    deleteButtonDeck.selectedIndex = SelectedMessagesAreDeleted() ? 1 : 0;
+}
+
 function UpdateDeleteCommand()
 {
   var value = "value";
   var uri = GetFirstSelectedMessage();
   if (IsNewsMessage(uri))
     value += "News";
   else if (SelectedMessagesAreDeleted())
     value += "IMAPDeleted";
@@ -2721,16 +2733,18 @@ function OnMsgLoaded(aUrl)
     // deletes it before the message is loaded (bug 183394)
     var wintype = document.documentElement.getAttribute('windowtype');
     if (wintype == "mail:messageWindow" || GetThreadTree().view.selection.currentIndex != gSelectedIndexWhenDeleting)
       gNextMessageViewIndexAfterDelete = -2;
 
     var msgHdr = msgHdrForCurrentMessage();
     gMessageNotificationBar.setJunkMsg(msgHdr);
 
+    goUpdateCommand('button_delete');
+
     var markReadAutoMode = gPrefBranch.getBoolPref("mailnews.mark_message_read.auto");
 
     // We just finished loading a message. If messages are to be marked as read
     // automatically, set a timer to mark the message is read after n seconds
     // where n can be configured by the user.
     if (msgHdr && !msgHdr.isRead && markReadAutoMode)
     {
       let markReadOnADelay = gPrefBranch.getBoolPref("mailnews.mark_message_read.delay");
@@ -2786,17 +2800,17 @@ function OnMsgLoaded(aUrl)
       }
       if (copyToOfflineFolder)
       {
         var messages = Components.classes["@mozilla.org/array;1"].createInstance(Components.interfaces.nsIMutableArray);
         messages.appendElement(msgHdr, false);
 
         res = outputPFC.copyMessages(currentMsgFolder, messages, false /*isMove*/, msgWindow /* nsIMsgWindow */, null /* listener */, false /* isFolder */, false /*allowUndo*/ );
       }
-   }
+    }
 }
 
 //
 // This function handles all mdn response generation (ie, imap and pop).
 // For pop the msg uid can be 0 (ie, 1st msg in a local folder) so no
 // need to check uid here. No one seems to set mimeHeaders to null so
 // no need to check it either.
 //
--- a/mail/base/content/mailWindowOverlay.xul
+++ b/mail/base/content/mailWindowOverlay.xul
@@ -1541,22 +1541,32 @@
         <toolbarbutton id="button-notJunk"
                        class="toolbarbutton-1 junk-button"
                        label="&notJunkButton.label;"
                        tooltiptext="&notJunkButton.tooltip;"
                        observes="button_junk"
                        oncommand="goDoCommand('button_junk')"/>
       </deck>
     </toolbaritem>
-    <toolbarbutton id="button-delete"
-                   class="toolbarbutton-1"
-                   label="&deleteButton.label;"
-                   tooltiptext="&deleteButton.tooltip;"
-                   observes="button_delete"
-                   oncommand="goDoCommand(event.shiftKey ? 'cmd_shiftDelete' : 'cmd_delete')"/>
+    <toolbaritem id="button-delete">
+      <deck id="delete-deck" observes="button_delete">
+         <toolbarbutton id="button-mark-deleted"
+                        class="toolbarbutton-1"
+                        label="&deleteButton.label;"
+                        tooltiptext="&deleteButton.tooltip;"
+                        observes="button_delete"
+                        oncommand="goDoCommand(event.shiftKey ? 'cmd_shiftDelete' : 'cmd_delete')"/>
+         <toolbarbutton id="button-mark-undelete"
+                        class="toolbarbutton-1"
+                        label="&undeleteButton.label;"
+                        tooltiptext="&undeleteButton.tooltip;"
+                        observes="button_delete"
+                        oncommand="goDoCommand('cmd_delete')"/>
+      </deck>
+    </toolbaritem>
 #ifdef XP_MACOSX
     <toolbarbutton id="button-print"
                    class="toolbarbutton-1"
                    label="&printButton.label;"
                    observes="button_print"
                    oncommand="goDoCommand('cmd_print')"
                    tooltiptext="&printButton.tooltip;"/>
 #else
--- a/mail/base/content/messageWindow.js
+++ b/mail/base/content/messageWindow.js
@@ -178,16 +178,17 @@ nsMsgDBViewCommandUpdater.prototype =
     },
 
   displayMessageChanged : function(aFolder, aSubject, aKeywords)
   {
     setTitleFromFolder(aFolder, aSubject);
     ClearPendingReadTimer(); // we are loading / selecting a new message so kill the mark as read timer for the currently viewed message
     gCurrentMessageUri = gDBView.URIForFirstSelectedMessage;
     UpdateStandAloneMessageCounts();
+    goUpdateCommand("button_delete");
     goUpdateCommand("button_junk");
     goUpdateCommand("button_goBack");
     goUpdateCommand("button_goForward");
   },
 
   updateNextMessageAfterDelete : function()
   {
     SetNextMessageAfterDelete();
@@ -841,16 +842,18 @@ var MessageWindowController =
       case "cmd_createFilterFromMenu":
         var loadedFolder = GetLoadedMsgFolder();
         if (!(loadedFolder && loadedFolder.server.canHaveFilters))
           return false;
       case "cmd_delete":
         UpdateDeleteCommand();
         // fall through
       case "button_delete":
+        UpdateDeleteToolbarButton();
+        // fall through
       case "cmd_shiftDelete":
         var loadedFolder = GetLoadedMsgFolder();
         return gCurrentMessageUri && loadedFolder && (loadedFolder.canDeleteMessages || isNewsURI(gCurrentFolderUri));
       case "button_junk":
         UpdateJunkToolbarButton();
         // fall through
       case "cmd_markAsJunk":
       case "cmd_markAsNotJunk":
--- a/mail/locales/en-US/chrome/messenger/messenger.dtd
+++ b/mail/locales/en-US/chrome/messenger/messenger.dtd
@@ -434,16 +434,17 @@
 <!ENTITY replyAllButton.label "Reply All">
 <!ENTITY forwardButton.label "Forward">
 <!ENTITY fileButton.label "File">
 <!ENTITY nextButton.label "Next">
 <!ENTITY previousButton.label "Previous">
 <!ENTITY backButton1.label "Back">
 <!ENTITY goForwardButton1.label "Forward">
 <!ENTITY deleteButton.label "Delete">
+<!ENTITY undeleteButton.label "Undelete">
 <!ENTITY markButton.label "Mark">
 <!ENTITY printButton.label "Print">
 <!ENTITY stopButton.label "Stop">
 <!ENTITY throbberItem.title "Activity Indicator">
 <!ENTITY updatesItem.title  "Updates">
 <!ENTITY junkButton.label "Junk">
 <!ENTITY notJunkButton.label "Not Junk">
 <!ENTITY addressBookButton.label "Address Book">
@@ -465,16 +466,17 @@
 <!ENTITY replyAllButton.tooltip "Reply to sender and all recipients">
 <!ENTITY forwardButton.tooltip "Forward selected message">
 <!ENTITY fileButton.tooltip "File selected message">
 <!ENTITY nextButton.tooltip "Move to the next unread message">
 <!ENTITY previousButton.tooltip "Move to the previous unread message">
 <!ENTITY goForwardButton.tooltip "Go forward one message">
 <!ENTITY goBackButton.tooltip "Go back one message">
 <!ENTITY deleteButton.tooltip "Delete selected message or folder">
+<!ENTITY undeleteButton.tooltip "Undelete selected message">
 <!ENTITY markButton.tooltip "Mark messages">
 <!ENTITY printButton.tooltip "Print this message">
 <!ENTITY stopButton.tooltip "Stop the current transfer">
 <!ENTITY junkButton.tooltip "Mark the selected messages as junk">
 <!ENTITY notJunkButton.tooltip "Mark the selected messages as not junk">
 <!ENTITY addressBookButton.tooltip "Go to the address book">
 <!ENTITY tagButton.tooltip "Tag messages">
 <!ENTITY compactButton.tooltip "Remove deleted messages from selected folder">