Get editorShell from window.opener now that editorAppCore is no more.

This commit is contained in:
sfraser%netscape.com 1999-06-11 18:58:32 +00:00
Родитель 1f90d70b37
Коммит 18b7cf617d
5 изменённых файлов: 181 добавлений и 272 удалений

Просмотреть файл

@ -1,55 +1,46 @@
/* Main Composer window UI control */ /* Main Composer window UI control */
/*the editor type, i.e. "text" or "html" */
/* the name of the editor. Must be unique globally, hence the timestamp */
var editorName = "EditorAppCore" + ( new Date() ).getTime().toString();
var appCore = null;
var toolbar; var toolbar;
var contentWindow;
function EditorStartup(editorType) function EditorStartup(editorType)
{ {
dump("Doing Startup...\n"); dump("Doing Startup...\n");
contentWindow = window.frames[0]; contentWindow = window.frames[0];
/* Get the global Editor AppCore and the XPFE toolkit core into globals here */
appCore = XPAppCoresManager.Find(editorName); dump("Trying to make an editor appcore through the component manager...\n");
dump("Looking up EditorAppCore...\n");
if (appCore == null) var editorShell = Components.classes["component://netscape/editor/editorshell"].createInstance();
editorShell = editorShell.QueryInterface(Components.interfaces.nsIEditorShell);
if (!editorShell)
{ {
dump("Creating EditorAppCore...\n"); dump("Failed to create editor shell\n");
appCore = new EditorAppCore(); window.close();
if (appCore) { return;
dump(editorName + " has been created.\n");
appCore.Init(editorName);
appCore.setWebShellWindow(window);
appCore.setToolbarWindow(window)
appCore.setEditorType(editorType);
appCore.setContentWindow(contentWindow);
// Get url for editor content
var url = document.getElementById("args").getAttribute("value");
// Load the source (the app core will magically know what to do).
appCore.loadUrl(url);
// the editor gets instantiated by the appcore when the URL has finished loading.
dump("EditorAppCore windows have been set.\n");
}
} else {
dump("EditorAppCore has already been created! Why?\n");
} }
EditorSetup(editorName, appCore);
// store the editor shell in the window, so that child windows can get to it.
window.editorShell = editorShell;
window.editorShell.Init();
window.editorShell.SetWebShellWindow(window);
window.editorShell.SetToolbarWindow(window)
window.editorShell.SetEditorType(editorType);
window.editorShell.SetContentWindow(contentWindow);
// Set focus to the editor content window // Get url for editor content and load it.
dump("Setting focus to content window\n"); // the editor gets instantiated by the editor shell when the URL has finished loading.
contentWindow.focus(); var url = document.getElementById("args").getAttribute("value");
window.editorShell.LoadUrl(url);
dump("EditorAppCore windows have been set.\n");
SetupToolbarElements();
// Set focus to the edit window
window.focus();
} }
function EditorSetup(p_editorName, p_appCore) function SetupToolbarElements()
{ {
editorName = p_editorName;
appCore = p_appCore;
// Create an object to store controls for easy access // Create an object to store controls for easy access
toolbar = new Object; toolbar = new Object;
if (!toolbar) { if (!toolbar) {
@ -63,7 +54,7 @@ function EditorSetup(p_editorName, p_appCore)
function EditorShutdown() function EditorShutdown()
{ {
dump("In EditorShutdown..\n"); dump("In EditorShutdown..\n");
appCore = XPAppCoresManager.Remove(appCore); //editorShell = XPAppCoresManager.Remove(editorShell);
} }
@ -72,24 +63,13 @@ function EditorShutdown()
function EditorNew() function EditorNew()
{ {
dump("In EditorNew..\n"); dump("In EditorNew..\n");
window.editorShell.NewWindow();
appCore = XPAppCoresManager.Find(editorName);
if (appCore)
{
appCore.newWindow();
}
} }
function EditorOpen() function EditorOpen()
{ {
dump("In EditorOpen..\n"); dump("In EditorOpen..\n");
window.editorShell.Open();
appCore = XPAppCoresManager.Find(editorName);
if (appCore)
{
appCore.open();
}
contentWindow.focus();
} }
function EditorNewPlaintext() function EditorNewPlaintext()
@ -131,218 +111,154 @@ function EditorNewBrowser()
function EditorSave() function EditorSave()
{ {
dump("In EditorSave...\n"); dump("In EditorSave...\n");
window.editorShell.Save();
appCore = XPAppCoresManager.Find(editorName);
if (appCore)
{
appCore.save();
}
contentWindow.focus();
} }
function EditorSaveAs() function EditorSaveAs()
{ {
dump("In EditorSave...\n"); dump("In EditorSave...\n");
window.editorShell.SaveAs();
appCore = XPAppCoresManager.Find(editorName);
if (appCore)
{
appCore.saveAs();
}
contentWindow.focus();
} }
function EditorPrint() function EditorPrint()
{ {
dump("In EditorPrint..\n"); dump("In EditorPrint..\n");
window.editorShell.Print();
appCore = XPAppCoresManager.Find(editorName);
if (appCore)
{
appCore.print();
}
contentWindow.focus();
} }
function EditorClose() function EditorClose()
{ {
dump("In EditorClose...\n"); dump("In EditorClose...\n");
window.editorShell.CloseWindow();
appCore = XPAppCoresManager.Find(editorName);
if (appCore)
{
appCore.closeWindow();
}
} }
// --------------------------- Edit menu --------------------------- // --------------------------- Edit menu ---------------------------
function EditorUndo() function EditorUndo()
{ {
if (appCore) { dump("Undoing\n");
dump("Undoing\n"); window.editorShell.Undo();
appCore.undo();
}
} }
function EditorRedo() function EditorRedo()
{ {
if (appCore) { dump("Redoing\n");
dump("Redoing\n"); window.editorShell.Redo();
appCore.redo();
}
} }
function EditorCut() function EditorCut()
{ {
if (appCore) { window.editorShell.Cut();
appCore.cut();
}
} }
function EditorCopy() function EditorCopy()
{ {
if (appCore) { window.editorShell.Copy();
appCore.copy();
}
} }
function EditorPaste() function EditorPaste()
{ {
if (appCore) { window.editorShell.Paste();
appCore.paste();
}
} }
function EditorPasteAsQuotation() function EditorPasteAsQuotation()
{ {
if (appCore) { window.editorShell.PasteAsQuotation();
appCore.pasteAsQuotation();
}
} }
function EditorPasteAsQuotationCited(citeString) function EditorPasteAsQuotationCited(citeString)
{ {
if (appCore) { window.editorShell.PasteAsCitedQuotation(CiteString);
appCore.pasteAsQuotationCited(CiteString);
}
} }
function EditorSelectAll() function EditorSelectAll()
{ {
if (appCore) { window.editorShell.SelectAll();
dump("Selecting all\n");
appCore.selectAll();
}
} }
function EditorFind() function EditorFind()
{ {
if (appCore) { window.editorShell.Find();
appCore.find();
}
contentWindow.focus();
} }
function EditorFindNext() function EditorFindNext()
{ {
if (appCore) { window.editorShell.FindNext();
appCore.findNext();
}
contentWindow.focus();
} }
function EditorShowClipboard() function EditorShowClipboard()
{ {
dump("In EditorShowClipboard...\n"); dump("In EditorShowClipboard...\n");
window.editorShell.ShowClipboard();
if (appCore) {
dump("Doing EditorShowClipboard...\n");
appCore.showClipboard();
}
} }
// --------------------------- Text style --------------------------- // --------------------------- Text style ---------------------------
// Currently not used???
function EditorSetTextProperty(property, attribute, value) function EditorSetTextProperty(property, attribute, value)
{ {
if (appCore) { window.editorShell.SetTextProperty(property, attribute, value);
appCore.setTextProperty(property, attribute, value); dump("Set text property -- calling focus()\n");
}
contentWindow.focus(); contentWindow.focus();
} }
function EditorSetParagraphFormat(paraFormat) function EditorSetParagraphFormat(paraFormat)
{ {
if (appCore) { window.editorShell.paragraphFormat = paraFormat;
appCore.setParagraphFormat(paraFormat);
}
contentWindow.focus(); contentWindow.focus();
} }
function EditorSetFontSize(size) function EditorSetFontSize(size)
{ {
if (appCore) { if( size == "0" || size == "normal" ||
if( size == "0" || size == "normal" || size === "+0" )
size === "+0" ) {
{ window.editorShell.RemoveTextProperty("font", size);
appCore.removeTextProperty("font", size); dump("Removing font size\n");
dump("Removing font size\n"); } else {
} else { dump("Setting font size\n");
dump("Setting font size\n"); window.editorShell.SetTextProperty("font", "size", size);
appCore.setTextProperty("font", "size", size); }
} contentWindow.focus();
}
} }
function EditorSetFontFace(fontFace) function EditorSetFontFace(fontFace)
{ {
if (appCore) { if( fontFace == "tt") {
if( fontFace == "tt") { // The old "teletype" attribute
// The old "teletype" attribute window.editorShell.SetTextProperty("tt", "", "");
appCore.setTextProperty("tt", "", ""); // Clear existing font face
// Clear existing font face fontFace = "";
fontFace = ""; window.editorShell.SetTextProperty("font", "face", fontFace);
}
appCore.setTextProperty("font", "face", fontFace);
} }
contentWindow.focus(); contentWindow.focus();
} }
function EditorSetFontColor(color) function EditorSetFontColor(color)
{ {
if (appCore) { window.editorShell.SetTextProperty("font", "color", color);
appCore.setTextProperty("font", "color", color);
}
contentWindow.focus(); contentWindow.focus();
} }
function EditorSetBackgroundColor(color) function EditorSetBackgroundColor(color)
{ {
appCore.setBackgroundColor(color); window.editorShell.SetBackgroundColor(color);
contentWindow.focus(); contentWindow.focus();
} }
function EditorApplyStyle(styleName) function EditorApplyStyle(styleName)
{ {
if (appCore) { dump("applying style\n");
dump("Applying Style\n"); window.editorShell.SetTextProperty(styleName, null, null);
appCore.setTextProperty(styleName, null, null);
dump("Restore focus to editor window: "+window.frames[0]+"\n");
}
contentWindow.focus(); contentWindow.focus();
} }
function EditorRemoveStyle(styleName) function EditorRemoveStyle(styleName)
{ {
if (appCore) { window.editorShell.RemoveTextProperty(styleName, null);
dump("Removing Style\n");
appCore.removeTextProperty(styleName, null);
}
contentWindow.focus(); contentWindow.focus();
} }
function EditorRemoveLinks() function EditorRemoveLinks()
{ {
dump("NOT IMPLEMENTED YET\n"); dump("NOT IMPLEMENTED YET\n");
@ -352,58 +268,58 @@ function EditorRemoveLinks()
function EditorGetText() function EditorGetText()
{ {
if (appCore) { if (window.editorShell) {
dump("Getting text\n"); dump("Getting text\n");
var outputText = appCore.contentsAsText; var outputText = window.editorShell.contentsAsText;
dump(outputText + "\n"); dump(outputText + "\n");
} }
} }
function EditorGetHTML() function EditorGetHTML()
{ {
if (appCore) { if (window.editorShell) {
dump("Getting HTML\n"); dump("Getting HTML\n");
var outputText = appCore.contentsAsHTML; var outputText = window.editorShell.contentsAsHTML;
dump(outputText + "\n"); dump(outputText + "\n");
} }
} }
function EditorInsertText() function EditorInsertText()
{ {
if (appCore) { if (window.editorShell) {
dump("Inserting text\n"); dump("Inserting text\n");
appCore.insertText("Once more into the breach, dear friends.\n"); window.editorShell.InsertText("Once more into the breach, dear friends.\n");
} }
} }
function EditorInsertLink() function EditorInsertLink()
{ {
if (appCore) { if (window.editorShell) {
window.openDialog("chrome://editordlgs/content/EdLinkProps.xul", "LinkDlg", "chrome", editorName); window.openDialog("chrome://editordlgs/content/EdLinkProps.xul", "LinkDlg", "chrome", "");
} }
contentWindow.focus(); contentWindow.focus();
} }
function EditorInsertImage() function EditorInsertImage()
{ {
if (appCore) { if (window.editorShell) {
window.openDialog("chrome://editordlgs/content/EdImageProps.xul", "dlg", "chrome", editorName); window.openDialog("chrome://editordlgs/content/EdImageProps.xul", "dlg", "chrome", "");
} }
contentWindow.focus(); contentWindow.focus();
} }
function EditorInsertHLine() function EditorInsertHLine()
{ {
if (appCore) { if (window.editorShell) {
window.openDialog("chrome://editordlgs/content/EdHLineProps.xul", "dlg", "chrome", editorName); window.openDialog("chrome://editordlgs/content/EdHLineProps.xul", "dlg", "chrome", "");
} }
contentWindow.focus(); contentWindow.focus();
} }
function EditorInsertNamedAnchor() function EditorInsertNamedAnchor()
{ {
if (appCore) { if (window.editorShell) {
window.openDialog("chrome://editordlgs/content/EdNamedAnchorProps.xul", "dlg", "chrome", editorName); window.openDialog("chrome://editordlgs/content/EdNamedAnchorProps.xul", "dlg", "chrome", "");
} }
contentWindow.focus(); contentWindow.focus();
} }
@ -411,60 +327,52 @@ function EditorInsertNamedAnchor()
function EditorIndent(indent) function EditorIndent(indent)
{ {
dump("indenting\n"); dump("indenting\n");
if (appCore) { window.editorShell.Indent(indent);
appCore.indent(indent);
}
contentWindow.focus(); contentWindow.focus();
} }
function EditorInsertList(listType) function EditorInsertList(listType)
{ {
if (appCore) { dump("Inserting list\n");
dump("Inserting list\n"); window.editorShell.InsertList(listType);
appCore.insertList(listType); }
dump("\n");
function EditorInsertImage()
{
if (window.editorShell) {
dump("Image Properties Dialog starting.\n");
window.openDialog("chrome://editordlgs/content/EdImageProps.xul", "dlg", "chrome", "");
} }
contentWindow.focus();
} }
function EditorAlign(align) function EditorAlign(align)
{ {
dump("aligning\n"); dump("aligning\n");
if (appCore) { window.editorShell.Align(align);
appCore.align(align);
}
contentWindow.focus();
} }
function EditorPrintPreview()
function EditorExit()
{ {
if (appCore) { window.openDialog("resource:/res/samples/printsetup.html", "PrintPreview", "chrome", "");
dump("Exiting\n");
appCore.exit();
}
}
function EditorPrintPreview() {
window.openDialog("resource:/res/samples/printsetup.html", "PrintPreview", "chrome", editorName);
} }
function CheckSpelling() function CheckSpelling()
{ {
if (appCore) { var spellChecker = window.editorShell.QueryInterface(Components.interfaces.nsISpellCheck);
if (spellChecker)
{
dump("Check Spelling starting...\n"); dump("Check Spelling starting...\n");
// Start the spell checker module. Return is first misspelled word // Start the spell checker module. Return is first misspelled word
firstMisspelledWord = appCore.startSpellChecking(); firstMisspelledWord = spellChecker.StartSpellChecking();
dump(firstMisspelledWord+"\n"); dump(firstMisspelledWord+"\n");
if( firstMisspelledWord == "") if( firstMisspelledWord == "")
{ {
dump("THERE IS NO MISSPELLED WORD!\n"); dump("THERE IS NO MISSPELLED WORD!\n");
// TODO: PUT UP A MESSAGE BOX TO TELL THE USER // TODO: PUT UP A MESSAGE BOX TO TELL THE USER
appCore.CloseSpellChecking(); window.editorShell.CloseSpellChecking();
} else { } else {
dump("We found a MISSPELLED WORD\n"); dump("We found a MISSPELLED WORD\n");
window.openDialog("chrome://editordlgs/content/EdSpellCheck.xul", "SpellDlg", "chrome", editorName, firstMisspelledWord); window.openDialog("chrome://editordlgs/content/EdSpellCheck.xul", "SpellDlg", "chrome", "", firstMisspelledWord);
} }
} }
} }
@ -517,10 +425,10 @@ function EditorSetSelectionFromOffsets(selRanges)
function EditorTestSelection() function EditorTestSelection()
{ {
if (appCore) if (window.editorShell)
{ {
dump("Testing selection\n"); dump("Testing selection\n");
var selection = appCore.editorSelection; var selection = window.editorShell.editorSelection;
if (selection) if (selection)
{ {
dump("Got selection\n"); dump("Got selection\n");
@ -536,26 +444,26 @@ function EditorTestSelection()
function EditorUnitTests() function EditorUnitTests()
{ {
if (appCore) { if (window.editorShell) {
dump("Running Unit Tests\n"); dump("Running Unit Tests\n");
appCore.runUnitTests(); window.editorShell.RunUnitTests();
} }
} }
function EditorExit() function EditorExit()
{ {
if (appCore) { if (window.editorShell) {
dump("Exiting\n"); dump("Exiting\n");
appCore.exit(); window.editorShell.exit();
} }
} }
function EditorTestDocument() function EditorTestDocument()
{ {
if (appCore) if (window.editorShell)
{ {
dump("Getting document\n"); dump("Getting document\n");
var theDoc = appCore.editorDocument; var theDoc = window.editorShell.editorDocument;
if (theDoc) if (theDoc)
{ {
dump("Got the doc\n"); dump("Got the doc\n");

Просмотреть файл

@ -1,4 +1,4 @@
var appCore; var editorShell;
var toolkitCore; var toolkitCore;
var insertNew = true; var insertNew = true;
@ -6,19 +6,17 @@ var insertNew = true;
function Startup() function Startup()
{ {
dump("Doing Startup...\n"); dump("Doing Startup...\n");
// New method: parameters passed via window.openDialog, which puts
// arguments in the array "arguments" // get the editor shell from the parent window
var editorName = window.arguments[0]; editorShell = window.opener.editorShell;
dump("Got editorAppCore called " + editorName + "\n"); editorShell = editorShell.QueryInterface(Components.interfaces.nsIEditorShell);
if(!editorShell) {
// NEVER create an appcore here - we must find parent editor's dump("EditoreditorShell not found!!!\n");
appCore = XPAppCoresManager.Find(editorName);
if(!appCore) {
dump("EditorAppCore not found!!!\n");
window.close(); window.close();
return; return;
} }
dump("EditorAppCore found for HRule Properties dialog\n");
dump("EditoreditorShell found for HRule Properties dialog\n");
// Create dialog object to store controls for easy access // Create dialog object to store controls for easy access
dialog = new Object; dialog = new Object;

Просмотреть файл

@ -1,4 +1,4 @@
var appCore; var editorShell;
var insertNew = true; var insertNew = true;
var imageWasInserted = false; var imageWasInserted = false;
var imageElement; var imageElement;
@ -10,19 +10,15 @@ function Startup()
{ {
dump("Doing Startup...\n"); dump("Doing Startup...\n");
// New method: parameters passed via window.openDialog, which puts // get the editor shell from the parent window
// arguments in the array "arguments" editorShell = window.opener.editorShell;
var editorName = window.arguments[0]; editorShell = editorShell.QueryInterface(Components.interfaces.nsIEditorShell);
dump("Got editorAppCore called " + editorName + "\n"); if(!editorShell) {
dump("EditoreditorShell not found!!!\n");
// NEVER create an appcore here - we must find parent editor's
appCore = XPAppCoresManager.Find(editorName);
if(!appCore) {
dump("EditorAppCore not found!!!\n");
window.close(); window.close();
return; return;
} }
dump("EditorAppCore found for Image Properties dialog\n"); dump("EditoreditorShell found for Image Properties dialog\n");
// Create dialog object to store controls for easy access // Create dialog object to store controls for easy access
dialog = new Object; dialog = new Object;
@ -55,7 +51,7 @@ function Startup()
function initDialog() { function initDialog() {
// Get a single selected anchor element // Get a single selected anchor element
imageElement = appCore.getSelectedElement(tagName); imageElement = editorShell.GetSelectedElement(tagName);
if (imageElement) { if (imageElement) {
dump("Found existing image\n"); dump("Found existing image\n");
@ -70,7 +66,7 @@ function initDialog() {
// We don't have an element selected, // We don't have an element selected,
// so create one with default attributes // so create one with default attributes
dump("Element not selected - calling createElementWithDefaults\n"); dump("Element not selected - calling createElementWithDefaults\n");
imageElement = appCore.createElementWithDefaults(tagName); imageElement = editorShell.CreateElementWithDefaults(tagName);
} }
if(!imageElement) { if(!imageElement) {
@ -82,7 +78,7 @@ function initDialog() {
function chooseFile() function chooseFile()
{ {
// Get a local file, converted into URL format // Get a local file, converted into URL format
fileName = appCore.getLocalFileURL(window, "img"); fileName = editorShell.GetLocalFileURL(window, "img");
if (fileName != "") { if (fileName != "") {
dialog.srcInput.value = fileName; dialog.srcInput.value = fileName;
} }
@ -129,9 +125,9 @@ function onOK()
imageElement.setAttribute("alt",dialog.altTextInput.value); imageElement.setAttribute("alt",dialog.altTextInput.value);
if (insertNew) { if (insertNew) {
dump("Src="+imageElement.getAttribute("src")+" Alt="+imageElement.getAttribute("alt")+"\n"); dump("Src="+imageElement.getAttribute("src")+" Alt="+imageElement.getAttribute("alt")+"\n");
appCore.insertElement(imageElement, true); editorShell.InsertElement(imageElement, true);
// Select the newly-inserted image // Select the newly-inserted image
appCore.selectElement(imageElement); editorShell.SelectElement(imageElement);
// Mark that we inserted so we can collapse the selection // Mark that we inserted so we can collapse the selection
// when dialog closes // when dialog closes
imageWasInserted = true; imageWasInserted = true;
@ -139,7 +135,7 @@ function onOK()
if (imageWasInserted) { if (imageWasInserted) {
// We selected the object, undo it by // We selected the object, undo it by
// setting caret to just after the inserted element // setting caret to just after the inserted element
appCore.setCaretAfterElement(imageElement); editorShell.SetSelectionAfterElement(imageElement);
} }
window.close(); window.close();
} }

Просмотреть файл

@ -1,4 +1,4 @@
var appCore; var editorShell;
var anchorElement = null; var anchorElement = null;
var insertNew = true; var insertNew = true;
var needLinkText = false; var needLinkText = false;
@ -11,14 +11,15 @@ var tagName = "HREF";
var dialog; var dialog;
// dialog initialization code // dialog initialization code
function Startup() { function Startup()
{
dump("Doing Startup...\n"); dump("Doing Startup...\n");
// NEVER create an appcore here - we must find parent editor's // get the editor shell from the parent window
var editorName = window.arguments[0]; editorShell = window.opener.editorShell;
dump("Got editorAppCore called " + editorName + "\n"); editorShell = editorShell.QueryInterface(Components.interfaces.nsIEditorShell);
appCore = XPAppCoresManager.Find(editorName);
if(!appCore) { if(!editorShell) {
dump("EditorAppCore not found!!!\n"); dump("EditorAppCore not found!!!\n");
window.close(); window.close();
return; return;
@ -46,8 +47,10 @@ function Startup() {
// Set initial focus // Set initial focus
if (insertNew) { if (insertNew) {
dump("Setting focus to linkTextInput\n");
dialog.linkTextInput.focus(); dialog.linkTextInput.focus();
} else { } else {
dump("Setting focus to linkTextInput\n");
dialog.hrefInput.focus(); dialog.hrefInput.focus();
// We will not insert a new link at caret, so remove link text input field // We will not insert a new link at caret, so remove link text input field
@ -60,11 +63,12 @@ function Startup() {
} }
} }
function initDialog() { function initDialog()
{
// Get a single selected anchor element // Get a single selected anchor element
anchorElement = appCore.getSelectedElement(tagName); anchorElement = editorShell.GetSelectedElement(tagName);
selection = appCore.editorSelection; selection = editorShell.editorSelection;
if (selection) { if (selection) {
dump("There is a selection: collapsed = "+selection.isCollapsed+"\n"); dump("There is a selection: collapsed = "+selection.isCollapsed+"\n");
} else { } else {
@ -72,18 +76,20 @@ function initDialog() {
} }
if (anchorElement) { if (anchorElement) {
dump("found anchor element\n");
// We found an element and don't need to insert one // We found an element and don't need to insert one
insertNew = false; insertNew = false;
} else { } else {
// We don't have an element selected, // We don't have an element selected,
// so create one with default attributes // so create one with default attributes
dump("Element not selected - calling createElementWithDefaults\n"); dump("Element not selected - calling createElementWithDefaults\n");
anchorElement = appCore.createElementWithDefaults(tagName); anchorElement = editorShell.CreateElementWithDefaults(tagName);
// We will insert a new link at caret location if there's no selection // We will insert a new link at caret location if there's no selection
// TODO: This isn't entirely correct. If selection doesn't have any text // TODO: This isn't entirely correct. If selection doesn't have any text
// or an image, then shouldn't we clear the selection and insert new text? // or an image, then shouldn't we clear the selection and insert new text?
insertNew = selection.isCollapsed; insertNew = selection.isCollapsed;
dump("insertNew is " + insertNew + "\n");
} }
if(!anchorElement) if(!anchorElement)
{ {
@ -115,7 +121,7 @@ function initDialog() {
function chooseFile() function chooseFile()
{ {
// Get a local file, converted into URL format // Get a local file, converted into URL format
fileName = appCore.getLocalFileURL(window, "html"); fileName = editorShell.GetLocalFileURL(window, "html");
if (fileName != "") { if (fileName != "") {
dialog.hrefInput.value = fileName; dialog.hrefInput.value = fileName;
} }
@ -128,29 +134,32 @@ function onOK()
// TODO: VALIDATE FIELDS BEFORE COMMITING CHANGES // TODO: VALIDATE FIELDS BEFORE COMMITING CHANGES
// Coalesce into one undo transaction // Coalesce into one undo transaction
appCore.beginBatchChanges(); editorShell.BeginBatchChanges();
// Set the HREF directly on the editor document's anchor node // Set the HREF directly on the editor document's anchor node
// or on the newly-created node if insertNew is true // or on the newly-created node if insertNew is true
dump(anchorElement + "\n");
anchorElement.setAttribute("href",dialog.hrefInput.value); anchorElement.setAttribute("href",dialog.hrefInput.value);
// Get text to use for a new link // Get text to use for a new link
if (insertNew) { if (insertNew) {
// Append the link text as the last child node // Append the link text as the last child node
// of the anchor node // of the anchor node
textNode = appCore.editorDocument.createTextNode(dialog.linkTextInput.value); dump("Creating text node\n");
textNode = editorShell.editorDocument.createTextNode(dialog.linkTextInput.value);
if (textNode) { if (textNode) {
anchorElement.appendChild(textNode); anchorElement.appendChild(textNode);
} }
newElement = appCore.insertElement(anchorElement, true); dump("Inserting\n");
if (newElement != anchorElement) { editorShell.InsertElement(anchorElement, true);
dump("Returned element from insertElement is different from orginal element.\n"); //if (newElement != anchorElement) {
} // dump("Returned element from insertElement is different from orginal element.\n");
//}
} else if (insertLinkAroundSelection) { } else if (insertLinkAroundSelection) {
dump("Setting link around selected text\n"); dump("Setting link around selected text\n");
appCore.insertLinkAroundSelection(anchorElement); editorShell.InsertLinkAroundSelection(anchorElement);
} }
appCore.endBatchChanges(); editorShell.EndBatchChanges();
window.close(); window.close();
} }

Просмотреть файл

@ -1,21 +1,19 @@
var edAppCore; var editorShell;
var misspelledWord; var misspelledWord;
// dialog initialization code // dialog initialization code
function Startup() function Startup()
{ {
dump("Doing Startup...\n"); dump("Doing Startup...\n");
// NEVER create an edAppCore here - we must find parent editor's
dump("Getting parent appcore\n"); // get the editor shell from the parent window
var editorName = window.arguments[0]; editorShell = window.opener.editorShell;
dump("EditorAppCore name =" + editorName + "\n"); editorShell = editorShell.QueryInterface(Components.interfaces.nsISpellCheck);
edAppCore = XPAppCoresManager.Find(editorName); if(!editorShell) {
if(!edAppCore) { dump("EditoreditorShell not found!!!\n");
dump("EditoredAppCore not found!!!\n");
window.close(); window.close();
} }
dump("EditoredAppCore found for Spell Checker dialog\n"); dump("EditoreditorShell found for Spell Checker dialog\n");
// Create dialog object to store controls for easy access // Create dialog object to store controls for easy access
dialog = new Object; dialog = new Object;
@ -54,7 +52,7 @@ function Startup()
function NextWord() function NextWord()
{ {
misspelledWord = edAppCore.getNextMisspelledWord(); misspelledWord = editorShell.GetNextMisspelledWord();
dialog.wordInput.value = misspelledWord; dialog.wordInput.value = misspelledWord;
if (misspelledWord == "") { if (misspelledWord == "") {
dump("FINISHED SPELL CHECKING\n"); dump("FINISHED SPELL CHECKING\n");
@ -70,7 +68,7 @@ function CheckWord()
word = dialog.wordInput.value; word = dialog.wordInput.value;
if (word != "") { if (word != "") {
dump("CheckWord: Word in edit field="+word+"\n"); dump("CheckWord: Word in edit field="+word+"\n");
isMisspelled = edAppCore.checkCurrentWord(word); isMisspelled = editorShell.CheckCurrentWord(word);
if (isMisspelled) { if (isMisspelled) {
dump("CheckWord says word was misspelled\n"); dump("CheckWord says word was misspelled\n");
misspelledWord = word; misspelledWord = word;
@ -98,7 +96,7 @@ function IgnoreAll()
{ {
dump("SpellCheck: IgnoreAll\n"); dump("SpellCheck: IgnoreAll\n");
if (misspelledWord != "") { if (misspelledWord != "") {
edAppCore.ignoreWordAllOccurrences(misspelledWord); editorShell.IgnoreWordAllOccurrences(misspelledWord);
} }
NextWord(); NextWord();
} }
@ -108,7 +106,7 @@ function Replace()
dump("SpellCheck: Replace\n"); dump("SpellCheck: Replace\n");
newWord = dialog.wordInput.value; newWord = dialog.wordInput.value;
if (misspelledWord != "" && misspelledWord != newWord) { if (misspelledWord != "" && misspelledWord != newWord) {
isMisspelled = edAppCore.replaceWord(misspelledWord, newWord, false); isMisspelled = editorShell.ReplaceWord(misspelledWord, newWord, false);
} }
NextWord(); NextWord();
} }
@ -118,7 +116,7 @@ function ReplaceAll()
dump("SpellCheck: ReplaceAll\n"); dump("SpellCheck: ReplaceAll\n");
newWord = dialog.wordInput.value; newWord = dialog.wordInput.value;
if (misspelledWord != "" && misspelledWord != newWord) { if (misspelledWord != "" && misspelledWord != newWord) {
isMisspelled = edAppCore.replaceWord(misspelledWord, newWord, true); isMisspelled = editorShell.ReplaceWord(misspelledWord, newWord, true);
} }
NextWord(); NextWord();
} }
@ -127,7 +125,7 @@ function AddToDictionary()
{ {
dump("SpellCheck: AddToDictionary\n"); dump("SpellCheck: AddToDictionary\n");
if (misspelledWord != "") { if (misspelledWord != "") {
edAppCore.addWordToDictionary(misspelledWord); editorShell.AddWordToDictionary(misspelledWord);
} }
} }
@ -148,7 +146,7 @@ function Close()
{ {
dump("SpellCheck: Spell Checker Closed\n"); dump("SpellCheck: Spell Checker Closed\n");
// Shutdown the spell check and close the dialog // Shutdown the spell check and close the dialog
edAppCore.closeSpellChecking(); editorShell.CloseSpellChecking();
window.close(); window.close();
} }
@ -167,7 +165,7 @@ function FillSuggestedList(firstWord)
// Get suggested words until an empty string is returned // Get suggested words until an empty string is returned
do { do {
word = edAppCore.getSuggestedWord(); word = editorShell.GetSuggestedWord();
dump("Suggested Word = "+word+"\n"); dump("Suggested Word = "+word+"\n");
if (word != "") { if (word != "") {
AppendStringToList(list, word); AppendStringToList(list, word);