?? edspellcheck.js
字號:
gPreviousReplaceWord = gMisspelledWord; // This sets gDialog.ReplaceWordInput to first suggested word in list FillSuggestedList(gMisspelledWord); DoEnabling(); if (gMisspelledWord) SetTextboxFocus(gDialog.ReplaceWordInput);}function CheckWord(){ var word = gDialog.ReplaceWordInput.value; if (word) { if (gSpellChecker.CheckCurrentWord(word)) { FillSuggestedList(word); SetReplaceEnable(); } else { ClearListbox(gDialog.SuggestedList); var item = gDialog.SuggestedList.appendItem(GetString("CorrectSpelling"), ""); if (item) item.setAttribute("disabled", "true"); // Suppress being able to select the message text gAllowSelectWord = false; } }}function SelectSuggestedWord(){ if (gAllowSelectWord) { var selectedItem if (gDialog.SuggestedList.selectedItem) { var selValue = gDialog.SuggestedList.selectedItem.getAttribute("label"); gDialog.ReplaceWordInput.value = selValue; gPreviousReplaceWord = selValue; } else { gDialog.ReplaceWordInput.value = gPreviousReplaceWord; } SetReplaceEnable(); }}function ChangeReplaceWord(){ // Calling this triggers SelectSuggestedWord(), // so temporarily suppress the effect of that var saveAllow = gAllowSelectWord; gAllowSelectWord = false; // Select matching word in list var newIndex = -1; var newSelectedItem; var replaceWord = TrimString(gDialog.ReplaceWordInput.value); if (replaceWord) { for (var i = 0; i < gDialog.SuggestedList.getRowCount(); i++) { var item = gDialog.SuggestedList.getItemAtIndex(i); if (item.getAttribute("label") == replaceWord) { newSelectedItem = item; break; } } } gDialog.SuggestedList.selectedItem = newSelectedItem; gAllowSelectWord = saveAllow; // Remember the new word gPreviousReplaceWord = gDialog.ReplaceWordInput.value; SetReplaceEnable();}function Ignore(){ NextWord();}function IgnoreAll(){ if (gMisspelledWord) { gSpellChecker.IgnoreWordAllOccurrences(gMisspelledWord); } NextWord();}function Replace(newWord){ if (!newWord) return; if (gMisspelledWord && gMisspelledWord != newWord) { var editor = GetCurrentEditor(); editor.beginTransaction(); try { gSpellChecker.ReplaceWord(gMisspelledWord, newWord, false); } catch (e) {} editor.endTransaction(); } NextWord();}function ReplaceAll(){ var newWord = gDialog.ReplaceWordInput.value; if (gMisspelledWord && gMisspelledWord != newWord) { var editor = GetCurrentEditor(); editor.beginTransaction(); try { gSpellChecker.ReplaceWord(gMisspelledWord, newWord, true); } catch (e) {} editor.endTransaction(); } NextWord();}function AddToDictionary(){ if (gMisspelledWord) { gSpellChecker.AddWordToDictionary(gMisspelledWord); } NextWord();}function EditDictionary(){ window.openDialog("chrome://editor/content/EdDictionary.xul", "_blank", "chrome,close,titlebar,modal", "", gMisspelledWord);}function SelectLanguage(){ try { var item = gDialog.LanguageMenulist.selectedItem; if (item.value != "more-cmd") { gSpellChecker.SetCurrentDictionary(item.value); gLastSelectedLang = item; } else {
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var uri = ioService.newURI(getDictionaryURL(), null, null);
var protocolSvc = Components.classes["@mozilla.org/uriloader/external-protocol-service;1"]
.getService(Components.interfaces.nsIExternalProtocolService);
protocolSvc.loadUrl(uri); if (gLastSelectedLang) gDialog.LanguageMenulist.selectedItem = gLastSelectedLang; } } catch (ex) { dump(ex); }}function getDictionaryURL()
{
var formatter = Components.classes["@mozilla.org/toolkit/URLFormatterService;1"]
.getService(Components.interfaces.nsIURLFormatter);
return formatter.formatURLPref("spellchecker.dictionaries.download.url");
}function Recheck(){ //TODO: Should we bother to add a "Recheck" method to interface? try { var curLang = gSpellChecker.GetCurrentDictionary(); gSpellChecker.UninitSpellChecker(); gSpellChecker.InitSpellChecker(GetCurrentEditor(), false); gSpellChecker.SetCurrentDictionary(curLang); gMisspelledWord = gSpellChecker.GetNextMisspelledWord(); SetWidgetsForMisspelledWord(); } catch(ex) { dump(ex); }}function FillSuggestedList(misspelledWord){ var list = gDialog.SuggestedList; // Clear the current contents of the list gAllowSelectWord = false; ClearListbox(list); var item; if (misspelledWord.length > 0) { // Get suggested words until an empty string is returned var count = 0; var firstWord = 0; do { var word = gSpellChecker.GetSuggestedWord(); if (count==0) firstWord = word; if (word.length > 0) { list.appendItem(word, ""); count++; } } while (word.length > 0); if (count == 0) { // No suggestions - show a message but don't let user select it item = list.appendItem(GetString("NoSuggestedWords")); if (item) item.setAttribute("disabled", "true"); gAllowSelectWord = false; } else { gAllowSelectWord = true; // Initialize with first suggested list by selecting it gDialog.SuggestedList.selectedIndex = 0; } } else { item = list.appendItem("", ""); if (item) item.setAttribute("disabled", "true"); }}function SetReplaceEnable(){ // Enable "Change..." buttons only if new word is different than misspelled var newWord = gDialog.ReplaceWordInput.value; var enable = newWord.length > 0 && newWord != gMisspelledWord; SetElementEnabledById("Replace", enable); SetElementEnabledById("ReplaceAll", enable); if (enable) { gDialog.ReplaceButton.setAttribute("default","true"); gDialog.IgnoreButton.removeAttribute("default"); } else { gDialog.IgnoreButton.setAttribute("default","true"); gDialog.ReplaceButton.removeAttribute("default"); }}function doDefault(){ if (gDialog.ReplaceButton.getAttribute("default") == "true") Replace(gDialog.ReplaceWordInput.value); else if (gDialog.IgnoreButton.getAttribute("default") == "true") Ignore(); else if (gDialog.CloseButton.getAttribute("default") == "true") onClose(); return false;}function ExitSpellChecker(){ if (gSpellChecker) { try { var curLang = gSpellChecker.GetCurrentDictionary(); gSpellChecker.UninitSpellChecker(); if ("@mozilla.org/spellchecker;1" in Components.classes) { var spellChecker = Components.classes["@mozilla.org/spellchecker/myspell;1"] .getService(Components.interfaces.mozISpellCheckingEngine); spellChecker.dictionary = curLang; } // now check the document over again with the new dictionary // if we have an inline spellchecker if (("InlineSpellChecker" in window.opener) && ("inlineSpellChecker" in window.opener.InlineSpellChecker)) if (window.opener.InlineSpellChecker.inlineSpellChecker.enableRealTimeSpell) window.opener.InlineSpellChecker.checkDocument(window.opener.content.document); } finally { gSpellChecker = null; } }}function CancelSpellCheck(){ ExitSpellChecker(); // Signal to calling window that we canceled window.opener.cancelSendMessage = true; return true;}function onClose(){ ExitSpellChecker(); window.opener.cancelSendMessage = false; window.close();}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -