1999-08-19 18:28:44 +04:00
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code, released
|
|
|
|
* March 31, 1998.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998-1999 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*/
|
|
|
|
|
1999-05-14 00:59:08 +04:00
|
|
|
var misspelledWord;
|
1999-07-14 19:24:33 +04:00
|
|
|
var spellChecker;
|
1999-08-28 06:40:18 +04:00
|
|
|
var allowSelectWord = true;
|
1999-05-14 00:59:08 +04:00
|
|
|
|
|
|
|
// dialog initialization code
|
|
|
|
function Startup()
|
|
|
|
{
|
1999-07-14 19:24:33 +04:00
|
|
|
if (!InitEditorShell())
|
|
|
|
return;
|
|
|
|
dump("EditorShell found for Spell Checker dialog\n");
|
|
|
|
|
|
|
|
// Get the spellChecker shell
|
|
|
|
spellChecker = editorShell.QueryInterface(Components.interfaces.nsIEditorSpellCheck);
|
|
|
|
if (!spellChecker) {
|
|
|
|
dump("SpellChecker not found!!!\n");
|
1999-05-27 01:40:51 +04:00
|
|
|
window.close();
|
1999-05-14 00:59:08 +04:00
|
|
|
}
|
1999-07-14 19:24:33 +04:00
|
|
|
// Save as a property of the window so it can be used by child dialogs
|
|
|
|
window.spellChecker = spellChecker;
|
1999-05-14 00:59:08 +04:00
|
|
|
|
|
|
|
// Create dialog object to store controls for easy access
|
|
|
|
dialog = new Object;
|
|
|
|
if (!dialog)
|
|
|
|
{
|
|
|
|
dump("Failed to create dialog object!!!\n");
|
1999-05-27 01:40:51 +04:00
|
|
|
window.close();
|
1999-05-14 00:59:08 +04:00
|
|
|
}
|
|
|
|
|
2000-01-19 00:53:21 +03:00
|
|
|
dialog.misspelledWord = document.getElementById("MisspelledWord");
|
|
|
|
dialog.replaceWordInput = document.getElementById("ReplaceWord");
|
1999-05-14 00:59:08 +04:00
|
|
|
dialog.suggestedList = document.getElementById("SuggestedList");
|
2000-01-19 00:53:21 +03:00
|
|
|
dialog.languageList = document.getElementById("LanguageList");
|
|
|
|
|
|
|
|
if (!dialog.misspelledWord ||
|
|
|
|
!dialog.replaceWordInput ||
|
1999-05-14 00:59:08 +04:00
|
|
|
!dialog.suggestedList ||
|
|
|
|
!dialog.languageList )
|
|
|
|
{
|
|
|
|
dump("Not all dialog controls were found!!!\n");
|
|
|
|
}
|
|
|
|
// NOTE: We shouldn't have been created if there was no misspelled word
|
|
|
|
|
1999-05-27 01:40:51 +04:00
|
|
|
// The first misspelled word is passed as the 2nd extra parameter in window.openDialog()
|
|
|
|
misspelledWord = window.arguments[1];
|
1999-05-14 00:59:08 +04:00
|
|
|
|
|
|
|
if (misspelledWord != "") {
|
|
|
|
dump("First misspelled word = "+misspelledWord+"\n");
|
2000-01-19 00:53:21 +03:00
|
|
|
// Put word in the borderless button used to show the misspelled word
|
|
|
|
dialog.misspelledWord.setAttribute("value", misspelledWord);
|
1999-05-27 01:40:51 +04:00
|
|
|
// Get the list of suggested replacements
|
1999-05-14 00:59:08 +04:00
|
|
|
FillSuggestedList();
|
|
|
|
} else {
|
|
|
|
dump("No misspelled word found\n");
|
2000-04-04 18:51:26 +04:00
|
|
|
// No more words - we're done!
|
|
|
|
Close();
|
1999-05-14 00:59:08 +04:00
|
|
|
}
|
2000-01-19 00:53:21 +03:00
|
|
|
// 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
|
|
|
|
dialog.languageList.selectedIndex = 0;
|
|
|
|
dump("Language Listed Index = "+dialog.languageList.selectedIndex+"\n");
|
1999-05-14 00:59:08 +04:00
|
|
|
|
|
|
|
dialog.suggestedList.focus();
|
|
|
|
}
|
1999-05-27 01:40:51 +04:00
|
|
|
|
1999-05-14 00:59:08 +04:00
|
|
|
function NextWord()
|
|
|
|
{
|
1999-07-14 19:24:33 +04:00
|
|
|
misspelledWord = spellChecker.GetNextMisspelledWord();
|
2000-01-19 00:53:21 +03:00
|
|
|
dialog.misspelledWord.setAttribute("value",misspelledWord);
|
|
|
|
|
1999-05-14 00:59:08 +04:00
|
|
|
if (misspelledWord == "") {
|
|
|
|
dump("FINISHED SPELL CHECKING\n");
|
2000-04-04 18:51:26 +04:00
|
|
|
// Simply close dialog when finished.
|
|
|
|
Close();
|
1999-05-14 00:59:08 +04:00
|
|
|
} else {
|
|
|
|
FillSuggestedList();
|
|
|
|
}
|
2000-01-19 00:53:21 +03:00
|
|
|
// Initial replace word is misspelled word
|
|
|
|
dialog.replaceWordInput.value = misspelledWord;
|
1999-05-14 00:59:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function CheckWord()
|
|
|
|
{
|
2000-01-19 00:53:21 +03:00
|
|
|
//dump("SpellCheck: CheckWord\n");
|
|
|
|
word = dialog.replaceWordInput.value;
|
1999-05-14 00:59:08 +04:00
|
|
|
if (word != "") {
|
2000-01-19 00:53:21 +03:00
|
|
|
//dump("CheckWord: Word in edit field="+word+"\n");
|
1999-07-14 19:24:33 +04:00
|
|
|
isMisspelled = spellChecker.CheckCurrentWord(word);
|
1999-05-27 01:40:51 +04:00
|
|
|
if (isMisspelled) {
|
|
|
|
dump("CheckWord says word was misspelled\n");
|
|
|
|
misspelledWord = word;
|
|
|
|
FillSuggestedList();
|
|
|
|
} else {
|
|
|
|
ClearList(dialog.suggestedList);
|
1999-09-04 02:05:47 +04:00
|
|
|
AppendStringToList(dialog.suggestedList, GetString("CorrectSpelling"));
|
1999-08-28 06:40:18 +04:00
|
|
|
// Suppress being able to select the message text
|
|
|
|
allowSelectWord = false;
|
1999-05-27 01:40:51 +04:00
|
|
|
}
|
1999-05-14 00:59:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function SelectSuggestedWord()
|
|
|
|
{
|
|
|
|
dump("SpellCheck: SelectSuggestedWord\n");
|
1999-08-28 06:40:18 +04:00
|
|
|
if (allowSelectWord)
|
2000-01-19 00:53:21 +03:00
|
|
|
dialog.replaceWordInput.value = dialog.suggestedList.options[dialog.suggestedList.selectedIndex].value;
|
|
|
|
}
|
|
|
|
|
|
|
|
function ChangeReplaceWord()
|
|
|
|
{
|
|
|
|
// Unselect the word in the suggested list when user edits the replacement word
|
|
|
|
dialog.suggestedList.selectedIndex = -1;
|
1999-05-14 00:59:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function Ignore()
|
|
|
|
{
|
|
|
|
dump("SpellCheck: Ignore\n");
|
|
|
|
NextWord();
|
|
|
|
}
|
|
|
|
|
|
|
|
function IgnoreAll()
|
|
|
|
{
|
|
|
|
dump("SpellCheck: IgnoreAll\n");
|
|
|
|
if (misspelledWord != "") {
|
1999-07-14 19:24:33 +04:00
|
|
|
spellChecker.IgnoreWordAllOccurrences(misspelledWord);
|
1999-05-14 00:59:08 +04:00
|
|
|
}
|
|
|
|
NextWord();
|
|
|
|
}
|
|
|
|
|
|
|
|
function Replace()
|
|
|
|
{
|
|
|
|
dump("SpellCheck: Replace\n");
|
2000-01-19 00:53:21 +03:00
|
|
|
newWord = dialog.replaceWordInput.value;
|
|
|
|
//dump("New = "+newWord+" Misspelled = "+misspelledWord+"\n");
|
1999-05-14 00:59:08 +04:00
|
|
|
if (misspelledWord != "" && misspelledWord != newWord) {
|
1999-07-14 19:24:33 +04:00
|
|
|
isMisspelled = spellChecker.ReplaceWord(misspelledWord, newWord, false);
|
1999-05-14 00:59:08 +04:00
|
|
|
}
|
|
|
|
NextWord();
|
|
|
|
}
|
|
|
|
|
|
|
|
function ReplaceAll()
|
|
|
|
{
|
|
|
|
dump("SpellCheck: ReplaceAll\n");
|
2000-01-19 00:53:21 +03:00
|
|
|
newWord = dialog.replaceWordInput.value;
|
1999-05-14 00:59:08 +04:00
|
|
|
if (misspelledWord != "" && misspelledWord != newWord) {
|
1999-07-14 19:24:33 +04:00
|
|
|
isMisspelled = spellChecker.ReplaceWord(misspelledWord, newWord, true);
|
1999-05-14 00:59:08 +04:00
|
|
|
}
|
|
|
|
NextWord();
|
|
|
|
}
|
|
|
|
|
|
|
|
function AddToDictionary()
|
|
|
|
{
|
|
|
|
dump("SpellCheck: AddToDictionary\n");
|
|
|
|
if (misspelledWord != "") {
|
1999-07-14 19:24:33 +04:00
|
|
|
spellChecker.AddWordToDictionary(misspelledWord);
|
1999-05-14 00:59:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function EditDictionary()
|
|
|
|
{
|
1999-09-18 03:13:59 +04:00
|
|
|
window.openDialog("chrome://editor/content/EdDictionary.xul", "_blank", "chrome,close,titlebar,modal", "", misspelledWord);
|
1999-05-14 00:59:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function SelectLanguage()
|
|
|
|
{
|
|
|
|
// A bug in combobox prevents this from working
|
|
|
|
dump("SpellCheck: SelectLanguage.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
function Close()
|
|
|
|
{
|
1999-05-27 01:40:51 +04:00
|
|
|
// Shutdown the spell check and close the dialog
|
1999-07-14 19:24:33 +04:00
|
|
|
spellChecker.CloseSpellChecking();
|
1999-05-27 01:40:51 +04:00
|
|
|
window.close();
|
1999-05-14 00:59:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function FillSuggestedList(firstWord)
|
|
|
|
{
|
|
|
|
list = dialog.suggestedList;
|
|
|
|
|
|
|
|
// Clear the current contents of the list
|
1999-05-27 01:40:51 +04:00
|
|
|
ClearList(list);
|
|
|
|
|
1999-05-14 00:59:08 +04:00
|
|
|
// We may have the initial word
|
|
|
|
if (firstWord && firstWord != "") {
|
|
|
|
dump("First Word = "+firstWord+"\n");
|
1999-05-27 01:40:51 +04:00
|
|
|
AppendStringToList(list, firstWord);
|
1999-05-14 00:59:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get suggested words until an empty string is returned
|
|
|
|
do {
|
1999-07-14 19:24:33 +04:00
|
|
|
word = spellChecker.GetSuggestedWord();
|
1999-05-14 00:59:08 +04:00
|
|
|
dump("Suggested Word = "+word+"\n");
|
|
|
|
if (word != "") {
|
1999-05-27 01:40:51 +04:00
|
|
|
AppendStringToList(list, word);
|
1999-05-14 00:59:08 +04:00
|
|
|
}
|
|
|
|
} while (word != "");
|
1999-08-28 06:40:18 +04:00
|
|
|
if (list.length == 0) {
|
|
|
|
// No suggestions - show a message but don't let user select it
|
1999-09-04 02:05:47 +04:00
|
|
|
AppendStringToList(list, GetString("NoSuggestedWords"));
|
1999-08-28 06:40:18 +04:00
|
|
|
allowSelectWord = false;
|
|
|
|
} else {
|
|
|
|
allowSelectWord = true;
|
|
|
|
}
|
1999-05-14 00:59:08 +04:00
|
|
|
}
|
|
|
|
|