diff --git a/mozilla/editor/ui/composer/content/ComposerCommands.js b/mozilla/editor/ui/composer/content/ComposerCommands.js index 5e94afe765f..69e3e1642c4 100644 --- a/mozilla/editor/ui/composer/content/ComposerCommands.js +++ b/mozilla/editor/ui/composer/content/ComposerCommands.js @@ -120,8 +120,8 @@ function SetupTextEditorCommands() //dump("Registering plain text editor commands\n"); commandTable.registerCommand("cmd_find", nsFindCommand); - commandTable.registerCommand("cmd_findNext", new nsFindAgainCommand(false)); - commandTable.registerCommand("cmd_findPrev", new nsFindAgainCommand(true)); + commandTable.registerCommand("cmd_findNext", nsFindAgainCommand); + commandTable.registerCommand("cmd_findPrev", nsFindAgainCommand); commandTable.registerCommand("cmd_rewrap", nsRewrapCommand); commandTable.registerCommand("cmd_spelling", nsSpellingCommand); commandTable.registerCommand("cmd_validate", nsValidateCommand); @@ -227,6 +227,7 @@ function GetComposerCommandTable() var editorController = controller.QueryInterface(Components.interfaces.nsIControllerContext); editorController.init(null); + editorController.setCommandContext(GetCurrentEditorElement()); window.content.controllers.insertControllerAt(0, controller); // Store the controller ID so we can be sure to get the right one later @@ -538,7 +539,7 @@ var nsSaveCommand = try { var docUrl = GetDocumentUrl(); return IsDocumentEditable() && - (IsDocumentModified() || window.gHTMLSourceChanged || + (IsDocumentModified() || IsHTMLSourceChanged() || IsUrlAboutBlank(docUrl) || GetScheme(docUrl) != "file"); } catch (e) {return false;} }, @@ -657,7 +658,7 @@ var nsPublishCommand = // when you first open any local file. try { var docUrl = GetDocumentUrl(); - return IsDocumentModified() || window.gHTMLSourceChanged + return IsDocumentModified() || IsHTMLSourceChanged() || IsUrlAboutBlank(docUrl) || GetScheme(docUrl) == "file"; } catch (e) {return false;} } @@ -2333,53 +2334,48 @@ var nsQuitCommand = //----------------------------------------------------------------------------------- var nsFindCommand = { - isCommandEnabled: function(aCommand, dummy) + isCommandEnabled: function(aCommand, editorElement) { - return GetCurrentEditor() != null; + return editorElement.getEditor(editorElement.contentWindow) != null; }, - getCommandStateParams: function(aCommand, aParams, aRefCon) {}, - doCommandParams: function(aCommand, aParams, aRefCon) {}, + getCommandStateParams: function(aCommand, aParams, editorElement) {}, + doCommandParams: function(aCommand, aParams, editorElement) {}, - doCommand: function(aCommand) + doCommand: function(aCommand, editorElement) { try { window.openDialog("chrome://editor/content/EdReplace.xul", "_blank", - "chrome,dependent,titlebar", ""); + "chrome,modal,titlebar", editorElement); } catch(ex) { dump("*** Exception: couldn't open Replace Dialog\n"); } - window.content.focus(); + //window.content.focus(); } }; //----------------------------------------------------------------------------------- - -function nsFindAgainCommand(isFindPrev) +var nsFindAgainCommand = { - this.isFindPrev = isFindPrev; -} - -nsFindAgainCommand.prototype = -{ - isCommandEnabled: function(aCommand, dummy) + isCommandEnabled: function(aCommand, editorElement) { // we can only do this if the search pattern is non-empty. Not sure how // to get that from here - return (GetCurrentEditor() != null && !IsInHTMLSourceMode()); + return editorElement.getEditor(editorElement.contentWindow) != null; }, - getCommandStateParams: function(aCommand, aParams, aRefCon) {}, - doCommandParams: function(aCommand, aParams, aRefCon) {}, + getCommandStateParams: function(aCommand, aParams, editorElement) {}, + doCommandParams: function(aCommand, aParams, editorElement) {}, - doCommand: function(aCommand) + doCommand: function(aCommand, editorElement) { try { - var findInst = GetCurrentEditorElement().webBrowserFind; + var findPrev = aCommand == "cmd_findPrev"; + var findInst = editorElement.webBrowserFind; var findService = Components.classes["@mozilla.org/find/find_service;1"] - .getService(Components.interfaces.nsIFindService); - findInst.findBackwards = findService.findBackwards ^ this.isFindPrev; + .getService(Components.interfaces.nsIFindService); + findInst.findBackwards = findService.findBackwards ^ findPrev; findInst.findNext(); // reset to what it was in dialog, otherwise dialog setting can get reversed findInst.findBackwards = findService.findBackwards; @@ -2447,7 +2443,7 @@ var nsValidateCommand = { // If the document hasn't been modified, // then just validate the current url. - if (IsDocumentModified() || gHTMLSourceChanged) + if (IsDocumentModified() || IsHTMLSourceChanged()) { if (!CheckAndSaveDocument("cmd_validate", false)) return; diff --git a/mozilla/editor/ui/composer/content/EditorContextMenuOverlay.xul b/mozilla/editor/ui/composer/content/EditorContextMenuOverlay.xul index 8842943e5f3..b7de713c0ca 100644 --- a/mozilla/editor/ui/composer/content/EditorContextMenuOverlay.xul +++ b/mozilla/editor/ui/composer/content/EditorContextMenuOverlay.xul @@ -111,6 +111,18 @@ + + + + + + + + + + + + + try { + gSourceContentWindow = document.getElementById("content-source"); + gSourceContentWindow.makeEditable("text", false); + gSourceTextEditor = gSourceContentWindow.getEditor(gSourceContentWindow.contentWindow); + gSourceTextEditor.QueryInterface(Components.interfaces.nsIPlaintextEditor); + gSourceTextEditor.enableUndo(false); + gSourceTextEditor.rootElement.style.fontFamily = "-moz-fixed"; + gSourceTextEditor.rootElement.style.whiteSpace = "pre"; + gSourceTextEditor.rootElement.style.margin = 0; + var controller = Components.classes["@mozilla.org/embedcomp/base-command-controller;1"] + .createInstance(Components.interfaces.nsIControllerContext); + controller.init(null); + controller.setCommandContext(gSourceContentWindow); + gSourceContentWindow.contentWindow.controllers.insertControllerAt(0, controller); + var commandTable = controller.QueryInterface(Components.interfaces.nsIInterfaceRequestor) + .getInterface(Components.interfaces.nsIControllerCommandTable); + commandTable.registerCommand("cmd_find", nsFindCommand); + commandTable.registerCommand("cmd_findNext", nsFindAgainCommand); + commandTable.registerCommand("cmd_findPrev", nsFindAgainCommand); + } catch (e) { dump("makeEditable failed: "+e+"\n"); } } +const gSourceTextListener = +{ + NotifyDocumentCreated: function NotifyDocumentCreated() {}, + NotifyDocumentWillBeDestroyed: function NotifyDocumentWillBeDestroyed() {}, + NotifyDocumentStateChanged: function NotifyDocumentStateChanged(isChanged) + { + window.updateCommands("save"); + } +}; + +const gSourceTextObserver = +{ + observe: function observe(aSubject, aTopic, aData) + { + // we currently only use this to update undo + window.updateCommands("undo"); + } +}; + function TextEditorOnLoad() { // See if argument was passed. @@ -351,16 +392,6 @@ var gEditorDocumentObserver = if (editorStatus) return; - var editorType = GetCurrentEditorType(); - if (editorType != "htmlmail" - && editorType != "textmail") - { - // Set focus to content window if not a mail composer - // Race conditions prevent us from setting focus here - // when loading a url into blank window - setTimeout("SetFocusOnStartup()", 0); - } - if (!("InsertCharWindow" in window)) window.InsertCharWindow = null; @@ -374,6 +405,11 @@ var gEditorDocumentObserver = // Things for just the Web Composer application if (IsWebComposer()) { + // Set focus to content window if not a mail composer + // Race conditions prevent us from setting focus here + // when loading a url into blank window + setTimeout(SetFocusOnStartup, 0); + // Call EditorSetDefaultPrefsAndDoctype first so it gets the default author before initing toolbars EditorSetDefaultPrefsAndDoctype(); @@ -492,8 +528,6 @@ function EditorStartup() var is_HTMLEditor = IsHTMLEditor(); if (is_HTMLEditor) { - gSourceContentWindow = document.getElementById("content-source"); - // XUL elements we use when switching from normal editor to edit source gContentWindowDeck = document.getElementById("ContentWindowDeck"); gFormatToolbar = document.getElementById("FormatToolbar"); @@ -693,12 +727,12 @@ function CheckAndSaveDocument(command, allowDontSave) return true; } catch (e) { return true; } - if (!IsDocumentModified() && !gHTMLSourceChanged) + if (!IsDocumentModified() && !IsHTMLSourceChanged()) return true; // call window.focus, since we need to pop up a dialog // and therefore need to be visible (to prevent user confusion) - window.focus(); + top.document.commandDispatcher.focusedWindow.focus(); var scheme = GetScheme(GetDocumentUrl()); var doPublish = (scheme && scheme != "file"); @@ -762,7 +796,7 @@ function CheckAndSaveDocument(command, allowDontSave) if (result == 0) { // Save, but first finish HTML source mode - if (gHTMLSourceChanged) { + if (IsHTMLSourceChanged()) { try { FinishHTMLSource(); } catch (e) { return false;} @@ -1740,17 +1774,18 @@ function SetEditMode(mode) var source = editor.outputToString(kHTMLMimeType, flags); var start = source.search(/ from the newly-parsed document @@ -1788,36 +1823,24 @@ function SetEditMode(mode) try { editor.transactionManager.maxTransactionCount = -1; } catch (e) {} - } else { - // We don't need to call this again, so remove handler - gSourceContentWindow.removeEventListener("input", oninputHTMLSource, false); } - gHTMLSourceChanged = false; // Clear out the string buffers - gSourceContentWindow.value = null; + gSourceContentWindow.commandManager.removeCommandObserver(gSourceTextObserver, "cmd_undo"); + gSourceTextEditor.removeDocumentStateListener(gSourceTextListener); + gSourceTextEditor.enableUndo(false); + gSourceTextEditor.selectAll(); + gSourceTextEditor.deleteSelection(gSourceTextEditor.eNone); + gSourceTextEditor.resetModificationCount(); gContentWindow.focus(); } } -function oninputHTMLSource() -{ - gHTMLSourceChanged = true; - - // Trigger update of "Save" and "Publish" buttons - goUpdateCommand("cmd_save"); - goUpdateCommand("cmd_publish"); - - // We don't need to call this again, so remove handler - gSourceContentWindow.removeEventListener("input", oninputHTMLSource, false); -} - function CancelHTMLSource() { // Don't convert source text back into the DOM document - gSourceContentWindow.value = ""; - gHTMLSourceChanged = false; + gSourceTextEditor.resetModificationCount(); SetDisplayMode(gPreviousNonSourceDisplayMode); } @@ -1827,7 +1850,7 @@ function FinishHTMLSource() //Or RebuildDocumentFromSource() will fail. if (IsInHTMLSourceMode()) { - var htmlSource = gSourceContentWindow.value; + var htmlSource = gSourceTextEditor.outputToString(kTextMimeType, 0); if (htmlSource.length > 0) { var beginHead = htmlSource.indexOf(" diff --git a/mozilla/editor/ui/composer/content/editorUtilities.js b/mozilla/editor/ui/composer/content/editorUtilities.js index 423174e7f73..265ba6fcc0e 100644 --- a/mozilla/editor/ui/composer/content/editorUtilities.js +++ b/mozilla/editor/ui/composer/content/editorUtilities.js @@ -293,8 +293,7 @@ function IsHTMLEditor() function PageIsEmptyAndUntouched() { - return IsDocumentEmpty() && !IsDocumentModified() - && !gHTMLSourceChanged; + return IsDocumentEmpty() && !IsDocumentModified() && !IsHTMLSourceChanged(); } function IsInHTMLSourceMode() @@ -337,6 +336,11 @@ function IsDocumentModified() return false; } +function IsHTMLSourceChanged() +{ + return gSourceTextEditor.documentModified; +} + function newCommandParams() { try { diff --git a/mozilla/editor/ui/dialogs/content/EdReplace.js b/mozilla/editor/ui/dialogs/content/EdReplace.js index 66d20708bca..afd4b8143f6 100644 --- a/mozilla/editor/ui/dialogs/content/EdReplace.js +++ b/mozilla/editor/ui/dialogs/content/EdReplace.js @@ -68,19 +68,19 @@ function loadDialog() function onLoad() { + // Get the xul element: + var editorElement = window.arguments[0]; + // If we don't get the editor, then we won't allow replacing. - gEditor = GetCurrentEditor(); + gEditor = editorElement.getEditor(editorElement.contentWindow); if (!gEditor) { window.close(); return; } - // Get the xul element: - var editorXUL = window.opener.document.getElementById("content-frame"); - // Get the nsIWebBrowserFind service: - gFindInst = editorXUL.webBrowserFind; + gFindInst = editorElement.webBrowserFind; try { // get the find service, which stores global find state