diff --git a/mozilla/editor/base/nsEditorShell.cpp b/mozilla/editor/base/nsEditorShell.cpp index a6bf9f2ca4a..a4869b74257 100644 --- a/mozilla/editor/base/nsEditorShell.cpp +++ b/mozilla/editor/base/nsEditorShell.cpp @@ -244,10 +244,12 @@ GetTreeOwner(nsIDocShell* aDocShell, nsIBaseWindow** aBaseWindow) ///////////////////////////////////////////////////////////////////////// nsEditorShell::nsEditorShell() -: mParserObserver(nsnull) -, mStateMaintainer(nsnull) +: mMailCompose(0) +, mDisplayMode(eDisplayModeNormal) , mWebShellWindow(nsnull) , mContentWindow(nsnull) +, mParserObserver(nsnull) +, mStateMaintainer(nsnull) , mEditorController(nsnull) , mDocShell(nsnull) , mContentAreaDocShell(nsnull) @@ -256,8 +258,6 @@ nsEditorShell::nsEditorShell() , mWrapColumn(0) , mSuggestedWordIndex(0) , mDictionaryIndex(0) -, mDisplayMode(eDisplayModeNormal) -, mMailCompose(0) { //TODO:Save last-used display mode in prefs so new window inherits? NS_INIT_REFCNT(); @@ -4200,6 +4200,108 @@ nsEditorShell::RemoveWordFromDictionary(const PRUnichar *aWord) return result; } +NS_IMETHODIMP +nsEditorShell::GetDictionaryList(PRUnichar ***aDictionaryList, PRUint32 *aCount) +{ + nsresult result = NS_ERROR_NOT_IMPLEMENTED; + + if (!aDictionaryList || !aCount) + return NS_ERROR_NULL_POINTER; + + *aDictionaryList = 0; + *aCount = 0; + + if (mEditor && mSpellChecker) + { + nsStringArray dictList; + + result = mSpellChecker->GetDictionaryList(&dictList); + + if (NS_FAILED(result)) + return result; + + PRUnichar **tmpPtr = 0; + + if (dictList.Count() < 1) + { + // If there are no dictionaries, return an array containing + // one element and a count of one. + + tmpPtr = (PRUnichar **)nsAllocator::Alloc(sizeof(PRUnichar *)); + + if (!tmpPtr) + return NS_ERROR_OUT_OF_MEMORY; + + *tmpPtr = 0; + *aDictionaryList = tmpPtr; + *aCount = 0; + + return NS_OK; + } + + tmpPtr = (PRUnichar **)nsAllocator::Alloc(sizeof(PRUnichar *) * dictList.Count()); + + if (!tmpPtr) + return NS_ERROR_OUT_OF_MEMORY; + + *aDictionaryList = tmpPtr; + *aCount = dictList.Count(); + + nsAutoString dictStr; + + PRUint32 i; + + for (i = 0; i < *aCount; i++) + { + dictList.StringAt(i, dictStr); + tmpPtr[i] = dictStr.ToNewUnicode(); + } + } + + return result; +} + +NS_IMETHODIMP +nsEditorShell::GetCurrentDictionary(PRUnichar **aDictionary) +{ + nsresult result = NS_ERROR_NOT_INITIALIZED; + + if (!aDictionary) + return NS_ERROR_NULL_POINTER; + + *aDictionary = 0; + + if (mEditor && mSpellChecker) + { + nsAutoString dictStr; + result = mSpellChecker->GetCurrentDictionary(&dictStr); + + if (NS_FAILED(result)) + return result; + + *aDictionary = dictStr.ToNewUnicode(); + } + + return result; +} + +NS_IMETHODIMP +nsEditorShell::SetCurrentDictionary(const PRUnichar *aDictionary) +{ + nsresult result = NS_ERROR_NOT_INITIALIZED; + + if (!aDictionary) + return NS_ERROR_NULL_POINTER; + + if (mEditor && mSpellChecker) + { + nsAutoString dictStr(aDictionary); + result = mSpellChecker->SetCurrentDictionary(&dictStr); + } + + return result; +} + NS_IMETHODIMP nsEditorShell::CloseSpellChecking() { diff --git a/mozilla/editor/composer/src/nsEditorShell.cpp b/mozilla/editor/composer/src/nsEditorShell.cpp index a6bf9f2ca4a..a4869b74257 100644 --- a/mozilla/editor/composer/src/nsEditorShell.cpp +++ b/mozilla/editor/composer/src/nsEditorShell.cpp @@ -244,10 +244,12 @@ GetTreeOwner(nsIDocShell* aDocShell, nsIBaseWindow** aBaseWindow) ///////////////////////////////////////////////////////////////////////// nsEditorShell::nsEditorShell() -: mParserObserver(nsnull) -, mStateMaintainer(nsnull) +: mMailCompose(0) +, mDisplayMode(eDisplayModeNormal) , mWebShellWindow(nsnull) , mContentWindow(nsnull) +, mParserObserver(nsnull) +, mStateMaintainer(nsnull) , mEditorController(nsnull) , mDocShell(nsnull) , mContentAreaDocShell(nsnull) @@ -256,8 +258,6 @@ nsEditorShell::nsEditorShell() , mWrapColumn(0) , mSuggestedWordIndex(0) , mDictionaryIndex(0) -, mDisplayMode(eDisplayModeNormal) -, mMailCompose(0) { //TODO:Save last-used display mode in prefs so new window inherits? NS_INIT_REFCNT(); @@ -4200,6 +4200,108 @@ nsEditorShell::RemoveWordFromDictionary(const PRUnichar *aWord) return result; } +NS_IMETHODIMP +nsEditorShell::GetDictionaryList(PRUnichar ***aDictionaryList, PRUint32 *aCount) +{ + nsresult result = NS_ERROR_NOT_IMPLEMENTED; + + if (!aDictionaryList || !aCount) + return NS_ERROR_NULL_POINTER; + + *aDictionaryList = 0; + *aCount = 0; + + if (mEditor && mSpellChecker) + { + nsStringArray dictList; + + result = mSpellChecker->GetDictionaryList(&dictList); + + if (NS_FAILED(result)) + return result; + + PRUnichar **tmpPtr = 0; + + if (dictList.Count() < 1) + { + // If there are no dictionaries, return an array containing + // one element and a count of one. + + tmpPtr = (PRUnichar **)nsAllocator::Alloc(sizeof(PRUnichar *)); + + if (!tmpPtr) + return NS_ERROR_OUT_OF_MEMORY; + + *tmpPtr = 0; + *aDictionaryList = tmpPtr; + *aCount = 0; + + return NS_OK; + } + + tmpPtr = (PRUnichar **)nsAllocator::Alloc(sizeof(PRUnichar *) * dictList.Count()); + + if (!tmpPtr) + return NS_ERROR_OUT_OF_MEMORY; + + *aDictionaryList = tmpPtr; + *aCount = dictList.Count(); + + nsAutoString dictStr; + + PRUint32 i; + + for (i = 0; i < *aCount; i++) + { + dictList.StringAt(i, dictStr); + tmpPtr[i] = dictStr.ToNewUnicode(); + } + } + + return result; +} + +NS_IMETHODIMP +nsEditorShell::GetCurrentDictionary(PRUnichar **aDictionary) +{ + nsresult result = NS_ERROR_NOT_INITIALIZED; + + if (!aDictionary) + return NS_ERROR_NULL_POINTER; + + *aDictionary = 0; + + if (mEditor && mSpellChecker) + { + nsAutoString dictStr; + result = mSpellChecker->GetCurrentDictionary(&dictStr); + + if (NS_FAILED(result)) + return result; + + *aDictionary = dictStr.ToNewUnicode(); + } + + return result; +} + +NS_IMETHODIMP +nsEditorShell::SetCurrentDictionary(const PRUnichar *aDictionary) +{ + nsresult result = NS_ERROR_NOT_INITIALIZED; + + if (!aDictionary) + return NS_ERROR_NULL_POINTER; + + if (mEditor && mSpellChecker) + { + nsAutoString dictStr(aDictionary); + result = mSpellChecker->SetCurrentDictionary(&dictStr); + } + + return result; +} + NS_IMETHODIMP nsEditorShell::CloseSpellChecking() { diff --git a/mozilla/editor/idl/nsIEditorSpellCheck.idl b/mozilla/editor/idl/nsIEditorSpellCheck.idl index 63e48a231ab..d495ea8a438 100644 --- a/mozilla/editor/idl/nsIEditorSpellCheck.idl +++ b/mozilla/editor/idl/nsIEditorSpellCheck.idl @@ -36,6 +36,9 @@ interface nsIEditorSpellCheck : nsISupports wstring GetPersonalDictionaryWord(); 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); + void SetCurrentDictionary(in wstring dictionary); void CloseSpellChecking(); }; diff --git a/mozilla/editor/libeditor/txtsvc/nsISpellChecker.h b/mozilla/editor/libeditor/txtsvc/nsISpellChecker.h index de2bd104e5f..79d775678b6 100644 --- a/mozilla/editor/libeditor/txtsvc/nsISpellChecker.h +++ b/mozilla/editor/libeditor/txtsvc/nsISpellChecker.h @@ -102,6 +102,32 @@ public: * list of words in the user's personal dictionary. */ NS_IMETHOD GetPersonalDictionary(nsStringArray *aWordList) = 0; + + /** + * Returns the list of strings representing the dictionaries + * the spellchecker supports. It was suggested that the strings + * returned be in the RFC 1766 format. This format looks something + * like -. + * For example: en-US + * @param aDictionaryList is an array of nsStrings that represent the + * dictionaries supported by the spellchecker. + */ + NS_IMETHOD GetDictionaryList(nsStringArray *aDictionaryList) = 0; + + /** + * Returns a string representing the current dictionary. + * @param aDictionary will contain the name of the dictionary. + * This name is the same string that is in the list returned + * by GetDictionaryList(). + */ + NS_IMETHOD GetCurrentDictionary(nsString *aDictionary) = 0; + + /** + * Tells the spellchecker to use a specific dictionary. + * @param aDictionary a string that is in the list returned + * by GetDictionaryList(). + */ + NS_IMETHOD SetCurrentDictionary(const nsString *aDictionary) = 0; }; #endif // nsISpellChecker_h__ diff --git a/mozilla/editor/txtsvc/public/nsISpellChecker.h b/mozilla/editor/txtsvc/public/nsISpellChecker.h index de2bd104e5f..79d775678b6 100644 --- a/mozilla/editor/txtsvc/public/nsISpellChecker.h +++ b/mozilla/editor/txtsvc/public/nsISpellChecker.h @@ -102,6 +102,32 @@ public: * list of words in the user's personal dictionary. */ NS_IMETHOD GetPersonalDictionary(nsStringArray *aWordList) = 0; + + /** + * Returns the list of strings representing the dictionaries + * the spellchecker supports. It was suggested that the strings + * returned be in the RFC 1766 format. This format looks something + * like -. + * For example: en-US + * @param aDictionaryList is an array of nsStrings that represent the + * dictionaries supported by the spellchecker. + */ + NS_IMETHOD GetDictionaryList(nsStringArray *aDictionaryList) = 0; + + /** + * Returns a string representing the current dictionary. + * @param aDictionary will contain the name of the dictionary. + * This name is the same string that is in the list returned + * by GetDictionaryList(). + */ + NS_IMETHOD GetCurrentDictionary(nsString *aDictionary) = 0; + + /** + * Tells the spellchecker to use a specific dictionary. + * @param aDictionary a string that is in the list returned + * by GetDictionaryList(). + */ + NS_IMETHOD SetCurrentDictionary(const nsString *aDictionary) = 0; }; #endif // nsISpellChecker_h__ diff --git a/mozilla/editor/ui/dialogs/content/EdDialogCommon.js b/mozilla/editor/ui/dialogs/content/EdDialogCommon.js index 1f97bd2c7dc..cc16fcdf8c3 100644 --- a/mozilla/editor/ui/dialogs/content/EdDialogCommon.js +++ b/mozilla/editor/ui/dialogs/content/EdDialogCommon.js @@ -354,6 +354,35 @@ function AppendStringToMenulist(menulist, string) return null; } +function AppendValueAndDataToMenulist(menulist, valueStr, dataStr) +{ + if (menulist) + { + var menupopup = menulist.firstChild; + // May not have any popup yet -- so create one + if (!menupopup) + { + menupopup = document.createElement("menupopup"); + if (menupopup) + menulist.appendChild(menupopup); + else + { + dump("Failed to create menupoup\n"); + return null; + } + } + menuItem = document.createElement("menuitem"); + if (menuItem) + { + menuItem.setAttribute("value", valueStr); + menuItem.setAttribute("data", dataStr); + menupopup.appendChild(menuItem); + return menuItem; + } + } + return null; +} + function ClearMenulist(menulist) { // There is usually not more than 1 menupopup under a menulist, diff --git a/mozilla/editor/ui/dialogs/content/EdSpellCheck.js b/mozilla/editor/ui/dialogs/content/EdSpellCheck.js index 14d6eb1530b..59e7b9668da 100644 --- a/mozilla/editor/ui/dialogs/content/EdSpellCheck.js +++ b/mozilla/editor/ui/dialogs/content/EdSpellCheck.js @@ -75,15 +75,67 @@ function Startup() // Initial replace word is the misspelled word; dialog.ReplaceWordInput.value = MisspelledWord; - //Use English for now TODO: Kin needs to finish this work so we can fill in list - - dump("Language Listed Index = "+dialog.LanguageMenulist.selectedIndex+"\n"); + if (dialog.LanguageMenulist) + InitLanguageMenu(""); DoEnabling(); dialog.SuggestedList.focus(); } +function InitLanguageMenu(defaultLangStr) +{ + ClearMenulist(dialog.LanguageMenulist); + + var o1 = {}; + var o2 = {}; + + // Get the list of dictionaries from + // the spellchecker. + + spellChecker.GetDictionaryList(o1, o2); + + var dictList = o1.value; + var count = o2.value; + + // Load the string bundle that will help us map + // RFC 1766 strings to UI strings. + + var bundle = srGetStrBundle("resource:/res/acceptlanguage.properties"); + var menuStr; + var defaultIndex = 0; + + for (var i = 0; i < dictList.length; i++) + { + try { + menuStr = bundle.GetStringFromName(dictList[i]+".title"); + + if (!menuStr) + menuStr = dictList[i]; + + if (defaultLangStr && dictList[i] == defaultLangStr) + defaultIndex = i; + } catch (ex) { + // GetStringFromName throws an exception when + // a key is not found in the bundle. In that + // case, just use the original dictList string. + + menuStr = dictList[i]; + } + + 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! + + if (dictList.length > 0) + { + dialog.LanguageMenulist.selectedIndex = defaultIndex; + // SelectLanguage(); + } +} + function DoEnabling() { if (MisspelledWord.length == 0) @@ -225,8 +277,13 @@ function EditDictionary() function SelectLanguage() { - // A bug in combobox prevents this from working - dump("SpellCheck: SelectLanguage.\n"); + var item = dialog.LanguageMenulist.selectedItem; + + try { + spellChecker.SetCurrentDictionary(item.data); + } catch (ex) { + dump(ex); + } } function Recheck() diff --git a/mozilla/editor/ui/dialogs/content/EdSpellCheck.xul b/mozilla/editor/ui/dialogs/content/EdSpellCheck.xul index e08e291e503..1d465b0af35 100644 --- a/mozilla/editor/ui/dialogs/content/EdSpellCheck.xul +++ b/mozilla/editor/ui/dialogs/content/EdSpellCheck.xul @@ -35,6 +35,7 @@ +