From fdc403c85928060f4b6697dc38c8599586129597 Mon Sep 17 00:00:00 2001 From: "cmanske%netscape.com" Date: Thu, 13 May 1999 20:59:08 +0000 Subject: [PATCH] Implemented Spell Checking --- editor/base/nsHTMLEditor.cpp | 16 +- editor/libeditor/html/nsHTMLEditor.cpp | 16 +- editor/ui/composer/content/EditorAppShell.xul | 32 ++- editor/ui/composer/content/EditorCommands.js | 28 ++- editor/ui/composer/skin/Editor.css | 41 ++++ editor/ui/dialogs/content/EdImageProps.js | 10 - editor/ui/dialogs/content/EdLinkProps.xul | 4 +- editor/ui/dialogs/content/EdSpellCheck.js | 196 ++++++++++++++++++ editor/ui/dialogs/content/EdSpellCheck.xul | 98 +++++++++ editor/ui/dialogs/content/MANIFEST | 2 + editor/ui/dialogs/content/Makefile.in | 2 + editor/ui/dialogs/content/makefile.win | 4 + editor/ui/dialogs/skin/EditorDialog.css | 9 +- 13 files changed, 423 insertions(+), 35 deletions(-) create mode 100644 editor/ui/dialogs/content/EdSpellCheck.js create mode 100644 editor/ui/dialogs/content/EdSpellCheck.xul diff --git a/editor/base/nsHTMLEditor.cpp b/editor/base/nsHTMLEditor.cpp index a3a6e90df32d..6fe794fbc1af 100644 --- a/editor/base/nsHTMLEditor.cpp +++ b/editor/base/nsHTMLEditor.cpp @@ -38,7 +38,7 @@ #include "nsIDOMRange.h" #include "nsISupportsArray.h" #include "nsVoidArray.h" - +#include "nsFileSpec.h" #include "nsIComponentManager.h" #include "nsIServiceManager.h" @@ -1545,6 +1545,20 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection, ns selection->ClearSelection(); } } + nsAutoString tagName; + + // MAJOR KLUDGE -- CONVERT THE PLATFORM-SPECIFIC FORMAT INTO URL FORMAT + // This should be done by the file-picker widget + nsCOMPtr image = (do_QueryInterface(aElement)); + + if (image) + { + printf("INSERTING AN IMAGE\n"); + nsAutoString src; + image->GetSrc(src); + nsFileSpec fileSpec(src); + nsFileURL fileURL(fileSpec); + } DeleteSelectionAndPrepareToCreateNode(parentSelectedNode, offsetOfNewNode); diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index a3a6e90df32d..6fe794fbc1af 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -38,7 +38,7 @@ #include "nsIDOMRange.h" #include "nsISupportsArray.h" #include "nsVoidArray.h" - +#include "nsFileSpec.h" #include "nsIComponentManager.h" #include "nsIServiceManager.h" @@ -1545,6 +1545,20 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection, ns selection->ClearSelection(); } } + nsAutoString tagName; + + // MAJOR KLUDGE -- CONVERT THE PLATFORM-SPECIFIC FORMAT INTO URL FORMAT + // This should be done by the file-picker widget + nsCOMPtr image = (do_QueryInterface(aElement)); + + if (image) + { + printf("INSERTING AN IMAGE\n"); + nsAutoString src; + image->GetSrc(src); + nsFileSpec fileSpec(src); + nsFileURL fileURL(fileSpec); + } DeleteSelectionAndPrepareToCreateNode(parentSelectedNode, offsetOfNewNode); diff --git a/editor/ui/composer/content/EditorAppShell.xul b/editor/ui/composer/content/EditorAppShell.xul index aa11197b3981..44176d544f36 100644 --- a/editor/ui/composer/content/EditorAppShell.xul +++ b/editor/ui/composer/content/EditorAppShell.xul @@ -112,7 +112,7 @@ - + @@ -132,8 +132,8 @@ - - + + @@ -177,26 +177,24 @@ + - - - + + - - - - - - - - - - - + + + + + + + + + diff --git a/editor/ui/composer/content/EditorCommands.js b/editor/ui/composer/content/EditorCommands.js index 1ce3ce750bd2..89841f4059f5 100644 --- a/editor/ui/composer/content/EditorCommands.js +++ b/editor/ui/composer/content/EditorCommands.js @@ -346,6 +346,25 @@ function EditorPrintPreview() { } } +function CheckSpelling() +{ + if (appCore && toolkitCore) { + dump("Check Spelling starting...\n"); + // Start the spell checker module. Return is first misspelled word + word = appCore.startSpellChecking(); + dump(word+"\n"); + if( word == "") + { + dump("THERE IS NO MISSPELLED WORD!\n"); + // TODO: PUT UP A MESSAGE BOX TO TELL THE USER + appCore.CloseSpellChecking(); + } else { + dump("We found a MISSPELLED WORD\n"); + toolkitCore.ShowWindowWithArgs("chrome://editordlgs/content/EdSpellCheck.xul", window, editorName); + } + } +} + // --------------------------- Debug stuff --------------------------- function EditorTestSelection() @@ -365,7 +384,12 @@ function EditorTestSelection() } } - } + function EditorExit() + { + if (appCore) { + dump("Exiting\n"); + appCore.exit(); + } } function EditorTestDocument() @@ -387,7 +411,6 @@ function EditorTestDocument() } } - // --------------------------- Callbacks --------------------------- function OpenFile(url) { @@ -421,7 +444,6 @@ function onBoldChange() else { button.setAttribute( "disabled", true ); } - } else { diff --git a/editor/ui/composer/skin/Editor.css b/editor/ui/composer/skin/Editor.css index 2057c0cc8155..b8f992cff8d1 100644 --- a/editor/ui/composer/skin/Editor.css +++ b/editor/ui/composer/skin/Editor.css @@ -38,3 +38,44 @@ p, br, td { background-color: #ffffcc } +table#editbar-table { + background: silver; + border: 1px; + border-style: outset; +} + +box#edit-bar { + /* DOESN'T WORK + background: silver; */ + /* THIS CAUSES CRASH + border: 1px; + border-style: outset; */ +} + +tr.panel [show="1"] { + display: table-row; + background: white; +} +tr.panel [show="2"] { + display: none; + background: gray; +} + +tr.panel [show=1] { + display: table-row; + background: white; +} +tr.panel [show=2] { + display: none; + background: gray; +} +tr.panel [align="left"] { + display: table-row; + background: white; +} + +tr.panel [align="right"] { + display: none; + background: gray; +} + diff --git a/editor/ui/dialogs/content/EdImageProps.js b/editor/ui/dialogs/content/EdImageProps.js index d107c5a0e440..7ade5c0e7156 100644 --- a/editor/ui/dialogs/content/EdImageProps.js +++ b/editor/ui/dialogs/content/EdImageProps.js @@ -40,14 +40,6 @@ function Startup() dialog = new Object; // This is the "combined" widget: dialog.Src = document.getElementById("image.Src"); - // Can we get at just the edit field? - fileChild = dialog.Src.firstChild; - if (fileChild) - { - dump("*** fileInput control has a child\n"); - } else { - dump("*** fileInput control has NO child\n"); - } dialog.AltText = document.getElementById("image.AltText"); if (null == dialog.Src || @@ -59,8 +51,6 @@ function Startup() initDialog(); dialog.Src.focus(); - if (fileChild) - fileChild.focus(); } function initDialog() { diff --git a/editor/ui/dialogs/content/EdLinkProps.xul b/editor/ui/dialogs/content/EdLinkProps.xul index 304a89ab80dd..1d6b1f8cb1ed 100644 --- a/editor/ui/dialogs/content/EdLinkProps.xul +++ b/editor/ui/dialogs/content/EdLinkProps.xul @@ -21,7 +21,7 @@
Link source

Enter text to display for a new link:

- +
@@ -30,7 +30,7 @@
Link to

Enter a web page location or local file:

- +
diff --git a/editor/ui/dialogs/content/EdSpellCheck.js b/editor/ui/dialogs/content/EdSpellCheck.js new file mode 100644 index 000000000000..1502bd28f06e --- /dev/null +++ b/editor/ui/dialogs/content/EdSpellCheck.js @@ -0,0 +1,196 @@ +// OnOK(), Undo(), and Cancel() are in EdDialogCommon.js +// applyChanges() must be implemented here + +var edAppCore; +var toolkitCore; +var misspelledWord; + +// dialog initialization code +function Startup() +{ + dump("Doing Startup...\n"); + toolkitCore = XPAppCoresManager.Find("ToolkitCore"); + if (!toolkitCore) { + toolkitCore = new ToolkitCore(); + if (toolkitCore) + toolkitCore.Init("ToolkitCore"); + } + if(!toolkitCore) { + dump("toolkitCore not found!!! And we can't close the dialog!\n"); + } + + // NEVER create an edAppCore here - we must find parent editor's + + // temporary while this window is opend with ShowWindowWithArgs + dump("Getting parent appcore\n"); + var editorName = document.getElementById("args").getAttribute("value"); + dump("Got editorAppCore called " + editorName + "\n"); + edAppCore = XPAppCoresManager.Find(editorName); + if(!edAppCore || !toolkitCore) { + dump("EditoredAppCore not found!!!\n"); + toolkitCore.CloseWindow(window); + } + dump("EditoredAppCore found for Spell Checker dialog\n"); + + // Create dialog object to store controls for easy access + dialog = new Object; + if (!dialog) + { + dump("Failed to create dialog object!!!\n"); + toolkitCore.CloseWindow(window); + } + + dialog.wordInput = document.getElementById("Word"); + dialog.suggestedList = document.getElementById("SuggestedList"); + dialog.languageList = document.getElementById(""); + if (!dialog.wordInput || + !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 + + misspelledWord = edAppCore.getFirstMisspelledWord(); + + if (misspelledWord != "") { + dump("First misspelled word = "+misspelledWord+"\n"); + // Put word in input field + dialog.wordInput.value = misspelledWord; + FillSuggestedList(); + } else { + dump("No misspelled word found\n"); + } + + dialog.suggestedList.focus(); +} +function NextWord() +{ + misspelledWord = edAppCore.getNextMisspelledWord(); + dialog.wordInput.value = misspelledWord; + if (misspelledWord == "") { + dump("FINISHED SPELL CHECKING\n"); + FillSuggestedList("(no suggestions)"); + } else { + FillSuggestedList(); + } +} + +function CheckWord() +{ + dump("SpellCheck: CheckWord\n"); + word = dialog.wordInput.value; + dump("Word in edit field = "+word+"\n"); + if (word != "") { + isMisspelled = edAppCore.checkCurrentWord(word); + misspelledWord = word; + } +} + +function SelectSuggestedWord() +{ + dump("SpellCheck: SelectSuggestedWord\n"); + dialog.wordInput.value = dialog.suggestedList.value; +} + +function Ignore() +{ + dump("SpellCheck: Ignore\n"); + NextWord(); +} + +function IgnoreAll() +{ + dump("SpellCheck: IgnoreAll\n"); + if (misspelledWord != "") { + edAppCore.ignoreWordAllOccurrences(misspelledWord); + } + NextWord(); +} + +function Replace() +{ + dump("SpellCheck: Replace\n"); + newWord = dialog.wordInput.value; + if (misspelledWord != "" && misspelledWord != newWord) { + isMisspelled = edAppCore.replaceWord(misspelledWord, newWord, false); + } + NextWord(); +} + +function ReplaceAll() +{ + dump("SpellCheck: ReplaceAll\n"); + newWord = dialog.wordInput.value; + if (misspelledWord != "" && misspelledWord != newWord) { + isMisspelled = edAppCore.replaceWord(misspelledWord, newWord, true); + } + NextWord(); +} + +function AddToDictionary() +{ + dump("SpellCheck: AddToDictionary\n"); + if (misspelledWord != "") { + edAppCore.addWordToDictionary(misspelledWord); + } +} + +function EditDictionary() +{ + dump("SpellCheck: EditDictionary TODO: IMPLEMENT DIALOG\n"); +} + +function SelectLanguage() +{ + // A bug in combobox prevents this from working + dump("SpellCheck: SelectLanguage.\n"); +} + +function Close() +{ + dump("SpellCheck: Close (can't close yet - CRASHES!)\n"); + edAppCore.closeSpellChecking(); +} + +function Help() +{ + dump("SpellCheck: Help me Rhonda, help, help me Rhonda\n"); +} + +function FillSuggestedList(firstWord) +{ + list = dialog.suggestedList; + + // Clear the current contents of the list + while (list.hasChildNodes()) { + dump("Removing list option node\n"); + list.removeChild(list.lastChild); + } + // We may have the initial word + if (firstWord && firstWord != "") { + dump("First Word = "+firstWord+"\n"); + AppendSuggestedList(firstWord); + } + + // Get suggested words until an empty string is returned + do { + word = edAppCore.getSuggestedWord(); + dump("Suggested Word = "+word+"\n"); + if (word != "") { + AppendSuggestedList(word); + } + } while (word != ""); +} + +function AppendSuggestedList(word) +{ + optionNode = document.createElement("option"); + if (optionNode) { + dump("Appending word to an OPTION node: "+word+"\n"); + optionNode.setAttribute("value", word); + dialog.suggestedList.appendChild(optionNode); + } else { + dump("Failed to create OPTION node: "+word+"\n"); + } +} diff --git a/editor/ui/dialogs/content/EdSpellCheck.xul b/editor/ui/dialogs/content/EdSpellCheck.xul new file mode 100644 index 000000000000..f82bdaf49956 --- /dev/null +++ b/editor/ui/dialogs/content/EdSpellCheck.xul @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Word
+
+ + + + +
+ Suggestions: +
+ + +
+ + + +
+ + + +
+ User Dictionary: +
+ + + +
+ Language: +
+ + + + + +
+
diff --git a/editor/ui/dialogs/content/MANIFEST b/editor/ui/dialogs/content/MANIFEST index 400ae52b6878..31758e4236e4 100644 --- a/editor/ui/dialogs/content/MANIFEST +++ b/editor/ui/dialogs/content/MANIFEST @@ -8,3 +8,5 @@ EdImageProps.xul EdImageProps.js EdLinkProps.js EdLinkProps.xul +EdSpellCheck.js +EdSpellCheck.xul diff --git a/editor/ui/dialogs/content/Makefile.in b/editor/ui/dialogs/content/Makefile.in index d1f32bbe5f51..50ffd443eac6 100644 --- a/editor/ui/dialogs/content/Makefile.in +++ b/editor/ui/dialogs/content/Makefile.in @@ -34,6 +34,8 @@ EXPORT_RESOURCE_CONTENT = \ $(srcdir)/EdLinkProps.js \ $(srcdir)/EdImageProps.js \ $(srcdir)/EdCharacterProps.js \ + $(srcdir)/EdSpellCheck.xul \ + $(srcdir)/EdSpellCheck.js \ $(NULL) install:: diff --git a/editor/ui/dialogs/content/makefile.win b/editor/ui/dialogs/content/makefile.win index dd9583f153ad..1c2a1a82f040 100644 --- a/editor/ui/dialogs/content/makefile.win +++ b/editor/ui/dialogs/content/makefile.win @@ -27,6 +27,8 @@ install:: $(MAKE_INSTALL) EdImageProps.js $(DIST)\bin\chrome\editor\dialogs\content\default $(MAKE_INSTALL) EdCharacterProps.xul $(DIST)\bin\chrome\editor\dialogs\content\default $(MAKE_INSTALL) EdCharacterProps.js $(DIST)\bin\chrome\editor\dialogs\content\default + $(MAKE_INSTALL) EdSpellCheck.xul $(DIST)\bin\chrome\editor\dialogs\content\default + $(MAKE_INSTALL) EdSpellCheck.js $(DIST)\bin\chrome\editor\dialogs\content\default clobber:: rm -f $(DIST)\bin\chrome\editor\dialogs\content\default\EdDialogCommon.js @@ -36,3 +38,5 @@ clobber:: rm -f $(DIST)\bin\chrome\editor\dialogs\content\default\EdImageProps.js rm -f $(DIST)\bin\chrome\editor\dialogs\content\default\EdCharacterProps.xul rm -f $(DIST)\bin\chrome\editor\dialogs\content\default\EdCharacterProps.js + rm -f $(DIST)\bin\chrome\editor\dialogs\content\default\EdSpellCheck.xul + rm -f $(DIST)\bin\chrome\editor\dialogs\content\default\EdSpellCheck.js diff --git a/editor/ui/dialogs/skin/EditorDialog.css b/editor/ui/dialogs/skin/EditorDialog.css index 0cc99b11f77a..60e10b21c84f 100644 --- a/editor/ui/dialogs/skin/EditorDialog.css +++ b/editor/ui/dialogs/skin/EditorDialog.css @@ -33,6 +33,12 @@ select.combobox { border-style: outset; } +select.SpellCheckList, select.SpellCheckLanguage, input.SpellCheckWord { + width: 20em; + border-style: inset; + background-color: #CCCCCC; /* not working on Macintosh */ +} + .checkboxtext { margin-top: -9px; margin-left: 3px; @@ -56,7 +62,8 @@ tree { tr, TR { vertical-align: top } /* FOR DEBUG PURPOSE -- use border-width: 1px */ -td, table { border-width: 0px; } +/* BORDER STYLE NOT WORKING 5/12/99 */ +td, table { border: 0px;} p, br, td { font-family: Sans-Serif;