diff --git a/editor/base/nsEditor.cpp b/editor/base/nsEditor.cpp index 7fe31ed10e08..11cf13af141f 100644 --- a/editor/base/nsEditor.cpp +++ b/editor/base/nsEditor.cpp @@ -4439,6 +4439,14 @@ nsresult nsEditor::EndUpdateViewBatch() return NS_OK; } +#if 0 +nsresult nsEditor::OpenDialog(const nsString &url) +{ + // Get the content window as the parent for the dialog + //nsWebShellWindow that lets you retrieve this. GetContentWebShell +} +#endif + /****************************************************************************** * nsAutoSelectionReset *****************************************************************************/ diff --git a/editor/base/nsHTMLEditor.cpp b/editor/base/nsHTMLEditor.cpp index ac64e7ac9caf..d7ad69d47263 100644 --- a/editor/base/nsHTMLEditor.cpp +++ b/editor/base/nsHTMLEditor.cpp @@ -1954,6 +1954,8 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu if (NS_SUCCEEDED(anchor->GetName(tmpText)) && tmpText.GetUnicode() && tmpText.Length() != 0) bNodeFound = PR_TRUE; } +#if 0 +// Not sure if this kind of logic should be here or in JavaScript } else if (TagName == "href") { // Check for a single image is inside a link @@ -1989,6 +1991,7 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu current = parent; } while (notDone); } +#endif } } else if (TagName == domTagName) { // All other tag names are handled here bNodeFound = PR_TRUE; @@ -2155,9 +2158,7 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection) nsCOMPtrselection; res = nsEditor::GetSelection(getter_AddRefs(selection)); if (NS_SUCCEEDED(res) && selection) - { selection->ClearSelection(); - } } PRBool isInline; @@ -2171,6 +2172,8 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection) { // The simple case of an inline node res = InsertNode(aElement, parentSelectedNode, offsetOfNewNode); + if( NS_SUCCEEDED(res)) + SetCaretAfterElement(aElement); } } return res; diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index 7fe31ed10e08..11cf13af141f 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -4439,6 +4439,14 @@ nsresult nsEditor::EndUpdateViewBatch() return NS_OK; } +#if 0 +nsresult nsEditor::OpenDialog(const nsString &url) +{ + // Get the content window as the parent for the dialog + //nsWebShellWindow that lets you retrieve this. GetContentWebShell +} +#endif + /****************************************************************************** * nsAutoSelectionReset *****************************************************************************/ diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index ac64e7ac9caf..d7ad69d47263 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -1954,6 +1954,8 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu if (NS_SUCCEEDED(anchor->GetName(tmpText)) && tmpText.GetUnicode() && tmpText.Length() != 0) bNodeFound = PR_TRUE; } +#if 0 +// Not sure if this kind of logic should be here or in JavaScript } else if (TagName == "href") { // Check for a single image is inside a link @@ -1989,6 +1991,7 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu current = parent; } while (notDone); } +#endif } } else if (TagName == domTagName) { // All other tag names are handled here bNodeFound = PR_TRUE; @@ -2155,9 +2158,7 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection) nsCOMPtrselection; res = nsEditor::GetSelection(getter_AddRefs(selection)); if (NS_SUCCEEDED(res) && selection) - { selection->ClearSelection(); - } } PRBool isInline; @@ -2171,6 +2172,8 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection) { // The simple case of an inline node res = InsertNode(aElement, parentSelectedNode, offsetOfNewNode); + if( NS_SUCCEEDED(res)) + SetCaretAfterElement(aElement); } } return res; diff --git a/editor/ui/composer/content/EditorAppShell.xul b/editor/ui/composer/content/EditorAppShell.xul index 00eeeaeed52b..27be85149a6e 100644 --- a/editor/ui/composer/content/EditorAppShell.xul +++ b/editor/ui/composer/content/EditorAppShell.xul @@ -469,13 +469,13 @@ - - + + - + diff --git a/editor/ui/composer/content/EditorCommands.js b/editor/ui/composer/content/EditorCommands.js index 4fc493b649c1..70e0db16a632 100644 --- a/editor/ui/composer/content/EditorCommands.js +++ b/editor/ui/composer/content/EditorCommands.js @@ -54,12 +54,9 @@ function EditorStartup(editorType) SetupToolbarElements(); // Set focus to the edit window - // (A bug currently prevents this from working, - // the actual edit window is a child of the webshell window - // designated as the contentWindow) - dump("Setting focus to content window\n"); + // This still doesn't work! + // It works after using a toolbar button, however! contentWindow.focus(); - window.frames[0].focus(); } function SetupToolbarElements() diff --git a/editor/ui/dialogs/content/EdCharacterProps.js b/editor/ui/dialogs/content/EdCharacterProps.js deleted file mode 100644 index 570864695f78..000000000000 --- a/editor/ui/dialogs/content/EdCharacterProps.js +++ /dev/null @@ -1,39 +0,0 @@ -// 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 Startup() -{ - dump("Doing Character Props 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"); - } - - // 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(editorName); - if(!appCore || !toolkitCore) { - dump("EditorAppCore not found!!!\n"); - toolkitCore.CloseWindow(window); - } -} - -function applyChanges() -{ -} diff --git a/editor/ui/dialogs/content/EdCharacterProps.xul b/editor/ui/dialogs/content/EdCharacterProps.xul deleted file mode 100644 index 346a843bfb6c..000000000000 --- a/editor/ui/dialogs/content/EdCharacterProps.xul +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - diff --git a/editor/ui/dialogs/content/EdDialogCommon.js b/editor/ui/dialogs/content/EdDialogCommon.js index 1ea00d08daaa..511a566563a4 100644 --- a/editor/ui/dialogs/content/EdDialogCommon.js +++ b/editor/ui/dialogs/content/EdDialogCommon.js @@ -38,6 +38,128 @@ function ValidateNumberString(value, minValue, maxValue) return ""; } + +function TrimStringLeft(string) +{ + firstCharIndex = 0; + len = string.length; + var result; + + while (firstCharIndex < len) { + if (!IsWhitespace(string.charAt(firstCharIndex))) break; + firstCharIndex = firstCharIndex + 1; + } + if (firstCharIndex > len) { + string = ""; + } else { + string = string.slice(firstCharIndex); + } + return string; +} + +function TrimStringRight(string) +{ + len = string.length; + if (len > 0 ) { + lastCharIndex = string.length-1; + var result; + + while (lastCharIndex > 0) { + // Find the last non-whitespace char + if (!IsWhitespace(string.charAt(lastCharIndex))) break; + lastCharIndex = lastCharIndex - 1; + } + if (lastCharIndex == 0) { + string = ""; + } else { + string = string.slice(0, lastCharIndex+1); + } + } + return string; +} + +// Remove whitespace from both ends of a string +function TrimString(string) +{ + return TrimStringRight(TrimStringLeft(string)); +} + +function IsWhitespace(character) +{ + result = character.match(/\s/); + if (result == null) + return false; + return true; +} + +function TruncateStringAtWordEnd(string, maxLength, addEllipses) +{ + // We assume they probably don't want whitespace at the beginning + string = TrimStringLeft(string); + + len = string.length; + if (len > maxLength) { + // We need to truncate the string + var max; + if (addEllipses) { + // Make room for ellipses + max = maxLength - 3; + } else { + max = maxLength; + } + var lastCharIndex = 0; + + // Start search just past max if there's enough characters + if (len >= (max+1)) { + lastCharIndex = max; + } else { + lastCharIndex = len-1; + } + dump("Len="+len+" lastCharIndex="+lastCharIndex+" max="+max+"\n"); + + // Find the last whitespace char from the end + dump("Skip to first whitspace from end: "); + + while (lastCharIndex > 0) { + lastChar = string.charAt(lastCharIndex); + dump(lastChar); + if (IsWhitespace(lastChar)) break; + lastCharIndex = lastCharIndex -1; + } + dump("[space found]\nlastCharIndex="+lastCharIndex+"\nSkip over whitespace:"); + + while (lastCharIndex > 0) { + // Find the last non-whitespace char + lastChar = string.charAt(lastCharIndex); + dump(lastChar); + if (!IsWhitespace(lastChar)) break; + lastCharIndex = lastCharIndex -1; + } + dump("[non-space found]\nlastCharIndex="+lastCharIndex+"\n"); + + string = string.slice(0, lastCharIndex+1); + if (addEllipses) { + string = string+"..."; + dump(string+"\n"); + } + } + return string; +} + +// Replace all whitespace characters with supplied character +// E.g.: Use charReplace = " ", to "unwrap" the string by removing line-end chars +// Use charReplace = "_" when you don't want spaces (like in a URL) +function ReplaceWhitespace(string, charReplace) { + if (string.length > 0 ) + { + string = TrimString(string); + // This replaces a run of whitespace with just one character + string = string.replace(/\s+/g, charReplace); + } + dump(string+"\n"); + return string; +} + // this function takes an elementID and a flag // if the element can be found by ID, then it is either enabled (by removing "disabled" attr) // or disabled (setAttribute) as specified in the "doEnable" parameter diff --git a/editor/ui/dialogs/content/EdDialogTemplate.xul b/editor/ui/dialogs/content/EdDialogTemplate.xul index 091a894f4f00..ac208c412d94 100644 --- a/editor/ui/dialogs/content/EdDialogTemplate.xul +++ b/editor/ui/dialogs/content/EdDialogTemplate.xul @@ -3,10 +3,12 @@ - + + onload = "Startup()" + align="vertical" flex="100%"> - +
- - - -
- - -
+ + + + + + + +
diff --git a/editor/ui/dialogs/content/EdHLineProps.js b/editor/ui/dialogs/content/EdHLineProps.js index 2d204ea5e60a..d0cb86732b7e 100644 --- a/editor/ui/dialogs/content/EdHLineProps.js +++ b/editor/ui/dialogs/content/EdHLineProps.js @@ -125,7 +125,7 @@ function ValidateData(setAttributes) if (setAttributes) { hLineElement.setAttribute("size", height); } else { - hLineElement.setAttribute("size", height); + tempLineElement.setAttribute("size", height); } var maxLimit; diff --git a/editor/ui/dialogs/content/EdHLineProps.xul b/editor/ui/dialogs/content/EdHLineProps.xul index b3e541942b4d..cbb7adf04f64 100644 --- a/editor/ui/dialogs/content/EdHLineProps.xul +++ b/editor/ui/dialogs/content/EdHLineProps.xul @@ -3,17 +3,20 @@ - + onload = "Startup()" + width="250" height="275" + align="vertical" flex="100%"> - +
+
Dimensions @@ -34,7 +37,7 @@
- +
@@ -55,7 +58,7 @@ - + @@ -71,6 +74,7 @@ + diff --git a/editor/ui/dialogs/content/EdImageProps.xul b/editor/ui/dialogs/content/EdImageProps.xul index 39e3d6bbdc25..31b9e62d193e 100644 --- a/editor/ui/dialogs/content/EdImageProps.xul +++ b/editor/ui/dialogs/content/EdImageProps.xul @@ -4,10 +4,12 @@ - + onload = "Startup()" + width="420" height="375" + align="vertical" flex="100%"> - +
- - -
@@ -166,13 +168,14 @@
- - - -
+ + + + + + + +
diff --git a/editor/ui/dialogs/content/EdInsSrc.xul b/editor/ui/dialogs/content/EdInsSrc.xul index e4ece75251c9..fede77e43cf5 100644 --- a/editor/ui/dialogs/content/EdInsSrc.xul +++ b/editor/ui/dialogs/content/EdInsSrc.xul @@ -6,7 +6,7 @@ + onload = "Startup()" align="vertical" flex="100%"> - +
0) { + // Use just the first 50 characters and add "..." + selectedText = TruncateStringAtWordEnd(selectedText, 50, true); + } else { + dump("Selected text for link source not found. Non-text elements selected?\n"); + } + dialog.linkMessage.data = selectedText; } if (!selection.isCollapsed) diff --git a/editor/ui/dialogs/content/EdLinkProps.xul b/editor/ui/dialogs/content/EdLinkProps.xul index 5f5af31a200e..9db8919d5e3a 100644 --- a/editor/ui/dialogs/content/EdLinkProps.xul +++ b/editor/ui/dialogs/content/EdLinkProps.xul @@ -3,10 +3,11 @@ - + onload = "Startup()" + align="vertical" flex="100%"> - +
@@ -41,4 +42,5 @@
+
diff --git a/editor/ui/dialogs/content/EdNamedAnchorProps.js b/editor/ui/dialogs/content/EdNamedAnchorProps.js index 3c11ccf46f00..6d5677d0922b 100644 --- a/editor/ui/dialogs/content/EdNamedAnchorProps.js +++ b/editor/ui/dialogs/content/EdNamedAnchorProps.js @@ -2,7 +2,8 @@ var editorShell; var insertNew = true; var inserted = false; -var tagname = "TAG NAME" +var tagName = "anchor" +var anchorElement = null; // dialog initialization code function Startup() @@ -20,58 +21,66 @@ function Startup() // Create dialog object to store controls for easy access dialog = new Object; // GET EACH CONTROL -- E.G.: - //dialog.editBox = document.getElementById("editBox"); + dialog.nameInput = document.getElementById("name"); - initDialog(); - - // SET FOCUS TO FIRST CONTROL - //dialog.editBox.focus(); -} - -function initDialog() { // Get a single selected element of the desired type - element = editorShell.GetSelectedElement(tagName); + anchorElement = editorShell.GetSelectedElement(tagName); - if (element) { + if (anchorElement) { // We found an element and don't need to insert one insertNew = false; - dump("Found existing image\n"); + dump("Found existing anchor\n"); + dialog.nameInput.value = anchorElement.getAttribute("name"); } else { insertNew = true; // We don't have an element selected, // so create one with default attributes dump("Element not selected - calling createElementWithDefaults\n"); - element = appCore.createElementWithDefaults(tagName); + anchorElement = editorShell.CreateElementWithDefaults(tagName); + // Use the current selection as suggested name + name = editorShell.selectionAsText; + // Get 40 characters of the selected text and don't add "..." + name = TruncateStringAtWordEnd(name, 40, false); + // Replace whitespace with "_" + name = ReplaceWhitespace(name, "_"); + dialog.nameInput.value = name; } - if(!element) + if(!anchorElement) { dump("Failed to get selected element or create a new one!\n"); window.close(); } -} -function CreatePixelOrPercentMenu() -{ - dump("Creating PixelOrPercent popup menu\n"); + + dialog.nameInput.focus(); } function onOK() { -// Set attribute example: -// imageElement.setAttribute("src",dialog.srcInput.value); - if (insertNew) { - editorShell.InsertElement(element, true); - // Select the newly-inserted image - editorShell.SelectElement(element); - // Mark that we inserted so we can collapse the selection - // when dialog closes - inserted = true; - } + name = dialog.nameInput.value; + name = TrimString(name); + if (name.length == 0) { + dump("EMPTY ANCHOR STRING\n"); + //TODO: POPUP ERROR DIALOG HERE + } else { + // Replace spaces with "_" else it causes trouble in URL parsing + name = ReplaceWhitespace(name, "_"); + imageElement.setAttribute("name",name); + if (insertNew) { + // Don't delete selected text when inserting + editorShell.InsertElement(element, false); + // Select the newly-inserted image + editorShell.SelectElement(element); + // Mark that we inserted so we can collapse the selection + // when dialog closes + inserted = true; + } - if (inserted) { - // We selected the object, undo it by - // setting caret to just after the inserted element - editorShell.SetSelectionAfterElement(imageElement); + if (inserted) { + // We selected the object, undo it by + // setting caret to just after the inserted element + editorShell.SetSelectionAfterElement(imageElement); + } + window.close(); } - window.close(); } diff --git a/editor/ui/dialogs/content/EdNamedAnchorProps.xul b/editor/ui/dialogs/content/EdNamedAnchorProps.xul index 5dd431a713c6..c95e6206a16f 100644 --- a/editor/ui/dialogs/content/EdNamedAnchorProps.xul +++ b/editor/ui/dialogs/content/EdNamedAnchorProps.xul @@ -2,11 +2,12 @@ - - + onload = "Startup()" + width="260" height="140" + align="vertical" flex="100%"> - +
- - - -
- Enter a name for this target:
+
+ Enter a name for this target: +
-
- - - - - - -
+ + +
+ + + + + + + + + + +
diff --git a/editor/ui/dialogs/content/EdSpellCheck.xul b/editor/ui/dialogs/content/EdSpellCheck.xul index 6e15c08dc3cc..a25467013c33 100644 --- a/editor/ui/dialogs/content/EdSpellCheck.xul +++ b/editor/ui/dialogs/content/EdSpellCheck.xul @@ -3,10 +3,12 @@ - + onload = "Startup()" + width="380" height="265" + align="vertical" flex="100%"> @@ -14,7 +16,7 @@ - +
@@ -94,4 +96,5 @@
+
diff --git a/editor/ui/dialogs/skin/EditorDialog.css b/editor/ui/dialogs/skin/EditorDialog.css index 8b26bd57c3b0..493159079cce 100644 --- a/editor/ui/dialogs/skin/EditorDialog.css +++ b/editor/ui/dialogs/skin/EditorDialog.css @@ -1,13 +1,4 @@ /* XUL ELEMENTS */ -window, WINDOW { - display: block; - width: 100%; - background: silver; - background-color: #CCCCCC; /* not working on Macintosh */ - padding: 5px; - font-family: Sans-Serif; - font-size: 8pt; -} /* values = margin, padding. Padding doesn't work yet */ checkbox { margin: 5px 3px }