Fix for bug 51547. Add several prefs to customize the behavior of the askSendFormatDialog. R=benb, alecf

This commit is contained in:
ducarroz%netscape.com 2000-09-14 04:55:07 +00:00
Родитель 92f8ac224b
Коммит bf17076266
2 изменённых файлов: 166 добавлений и 131 удалений

Просмотреть файл

@ -1,162 +1,196 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
var msgCompSendFormat = Components.interfaces.nsIMsgCompSendFormat;
var msgCompConvertible = Components.interfaces.nsIMsgCompConvertible;
var changeDefault = false; /* Set default selection following
the recommendation. Some people think, the
default should *always* be the same. */
var param = null;
/* There is 3 preferences that let you customize the behavior of this dialog
1. pref("mail.asksendformat.default", 1); //1=plaintext, 2=html, 3=both
This define the default action selected when the dialog open. This could be overwritten by the preference
mail.asksendformat.recommended_as_default (described here after)
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 be 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 prefs = Components.classes["component://netscape/preferences"].getService();
if (prefs) {
prefs = prefs.QueryInterface(Components.interfaces.nsIPref);
if (prefs) {
try {
defaultAction = prefs.GetIntPref("mail.asksendformat.default");
} 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) {}
}
}
function Startup()
{
if (window.arguments && window.arguments[0])
if (window.arguments && window.arguments[0])
{
var defaultElement;
switch (defaultAction)
{
var defaultElement = document.getElementById("SendPlainTextOnly");
// used only if changeDefault == false
// maybe make that a (default) pref
case msgCompSendFormat.HTML: defaultElement = document.getElementById("SendHtmlOnly"); break
case msgCompSendFormat.Both: defaultElement = document.getElementById("SendPlainTextAndHtml"); break
default: defaultElement = document.getElementById("SendPlainTextOnly"); break
}
param = window.arguments[0];
param.abort = true; //if the user hit the close box, we will abort.
if (param.action)
{
// Set the question label
var labeldeck = document.getElementById("mailSendFormatExplanation");
var icon = document.getElementById("convertDefault");
switch (param.convertible)
{
case msgCompConvertible.Plain:
// We shouldn't be here at all
labeldeck.setAttribute("index", 1);
// No icon
break;
case msgCompConvertible.Yes:
labeldeck.setAttribute("index", 1);
icon.setAttribute("id", "convertYes");
break;
case msgCompConvertible.Altering:
labeldeck.setAttribute("index", 2);
icon.setAttribute("id", "convertAltering");
break;
case msgCompConvertible.No:
labeldeck.setAttribute("index", 3);
icon.setAttribute("id", "convertNo");
break;
}
param = window.arguments[0];
param.abort = true; //if the user hit the close box, we will abort.
if (param.action)
{
// Set the question label
var labeldeck = document.getElementById("mailSendFormatExplanation");
var icon = document.getElementById("convertDefault");
switch (param.convertible)
{
case msgCompConvertible.Plain:
// We shouldn't be here at all
labeldeck.setAttribute("index", 1);
// No icon
break;
case msgCompConvertible.Yes:
labeldeck.setAttribute("index", 1);
icon.setAttribute("id", "convertYes");
break;
case msgCompConvertible.Altering:
labeldeck.setAttribute("index", 2);
icon.setAttribute("id", "convertAltering");
break;
case msgCompConvertible.No:
labeldeck.setAttribute("index", 3);
icon.setAttribute("id", "convertNo");
break;
}
// Set the default radio array value and recommendation
var group = document.getElementById("mailDefaultHTMLAction");
var element;
var recommlabels = document.getElementById("hiddenLabels");
var label;
var setrecomm = false;
switch (param.action)
{
case msgCompSendFormat.AskUser:
//setrecomm = false;
break;
case msgCompSendFormat.PlainText:
element = document.getElementById("SendPlainTextOnly");
//label = recommlabels.getAttribute("plainTextOnlyRecommendedLabel");
label = document.getElementById("plainTextOnlyRecommended");
// elements for "recommended" are a workaround for bug 49623
setrecomm = true;
break;
case msgCompSendFormat.Both:
element = document.getElementById("SendPlainTextAndHtml");
//label = recommlabels.getAttribute("plainTextAndHtmlRecommendedLabel");
label = document.getElementById("plainTextAndHtmlRecommended");
setrecomm = true;
break;
case msgCompSendFormat.HTML:
element = document.getElementById("SendHtmlOnly");
//label = recommlabels.getAttribute("htmlOnlyRecommendedLabel");
label = document.getElementById("htmlOnlyRecommended");
setrecomm = true;
break;
}
if (setrecomm)
{
/*
dump(element.getAttribute("value"));
element.setAttribute("value", label);
element.setAttribute("value", "foo");
dump(element.getAttribute("value"));
*/
label.removeAttribute("hidden");
if (changeDefault)
{
group.selectedItem = element;
group.data = element.data;
}
}
if (!changeDefault)
{
group.selectedItem = defaultElement;
group.data = defaultElement.data;
}
// Set the default radio array value and recommendation
var group = document.getElementById("mailDefaultHTMLAction");
var element;
var recommlabels = document.getElementById("hiddenLabels");
var label;
var haveRecommendation = false;
switch (param.action)
{
case msgCompSendFormat.AskUser:
//haveRecommendation = false;
break;
case msgCompSendFormat.PlainText:
element = document.getElementById("SendPlainTextOnly");
//label = recommlabels.getAttribute("plainTextOnlyRecommendedLabel");
label = document.getElementById("plainTextOnlyRecommended");
// elements for "recommended" are a workaround for bug 49623
haveRecommendation = true;
break;
case msgCompSendFormat.Both:
element = document.getElementById("SendPlainTextAndHtml");
//label = recommlabels.getAttribute("plainTextAndHtmlRecommendedLabel");
label = document.getElementById("plainTextAndHtmlRecommended");
haveRecommendation = true;
break;
case msgCompSendFormat.HTML:
element = document.getElementById("SendHtmlOnly");
//label = recommlabels.getAttribute("htmlOnlyRecommendedLabel");
label = document.getElementById("htmlOnlyRecommended");
haveRecommendation = true;
break;
}
if (haveRecommendation)
{
if (display_recommendation)
{
/*
dump(element.getAttribute("value"));
element.setAttribute("value", label);
element.setAttribute("value", "foo");
dump(element.getAttribute("value"));
*/
label.removeAttribute("hidden");
}
if (recommended_as_default)
{
group.selectedItem = element;
group.data = element.data;
}
}
if (!haveRecommendation || !recommended_as_default)
{
group.selectedItem = defaultElement;
group.data = defaultElement.data;
}
//change the button label
var buttonlabels = document.getElementById("okCancelButtons");
element = document.getElementById("ok");
element.setAttribute("value", buttonlabels.getAttribute("button1Label"));
element = document.getElementById("cancel");
element.setAttribute("value", buttonlabels.getAttribute("button2Label"));
//change the button label
var buttonlabels = document.getElementById("okCancelButtons");
element = document.getElementById("ok");
element.setAttribute("value", buttonlabels.getAttribute("button1Label"));
element = document.getElementById("cancel");
element.setAttribute("value", buttonlabels.getAttribute("button2Label"));
/*
element = document.getElementById("Button2");
element.setAttribute("value", buttonlabels.getAttribute("button3Label"));
element.removeAttribute("hidden");
element.setAttribute("disabled", "true");
element = document.getElementById("Button3");
element.setAttribute("value", buttonlabels.getAttribute("button4Label"));
element.removeAttribute("hidden");
element.setAttribute("disabled", "true");
*/
//set buttons action
doSetOKCancel(Send, Cancel, Recipients, Help);
/* XXX Don't deliberately move windos around, compare bug 28260. Also, for any reason, the window will finally sit outside the visible screen for me. /BenB
//At this point, we cannot position the window because it still doesn't have a width and a height.
//Let move it out of the screen and then move it back at the right position, this after the first refresh.
window.moveTo(32000, 32000);
setTimeout("moveToAlertPosition();", 0);
*/
// moveToAlertPosition();
}
}
else
{
dump("error, no return object registered\n");
}
element = document.getElementById("Button2");
element.setAttribute("value", buttonlabels.getAttribute("button3Label"));
element.removeAttribute("hidden");
element.setAttribute("disabled", "true");
element = document.getElementById("Button3");
element.setAttribute("value", buttonlabels.getAttribute("button4Label"));
element.removeAttribute("hidden");
element.setAttribute("disabled", "true");
*/
//set buttons action
doSetOKCancel(Send, Cancel, Recipients, Help);
}
}
else
{
dump("error, no return object registered\n");
}
}
function Send()
{
if (param)
if (param)
{
switch (document.getElementById("mailDefaultHTMLAction").data)
{
switch (document.getElementById("mailDefaultHTMLAction").data)
{
case "0": param.action = msgCompSendFormat.Both; break;
case "1": param.action = msgCompSendFormat.PlainText; break;
case "2": param.action = msgCompSendFormat.HTML; break;
}
param.abort = false;
case "0": param.action = msgCompSendFormat.Both; break;
case "1": param.action = msgCompSendFormat.PlainText; break;
case "2": param.action = msgCompSendFormat.HTML; break;
}
return true;
param.abort = false;
}
return true;
}
function Cancel()
{
if (param)
param.abort = true;
return true;
if (param)
param.abort = true;
return true;
}
function Recipients()
{
return false;
return false;
}
function Help()
{
return false;
return false;
}

Просмотреть файл

@ -1,5 +1,6 @@
<?xml version="1.0"?><!-- -*- Mode: SGML; tab-width: 4; indent-tabs-mode: nil; -*- -->
<?xml-stylesheet href="chrome://messenger/skin/messenger.css" type="text/css"?>
<?xml-stylesheet href="chrome://messenger/skin/messengercompose/messengercompose.css" type="text/css"?>
<?xul-overlay href="chrome://global/content/dialogOverlay.xul"?>