Bug 1597073 - Port |Bug 231654 - make delete normally only apply to the threadpane - too easy to accidentally delete folder|. r=frg a=frg CLOSED TREE default tip
authorIan Neal <iann_cvs@blueyonder.co.uk>
Sun, 24 Nov 2019 14:23:39 +0100
changeset 32382 fddcb5bd203c2f4bb0c85225231efd7ae10ec8e5
parent 32381 d1bf768379071baecf3f20f9bb7149f3a33724f1
push id231
push userfrgrahl@gmx.net
push dateSun, 24 Nov 2019 13:24:21 +0000
treeherdercomm-esr60@fddcb5bd203c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrg, frg
bugs1597073, 231654
Bug 1597073 - Port |Bug 231654 - make delete normally only apply to the threadpane - too easy to accidentally delete folder|. r=frg a=frg CLOSED TREE
suite/app/profile/suite-prefs.js
suite/mailnews/content/mail3PaneWindowCommands.js
--- a/suite/app/profile/suite-prefs.js
+++ b/suite/app/profile/suite-prefs.js
@@ -358,16 +358,17 @@ pref("network.auth.subresource-img-cross
 pref("network.auth.non-web-content-triggered-resources-http-auth-allow", true);
 
 pref("mail.biff.show_new_alert",     true);
 
 // default calendar integration
 pref("mail.calendar-integration.opt-out", false);
 
 pref("mailnews.ui.deleteMarksRead", true);
+pref("mailnews.ui.deleteAlwaysSelectedMessages", false);
 
 // The maximum amount of decoded image data we'll willingly keep around (we
 // might keep around more than this, but we'll try to get down to this value).
 // (This is intentionally on the high side; see bugs 746055 and 768015.)
 pref("image.mem.max_decoded_image_kb", 256000);
 
 pref("spellchecker.dictionary", "");
 pref("spellchecker.dictionaries.download.url", "https://addons.thunderbird.net/%LOCALE%/%APP%/dictionaries");
--- a/suite/mailnews/content/mail3PaneWindowCommands.js
+++ b/suite/mailnews/content/mail3PaneWindowCommands.js
@@ -16,16 +16,23 @@ 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 (Services.prefs.getBoolPref("mailnews.ui.deleteAlwaysSelectedMessages") && (gFolderDisplay.selectedCount != 0))
+          return false;
+        // else fall through
       //case "cmd_selectAll": the folder pane currently only handles single selection
       case "cmd_cut":
       case "cmd_copy":
       case "cmd_paste":
         return true;
 
       default:
         return false;
@@ -47,43 +54,28 @@ var FolderPaneController =
         if (command == "button_delete")
           UpdateDeleteToolbarButton(true);
       case "button_shiftDelete":
         if ( command == "cmd_delete" )
           goSetMenuValue(command, 'valueFolder');
         let folders = GetSelectedMsgFolders();
 
         if (folders.length) {
-          var canDeleteThisFolder;
-        var specialFolder = null;
-        var isServer = null;
-        try {
           let folder = folders[0];
-          specialFolder = getSpecialFolderString(folder);
-          isServer = folder.isServer;
+          let canDeleteThisFolder = CanDeleteFolder(folder);
           if (folder.server.type == "nntp") {
              if ( command == "cmd_delete" ) {
                 goSetMenuValue(command, 'valueNewsgroup');
                 goSetAccessKey(command, 'valueNewsgroupAccessKey');
             }
           }
-        }
-        catch (ex) {
-          //dump("specialFolder failure: " + ex + "\n");
+          return canDeleteThisFolder && isCommandEnabled(command);
         }
-        if (specialFolder == "Inbox" || specialFolder == "Trash" || specialFolder == "Drafts" ||
-            specialFolder == "Sent" || specialFolder == "Templates" || specialFolder == "Outbox" ||
-            (specialFolder == "Junk" && !CanRenameDeleteJunkMail(GetSelectedFolderURI())) || isServer)
-          canDeleteThisFolder = false;
         else
-          canDeleteThisFolder = true;
-        return canDeleteThisFolder && isCommandEnabled(command);
-      }
-      else
-        return false;
+          return false;
 
       default:
         return false;
     }
   },
 
   doCommand: function(command)
   {
@@ -1070,8 +1062,24 @@ function CanRenameDeleteJunkMail(aFolder
     }
   }
   catch(ex)
   {
       dump("Can't get all servers\n");
   }
   return true;
 }
+
+/** Check if this is a folder the user is allowed to delete. */
+function CanDeleteFolder(folder) {
+  if (folder.isServer)
+    return false;
+
+  var specialFolder = getSpecialFolderString(folder);
+
+  if (specialFolder == "Inbox" || specialFolder == "Trash" ||
+      specialFolder == "Drafts" || specialFolder == "Sent" ||
+      specialFolder == "Templates" || specialFolder == "Outbox" ||
+      (specialFolder == "Junk" && !CanRenameDeleteJunkMail(folder.URI)))
+    return false;
+
+  return true;
+}