diff --git a/mozilla/mailnews/compose/resources/content/MsgComposeCommands.js b/mozilla/mailnews/compose/resources/content/MsgComposeCommands.js index 5d54ec70f90..be24ccf1153 100644 --- a/mozilla/mailnews/compose/resources/content/MsgComposeCommands.js +++ b/mozilla/mailnews/compose/resources/content/MsgComposeCommands.js @@ -26,6 +26,7 @@ var msgCompose = null; var MAX_RECIPIENTS = 0; var currentAttachment = null; var tabIntoBodyPhase = 0; +var documentLoaded = false; var other_header = ""; var update_compose_title_as_you_type = true; @@ -50,20 +51,7 @@ if (prefs) { var editorDocumentListener = { NotifyDocumentCreated: function() { - - CompFields2Recipients(msgCompose.compFields); - - if (document.getElementById("msgRecipient#1").value == "") - { - dump("set focus on the recipient\n"); - document.getElementById("msgRecipient#1").focus(); - } - else - { - dump("set focus on the body\n"); - contentWindow.focus(); - } - SetComposeWindowTitle(13); + documentLoaded = true; } }; @@ -118,6 +106,18 @@ function GetArgs() return args; } +function WaitFinishLoadingDocument() +{ + if (documentLoaded) + { + CompFields2Recipients(msgCompose.compFields); + SetComposeWindowTitle(13); + AdjustFocus(); + } + else + setTimeout("WaitFinishLoadingDocument();", 200); +} + function ComposeStartup() { dump("Compose: ComposeStartup\n"); @@ -236,8 +236,7 @@ function ComposeStartup() // Now that we have an Editor AppCore, we can finish to initialize the Compose AppCore msgCompose.editor = window.editorShell; - - document.getElementById("msgRecipient#1").focus(); + WaitFinishLoadingDocument(); } } } @@ -572,6 +571,20 @@ function getIdentityForKey(key) return accountManager.getIdentity(key); } +function AdjustFocus() +{ + if (document.getElementById("msgRecipient#1").value == "") + { + dump("set focus on the recipient\n"); + document.getElementById("msgRecipient#1").focus(); + } + else + { + dump("set focus on the body\n"); + contentWindow.focus(); + } +} + function SetComposeWindowTitle(event) { /* dump("event = " + event + "\n"); */ diff --git a/mozilla/mailnews/compose/src/nsMsgCompose.cpp b/mozilla/mailnews/compose/src/nsMsgCompose.cpp index 1100324b3a3..fc5b7d43ded 100644 --- a/mozilla/mailnews/compose/src/nsMsgCompose.cpp +++ b/mozilla/mailnews/compose/src/nsMsgCompose.cpp @@ -44,7 +44,8 @@ #include "nsMsgPrompts.h" #include "nsMimeTypes.h" #include "nsICharsetConverterManager.h" -#include "nsTextFormater.h" +#include "nsTextFormater.h" +#include "nsIEditor.h" // XXX temporary so we can use the current identity hack -alecf #include "nsIMsgMailSession.h" @@ -58,6 +59,16 @@ static NS_DEFINE_CID(kMsgQuoteCID, NS_MSGQUOTE_CID); static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); static NS_DEFINE_CID(kHeaderParserCID, NS_MSGHEADERPARSER_CID); +static PRInt32 GetReplyOnTop() +{ + PRInt32 reply_on_top = 1; + nsresult rv; + NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &rv); + if (NS_SUCCEEDED(rv)) + prefs->GetIntPref("mailnews.reply_on_top", &reply_on_top); + return reply_on_top; +} + nsMsgCompose::nsMsgCompose() { NS_INIT_REFCNT(); @@ -110,17 +121,33 @@ NS_IMPL_ISUPPORTS(nsMsgCompose, nsCOMTypeInfo::GetIID()); static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID); nsresult -ConvertAndLoadComposeWindow(nsIEditorShell *aEditor, nsString aBuf, PRBool aQuoted, PRBool aHTMLEditor) +ConvertAndLoadComposeWindow(nsIEditorShell *aEditorShell, nsString aBuf, PRBool aQuoted, PRBool aHTMLEditor) { // Now, insert it into the editor... if ( (aQuoted) ) - aEditor->InsertAsQuotation(aBuf.GetUnicode()); + aEditorShell->InsertAsQuotation(aBuf.GetUnicode()); else { if (aHTMLEditor) - aEditor->InsertSource(aBuf.GetUnicode()); + aEditorShell->InsertSource(aBuf.GetUnicode()); else - aEditor->InsertText(aBuf.GetUnicode()); + aEditorShell->InsertText(aBuf.GetUnicode()); + } + + nsCOMPtr editor; + aEditorShell->GetEditor(getter_AddRefs(editor)); + if (editor) + { + switch (GetReplyOnTop()) + { + /* TODO: in case of the user want the insertion point at the end of the body, + we need to be smarter than just doing editor->EndOfDocument() because + if we have a signature, we need to put the cursor just before it. + */ + case 0 : editor->EndOfDocument(); break; + case 2 : editor->SelectAll(); break; + default : editor->BeginningOfDocument(); break; + } } return NS_OK; @@ -752,7 +779,8 @@ QuotingOutputStreamListener::QuotingOutputStreamListener(const PRUnichar * origi } if (NS_SUCCEEDED(rv)) { - mMsgBody = "

"; + if (GetReplyOnTop() == 1) + mMsgBody = "

"; mMsgBody += author; mMsgBody += " wrote:
"; } @@ -1457,7 +1485,7 @@ nsMsgCompose::ProcessSignature(nsIMsgIdentity *identity, nsString *aMsgBody) // looking manner // char *htmlBreak = "
"; - char *dashes = "--"; + char *dashes = "-- "; if (sigData != "") { if (m_composeHTML)