diff --git a/mozilla/editor/ui/dialogs/content/EdAECSSAttributes.js b/mozilla/editor/ui/dialogs/content/EdAECSSAttributes.js index c74e80c484d..9ad2ebb0781 100644 --- a/mozilla/editor/ui/dialogs/content/EdAECSSAttributes.js +++ b/mozilla/editor/ui/dialogs/content/EdAECSSAttributes.js @@ -20,6 +20,8 @@ * Contributor(s): * Ben "Count XULula" Goodger * Daniel Glazman + * Charles Manske (cmanske@netscape.com) + * Neil Rashbrook */ // build attribute list in tree form from element attributes @@ -28,8 +30,11 @@ function BuildCSSAttributeTable() // we can't trust DOM 2 ElementCSSInlineStyle because gElement can be // outside of the document's tree var styleAttr = gElement.getAttribute("style"); - var editor = editorShell.editor.QueryInterface(Components.interfaces.nsIHTMLEditor); - var styleRule = editor.parseStyleAttrIntoCSSRule(styleAttr); + var styleRule; + try { + var editor = GetCurrentEditor(); + styleRule = editor.parseStyleAttrIntoCSSRule(styleAttr); + } catch(ex) {} if (styleRule == undefined) { diff --git a/mozilla/editor/ui/dialogs/content/EdAEJSEAttributes.js b/mozilla/editor/ui/dialogs/content/EdAEJSEAttributes.js index 02c8d743e19..0691736cf4a 100644 --- a/mozilla/editor/ui/dialogs/content/EdAEJSEAttributes.js +++ b/mozilla/editor/ui/dialogs/content/EdAEJSEAttributes.js @@ -48,7 +48,7 @@ function BuildJSEAttributeNameList() } for (i = 0; i < attNames.length; i++) - AppendStringToMenulist(gDialog.AddJSEAttributeNameList, attNames[i]); + gDialog.AddJSEAttributeNameList.appendItem(attNames[i], attNames[i]); popup = gDialog.AddJSEAttributeNameList.firstChild; if (popup) @@ -74,7 +74,7 @@ function BuildJSEAttributeNameList() popup.appendChild(sep); } else - AppendStringToMenulist(gDialog.AddJSEAttributeNameList, gCoreJSEvents[i]); + gDialog.AddJSEAttributeNameList.appendItem(gCoreJSEvents[i], gCoreJSEvents[i]); } gDialog.AddJSEAttributeNameList.selectedIndex = 0; @@ -133,20 +133,13 @@ function onSelectJSETreeItem() var tree = gDialog.AddJSEAttributeTree; if (tree && tree.treeBoxObject.selection.count) { - var name = GetTreeItemAttributeStr(getSelectedItem(tree)); - // Select attribute name in list - if (gDialog.AddJSEAttributeNameList.firstChild) - { - var arr = gDialog.AddJSEAttributeNameList.firstChild.getElementsByAttribute('label', name); - if (arr && arr.length) - gDialog.AddJSEAttributeNameList.selectedItem = arr[0]; + gDialog.AddJSEAttributeNameList.value = GetTreeItemAttributeStr(getSelectedItem(tree)); - // Set value input to that in tree (no need to update this in the tree) - gUpdateTreeValue = false; - gDialog.AddJSEAttributeValueInput.value = GetTreeItemValueStr(getSelectedItem(tree)); - gUpdateTreeValue = true; - } + // Set value input to that in tree (no need to update this in the tree) + gUpdateTreeValue = false; + gDialog.AddJSEAttributeValueInput.value = GetTreeItemValueStr(getSelectedItem(tree)); + gUpdateTreeValue = true; } } diff --git a/mozilla/editor/ui/dialogs/content/EdAdvancedEdit.js b/mozilla/editor/ui/dialogs/content/EdAdvancedEdit.js index 51b41cfb636..0a1f14a173e 100644 --- a/mozilla/editor/ui/dialogs/content/EdAdvancedEdit.js +++ b/mozilla/editor/ui/dialogs/content/EdAdvancedEdit.js @@ -18,7 +18,9 @@ * Rights Reserved. * * Contributor(s): - * Ben "Count XULula" Goodger + * Ben "Count XULula" Goodger + * Charles Manske (cmanske@netscape.com) + * Neil Rashbrook (neil@parkwaycc.co.uk) */ /************** GLOBALS **************/ @@ -47,20 +49,19 @@ var gUpdateTreeValue = true; **/ function Startup() { + var editor = GetCurrentEditor(); + + // Element to edit is passed in + if (!editor || !window.arguments[1]) + { + dump("Advanced Edit: No editor or element to edit not supplied\n"); + window.close(); + return; + } // This is the return value for the parent, // who only needs to know if OK was clicked window.opener.AdvancedEditOK = false; - if (!InitEditorShell()) - return; - - // Element to edit is passed in - if (!window.arguments[1]) - { - dump("Advanced Edit: Element to edit not supplied\n"); - window.close(); - return; - } // The actual element edited (not a copy!) gElement = window.arguments[1]; @@ -106,14 +107,15 @@ function Startup() } /** - * function : bool onOK ( void ); + * function : bool onAccept ( void ); * parameters : none * returns : boolean true to close the window * desc. : event handler for ok button **/ function onAccept() { - editorShell.BeginBatchChanges(); + var editor = GetCurrentEditor(); + editor.beginTransaction(); try { // Update our gElement attributes UpdateHTMLAttributes(); @@ -122,7 +124,7 @@ function onAccept() } catch(ex) { dump(ex); } - editorShell.EndBatchChanges(); + editor.endTransaction(); window.opener.AdvancedEditOK = true; SaveWindowLocation(); @@ -135,18 +137,24 @@ function onAccept() // (Temporary element from a property dialog won't have a parent node) function doRemoveAttribute(attrib) { - if (gElement.parentNode) - editorShell.RemoveAttribute(gElement, attrib); - else - gElement.removeAttribute(attrib); + try { + var editor = GetCurrentEditor(); + if (gElement.parentNode) + editor.removeAttribute(gElement, attrib); + else + gElement.removeAttribute(attrib); + } catch(ex) {} } function doSetAttribute(attrib, value) { - if (gElement.parentNode) - editorShell.SetAttribute(gElement, attrib, value); - else - gElement.setAttribute(attrib, value); + try { + var editor = GetCurrentEditor(); + if (gElement.parentNode) + editor.setAttribute(gElement, attrib, value); + else + gElement.setAttribute(attrib, value); + } catch(ex) {} } /** diff --git a/mozilla/editor/ui/dialogs/content/EdAdvancedEdit.xul b/mozilla/editor/ui/dialogs/content/EdAdvancedEdit.xul index 78625477ed4..ef555ee811c 100644 --- a/mozilla/editor/ui/dialogs/content/EdAdvancedEdit.xul +++ b/mozilla/editor/ui/dialogs/content/EdAdvancedEdit.xul @@ -74,7 +74,7 @@ - - - - - + oncommand="onSelectJSEAttribute();"> + + - diff --git a/mozilla/editor/ui/dialogs/content/EdButtonProps.js b/mozilla/editor/ui/dialogs/content/EdButtonProps.js index 2749dbc751b..630cc716043 100644 --- a/mozilla/editor/ui/dialogs/content/EdButtonProps.js +++ b/mozilla/editor/ui/dialogs/content/EdButtonProps.js @@ -41,8 +41,12 @@ var buttonElement; function Startup() { - if (!InitEditorShell()) + var editor = GetCurrentEditor(); + if (!editor) + { + window.close(); return; + } gDialog = { buttonType: document.getElementById("ButtonType"), @@ -58,7 +62,7 @@ function Startup() // Get a single selected button element var tagName = "button"; - buttonElement = editorShell.GetSelectedElement(tagName); + buttonElement = editor.getSelectedElement(tagName); if (buttonElement) // We found an element and don't need to insert one @@ -70,7 +74,7 @@ function Startup() // We don't have an element selected, // so create one with default attributes - buttonElement = editorShell.CreateElementWithDefaults(tagName); + buttonElement = editor.createElementWithDefaults(tagName); if (!buttonElement) { dump("Failed to get selected element or create a new one!\n"); @@ -78,7 +82,7 @@ function Startup() return; } // Hide button removing existing button - gDialog.RemoveButton.setAttribute("hidden", "true"); + gDialog.RemoveButton.hidden = true; } // Make a copy to use for AdvancedEdit @@ -150,12 +154,14 @@ function onAccept() // element created to insert ValidateData(); - editorShell.CloneAttributes(buttonElement, globalElement); + var editor = GetCurrentEditor(); + + editor.cloneAttributes(buttonElement, globalElement); if (insertNew && !InsertElementAroundSelection(buttonElement)) { - buttonElement.innerHTML = editorShell.GetContentsAs("text/html", 1); // OutputSelectionOnly (see nsIDocumentEncoder.h) - editorShell.InsertElementAtSelection(buttonElement, true); + buttonElement.innerHTML = editor.outputToString("text/html", 1); // OutputSelectionOnly (see nsIDocumentEncoder.h) + editor.insertElementAtSelection(buttonElement, true); } SaveWindowLocation(); diff --git a/mozilla/editor/ui/dialogs/content/EdColorProps.js b/mozilla/editor/ui/dialogs/content/EdColorProps.js index 283857f3aa4..1e86c923961 100644 --- a/mozilla/editor/ui/dialogs/content/EdColorProps.js +++ b/mozilla/editor/ui/dialogs/content/EdColorProps.js @@ -32,7 +32,7 @@ //Cancel() is in EdDialogCommon.js -var BodyElement; +var gBodyElement; var prefs; var gBackgroundImage; @@ -67,8 +67,12 @@ var gHaveDocumentUrl = false; // dialog initialization code function Startup() { - if (!InitEditorShell()) + var editor = GetCurrentEditor(); + if (!editor) + { + window.close(); return; + } gDialog.ColorPreview = document.getElementById("ColorPreview"); gDialog.NormalText = document.getElementById("NormalText"); @@ -80,15 +84,18 @@ function Startup() gDialog.CustomColorsRadio = document.getElementById("CustomColorsRadio"); gDialog.BackgroundImageInput = document.getElementById("BackgroundImageInput"); - BodyElement = editorShell.editorDocument.body; - if (!BodyElement) + try { + gBodyElement = editor.rootElement; + } catch (e) {} + + if (!gBodyElement) { dump("Failed to get BODY element!\n"); window.close(); } // Set element we will edit - globalElement = BodyElement.cloneNode(false); + globalElement = gBodyElement.cloneNode(false); // Initialize default colors from browser prefs var browserColors = GetDefaultBrowserColors(); @@ -365,47 +372,50 @@ function ValidateAndPreviewImage(ShowErrorMessage) function ValidateData() { - // Colors values are updated as they are picked, no validation necessary - if (gDialog.DefaultColorsRadio.selected) - { - gEditor.removeAttributeOrEquivalent(globalElement, textStr, true); - globalElement.removeAttribute(linkStr); - globalElement.removeAttribute(vlinkStr); - globalElement.removeAttribute(alinkStr); - gEditor.removeAttributeOrEquivalent(globalElement, bgcolorStr, true); - } - else - { - //Do NOT accept the CSS "WindowsOS" color strings! - // Problem: We really should try to get the actual color values - // from windows, but I don't know how to do that! - var tmpColor = customTextColor.toLowerCase(); - if (tmpColor != "windowtext") - globalElement.setAttribute(textStr, customTextColor); + var editor = GetCurrentEditor(); + try { + // Colors values are updated as they are picked, no validation necessary + if (gDialog.DefaultColorsRadio.selected) + { + editor.removeAttributeOrEquivalent(globalElement, textStr, true); + globalElement.removeAttribute(linkStr); + globalElement.removeAttribute(vlinkStr); + globalElement.removeAttribute(alinkStr); + editor.removeAttributeOrEquivalent(globalElement, bgcolorStr, true); + } else - gEditor.removeAttributeOrEquivalent(globalElement, textStr, true); + { + //Do NOT accept the CSS "WindowsOS" color strings! + // Problem: We really should try to get the actual color values + // from windows, but I don't know how to do that! + var tmpColor = customTextColor.toLowerCase(); + if (tmpColor != "windowtext") + globalElement.setAttribute(textStr, customTextColor); + else + editor.removeAttributeOrEquivalent(globalElement, textStr, true); - tmpColor = customBackgroundColor.toLowerCase(); - if (tmpColor != "window") - globalElement.setAttribute(bgcolorStr, customBackgroundColor); - else - gEditor.removeAttributeOrEquivalent(globalElement, bgcolorStr, true); + tmpColor = customBackgroundColor.toLowerCase(); + if (tmpColor != "window") + globalElement.setAttribute(bgcolorStr, customBackgroundColor); + else + editor.removeAttributeOrEquivalent(globalElement, bgcolorStr, true); - globalElement.setAttribute(linkStr, customLinkColor); - globalElement.setAttribute(vlinkStr, customVisitedColor); - globalElement.setAttribute(alinkStr, customActiveColor); - } + globalElement.setAttribute(linkStr, customLinkColor); + globalElement.setAttribute(vlinkStr, customVisitedColor); + globalElement.setAttribute(alinkStr, customActiveColor); + } - if (ValidateAndPreviewImage(true)) - { - // A valid image may be null for no image - if (gBackgroundImage) - globalElement.setAttribute(backgroundStr, gBackgroundImage); - else - gEditor.removeAttributeOrEquivalent(globalElement, backgroundStr, true); + if (ValidateAndPreviewImage(true)) + { + // A valid image may be null for no image + if (gBackgroundImage) + globalElement.setAttribute(backgroundStr, gBackgroundImage); + else + editor.removeAttributeOrEquivalent(globalElement, backgroundStr, true); - return true; - } + return true; + } + } catch (e) {} return false; } @@ -414,7 +424,9 @@ function onAccept() if (ValidateData()) { // Copy attributes to element we are changing - editorShell.CloneAttributes(BodyElement, globalElement); + try { + GetCurrentEditor().cloneAttributes(gBodyElement, globalElement); + } catch (e) {} SaveWindowLocation(); return true; // do close the window diff --git a/mozilla/editor/ui/dialogs/content/EdDialogCommon.js b/mozilla/editor/ui/dialogs/content/EdDialogCommon.js index 04cb719f4a1..9c0f8db15b8 100644 --- a/mozilla/editor/ui/dialogs/content/EdDialogCommon.js +++ b/mozilla/editor/ui/dialogs/content/EdDialogCommon.js @@ -20,12 +20,13 @@ * Contributor(s): * Pete Collins * Brian King + * Charles Manske (cmanske@netscape.com) + * Neil Rashbrook (neil@parkwaycc.co.uk) */ // Each editor window must include this file // Variables shared by all dialogs: var editorShell; -var gEditor; // Object to attach commonly-used widgets (all dialogs should use this) var gDialog = {}; @@ -53,6 +54,10 @@ var gLocation; // The element being edited - so AdvancedEdit can have access to it var globalElement; +//XXX THIS METHOD IS GOING AWAY SOON! +// We are removing all editorShell calls +// Use GetCurrentEditor() to get the nsIEditor/nsIHTMLEditor interface +// Do not modify it or rely on it in any way! function InitEditorShell() { // get the editor shell from the parent window @@ -70,7 +75,6 @@ function InitEditorShell() // Save as a property of the window so it can be used by child dialogs window.editorShell = editorShell; - gEditor = editorShell.editor.QueryInterface(Components.interfaces.nsIHTMLEditor); return true; } @@ -639,7 +643,7 @@ function SetMetaElementContent(metaElement, content, insertNew) if(!content || content == "") { if (!insertNew) - editor.deleteElement(metaElement); + editor.deleteNode(metaElement); } else { @@ -1074,7 +1078,7 @@ function FillLinkMenulist(linkMenulist, headingsArray) linkMenulist.appendItem(text); // Save nodes in an array so we can create anchor node under it later - headingsArray[NamedAnchorCount++] = heading; + headingsArray[text] = heading; } } } diff --git a/mozilla/editor/ui/dialogs/content/EdDialogOverlay.xul b/mozilla/editor/ui/dialogs/content/EdDialogOverlay.xul index 5aee3b762ad..68adf883f63 100644 --- a/mozilla/editor/ui/dialogs/content/EdDialogOverlay.xul +++ b/mozilla/editor/ui/dialogs/content/EdDialogOverlay.xul @@ -82,7 +82,7 @@ oncommand="MakeInputValueRelativeOrAbsolute(this);" tooltiptext="&makeUrlRelative.tooltip;"/> -