Bug 942436 - add a way to disable attachment reminder for the current message. r=aceman
authorSuyash Agarwal <syshagarwal@gmail.com>
Wed, 03 Aug 2016 23:26:40 +0200
changeset 26524 3017483c2ab2a534739942581aa13ebc7480f883
parent 26523 119ebe23dce8455b75bcc3e3e5b992a580724dbc
child 26525 57413ea27411082431565097614074553cb5a1b6
push id353
push userclokep@gmail.com
push dateMon, 23 Jan 2017 21:39:40 +0000
reviewersaceman
bugs942436
Bug 942436 - add a way to disable attachment reminder for the current message. r=aceman
mail/components/compose/content/MsgComposeCommands.js
mail/components/compose/content/messengercompose.xul
mail/locales/en-US/chrome/messenger/messengercompose/composeMsgs.properties
mail/themes/osx/mail/compose/messengercompose.css
mail/themes/windows/mail/compose/messengercompose.css
--- a/mail/components/compose/content/MsgComposeCommands.js
+++ b/mail/components/compose/content/MsgComposeCommands.js
@@ -66,17 +66,19 @@ var gCloseWindowAfterSave;
 var gSavedSendNowKey;
 var gSendFormat;
 
 var gMsgIdentityElement;
 var gMsgAddressingWidgetTreeElement;
 var gMsgSubjectElement;
 var gMsgAttachmentElement;
 var gMsgHeadersToolbarElement;
+// TODO: Maybe the following two variables can be combined.
 var gManualAttachmentReminder;
+var gDisableAttachmentReminder;
 var gComposeType;
 var gLanguageObserver;
 
 // i18n globals
 var gCharsetConvertManager;
 var _gComposeBundle;
 function getComposeBundle() {
   // That one has to be lazy. Getting a reference to an element with a XBL
@@ -119,16 +121,17 @@ function InitializeGlobalVariables()
   gSendOperationInProgress = false;
   gSaveOperationInProgress = false;
   gAutoSaving = false;
   gCloseWindowAfterSave = false;
   gSavedSendNowKey = null;
   gSendFormat = nsIMsgCompSendFormat.AskUser;
   gCharsetConvertManager = Components.classes['@mozilla.org/charset-converter-manager;1'].getService(Components.interfaces.nsICharsetConverterManager);
   gManualAttachmentReminder = false;
+  gDisableAttachmentReminder = false;
   gLanguageObserver = null;
 
   gLastWindowToHaveFocus = null;
   gReceiptOptionChanged = false;
   gDSNOptionChanged = false;
   gAttachVCardOptionChanged = false;
   gAttachmentsSize = 0;
   gNumUploadingAttachments = 0;
@@ -139,16 +142,17 @@ function InitializeGlobalVariables()
 InitializeGlobalVariables();
 
 function ReleaseGlobalVariables()
 {
   gCurrentIdentity = null;
   gCharsetConvertManager = null;
   gMsgCompose = null;
   gMessenger = null;
+  gDisableAttachmentReminder = false;
   _gComposeBundle = null;
   MailServices.mailSession.RemoveMsgWindow(msgWindow);
   msgWindow = null;
 }
 
 /**
  * Disables or enables editable elements in the window.
  * The elements to operate on are marked with the "disableonsend" attribute.
@@ -1928,23 +1932,30 @@ function handleEsc()
   if (notification && (activeElement.id == "content-frame" ||
       activeElement.parentNode.parentNode.id == "msgSubject" ||
       notification.contains(activeElement) ||
       activeElement.classList.contains("messageCloseButton"))) {
     notification.close();
   }
 }
 
+function disableAttachmentReminder()
+{
+  gDisableAttachmentReminder = true;
+  toggleAttachmentReminder(false);
+}
+
 /**
  * This state machine manages all showing and hiding of the attachment
  * notification bar. It is only called if any change happened so that
  * recalculating of the notification is needed:
  * - keywords changed
  * - manual reminder was toggled
  * - attachments changed
+ * - manual reminder is disabled
  *
  * It does not track whether the notification is still up when it should be.
  * That allows the user to close it any time without this function showing
  * it again.
  * We ensure notification is only shown on right events, e.g. only when we have
  * keywords and attachments were removed (but not when we have keywords and
  * manual reminder was just turned off). We always show the notification
  * again if keywords change (if no attachments and no manual reminder).
@@ -2032,19 +2043,30 @@ function manageAttachmentNotification(aF
     accessKey : getComposeBundle().getString("addAttachmentButton.accesskey"),
     label: getComposeBundle().getString("addAttachmentButton"),
     callback: function (aNotificationBar, aButton) {
       goDoCommand("cmd_attachFile");
       return true; // keep notification open (the state machine will decide on it later)
     }
   };
 
+  let remindLaterMenuPopup = document.createElement("menupopup");
+  remindLaterMenuPopup.id = "reminderBarPopup";
+  let disableAttachmentReminder = document.createElement("menuitem");
+  disableAttachmentReminder.id = "disableReminder";
+  disableAttachmentReminder.setAttribute("label",
+    getComposeBundle().getString("disableAttachmentReminderButton"));
+  disableAttachmentReminder.setAttribute("command", "cmd_doNotRemindForAttachments");
+  remindLaterMenuPopup.appendChild(disableAttachmentReminder);
+
   let remindButton = {
+    type: "menu-button",
     accessKey : getComposeBundle().getString("remindLaterButton.accesskey"),
     label: getComposeBundle().getString("remindLaterButton"),
+    popup: remindLaterMenuPopup,
     callback: function (aNotificationBar, aButton) {
       toggleAttachmentReminder(true);
     }
   };
 
   notification = nBox.appendNotification("", "attachmentReminder",
                                /* fake out the image so we can do it in CSS */
                                "null",
@@ -2054,17 +2076,18 @@ function manageAttachmentNotification(aF
   notification.insertBefore(msg, buttons);
 }
 
 /**
  * Returns whether the attachment notification should be supressed regardless of
  * the state of keywords.
  */
 function attachmentNotificationSupressed() {
-  return (gManualAttachmentReminder || AttachmentElementHasItems());
+  return (gDisableAttachmentReminder || gManualAttachmentReminder ||
+          AttachmentElementHasItems());
 }
 
 var attachmentWorker = new Worker("resource:///modules/attachmentChecker.js");
 
 // The array of currently found keywords. Or null if keyword detection wasn't
 // run yet so we don't know.
 attachmentWorker.lastMessage = null;
 
@@ -3461,16 +3484,21 @@ function ToggleAttachVCard(target)
  *                          (default) = toggle reminder state.
  */
 function toggleAttachmentReminder(aState = !gManualAttachmentReminder)
 {
   gManualAttachmentReminder = aState;
   document.getElementById("cmd_remindLater")
           .setAttribute("checked", aState);
   gMsgCompose.compFields.attachmentReminder = aState;
+
+  // If we enabled manual reminder, the reminder can't be turned off.
+  if (aState)
+    gDisableAttachmentReminder = false;
+
   manageAttachmentNotification(false);
 }
 
 function FillIdentityList(menulist)
 {
   let accounts = allAccountsSorted(true);
 
   let accountHadSeparator = false;
--- a/mail/components/compose/content/messengercompose.xul
+++ b/mail/components/compose/content/messengercompose.xul
@@ -170,16 +170,18 @@
 
   <command id="cmd_convertCloud" oncommand="convertSelectedToCloudAttachment(event.target.cloudProvider); event.stopPropagation();"/>
   <command id="cmd_convertAttachment" oncommand="goDoCommand('cmd_convertAttachment')"/>
   <command id="cmd_cancelUpload" oncommand="goDoCommand('cmd_cancelUpload')"/>
   <command id="cmd_customizeFromAddress" oncommand="MakeFromFieldEditable();"
            checked="false" label="&customizeFromAddress.label;"/>
 </commandset>
 
+  <command id="cmd_doNotRemindForAttachments" oncommand="disableAttachmentReminder();"/>
+
 <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
--- a/mail/locales/en-US/chrome/messenger/messengercompose/composeMsgs.properties
+++ b/mail/locales/en-US/chrome/messenger/messengercompose/composeMsgs.properties
@@ -258,17 +258,17 @@ renameAttachmentMessage=New attachment n
 ## LOCALIZATION NOTE (mail.compose.attachment_reminder_keywords): comma separated
 ## words that should trigger an attachment reminder.
 mail.compose.attachment_reminder_keywords=.doc,.pdf,.xls,.ppt,.rtf,.pps,attachment,attach,attached,attaching,enclosed,CV,cover letter
 
 addAttachmentButton=Add Attachment…
 addAttachmentButton.accesskey=A
 remindLaterButton=Remind Me Later
 remindLaterButton.accesskey=L
-
+disableAttachmentReminderButton=Disable attachment reminder for current message
 attachmentReminderTitle=Attachment Reminder
 attachmentReminderMsg=Did you forget to add an attachment?
 
 # LOCALIZATION NOTE (attachmentReminderKeywordsMsgs): Semi-colon list of plural forms.
 # See: http://developer.mozilla.org/en/Localization_and_Plurals
 # #1 number of keywords
 attachmentReminderKeywordsMsgs=Found an attachment keyword:;Found #1 attachment keywords:
 attachmentReminderOptionsMsg=Attachment reminder words can be configured in your preferences
--- a/mail/themes/osx/mail/compose/messengercompose.css
+++ b/mail/themes/osx/mail/compose/messengercompose.css
@@ -313,16 +313,29 @@ toolbar[brighttext] #button-print {
 
 #attachmentKeywords {
   font-weight: bold;
   margin-inline-start: 0px;
   text-decoration: underline;
   cursor: pointer;
 }
 
+.notification-button[type="menu-button"] {
+  padding-top: 0;
+}
+
+.notification-button[type="menu-button"] > button {
+  -moz-appearance: none;
+  margin-bottom: -1px;
+  margin-inline-start: -3px;
+  margin-inline-end: 3px;
+  padding-inline-end: 5px;
+  border-inline-end: 1px solid #9b9b9b;
+}
+
 /* XXX I should really have a selector rule here to select just .listcell-icon objects underneath the attachmentList listbox */
 
 .listcell-icon {
   margin-inline-start: 2px;
   margin-top: 2px;
 }
 
 #subjectLabel {
--- a/mail/themes/windows/mail/compose/messengercompose.css
+++ b/mail/themes/windows/mail/compose/messengercompose.css
@@ -1613,16 +1613,21 @@
     list-style-image: url("chrome://messenger/skin/icons/dropmarker.svg#win8");
   }
 
   #attachmentNotificationBox > notification .messageImage {
     background-image: url(chrome://messenger/skin/messengercompose/compose-toolbar.svg#attach-flat);
   }
 }
 
+.notification-button {
+  margin-top: 2px;
+  margin-bottom: 2px;
+}
+
 @media (-moz-windows-default-theme) and (-moz-os-version: windows-win8),
        (-moz-windows-default-theme) and (-moz-os-version: windows-win10) {
   #button-send {
     list-style-image: url("chrome://messenger/skin/messengercompose/compose-toolbar.svg#send-flat");
   }
 
   #button-contacts {
     list-style-image: url("chrome://messenger/skin/messengercompose/compose-toolbar.svg#contacts-flat");