From 335fb3a1bbf640538896c462ada1fe7a5b3cccb6 Mon Sep 17 00:00:00 2001 From: "cmanske%netscape.com" Date: Tue, 12 Nov 2002 22:44:04 +0000 Subject: [PATCH] Remove editorShell from editor dialogs. b=158881, r=brade, sr=alecf git-svn-id: svn://10.0.0.236/trunk@133697 18797224-902f-48f8-a5cc-f745e15eee43 --- .../ui/dialogs/content/EdColorPicker.js | 2 +- .../ui/dialogs/content/EdDialogCommon.js | 26 ----------- .../editor/ui/dialogs/content/EdDictionary.js | 11 +++-- .../ui/dialogs/content/EdInsertTable.js | 4 +- .../ui/dialogs/content/EdLinkChecker.js | 6 +-- .../editor/ui/dialogs/content/EdReplace.js | 14 +++--- .../editor/ui/dialogs/content/EdSpellCheck.js | 46 +++++++++++-------- .../editor/ui/dialogs/content/EdTableProps.js | 2 +- .../editor/ui/dialogs/content/EditConflict.js | 3 +- 9 files changed, 50 insertions(+), 64 deletions(-) diff --git a/mozilla/editor/ui/dialogs/content/EdColorPicker.js b/mozilla/editor/ui/dialogs/content/EdColorPicker.js index 5458edf5249..a51c66ab40f 100644 --- a/mozilla/editor/ui/dialogs/content/EdColorPicker.js +++ b/mozilla/editor/ui/dialogs/content/EdColorPicker.js @@ -73,7 +73,7 @@ function Startup() if (GetCurrentEditor()) { window.title = GetString(ColorType+"Color"); - if (ColorType == "Page" && IsCSSPrefChecked && isHTMLEditor()) + if (ColorType == "Page" && IsCSSPrefChecked && IsHTMLEditor()) window.title = GetString("BlockColor"); } } diff --git a/mozilla/editor/ui/dialogs/content/EdDialogCommon.js b/mozilla/editor/ui/dialogs/content/EdDialogCommon.js index 1eac504547e..ecd09f950ed 100644 --- a/mozilla/editor/ui/dialogs/content/EdDialogCommon.js +++ b/mozilla/editor/ui/dialogs/content/EdDialogCommon.js @@ -25,8 +25,6 @@ */ // Each editor window must include this file -// Variables shared by all dialogs: -var editorShell; // Object to attach commonly-used widgets (all dialogs should use this) var gDialog = {}; @@ -54,30 +52,6 @@ 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 - - editorShell = window.opener.editorShell; - if (editorShell) { - editorShell = editorShell.QueryInterface(Components.interfaces.nsIEditorShell); - } - if (!editorShell) { - dump("EditorShell not found!!!\n"); - window.close(); - return false; - } - - // Save as a property of the window so it can be used by child dialogs - - window.editorShell = editorShell; - return true; -} - /* Validate contents of an input field * * inputWidget The 'textbox' XUL element for text input of the attribute's value diff --git a/mozilla/editor/ui/dialogs/content/EdDictionary.js b/mozilla/editor/ui/dialogs/content/EdDictionary.js index d3457400d4e..68fcbdf8c9b 100644 --- a/mozilla/editor/ui/dialogs/content/EdDictionary.js +++ b/mozilla/editor/ui/dialogs/content/EdDictionary.js @@ -26,12 +26,15 @@ var gWordToAdd; function Startup() { - if (!InitEditorShell()) + if (!GetCurrentEditor()) + { + window.close(); return; - dump("EditoreditorShell found for dialog\n"); - + } // Get the SpellChecker shell - gSpellChecker = editorShell.QueryInterface(Components.interfaces.nsIEditorSpellCheck); + if ("gSpellChecker" in window.opener && window.opener.gSpellChecker) + gSpellChecker = window.opener.gSpellChecker; + if (!gSpellChecker) { dump("SpellChecker not found!!!\n"); diff --git a/mozilla/editor/ui/dialogs/content/EdInsertTable.js b/mozilla/editor/ui/dialogs/content/EdInsertTable.js index 471df03fce3..e8ddb0e4924 100644 --- a/mozilla/editor/ui/dialogs/content/EdInsertTable.js +++ b/mozilla/editor/ui/dialogs/content/EdInsertTable.js @@ -29,7 +29,7 @@ var gActiveEditor; // dialog initialization code function Startup() { - gActiveEditor = GetCurrentEditor(); + gActiveEditor = GetCurrentTableEditor(); if (!gActiveEditor) { dump("Failed to get active editor!\n"); @@ -57,7 +57,7 @@ function Startup() // Make a copy to use for AdvancedEdit globalElement = gTableElement.cloneNode(false); try { - if (GetPrefs().getBoolPref("editor.use_css") && isHTMLEditor() + if (GetPrefs().getBoolPref("editor.use_css") && IsHTMLEditor() && !(gActiveEditor.flags & Components.interfaces.nsIPlaintextEditor.eEditorMailMask)) { // only for Composer and not for htmlmail diff --git a/mozilla/editor/ui/dialogs/content/EdLinkChecker.js b/mozilla/editor/ui/dialogs/content/EdLinkChecker.js index ee46186d3b7..042280a2feb 100644 --- a/mozilla/editor/ui/dialogs/content/EdLinkChecker.js +++ b/mozilla/editor/ui/dialogs/content/EdLinkChecker.js @@ -74,9 +74,9 @@ function Startup() objects = editor.getLinkedObjects(); } catch (e) {} - if (!objects || objects.count == 0) + if (!objects || objects.Count() == 0) { - AlertWithTitle(GetString("Alert"), GetString("NoLinksToCheck"); + AlertWithTitle(GetString("Alert"), GetString("NoLinksToCheck")); window.close(); return; } @@ -89,7 +89,7 @@ function Startup() // 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/mozilla/editor/ui/dialogs/content/EdReplace.js b/mozilla/editor/ui/dialogs/content/EdReplace.js index ee8a45b4fea..66d20708bca 100644 --- a/mozilla/editor/ui/dialogs/content/EdReplace.js +++ b/mozilla/editor/ui/dialogs/content/EdReplace.js @@ -42,7 +42,6 @@ function initDialogObject() gReplaceDialog.replace = document.getElementById("replace"); gReplaceDialog.replaceAndFind = document.getElementById("replaceAndFind"); gReplaceDialog.replaceAll = document.getElementById("replaceAll"); - gEditor = null; } function loadDialog() @@ -69,6 +68,14 @@ function loadDialog() function onLoad() { + // If we don't get the editor, then we won't allow replacing. + gEditor = GetCurrentEditor(); + if (!gEditor) + { + window.close(); + return; + } + // Get the xul element: var editorXUL = window.opener.document.getElementById("content-frame"); @@ -84,11 +91,6 @@ function onLoad() // Init gReplaceDialog. initDialogObject(); - try { - gEditor = editorXUL.editorShell.editor.QueryInterface(Components.interfaces.nsIPlaintextEditor); - } catch(e) { dump("Couldn't get an editor! " + e + "\n"); } - // If we don't get the editor, then we won't allow replacing. - // Change "OK" to "Find". //dialog.find.label = document.getElementById("fBLT").getAttribute("label"); diff --git a/mozilla/editor/ui/dialogs/content/EdSpellCheck.js b/mozilla/editor/ui/dialogs/content/EdSpellCheck.js index 99656f230e2..dc01da11518 100644 --- a/mozilla/editor/ui/dialogs/content/EdSpellCheck.js +++ b/mozilla/editor/ui/dialogs/content/EdSpellCheck.js @@ -19,24 +19,28 @@ * Rights Reserved. * * Contributor(s): + * Charles Manske (cmanske@netscape.com) + * Neil Rashbrook (neil@parkwaycc.co.uk) */ var gMisspelledWord; -var gSpellChecker; +var gSpellChecker = null; var gAllowSelectWord = true; var gPreviousReplaceWord = ""; var gFirstTime = true; var gSendMailMessageMode = false; -// dialog initialization code function Startup() { - if (!InitEditorShell()) + if (!GetCurrentEditor()) + { + window.close(); return; - + } // Get the spellChecker shell gSpellChecker = Components.classes['@mozilla.org/editor/editorspellchecker;1'].createInstance(Components.interfaces.nsIEditorSpellCheck); - if (!gSpellChecker) { + if (!gSpellChecker) + { dump("SpellChecker not found!!!\n"); window.close(); return; @@ -144,7 +148,7 @@ function InitLanguageMenu(curLang) var menuStr2; var isoStrArray; - var defaultIndex = 0; + var defaultItem = null; var langId; var i; for (i = 0; i < dictList.length; i++) @@ -183,15 +187,15 @@ function InitLanguageMenu(curLang) for (i = 0; i < dictList.length; i++) { - gDialog.LanguageMenulist.appendItem(dictList[i][0], dictList[i][1]); + var item = gDialog.LanguageMenulist.appendItem(dictList[i][0], dictList[i][1]); if (curLang && dictList[i][1] == curLang) - defaultIndex = i+2; //first two items are pre-populated and fixed + defaultItem = item; } // Now make sure the correct item in the menu list is selected. - if (dictList.length > 0) - gDialog.LanguageMenulist.selectedIndex = defaultIndex; + if (defaultItem) + gDialog.LanguageMenulist.selectedItem = defaultItem; } function DoEnabling() @@ -264,8 +268,7 @@ function CheckWord() word = gDialog.ReplaceWordInput.value; if (word) { - isMisspelled = gSpellChecker.CheckCurrentWord(word); - if (isMisspelled) + if (gSpellChecker.CheckCurrentWord(word)) { FillSuggestedList(word); SetReplaceEnable(); @@ -351,9 +354,12 @@ function Replace() var newWord = gDialog.ReplaceWordInput.value; if (gMisspelledWord && gMisspelledWord != newWord) { - editorShell.BeginBatchChanges(); - var isMisspelled = gSpellChecker.ReplaceWord(gMisspelledWord, newWord, false); - editorShell.EndBatchChanges(); + var editor = GetCurrentEditor(); + editor.beginTransaction(); + try { + gSpellChecker.ReplaceWord(gMisspelledWord, newWord, false); + } catch (e) {} + editor.endTransaction(); } NextWord(); } @@ -363,9 +369,12 @@ function ReplaceAll() var newWord = gDialog.ReplaceWordInput.value; if (gMisspelledWord && gMisspelledWord != newWord) { - editorShell.BeginBatchChanges(); - isMisspelled = gSpellChecker.ReplaceWord(gMisspelledWord, newWord, true); - editorShell.EndBatchChanges(); + var editor = GetCurrentEditor(); + editor.beginTransaction(); + try { + gSpellChecker.ReplaceWord(gMisspelledWord, newWord, true); + } catch (e) {} + editor.endTransaction(); } NextWord(); } @@ -510,7 +519,6 @@ function onClose() gSpellChecker.UninitSpellChecker(); } finally { gSpellChecker = null; } } - window.opener.cancelSendMessage = false; window.close(); } diff --git a/mozilla/editor/ui/dialogs/content/EdTableProps.js b/mozilla/editor/ui/dialogs/content/EdTableProps.js index 8a9ca6cab07..a44ceb26249 100644 --- a/mozilla/editor/ui/dialogs/content/EdTableProps.js +++ b/mozilla/editor/ui/dialogs/content/EdTableProps.js @@ -87,7 +87,7 @@ var gActiveEditor; // dialog initialization code function Startup() { - gActiveEditor = GetCurrentEditor(); + gActiveEditor = GetCurrentTableEditor(); if (!gActiveEditor) { window.close(); diff --git a/mozilla/editor/ui/dialogs/content/EditConflict.js b/mozilla/editor/ui/dialogs/content/EditConflict.js index c9b86c797de..fa20487b95a 100644 --- a/mozilla/editor/ui/dialogs/content/EditConflict.js +++ b/mozilla/editor/ui/dialogs/content/EditConflict.js @@ -43,8 +43,7 @@ function KeepCurrentPage() function UseOtherPage() { // Reload the URL -- that will get other editor's contents - // XXX TODO: Need to replace editorShell.LoadUrl with something in nsIEditingSession? - setTimeout("editorShell.LoadUrl(GetDocumentUrl())", 10); + setTimeout("window.opener.EditorLoadUrl(GetDocumentUrl())", 10); SaveWindowLocation(); return true; }