diff --git a/mozilla/editor/base/nsEditorShell.cpp b/mozilla/editor/base/nsEditorShell.cpp index 291da3b7ac9..73f0963e0aa 100644 --- a/mozilla/editor/base/nsEditorShell.cpp +++ b/mozilla/editor/base/nsEditorShell.cpp @@ -130,19 +130,20 @@ NS_NewEditorShell(nsIEditorShell** aEditorShell) ///////////////////////////////////////////////////////////////////////// nsEditorShell::nsEditorShell() -: mSuggestedWordIndex(0) -, mToolbarWindow(nsnull) +: mToolbarWindow(nsnull) , mContentWindow(nsnull) , mWebShellWin(nsnull) , mWebShell(nsnull) , mContentAreaWebShell(nsnull) , mEditorType(eUninitializedEditorType) , mWrapColumn(0) +, mSuggestedWordIndex(0) +, mDictionaryIndex(0) { #ifdef APP_DEBUG printf("Created nsEditorShell\n"); #endif - + NS_INIT_REFCNT(); } @@ -609,6 +610,13 @@ NS_IMETHODIMP nsEditorShell::SetBackgroundColor(const PRUnichar *color) result = htmlEditor->SetBackgroundColor(aColor); break; } + case ePlainTextEditorType: + { + nsCOMPtr textEditor = do_QueryInterface(mEditor); + if (textEditor) + result = textEditor->SetBackgroundColor(aColor); + } + break; default: result = NS_ERROR_NOT_IMPLEMENTED; } @@ -2019,10 +2027,10 @@ nsEditorShell::SetSelectionAfterElement(nsIDOMElement* aElement) } NS_IMETHODIMP -nsEditorShell::StartSpellChecking(PRUnichar **firstMisspelledWord) +nsEditorShell::StartSpellChecking(PRUnichar **aFirstMisspelledWord) { nsresult result = NS_NOINTERFACE; - nsAutoString aFirstMisspelledWord; + nsAutoString firstMisspelledWord; // We can spell check with any editor type if (mEditor) { @@ -2068,125 +2076,148 @@ nsEditorShell::StartSpellChecking(PRUnichar **firstMisspelledWord) DeleteSuggestedWordList(); // Return the first misspelled word and initialize the suggested list - result = mSpellChecker->NextMisspelledWord(&aFirstMisspelledWord, &mSuggestedWordList); + result = mSpellChecker->NextMisspelledWord(&firstMisspelledWord, &mSuggestedWordList); } - *firstMisspelledWord = aFirstMisspelledWord.ToNewUnicode(); + *aFirstMisspelledWord = firstMisspelledWord.ToNewUnicode(); return result; } NS_IMETHODIMP -nsEditorShell::GetNextMisspelledWord(PRUnichar **nextMisspelledWord) +nsEditorShell::GetNextMisspelledWord(PRUnichar **aNextMisspelledWord) { nsresult result = NS_NOINTERFACE; - nsAutoString aNextMisspelledWord; + nsAutoString nextMisspelledWord; // We can spell check with any editor type if (mEditor && mSpellChecker) { DeleteSuggestedWordList(); - result = mSpellChecker->NextMisspelledWord(&aNextMisspelledWord, &mSuggestedWordList); + result = mSpellChecker->NextMisspelledWord(&nextMisspelledWord, &mSuggestedWordList); } - *nextMisspelledWord = aNextMisspelledWord.ToNewUnicode(); + *aNextMisspelledWord = nextMisspelledWord.ToNewUnicode(); return result; } NS_IMETHODIMP -nsEditorShell::GetSuggestedWord(PRUnichar **suggestedWord) +nsEditorShell::GetSuggestedWord(PRUnichar **aSuggestedWord) { nsresult result = NS_NOINTERFACE; - nsAutoString aSuggestedWord; + nsAutoString word; // We can spell check with any editor type if (mEditor) { if ( mSuggestedWordIndex < mSuggestedWordList.Count()) { - mSuggestedWordList.StringAt(mSuggestedWordIndex, aSuggestedWord); + mSuggestedWordList.StringAt(mSuggestedWordIndex, word); mSuggestedWordIndex++; } else { // A blank string signals that there are no more strings - aSuggestedWord = ""; + word = ""; } result = NS_OK; } - *suggestedWord = aSuggestedWord.ToNewUnicode(); + *aSuggestedWord = word.ToNewUnicode(); return result; } NS_IMETHODIMP -nsEditorShell::CheckCurrentWord(const PRUnichar *suggestedWord, PRBool *aIsMisspelled) +nsEditorShell::CheckCurrentWord(const PRUnichar *aSuggestedWord, PRBool *aIsMisspelled) { nsresult result = NS_NOINTERFACE; - nsAutoString aSuggestedWord(suggestedWord); + nsAutoString suggestedWord(aSuggestedWord); // We can spell check with any editor type if (mEditor && mSpellChecker) { DeleteSuggestedWordList(); - result = mSpellChecker->CheckWord(&aSuggestedWord, aIsMisspelled, &mSuggestedWordList); + result = mSpellChecker->CheckWord(&suggestedWord, aIsMisspelled, &mSuggestedWordList); } return result; } NS_IMETHODIMP -nsEditorShell::ReplaceWord(const PRUnichar *misspelledWord, const PRUnichar *replaceWord, PRBool allOccurrences) +nsEditorShell::ReplaceWord(const PRUnichar *aMisspelledWord, const PRUnichar *aReplaceWord, PRBool allOccurrences) { nsresult result = NS_NOINTERFACE; - nsAutoString aMisspelledWord(misspelledWord); - nsAutoString aReplaceWord(replaceWord); + nsAutoString misspelledWord(aMisspelledWord); + nsAutoString replaceWord(aReplaceWord); if (mEditor && mSpellChecker) { - result = mSpellChecker->Replace(&aMisspelledWord, &aReplaceWord, allOccurrences); + result = mSpellChecker->Replace(&misspelledWord, &replaceWord, allOccurrences); } return result; } NS_IMETHODIMP -nsEditorShell::IgnoreWordAllOccurrences(const PRUnichar *word) +nsEditorShell::IgnoreWordAllOccurrences(const PRUnichar *aWord) { nsresult result = NS_NOINTERFACE; - nsAutoString aWord(word); + nsAutoString word(aWord); if (mEditor && mSpellChecker) { - result = mSpellChecker->IgnoreAll(&aWord); + result = mSpellChecker->IgnoreAll(&word); } return result; } NS_IMETHODIMP -nsEditorShell::AddWordToDictionary(const PRUnichar *word) +nsEditorShell::GetPersonalDictionary() { nsresult result = NS_NOINTERFACE; - nsAutoString aWord(word); + // We can spell check with any editor type if (mEditor && mSpellChecker) { - result = mSpellChecker->AddWordToPersonalDictionary(&aWord); + mDictionaryList.Clear(); + mDictionaryIndex = 0; + result = mSpellChecker->GetPersonalDictionary(&mDictionaryList); } return result; } NS_IMETHODIMP -nsEditorShell::RemoveWordFromDictionary(const PRUnichar *word) +nsEditorShell::GetPersonalDictionaryWord(PRUnichar **aDictionaryWord) { nsresult result = NS_NOINTERFACE; - nsAutoString aWord(word); + nsAutoString word; + if (mEditor) + { + if ( mDictionaryIndex < mDictionaryList.Count()) + { + mDictionaryList.StringAt(mDictionaryIndex, word); + mDictionaryIndex++; + } else { + // A blank string signals that there are no more strings + word = ""; + } + result = NS_OK; + } + *aDictionaryWord = word.ToNewUnicode(); + return result; +} + +NS_IMETHODIMP +nsEditorShell::AddWordToDictionary(const PRUnichar *aWord) +{ + nsresult result = NS_NOINTERFACE; + nsString word(aWord); if (mEditor && mSpellChecker) { - result = mSpellChecker->RemoveWordFromPersonalDictionary(&aWord); + result = mSpellChecker->AddWordToPersonalDictionary(&word); } return result; } NS_IMETHODIMP -nsEditorShell::GetPersonalDictionaryWord(const PRUnichar *word, PRUnichar **suggestedWord) +nsEditorShell::RemoveWordFromDictionary(const PRUnichar *aWord) { nsresult result = NS_NOINTERFACE; + nsString word(aWord); if (mEditor && mSpellChecker) { - printf("GetPersonalDictionaryWord NOT IMPLEMENTED\n"); + result = mSpellChecker->RemoveWordFromPersonalDictionary(&word); } return result; } - NS_IMETHODIMP nsEditorShell::CloseSpellChecking() { @@ -2196,6 +2227,8 @@ nsEditorShell::CloseSpellChecking() { // Cleanup - kill the spell checker DeleteSuggestedWordList(); + mDictionaryList.Clear(); + mDictionaryIndex = 0; mSpellChecker = 0; result = NS_OK; } diff --git a/mozilla/editor/base/nsEditorShell.h b/mozilla/editor/base/nsEditorShell.h index 9106bd16543..b6ee11b59f6 100644 --- a/mozilla/editor/base/nsEditorShell.h +++ b/mozilla/editor/base/nsEditorShell.h @@ -184,16 +184,17 @@ class nsEditorShell : public nsIEditorShell, /* Spell check interface */ - NS_IMETHOD StartSpellChecking(PRUnichar **_retval); - NS_IMETHOD GetNextMisspelledWord(PRUnichar **_retval); - NS_IMETHOD GetSuggestedWord(PRUnichar **_retval); - NS_IMETHOD CheckCurrentWord(const PRUnichar *suggestedWord, PRBool *_retval); - NS_IMETHOD ReplaceWord(const PRUnichar *misspelledWord, const PRUnichar *replaceWord, PRBool allOccurrences); - NS_IMETHOD IgnoreWordAllOccurrences(const PRUnichar *word); - NS_IMETHOD AddWordToDictionary(const PRUnichar *word); - NS_IMETHOD RemoveWordFromDictionary(const PRUnichar *word); - NS_IMETHOD GetPersonalDictionaryWord(const PRUnichar *word, PRUnichar **_retval); - NS_IMETHOD CloseSpellChecking(); + NS_IMETHOD StartSpellChecking(PRUnichar **_retval); + NS_IMETHOD GetNextMisspelledWord(PRUnichar **_retval); + NS_IMETHOD GetSuggestedWord(PRUnichar **_retval); + NS_IMETHOD CheckCurrentWord(const PRUnichar *suggestedWord, PRBool *_retval); + NS_IMETHOD ReplaceWord(const PRUnichar *misspelledWord, const PRUnichar *replaceWord, PRBool allOccurrences); + NS_IMETHOD IgnoreWordAllOccurrences(const PRUnichar *word); + NS_IMETHOD GetPersonalDictionary(); + NS_IMETHOD GetPersonalDictionaryWord(PRUnichar **_retval); + NS_IMETHOD AddWordToDictionary(const PRUnichar *word); + NS_IMETHOD RemoveWordFromDictionary(const PRUnichar *word); + NS_IMETHOD CloseSpellChecking(); // nsIDocumentLoaderObserver diff --git a/mozilla/editor/composer/src/nsEditorShell.cpp b/mozilla/editor/composer/src/nsEditorShell.cpp index 291da3b7ac9..73f0963e0aa 100644 --- a/mozilla/editor/composer/src/nsEditorShell.cpp +++ b/mozilla/editor/composer/src/nsEditorShell.cpp @@ -130,19 +130,20 @@ NS_NewEditorShell(nsIEditorShell** aEditorShell) ///////////////////////////////////////////////////////////////////////// nsEditorShell::nsEditorShell() -: mSuggestedWordIndex(0) -, mToolbarWindow(nsnull) +: mToolbarWindow(nsnull) , mContentWindow(nsnull) , mWebShellWin(nsnull) , mWebShell(nsnull) , mContentAreaWebShell(nsnull) , mEditorType(eUninitializedEditorType) , mWrapColumn(0) +, mSuggestedWordIndex(0) +, mDictionaryIndex(0) { #ifdef APP_DEBUG printf("Created nsEditorShell\n"); #endif - + NS_INIT_REFCNT(); } @@ -609,6 +610,13 @@ NS_IMETHODIMP nsEditorShell::SetBackgroundColor(const PRUnichar *color) result = htmlEditor->SetBackgroundColor(aColor); break; } + case ePlainTextEditorType: + { + nsCOMPtr textEditor = do_QueryInterface(mEditor); + if (textEditor) + result = textEditor->SetBackgroundColor(aColor); + } + break; default: result = NS_ERROR_NOT_IMPLEMENTED; } @@ -2019,10 +2027,10 @@ nsEditorShell::SetSelectionAfterElement(nsIDOMElement* aElement) } NS_IMETHODIMP -nsEditorShell::StartSpellChecking(PRUnichar **firstMisspelledWord) +nsEditorShell::StartSpellChecking(PRUnichar **aFirstMisspelledWord) { nsresult result = NS_NOINTERFACE; - nsAutoString aFirstMisspelledWord; + nsAutoString firstMisspelledWord; // We can spell check with any editor type if (mEditor) { @@ -2068,125 +2076,148 @@ nsEditorShell::StartSpellChecking(PRUnichar **firstMisspelledWord) DeleteSuggestedWordList(); // Return the first misspelled word and initialize the suggested list - result = mSpellChecker->NextMisspelledWord(&aFirstMisspelledWord, &mSuggestedWordList); + result = mSpellChecker->NextMisspelledWord(&firstMisspelledWord, &mSuggestedWordList); } - *firstMisspelledWord = aFirstMisspelledWord.ToNewUnicode(); + *aFirstMisspelledWord = firstMisspelledWord.ToNewUnicode(); return result; } NS_IMETHODIMP -nsEditorShell::GetNextMisspelledWord(PRUnichar **nextMisspelledWord) +nsEditorShell::GetNextMisspelledWord(PRUnichar **aNextMisspelledWord) { nsresult result = NS_NOINTERFACE; - nsAutoString aNextMisspelledWord; + nsAutoString nextMisspelledWord; // We can spell check with any editor type if (mEditor && mSpellChecker) { DeleteSuggestedWordList(); - result = mSpellChecker->NextMisspelledWord(&aNextMisspelledWord, &mSuggestedWordList); + result = mSpellChecker->NextMisspelledWord(&nextMisspelledWord, &mSuggestedWordList); } - *nextMisspelledWord = aNextMisspelledWord.ToNewUnicode(); + *aNextMisspelledWord = nextMisspelledWord.ToNewUnicode(); return result; } NS_IMETHODIMP -nsEditorShell::GetSuggestedWord(PRUnichar **suggestedWord) +nsEditorShell::GetSuggestedWord(PRUnichar **aSuggestedWord) { nsresult result = NS_NOINTERFACE; - nsAutoString aSuggestedWord; + nsAutoString word; // We can spell check with any editor type if (mEditor) { if ( mSuggestedWordIndex < mSuggestedWordList.Count()) { - mSuggestedWordList.StringAt(mSuggestedWordIndex, aSuggestedWord); + mSuggestedWordList.StringAt(mSuggestedWordIndex, word); mSuggestedWordIndex++; } else { // A blank string signals that there are no more strings - aSuggestedWord = ""; + word = ""; } result = NS_OK; } - *suggestedWord = aSuggestedWord.ToNewUnicode(); + *aSuggestedWord = word.ToNewUnicode(); return result; } NS_IMETHODIMP -nsEditorShell::CheckCurrentWord(const PRUnichar *suggestedWord, PRBool *aIsMisspelled) +nsEditorShell::CheckCurrentWord(const PRUnichar *aSuggestedWord, PRBool *aIsMisspelled) { nsresult result = NS_NOINTERFACE; - nsAutoString aSuggestedWord(suggestedWord); + nsAutoString suggestedWord(aSuggestedWord); // We can spell check with any editor type if (mEditor && mSpellChecker) { DeleteSuggestedWordList(); - result = mSpellChecker->CheckWord(&aSuggestedWord, aIsMisspelled, &mSuggestedWordList); + result = mSpellChecker->CheckWord(&suggestedWord, aIsMisspelled, &mSuggestedWordList); } return result; } NS_IMETHODIMP -nsEditorShell::ReplaceWord(const PRUnichar *misspelledWord, const PRUnichar *replaceWord, PRBool allOccurrences) +nsEditorShell::ReplaceWord(const PRUnichar *aMisspelledWord, const PRUnichar *aReplaceWord, PRBool allOccurrences) { nsresult result = NS_NOINTERFACE; - nsAutoString aMisspelledWord(misspelledWord); - nsAutoString aReplaceWord(replaceWord); + nsAutoString misspelledWord(aMisspelledWord); + nsAutoString replaceWord(aReplaceWord); if (mEditor && mSpellChecker) { - result = mSpellChecker->Replace(&aMisspelledWord, &aReplaceWord, allOccurrences); + result = mSpellChecker->Replace(&misspelledWord, &replaceWord, allOccurrences); } return result; } NS_IMETHODIMP -nsEditorShell::IgnoreWordAllOccurrences(const PRUnichar *word) +nsEditorShell::IgnoreWordAllOccurrences(const PRUnichar *aWord) { nsresult result = NS_NOINTERFACE; - nsAutoString aWord(word); + nsAutoString word(aWord); if (mEditor && mSpellChecker) { - result = mSpellChecker->IgnoreAll(&aWord); + result = mSpellChecker->IgnoreAll(&word); } return result; } NS_IMETHODIMP -nsEditorShell::AddWordToDictionary(const PRUnichar *word) +nsEditorShell::GetPersonalDictionary() { nsresult result = NS_NOINTERFACE; - nsAutoString aWord(word); + // We can spell check with any editor type if (mEditor && mSpellChecker) { - result = mSpellChecker->AddWordToPersonalDictionary(&aWord); + mDictionaryList.Clear(); + mDictionaryIndex = 0; + result = mSpellChecker->GetPersonalDictionary(&mDictionaryList); } return result; } NS_IMETHODIMP -nsEditorShell::RemoveWordFromDictionary(const PRUnichar *word) +nsEditorShell::GetPersonalDictionaryWord(PRUnichar **aDictionaryWord) { nsresult result = NS_NOINTERFACE; - nsAutoString aWord(word); + nsAutoString word; + if (mEditor) + { + if ( mDictionaryIndex < mDictionaryList.Count()) + { + mDictionaryList.StringAt(mDictionaryIndex, word); + mDictionaryIndex++; + } else { + // A blank string signals that there are no more strings + word = ""; + } + result = NS_OK; + } + *aDictionaryWord = word.ToNewUnicode(); + return result; +} + +NS_IMETHODIMP +nsEditorShell::AddWordToDictionary(const PRUnichar *aWord) +{ + nsresult result = NS_NOINTERFACE; + nsString word(aWord); if (mEditor && mSpellChecker) { - result = mSpellChecker->RemoveWordFromPersonalDictionary(&aWord); + result = mSpellChecker->AddWordToPersonalDictionary(&word); } return result; } NS_IMETHODIMP -nsEditorShell::GetPersonalDictionaryWord(const PRUnichar *word, PRUnichar **suggestedWord) +nsEditorShell::RemoveWordFromDictionary(const PRUnichar *aWord) { nsresult result = NS_NOINTERFACE; + nsString word(aWord); if (mEditor && mSpellChecker) { - printf("GetPersonalDictionaryWord NOT IMPLEMENTED\n"); + result = mSpellChecker->RemoveWordFromPersonalDictionary(&word); } return result; } - NS_IMETHODIMP nsEditorShell::CloseSpellChecking() { @@ -2196,6 +2227,8 @@ nsEditorShell::CloseSpellChecking() { // Cleanup - kill the spell checker DeleteSuggestedWordList(); + mDictionaryList.Clear(); + mDictionaryIndex = 0; mSpellChecker = 0; result = NS_OK; } diff --git a/mozilla/editor/composer/src/nsEditorShell.h b/mozilla/editor/composer/src/nsEditorShell.h index 9106bd16543..b6ee11b59f6 100644 --- a/mozilla/editor/composer/src/nsEditorShell.h +++ b/mozilla/editor/composer/src/nsEditorShell.h @@ -184,16 +184,17 @@ class nsEditorShell : public nsIEditorShell, /* Spell check interface */ - NS_IMETHOD StartSpellChecking(PRUnichar **_retval); - NS_IMETHOD GetNextMisspelledWord(PRUnichar **_retval); - NS_IMETHOD GetSuggestedWord(PRUnichar **_retval); - NS_IMETHOD CheckCurrentWord(const PRUnichar *suggestedWord, PRBool *_retval); - NS_IMETHOD ReplaceWord(const PRUnichar *misspelledWord, const PRUnichar *replaceWord, PRBool allOccurrences); - NS_IMETHOD IgnoreWordAllOccurrences(const PRUnichar *word); - NS_IMETHOD AddWordToDictionary(const PRUnichar *word); - NS_IMETHOD RemoveWordFromDictionary(const PRUnichar *word); - NS_IMETHOD GetPersonalDictionaryWord(const PRUnichar *word, PRUnichar **_retval); - NS_IMETHOD CloseSpellChecking(); + NS_IMETHOD StartSpellChecking(PRUnichar **_retval); + NS_IMETHOD GetNextMisspelledWord(PRUnichar **_retval); + NS_IMETHOD GetSuggestedWord(PRUnichar **_retval); + NS_IMETHOD CheckCurrentWord(const PRUnichar *suggestedWord, PRBool *_retval); + NS_IMETHOD ReplaceWord(const PRUnichar *misspelledWord, const PRUnichar *replaceWord, PRBool allOccurrences); + NS_IMETHOD IgnoreWordAllOccurrences(const PRUnichar *word); + NS_IMETHOD GetPersonalDictionary(); + NS_IMETHOD GetPersonalDictionaryWord(PRUnichar **_retval); + NS_IMETHOD AddWordToDictionary(const PRUnichar *word); + NS_IMETHOD RemoveWordFromDictionary(const PRUnichar *word); + NS_IMETHOD CloseSpellChecking(); // nsIDocumentLoaderObserver diff --git a/mozilla/editor/idl/nsIEditorSpellCheck.idl b/mozilla/editor/idl/nsIEditorSpellCheck.idl index e39ce2f8a7f..3b3802cf676 100644 --- a/mozilla/editor/idl/nsIEditorSpellCheck.idl +++ b/mozilla/editor/idl/nsIEditorSpellCheck.idl @@ -28,9 +28,10 @@ interface nsIEditorSpellCheck : nsISupports boolean CheckCurrentWord(in wstring suggestedWord); void ReplaceWord(in wstring misspelledWord, in wstring replaceWord, in boolean allOccurrences); void IgnoreWordAllOccurrences(in wstring word); + void GetPersonalDictionary(); + wstring GetPersonalDictionaryWord(); void AddWordToDictionary(in wstring word); void RemoveWordFromDictionary(in wstring word); - wstring GetPersonalDictionaryWord(in wstring word); void CloseSpellChecking(); }; diff --git a/mozilla/editor/ui/dialogs/content/EdDialogCommon.js b/mozilla/editor/ui/dialogs/content/EdDialogCommon.js index 26dfc8b7548..37805d797ed 100644 --- a/mozilla/editor/ui/dialogs/content/EdDialogCommon.js +++ b/mozilla/editor/ui/dialogs/content/EdDialogCommon.js @@ -27,6 +27,37 @@ function ClearList(list) } } +function ReplaceStringInList(list, index, string) +{ + //Hmmm... We should be able to simply set the "text" and "value" + // properties of the option element, but setting "text" doesn't work. + // Replace with a new node instead: + if (index < list.options.length) + { +/* + node = list.options[index]; + dump("BEFORE Option node text: "+node.text+" Value: "+node.value+"\n"); + node.text = string; + node.value = string; + dump("AFTER Option node text: "+node.text+" Value: "+node.value+"\n"); +*/ + // Save and remove selection else we have trouble below! + // (This must be a bug!) + selIndex = list.selectedIndex; + list.selectedIndex = -1; + + optionNode = new Option(string, string); + // Remove existing option node + //list.remove(index); + list.options[index] = null; + // Insert the new node + list.options[index] = optionNode; + // NOTE: If we insert, then remove, we crash! + // Reset the selected item + list.selectedIndex = selIndex; + } +} + function AppendStringToList(list, string) { diff --git a/mozilla/editor/ui/dialogs/content/EdDictionary.js b/mozilla/editor/ui/dialogs/content/EdDictionary.js index cfea6fd9fe1..87e12a863a3 100644 --- a/mozilla/editor/ui/dialogs/content/EdDictionary.js +++ b/mozilla/editor/ui/dialogs/content/EdDictionary.js @@ -1,4 +1,7 @@ var spellChecker; +var WordToAdd; +var WordInput; +var DictionaryList; function Startup() { @@ -12,38 +15,125 @@ function Startup() dump("SpellChecker not found!!!\n"); window.close(); } + // The word to add word is passed as the 2nd extra parameter in window.openDialog() + WordToAdd = window.arguments[1]; - // Create dialog object to store controls for easy access - dialog = new Object; - // GET EACH CONTROL -- E.G.: - //dialog.editBox = document.getElementById("editBox"); - - // SET FOCUS TO FIRST CONTROL - //dialog.editBox.focus(); + WordInput = document.getElementById("WordInput"); + DictionaryList = document.getElementById("DictionaryList"); + + WordInput.value = WordToAdd; + FillDictionaryList(); + // Select the supplied word if it is already in the list + SelectWordToAddInList(); + WordInput.focus(); } -function SelectWord() +function ValidateWordToAdd() { - dump("SelectWord\n"); + WordToAdd = TrimString(WordInput.value); + if (WordToAdd.length > 0) { + return true; + } else { + return false; + } +} + +function SelectWordToAddInList() +{ + for (index = 0; index < DictionaryList.length; index++) { + if (WordToAdd.toLowerCase() == DictionaryList.options[index].text.toLowerCase()) { + DictionaryList.selectedIndex = index; + break; + } + } } function AddWord() { - dump("AddWord\n"); + if (ValidateWordToAdd()) { + try { + spellChecker.AddWordToDictionary(WordToAdd); + } + catch (e) { + dump("Exception occured in spellChecker.AddWordToDictionary\nWord to add probably already existed"); + } + + // Rebuild the dialog list + FillDictionaryList(); + + SelectWordToAddInList(); + } } function ReplaceWord() { - dump("ReplaceWord\n"); + if (ValidateWordToAdd()) { + selIndex = DictionaryList.selectedIndex; + if (selIndex >= 0) { + WordToRemove = DictionaryList.options[selIndex].text; + dump("Word to remove: "+WordToRemove+"\n"); + spellChecker.RemoveWordFromDictionary(WordToRemove); + try { + // Add to the dictionary list + spellChecker.AddWordToDictionary(WordToAdd); + // Just change the text on the selected item + // instead of rebuilding the list + ReplaceStringInList(DictionaryList, selIndex, WordToAdd); + } catch (e) { + // Rebuild list and select the word - it was probably already in the list + dump("Exception occured adding word in ReplaceWord\n"); + FillDictionaryList(); + SelectWordToAddInList(); + } + } + } } function RemoveWord() { - dump("RemoveWord\n"); + selIndex = DictionaryList.selectedIndex; + if (selIndex >= 0) { + word = TrimString(DictionaryList.options[selIndex].text); + // Remove word from list + DictionaryList.options[selIndex] = null; + // Remove from dictionary + spellChecker.RemoveWordFromDictionary(word); + + ResetSelectedItem(selIndex); + } } - -function onOK() +function FillDictionaryList() { - window.close(); + selIndex = DictionaryList.selectedIndex; + + // Clear the current contents of the list + ClearList(DictionaryList); + // Get the list from the spell checker + spellChecker.GetPersonalDictionary() + + // Get words until an empty string is returned + do { + word = spellChecker.GetPersonalDictionaryWord(); + if (word != "") { + AppendStringToList(DictionaryList, word); + } + } while (word != ""); + + ResetSelectedItem(selIndex); } + +function ResetSelectedItem(index) +{ + lastIndex = DictionaryList.length - 1; + if (index > lastIndex) + index = lastIndex; + + // If we didn't have a selected item, + // set it to the first item + if (index == -1 && lastIndex >= 0) + index = 0; + + DictionaryList.selectedIndex = index; +} + diff --git a/mozilla/editor/ui/dialogs/content/EdDictionary.xul b/mozilla/editor/ui/dialogs/content/EdDictionary.xul index 055232400b8..54e47ebbbeb 100644 --- a/mozilla/editor/ui/dialogs/content/EdDictionary.xul +++ b/mozilla/editor/ui/dialogs/content/EdDictionary.xul @@ -20,12 +20,12 @@ - -
- NewWord
+ New word:
- + @@ -33,31 +33,22 @@
- Words: + Words in dictionary:
-

+
+ +
- - - - - - - diff --git a/mozilla/editor/ui/dialogs/content/EdMessage.js b/mozilla/editor/ui/dialogs/content/EdMessage.js index 8f5430888fc..bda854429c1 100644 --- a/mozilla/editor/ui/dialogs/content/EdMessage.js +++ b/mozilla/editor/ui/dialogs/content/EdMessage.js @@ -57,6 +57,7 @@ function Startup() button1 = document.getElementById("button1"); button2 = document.getElementById("button2"); button3 = document.getElementById("button3"); + button4 = document.getElementById("button4"); // All buttons must have the same parent buttonParent = button1.parentNode; @@ -87,6 +88,15 @@ function Startup() } else { buttonParent.removeChild(button3); } + + button4Text = window.arguments[6]; + if (button4Text && button4Text.length > 0) + { + dump(button4Text+"\n"); + button4.setAttribute("value", button4Text); + } else { + buttonParent.removeChild(button4); + } } function onButton1() @@ -106,3 +116,9 @@ function onButton3() window.opener.msgResult = 3; window.close(); } + +function onButton3() +{ + window.opener.msgResult = 4; + window.close(); +} diff --git a/mozilla/editor/ui/dialogs/content/EdMessage.xul b/mozilla/editor/ui/dialogs/content/EdMessage.xul index a5f9e6ceaff..88312b1e522 100644 --- a/mozilla/editor/ui/dialogs/content/EdMessage.xul +++ b/mozilla/editor/ui/dialogs/content/EdMessage.xul @@ -24,6 +24,7 @@ + diff --git a/mozilla/editor/ui/dialogs/content/EdSpellCheck.xul b/mozilla/editor/ui/dialogs/content/EdSpellCheck.xul index 03d3512ee91..469410f7220 100644 --- a/mozilla/editor/ui/dialogs/content/EdSpellCheck.xul +++ b/mozilla/editor/ui/dialogs/content/EdSpellCheck.xul @@ -67,9 +67,6 @@ diff --git a/mozilla/editor/ui/dialogs/skin/EditorDialog.css b/mozilla/editor/ui/dialogs/skin/EditorDialog.css index 928275ec937..de7019d3931 100644 --- a/mozilla/editor/ui/dialogs/skin/EditorDialog.css +++ b/mozilla/editor/ui/dialogs/skin/EditorDialog.css @@ -153,8 +153,12 @@ titledbutton.PixelOrPercent { } titledbutton.SizeToCell { - /* BUG: Setting this to 100% chops off right border of button */ - width: 90%; + width: 100%; +} + +titledbutton.CloseButton { + width: 100%; + margin-top: 10px; } titledbutton.MsgButton {