зеркало из https://github.com/mozilla/pjs.git
Get editorShell from window.opener now that editorAppCore is no more.
This commit is contained in:
Родитель
1f90d70b37
Коммит
18b7cf617d
|
@ -1,55 +1,46 @@
|
|||
/* 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 contentWindow;
|
||||
|
||||
function EditorStartup(editorType)
|
||||
{
|
||||
dump("Doing Startup...\n");
|
||||
contentWindow = window.frames[0];
|
||||
/* Get the global Editor AppCore and the XPFE toolkit core into globals here */
|
||||
appCore = XPAppCoresManager.Find(editorName);
|
||||
dump("Looking up EditorAppCore...\n");
|
||||
if (appCore == null)
|
||||
|
||||
dump("Trying to make an editor appcore through the component manager...\n");
|
||||
|
||||
var editorShell = Components.classes["component://netscape/editor/editorshell"].createInstance();
|
||||
editorShell = editorShell.QueryInterface(Components.interfaces.nsIEditorShell);
|
||||
if (!editorShell)
|
||||
{
|
||||
dump("Creating EditorAppCore...\n");
|
||||
appCore = new EditorAppCore();
|
||||
if (appCore) {
|
||||
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");
|
||||
dump("Failed to create editor shell\n");
|
||||
window.close();
|
||||
return;
|
||||
}
|
||||
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
|
||||
dump("Setting focus to content window\n");
|
||||
contentWindow.focus();
|
||||
// Get url for editor content and load it.
|
||||
// the editor gets instantiated by the editor shell when the URL has finished loading.
|
||||
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
|
||||
toolbar = new Object;
|
||||
if (!toolbar) {
|
||||
|
@ -63,7 +54,7 @@ function EditorSetup(p_editorName, p_appCore)
|
|||
function EditorShutdown()
|
||||
{
|
||||
dump("In EditorShutdown..\n");
|
||||
appCore = XPAppCoresManager.Remove(appCore);
|
||||
//editorShell = XPAppCoresManager.Remove(editorShell);
|
||||
}
|
||||
|
||||
|
||||
|
@ -72,24 +63,13 @@ function EditorShutdown()
|
|||
function EditorNew()
|
||||
{
|
||||
dump("In EditorNew..\n");
|
||||
|
||||
appCore = XPAppCoresManager.Find(editorName);
|
||||
if (appCore)
|
||||
{
|
||||
appCore.newWindow();
|
||||
}
|
||||
window.editorShell.NewWindow();
|
||||
}
|
||||
|
||||
function EditorOpen()
|
||||
{
|
||||
dump("In EditorOpen..\n");
|
||||
|
||||
appCore = XPAppCoresManager.Find(editorName);
|
||||
if (appCore)
|
||||
{
|
||||
appCore.open();
|
||||
}
|
||||
contentWindow.focus();
|
||||
window.editorShell.Open();
|
||||
}
|
||||
|
||||
function EditorNewPlaintext()
|
||||
|
@ -131,218 +111,154 @@ function EditorNewBrowser()
|
|||
function EditorSave()
|
||||
{
|
||||
dump("In EditorSave...\n");
|
||||
|
||||
appCore = XPAppCoresManager.Find(editorName);
|
||||
if (appCore)
|
||||
{
|
||||
appCore.save();
|
||||
}
|
||||
contentWindow.focus();
|
||||
window.editorShell.Save();
|
||||
}
|
||||
|
||||
function EditorSaveAs()
|
||||
{
|
||||
dump("In EditorSave...\n");
|
||||
|
||||
appCore = XPAppCoresManager.Find(editorName);
|
||||
if (appCore)
|
||||
{
|
||||
appCore.saveAs();
|
||||
}
|
||||
contentWindow.focus();
|
||||
window.editorShell.SaveAs();
|
||||
}
|
||||
|
||||
|
||||
function EditorPrint()
|
||||
{
|
||||
dump("In EditorPrint..\n");
|
||||
|
||||
appCore = XPAppCoresManager.Find(editorName);
|
||||
if (appCore)
|
||||
{
|
||||
appCore.print();
|
||||
}
|
||||
contentWindow.focus();
|
||||
window.editorShell.Print();
|
||||
}
|
||||
|
||||
function EditorClose()
|
||||
{
|
||||
dump("In EditorClose...\n");
|
||||
|
||||
appCore = XPAppCoresManager.Find(editorName);
|
||||
if (appCore)
|
||||
{
|
||||
appCore.closeWindow();
|
||||
}
|
||||
window.editorShell.CloseWindow();
|
||||
}
|
||||
|
||||
// --------------------------- Edit menu ---------------------------
|
||||
|
||||
function EditorUndo()
|
||||
{
|
||||
if (appCore) {
|
||||
dump("Undoing\n");
|
||||
appCore.undo();
|
||||
}
|
||||
dump("Undoing\n");
|
||||
window.editorShell.Undo();
|
||||
}
|
||||
|
||||
function EditorRedo()
|
||||
{
|
||||
if (appCore) {
|
||||
dump("Redoing\n");
|
||||
appCore.redo();
|
||||
}
|
||||
dump("Redoing\n");
|
||||
window.editorShell.Redo();
|
||||
}
|
||||
|
||||
function EditorCut()
|
||||
{
|
||||
if (appCore) {
|
||||
appCore.cut();
|
||||
}
|
||||
window.editorShell.Cut();
|
||||
}
|
||||
|
||||
function EditorCopy()
|
||||
{
|
||||
if (appCore) {
|
||||
appCore.copy();
|
||||
}
|
||||
window.editorShell.Copy();
|
||||
}
|
||||
|
||||
function EditorPaste()
|
||||
{
|
||||
if (appCore) {
|
||||
appCore.paste();
|
||||
}
|
||||
window.editorShell.Paste();
|
||||
}
|
||||
|
||||
function EditorPasteAsQuotation()
|
||||
{
|
||||
if (appCore) {
|
||||
appCore.pasteAsQuotation();
|
||||
}
|
||||
window.editorShell.PasteAsQuotation();
|
||||
}
|
||||
|
||||
function EditorPasteAsQuotationCited(citeString)
|
||||
{
|
||||
if (appCore) {
|
||||
appCore.pasteAsQuotationCited(CiteString);
|
||||
}
|
||||
window.editorShell.PasteAsCitedQuotation(CiteString);
|
||||
}
|
||||
|
||||
function EditorSelectAll()
|
||||
{
|
||||
if (appCore) {
|
||||
dump("Selecting all\n");
|
||||
appCore.selectAll();
|
||||
}
|
||||
window.editorShell.SelectAll();
|
||||
}
|
||||
|
||||
function EditorFind()
|
||||
{
|
||||
if (appCore) {
|
||||
appCore.find();
|
||||
}
|
||||
contentWindow.focus();
|
||||
window.editorShell.Find();
|
||||
}
|
||||
|
||||
function EditorFindNext()
|
||||
{
|
||||
if (appCore) {
|
||||
appCore.findNext();
|
||||
}
|
||||
contentWindow.focus();
|
||||
window.editorShell.FindNext();
|
||||
}
|
||||
|
||||
function EditorShowClipboard()
|
||||
{
|
||||
dump("In EditorShowClipboard...\n");
|
||||
|
||||
if (appCore) {
|
||||
dump("Doing EditorShowClipboard...\n");
|
||||
appCore.showClipboard();
|
||||
}
|
||||
window.editorShell.ShowClipboard();
|
||||
}
|
||||
|
||||
// --------------------------- Text style ---------------------------
|
||||
|
||||
// Currently not used???
|
||||
function EditorSetTextProperty(property, attribute, value)
|
||||
{
|
||||
if (appCore) {
|
||||
appCore.setTextProperty(property, attribute, value);
|
||||
}
|
||||
window.editorShell.SetTextProperty(property, attribute, value);
|
||||
dump("Set text property -- calling focus()\n");
|
||||
contentWindow.focus();
|
||||
}
|
||||
|
||||
function EditorSetParagraphFormat(paraFormat)
|
||||
{
|
||||
if (appCore) {
|
||||
appCore.setParagraphFormat(paraFormat);
|
||||
}
|
||||
window.editorShell.paragraphFormat = paraFormat;
|
||||
contentWindow.focus();
|
||||
}
|
||||
|
||||
function EditorSetFontSize(size)
|
||||
{
|
||||
if (appCore) {
|
||||
if( size == "0" || size == "normal" ||
|
||||
size === "+0" )
|
||||
{
|
||||
appCore.removeTextProperty("font", size);
|
||||
dump("Removing font size\n");
|
||||
} else {
|
||||
dump("Setting font size\n");
|
||||
appCore.setTextProperty("font", "size", size);
|
||||
}
|
||||
}
|
||||
if( size == "0" || size == "normal" ||
|
||||
size === "+0" )
|
||||
{
|
||||
window.editorShell.RemoveTextProperty("font", size);
|
||||
dump("Removing font size\n");
|
||||
} else {
|
||||
dump("Setting font size\n");
|
||||
window.editorShell.SetTextProperty("font", "size", size);
|
||||
}
|
||||
contentWindow.focus();
|
||||
}
|
||||
|
||||
function EditorSetFontFace(fontFace)
|
||||
{
|
||||
if (appCore) {
|
||||
if( fontFace == "tt") {
|
||||
// The old "teletype" attribute
|
||||
appCore.setTextProperty("tt", "", "");
|
||||
// Clear existing font face
|
||||
fontFace = "";
|
||||
}
|
||||
appCore.setTextProperty("font", "face", fontFace);
|
||||
if( fontFace == "tt") {
|
||||
// The old "teletype" attribute
|
||||
window.editorShell.SetTextProperty("tt", "", "");
|
||||
// Clear existing font face
|
||||
fontFace = "";
|
||||
window.editorShell.SetTextProperty("font", "face", fontFace);
|
||||
}
|
||||
contentWindow.focus();
|
||||
}
|
||||
|
||||
function EditorSetFontColor(color)
|
||||
{
|
||||
if (appCore) {
|
||||
appCore.setTextProperty("font", "color", color);
|
||||
}
|
||||
window.editorShell.SetTextProperty("font", "color", color);
|
||||
contentWindow.focus();
|
||||
}
|
||||
|
||||
function EditorSetBackgroundColor(color)
|
||||
{
|
||||
appCore.setBackgroundColor(color);
|
||||
window.editorShell.SetBackgroundColor(color);
|
||||
contentWindow.focus();
|
||||
}
|
||||
|
||||
function EditorApplyStyle(styleName)
|
||||
{
|
||||
if (appCore) {
|
||||
dump("Applying Style\n");
|
||||
appCore.setTextProperty(styleName, null, null);
|
||||
dump("Restore focus to editor window: "+window.frames[0]+"\n");
|
||||
}
|
||||
dump("applying style\n");
|
||||
window.editorShell.SetTextProperty(styleName, null, null);
|
||||
contentWindow.focus();
|
||||
}
|
||||
|
||||
function EditorRemoveStyle(styleName)
|
||||
{
|
||||
if (appCore) {
|
||||
dump("Removing Style\n");
|
||||
appCore.removeTextProperty(styleName, null);
|
||||
}
|
||||
window.editorShell.RemoveTextProperty(styleName, null);
|
||||
contentWindow.focus();
|
||||
}
|
||||
|
||||
function EditorRemoveLinks()
|
||||
{
|
||||
dump("NOT IMPLEMENTED YET\n");
|
||||
|
@ -352,58 +268,58 @@ function EditorRemoveLinks()
|
|||
|
||||
function EditorGetText()
|
||||
{
|
||||
if (appCore) {
|
||||
if (window.editorShell) {
|
||||
dump("Getting text\n");
|
||||
var outputText = appCore.contentsAsText;
|
||||
var outputText = window.editorShell.contentsAsText;
|
||||
dump(outputText + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
function EditorGetHTML()
|
||||
{
|
||||
if (appCore) {
|
||||
if (window.editorShell) {
|
||||
dump("Getting HTML\n");
|
||||
var outputText = appCore.contentsAsHTML;
|
||||
var outputText = window.editorShell.contentsAsHTML;
|
||||
dump(outputText + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
function EditorInsertText()
|
||||
{
|
||||
if (appCore) {
|
||||
if (window.editorShell) {
|
||||
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()
|
||||
{
|
||||
if (appCore) {
|
||||
window.openDialog("chrome://editordlgs/content/EdLinkProps.xul", "LinkDlg", "chrome", editorName);
|
||||
if (window.editorShell) {
|
||||
window.openDialog("chrome://editordlgs/content/EdLinkProps.xul", "LinkDlg", "chrome", "");
|
||||
}
|
||||
contentWindow.focus();
|
||||
}
|
||||
|
||||
function EditorInsertImage()
|
||||
{
|
||||
if (appCore) {
|
||||
window.openDialog("chrome://editordlgs/content/EdImageProps.xul", "dlg", "chrome", editorName);
|
||||
if (window.editorShell) {
|
||||
window.openDialog("chrome://editordlgs/content/EdImageProps.xul", "dlg", "chrome", "");
|
||||
}
|
||||
contentWindow.focus();
|
||||
}
|
||||
|
||||
function EditorInsertHLine()
|
||||
{
|
||||
if (appCore) {
|
||||
window.openDialog("chrome://editordlgs/content/EdHLineProps.xul", "dlg", "chrome", editorName);
|
||||
if (window.editorShell) {
|
||||
window.openDialog("chrome://editordlgs/content/EdHLineProps.xul", "dlg", "chrome", "");
|
||||
}
|
||||
contentWindow.focus();
|
||||
}
|
||||
|
||||
function EditorInsertNamedAnchor()
|
||||
{
|
||||
if (appCore) {
|
||||
window.openDialog("chrome://editordlgs/content/EdNamedAnchorProps.xul", "dlg", "chrome", editorName);
|
||||
if (window.editorShell) {
|
||||
window.openDialog("chrome://editordlgs/content/EdNamedAnchorProps.xul", "dlg", "chrome", "");
|
||||
}
|
||||
contentWindow.focus();
|
||||
}
|
||||
|
@ -411,60 +327,52 @@ function EditorInsertNamedAnchor()
|
|||
function EditorIndent(indent)
|
||||
{
|
||||
dump("indenting\n");
|
||||
if (appCore) {
|
||||
appCore.indent(indent);
|
||||
}
|
||||
window.editorShell.Indent(indent);
|
||||
contentWindow.focus();
|
||||
}
|
||||
|
||||
|
||||
function EditorInsertList(listType)
|
||||
{
|
||||
if (appCore) {
|
||||
dump("Inserting list\n");
|
||||
appCore.insertList(listType);
|
||||
dump("\n");
|
||||
dump("Inserting list\n");
|
||||
window.editorShell.InsertList(listType);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
dump("aligning\n");
|
||||
if (appCore) {
|
||||
appCore.align(align);
|
||||
}
|
||||
contentWindow.focus();
|
||||
window.editorShell.Align(align);
|
||||
}
|
||||
|
||||
|
||||
function EditorExit()
|
||||
function EditorPrintPreview()
|
||||
{
|
||||
if (appCore) {
|
||||
dump("Exiting\n");
|
||||
appCore.exit();
|
||||
}
|
||||
}
|
||||
|
||||
function EditorPrintPreview() {
|
||||
window.openDialog("resource:/res/samples/printsetup.html", "PrintPreview", "chrome", editorName);
|
||||
window.openDialog("resource:/res/samples/printsetup.html", "PrintPreview", "chrome", "");
|
||||
}
|
||||
|
||||
function CheckSpelling()
|
||||
{
|
||||
if (appCore) {
|
||||
var spellChecker = window.editorShell.QueryInterface(Components.interfaces.nsISpellCheck);
|
||||
if (spellChecker)
|
||||
{
|
||||
dump("Check Spelling starting...\n");
|
||||
// Start the spell checker module. Return is first misspelled word
|
||||
firstMisspelledWord = appCore.startSpellChecking();
|
||||
firstMisspelledWord = spellChecker.StartSpellChecking();
|
||||
dump(firstMisspelledWord+"\n");
|
||||
if( firstMisspelledWord == "")
|
||||
{
|
||||
dump("THERE IS NO MISSPELLED WORD!\n");
|
||||
// TODO: PUT UP A MESSAGE BOX TO TELL THE USER
|
||||
appCore.CloseSpellChecking();
|
||||
window.editorShell.CloseSpellChecking();
|
||||
} else {
|
||||
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()
|
||||
{
|
||||
if (appCore)
|
||||
if (window.editorShell)
|
||||
{
|
||||
dump("Testing selection\n");
|
||||
var selection = appCore.editorSelection;
|
||||
var selection = window.editorShell.editorSelection;
|
||||
if (selection)
|
||||
{
|
||||
dump("Got selection\n");
|
||||
|
@ -536,26 +444,26 @@ function EditorTestSelection()
|
|||
|
||||
function EditorUnitTests()
|
||||
{
|
||||
if (appCore) {
|
||||
if (window.editorShell) {
|
||||
dump("Running Unit Tests\n");
|
||||
appCore.runUnitTests();
|
||||
window.editorShell.RunUnitTests();
|
||||
}
|
||||
}
|
||||
|
||||
function EditorExit()
|
||||
{
|
||||
if (appCore) {
|
||||
if (window.editorShell) {
|
||||
dump("Exiting\n");
|
||||
appCore.exit();
|
||||
window.editorShell.exit();
|
||||
}
|
||||
}
|
||||
|
||||
function EditorTestDocument()
|
||||
{
|
||||
if (appCore)
|
||||
if (window.editorShell)
|
||||
{
|
||||
dump("Getting document\n");
|
||||
var theDoc = appCore.editorDocument;
|
||||
var theDoc = window.editorShell.editorDocument;
|
||||
if (theDoc)
|
||||
{
|
||||
dump("Got the doc\n");
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var appCore;
|
||||
var editorShell;
|
||||
var toolkitCore;
|
||||
var insertNew = true;
|
||||
|
||||
|
@ -6,19 +6,17 @@ var insertNew = true;
|
|||
function Startup()
|
||||
{
|
||||
dump("Doing Startup...\n");
|
||||
// New method: parameters passed via window.openDialog, which puts
|
||||
// arguments in the array "arguments"
|
||||
var editorName = window.arguments[0];
|
||||
dump("Got editorAppCore called " + editorName + "\n");
|
||||
|
||||
// NEVER create an appcore here - we must find parent editor's
|
||||
appCore = XPAppCoresManager.Find(editorName);
|
||||
if(!appCore) {
|
||||
dump("EditorAppCore not found!!!\n");
|
||||
|
||||
// get the editor shell from the parent window
|
||||
editorShell = window.opener.editorShell;
|
||||
editorShell = editorShell.QueryInterface(Components.interfaces.nsIEditorShell);
|
||||
if(!editorShell) {
|
||||
dump("EditoreditorShell not found!!!\n");
|
||||
window.close();
|
||||
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
|
||||
dialog = new Object;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var appCore;
|
||||
var editorShell;
|
||||
var insertNew = true;
|
||||
var imageWasInserted = false;
|
||||
var imageElement;
|
||||
|
@ -10,19 +10,15 @@ function Startup()
|
|||
{
|
||||
dump("Doing Startup...\n");
|
||||
|
||||
// New method: parameters passed via window.openDialog, which puts
|
||||
// arguments in the array "arguments"
|
||||
var editorName = window.arguments[0];
|
||||
dump("Got editorAppCore called " + editorName + "\n");
|
||||
|
||||
// NEVER create an appcore here - we must find parent editor's
|
||||
appCore = XPAppCoresManager.Find(editorName);
|
||||
if(!appCore) {
|
||||
dump("EditorAppCore not found!!!\n");
|
||||
// get the editor shell from the parent window
|
||||
editorShell = window.opener.editorShell;
|
||||
editorShell = editorShell.QueryInterface(Components.interfaces.nsIEditorShell);
|
||||
if(!editorShell) {
|
||||
dump("EditoreditorShell not found!!!\n");
|
||||
window.close();
|
||||
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
|
||||
dialog = new Object;
|
||||
|
@ -55,7 +51,7 @@ function Startup()
|
|||
|
||||
function initDialog() {
|
||||
// Get a single selected anchor element
|
||||
imageElement = appCore.getSelectedElement(tagName);
|
||||
imageElement = editorShell.GetSelectedElement(tagName);
|
||||
|
||||
if (imageElement) {
|
||||
dump("Found existing image\n");
|
||||
|
@ -70,7 +66,7 @@ function initDialog() {
|
|||
// We don't have an element selected,
|
||||
// so create one with default attributes
|
||||
dump("Element not selected - calling createElementWithDefaults\n");
|
||||
imageElement = appCore.createElementWithDefaults(tagName);
|
||||
imageElement = editorShell.CreateElementWithDefaults(tagName);
|
||||
}
|
||||
|
||||
if(!imageElement) {
|
||||
|
@ -82,7 +78,7 @@ function initDialog() {
|
|||
function chooseFile()
|
||||
{
|
||||
// Get a local file, converted into URL format
|
||||
fileName = appCore.getLocalFileURL(window, "img");
|
||||
fileName = editorShell.GetLocalFileURL(window, "img");
|
||||
if (fileName != "") {
|
||||
dialog.srcInput.value = fileName;
|
||||
}
|
||||
|
@ -129,9 +125,9 @@ function onOK()
|
|||
imageElement.setAttribute("alt",dialog.altTextInput.value);
|
||||
if (insertNew) {
|
||||
dump("Src="+imageElement.getAttribute("src")+" Alt="+imageElement.getAttribute("alt")+"\n");
|
||||
appCore.insertElement(imageElement, true);
|
||||
editorShell.InsertElement(imageElement, true);
|
||||
// Select the newly-inserted image
|
||||
appCore.selectElement(imageElement);
|
||||
editorShell.SelectElement(imageElement);
|
||||
// Mark that we inserted so we can collapse the selection
|
||||
// when dialog closes
|
||||
imageWasInserted = true;
|
||||
|
@ -139,7 +135,7 @@ function onOK()
|
|||
if (imageWasInserted) {
|
||||
// We selected the object, undo it by
|
||||
// setting caret to just after the inserted element
|
||||
appCore.setCaretAfterElement(imageElement);
|
||||
editorShell.SetSelectionAfterElement(imageElement);
|
||||
}
|
||||
window.close();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var appCore;
|
||||
var editorShell;
|
||||
var anchorElement = null;
|
||||
var insertNew = true;
|
||||
var needLinkText = false;
|
||||
|
@ -11,14 +11,15 @@ var tagName = "HREF";
|
|||
var dialog;
|
||||
|
||||
// dialog initialization code
|
||||
function Startup() {
|
||||
function Startup()
|
||||
{
|
||||
dump("Doing Startup...\n");
|
||||
|
||||
// NEVER create an appcore here - we must find parent editor's
|
||||
var editorName = window.arguments[0];
|
||||
dump("Got editorAppCore called " + editorName + "\n");
|
||||
appCore = XPAppCoresManager.Find(editorName);
|
||||
if(!appCore) {
|
||||
// get the editor shell from the parent window
|
||||
editorShell = window.opener.editorShell;
|
||||
editorShell = editorShell.QueryInterface(Components.interfaces.nsIEditorShell);
|
||||
|
||||
if(!editorShell) {
|
||||
dump("EditorAppCore not found!!!\n");
|
||||
window.close();
|
||||
return;
|
||||
|
@ -46,8 +47,10 @@ function Startup() {
|
|||
// Set initial focus
|
||||
|
||||
if (insertNew) {
|
||||
dump("Setting focus to linkTextInput\n");
|
||||
dialog.linkTextInput.focus();
|
||||
} else {
|
||||
dump("Setting focus to linkTextInput\n");
|
||||
dialog.hrefInput.focus();
|
||||
|
||||
// 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
|
||||
anchorElement = appCore.getSelectedElement(tagName);
|
||||
anchorElement = editorShell.GetSelectedElement(tagName);
|
||||
|
||||
selection = appCore.editorSelection;
|
||||
selection = editorShell.editorSelection;
|
||||
if (selection) {
|
||||
dump("There is a selection: collapsed = "+selection.isCollapsed+"\n");
|
||||
} else {
|
||||
|
@ -72,18 +76,20 @@ function initDialog() {
|
|||
}
|
||||
|
||||
if (anchorElement) {
|
||||
dump("found anchor element\n");
|
||||
// We found an element and don't need to insert one
|
||||
insertNew = false;
|
||||
} else {
|
||||
// We don't have an element selected,
|
||||
// so create one with default attributes
|
||||
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
|
||||
// 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?
|
||||
insertNew = selection.isCollapsed;
|
||||
dump("insertNew is " + insertNew + "\n");
|
||||
}
|
||||
if(!anchorElement)
|
||||
{
|
||||
|
@ -115,7 +121,7 @@ function initDialog() {
|
|||
function chooseFile()
|
||||
{
|
||||
// Get a local file, converted into URL format
|
||||
fileName = appCore.getLocalFileURL(window, "html");
|
||||
fileName = editorShell.GetLocalFileURL(window, "html");
|
||||
if (fileName != "") {
|
||||
dialog.hrefInput.value = fileName;
|
||||
}
|
||||
|
@ -128,29 +134,32 @@ function onOK()
|
|||
// TODO: VALIDATE FIELDS BEFORE COMMITING CHANGES
|
||||
|
||||
// Coalesce into one undo transaction
|
||||
appCore.beginBatchChanges();
|
||||
editorShell.BeginBatchChanges();
|
||||
|
||||
// Set the HREF directly on the editor document's anchor node
|
||||
// or on the newly-created node if insertNew is true
|
||||
dump(anchorElement + "\n");
|
||||
anchorElement.setAttribute("href",dialog.hrefInput.value);
|
||||
|
||||
// Get text to use for a new link
|
||||
if (insertNew) {
|
||||
// Append the link text as the last child 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) {
|
||||
anchorElement.appendChild(textNode);
|
||||
}
|
||||
newElement = appCore.insertElement(anchorElement, true);
|
||||
if (newElement != anchorElement) {
|
||||
dump("Returned element from insertElement is different from orginal element.\n");
|
||||
}
|
||||
dump("Inserting\n");
|
||||
editorShell.InsertElement(anchorElement, true);
|
||||
//if (newElement != anchorElement) {
|
||||
// dump("Returned element from insertElement is different from orginal element.\n");
|
||||
//}
|
||||
} else if (insertLinkAroundSelection) {
|
||||
dump("Setting link around selected text\n");
|
||||
appCore.insertLinkAroundSelection(anchorElement);
|
||||
editorShell.InsertLinkAroundSelection(anchorElement);
|
||||
}
|
||||
appCore.endBatchChanges();
|
||||
editorShell.EndBatchChanges();
|
||||
|
||||
window.close();
|
||||
}
|
||||
|
|
|
@ -1,21 +1,19 @@
|
|||
var edAppCore;
|
||||
var editorShell;
|
||||
var misspelledWord;
|
||||
|
||||
// dialog initialization code
|
||||
function Startup()
|
||||
{
|
||||
dump("Doing Startup...\n");
|
||||
// NEVER create an edAppCore here - we must find parent editor's
|
||||
|
||||
dump("Getting parent appcore\n");
|
||||
var editorName = window.arguments[0];
|
||||
dump("EditorAppCore name =" + editorName + "\n");
|
||||
edAppCore = XPAppCoresManager.Find(editorName);
|
||||
if(!edAppCore) {
|
||||
dump("EditoredAppCore not found!!!\n");
|
||||
// get the editor shell from the parent window
|
||||
editorShell = window.opener.editorShell;
|
||||
editorShell = editorShell.QueryInterface(Components.interfaces.nsISpellCheck);
|
||||
if(!editorShell) {
|
||||
dump("EditoreditorShell not found!!!\n");
|
||||
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
|
||||
dialog = new Object;
|
||||
|
@ -54,7 +52,7 @@ function Startup()
|
|||
|
||||
function NextWord()
|
||||
{
|
||||
misspelledWord = edAppCore.getNextMisspelledWord();
|
||||
misspelledWord = editorShell.GetNextMisspelledWord();
|
||||
dialog.wordInput.value = misspelledWord;
|
||||
if (misspelledWord == "") {
|
||||
dump("FINISHED SPELL CHECKING\n");
|
||||
|
@ -70,7 +68,7 @@ function CheckWord()
|
|||
word = dialog.wordInput.value;
|
||||
if (word != "") {
|
||||
dump("CheckWord: Word in edit field="+word+"\n");
|
||||
isMisspelled = edAppCore.checkCurrentWord(word);
|
||||
isMisspelled = editorShell.CheckCurrentWord(word);
|
||||
if (isMisspelled) {
|
||||
dump("CheckWord says word was misspelled\n");
|
||||
misspelledWord = word;
|
||||
|
@ -98,7 +96,7 @@ function IgnoreAll()
|
|||
{
|
||||
dump("SpellCheck: IgnoreAll\n");
|
||||
if (misspelledWord != "") {
|
||||
edAppCore.ignoreWordAllOccurrences(misspelledWord);
|
||||
editorShell.IgnoreWordAllOccurrences(misspelledWord);
|
||||
}
|
||||
NextWord();
|
||||
}
|
||||
|
@ -108,7 +106,7 @@ function Replace()
|
|||
dump("SpellCheck: Replace\n");
|
||||
newWord = dialog.wordInput.value;
|
||||
if (misspelledWord != "" && misspelledWord != newWord) {
|
||||
isMisspelled = edAppCore.replaceWord(misspelledWord, newWord, false);
|
||||
isMisspelled = editorShell.ReplaceWord(misspelledWord, newWord, false);
|
||||
}
|
||||
NextWord();
|
||||
}
|
||||
|
@ -118,7 +116,7 @@ function ReplaceAll()
|
|||
dump("SpellCheck: ReplaceAll\n");
|
||||
newWord = dialog.wordInput.value;
|
||||
if (misspelledWord != "" && misspelledWord != newWord) {
|
||||
isMisspelled = edAppCore.replaceWord(misspelledWord, newWord, true);
|
||||
isMisspelled = editorShell.ReplaceWord(misspelledWord, newWord, true);
|
||||
}
|
||||
NextWord();
|
||||
}
|
||||
|
@ -127,7 +125,7 @@ function AddToDictionary()
|
|||
{
|
||||
dump("SpellCheck: AddToDictionary\n");
|
||||
if (misspelledWord != "") {
|
||||
edAppCore.addWordToDictionary(misspelledWord);
|
||||
editorShell.AddWordToDictionary(misspelledWord);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,7 +146,7 @@ function Close()
|
|||
{
|
||||
dump("SpellCheck: Spell Checker Closed\n");
|
||||
// Shutdown the spell check and close the dialog
|
||||
edAppCore.closeSpellChecking();
|
||||
editorShell.CloseSpellChecking();
|
||||
window.close();
|
||||
}
|
||||
|
||||
|
@ -167,7 +165,7 @@ function FillSuggestedList(firstWord)
|
|||
|
||||
// Get suggested words until an empty string is returned
|
||||
do {
|
||||
word = edAppCore.getSuggestedWord();
|
||||
word = editorShell.GetSuggestedWord();
|
||||
dump("Suggested Word = "+word+"\n");
|
||||
if (word != "") {
|
||||
AppendStringToList(list, word);
|
||||
|
|
Загрузка…
Ссылка в новой задаче