More improvements to insert link and insert image dialogs. Added EdDialogCommon.js, where we should put java script used by all dialogs

This commit is contained in:
cmanske%netscape.com 1999-05-07 00:44:46 +00:00
Родитель 3ff6ddce37
Коммит b967b34da5
12 изменённых файлов: 219 добавлений и 82 удалений

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

@ -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<nsIDOMNode> parentSelectedNode;
PRInt32 offsetOfNewNode;
// Clear current selection.
// Should put caret at anchor point?
if (!aDeleteSelection)
{
nsCOMPtr<nsIDOMSelection>selection;
nsresult res = nsEditor::GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(res) && selection)
{
selection->ClearSelection();
}
}
DeleteSelectionAndPrepareToCreateNode(parentSelectedNode, offsetOfNewNode);
if (NS_SUCCEEDED(result))
{
nsCOMPtr<nsIDOMNode> newNode = do_QueryInterface(aElement);

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

@ -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<nsIDOMNode> parentSelectedNode;
PRInt32 offsetOfNewNode;
// Clear current selection.
// Should put caret at anchor point?
if (!aDeleteSelection)
{
nsCOMPtr<nsIDOMSelection>selection;
nsresult res = nsEditor::GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(res) && selection)
{
selection->ClearSelection();
}
}
DeleteSelectionAndPrepareToCreateNode(parentSelectedNode, offsetOfNewNode);
if (NS_SUCCEEDED(result))
{
nsCOMPtr<nsIDOMNode> newNode = do_QueryInterface(aElement);

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

@ -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");
@ -25,3 +28,7 @@ function Statup()
toolkitCore.CloseWindow(window);
}
}
function applyChanges()
{
}

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

@ -7,6 +7,11 @@
xmlns:xul ="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload = "Startup()">
<!-- Methods common to all editor dialogs -->
<script language="JavaScript" src="chrome://editordlgs/content/EdDialogCommon.js">
</script>
<html:script language="JavaScript" src="chrome://editordlgs/content/EdCharacterProps.js">
</html:script>
</xul:window>

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

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

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

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

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

@ -3,18 +3,22 @@
<?xml-stylesheet href="chrome://editordlgs/skin/EditorDialog.css" type="text/css"?>
<!DOCTYPE window>
<!-- dialog containing a control requiring initial setup -->
<xul:window width="370" height="255" title="Image Properties"
<xul:window width="380" height="205" title="Image Properties"
xmlns:xul ="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns="http://www.w3.org/TR/REC-html40"
onload = "Startup()">
<!-- Methods common to all editor dialogs -->
<script language="JavaScript" src="chrome://editordlgs/content/EdDialogCommon.js">
</script>
<script language="JavaScript" src="chrome://editordlgs/content/EdImageProps.js">
</script>
<table>
<tr>
<td>
<fieldset><legend align="left">Image Information </legend>
<input type="file" value=" Choose File... " size="50" length="50" maxlength="255" id="image.url" />
<p class="smallmargin">Enter a remote URL or local file: </p>
<input type="file" size="50" length="50" maxlength="255" id="image.Src" />
<br/>
<p class="smallmargin">Alternative Text</p>
<input type="text" size="30" length="30" maxlength="255" id="image.AltText" />

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

@ -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 <p>, 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");
}
if (!insertNew)
{
var parent = dialog.linkTextInput.parentNode;
if (parent) {
parent.removeChild(dialog.linkTextInput);
// Set data for the dialog controls
initDialog();
// 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);
}

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

@ -7,13 +7,16 @@
xmlns="http://www.w3.org/TR/REC-html40"
onload = "Startup()">
<!-- Methods common to all editor dialogs -->
<script language="JavaScript" src="chrome://editordlgs/content/EdDialogCommon.js">
</script>
<script language="JavaScript" src="chrome://editordlgs/content/EdLinkProps.js">
</script>
<table>
<tr>
<td>
<fieldset><legend align="left">Link source </legend>
<p class="smallmargin" id="linkMessage"> Enter text to display for a new link:</p>
<p class="smallmargin" id="linkMessage">Enter text to display for a new link:</p>
<input type="text" size="25" length="25" maxlength="100" id="linkTextInput"></input>
</fieldset>
</td>

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

@ -1,6 +1,7 @@
#dialogs:content directory
EdDialogCommon.js
EdCharacterProps.xul
EdCharacterProps.js
EdImageProps.xul

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

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

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

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