From b967b34da50809e4c01e6effffa8c97f26cde225 Mon Sep 17 00:00:00 2001 From: "cmanske%netscape.com" Date: Fri, 7 May 1999 00:44:46 +0000 Subject: [PATCH] More improvements to insert link and insert image dialogs. Added EdDialogCommon.js, where we should put java script used by all dialogs --- editor/base/nsHTMLEditor.cpp | 19 +++- editor/libeditor/html/nsHTMLEditor.cpp | 19 +++- editor/ui/dialogs/content/EdCharacterProps.js | 13 ++- .../ui/dialogs/content/EdCharacterProps.xul | 5 + editor/ui/dialogs/content/EdDialogCommon.js | 23 ++++ editor/ui/dialogs/content/EdImageProps.js | 102 ++++++++++++++--- editor/ui/dialogs/content/EdImageProps.xul | 8 +- editor/ui/dialogs/content/EdLinkProps.js | 103 +++++++++--------- editor/ui/dialogs/content/EdLinkProps.xul | 5 +- editor/ui/dialogs/content/MANIFEST | 1 + editor/ui/dialogs/content/Makefile.in | 1 + editor/ui/dialogs/content/makefile.win | 2 + 12 files changed, 219 insertions(+), 82 deletions(-) create mode 100644 editor/ui/dialogs/content/EdDialogCommon.js diff --git a/editor/base/nsHTMLEditor.cpp b/editor/base/nsHTMLEditor.cpp index c3663e0cd8f..25b2ad384a6 100644 --- a/editor/base/nsHTMLEditor.cpp +++ b/editor/base/nsHTMLEditor.cpp @@ -1439,8 +1439,10 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu iter->Next(); } - if (!bNodeFound) - printf("No nodes of tag name = %s were found in selection\n", aTagName); + if (!bNodeFound) { + char TagBuf[50] = ""; + printf("No nodes of tag name = %s were found in selection\n", aTagName.ToCString(TagBuf, 50)); + } } } else { // Should never get here? @@ -1525,7 +1527,20 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection, ns nsCOMPtr parentSelectedNode; PRInt32 offsetOfNewNode; + // Clear current selection. + // Should put caret at anchor point? + if (!aDeleteSelection) + { + nsCOMPtrselection; + nsresult res = nsEditor::GetSelection(getter_AddRefs(selection)); + if (NS_SUCCEEDED(res) && selection) + { + selection->ClearSelection(); + } + } + DeleteSelectionAndPrepareToCreateNode(parentSelectedNode, offsetOfNewNode); + if (NS_SUCCEEDED(result)) { nsCOMPtr newNode = do_QueryInterface(aElement); diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index c3663e0cd8f..25b2ad384a6 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -1439,8 +1439,10 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu iter->Next(); } - if (!bNodeFound) - printf("No nodes of tag name = %s were found in selection\n", aTagName); + if (!bNodeFound) { + char TagBuf[50] = ""; + printf("No nodes of tag name = %s were found in selection\n", aTagName.ToCString(TagBuf, 50)); + } } } else { // Should never get here? @@ -1525,7 +1527,20 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection, ns nsCOMPtr parentSelectedNode; PRInt32 offsetOfNewNode; + // Clear current selection. + // Should put caret at anchor point? + if (!aDeleteSelection) + { + nsCOMPtrselection; + nsresult res = nsEditor::GetSelection(getter_AddRefs(selection)); + if (NS_SUCCEEDED(res) && selection) + { + selection->ClearSelection(); + } + } + DeleteSelectionAndPrepareToCreateNode(parentSelectedNode, offsetOfNewNode); + if (NS_SUCCEEDED(result)) { nsCOMPtr newNode = do_QueryInterface(aElement); diff --git a/editor/ui/dialogs/content/EdCharacterProps.js b/editor/ui/dialogs/content/EdCharacterProps.js index 4e3ba603cac..cd25ce56106 100644 --- a/editor/ui/dialogs/content/EdCharacterProps.js +++ b/editor/ui/dialogs/content/EdCharacterProps.js @@ -1,11 +1,14 @@ - // dialog initialization code +// OnOK(), Undo(), and Cancel() are in EdDialogCommon.js +// applyChanges() must be implemented here + +// dialog initialization code var appCore; var toolkitCore; var insertNew = true; var selectionIsCollapsed = false; var undoCount = 0; -function Statup() +function Startup() { dump("Doing Character Props Startup...\n"); toolkitCore = XPAppCoresManager.Find("ToolkitCore"); @@ -24,4 +27,8 @@ function Statup() dump("EditorAppCore not found!!!\n"); toolkitCore.CloseWindow(window); } -} \ No newline at end of file +} + +function applyChanges() +{ +} diff --git a/editor/ui/dialogs/content/EdCharacterProps.xul b/editor/ui/dialogs/content/EdCharacterProps.xul index 5736afc6833..09c4ff54978 100644 --- a/editor/ui/dialogs/content/EdCharacterProps.xul +++ b/editor/ui/dialogs/content/EdCharacterProps.xul @@ -7,6 +7,11 @@ xmlns:xul ="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" onload = "Startup()"> + + + + diff --git a/editor/ui/dialogs/content/EdDialogCommon.js b/editor/ui/dialogs/content/EdDialogCommon.js new file mode 100644 index 00000000000..1a988bd8f1d --- /dev/null +++ b/editor/ui/dialogs/content/EdDialogCommon.js @@ -0,0 +1,23 @@ +function onUndo() { + if (undoCount > 0) + { + dump("Undo count = "+undoCount+"\n"); + undoCount = undoCount - 1; + appCore.undo(); + } +} + +function onOK() { + applyChanges(); + //toolkitCore.CloseWindow(window); +} + +function onCancel() { + // Undo all actions performed within the dialog + // TODO: We need to suppress reflow/redraw untill all levels are undone + while (undoCount > 0) { + appCore.undo(); + } + //toolkitCore.CloseWindow(window); +} + diff --git a/editor/ui/dialogs/content/EdImageProps.js b/editor/ui/dialogs/content/EdImageProps.js index 1f10fa90803..1e4fd5e0138 100644 --- a/editor/ui/dialogs/content/EdImageProps.js +++ b/editor/ui/dialogs/content/EdImageProps.js @@ -1,28 +1,94 @@ +// OnOK(), Undo(), and Cancel() are in EdDialogCommon.js +// applyChanges() must be implemented here + var appCore; var toolkitCore; var insertNew = true; -var selectionIsCollapsed = false; var undoCount = 0; +var imageElement; +var tagName = "img" // 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"); - } + 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 appcore here - we must find parent editor's - appCore = XPAppCoresManager.Find("EditorAppCoreHTML"); - if(!appCore || !toolkitCore) { - dump("EditorAppCore not found!!!\n"); - toolkitCore.CloseWindow(window); - } - dump("EditorAppCore found for Image Properties dialog\n"); + // NEVER create an appcore here - we must find parent editor's + appCore = XPAppCoresManager.Find("EditorAppCoreHTML"); + if(!appCore || !toolkitCore) { + dump("EditorAppCore not found!!!\n"); + toolkitCore.CloseWindow(window); + } + dump("EditorAppCore found for Image Properties dialog\n"); + + // Create dialog object to store controls for easy access + 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 || + null == dialog.AltText ) + { + dump("Not all dialog controls were found!!!\n"); + } + + initDialog(); + + dialog.Src.focus(); + if (fileChild) + fileChild.focus(); } + +function initDialog() { + // Get a single selected anchor element + imageElement = appCore.getSelectedElement(tagName); + + if (imageElement) { + // We found an element and don't need to insert one + insertNew = false; + dump("Found existing image\n"); + } else { + insertNew = true; + // We don't have an element selected, + // so create one with default attributes + dump("Element not selected - calling createElementWithDefaults\n"); + imageElement = appCore.createElementWithDefaults(tagName); + } + + if(!imageElement) + { + dump("Failed to get selected element or create a new one!\n"); + //toolkitCore.CloseWindow(window); + } +} + +function applyChanges() +{ + // TODO: BE SURE Src AND AltText are completed! + imageElement.setAttribute("src",dialog.Src.value); + // We must convert to "file:///" format else image doesn't load! + imageElement.setAttribute("alt",dialog.AltText.value); + if (insertNew) { + dump("Src="+imageElement.getAttribute("src")+" Alt="+imageElement.getAttribute("alt")+"\n"); + appCore.insertElement(imageElement, true) + + } +} \ No newline at end of file diff --git a/editor/ui/dialogs/content/EdImageProps.xul b/editor/ui/dialogs/content/EdImageProps.xul index cc3837bca18..df968b5daf9 100644 --- a/editor/ui/dialogs/content/EdImageProps.xul +++ b/editor/ui/dialogs/content/EdImageProps.xul @@ -3,18 +3,22 @@ - + +
Image Information - +

Enter a remote URL or local file:

+

Alternative Text

diff --git a/editor/ui/dialogs/content/EdLinkProps.js b/editor/ui/dialogs/content/EdLinkProps.js index c4798aa1153..b0a5d0c9501 100644 --- a/editor/ui/dialogs/content/EdLinkProps.js +++ b/editor/ui/dialogs/content/EdLinkProps.js @@ -1,10 +1,14 @@ +// OnOK(), Undo(), and Cancel() are in EdDialogCommon.js +// applyChanges() must be implemented here + var appCore; var toolkitCore; var anchorElement = null; var insertNew = true; var needLinkText = false; -var selectionIsCollapsed = false; +var selection; var undoCount = 0; +var makeLinkWithSelection = false; // NOTE: Use "HREF" instead of "A" to distinguish from Named Anchor // The returned node is has an "A" tagName @@ -37,27 +41,35 @@ function Startup() { dialog = new Object; dialog.linkTextInput = document.getElementById("linkTextInput"); dialog.hrefInput = document.getElementById("hrefInput"); - dialog.linkMessage = document.getElementById("linkMessage"); - dialog.ok = document.getElementById("OK"); + + // Kinda clunky: Message was wrapped in a

, so actual message is a child text node + dialog.linkMessage = (document.getElementById("linkMessage")).firstChild; if (null == dialog.linkTextInput || null == dialog.hrefInput || - null == dialog.linkMessage || - null == dialog.ok ) + null == dialog.linkMessage ) { dump("Not all dialog controls were found!!!\n"); } + + // Set data for the dialog controls + initDialog(); - if (!insertNew) - { - var parent = dialog.linkTextInput.parentNode; - if (parent) { - parent.removeChild(dialog.linkTextInput); + // Set initial focus + + if (insertNew) { + dialog.linkTextInput.focus(); + } else { + dialog.hrefInput.focus(); + + // We will not insert a new link at caret, so remove link text input field + parentNode = dialog.linkTextInput.parentNode; + if (parentNode) { + dump("Removing link text input field.\n"); + parentNode.removeChild(dialog.linkTextInput); dialog.linkTextInput = null; - // TODO: Replace the text with the currently-selected text } } - initDialog(); } function initDialog() { @@ -65,10 +77,8 @@ function initDialog() { anchorElement = appCore.getSelectedElement(tagName); selection = appCore.editorSelection; - if (selection) - { - selectionIsCollapsed = selection.selectionIsCollapsed; - dump("There is a selection: collapsed = "+selectionIsCollapsed+"\n"); + if (selection) { + dump("There is a selection: collapsed = "+selection.isCollapsed+"\n"); } else { dump("Failed to get selection\n"); } @@ -77,26 +87,38 @@ function initDialog() { // We found an element and don't need to insert one insertNew = false; - // BUT href is a weird case: If selection extends beyond - // the link, user probably wants to extend link to - // entire selection. We do this by "inserting" the link - // (actually does the appropriate reparenting) - if (!selectionIsCollapsed) + if (!selection.isCollapsed) { - insertNew = true; + // HREF is a weird case: If selection extends beyond + // the link, user probably wants to extend link to + // entire selection. + // TODO: We need to know if selection extends beyond existing + // link text before we should do this + //makeLinkWithSelection = true; } } else { - insertNew = true; // We don't have an element selected, // so create one with default attributes dump("Element not selected - calling createElementWithDefaults\n"); anchorElement = appCore.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; + } if(!anchorElement) { dump("Failed to get selected element or create a new one!\n"); toolkitCore.CloseWindow(window); + } else if (!insertNew) { + dump("Need to get selected text\n"); + + // Replace the link message with the link source string + // TODO: Get the text of the selection WHAT ABOUT IMAGES? + // Maybe have a special method "GetLinkSource" that resolves images as + // their URL? E.g.: "Link source [image:http://myimage.gif]" + dialog.linkMessage.data = "[Link source text or image URL goes here]"; } } @@ -110,18 +132,15 @@ function applyChanges() anchorElement.setAttribute("href",dialog.hrefInput.value); // Get text to use for a new link - if (insertNew) - { + if (insertNew) { // Append the link text as the last child node // of the anchor node textNode = appCore.editorDocument.createTextNode(dialog.linkTextInput.value); - if (textNode) - { + if (textNode) { anchorElement.appendChild(textNode); } newElement = appCore.insertElement(anchorElement, true); - if (newElement != anchorElement) - { + if (newElement != anchorElement) { dump("Returned element from insertElement is different from orginal element.\n"); } } @@ -131,27 +150,3 @@ function applyChanges() // Reinitialize dialog data initDialog(); } - -function onUndo() { - if (undoCount > 0) - { - dump("Undo count = "+undoCount+"\n"); - undoCount = undoCount - 1; - appCore.undo(); - } -} - -function onOK() { - applyChanges(); - //toolkitCore.CloseWindow(window); -} - -function onCancel() { - // Undo all actions performed within the dialog - // TODO: We need to suppress reflow/redraw untill all levels are undone - while (undoCount > 0) { - appCore.undo(); - } - //toolkitCore.CloseWindow(window); -} - diff --git a/editor/ui/dialogs/content/EdLinkProps.xul b/editor/ui/dialogs/content/EdLinkProps.xul index d365778dd4b..860524296ab 100644 --- a/editor/ui/dialogs/content/EdLinkProps.xul +++ b/editor/ui/dialogs/content/EdLinkProps.xul @@ -7,13 +7,16 @@ xmlns="http://www.w3.org/TR/REC-html40" onload = "Startup()"> + + diff --git a/editor/ui/dialogs/content/MANIFEST b/editor/ui/dialogs/content/MANIFEST index d0e775dbed8..400ae52b687 100644 --- a/editor/ui/dialogs/content/MANIFEST +++ b/editor/ui/dialogs/content/MANIFEST @@ -1,6 +1,7 @@ #dialogs:content directory +EdDialogCommon.js EdCharacterProps.xul EdCharacterProps.js EdImageProps.xul diff --git a/editor/ui/dialogs/content/Makefile.in b/editor/ui/dialogs/content/Makefile.in index 64ec9457c26..d1f32bbe5f5 100644 --- a/editor/ui/dialogs/content/Makefile.in +++ b/editor/ui/dialogs/content/Makefile.in @@ -27,6 +27,7 @@ include $(topsrcdir)/config/config.mk include $(topsrcdir)/config/rules.mk EXPORT_RESOURCE_CONTENT = \ + $(srcdir)/EdDialogCommon.js \ $(srcdir)/EdLinkProps.xul \ $(srcdir)/EdImageProps.xul \ $(srcdir)/EdCharacterProps.xul \ diff --git a/editor/ui/dialogs/content/makefile.win b/editor/ui/dialogs/content/makefile.win index 8981f33f01d..dd9583f153a 100644 --- a/editor/ui/dialogs/content/makefile.win +++ b/editor/ui/dialogs/content/makefile.win @@ -20,6 +20,7 @@ DEPTH=..\..\..\.. include <$(DEPTH)\config\rules.mak> install:: + $(MAKE_INSTALL) EdDialogCommon.js $(DIST)\bin\chrome\editor\dialogs\content\default $(MAKE_INSTALL) EdLinkProps.xul $(DIST)\bin\chrome\editor\dialogs\content\default $(MAKE_INSTALL) EdLinkProps.js $(DIST)\bin\chrome\editor\dialogs\content\default $(MAKE_INSTALL) EdImageProps.xul $(DIST)\bin\chrome\editor\dialogs\content\default @@ -28,6 +29,7 @@ install:: $(MAKE_INSTALL) EdCharacterProps.js $(DIST)\bin\chrome\editor\dialogs\content\default clobber:: + rm -f $(DIST)\bin\chrome\editor\dialogs\content\default\EdDialogCommon.js rm -f $(DIST)\bin\chrome\editor\dialogs\content\default\EdLinkProps.xul rm -f $(DIST)\bin\chrome\editor\dialogs\content\default\EdLinkProps.js rm -f $(DIST)\bin\chrome\editor\dialogs\content\default\EdImageProps.xul
Link source -

Enter text to display for a new link:

+

Enter text to display for a new link: