Bug 507682: askSendFormat modernization. r=mnyromyr, sr=neil
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Sat, 05 Sep 2009 13:25:15 +0300
changeset 3547 c014663a43907ff86d912a693cb03322ed104e5f
parent 3546 37532e529fbe5a33357210502fa25665a41fbee5
child 3548 6ef1407c253054cb9f6fc62afd6a5c686c2174f7
push idunknown
push userunknown
push dateunknown
reviewersmnyromyr, neil
bugs507682
Bug 507682: askSendFormat modernization. r=mnyromyr, sr=neil
mail/themes/gnomestripe/mail/dialogs.css
mail/themes/pinstripe/mail/dialogs.css
mail/themes/qute/mail/dialogs.css
mailnews/compose/content/askSendFormat.js
mailnews/compose/content/askSendFormat.xul
suite/themes/classic/messenger/dialogs.css
suite/themes/modern/messenger/dialogs.css
--- a/mail/themes/gnomestripe/mail/dialogs.css
+++ b/mail/themes/gnomestripe/mail/dialogs.css
@@ -62,32 +62,8 @@ menu.push[open="true"] {
   -moz-padding-end: 1px;
 }
 
 menu.push[disabled="true"],
 menu.push[disabled="true"]:hover,
 menu.push[disabled="true"]:hover:active {
   color: GrayText;
 }
-
-/* ::::: askSendFormat.xul ::::: */
-
-#askSendFormat {
-  width: 40em;
-}
-
-#askImageBox {
- -moz-box-align: start;
-}
-
-#convertYes,
-#convertAltering {
-  list-style-image:url("chrome://global/skin/icons/Question.png");
-}
-
-#convertNo {
-  list-style-image:url("chrome://global/skin/icons/Warning.png");
-}
-
-/* Workaround for bug 50217. Please remove this rule, when this bug is fixed. */
-#convertDefault {
-  list-style-image:url("chrome://global/skin/icons/Question.png");
-}
--- a/mail/themes/pinstripe/mail/dialogs.css
+++ b/mail/themes/pinstripe/mail/dialogs.css
@@ -62,38 +62,8 @@ menu.push[open="true"] {
   -moz-padding-end: 1px;
 }
 
 menu.push[disabled="true"],
 menu.push[disabled="true"]:hover,
 menu.push[disabled="true"]:hover:active {
   color: GrayText;
 }
-
-/* ::::: askSendFormat.xul ::::: */
-
-#askSendFormat {
-  width: 40em;
-}
-
-#askImageBox {
- -moz-box-align: start;
-}
-
-#convertYes {
-  list-style-image:url("chrome://global/skin/question-icon.png");
-}
-
-#convertAltering {
-  list-style-image:url("chrome://global/skin/question-icon.png");
-}
-
-#convertNo {
-  list-style-image:url("chrome://global/skin/alert-icon.png");
-}
-
-/* Workaround for bug 50217. Please remove this rule, when this bug is fixed. */
-#convertDefault {
-  list-style-image:url("chrome://global/skin/question-icon.png");
-}
-
-
-
--- a/mail/themes/qute/mail/dialogs.css
+++ b/mail/themes/qute/mail/dialogs.css
@@ -62,32 +62,8 @@ menu.push[open="true"] {
   -moz-padding-end: 1px;
 }
 
 menu.push[disabled="true"],
 menu.push[disabled="true"]:hover,
 menu.push[disabled="true"]:hover:active {
   color: GrayText;
 }
-
-/* ::::: askSendFormat.xul ::::: */
-
-#askSendFormat {
-  width: 40em;
-}
-
-#askImageBox {
- -moz-box-align: start;
-}
-
-#convertYes,
-#convertAltering {
-  list-style-image:url("chrome://global/skin/icons/Question.png");
-}
-
-#convertNo {
-  list-style-image:url("chrome://global/skin/icons/Warning.png");
-}
-
-/* Workaround for bug 50217. Please remove this rule, when this bug is fixed. */
-#convertDefault {
-  list-style-image:url("chrome://global/skin/icons/Question.png");
-}
--- a/mailnews/compose/content/askSendFormat.js
+++ b/mailnews/compose/content/askSendFormat.js
@@ -18,173 +18,78 @@
  * Portions created by the Initial Developer are Copyright (C) 2000
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
  *   Jean-Francois Ducarroz <ducarroz@netscape.com>
  *   Ben Bucksch <mozilla.BenB@bucksch.org>
  *   Ian Neal <bugzilla@arlen.demon.co.uk>
  *   Žiga Sancin <bisi@pikslar.com>
+ *   Magnus Melin <mkmelin+mozilla@iki.fi>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either of 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
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-var msgCompSendFormat = Components.interfaces.nsIMsgCompSendFormat;
-var msgCompConvertible = Components.interfaces.nsIMsgCompConvertible;
-var param = null;
-
-/* There are 3 preferences that let you customize the behavior of this dialog
-
-1. pref("mail.asksendformat.default", 1); //1=plaintext, 2=html, 3=both
-   This defines the default action selected when the dialog opens. It can be overwritten by the preference
-   mail.asksendformat.recommended_as_default
-
-
-2. pref("mail.asksendformat.recommended_as_default", true);
-   If you set this preference to true and we have a recommended action, this action will be selected by default.
-   In this case, we ignore the preference mail.asksendformat.default
-
-
-3. pref("mail.asksendformat.display_recommendation", true);
-   When this preference is set to false, the recommended action label will not be displayed next to the action
-   radio button. However, the default action might change to the recommended one if the preference
-   mail.asksendformat.recommended_as_default is set.
-*/
-
-var defaultAction = msgCompSendFormat.PlainText;
-var recommended_as_default = true;
-var display_recommendation = true;
-var useDefault = false;
+var gParam = null;
 
-var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService();
-if (prefs)
-{
-  prefs = prefs.QueryInterface(Components.interfaces.nsIPrefBranch);
-  if (prefs)
-  {
-    try
-    {
-      defaultAction = prefs.getIntPref("mail.asksendformat.default");
-      useDefault = true;
-    }
-    catch (ex) {}
-
-    try
-    {
-      recommended_as_default = prefs.getBoolPref("mail.asksendformat.recommended_as_default");
-    }
-    catch (ex) {}
-
-    try
-    {
-      display_recommendation = prefs.getBoolPref("mail.asksendformat.display_recommendation");
-    }
-    catch (ex) {}
-  }
-}
-
+/**
+ * This dialog should be opened with arguments like e.g.
+ * {action: nsIMsgCompSendFormat.AskUser, convertible: nsIMsgCompConvertible.Yes}
+ */
 function Startup()
 {
-  if (window.arguments && window.arguments[0])
-  {
-    var askSendFormatStringBundle = document.getElementById("askSendFormatStringBundle");
-    param = window.arguments[0];
-    // If the user hits the close box, we will abort.
-    param.abort = true;
-    if (param.action)
-    {
-      // Set the question label
-      var mailSendFormatExplanation = document.getElementById("mailSendFormatExplanation");
-      var icon = document.getElementById("convertDefault");
-      switch (param.convertible)
-      {
-        case msgCompConvertible.Plain:
-          // We shouldn't be here at all
-          mailSendFormatExplanation.textContent = askSendFormatStringBundle.getString("convertibleYes");
-          // No icon
-          break;
-        case msgCompConvertible.Yes:
-          mailSendFormatExplanation.textContent = askSendFormatStringBundle.getString("convertibleYes");
-          icon.setAttribute("id", "convertYes");
-          break;
-        case msgCompConvertible.Altering:
-          mailSendFormatExplanation.textContent = askSendFormatStringBundle.getString("convertibleAltering");
-          icon.setAttribute("id", "convertAltering");
-          break;
-        case msgCompConvertible.No:
-          mailSendFormatExplanation.textContent = askSendFormatStringBundle.getString("convertibleNo");
-          icon.setAttribute("id", "convertNo");
-          break;
-      }
+  gParam = window.arguments[0];
+
+  const msgCompSendFormat = Components.interfaces.nsIMsgCompSendFormat;
+  const msgCompConvertible = Components.interfaces.nsIMsgCompConvertible;
+
+  var bundle = document.getElementById("askSendFormatStringBundle");
+
+  // If the user hits the close box, we will abort.
+  gParam.abort = true;
+
+  // Set the question label
+  var mailSendFormatExplanation = document.getElementById("mailSendFormatExplanation");
+  var icon = document.getElementById("convertDefault");
 
-      // Set the default radio array value and recommendation
-      var group = document.getElementById("mailDefaultHTMLAction");
-      var radio;
-      var radioButtons = group.getElementsByTagName("radio");
-      var haveRecommendation = false;
-      var format = (useDefault) ? defaultAction : param.action;
+  switch (gParam.convertible)
+  {
+    case msgCompConvertible.Altering:
+      mailSendFormatExplanation.textContent = bundle.getString("convertibleAltering");
+      icon.className = "question-icon";
+      break;
+    case msgCompConvertible.No:
+      mailSendFormatExplanation.textContent = bundle.getString("convertibleNo");
+      icon.className = "alert-icon";
+      break;
+    default: // msgCompConvertible.Yes
+      mailSendFormatExplanation.textContent = bundle.getString("convertibleYes");
+      // XXX change this to use class message-icon once bug 512173 is fixed
+      icon.className = "question-icon";
+      break;
+  }
 
-      switch (format)
-      {
-        case msgCompSendFormat.AskUser:
-          // haveRecommendation = false;
-          break;
-        case msgCompSendFormat.PlainText:
-          radio = radioButtons[1];
-          haveRecommendation = true;
-          break;
-        case msgCompSendFormat.Both:
-          radio = radioButtons[0];
-          haveRecommendation = true;
-          break;
-        case msgCompSendFormat.HTML:
-          radio = radioButtons[2];
-          haveRecommendation = true;
-          break;
-      }
-
-      if (haveRecommendation)
-      {
-        if (display_recommendation)
-          radio.label += " " + askSendFormatStringBundle.getString("recommended");
-
-        if (recommended_as_default)
-          group.value = format;
-      }
-
-      if (!haveRecommendation || !recommended_as_default)
-        group.value = defaultAction;
-    }
-  }
-  else 
+  // Set the default radio array value and recommendation.
+  var group = document.getElementById("mailDefaultHTMLAction");
+  if (gParam.action != msgCompSendFormat.AskUser)
   {
-    dump("error, no return object registered\n");
+    group.value = gParam.action;
+    group.selectedItem.label += " " + bundle.getString("recommended");
   }
 }
 
 function Send()
 {
-  if (param)
-  {
-    // param.action should be an integer for when it is returned to MsgComposeCommands.js
-    param.action = parseInt(document.getElementById("mailDefaultHTMLAction").value);
-    param.abort = false;
-  }
-  return true;
+  // gParam.action should be an integer for when it is returned to MsgComposeCommands.js
+  gParam.action = parseInt(document.getElementById("mailDefaultHTMLAction").value);
+  gParam.abort = false;
 }
-
-function Cancel()
-{
-  if (param)
-    param.abort = true;
-  return true;
-}
--- a/mailnews/compose/content/askSendFormat.xul
+++ b/mailnews/compose/content/askSendFormat.xul
@@ -34,29 +34,29 @@
    - use your version of this file under the terms of the MPL, indicate your
    - decision by deleting the provisions above and replace them with the notice
    - and other provisions required by the GPL or the LGPL. If you do not delete
    - the provisions above, a recipient may use your version of this file under
    - the terms of any one of the MPL, the GPL or the LGPL.
    -
    - ***** END LICENSE BLOCK ***** -->
 
-<?xml-stylesheet href="chrome://messenger/skin/dialogs.css" type="text/css"?>
+<?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
 
 <!DOCTYPE dialog SYSTEM "chrome://messenger/locale/messengercompose/askSendFormat.dtd">
 
 <dialog id="askSendFormat"
         title="&windowTitle.label;"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         buttonpack="center"
         onload="Startup();"
-        ondialogaccept="return Send();"
-        ondialogcancel="return Cancel();"
+        ondialogaccept="Send();"
         buttonlabelaccept="&send.label;"
-        buttonaccesskeyaccept="&send.accesskey;">
+        buttonaccesskeyaccept="&send.accesskey;"
+        style="width: 75ch;">
 
   <script type="application/javascript"
           src="chrome://messenger/content/messengercompose/askSendFormat.js"/>
 
   <stringbundle id="askSendFormatStringBundle"
                 src="chrome://messenger/locale/messengercompose/askSendFormat.properties"/>
 
     <separator class="thin"/>
@@ -68,14 +68,15 @@
       <separator orient="vertical"/>
       <vbox flex="1">
         <description>&recipient.label;</description>
         <description id="mailSendFormatExplanation"/>
         <description>&question.label;</description>
         <separator/>
         <radiogroup id="mailDefaultHTMLAction">
           <radio value="3" label="&plainTextAndHtml.label;" accesskey="&plainTextAndHtml.accesskey;"/>
-          <radio value="1" label="&plainTextOnly.label;" accesskey="&plainTextOnly.accesskey;"/>
+          <radio value="1" selected="true"
+                 label="&plainTextOnly.label;" accesskey="&plainTextOnly.accesskey;"/>
           <radio value="2" label="&htmlOnly.label;" accesskey="&htmlOnly.accesskey;"/>
         </radiogroup>
       </vbox>
     </hbox>
 </dialog>
--- a/suite/themes/classic/messenger/dialogs.css
+++ b/suite/themes/classic/messenger/dialogs.css
@@ -63,31 +63,8 @@ menu.push[open="true"] {
 }
 
 menu.push[disabled="true"],
 menu.push[disabled="true"]:hover,
 menu.push[disabled="true"]:hover:active {
   color: GrayText;
 }
 
-/* ::::: askSendFormat.xul ::::: */
-
-#askSendFormat {
-  width: 40em;
-}
-
-#askImageBox {
- -moz-box-align: start;
-}
-
-#convertYes,
-#convertAltering {
-  list-style-image:url("chrome://global/skin/icons/alert-question.gif");
-}
-
-#convertNo {
-  list-style-image:url("chrome://global/skin/icons/alert-exclam.gif");
-}
-
-/* Workaround for bug 50217. Please remove this rule, when this bug is fixed. */
-#convertDefault {
-  list-style-image:url("chrome://global/skin/icons/alert-question.gif");
-}
--- a/suite/themes/modern/messenger/dialogs.css
+++ b/suite/themes/modern/messenger/dialogs.css
@@ -90,33 +90,8 @@ treecell.importsampledata {
 
 #progressMeter {
   margin-top: 1em;
   margin-bottom: 2em;
   -moz-margin-start: 1em;
   -moz-margin-end: 2em;
   width: 26em;
 }
-
-/* ::::: askSendFormat.xul ::::: */
-
-#askSendFormat {
-  width: 40em;
-}
-
-#askImageBox {
-  -moz-box-align: start;
-}
-
-#convertYes,
-#convertAltering {
-  list-style-image: url("chrome://global/skin/icons/alert-question.gif");
-}
-
-#convertNo {
-  list-style-image: url("chrome://global/skin/icons/alert-exclam.gif");
-}
-
-/* Workaround for bug 50217. Please remove this rule, when this bug is fixed. */
-#convertDefault {
-  list-style-image: url("chrome://global/skin/icons/alert-question.gif");
-}
-