!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is Mozilla Communicator client code, released
16 * March 31, 1998.
17 *
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998-1999
21 * the Initial Developer. All Rights Reserved.
22 *
23 * Contributor(s):
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
36 *
37 * ***** END LICENSE BLOCK ***** */
38
39 var gSpellChecker;
40 var gWordToAdd;
41
Startup
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
42 function Startup()
43 {
44 if (!GetCurrentEditor())
45 {
46 window.close();
47 return;
48 }
49 // Get the SpellChecker shell
50 if ("gSpellChecker" in window.opener && window.opener.gSpellChecker)
51 gSpellChecker = window.opener.gSpellChecker;
52
53 if (!gSpellChecker)
54 {
55 dump("SpellChecker not found!!!\n");
56 window.close();
57 return;
58 }
59 // The word to add word is passed as the 2nd extra parameter in window.openDialog()
60 gWordToAdd = window.arguments[1];
61
62 gDialog.WordInput = document.getElementById("WordInput");
63 gDialog.DictionaryList = document.getElementById("DictionaryList");
64
65 gDialog.WordInput.value = gWordToAdd;
66 FillDictionaryList();
67
68 // Select the supplied word if it is already in the list
69 SelectWordToAddInList();
70 SetTextboxFocus(gDialog.WordInput);
71 }
72
ValidateWordToAdd
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
73 function ValidateWordToAdd()
74 {
75 gWordToAdd = TrimString(gDialog.WordInput.value);
76 if (gWordToAdd.length > 0)
77 {
78 return true;
79 } else {
80 return false;
81 }
82 }
83
SelectWordToAddInList
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
84 function SelectWordToAddInList()
85 {
86 for (var i = 0; i < gDialog.DictionaryList.getRowCount(); i++)
87 {
88
89 var wordInList = gDialog.DictionaryList.getItemAtIndex(i);
90 if (wordInList && gWordToAdd == wordInList.label)
91 {
92 gDialog.DictionaryList.selectedIndex = i;
93 break;
94 }
95 }
96 }
97
AddWord
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
98 function AddWord()
99 {
100 if (ValidateWordToAdd())
101 {
102 try {
103 gSpellChecker.AddWordToDictionary(gWordToAdd);
104 }
105 catch (e) {
106 dump("Exception occured in gSpellChecker.AddWordToDictionary\nWord to add probably already existed\n");
107 }
108
109 // Rebuild the dialog list
110 FillDictionaryList();
111
112 SelectWordToAddInList();
113 gDialog.WordInput.value = "";
114 }
115 }
116
ReplaceWord
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
117 function ReplaceWord()
118 {
119 if (ValidateWordToAdd())
120 {
121 var selItem = gDialog.DictionaryList.selectedItem;
122 if (selItem)
123 {
124 try {
125 gSpellChecker.RemoveWordFromDictionary(selItem.label);
126 } catch (e) {}
127
128 try {
129 // Add to the dictionary list
130 gSpellChecker.AddWordToDictionary(gWordToAdd);
131
132 // Just change the text on the selected item
133 // instead of rebuilding the list
134 selItem.label = gWordToAdd;
135 } catch (e) {
136 // Rebuild list and select the word - it was probably already in the list
137 dump("Exception occured adding word in ReplaceWord\n");
138 FillDictionaryList();
139 SelectWordToAddInList();
140 }
141 }
142 }
143 }
144
RemoveWord
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
145 function RemoveWord()
146 {
147 var selIndex = gDialog.DictionaryList.selectedIndex;
148 if (selIndex >= 0)
149 {
150 var word = gDialog.DictionaryList.selectedItem.label;
151
152 // Remove word from list
153 gDialog.DictionaryList.removeItemAt(selIndex);
154
155 // Remove from dictionary
156 try {
157 //Not working: BUG 43348
158 gSpellChecker.RemoveWordFromDictionary(word);
159 }
160 catch (e)
161 {
162 dump("Failed to remove word from dictionary\n");
163 }
164
165 ResetSelectedItem(selIndex);
166 }
167 }
168
FillDictionaryList
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
169 function FillDictionaryList()
170 {
171 var selIndex = gDialog.DictionaryList.selectedIndex;
172
173 // Clear the current contents of the list
174 ClearListbox(gDialog.DictionaryList);
175
176 // Get the list from the spell checker
177 gSpellChecker.GetPersonalDictionary()
178
179 var haveList = false;
180
181 // Get words until an empty string is returned
182 do {
183 var word = gSpellChecker.GetPersonalDictionaryWord();
184 if (word != "")
185 {
186 gDialog.DictionaryList.appendItem(word, "");
187 haveList = true;
188 }
189 } while (word != "");
190
191 //XXX: BUG 74467: If list is empty, it doesn't layout to full height correctly
192 // (ignores "rows" attribute) (bug is latered, so we are fixing here for now)
193 if (!haveList)
194 gDialog.DictionaryList.appendItem("", "");
195
196 ResetSelectedItem(selIndex);
197 }
198
ResetSelectedItem
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
199 function ResetSelectedItem(index)
200 {
201 var lastIndex = gDialog.DictionaryList.getRowCount() - 1;
202 if (index > lastIndex)
203 index = lastIndex;
204
205 // If we didn't have a selected item,
206 // set it to the first item
207 if (index == -1 && lastIndex >= 0)
208 index = 0;
209
210 gDialog.DictionaryList.selectedIndex = index;
211 }
212
onClose
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
213 function onClose()
214 {
215 return true;
216 }