Implemented Spell Checking

This commit is contained in:
cmanske%netscape.com 1999-05-13 20:59:08 +00:00
parent 0111620f4d
commit fdc403c859
13 changed files with 423 additions and 35 deletions

View File

@ -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<nsIDOMHTMLImageElement> 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);

View File

@ -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<nsIDOMHTMLImageElement> 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);

View File

@ -112,7 +112,7 @@
</menu>
</menu>
<menu name="Tools">
<menuitem name=".Spell Check" onclick=""/>
<menuitem name="Spell Check" onclick="CheckSpelling()"/>
</menu>
<menu name="Debug">
<menuitem name="Output Text" onclick="EditorGetText()"/>
@ -132,8 +132,8 @@
<broadcaster id="Editor:Style:IsBold" bold="false"/>
<broadcaster id="Editor:Style:IsItalic"/>
<broadcaster id="Editor:Style:IsUnderline"/>
<box id="outer-box" align="vertical">
<box id="outer-box" align="vertical">
<toolbox>
<toolbar>
<!-- Most of the message handlers don't work! -->
@ -177,26 +177,24 @@
<titledbutton src="chrome://editor/skin/images/ED_Left.gif" align="bottom" class="popup" onclick="EditorAlign('left')"/>
<titledbutton src="chrome://editor/skin/images/ED_Link.gif" align="bottom" onclick="EditorInsertLink()"/>
<titledbutton src="chrome://editor/skin/images/ED_Image.gif" align="bottom" onclick= "EditorInsertImage()"/>
<titledbutton src="chrome://editor/skin/images/ED_Spell.gif" align="bottom" class="popup" onclick="CheckSpelling()"/>
</toolbar>
</toolbox>
<html:iframe type="content" id="content-frame" src="about:blank" flex="100%"/>
<!-- Ripped off from navigator.xul; this should be a XUL fragment! -->
<box align="horizontal" id="status-bar">
<!-- Ripped off from navigator.xul; this should be a XUL fragment! -->
<box align="horizontal" id="status-bar">
<titledbutton value="[Notification Component]" onclick="doTests()"/>
<box align="vertical" style="width:100px">
<spring flex="100%"/>
<progressmeter mode="normal" value="0">
</progressmeter>
<spring flex="100%"/>
</box>
<titledbutton id="statusText" align="right" flex="100%" value="Document: Done" style="font-family:sans-serif;font-size:2.5mm">
</titledbutton>
</box>
<box align="vertical" style="width:100px">
<spring flex="100%"/>
<progressmeter mode="normal" value="0">
</progressmeter>
<spring flex="100%"/>
</box>
<titledbutton id="statusText" align="right" flex="100%" value="Document: Done" style="font-family:sans-serif;font-size:2.5mm">
</titledbutton>
</box>
</box>
</window>

View File

@ -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
{

View File

@ -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;
}

View File

@ -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() {

View File

@ -21,7 +21,7 @@
<td>
<fieldset><legend align="left">Link source </legend>
<p class="smallmargin" id="linkMessage">Enter text to display for a new link:</p>
<input type="text" size="25" length="25" maxlength="100" id="linkTextInput"></input>
<input type="text" size="25" length="25" id="linkTextInput"></input>
</fieldset>
</td>
</tr>
@ -30,7 +30,7 @@
<fieldset><legend align="left">Link to </legend>
<p class="smallmargin">Enter a web page location or local file:
<button class="ChooseFile" id="ChooseFile" align="top">Choose File</button></p>
<input type="text" size="25" length="25" maxlength="100" id="hrefInput"></input>
<input type="text" size="25" length="25" id="hrefInput"></input>
</fieldset>
</td>
</tr>

View File

@ -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");
}
}

View File

@ -0,0 +1,98 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/xul.css" type="text/css"?>
<?xml-stylesheet href="chrome://editordlgs/skin/EditorDialog.css" type="text/css"?>
<!DOCTYPE window>
<!-- dialog containing a control requiring initial setup -->
<xul:window width="380" height="265" title="Check Spelling"
xmlns:xul ="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns="http://www.w3.org/TR/REC-html40"
onload = "Startup()">
<script language="JavaScript" src="chrome://editordlgs/content/EdSpellCheck.js">
</script>
<!-- The argument to ShowWindowWithArgs (the editor appCore name) is placed here -->
<xul:broadcaster id="args" value=""/>
<table>
<tr>
<td colspan="3">
Word<br/>
</td>
</tr>
<tr>
<td>
<input type="text" class="SpellCheckWord" id="Word" size="10"/>
</td>
<td>
<button width="30" id="CheckWord" onclick="CheckWord()">Check word</button>
</td>
<td>
</td>
</tr>
<tr>
<td colspan="3">
Suggestions:
</td>
</tr>
<tr>
<td rowspan="5">
<select class="SpellCheckList" id="SuggestedList" size="6" onchange="SelectSuggestedWord()">
<option>Sample contents 1</option>
<option>Sample contents 2</option>
<option>Sample contents 3</option>
</select>
</td>
<!-- THIS IS A BOGUS HACK TO COMPENSATE FOR A DISPLAY BUG -->
<td colspan="2">
</td>
</tr>
<tr>
<td>
<button width="30" id="Ignore" onclick="Ignore()">Ignore</button>
</td>
<td>
<button width="30" id="IgnoreAll" onclick="IgnoreAll()">Ignore All</button>
</td>
</tr>
<tr>
<td>
<button width="30" id="Replace" onclick="Replace()">Change</button>
</td>
<td>
<button width="30" id="ReplaceAll" onclick="ReplaceAll()">Change All</button>
</td>
</tr>
<tr>
<td colspan="2">
User Dictionary:
</td>
</tr>
<tr>
<td>
<button width="30" id="AddToDictionary" onclick="AddToDictionary()">Add</button>
</td>
<td>
<button width="30" id="EditDictionary" onclick="EditDictionary()">Edit</button>
</td>
</tr>
<tr>
<td colspan="3">
Language:
</td>
</tr>
<tr>
<td>
<select class="SpellCheckLanguage" id="LanguageList" size="1" onchange="SelectLanguage()">
<option>English
</option>
</select>
</td>
<td>
<button id="Close" onclick="Close()">Close</button>
</td>
<td>
<button id="Help" onclick="Help()">Help</button>
</td>
</tr>
</table>
</xul:window>

View File

@ -8,3 +8,5 @@ EdImageProps.xul
EdImageProps.js
EdLinkProps.js
EdLinkProps.xul
EdSpellCheck.js
EdSpellCheck.xul

View File

@ -34,6 +34,8 @@ EXPORT_RESOURCE_CONTENT = \
$(srcdir)/EdLinkProps.js \
$(srcdir)/EdImageProps.js \
$(srcdir)/EdCharacterProps.js \
$(srcdir)/EdSpellCheck.xul \
$(srcdir)/EdSpellCheck.js \
$(NULL)
install::

View File

@ -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

View File

@ -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;