diff --git a/mozilla/editor/base/nsEditorShell.cpp b/mozilla/editor/base/nsEditorShell.cpp index 63ea35a5cb7..e96cff95767 100644 --- a/mozilla/editor/base/nsEditorShell.cpp +++ b/mozilla/editor/base/nsEditorShell.cpp @@ -130,7 +130,6 @@ static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID); static NS_DEFINE_CID(kHTMLEditorCID, NS_HTMLEDITOR_CID); static NS_DEFINE_CID(kCTextServicesDocumentCID, NS_TEXTSERVICESDOCUMENT_CID); -static NS_DEFINE_CID(kCSpellCheckerCID, NS_SPELLCHECKER_CID); static NS_DEFINE_IID(kCFileWidgetCID, NS_FILEWIDGET_CID); static NS_DEFINE_CID(kCStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); static NS_DEFINE_CID(kCommonDialogsCID, NS_CommonDialog_CID ); @@ -1050,8 +1049,6 @@ nsEditorShell::ApplyStyleSheet(const PRUnichar *url) NS_IMETHODIMP nsEditorShell::SetDisplayMode(PRInt32 aDisplayMode) { - nsresult res = NS_OK; - // Reqesting SourceMode and we are already doing that if (aDisplayMode == eDisplayModeSource && mDisplayMode == eDisplayModeSource) return NS_OK; @@ -4028,10 +4025,10 @@ nsEditorShell::GetEmbeddedObjects(nsISupportsArray **aObjectArray) } NS_IMETHODIMP -nsEditorShell::StartSpellChecking(PRUnichar **aFirstMisspelledWord) +nsEditorShell::InitSpellChecker() { nsresult result = NS_NOINTERFACE; - nsAutoString firstMisspelledWord; + // We can spell check with any editor type if (mEditor) { @@ -4059,7 +4056,7 @@ nsEditorShell::StartSpellChecking(PRUnichar **aFirstMisspelledWord) if (NS_FAILED(result)) return result; - result = nsComponentManager::CreateInstance(kCSpellCheckerCID, + result = nsComponentManager::CreateInstance(NS_SPELLCHECKER_PROGID, nsnull, NS_GET_IID(nsISpellChecker), (void **)getter_AddRefs(mSpellChecker)); @@ -4076,10 +4073,8 @@ nsEditorShell::StartSpellChecking(PRUnichar **aFirstMisspelledWord) return result; DeleteSuggestedWordList(); - // Return the first misspelled word and initialize the suggested list - result = mSpellChecker->NextMisspelledWord(&firstMisspelledWord, &mSuggestedWordList); } - *aFirstMisspelledWord = firstMisspelledWord.ToNewUnicode(); + return result; } @@ -4322,7 +4317,7 @@ nsEditorShell::SetCurrentDictionary(const PRUnichar *aDictionary) } NS_IMETHODIMP -nsEditorShell::CloseSpellChecking() +nsEditorShell::UninitSpellChecker() { nsresult result = NS_NOINTERFACE; // We can spell check with any editor type diff --git a/mozilla/editor/composer/src/nsEditorShell.cpp b/mozilla/editor/composer/src/nsEditorShell.cpp index 63ea35a5cb7..e96cff95767 100644 --- a/mozilla/editor/composer/src/nsEditorShell.cpp +++ b/mozilla/editor/composer/src/nsEditorShell.cpp @@ -130,7 +130,6 @@ static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID); static NS_DEFINE_CID(kHTMLEditorCID, NS_HTMLEDITOR_CID); static NS_DEFINE_CID(kCTextServicesDocumentCID, NS_TEXTSERVICESDOCUMENT_CID); -static NS_DEFINE_CID(kCSpellCheckerCID, NS_SPELLCHECKER_CID); static NS_DEFINE_IID(kCFileWidgetCID, NS_FILEWIDGET_CID); static NS_DEFINE_CID(kCStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); static NS_DEFINE_CID(kCommonDialogsCID, NS_CommonDialog_CID ); @@ -1050,8 +1049,6 @@ nsEditorShell::ApplyStyleSheet(const PRUnichar *url) NS_IMETHODIMP nsEditorShell::SetDisplayMode(PRInt32 aDisplayMode) { - nsresult res = NS_OK; - // Reqesting SourceMode and we are already doing that if (aDisplayMode == eDisplayModeSource && mDisplayMode == eDisplayModeSource) return NS_OK; @@ -4028,10 +4025,10 @@ nsEditorShell::GetEmbeddedObjects(nsISupportsArray **aObjectArray) } NS_IMETHODIMP -nsEditorShell::StartSpellChecking(PRUnichar **aFirstMisspelledWord) +nsEditorShell::InitSpellChecker() { nsresult result = NS_NOINTERFACE; - nsAutoString firstMisspelledWord; + // We can spell check with any editor type if (mEditor) { @@ -4059,7 +4056,7 @@ nsEditorShell::StartSpellChecking(PRUnichar **aFirstMisspelledWord) if (NS_FAILED(result)) return result; - result = nsComponentManager::CreateInstance(kCSpellCheckerCID, + result = nsComponentManager::CreateInstance(NS_SPELLCHECKER_PROGID, nsnull, NS_GET_IID(nsISpellChecker), (void **)getter_AddRefs(mSpellChecker)); @@ -4076,10 +4073,8 @@ nsEditorShell::StartSpellChecking(PRUnichar **aFirstMisspelledWord) return result; DeleteSuggestedWordList(); - // Return the first misspelled word and initialize the suggested list - result = mSpellChecker->NextMisspelledWord(&firstMisspelledWord, &mSuggestedWordList); } - *aFirstMisspelledWord = firstMisspelledWord.ToNewUnicode(); + return result; } @@ -4322,7 +4317,7 @@ nsEditorShell::SetCurrentDictionary(const PRUnichar *aDictionary) } NS_IMETHODIMP -nsEditorShell::CloseSpellChecking() +nsEditorShell::UninitSpellChecker() { nsresult result = NS_NOINTERFACE; // We can spell check with any editor type diff --git a/mozilla/editor/idl/nsIEditorSpellCheck.idl b/mozilla/editor/idl/nsIEditorSpellCheck.idl index d495ea8a438..ce4234973ab 100644 --- a/mozilla/editor/idl/nsIEditorSpellCheck.idl +++ b/mozilla/editor/idl/nsIEditorSpellCheck.idl @@ -26,7 +26,7 @@ interface nsIEditorSpellCheck : nsISupports { - wstring StartSpellChecking(); + void InitSpellChecker(); wstring GetNextMisspelledWord(); wstring GetSuggestedWord(); boolean CheckCurrentWord(in wstring suggestedWord); @@ -37,8 +37,8 @@ interface nsIEditorSpellCheck : nsISupports void AddWordToDictionary(in wstring word); void RemoveWordFromDictionary(in wstring word); void GetDictionaryList([array, size_is(count)] out wstring dictionaryList, out PRUint32 count); - void GetCurrentDictionary(out wstring dictionary); + wstring GetCurrentDictionary(); void SetCurrentDictionary(in wstring dictionary); - void CloseSpellChecking(); + void UninitSpellChecker(); }; diff --git a/mozilla/editor/libeditor/txtsvc/nsISpellChecker.h b/mozilla/editor/libeditor/txtsvc/nsISpellChecker.h index 79d775678b6..51447c1df4a 100644 --- a/mozilla/editor/libeditor/txtsvc/nsISpellChecker.h +++ b/mozilla/editor/libeditor/txtsvc/nsISpellChecker.h @@ -25,6 +25,8 @@ #include "nsISupports.h" +#define NS_SPELLCHECKER_PROGID "mozilla.spellchecker.1" + #define NS_ISPELLCHECKER_IID \ { /* F72A52F1-F83B-11d2-8D54-000064657374 */ \ 0xf72a52f1, 0xf83b, 0x11d2, \ diff --git a/mozilla/editor/libeditor/txtsvc/nsTextServicesCID.h b/mozilla/editor/libeditor/txtsvc/nsTextServicesCID.h index df1bceda4bd..9a9edcadde3 100644 --- a/mozilla/editor/libeditor/txtsvc/nsTextServicesCID.h +++ b/mozilla/editor/libeditor/txtsvc/nsTextServicesCID.h @@ -33,9 +33,4 @@ 0x019718e3, 0xcdb5, 0x11d2, \ { 0x8d, 0x3c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } } -#define NS_SPELLCHECKER_CID \ -{ /* 019718E4-CDB5-11d2-8D3C-000000000000 */ \ -0x019718e4, 0xcdb5, 0x11d2, \ -{ 0x8d, 0x3c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } } - #endif /* nsTextServicesCID_h__ */ diff --git a/mozilla/editor/txtsvc/public/nsISpellChecker.h b/mozilla/editor/txtsvc/public/nsISpellChecker.h index 79d775678b6..51447c1df4a 100644 --- a/mozilla/editor/txtsvc/public/nsISpellChecker.h +++ b/mozilla/editor/txtsvc/public/nsISpellChecker.h @@ -25,6 +25,8 @@ #include "nsISupports.h" +#define NS_SPELLCHECKER_PROGID "mozilla.spellchecker.1" + #define NS_ISPELLCHECKER_IID \ { /* F72A52F1-F83B-11d2-8D54-000064657374 */ \ 0xf72a52f1, 0xf83b, 0x11d2, \ diff --git a/mozilla/editor/txtsvc/public/nsTextServicesCID.h b/mozilla/editor/txtsvc/public/nsTextServicesCID.h index df1bceda4bd..9a9edcadde3 100644 --- a/mozilla/editor/txtsvc/public/nsTextServicesCID.h +++ b/mozilla/editor/txtsvc/public/nsTextServicesCID.h @@ -33,9 +33,4 @@ 0x019718e3, 0xcdb5, 0x11d2, \ { 0x8d, 0x3c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } } -#define NS_SPELLCHECKER_CID \ -{ /* 019718E4-CDB5-11d2-8D3C-000000000000 */ \ -0x019718e4, 0xcdb5, 0x11d2, \ -{ 0x8d, 0x3c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } } - #endif /* nsTextServicesCID_h__ */ diff --git a/mozilla/editor/ui/composer/content/ComposerCommands.js b/mozilla/editor/ui/composer/content/ComposerCommands.js index 2a7702cdc71..2b882cc0089 100644 --- a/mozilla/editor/ui/composer/content/ComposerCommands.js +++ b/mozilla/editor/ui/composer/content/ComposerCommands.js @@ -225,19 +225,25 @@ var nsSpellingCommand = // dump("Check Spelling starting...\n"); // Start the spell checker module. Return is first misspelled word try { - firstMisspelledWord = spellChecker.StartSpellChecking(); + spellChecker.InitSpellChecker(); + + // XXX: We need to read in a pref here so we can set the + // default language for the spellchecker! + // spellChecker.SetCurrentDictionary(); + + firstMisspelledWord = spellChecker.GetNextMisspelledWord(); } catch(ex) { - dump("*** Exception error: StartSpellChecking\n"); + dump("*** Exception error: InitSpellChecker\n"); return; } if( firstMisspelledWord == "") { try { - spellChecker.CloseSpellChecking(); + spellChecker.UninitSpellChecker(); } catch(ex) { - dump("*** Exception error: CloseSpellChecking\n"); + dump("*** Exception error: UnInitSpellChecker\n"); return; } // No misspelled word - tell user diff --git a/mozilla/editor/ui/dialogs/content/EdSpellCheck.js b/mozilla/editor/ui/dialogs/content/EdSpellCheck.js index 59e7b9668da..3f7ebfc44ab 100644 --- a/mozilla/editor/ui/dialogs/content/EdSpellCheck.js +++ b/mozilla/editor/ui/dialogs/content/EdSpellCheck.js @@ -76,14 +76,28 @@ function Startup() dialog.ReplaceWordInput.value = MisspelledWord; if (dialog.LanguageMenulist) - InitLanguageMenu(""); + { + // Fill in the language menulist and sync it up + // with the spellchecker's current language. + + var curLang; + + try { + curLang = spellChecker.GetCurrentDictionary(); + } catch(ex) { + dump(ex); + curLang = ""; + } + + InitLanguageMenu(curLang); + } DoEnabling(); dialog.SuggestedList.focus(); } -function InitLanguageMenu(defaultLangStr) +function InitLanguageMenu(curLang) { ClearMenulist(dialog.LanguageMenulist); @@ -113,7 +127,7 @@ function InitLanguageMenu(defaultLangStr) if (!menuStr) menuStr = dictList[i]; - if (defaultLangStr && dictList[i] == defaultLangStr) + if (curLang && dictList[i] == curLang) defaultIndex = i; } catch (ex) { // GetStringFromName throws an exception when @@ -126,14 +140,10 @@ function InitLanguageMenu(defaultLangStr) AppendValueAndDataToMenulist(dialog.LanguageMenulist, menuStr, dictList[i]); } - // Now make sure the correct item in the menu list - // is selected and that the spellchecker is in sync! + // Now make sure the correct item in the menu list is selected. if (dictList.length > 0) - { dialog.LanguageMenulist.selectedIndex = defaultIndex; - // SelectLanguage(); - } } function DoEnabling() @@ -289,15 +299,23 @@ function SelectLanguage() function Recheck() { //TODO: Should we bother to add a "Recheck" method to interface? - spellChecker.CloseSpellChecking(); - MisspelledWord = spellChecker.StartSpellChecking(); - SetWidgetsForMisspelledWord(); + try { + var curLang = spellChecker.GetCurrentDictionary(); + + spellChecker.UninitSpellChecker(); + spellChecker.InitSpellChecker(); + spellChecker.SetCurrentDictionary(curLang); + MisspelledWord = spellChecker.GetNextMisspelledWord(); + SetWidgetsForMisspelledWord(); + } catch(ex) { + dump(ex); + } } function Close() { // Shutdown the spell check and close the dialog - spellChecker.CloseSpellChecking(); + spellChecker.UninitSpellChecker(); window.close(); }