From a92c7d003d04ad2dbfed268a7fa0eb0d43d4f7be Mon Sep 17 00:00:00 2001 From: "scott%scott-macgregor.org" Date: Fri, 26 Jan 2007 20:40:15 +0000 Subject: [PATCH] Bug #355064 --> thunderbird's inline spell checker should use InlineSpellCheckUI instead of the older InlineSpellCheck interface. No one is now using editorInlineSpellCheck.js so remove it from the tree. sr=neil git-svn-id: svn://10.0.0.236/trunk@219002 18797224-902f-48f8-a5cc-f745e15eee43 --- .../content/editorInlineSpellCheck.js | 178 ------------------ mozilla/editor/ui/jar.mn | 1 - .../compose/content/MsgComposeCommands.js | 60 +++--- .../compose/content/messengercompose.xul | 13 +- 4 files changed, 33 insertions(+), 219 deletions(-) delete mode 100644 mozilla/editor/ui/composer/content/editorInlineSpellCheck.js diff --git a/mozilla/editor/ui/composer/content/editorInlineSpellCheck.js b/mozilla/editor/ui/composer/content/editorInlineSpellCheck.js deleted file mode 100644 index b5bfafd62ce..00000000000 --- a/mozilla/editor/ui/composer/content/editorInlineSpellCheck.js +++ /dev/null @@ -1,178 +0,0 @@ -/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla 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/MPL/ - * - * 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 Inline Spellchecker. - * - * The Initial Developer of the Original Code is - * Mozdev Group, Inc. - * Portions created by the Initial Developer are Copyright (C) 2004 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Neil Deakin (neil@mozdevgroup.com) - * Scott MacGregor (mscott@mozilla.org) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -const kSpellMaxNumSuggestions = 7; // Maximum number of suggested words to fill into the context menu. Most - // applications (like Open Office) set this value to 15. - -const kSpellNoMispelling = -1; -const kSpellNoSuggestionsFound = 0; - -var InlineSpellChecker = -{ - editor : null, - inlineSpellChecker: null, - - Init : function (editor, enable) - { - this.editor = editor; - this.inlineSpellChecker = editor.getInlineSpellChecker(true); - this.editor.setSpellcheckUserOverride(enable); - }, - - checkDocument : function(doc) - { - if (!this.inlineSpellChecker || !this.inlineSpellChecker.enableRealTimeSpell) - return; - - var range = doc.createRange(); - range.selectNodeContents(doc.body); - this.inlineSpellChecker.spellCheckRange(range); - }, - - getMispelledWord : function() - { - if (!this.inlineSpellChecker || !this.inlineSpellChecker.enableRealTimeSpell) - return null; - - var selection = this.editor.selection; - return this.inlineSpellChecker.getMispelledWord(selection.anchorNode, selection.anchorOffset); - }, - - // returns kSpellNoMispelling if the word is spelled correctly - // For mispelled words, returns kSpellNoSuggestionsFound when there are no suggestions otherwise the - // number of suggestions is returned. - // firstNonWordMenuItem is the first element in the menu popup that isn't a dynamically added word - // added by updateSuggestionsMenu. - updateSuggestionsMenu : function (menupopup, firstNonWordMenuItem, word) - { - if (!this.inlineSpellChecker || !this.inlineSpellChecker.enableRealTimeSpell) - return kSpellNoMispelling; - - var child = menupopup.firstChild; - while (child != firstNonWordMenuItem) - { - var next = child.nextSibling; - menupopup.removeChild(child); - child = next; - } - - if (!word) - { - word = this.getMispelledWord(); - if (!word) - return kSpellNoMispelling; - } - - var spellChecker = this.inlineSpellChecker.spellChecker; - if (!spellChecker) - return kSpellNoMispelling; - - var numSuggestedWords = 0; - - var isIncorrect = spellChecker.CheckCurrentWord(word.toString()); - if (isIncorrect) - { - do { - var suggestion = spellChecker.GetSuggestedWord(); - if (!suggestion) - break; - - var item = document.createElement("menuitem"); - item.setAttribute("label", suggestion); - item.setAttribute("value", suggestion); - - item.setAttribute("oncommand", "InlineSpellChecker.selectSuggestion(event.target.value, null, null);"); - menupopup.insertBefore(item, firstNonWordMenuItem); - numSuggestedWords++; - } while (numSuggestedWords < kSpellMaxNumSuggestions); - } - else - numSuggestedWords = kSpellNoMispelling; - - return numSuggestedWords; - }, - - selectSuggestion : function (newword, node, offset) - { - if (!this.inlineSpellChecker || !this.inlineSpellChecker.enableRealTimeSpell) - return; - - if (!node) - { - var selection = this.editor.selection; - node = selection.anchorNode; - offset = selection.anchorOffset; - } - - this.inlineSpellChecker.replaceWord(node, offset, newword); - }, - - addToDictionary : function (node, offset) - { - if (!this.inlineSpellChecker || !this.inlineSpellChecker.enableRealTimeSpell) - return; - - if (!node) - { - var selection = this.editor.selection; - node = selection.anchorNode; - offset = selection.anchorOffset; - } - - var word = this.inlineSpellChecker.getMispelledWord(node,offset); - if (word) this.inlineSpellChecker.addWordToDictionary(word); - }, - - ignoreWord : function (node, offset) - { - if (!this.inlineSpellChecker || !this.inlineSpellChecker.enableRealTimeSpell) - return; - - if (!node) - { - var selection = this.editor.selection; - node = selection.anchorNode; - offset = selection.anchorOffset; - } - - var word = this.inlineSpellChecker.getMispelledWord(node, offset); - if (word) - this.inlineSpellChecker.ignoreWord(word); - } -} diff --git a/mozilla/editor/ui/jar.mn b/mozilla/editor/ui/jar.mn index 6e481ab2411..dcb5f403253 100644 --- a/mozilla/editor/ui/jar.mn +++ b/mozilla/editor/ui/jar.mn @@ -37,7 +37,6 @@ comm.jar: content/editor/pref-composer.xul (composer/content/pref-composer.xul) content/editor/pref-publish.xul (composer/content/pref-publish.xul) content/editor/editorSmileyOverlay.xul (composer/content/editorSmileyOverlay.xul) - content/editor/editorInlineSpellCheck.js (composer/content/editorInlineSpellCheck.js) content/editor/editorPrefsOverlay.xul (composer/content/editorPrefsOverlay.xul) content/editor/editorNavigatorOverlay.xul (composer/content/editorNavigatorOverlay.xul) content/editor/editorMailOverlay.xul (composer/content/editorMailOverlay.xul) diff --git a/mozilla/mail/components/compose/content/MsgComposeCommands.js b/mozilla/mail/components/compose/content/MsgComposeCommands.js index e8d50ac8461..1ae1dfe15a3 100644 --- a/mozilla/mail/components/compose/content/MsgComposeCommands.js +++ b/mozilla/mail/components/compose/content/MsgComposeCommands.js @@ -257,8 +257,10 @@ var gComposeRecyclingListener = { document.getElementById("FormatToolbar").hidden = false; } + // Stop InlineSpellCheckerUI so personal dictionary is saved + InlineSpellCheckerUI.enabled = false; + //Reset editor - InlineSpellChecker.Init(GetCurrentEditor(), false); // unregister inline spell checking listeners and release the spell checker EditorResetFontAndColorAttributes(); EditorCleanup(); @@ -646,20 +648,18 @@ function updateComposeItems() } catch(e) {} } -function openEditorContextMenu() +function openEditorContextMenu(popup) { - // if we have a mispelled word, do one thing, otherwise show the usual context menu - var spellCheckNoSuggestionsItem = document.getElementById('spellCheckNoSuggestions'); - var word; - var misspelledWordStatus = InlineSpellChecker.updateSuggestionsMenu(document.getElementById('msgComposeContext'), spellCheckNoSuggestionsItem, - word); - - var hideSpellingItems = (misspelledWordStatus == kSpellNoMispelling); - spellCheckNoSuggestionsItem.hidden = hideSpellingItems || misspelledWordStatus != kSpellNoSuggestionsFound; - document.getElementById('spellCheckAddToDictionary').hidden = hideSpellingItems; - document.getElementById('spellCheckIgnoreWord').hidden = hideSpellingItems; - document.getElementById('spellCheckAddSep').hidden = hideSpellingItems; - document.getElementById('spellCheckSuggestionsSeparator').hidden = hideSpellingItems; + InlineSpellCheckerUI.clearSuggestionsFromMenu(); + InlineSpellCheckerUI.initFromEvent(document.popupRangeParent, document.popupRangeOffset); + var onMisspelling = InlineSpellCheckerUI.overMisspelling; + document.getElementById('spellCheckSuggestionsSeparator').hidden = !onMisspelling; + document.getElementById('spellCheckAddToDictionary').hidden = !onMisspelling; + document.getElementById('spellCheckIgnoreWord').hidden = !onMisspelling; + var separator = document.getElementById('spellCheckAddSep'); + separator.hidden = !onMisspelling; + document.getElementById('spellCheckNoSuggestions').hidden = !onMisspelling || + InlineSpellCheckerUI.addSuggestionsToMenu(popup, separator, 5); updateEditItems(); } @@ -1364,6 +1364,7 @@ function ComposeStartup(recycled, aParams) // Do setup common to Message Composer and Web Composer EditorSharedStartup(); + InitLanguageMenu(); } var msgCompFields = gMsgCompose.compFields; @@ -1592,7 +1593,10 @@ function ComposeLoad() function ComposeUnload() { dump("\nComposeUnload from XUL\n"); - + + // Stop InlineSpellCheckerUI so personal dictionary is saved + InlineSpellCheckerUI.enabled = false; + EditorCleanup(); RemoveMessageComposeOfflineObserver(); @@ -2155,7 +2159,7 @@ function SelectAddress() // walk through the recipients list and add them to the inline spell checker ignore list function addRecipientsToIgnoreList(aAddressesToAdd) { - if (InlineSpellChecker.inlineSpellChecker && InlineSpellChecker.inlineSpellChecker.enableRealTimeSpell) + if (InlineSpellCheckerUI.enabled) { // break the list of potentially many recipients back into individual names var hdrParser = Components.classes["@mozilla.org/messenger/headerparser;1"].getService(Components.interfaces.nsIMsgHeaderParser); @@ -2180,19 +2184,7 @@ function addRecipientsToIgnoreList(aAddressesToAdd) } } - InlineSpellChecker.inlineSpellChecker.ignoreWords(tokenizedNames, tokenizedNames.length); - } -} - -function ToggleInlineSpellChecker(target) -{ - if (InlineSpellChecker.inlineSpellChecker) - { - InlineSpellChecker.editor.setSpellcheckUserOverride(!InlineSpellChecker.inlineSpellChecker.enableRealTimeSpell); - target.setAttribute('checked', InlineSpellChecker.inlineSpellChecker.enableRealTimeSpell); - - if (InlineSpellChecker.inlineSpellChecker.enableRealTimeSpell) - InlineSpellChecker.checkDocument(window.content.document); + InlineSpellCheckerUI.mInlineSpellChecker.ignoreWords(tokenizedNames, tokenizedNames.length); } } @@ -2310,9 +2302,8 @@ function ChangeLanguage(event) sPrefs.setComplexValue("spellchecker.dictionary", nsISupportsString, str); // now check the document over again with the new dictionary - if (InlineSpellChecker.inlineSpellChecker) - if (InlineSpellChecker.inlineSpellChecker.enableRealTimeSpell) - InlineSpellChecker.checkDocument(window.content.document); + if (InlineSpellCheckerUI.enabled) + InlineSpellCheckerUI.mInlineSpellChecker.spellCheckRange(null); } event.stopPropagation(); } @@ -3621,5 +3612,8 @@ function InitEditor() { var editor = GetCurrentEditor(); gMsgCompose.initEditor(editor, window.content); - InlineSpellChecker.Init(editor, sPrefs.getBoolPref("mail.spellcheck.inline")); + + InlineSpellCheckerUI.init(editor); + InlineSpellCheckerUI.enabled = sPrefs.getBoolPref("mail.spellcheck.inline"); + document.getElementById('menu_inlineSpellCheck').setAttribute('disabled', !InlineSpellCheckerUI.canSpellCheck); } diff --git a/mozilla/mail/components/compose/content/messengercompose.xul b/mozilla/mail/components/compose/content/messengercompose.xul index 8a15da43525..c62b00a8bbc 100644 --- a/mozilla/mail/components/compose/content/messengercompose.xul +++ b/mozilla/mail/components/compose/content/messengercompose.xul @@ -71,10 +71,10 @@