From 6236efde575747632a16403abb39e9ce104914df Mon Sep 17 00:00:00 2001 From: Quentin Headen Date: Thu, 29 Dec 2011 16:06:56 -0500 Subject: [PATCH] Bug 352037 - Add an "Undo add to dictionary" item to spell checker's context menu item; r=ehsan --- browser/base/content/browser-context.inc | 4 + browser/base/content/nsContextMenu.js | 1 + .../base/content/test/test_contextmenu.html | 39 +++++++-- .../txtsvc/public/nsIInlineSpellChecker.idl | 3 +- .../spellcheck/src/mozInlineSpellChecker.cpp | 18 ++++ toolkit/content/InlineSpellChecker.jsm | 21 +++++ toolkit/content/tests/chrome/Makefile.in | 1 + .../tests/chrome/test_textbox_dictionary.xul | 85 +++++++++++++++++++ toolkit/content/widgets/textbox.xml | 4 + .../en-US/chrome/global/textcontext.dtd | 2 + 10 files changed, 170 insertions(+), 8 deletions(-) create mode 100644 toolkit/content/tests/chrome/test_textbox_dictionary.xul diff --git a/browser/base/content/browser-context.inc b/browser/base/content/browser-context.inc index a4b7c8645d0..2f9d64304df 100644 --- a/browser/base/content/browser-context.inc +++ b/browser/base/content/browser-context.inc @@ -46,6 +46,10 @@ label="&spellAddToDictionary.label;" accesskey="&spellAddToDictionary.accesskey;" oncommand="InlineSpellCheckerUI.addToDictionary();"/> + RemoveWordFromDictionary(wordstr.get()); + NS_ENSURE_SUCCESS(rv, rv); + + mozInlineSpellStatus status(this); + nsCOMPtr range = do_QueryInterface(NULL); // Check everything + rv = status.InitForRange(range); + NS_ENSURE_SUCCESS(rv, rv); + return ScheduleSpellCheck(status); +} + // mozInlineSpellChecker::IgnoreWord NS_IMETHODIMP diff --git a/toolkit/content/InlineSpellChecker.jsm b/toolkit/content/InlineSpellChecker.jsm index 8942c9427a5..0d25229e681 100644 --- a/toolkit/content/InlineSpellChecker.jsm +++ b/toolkit/content/InlineSpellChecker.jsm @@ -38,9 +38,11 @@ var EXPORTED_SYMBOLS = [ "InlineSpellChecker" ]; var gLanguageBundle; var gRegionBundle; +const MAX_UNDO_STACK_DEPTH = 1; function InlineSpellChecker(aEditor) { this.init(aEditor); + this.mAddedWordStack = []; // We init this here to preserve it between init/uninit calls } InlineSpellChecker.prototype = { @@ -284,8 +286,27 @@ InlineSpellChecker.prototype = { // callback for adding the current misspelling to the user-defined dictionary addToDictionary: function() { + // Prevent the undo stack from growing over the max depth + if (this.mAddedWordStack.length == MAX_UNDO_STACK_DEPTH) + this.mAddedWordStack.shift(); + + this.mAddedWordStack.push(this.mMisspelling); this.mInlineSpellChecker.addWordToDictionary(this.mMisspelling); }, + // callback for removing the last added word to the dictionary LIFO fashion + undoAddToDictionary: function() + { + if (this.mAddedWordStack.length > 0) + { + var word = this.mAddedWordStack.pop(); + this.mInlineSpellChecker.removeWordFromDictionary(word); + } + }, + canUndo : function() + { + // Return true if we have words on the stack + return (this.mAddedWordStack.length > 0); + }, ignoreWord: function() { this.mInlineSpellChecker.ignoreWord(this.mMisspelling); diff --git a/toolkit/content/tests/chrome/Makefile.in b/toolkit/content/tests/chrome/Makefile.in index e4e2233f539..6857bb620b0 100644 --- a/toolkit/content/tests/chrome/Makefile.in +++ b/toolkit/content/tests/chrome/Makefile.in @@ -144,6 +144,7 @@ _TEST_FILES += \ test_textbox_emptytext.xul \ test_textbox_number.xul \ test_textbox_search.xul \ + test_textbox_dictionary.xul\ test_toolbar.xul \ xul_selectcontrol.js \ test_popupincontent.xul \ diff --git a/toolkit/content/tests/chrome/test_textbox_dictionary.xul b/toolkit/content/tests/chrome/test_textbox_dictionary.xul new file mode 100644 index 00000000000..53a0bb9e081 --- /dev/null +++ b/toolkit/content/tests/chrome/test_textbox_dictionary.xul @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + diff --git a/toolkit/content/widgets/textbox.xml b/toolkit/content/widgets/textbox.xml index 50d0bfe361a..b2a663dc8cc 100644 --- a/toolkit/content/widgets/textbox.xml +++ b/toolkit/content/widgets/textbox.xml @@ -515,6 +515,8 @@ + @@ -580,6 +582,7 @@ this._setMenuItemVisibility("spell-check-enabled", false); this._setMenuItemVisibility("spell-check-separator", false); this._setMenuItemVisibility("spell-add-to-dictionary", false); + this._setMenuItemVisibility("spell-undo-add-to-dictionary", false); this._setMenuItemVisibility("spell-suggestions-separator", false); this._setMenuItemVisibility("spell-dictionaries", false); return; @@ -593,6 +596,7 @@ var overMisspelling = spellui.overMisspelling; this._setMenuItemVisibility("spell-add-to-dictionary", overMisspelling); + this._setMenuItemVisibility("spell-undo-add-to-dictionary", spellui.canUndo()); this._setMenuItemVisibility("spell-suggestions-separator", overMisspelling); // suggestion list diff --git a/toolkit/locales/en-US/chrome/global/textcontext.dtd b/toolkit/locales/en-US/chrome/global/textcontext.dtd index c870eeca52b..26c66d6f4dd 100644 --- a/toolkit/locales/en-US/chrome/global/textcontext.dtd +++ b/toolkit/locales/en-US/chrome/global/textcontext.dtd @@ -13,6 +13,8 @@ + +