Follow up patch to bug 300338 - tidy MsgComposeCommands.js. Patch by Serge GAUTHERIE <gautheri@noos.fr>. r=dmose,sr=bienvenu

This commit is contained in:
bugzilla%standard8.demon.co.uk 2005-08-31 17:44:26 +00:00
Родитель d4b89719f4
Коммит b28a23f916
2 изменённых файлов: 257 добавлений и 264 удалений

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

@ -74,6 +74,7 @@ var sNameProperty = null;
var msgWindow = Components.classes["@mozilla.org/messenger/msgwindow;1"].createInstance();
msgWindow = msgWindow.QueryInterface(Components.interfaces.nsIMsgWindow);
/**
* Global variables, need to be re-initialized every time mostly because we need to release them when the window close
*/
@ -128,10 +129,13 @@ function InitializeGlobalVariables()
gPromptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
//This migrates the LDAPServer Preferences from 4.x to mozilla format.
gLDAPPrefsService = Components.classes["@mozilla.org/ldapprefs-service;1"];
if (gLDAPPrefsService) {
try {
gLDAPPrefsService = Components.classes["@mozilla.org/ldapprefs-service;1"].getService();
gLDAPPrefsService = gLDAPPrefsService.QueryInterface( Components.interfaces.nsILDAPPrefsService);
} catch (ex) {dump ("ERROR: Cannot get the LDAP service\n" + ex + "\n");}
gLDAPPrefsService = gLDAPPrefsService
.getService(Components.interfaces.nsILDAPPrefsService);
} catch (ex) {dump ("ERROR: Cannot get the LDAP prefs service\n" + ex + "\n");}
}
gMsgCompose = null;
gWindowLocked = false;
@ -184,7 +188,9 @@ function disableEditableFields()
gMsgCompose.editor.flags |= nsIPlaintextEditorMail.eEditorReadonlyMask;
var disableElements = document.getElementsByAttribute("disableonsend", "true");
for (i=0;i<disableElements.length;i++)
{
disableElements[i].setAttribute('disabled', 'true');
}
}
function enableEditableFields()
@ -251,7 +257,7 @@ var gComposeRecyclingListener = {
},
onReopen: function(params) {
//Reset focus to avoid undesirable visual effect when reopening the winodw
// Reset focus to avoid undesirable visual effect when reopening the window
var identityElement = document.getElementById("msgIdentity");
if (identityElement)
identityElement.focus();
@ -355,7 +361,7 @@ var progressListener = {
statusText = document.getElementById("statusText");
if (statusText)
statusText.setAttribute("label", aMessage);
} catch (ex) {};
} catch (ex) {}
},
onSecurityChange: function(aWebProgress, aRequest, state)
@ -591,12 +597,11 @@ function CommandUpdate_MsgCompose()
function updateComposeItems()
{
try
{
//Edit Menu
try {
// Edit Menu
goUpdateCommand("cmd_rewrap");
//Insert Menu
// Insert Menu
if (gMsgCompose && gMsgCompose.composeHTML)
{
goUpdateCommand("cmd_renderedHTMLEnabler");
@ -613,10 +618,9 @@ function updateComposeItems()
goUpdateCommand("cmd_smiley");
}
//Options Menu
// Options Menu
goUpdateCommand("cmd_spelling");
goUpdateCommand("cmd_quoteMessage");
} catch(e) {}
}
@ -650,10 +654,8 @@ function updateEditItems()
goUpdateCommand("cmd_findPrev");
}
var messageComposeOfflineObserver =
{
observe: function(subject, topic, state)
{
var messageComposeOfflineObserver = {
observe: function(subject, topic, state) {
// sanity checks
if (topic != "network:offline-status-changed") return;
if (state == "offline")
@ -795,9 +797,14 @@ function setupLdapAutocompleteSession()
if (gLDAPSession) {
LDAPSession = gLDAPSession;
} else {
LDAPSession = Components.classes[
"@mozilla.org/autocompleteSession;1?type=ldap"].createInstance()
LDAPSession = Components
.classes["@mozilla.org/autocompleteSession;1?type=ldap"];
if (LDAPSession) {
try {
LDAPSession = LDAPSession.createInstance()
.QueryInterface(Components.interfaces.nsILDAPAutoCompleteSession);
} catch (ex) {dump ("ERROR: Cannot get the LDAP autocomplete session\n" + ex + "\n");}
}
}
if (autocompleteDirectory && !gIsOffline) {
@ -1172,6 +1179,7 @@ function ComposeFieldsReady(msgType)
CompFields2Recipients(gMsgCompose.compFields, gMsgCompose.type);
SetComposeWindowTitle();
// need timeout for reply to work
if (gMsgCompose.composeHTML)
setTimeout("loadHTMLMsgPrefs();", 0);
@ -1203,23 +1211,22 @@ function ComposeStartup(recycled, aParams)
if (aParams)
params = aParams;
else if (window.arguments && window.arguments[0])
{
try
{
else if (window.arguments && window.arguments[0]) {
try {
if (window.arguments[0] instanceof Components.interfaces.nsIMsgComposeParams)
params = window.arguments[0];
else
params = handleMailtoArgs(window.arguments[0]);
}
catch(ex) { dump("ERROR with parameters: " + ex + "\n"); }
// if still no dice, try and see if the params is an old fashioned list of string attributes
// XXX can we get rid of this yet?
if (!params)
{
args = GetArgs(window.arguments[0]);
}
}
var identityList = document.getElementById("msgIdentity");
var identityListPopup = document.getElementById("msgIdentityPopup");
@ -1319,7 +1326,11 @@ function ComposeStartup(recycled, aParams)
} catch (e) { dump(" FAILED TO START EDITOR: "+e+"\n"); }
// setEditorType MUST be call before setContentWindow
if (!gMsgCompose.composeHTML)
if (gMsgCompose.composeHTML)
{
initLocalFontFaceMenu(document.getElementById("FontFacePopup"));
}
else
{
//Remove HTML toolbar, format and insert menus as we are editing in plain text mode
document.getElementById("outputFormatMenu").setAttribute("hidden", true);
@ -1328,11 +1339,7 @@ function ComposeStartup(recycled, aParams)
document.getElementById("insertMenu").setAttribute("hidden", true);
document.getElementById("menu_showFormatToolbar").setAttribute("hidden", true);
}
else //if (gMsgCompose.composeHTML)
{
var fontsList = document.getElementById("FontFacePopup");
initLocalFontFaceMenu(fontsList);
}
// Do setup common to Message Composer and Web Composer
EditorSharedStartup();
initLanguageMenu();
@ -1351,7 +1358,7 @@ function ComposeStartup(recycled, aParams)
cleanBody = decodeURI(body);
} catch(e) { cleanBody = body;}
// XXX : need html-escaping here
// XXX : need to do html-escaping here !
msgCompFields.body = "<BR><A HREF=\"" + body + "\">" + cleanBody + "</A><BR>";
}
else
@ -1692,8 +1699,8 @@ function GenericSendMessage( msgType )
//Do we need to check the spelling?
if (sPrefs.getBoolPref("mail.SpellCheckBeforeSend"))
{
//We disable spellcheck for the following -subject line, attachment pane, identity and addressing widget
//therefore we need to explicitly focus on the mail body when we have to do a spellcheck.
// We disable spellcheck for the following -subject line, attachment pane, identity and addressing widget
// therefore we need to explicitly focus on the mail body when we have to do a spellcheck.
window.content.focus();
window.cancelSendMessage = false;
try {
@ -1705,7 +1712,7 @@ function GenericSendMessage( msgType )
return;
}
//Check if we have a subject, else ask user for confirmation
// Check if we have a subject, else ask user for confirmation
if (subject == "")
{
if (gPromptService)
@ -1746,10 +1753,12 @@ function GenericSendMessage( msgType )
if (!dontAskAgain)
{
var checkbox = {value:false};
var okToProceed = gPromptService.confirmCheck(window,
var okToProceed = gPromptService.confirmCheck(
window,
sComposeMsgsBundle.getString("sendMsgTitle"),
sComposeMsgsBundle.getString("recipientDlogMessage"),
sComposeMsgsBundle.getString("CheckMsg"), checkbox);
sComposeMsgsBundle.getString("CheckMsg"),
checkbox);
if (!okToProceed)
return;
@ -1773,7 +1782,7 @@ function GenericSendMessage( msgType )
if (action == nsIMsgCompSendFormat.AskUser)
{
var recommAction = convert == nsIMsgCompConvertible.No
var recommAction = (convert == nsIMsgCompConvertible.No)
? nsIMsgCompSendFormat.AskUser
: nsIMsgCompSendFormat.PlainText;
var result2 = {action:recommAction,
@ -1792,7 +1801,6 @@ function GenericSendMessage( msgType )
// by using msgCompFields.forcePlainText and msgCompFields.useMultipartAlternative
// to determine the nsIAbPreferMailFormat (unknown, plaintext, or html)
// if the user sends both, we remember html.
switch (action)
{
case nsIMsgCompSendFormat.PlainText:
@ -1987,7 +1995,6 @@ function SaveAsTemplate()
defaultSaveOperation = "template";
}
function MessageFcc(menuItem)
{
// Get the id for the folder we're FCC into
@ -2564,7 +2571,6 @@ function AttachFile()
var fileHandler = ioService.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);
var currentAttachment = fileHandler.getURLSpecFromFile(currentFile);
if (!DuplicateFileCheck(currentAttachment)) {
var attachment = Components.classes["@mozilla.org/messengercompose/attachment;1"].createInstance(Components.interfaces.nsIMsgAttachment);
attachment.url = currentAttachment;
@ -2676,6 +2682,7 @@ function AttachPage()
}
}
}
function DuplicateFileCheck(FileUrl)
{
var bucket = document.getElementById('attachmentBucket');
@ -3236,7 +3243,6 @@ var envelopeDragObserver = {
}
};
function DisplaySaveFolderDlg(folderURI)
{
try{
@ -3272,8 +3278,6 @@ function DisplaySaveFolderDlg(folderURI)
return;
}
function SetMsgAddressingWidgetTreeElementFocus()
{
var element = document.getElementById("msgRecipient#" + awGetNumberOfRecipients());
@ -3461,7 +3465,6 @@ function toggleAddressPicker()
sidebarBox.setAttribute("sidebarVisible", "false");
elt.removeAttribute("checked");
}
}
// public method called by the address picker sidebar
@ -3489,6 +3492,7 @@ function loadHTMLMsgPrefs()
} catch (e) {}
var bodyElement = GetBodyElement();
try {
textColor = pref.getCharPref("msgcompose.text_color");
if (!bodyElement.getAttribute("text"))
@ -3527,4 +3531,3 @@ function InitEditor()
InlineSpellChecker.Init(editor, sPrefs.getBoolPref("mail.spellcheck.inline"));
InlineSpellChecker.checkDocument(window.content.document);
}

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

@ -133,8 +133,8 @@ function InitializeGlobalVariables()
gLDAPPrefsService = Components.classes["@mozilla.org/ldapprefs-service;1"];
if (gLDAPPrefsService) {
try {
gLDAPPrefsService = gLDAPPrefsService.getService().gLDAPPrefsService
.QueryInterface( Components.interfaces.nsILDAPPrefsService);
gLDAPPrefsService = gLDAPPrefsService
.getService(Components.interfaces.nsILDAPPrefsService);
} catch (ex) {dump ("ERROR: Cannot get the LDAP prefs service\n" + ex + "\n");}
}
@ -166,8 +166,6 @@ function InitializeGlobalVariables()
gLastWindowToHaveFocus = null;
gReceiptOptionChanged = false;
gAttachVCardOptionChanged = false;
}
InitializeGlobalVariables();
@ -263,7 +261,7 @@ var gComposeRecyclingListener = {
},
onReopen: function(params) {
//Reset focus to avoid undesirable visual effect when reopening the winodw
// Reset focus to avoid undesirable visual effect when reopening the window
var identityElement = document.getElementById("msgIdentity");
if (identityElement)
identityElement.focus();
@ -369,7 +367,7 @@ var progressListener = {
statusText = document.getElementById("statusText");
if (statusText)
statusText.setAttribute("label", aMessage);
} catch (ex) {};
} catch (ex) {}
},
onSecurityChange: function(aWebProgress, aRequest, state)
@ -564,7 +562,6 @@ function GetSelectedMessages()
function SetupCommandUpdateHandlers()
{
// dump("SetupCommandUpdateHandlers\n");
top.controllers.insertControllerAt(0, defaultController);
}
@ -585,13 +582,13 @@ function CommandUpdate_MsgCompose()
updateComposeItems();
}
function updateComposeItems() {
function updateComposeItems()
{
try {
//Edit Menu
// Edit Menu
goUpdateCommand("cmd_rewrap");
//Insert Menu
// Insert Menu
if (gMsgCompose && gMsgCompose.composeHTML)
{
goUpdateCommand("cmd_renderedHTMLEnabler");
@ -608,10 +605,8 @@ function updateComposeItems() {
goUpdateCommand("cmd_smiley");
}
//Options Menu
// Options Menu
goUpdateCommand("cmd_spelling");
} catch(e) {}
}
@ -634,7 +629,8 @@ function openEditorContextMenu()
updateEditItems();
}
function updateEditItems() {
function updateEditItems()
{
goUpdateCommand("cmd_pasteNoFormatting");
goUpdateCommand("cmd_pasteQuote");
goUpdateCommand("cmd_delete");
@ -792,8 +788,8 @@ function setupLdapAutocompleteSession()
if (gLDAPSession) {
LDAPSession = gLDAPSession;
} else {
LDAPSession = Components.classes[
"@mozilla.org/autocompleteSession;1?type=ldap"];
LDAPSession = Components
.classes["@mozilla.org/autocompleteSession;1?type=ldap"];
if (LDAPSession) {
try {
LDAPSession = LDAPSession.createInstance()
@ -1214,8 +1210,7 @@ function ComposeStartup(recycled, aParams)
if (aParams)
params = aParams;
else
if (window.arguments && window.arguments[0]) {
else if (window.arguments && window.arguments[0]) {
try {
if (window.arguments[0] instanceof Components.interfaces.nsIMsgComposeParams)
params = window.arguments[0];
@ -1314,6 +1309,7 @@ function ComposeStartup(recycled, aParams)
dump("Failed to get editor element!\n");
return;
}
document.getElementById("returnReceiptMenu").setAttribute('checked',
gMsgCompose.compFields.returnReceipt);
document.getElementById("cmd_attachVCard").setAttribute('checked',
@ -1330,7 +1326,11 @@ function ComposeStartup(recycled, aParams)
} catch (e) { dump(" FAILED TO START EDITOR: "+e+"\n"); }
// setEditorType MUST be call before setContentWindow
if (!gMsgCompose.composeHTML)
if (gMsgCompose.composeHTML)
{
initLocalFontFaceMenu(document.getElementById("FontFacePopup"));
}
else
{
//Remove HTML toolbar, format and insert menus as we are editing in plain text mode
document.getElementById("outputFormatMenu").setAttribute("hidden", true);
@ -1340,11 +1340,6 @@ function ComposeStartup(recycled, aParams)
document.getElementById("menu_showFormatToolbar").setAttribute("hidden", true);
}
if (gMsgCompose.composeHTML) {
var fontsList = document.getElementById("FontFacePopup");
initLocalFontFaceMenu(fontsList);
}
// Do setup common to Message Composer and Web Composer
EditorSharedStartup();
}
@ -1669,9 +1664,10 @@ function GenericSendMessage( msgType )
if (msgType == nsIMsgCompDeliverMode.Now || msgType == nsIMsgCompDeliverMode.Later)
{
//Do we need to check the spelling?
if (sPrefs.getBoolPref("mail.SpellCheckBeforeSend")){
//We disable spellcheck for the following -subject line, attachment pane, identity and addressing widget
//therefore we need to explicitly focus on the mail body when we have to do a spellcheck.
if (sPrefs.getBoolPref("mail.SpellCheckBeforeSend"))
{
// We disable spellcheck for the following -subject line, attachment pane, identity and addressing widget
// therefore we need to explicitly focus on the mail body when we have to do a spellcheck.
window.content.focus();
window.cancelSendMessage = false;
try {
@ -1683,7 +1679,7 @@ function GenericSendMessage( msgType )
return;
}
//Check if we have a subject, else ask user for confirmation
// Check if we have a subject, else ask user for confirmation
if (subject == "")
{
if (gPromptService)
@ -1695,8 +1691,7 @@ function GenericSendMessage( msgType )
sComposeMsgsBundle.getString("subjectDlogMessage"),
result,
null,
{value:0}
))
{value:0}))
{
msgCompFields.subject = result.value;
var subjectInputElem = document.getElementById("msgSubject");
@ -1762,7 +1757,7 @@ function GenericSendMessage( msgType )
if (action == nsIMsgCompSendFormat.AskUser)
{
var recommAction = convert == nsIMsgCompConvertible.No
var recommAction = (convert == nsIMsgCompConvertible.No)
? nsIMsgCompSendFormat.AskUser
: nsIMsgCompSendFormat.PlainText;
var result2 = {action:recommAction,
@ -1853,7 +1848,6 @@ function GenericSendMessage( msgType )
}
msgWindow.SetDOMWindow(window);
msgWindow.rootDocShell.allowAuth = true;
gMsgCompose.SendMsg(msgType, getCurrentIdentity(), currentAccountKey, msgWindow, progress);
}
catch (ex) {
@ -1945,6 +1939,7 @@ function SaveAsFile(saveAs)
dump("SaveAsFile from XUL\n");
var subject = document.getElementById('msgSubject').value;
GetCurrentEditor().setDocumentTitle(subject);
if (gMsgCompose.bodyConvertible() == nsIMsgCompConvertible.Plain)
SaveDocument(saveAs, false, "text/plain");
else
@ -1968,7 +1963,6 @@ function SaveAsTemplate()
defaultSaveOperation = "template";
}
function MessageFcc(menuItem)
{
// Get the id for the folder we're FCC into
@ -2567,7 +2561,6 @@ function FocusOnFirstAttachment()
function AttachmentElementHasItems()
{
var element = document.getElementById("attachmentBucket");
return element ? element.childNodes.length : 0;
}
@ -2979,8 +2972,6 @@ function DisplaySaveFolderDlg(folderURI)
return;
}
function SetMsgAddressingWidgetElementFocus()
{
var element = awGetInputElement(awGetNumberOfRecipients());
@ -3141,9 +3132,9 @@ function SwitchElementFocus(event)
}
}
function loadHTMLMsgPrefs() {
function loadHTMLMsgPrefs()
{
var pref = GetPrefs();
var fontFace;
var fontSize;
var textColor;
@ -3176,7 +3167,6 @@ function loadHTMLMsgPrefs() {
document.getElementById("cmd_backgroundColor").setAttribute("state", bgColor);
onBackgroundColorChange();
} catch (e) {}
}
function AutoSave()