diff --git a/editor/ui/dialogs/content/EdColorPicker.js b/editor/ui/dialogs/content/EdColorPicker.js index c950e0293e7..5458edf5249 100644 --- a/editor/ui/dialogs/content/EdColorPicker.js +++ b/editor/ui/dialogs/content/EdColorPicker.js @@ -19,6 +19,7 @@ * * Contributor(s): * Daniel Glazman (glazman@netscape.com) + * Charles Manske (cmanske@netscape.com) */ @@ -69,13 +70,10 @@ function Startup() var prefs = GetPrefs(); var IsCSSPrefChecked = prefs.getBoolPref("editor.use_css"); - editorShell = window.opener.editorShell; - if (editorShell) + if (GetCurrentEditor()) { - editorShell = editorShell.QueryInterface(Components.interfaces.nsIEditorShell); - window.title = GetString(ColorType+"Color"); - if (editorShell && ColorType == "Page" && IsCSSPrefChecked && editorShell.editorType == "html") + if (ColorType == "Page" && IsCSSPrefChecked && isHTMLEditor()) window.title = GetString("BlockColor"); } } diff --git a/editor/ui/dialogs/content/EdConvertToTable.js b/editor/ui/dialogs/content/EdConvertToTable.js index c9dbc82807c..2d1d7b1cee0 100644 --- a/editor/ui/dialogs/content/EdConvertToTable.js +++ b/editor/ui/dialogs/content/EdConvertToTable.js @@ -18,6 +18,7 @@ * Rights Reserved. * * Contributor(s): + * Charles Manske (cmanske@netscape.com) */ var gIndex; @@ -28,8 +29,11 @@ var gOtherIndex = "2"; // dialog initialization code function Startup() { - if (!InitEditorShell()) + if (!GetCurrentEditor()) + { + window.close(); return; + } gDialog.sepRadioGroup = document.getElementById("SepRadioGroup"); gDialog.sepCharacterInput = document.getElementById("SepCharacterInput"); @@ -101,9 +105,18 @@ function onAccept() break; } - // 1 = OutputSelectionOnly, 1024 = OutputLFLineBreak - // 256 = OutputEncodeEntities - var str = editorShell.GetContentsAs("text/html", 1+1024); + var editor = GetCurrentEditor(); + var str; + try { + // 1 = OutputSelectionOnly, 1024 = OutputLFLineBreak + // 256 = OutputEncodeEntities + str = editor.outputToString("text/html", 1+1024); + } catch (e) {} + if (!str) + { + SaveWindowLocation(); + return true; + } // Replace nbsp with spaces: str = str.replace(/\u00a0/g, " "); @@ -257,31 +270,33 @@ function onAccept() // (Default width="100%" is used in EdInsertTable.js) str = "\n\n
" + str + "
\n"; - editorShell.BeginBatchChanges(); + editor.beginTransaction(); // Delete the selection -- makes it easier to find where table will insert - editorShell.DeleteSelection(0); - - var anchorNodeBeforeInsert = editorShell.editorSelection.anchorNode; - var offset = editorShell.editorSelection.anchorOffset; var nodeBeforeTable = null; var nodeAfterTable = null; - if (anchorNodeBeforeInsert.nodeType == Node.TEXT_NODE) - { - // Text was split. Table should be right after the first or before - nodeBeforeTable = anchorNodeBeforeInsert.previousSibling; - nodeAfterTable = anchorNodeBeforeInsert; - } - else - { - // Table should be inserted right after node pointed to by selection - if (offset > 0) - nodeBeforeTable = anchorNodeBeforeInsert.childNodes.item(offset - 1); + try { + editor.deleteSelection(0); - nodeAfterTable = anchorNodeBeforeInsert.childNodes.item(offset); - } + var anchorNodeBeforeInsert = editor.selection.anchorNode; + var offset = editor.selection.anchorOffset; + if (anchorNodeBeforeInsert.nodeType == Node.TEXT_NODE) + { + // Text was split. Table should be right after the first or before + nodeBeforeTable = anchorNodeBeforeInsert.previousSibling; + nodeAfterTable = anchorNodeBeforeInsert; + } + else + { + // Table should be inserted right after node pointed to by selection + if (offset > 0) + nodeBeforeTable = anchorNodeBeforeInsert.childNodes.item(offset - 1); + + nodeAfterTable = anchorNodeBeforeInsert.childNodes.item(offset); + } - editorShell.InsertSource(str); + editor.insertHTML(str); + } catch (e) {} var table = null; if (nodeAfterTable) @@ -301,15 +316,15 @@ function onAccept() { // Fixup table only if pref is set var prefs = GetPrefs(); + var firstRow; try { if (prefs && prefs.getBoolPref("editor.table.maintain_structure") ) - editorShell.NormalizeTable(table); - } catch(ex) { - dump(ex); - } + editor.normalizeTable(table); + + firstRow = editor.getFirstRow(table); + } catch(e) {} // Put caret in first cell - var firstRow = editorShell.GetFirstRow(table); if (firstRow) { var node2 = firstRow.firstChild; @@ -317,7 +332,9 @@ function onAccept() if (node2.nodeName.toLowerCase() == "td" || node2.nodeName.toLowerCase() == "th") { - editorShell.editorSelection.collapse(node2, 0); + try { + editor.selection.collapse(node2, 0); + } catch(e) {} break; } node2 = node.nextSibling; @@ -325,7 +342,7 @@ function onAccept() } } - editorShell.EndBatchChanges(); + editor.endTransaction(); // Save persisted attributes gDialog.sepRadioGroup.setAttribute("index", gIndex); diff --git a/editor/ui/dialogs/content/EdDialogTemplate.js b/editor/ui/dialogs/content/EdDialogTemplate.js index c78cfbcdffa..7aea29f1fcb 100644 --- a/editor/ui/dialogs/content/EdDialogTemplate.js +++ b/editor/ui/dialogs/content/EdDialogTemplate.js @@ -28,9 +28,11 @@ var tagname = "TAG NAME" // dialog initialization code function Startup() { - if (!InitEditorShell()) + if (!GetCurrentEditor()) + { + window.close(); return; - + } // gDialog is declared in EdDialogCommon.js // Set commonly-used widgets like this: gDialog.fooButton = document.getElementById("fooButton"); diff --git a/editor/ui/dialogs/content/EdImageMap.js b/editor/ui/dialogs/content/EdImageMap.js index 75fed4ea2b0..8960876b71f 100644 --- a/editor/ui/dialogs/content/EdImageMap.js +++ b/editor/ui/dialogs/content/EdImageMap.js @@ -34,9 +34,11 @@ var frameDoc = null; var buttonArray = []; function Startup(){ - if (!InitEditorShell()) + if (!GetCurrentEditor()) + { + window.close(); return; - + } initDialog(); } @@ -66,18 +68,18 @@ function initDialog(){ //check for relative url if (!((srcInput.value.indexOf("http://") != -1) || (srcInput.value.indexOf("file://") != -1))){ - if (IsUrlAboutBlank(editorShell.editorDocument.location)){ + if (IsUrlAboutBlank(GetDocumentUrl())){ alert(GetString("SaveToUseRelativeUrl")); window.close(); //TODO: add option to save document now } else{ - var edDoc = new String(editorShell.editorDocument.location); - var imgDoc = new String(srcInput.value); + var edDoc = GetDocumentUrl(); + var imgDoc = srcInput.value; imgDoc = imgDoc.split("../"); var len = imgDoc.length; for (var i=0; i (String(editorShell.editorDocument.location.protocol).length+2)) + if (edDoc.length > (String(GetCurrentEditor().document.location.protocol).length+2)) edDoc = edDoc.substring(0, edDoc.lastIndexOf("/")); } imgDoc = edDoc+"/"+imgDoc[imgDoc.length-1]; @@ -219,17 +221,23 @@ function finishMap(){ else createPoly(curSpot); } - //editorShell.editorDocument.body.appendChild(imageMap); + //try{ + // GetCurrentEditor().root.appendChild(imageMap); + //} catch (e) {} //returnValue = "test"; - //window.arguments[0] = "test"; //editorShell.editorDocument.body.appendChild(imageMap); //editorShell.InsertElementAtSelection(imageMap, false); - //dump(window.arguments[0]+"\n"); + //try{ + // window.arguments[0] = "test"; //GetCurrentEditor().insertElementAtSelection(imageMap, false); + // dump(window.arguments[0]+"\n"); + //} catch (e) {} dump("imageMap.childNodes.length = "+imageMap.childNodes.length+"\n"); } return true; } -function setMapName(){ - //imageMap = editorShell.CreateElementWithDefaults("map"); +function setMapName() { + //try { + // imageMap = GetCurrentEditor().createElementWithDefaults("map"); + //} catch (e) {} //dump(imageMap+"\n"); //imageMap = frameDoc.createElement("map"); @@ -250,7 +258,10 @@ function setMapName(){ } function createRect(which){ - //newRect = editorShell.CreateElementWithDefaults("area"); + var newRect; + //try { + // newRect = editor.createElementWithDefaults("area"); + //} catch (e) {} newRect = frameDoc.createElement("area"); newRect.setAttribute("shape", "rect"); coords = parseInt(which.style.left)+","+parseInt(which.style.top)+","+(parseInt(which.style.left)+parseInt(which.style.width))+","+(parseInt(which.style.top)+parseInt(which.style.height)); @@ -272,8 +283,11 @@ function createRect(which){ } function createCir(which){ - //newCir = editorShell.CreateElementWithDefaults("area"); - var newCir = frameDoc.createElement("area"); + var newCir; + //try { + // newCir = editor.createElementWithDefaults("area"); + //} catch (e) {} + newCir = frameDoc.createElement("area"); if ( !newCir ) return; @@ -297,8 +311,11 @@ function createCir(which){ } function createPoly(which){ - //newPoly = editorShell.CreateElementWithDefaults("area"); - var newPoly = frameDoc.createElement("area"); + var newPoly; + //try { + // newPoly = editor.createElementWithDefaults("area"); + //} catch (e) {} + newPoly = frameDoc.createElement("area"); if ( !newPoly ) return; diff --git a/editor/ui/dialogs/content/EdImageMapHotSpot.js b/editor/ui/dialogs/content/EdImageMapHotSpot.js index 32dd5fae373..63487ec9330 100644 --- a/editor/ui/dialogs/content/EdImageMapHotSpot.js +++ b/editor/ui/dialogs/content/EdImageMapHotSpot.js @@ -24,9 +24,6 @@ // dialog initialization code function Startup() { - if (!InitEditorShell()) - return; - gDialog.urlInput = document.getElementById("urlInput"); gDialog.targetInput = document.getElementById("targetInput"); gDialog.altInput = document.getElementById("altInput"); diff --git a/editor/ui/dialogs/content/EdInsSrc.js b/editor/ui/dialogs/content/EdInsSrc.js index 5398eeea39a..560c25e8ff0 100644 --- a/editor/ui/dialogs/content/EdInsSrc.js +++ b/editor/ui/dialogs/content/EdInsSrc.js @@ -20,6 +20,8 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): + * Akkana Peck (akkana@netscape.com) + * Charles Manske (cmanske@netscape.com) * * * Alternatively, the contents of this file may be used under the terms of @@ -37,13 +39,15 @@ * ***** END LICENSE BLOCK ***** */ /* Insert Source HTML dialog */ -var srcInput; -// dialog initialization code function Startup() { - if (!InitEditorShell()) + var editor = GetCurrentEditor(); + if (!editor) + { + window.close(); return; + } var okButton = document.documentElement.getButton("accept"); if (okButton) @@ -53,24 +57,34 @@ function Startup() okButton.setAttribute("accesskey",GetString("InsertAccessKey")); } // Create dialog object to store controls for easy access - srcInput = document.getElementById("srcInput"); - - var selection = editorShell.GetContentsAs("text/html", 35); - selection = (selection.replace(/]*>/,"")).replace(/<\/body>/,""); - if (selection != "") - srcInput.value = selection; + gDialog.srcInput = document.getElementById("srcInput"); + var selection; + try { + selection = editor.outputToString("text/html", 35); // OutputWrap+OutputFormatted+OutputSelectionOnly + } catch (e) {} + if (selection) + { + selection = (selection.replace(/]*>/,"")).replace(/<\/body>/,""); + if (selection) + gDialog.srcInput.value = selection; + } // Set initial focus - srcInput.focus(); + gDialog.srcInput.focus(); // Note: We can't set the caret location in a multiline textbox SetWindowLocation(); } function onAccept() { - if (srcInput.value != "") - editorShell.InsertSource(srcInput.value); - else { + if (gDialog.srcInput.value) + { + try { + GetCurrentEditor().insertHTML(gDialog.srcInput.value); + } catch (e) {} + } + else + { dump("Null value -- not inserting in HTML Source dialog\n"); return false; } diff --git a/editor/ui/dialogs/content/EdLinkChecker.js b/editor/ui/dialogs/content/EdLinkChecker.js index 880348778ad..ee46186d3b7 100644 --- a/editor/ui/dialogs/content/EdLinkChecker.js +++ b/editor/ui/dialogs/content/EdLinkChecker.js @@ -61,8 +61,25 @@ var gRequestObserver = function Startup() { - if (!InitEditorShell()) + var editor = GetCurrentEditor(); + if (!editor) + { + window.close(); return; + } + + // Get all objects that refer to other locations + var objects; + try { + objects = editor.getLinkedObjects(); + } catch (e) {} + + if (!objects || objects.count == 0) + { + AlertWithTitle(GetString("Alert"), GetString("NoLinksToCheck"); + window.close(); + return; + } gDialog.LinksList = document.getElementById("LinksList"); gDialog.Close = document.documentElement.getButton("cancel"); @@ -70,11 +87,9 @@ function Startup() // Set window location relative to parent window (based on persisted attributes) SetWindowLocation(); - // Get all objects that refer to other locations - var objects = editorShell.GetLinkedObjects(); // Loop over the nodes that have links: - for (var i = 0; i < objects.Count(); i++) + for (var i = 0; i < objects.count; i++) { var refobj = objects.GetElementAt(gNumLinksToCheck).QueryInterface(Components.interfaces.nsIURIRefObject); // Loop over the links in this node: diff --git a/editor/ui/dialogs/content/EdLinkChecker.xul b/editor/ui/dialogs/content/EdLinkChecker.xul index 1dd7ff54cec..72649b6ab41 100644 --- a/editor/ui/dialogs/content/EdLinkChecker.xul +++ b/editor/ui/dialogs/content/EdLinkChecker.xul @@ -19,6 +19,7 @@ - Rights Reserved. - - Contributor(s): + - Charles Manske (cmanske@netscape.com) --> @@ -44,16 +45,15 @@ -