Give editor app cores a unique name so that you can have more than one open at a time, and fix the dialogs to cope with this. Also added file opening UI.

This commit is contained in:
sfraser%netscape.com 1999-05-12 22:25:45 +00:00
parent 9897e27ec2
commit e11fb63db9
8 changed files with 431 additions and 302 deletions

View File

@ -1,5 +1,6 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://navigator/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://editor/skin/" type="text/css"?>
<!DOCTYPE window
@ -19,17 +20,18 @@
<window id="main-window" xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="Startup()" onunload="Shutdown()" title="Editor">
onload="EditorStartup()" onunload="EditorShutdown()" title="Editor">
<html:script language="JavaScript" src="chrome://editor/content/EditorCommands.js">
</html:script>
<broadcaster id="args" value="chrome://editor/content/EditorInitPage.html"/>
<broadcaster id="canPrint"/>
<menubar>
<menu name="File">
<menuitem name=".New" onclick=""/>
<menuitem name=".Open..." onclick=""/>
<menuitem name="New" onclick="EditorNew()"/>
<menuitem name="Open..." onclick="EditorOpen()"/>
<menuitem name=".Close" onclick="EditorClose()"/>
<separator />
<menuitem name="Save" onclick="EditorSave()"/>
@ -37,7 +39,7 @@
<separator />
<menuitem name=".Print Setup..." onclick=""/>
<menuitem name="Print Preview" onclick="EditorPrintPreview()"/>
<menuitem name=".Print..." onclick=""/>
<menuitem name=".Print..." onclick="EditorPrint()"/>
<separator />
<menuitem name="Quit" onclick="EditorExit()"/>
</menu>
@ -178,9 +180,24 @@
</toolbar>
</toolbox>
<html:iframe type="content" id="content-frame" html:src="chrome://editor/content/EditorInitPage.html" flex="100%" />
</box>
<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">
<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>
</window>

View File

@ -1,344 +1,430 @@
/* Main Composer window UI control */
/*the editor type, i.e. "text" or "html" */
/* the name of the editor. Must be unique to this window clique */
var editorName = "EditorAppCoreHTML";
var appCore = null;
var toolkitCore = null;
/*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 toolkitCore = null;
function Startup()
function EditorStartup()
{
dump("Doing Startup...\n");
/* 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("Doing Startup...\n");
dump("Creating EditorAppCore...\n");
appCore = new EditorAppCore();
if (appCore) {
dump(editorName + " has been created.\n");
appCore.Init(editorName);
/* 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("Creating EditorAppCore...\n");
appCore = new EditorAppCore();
if (appCore) {
dump("EditorAppCore has been created.\n");
appCore.Init(editorName);
appCore.setEditorType("html");
appCore.setContentWindow( window.frames[0] );
appCore.setWebShellWindow(window);
appCore.setToolbarWindow(window);
dump("EditorAppCore windows have been set.\n");
}
} else {
dump("EditorAppCore has already been created! Why?\n");
}
toolkitCore = XPAppCoresManager.Find("ToolkitCore");
if (!toolkitCore) {
toolkitCore = new ToolkitCore();
if (toolkitCore) {
toolkitCore.Init("ToolkitCore");
dump("ToolkitCore initialized for Editor\n");
}
} else {
dump("ToolkitCore found\n");
appCore.setWebShellWindow(window);
appCore.setToolbarWindow(window)
appCore.setEditorType("html");
appCore.setContentWindow( window.frames[0] );
// 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");
}
function EditorSave()
toolkitCore = XPAppCoresManager.Find("ToolkitCore");
if (!toolkitCore)
{
dump("In EditorSave...\n");
appCore = XPAppCoresManager.Find(editorName);
if (appCore)
{
appCore.save();
toolkitCore = new ToolkitCore();
if (toolkitCore) {
toolkitCore.Init("ToolkitCore");
dump("ToolkitCore initialized for Editor\n");
}
} else {
dump("ToolkitCore found\n");
}
}
function EditorSaveAs()
function EditorShutdown()
{
dump("In EditorShutdown..\n");
appCore = XPAppCoresManager.Remove(editorName);
}
// --------------------------- File menu ---------------------------
function EditorNew()
{
dump("In EditorNew..\n");
appCore = XPAppCoresManager.Find(editorName);
if (appCore)
{
dump("In EditorSave...\n");
appCore = XPAppCoresManager.Find(editorName);
if (appCore)
{
appCore.saveAs();
}
}
function EditorClose()
appCore.newWindow();
}
}
function EditorOpen()
{
dump("In EditorOpen..\n");
appCore = XPAppCoresManager.Find(editorName);
if (appCore)
{
dump("In EditorClose...\n");
appCore = XPAppCoresManager.Find(editorName);
if (appCore)
{
}
appCore.open();
}
}
function EditorSave()
{
dump("In EditorSave...\n");
appCore = XPAppCoresManager.Find(editorName);
if (appCore)
{
appCore.save();
}
}
function EditorSaveAs()
{
dump("In EditorSave...\n");
appCore = XPAppCoresManager.Find(editorName);
if (appCore)
{
appCore.saveAs();
}
}
function EditorPrint()
{
dump("In EditorPrint..\n");
appCore = XPAppCoresManager.Find(editorName);
if (appCore)
{
appCore.print();
}
}
function EditorClose()
{
dump("In EditorClose...\n");
appCore = XPAppCoresManager.Find(editorName);
if (appCore)
{
appCore.closeWindow();
}
}
// --------------------------- Edit menu ---------------------------
function EditorUndo()
{
if (appCore) {
dump("Undoing\n");
appCore.undo();
}
}
function EditorRedo()
{
if (appCore) {
dump("Redoing\n");
appCore.redo();
}
}
function EditorCut()
{
if (appCore) {
dump("Cutting\n");
appCore.cut();
}
}
function EditorCopy()
{
if (appCore) {
dump("Copying\n");
appCore.copy();
}
}
function EditorPaste()
{
if (appCore) {
dump("Pasting\n");
appCore.paste();
}
}
function EditorSelectAll()
{
if (appCore) {
dump("Selecting all\n");
appCore.selectAll();
}
}
function EditorFind(firstTime)
{
if (toolkitCore && firstTime) {
toolkitCore.ShowWindow("resource:/res/samples/find.xul", window);
}
function EditorFind(firstTime)
{
if (toolkitCore && firstTime) {
toolkitCore.ShowWindow("resource:/res/samples/find.xul", window);
if (appCore) {
appCore.find("test", true, true);
}
}
function EditorShowClipboard()
{
dump("In EditorShowClipboard...\n");
if (appCore) {
dump("Doing EditorShowClipboard...\n");
appCore.showClipboard();
}
}
// --------------------------- Text style ---------------------------
function SetTextProperty(property, attribute, value)
{
if (appCore) {
appCore.setTextProperty(property, attribute, value);
}
}
function SetParagraphFormat(paraFormat)
{
if (appCore) {
appCore.setParagraphFormat(paraFormat);
}
}
function SetFontSize(size)
{
if (appCore) {
appCore.setTextProperty("font", "size", size);
}
}
function SetFontFace(fontFace)
{
if (appCore) {
if( fontFace == "tt") {
// The old "teletype" attribute
appCore.setTextProperty("tt", "", "");
// Clear existing font face
fontFace = "";
}
if (appCore) {
appCore.find("test", true, true);
}
}
appCore.setTextProperty("font", "face", fontFace);
}
}
function SetTextProperty(property, attribute, value)
{
if (appCore) {
appCore.setTextProperty(property, attribute, value);
}
}
function SetParagraphFormat(paraFormat)
{
if (appCore) {
appCore.setParagraphFormat(paraFormat);
}
}
function SetFontSize(size)
{
if (appCore) {
appCore.setTextProperty("font", "size", size);
}
}
function SetFontFace(fontFace)
{
if (appCore) {
if( fontFace == "tt") {
// The old "teletype" attribute
appCore.setTextProperty("tt", "", "");
// Clear existing font face
fontFace = "";
}
appCore.setTextProperty("font", "face", fontFace);
}
}
function SetFontColor(color)
{
if (appCore) {
appCore.setTextProperty("font", "color", color);
}
}
function SetFontColor(color)
{
if (appCore) {
appCore.setTextProperty("font", "color", color);
}
}
// Debug methods to test the SELECT element used in a toolbar:
function OnChangeParaFormat()
{
dump(" *** Change Paragraph Format combobox setting\n");
}
function OnChangeParaFormat()
{
dump(" *** Change Paragraph Format combobox setting\n");
}
function OnFocusParaFormat()
{
dump(" *** OnFocus -- Paragraph Format\n");
}
function OnFocusParaFormat()
{
dump(" *** OnFocus -- Paragraph Format\n");
}
function OnBlurParaFormat()
{
dump(" *** OnBlur -- Paragraph Format\n");
}
function OnBlurParaFormat()
{
dump(" *** OnBlur -- Paragraph Format\n");
}
function EditorApplyStyle(styleName)
{
if (appCore) {
dump("Applying Style\n");
appCore.setTextProperty(styleName, null, null);
}
function EditorApplyStyle(styleName)
{
if (appCore) {
dump("Applying Style\n");
appCore.setTextProperty(styleName, null, null);
}
}
function EditorRemoveStyle(styleName)
{
if (appCore) {
dump("Removing Style\n");
appCore.removeTextProperty(styleName, null);
}
function EditorRemoveStyle(styleName)
{
if (appCore) {
dump("Removing Style\n");
appCore.removeTextProperty(styleName, null);
}
}
function EditorGetText()
{
if (appCore) {
dump("Getting text\n");
var outputText = appCore.contentsAsText;
dump(outputText + "\n");
}
}
// --------------------------- Output ---------------------------
function EditorGetHTML()
{
if (appCore) {
dump("Getting HTML\n");
var outputText = appCore.contentsAsHTML;
dump(outputText + "\n");
}
function EditorGetText()
{
if (appCore) {
dump("Getting text\n");
var outputText = appCore.contentsAsText;
dump(outputText + "\n");
}
}
function EditorUndo()
{
if (appCore) {
dump("Undoing\n");
appCore.undo();
}
function EditorGetHTML()
{
if (appCore) {
dump("Getting HTML\n");
var outputText = appCore.contentsAsHTML;
dump(outputText + "\n");
}
}
function EditorRedo()
{
if (appCore) {
dump("Redoing\n");
appCore.redo();
}
}
function EditorCut()
{
if (appCore) {
dump("Cutting\n");
appCore.cut();
}
}
function EditorCopy()
{
if (appCore) {
dump("Copying\n");
appCore.copy();
}
}
function EditorPaste()
{
if (appCore) {
dump("Pasting\n");
appCore.paste();
}
}
function EditorSelectAll()
{
if (appCore) {
dump("Selecting all\n");
appCore.selectAll();
}
}
function EditorInsertText()
{
if (appCore) {
dump("Inserting text\n");
appCore.insertText("Once more into the breach, dear friends.\n");
}
function EditorInsertText()
{
if (appCore) {
dump("Inserting text\n");
appCore.insertText("Once more into the breach, dear friends.\n");
}
}
function EditorInsertLink()
{
dump("Starting Insert Link... appCore, toolkitCore: "+(appCore==null)+(toolkitCore==null)+"\n");
if (appCore && toolkitCore) {
dump("Link Properties Dialog starting...\n");
toolkitCore.ShowModalDialog("chrome://editordlgs/content/EdLinkProps.xul",
window);
}
{
dump("Starting Insert Link... appCore, toolkitCore: "+(appCore==null)+(toolkitCore==null)+"\n");
if (appCore && toolkitCore) {
dump("Link Properties Dialog starting...\n");
// go back to using this when window.opener works.
//toolkitCore.ShowModalDialog("chrome://editordlgs/content/EdLinkProps.xul", window);
toolkitCore.ShowWindowWithArgs("chrome://editordlgs/content/EdLinkProps.xul", window, editorName);
}
}
function EditorInsertList(listType)
{
if (appCore) {
dump("Inserting link\n");
appCore.insertList(listType);
}
function EditorInsertList(listType)
{
if (appCore) {
dump("Inserting link\n");
appCore.insertList(listType);
}
}
function EditorInsertImage()
function EditorInsertImage()
{
dump("Starting Insert Image...\n");
if (appCore && toolkitCore) {
dump("Link Properties Dialog starting...\n");
//toolkitCore.ShowModalDialog("chrome://editordlgs/content/EdImageProps.xul", window);
toolkitCore.ShowWindowWithArgs("chrome://editordlgs/content/EdImageProps.xul", window, editorName);
}
}
function EditorExit()
{
if (appCore) {
dump("Exiting\n");
appCore.exit();
}
}
function EditorPrintPreview() {
if (toolkitCore) {
toolkitCore.ShowWindow("resource:/res/samples/printsetup.html", window);
}
}
// --------------------------- Debug stuff ---------------------------
function EditorTestSelection()
{
if (appCore)
{
dump("Starting Insert Image...\n");
if (appCore && toolkitCore) {
dump("Link Properties Dialog starting...\n");
toolkitCore.ShowModalDialog("chrome://editordlgs/content/EdImageProps.xul",
window);
dump("Testing selection\n");
var selection = appCore.editorSelection;
if (selection)
{
dump("Got selection\n");
var firstRange = selection.getRangeAt(0);
if (firstRange)
{
dump("Range contains \"");
dump(firstRange.toString() + "\"\n");
}
}
function EditorExit()
}
}
function EditorTestDocument()
{
if (appCore)
{
if (appCore) {
dump("Exiting\n");
appCore.exit();
dump("Getting document\n");
var theDoc = appCore.editorDocument;
if (theDoc)
{
dump("Got the doc\n");
dump("Document name:" + theDoc.nodeName + "\n");
dump("Document type:" + theDoc.doctype + "\n");
}
else
{
dump("Failed to get the doc\n");
}
}
}
function EditorPrintPreview() {
if (toolkitCore) {
toolkitCore.ShowWindow("resource:/res/samples/printsetup.html", window);
}
// --------------------------- Callbacks ---------------------------
function OpenFile(url)
{
// This is invoked from the browser app core.
core = XPAppCoresManager.Find("toolkitCore");
if ( !core ) {
core = new ToolkitCore();
if ( core ) {
core.Init("toolkitCore");
}
}
if ( core ) {
core.ShowWindowWithArgs( "chrome://editor/content/", window, url );
} else {
dump("Error; can't create toolkitCore\n");
}
}
function EditorTestSelection()
{
if (appCore)
{
dump("Testing selection\n");
var selection = appCore.editorSelection;
if (selection)
{
dump("Got selection\n");
var firstRange = selection.getRangeAt(0);
if (firstRange)
{
dump("Range contains \"");
dump(firstRange.toString() + "\"\n");
}
}
}
}
function EditorTestDocument()
{
if (appCore)
{
dump("Getting document\n");
var theDoc = appCore.editorDocument;
if (theDoc)
{
dump("Got the doc\n");
dump("Document name:" + theDoc.nodeName + "\n");
dump("Document type:" + theDoc.doctype + "\n");
}
else
{
dump("Failed to get the doc\n");
}
}
}
/* Status calls */
function onBoldChange()
{
var button = document.getElementById("Editor:Style:IsBold");
if (button)
{
var bold = button.getAttribute("bold");
if ( bold == "true" ) {
button.setAttribute( "disabled", false );
}
else {
button.setAttribute( "disabled", true );
}
}
else
{
dump("Can't find bold broadcaster!\n");
}
}
function Shutdown()
// --------------------------- Status calls ---------------------------
function onBoldChange()
{
var button = document.getElementById("Editor:Style:IsBold");
if (button)
{
}
var bold = button.getAttribute("bold");
if ( bold == "true" ) {
button.setAttribute( "disabled", false );
}
else {
button.setAttribute( "disabled", true );
}
}
else
{
dump("Can't find bold broadcaster!\n");
}
}

View File

@ -21,8 +21,13 @@ function Startup()
dump("toolkitCore not found!!! And we can't close the dialog!\n");
}
// 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");
// NEVER create an appcore here - we must find parent editor's
appCore = XPAppCoresManager.Find("EditorAppCoreHTML");
appCore = XPAppCoresManager.Find(editorName);
if(!appCore || !toolkitCore) {
dump("EditorAppCore not found!!!\n");
toolkitCore.CloseWindow(window);

View File

@ -13,5 +13,6 @@
<html:script language="JavaScript" src="chrome://editordlgs/content/EdCharacterProps.js">
</html:script>
<xul:broadcaster id="args" value=""/>
</xul:window>

View File

@ -22,11 +22,17 @@ function Startup()
dump("toolkitCore not found!!! And we can't close the dialog!\n");
}
// 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");
// NEVER create an appcore here - we must find parent editor's
appCore = XPAppCoresManager.Find("EditorAppCoreHTML");
appCore = XPAppCoresManager.Find(editorName);
if(!appCore || !toolkitCore) {
dump("EditorAppCore not found!!!\n");
toolkitCore.CloseWindow(window);
return;
}
dump("EditorAppCore found for Image Properties dialog\n");

View File

@ -2,6 +2,7 @@
<?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="205" title="Image Properties"
xmlns:xul ="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
@ -13,6 +14,9 @@
</script>
<script language="JavaScript" src="chrome://editordlgs/content/EdImageProps.js">
</script>
<xul:broadcaster id="args" value=""/>
<table>
<tr>
<td>

View File

@ -28,11 +28,17 @@ function Startup() {
dump("toolkitCore not found!!! And we can't close the dialog!\n");
}
// 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");
// NEVER create an appcore here - we must find parent editor's
appCore = XPAppCoresManager.Find("EditorAppCoreHTML");
appCore = XPAppCoresManager.Find(editorName);
if(!appCore || !toolkitCore) {
dump("EditorAppCore not found!!!\n");
toolkitCore.CloseWindow(window);
return;
}
dump("EditorAppCore found for Link Properties dialog\n");

View File

@ -2,6 +2,7 @@
<?xml-stylesheet href="chrome://global/skin/xul.css" type="text/css"?>
<?xml-stylesheet href="chrome://editordlgs/skin/EditorDialog.css" type="text/css"?>
<!DOCTYPE window>
<xul:window width="320" height="255" title="Link Properties"
xmlns:xul ="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns="http://www.w3.org/TR/REC-html40"
@ -12,6 +13,9 @@
</script>
<script language="JavaScript" src="chrome://editordlgs/content/EdLinkProps.js">
</script>
<xul:broadcaster id="args" value=""/>
<table>
<tr>
<td>