diff --git a/editor/base/nsEditor.cpp b/editor/base/nsEditor.cpp index 0112ff1c4607..c832e2aa3996 100644 --- a/editor/base/nsEditor.cpp +++ b/editor/base/nsEditor.cpp @@ -2108,14 +2108,7 @@ NS_IMETHODIMP nsEditor::DeleteSelectionAndPrepareToCreateNode(nsCOMPtrselectedParentNodeAsText; selectedParentNodeAsText = do_QueryInterface(parentSelectedNode); -#ifdef DEBUG_cmanske - // What is the parent node for the selection? - nsAutoString tag; - parentSelectedNode->GetNodeName(tag); - printf("DeleteSelectionAndPrepareToCreateNode: Parent of selected node: "); - wprintf(tag.GetUnicode()); - printf("\n"); -#endif + /* if the selection is a text node, split the text node if necesary and compute where to put the new node */ @@ -2159,14 +2152,6 @@ NS_IMETHODIMP nsEditor::DeleteSelectionAndPrepareToCreateNode(nsCOMPtrItem(offsetOfSelectedNode, getter_AddRefs(selectedNode)); if ((NS_SUCCEEDED(result)) && selectedNode) { -#if 0 //def DEBUG_cmanske - // What is the item at the selected offset? - nsAutoString tag; - selectedNode->GetNodeName(tag); - printf("Selected Node's name = "); - wprintf(tag.GetUnicode()); - printf("\n"); -#endif nsCOMPtrselectedNodeAsText; selectedNodeAsText = do_QueryInterface(selectedNode); nsCOMPtrchildList; diff --git a/editor/base/nsHTMLEditor.cpp b/editor/base/nsHTMLEditor.cpp index 06a7cc3c6271..7bf479fb3bf4 100644 --- a/editor/base/nsHTMLEditor.cpp +++ b/editor/base/nsHTMLEditor.cpp @@ -2308,18 +2308,17 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection) } nsCOMPtr parentSelectedNode; - PRInt32 splitPointOffset; - PRInt32 offsetOfSelectedNode; + PRInt32 offsetForInsert; res = selection->GetAnchorNode(getter_AddRefs(parentSelectedNode)); - if (NS_SUCCEEDED(res) && NS_SUCCEEDED(selection->GetAnchorOffset(&splitPointOffset)) && parentSelectedNode) + if (NS_SUCCEEDED(res) && NS_SUCCEEDED(selection->GetAnchorOffset(&offsetForInsert)) && parentSelectedNode) { #ifdef DEBUG_cmanske { nsAutoString name; parentSelectedNode->GetNodeName(name); - printf("parentSelectedNode: "); + printf("InsertElement: Anchor node of selection: "); wprintf(name.GetUnicode()); - printf("\n"); + printf(" Offset: %d\n", offsetForInsert); } #endif nsAutoString tagName; @@ -2328,15 +2327,15 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection) nsCOMPtr parent = parentSelectedNode; nsCOMPtr topChild = parentSelectedNode; nsCOMPtr tmp; - PRInt32 offset = offsetOfSelectedNode; - + nsAutoString parentTagName; + PRBool isRoot; + + // Search up the parent chain to find a suitable container while (!CanContainTag(parent, tagName)) { // If the current parent is a root (body or table cell) // then go no further - we can't insert - nsAutoString parentTagName; parent->GetNodeName(parentTagName); - PRBool isRoot; res = IsRootTag(parentTagName, isRoot); if (!NS_SUCCEEDED(res) || isRoot) return NS_ERROR_FAILURE; @@ -2347,18 +2346,31 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection) topChild = parent; parent = tmp; } - - // we need to split up to the child of parent - res = SplitNodeDeep(topChild, parentSelectedNode, splitPointOffset); - if (NS_FAILED(res)) - return res; - // topChild already went to the right on the split - // so we don't need to add one to offset when figuring - // out where to plop list - offset = GetIndexOf(parent,topChild); - - // Now we can finally insert the new node - res = InsertNode(aElement, parent, offset); +#ifdef DEBUG_cmanske + { + nsAutoString name; + parent->GetNodeName(name); + printf("Parent node to insert under: "); + wprintf(name.GetUnicode()); + printf("\n"); + topChild->GetNodeName(name); + printf("TopChild to split: "); + wprintf(name.GetUnicode()); + printf("\n"); + } +#endif + if (parent != topChild) + { + // we need to split some levels above the original selection parent + res = SplitNodeDeep(topChild, parentSelectedNode, offsetForInsert); + if (NS_FAILED(res)) + return res; + // topChild went to the right on the split + // so this is the offset to insert at + offsetForInsert = GetIndexOf(parent,topChild); + } + // Now we can insert the new node + res = InsertNode(aElement, parent, offsetForInsert); // Set caret after element, but check for special case // of inserting table-related elements: set in first cell instead @@ -2634,6 +2646,19 @@ nsHTMLEditor::SetCaretAfterElement(nsIDOMElement* aElement) { // Collapse selection to just after desired element, selection->Collapse(parent, offsetInParent+1); +#ifdef DEBUG_cmanske + { + nsAutoString name; + parent->GetNodeName(name); + printf("SetCaretAfterElement: Parent node: "); + wprintf(name.GetUnicode()); + printf(" Offset: %d\n\nHTML:\n", offsetInParent+1); + nsString Format("text/html"); + nsString ContentsAs; + OutputToString(ContentsAs, Format, 2); + wprintf(ContentsAs.GetUnicode()); + } +#endif } } } diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index 0112ff1c4607..c832e2aa3996 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -2108,14 +2108,7 @@ NS_IMETHODIMP nsEditor::DeleteSelectionAndPrepareToCreateNode(nsCOMPtrselectedParentNodeAsText; selectedParentNodeAsText = do_QueryInterface(parentSelectedNode); -#ifdef DEBUG_cmanske - // What is the parent node for the selection? - nsAutoString tag; - parentSelectedNode->GetNodeName(tag); - printf("DeleteSelectionAndPrepareToCreateNode: Parent of selected node: "); - wprintf(tag.GetUnicode()); - printf("\n"); -#endif + /* if the selection is a text node, split the text node if necesary and compute where to put the new node */ @@ -2159,14 +2152,6 @@ NS_IMETHODIMP nsEditor::DeleteSelectionAndPrepareToCreateNode(nsCOMPtrItem(offsetOfSelectedNode, getter_AddRefs(selectedNode)); if ((NS_SUCCEEDED(result)) && selectedNode) { -#if 0 //def DEBUG_cmanske - // What is the item at the selected offset? - nsAutoString tag; - selectedNode->GetNodeName(tag); - printf("Selected Node's name = "); - wprintf(tag.GetUnicode()); - printf("\n"); -#endif nsCOMPtrselectedNodeAsText; selectedNodeAsText = do_QueryInterface(selectedNode); nsCOMPtrchildList; diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index 06a7cc3c6271..7bf479fb3bf4 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -2308,18 +2308,17 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection) } nsCOMPtr parentSelectedNode; - PRInt32 splitPointOffset; - PRInt32 offsetOfSelectedNode; + PRInt32 offsetForInsert; res = selection->GetAnchorNode(getter_AddRefs(parentSelectedNode)); - if (NS_SUCCEEDED(res) && NS_SUCCEEDED(selection->GetAnchorOffset(&splitPointOffset)) && parentSelectedNode) + if (NS_SUCCEEDED(res) && NS_SUCCEEDED(selection->GetAnchorOffset(&offsetForInsert)) && parentSelectedNode) { #ifdef DEBUG_cmanske { nsAutoString name; parentSelectedNode->GetNodeName(name); - printf("parentSelectedNode: "); + printf("InsertElement: Anchor node of selection: "); wprintf(name.GetUnicode()); - printf("\n"); + printf(" Offset: %d\n", offsetForInsert); } #endif nsAutoString tagName; @@ -2328,15 +2327,15 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection) nsCOMPtr parent = parentSelectedNode; nsCOMPtr topChild = parentSelectedNode; nsCOMPtr tmp; - PRInt32 offset = offsetOfSelectedNode; - + nsAutoString parentTagName; + PRBool isRoot; + + // Search up the parent chain to find a suitable container while (!CanContainTag(parent, tagName)) { // If the current parent is a root (body or table cell) // then go no further - we can't insert - nsAutoString parentTagName; parent->GetNodeName(parentTagName); - PRBool isRoot; res = IsRootTag(parentTagName, isRoot); if (!NS_SUCCEEDED(res) || isRoot) return NS_ERROR_FAILURE; @@ -2347,18 +2346,31 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection) topChild = parent; parent = tmp; } - - // we need to split up to the child of parent - res = SplitNodeDeep(topChild, parentSelectedNode, splitPointOffset); - if (NS_FAILED(res)) - return res; - // topChild already went to the right on the split - // so we don't need to add one to offset when figuring - // out where to plop list - offset = GetIndexOf(parent,topChild); - - // Now we can finally insert the new node - res = InsertNode(aElement, parent, offset); +#ifdef DEBUG_cmanske + { + nsAutoString name; + parent->GetNodeName(name); + printf("Parent node to insert under: "); + wprintf(name.GetUnicode()); + printf("\n"); + topChild->GetNodeName(name); + printf("TopChild to split: "); + wprintf(name.GetUnicode()); + printf("\n"); + } +#endif + if (parent != topChild) + { + // we need to split some levels above the original selection parent + res = SplitNodeDeep(topChild, parentSelectedNode, offsetForInsert); + if (NS_FAILED(res)) + return res; + // topChild went to the right on the split + // so this is the offset to insert at + offsetForInsert = GetIndexOf(parent,topChild); + } + // Now we can insert the new node + res = InsertNode(aElement, parent, offsetForInsert); // Set caret after element, but check for special case // of inserting table-related elements: set in first cell instead @@ -2634,6 +2646,19 @@ nsHTMLEditor::SetCaretAfterElement(nsIDOMElement* aElement) { // Collapse selection to just after desired element, selection->Collapse(parent, offsetInParent+1); +#ifdef DEBUG_cmanske + { + nsAutoString name; + parent->GetNodeName(name); + printf("SetCaretAfterElement: Parent node: "); + wprintf(name.GetUnicode()); + printf(" Offset: %d\n\nHTML:\n", offsetInParent+1); + nsString Format("text/html"); + nsString ContentsAs; + OutputToString(ContentsAs, Format, 2); + wprintf(ContentsAs.GetUnicode()); + } +#endif } } } diff --git a/editor/ui/composer/content/EditorAppShell.xul b/editor/ui/composer/content/EditorAppShell.xul index 1b143c9d526e..43a8b97c3166 100644 --- a/editor/ui/composer/content/EditorAppShell.xul +++ b/editor/ui/composer/content/EditorAppShell.xul @@ -259,6 +259,8 @@ + diff --git a/editor/ui/composer/content/EditorCommands.js b/editor/ui/composer/content/EditorCommands.js index c7179cf9ba35..f25272f76972 100644 --- a/editor/ui/composer/content/EditorCommands.js +++ b/editor/ui/composer/content/EditorCommands.js @@ -476,8 +476,8 @@ function CheckSpelling() dump(firstMisspelledWord+"\n"); if( firstMisspelledWord == "") { - dump("THERE IS NO MISSPELLED WORD!\n"); - // TODO: PUT UP A MESSAGE BOX TO TELL THE USER + // No misspelled word - tell user + window.openDialog("chrome://editor/content/EdMessage.xul", "NoSpellError", "chrome", "", "No misspelled word was found.", "Check Spelling"); spellChecker.CloseSpellChecking(); } else { dump("We found a MISSPELLED WORD\n"); diff --git a/editor/ui/dialogs/content/EdDialogCommon.js b/editor/ui/dialogs/content/EdDialogCommon.js index 8304e1576242..9224ffe292de 100644 --- a/editor/ui/dialogs/content/EdDialogCommon.js +++ b/editor/ui/dialogs/content/EdDialogCommon.js @@ -23,6 +23,14 @@ function InitEditorShell() return true; } +function StringExists(string) +{ + if (string != null && string != "undefined" && string.length > 0) + return true; + + return false; +} + function ClearList(list) { for( i = (list.length-1); i >= 0; i-- ) { @@ -93,7 +101,6 @@ function ValidateNumberString(value, minValue, maxValue) } message = "The number you entered ("+number+") is outside of allowed range.\nPlease enter a number between "+minValue+" and "+maxValue; ShowInputErrorMessage(message); - window.openDialog("chrome://editor/content/EdMessage.xul", "MsgDlg", "chrome", "", message, "Input Error", "OK"); // Return an empty string to indicate error return ""; @@ -102,7 +109,7 @@ function ValidateNumberString(value, minValue, maxValue) function ShowInputErrorMessage(message) { // This is NOT MODAL as of 7/16/99! - window.openDialog("chrome://editor/content/EdMessage.xul", "MsgDlg", "chrome", "", message, "Input Error", "OK"); + window.openDialog("chrome://editor/content/EdMessage.xul", "MsgDlg", "chrome", "", message, "Input Error"); } function TrimStringLeft(string) diff --git a/editor/ui/dialogs/content/EdDialogTemplate.xul b/editor/ui/dialogs/content/EdDialogTemplate.xul index f2af9275dbc0..81c0a623615c 100644 --- a/editor/ui/dialogs/content/EdDialogTemplate.xul +++ b/editor/ui/dialogs/content/EdDialogTemplate.xul @@ -19,7 +19,7 @@
- + diff --git a/editor/ui/dialogs/content/EdHLineProps.xul b/editor/ui/dialogs/content/EdHLineProps.xul index 5d36e30d13ec..62a00fc78b3c 100644 --- a/editor/ui/dialogs/content/EdHLineProps.xul +++ b/editor/ui/dialogs/content/EdHLineProps.xul @@ -23,7 +23,7 @@ - + ]> @@ -92,7 +92,7 @@
- + diff --git a/editor/ui/dialogs/content/EdImageProps.xul b/editor/ui/dialogs/content/EdImageProps.xul index c372ee1a2453..b4cc63fbfdea 100644 --- a/editor/ui/dialogs/content/EdImageProps.xul +++ b/editor/ui/dialogs/content/EdImageProps.xul @@ -37,7 +37,7 @@ - + ]> diff --git a/editor/ui/dialogs/content/EdInsertTable.xul b/editor/ui/dialogs/content/EdInsertTable.xul index 166ae1402fd2..be767b8f2ecf 100644 --- a/editor/ui/dialogs/content/EdInsertTable.xul +++ b/editor/ui/dialogs/content/EdInsertTable.xul @@ -23,7 +23,7 @@ - + ]> @@ -89,7 +89,7 @@
- + diff --git a/editor/ui/dialogs/content/EdLinkProps.js b/editor/ui/dialogs/content/EdLinkProps.js index 66fb12807f89..938c1d56cee4 100644 --- a/editor/ui/dialogs/content/EdLinkProps.js +++ b/editor/ui/dialogs/content/EdLinkProps.js @@ -4,11 +4,13 @@ var insertNew = true; var needLinkText = false; var selection; var insertLinkAroundSelection = false; +var linkTextInput; +var hrefInput; +var linkMessage; // NOTE: Use "href" instead of "a" to distinguish from Named Anchor // The returned node is has an "a" tagName var tagName = "href"; -var dialog; // dialog initialization code function Startup() @@ -16,17 +18,15 @@ function Startup() if (!InitEditorShell()) return; - // Create dialog object to store controls for easy access - dialog = new Object; - dialog.linkTextInput = document.getElementById("linkTextInput"); - dialog.hrefInput = document.getElementById("hrefInput"); + linkTextInput = document.getElementById("linkTextInput"); + hrefInput = document.getElementById("hrefInput"); - // Kinda clunky: Message was wrapped in a

, so actual message is a child text node - dialog.linkMessage = (document.getElementById("linkMessage")).firstChild; + // Message was wrapped in a

, so actual message is a child text node + linkMessage = (document.getElementById("linkMessage")).firstChild; - if (null == dialog.linkTextInput || - null == dialog.hrefInput || - null == dialog.linkMessage ) + if (null == linkTextInput || + null == hrefInput || + null == linkMessage ) { dump("Not all dialog controls were found!!!\n"); } @@ -38,17 +38,17 @@ function Startup() if (insertNew) { dump("Setting focus to linkTextInput\n"); - dialog.linkTextInput.focus(); + linkTextInput.focus(); } else { dump("Setting focus to linkTextInput\n"); - dialog.hrefInput.focus(); + hrefInput.focus(); // We will not insert a new link at caret, so remove link text input field - parentNode = dialog.linkTextInput.parentNode; + parentNode = linkTextInput.parentNode; if (parentNode) { dump("Removing link text input field.\n"); - parentNode.removeChild(dialog.linkTextInput); - dialog.linkTextInput = null; + parentNode.removeChild(linkTextInput); + linkTextInput = null; } } } @@ -83,7 +83,7 @@ function initDialog() insertNew = false; // Link source string is the source URL of image // TODO: THIS STILL DOESN'T HANDLE MULTIPLE SELECTED IMAGES! - dialog.linkMessage.data = imageElement.getAttribute("src");; + linkMessage.data = imageElement.getAttribute("src");; } } else { // We don't have an element selected, @@ -112,7 +112,7 @@ function initDialog() } else { dump("Selected text for link source not found. Non-text elements selected?\n"); } - dialog.linkMessage.data = selectedText; + linkMessage.data = selectedText; } if (!selection.isCollapsed) @@ -133,17 +133,23 @@ function chooseFile() // Get a local file, converted into URL format fileName = editorShell.GetLocalFileURL(window, "html"); if (fileName != "") { - dialog.hrefInput.value = fileName; + hrefInput.value = fileName; } // Put focus into the input field - dialog.hrefInput.focus(); + hrefInput.focus(); +} + +function RemoveLink() +{ + // Simple clear the input field! + hrefInput.value = ""; } function onOK() { // TODO: VALIDATE FIELDS BEFORE COMMITING CHANGES - href = TrimString(dialog.hrefInput.value); + href = TrimString(hrefInput.value); if (href.length > 0) { // Coalesce into one undo transaction editorShell.BeginBatchChanges(); @@ -157,10 +163,10 @@ function onOK() // Append the link text as the last child node // of the anchor node dump("Creating text node\n"); - newText = TrimString(dialog.linkTextInput.value); + newText = TrimString(linkTextInput.value); if (newText.length == 0) { ShowInputErrorMessage("You must enter some text for this link."); - dialog.linkTextInput.focus(); + linkTextInput.focus(); return; } textNode = editorShell.editorDocument.createTextNode(newText); diff --git a/editor/ui/dialogs/content/EdLinkProps.xul b/editor/ui/dialogs/content/EdLinkProps.xul index f7443572d07a..222dd676704c 100644 --- a/editor/ui/dialogs/content/EdLinkProps.xul +++ b/editor/ui/dialogs/content/EdLinkProps.xul @@ -15,7 +15,7 @@ - + @@ -25,13 +25,14 @@ - - + + + ]> @@ -49,29 +50,30 @@ -

&LinkSourceFieldset.label; - - align="horizontal"> - - - - -
+ + align="horizontal"> + + + +
&LinkURLFieldset.label; + + +
- + diff --git a/editor/ui/dialogs/content/EdMessage.js b/editor/ui/dialogs/content/EdMessage.js index 70f22396a4a0..5fee9e7f4ee4 100644 --- a/editor/ui/dialogs/content/EdMessage.js +++ b/editor/ui/dialogs/content/EdMessage.js @@ -10,15 +10,18 @@ function Startup() // Message is wrapped in a
// We will add child text node(s) - messageParent = (document.getElementById("message")); - messageText = window.arguments[1]; - if (messageText && messageText.length > 0) - { + var messageParent = (document.getElementById("message")); + var messageText = String(window.arguments[1]); + + if (StringExists(messageText)) { + var messageFragment; + // Let the caller use "\n" to cause breaks // Translate these into
tags + done = false; while (!done) { - breakIndex = messageText.search(/\n/); + breakIndex = messageText.indexOf('\n'); if (breakIndex == 0) { // Ignore break at the first character messageText = messageText.slice(1); @@ -48,77 +51,42 @@ function Startup() // We must have a message window.close(); } - titleText = window.arguments[2]; - if (titleText.length > 0) { + + titleText = String(window.arguments[2]); + if (StringExists(titleText)) { dump(titleText+" is the message dialog title\n"); window.title = titleText; } - - button1 = document.getElementById("button1"); - button2 = document.getElementById("button2"); - button3 = document.getElementById("button3"); - button4 = document.getElementById("button4"); - // All buttons must have the same parent - buttonParent = button1.parentNode; + // Set the button text from dialog arguments + // if first button doesn't have text, use "OK" + InitButton(3,"button1", true); + InitButton(4,"button2", false); + InitButton(5,"button3", false); + InitButton(6,"button4", false); +} - button1Text = window.arguments[3]; - if (button1Text && button1Text.length > 0) - { - dump(button1Text+"\n"); - button1.setAttribute("value", button1Text); - } else { - // We must have at least one button! - window.close(); +function InitButton(argIndex, buttonID, useOK) +{ + var button = document.getElementById(buttonID); + var text = String(window.arguments[argIndex]); + var exists = StringExists(text); + if (!exists && useOK) { + text = "OK"; + exists = true; } - button2Text = window.arguments[4]; - if (button2Text && button2Text.length > 0) + if (exists) { - dump(button2Text+"\n"); - button2.setAttribute("value", button2Text); + dump(text+"\n"); + button.setAttribute("value", text); } else { - buttonParent.removeChild(button2); - } - - button3Text = window.arguments[5]; - if (button3Text && button3Text.length > 0) - { - dump(button3Text+"\n"); - button3.setAttribute("value", button3Text); - } else { - buttonParent.removeChild(button3); - } - - button4Text = window.arguments[6]; - if (button4Text && button4Text.length > 0) - { - dump(button4Text+"\n"); - button4.setAttribute("value", button4Text); - } else { - buttonParent.removeChild(button4); + var buttonParent = document.getElementById(buttonID).parentNode; + buttonParent.removeChild(button); } } -function onButton1() +function onButton(buttonNumber) { - window.opener.msgResult = 1; - window.close(); -} - -function onButton2() -{ - window.opener.msgResult = 2; - window.close(); -} - -function onButton3() -{ - window.opener.msgResult = 3; - window.close(); -} - -function onButton3() -{ - window.opener.msgResult = 4; + window.opener.msgResult = buttonNumber; window.close(); } diff --git a/editor/ui/dialogs/content/EdMessage.xul b/editor/ui/dialogs/content/EdMessage.xul index 5460f2cfbbdc..c972f6a962c8 100644 --- a/editor/ui/dialogs/content/EdMessage.xul +++ b/editor/ui/dialogs/content/EdMessage.xul @@ -21,10 +21,10 @@ - - - - + + + + diff --git a/editor/ui/dialogs/content/EdNamedAnchorProps.xul b/editor/ui/dialogs/content/EdNamedAnchorProps.xul index 8768ffa903a3..8d32c2250e56 100644 --- a/editor/ui/dialogs/content/EdNamedAnchorProps.xul +++ b/editor/ui/dialogs/content/EdNamedAnchorProps.xul @@ -9,7 +9,7 @@ - + ]>