From aadf2042b2e35a776044d033e20134be94114172 Mon Sep 17 00:00:00 2001 From: "cmanske%netscape.com" Date: Fri, 12 May 2000 02:37:40 +0000 Subject: [PATCH] UI work: Implemented table commands (part of 20973), fixed Plain Text editor, don't remove toolbars for HTML Source editmode, helped ftang with new 'Save As Charset' dialog (moved methods shared with Page Properties dialog to common file) git-svn-id: svn://10.0.0.236/trunk@69318 18797224-902f-48f8-a5cc-f745e15eee43 --- .../ui/composer/content/ComposerCommands.js | 558 +++++++++++++++--- .../content/EditorCommandsOverlay.xul | 72 ++- .../content/EditorContextMenuOverlay.xul | 2 +- mozilla/editor/ui/composer/content/editor.js | 285 +++++---- mozilla/editor/ui/composer/content/editor.xul | 8 +- .../ui/composer/content/editorOverlay.xul | 3 +- .../composer/locale/en-US/editor.properties | 3 +- .../composer/locale/en-US/editorOverlay.dtd | 4 +- .../ui/dialogs/content/EdDialogCommon.js | 119 ++++ .../editor/ui/dialogs/content/EdPageProps.js | 107 +--- .../ui/dialogs/content/EditorSaveAsCharset.js | 148 +---- .../dialogs/content/EditorSaveAsCharset.xul | 11 +- .../locale/en-US/EditorSaveAsCharset.dtd | 5 +- 13 files changed, 820 insertions(+), 505 deletions(-) diff --git a/mozilla/editor/ui/composer/content/ComposerCommands.js b/mozilla/editor/ui/composer/content/ComposerCommands.js index fe4b68bb3c7..ce347ace3db 100644 --- a/mozilla/editor/ui/composer/content/ComposerCommands.js +++ b/mozilla/editor/ui/composer/content/ComposerCommands.js @@ -28,6 +28,110 @@ var gComposerCommandManager = null; var commonDialogsService = Components.classes["component://netscape/appshell/commonDialogs"].getService(); commonDialogsService = commonDialogsService.QueryInterface(Components.interfaces.nsICommonDialogs); +//----------------------------------------------------------------------------------- +function SetupControllerCommands() +{ + gComposerCommandManager = GetComposerController(); + if (!gComposerCommandManager) + return; + + dump("Registering commands\n"); + + gComposerCommandManager.registerCommand("cmd_newEditor", nsNewEditorCommand); + + gComposerCommandManager.registerCommand("cmd_open", nsOpenCommand); + gComposerCommandManager.registerCommand("cmd_saveAsCharset", nsSaveAsCharsetCommand); + gComposerCommandManager.registerCommand("cmd_revert", nsRevertCommand); + gComposerCommandManager.registerCommand("cmd_openRemote", nsOpenRemoteCommand); + gComposerCommandManager.registerCommand("cmd_preview", nsPreviewCommand); + gComposerCommandManager.registerCommand("cmd_quit", nsQuitCommand); + + gComposerCommandManager.registerCommand("cmd_find", nsFindCommand); + gComposerCommandManager.registerCommand("cmd_findNext", nsFindNextCommand); + gComposerCommandManager.registerCommand("cmd_spelling", nsSpellingCommand); + + gComposerCommandManager.registerCommand("cmd_editHTML", nsEditHTMLCommand); + gComposerCommandManager.registerCommand("cmd_insertChars", nsInsertCharsCommand); + gComposerCommandManager.registerCommand("cmd_preferences", nsPreferencesCommand); + + gComposerCommandManager.registerCommand("cmd_listProperties", nsListPropertiesCommand); + gComposerCommandManager.registerCommand("cmd_pageProperties", nsPagePropertiesCommand); + gComposerCommandManager.registerCommand("cmd_colorProperties", nsColorPropertiesCommand); + gComposerCommandManager.registerCommand("cmd_advancedProperties", nsAdvancedPropertiesCommand); + + gComposerCommandManager.registerCommand("cmd_image", nsImageCommand); + gComposerCommandManager.registerCommand("cmd_hline", nsHLineCommand); + gComposerCommandManager.registerCommand("cmd_table", nsTableCommand); // insert or edit + gComposerCommandManager.registerCommand("cmd_editTable", nsEditTableCommand); // edit + gComposerCommandManager.registerCommand("cmd_link", nsLinkCommand); + gComposerCommandManager.registerCommand("cmd_anchor", nsAnchorCommand); + gComposerCommandManager.registerCommand("cmd_insertHTML", nsInsertHTMLCommand); + gComposerCommandManager.registerCommand("cmd_insertBreak", nsInsertBreakCommand); + gComposerCommandManager.registerCommand("cmd_insertBreakAll",nsInsertBreakAllCommand); + + gComposerCommandManager.registerCommand("cmd_SelectTable", nsSelectTableCommand); + gComposerCommandManager.registerCommand("cmd_SelectRow", nsSelectTableRowCommand); + gComposerCommandManager.registerCommand("cmd_SelectColumn", nsSelectTableColumnCommand); + gComposerCommandManager.registerCommand("cmd_SelectCell", nsSelectTableCellCommand); + gComposerCommandManager.registerCommand("cmd_SelectAllCells", nsSelectAllTableCellsCommand); + gComposerCommandManager.registerCommand("cmd_InsertTable", nsInsertTableCommand); + gComposerCommandManager.registerCommand("cmd_InsertRowAbove", nsInsertTableRowAboveCommand); + gComposerCommandManager.registerCommand("cmd_InsertRowBelow", nsInsertTableRowBelowCommand); + gComposerCommandManager.registerCommand("cmd_InsertColumnBefore", nsInsertTableColumnBeforeCommand); + gComposerCommandManager.registerCommand("cmd_InsertColumnAfter", nsInsertTableColumnAfterCommand); + gComposerCommandManager.registerCommand("cmd_InsertCellBefore", nsInsertTableCellBeforeCommand); + gComposerCommandManager.registerCommand("cmd_InsertCellAfter", nsInsertTableCellAfterCommand); + gComposerCommandManager.registerCommand("cmd_DeleteTable", nsDeleteTableCommand); + gComposerCommandManager.registerCommand("cmd_DeleteRow", nsDeleteTableRowCommand); + gComposerCommandManager.registerCommand("cmd_DeleteColumn", nsDeleteTableColumnCommand); + gComposerCommandManager.registerCommand("cmd_DeleteCell", nsDeleteTableCellCommand); + gComposerCommandManager.registerCommand("cmd_DeleteCellContents", nsDeleteTableCellContentsCommand); + gComposerCommandManager.registerCommand("cmd_NormalizeTable", nsNormalizeTableCommand); +} + +//----------------------------------------------------------------------------------- +function GetComposerController() +{ + var numControllers = window.content.controllers.getControllerCount(); + + // count down to find a controller that supplies a nsIControllerCommandManager interface + for (var i = numControllers; i >= 0 ; i --) + { + var commandManager = null; + + try { + var controller = window.content.controllers.getControllerAt(i); + var interfaceRequestor = controller.QueryInterface(Components.interfaces.nsIInterfaceRequestor); + if (!interfaceRequestor) continue; + + commandManager = interfaceRequestor.getInterface(Components.interfaces.nsIControllerCommandManager); + } catch(ex) { + dump("failed to get command manager number "+i+"\n"); + } + + if (commandManager) + return commandManager; + } + + dump("Failed to find a controller to register commands with\n"); + return null; +} + +//----------------------------------------------------------------------------------- +function goUpdateComposerMenuItems(commandset) +{ + // dump("Updating commands for " + commandset.id + "\n"); + + for (var i = 0; i < commandset.childNodes.length; i++) + { + var commandID = commandset.childNodes[i].getAttribute("id"); + if (commandID) + { + goUpdateCommand(commandID); + } + } +} + //----------------------------------------------------------------------------------- function PrintObject(obj) { @@ -598,11 +702,373 @@ var nsEditHTMLCommand = { isCommandEnabled: function(aCommand, dummy) { - return false; + return (window.editorShell && window.editorShell.documentEditable); }, doCommand: function(aCommand) { - _EditorNotImplemented(); + _EditorNotImplemented(); //TODO: IMPLEMENT ME! + } +}; + +//----------------------------------------------------------------------------------- +// TABLE EDITING COMMANDS +// Command Updating Strategy: +// Don't update + +function EditorInitTableMenu() +{ + // Change text on the "Join..." item depending if we + // are joining selected cells or just cell to right + // TODO: What to do about normal selection that crosses + // table border? Try to figure out all cells + // included in the selection? + var menuText; + if (editorShell.GetFirstSelectedCell()) + menuText = GetString("JoinSelectedCells"); + else + menuText = GetString("JoinCellToRight"); + + document.getElementById("menu_tableJoinCells").setAttribute("value",menuText); + + // Set platform-specific hints for how to select cells + if (gIsWin) osKey = "XulKeyWin"; + if (gIsMac) osKey = "XulKeyMac"; + if (gIsUNIX) osKey = "XulKeyUnix"; + + var DragStr = GetString(osKey)+GetString("Drag"); + var ClickStr = GetString(osKey)+GetString("Click"); + var DelStr = GetString(gIsMac ? "Clear" : "Del"); + + document.getElementById("menu_DeleteCell").setAttribute("acceltext",ClickStr); + document.getElementById("menu_SelectRow").setAttribute("acceltext",DragStr); + document.getElementById("menu_SelectColumn").setAttribute("acceltext",DragStr); + document.getElementById("menu_SelectAllCells").setAttribute("acceltext",DragStr); + // And add "Del" or "Clear" + document.getElementById("menu_DeleteCellContents").setAttribute("acceltext",DelStr); +dump("*** commandset id=composerTableMenuItems:"+document.getElementById('composerTableMenuItems')+"\n"); + + goUpdateTableMenuItems(document.getElementById("composerTableMenuItems")); +} + + +function goUpdateTableMenuItems(commandset) +{ +dump(" **** goUpdateTableMenuItems: commandset="+commandset+"\n"); + // Insert table can be done any time (if editable document) + goUpdateCommand("cmd_InsertTable"); + + var enabled = false; + var enabledIfTable = false; + if (window.editorShell && window.editorShell.documentEditable) + { + var selectedCountObj = new Object(); + var tagNameObj = new Object(); + var element = editorShell.GetSelectedOrParentTableElement(tagNameObj, selectedCountObj); + if (element) + { + // We can delete or normalize table if inside a table + // or any table element is selected + enabledIfTable = true; + + // All others require being inside a cell or selected cell + enable = (tagNameObj.value == "td"); + } + } + + goSetCommandEnabled("cmd_DeleteTable", enabledIfTable); + goSetCommandEnabled("cmd_NormalizeTable", enabledIfTable); + + // Loop through command nodes to set all the others + for (var i = 0; i < commandset.childNodes.length; i++) + { + var commandID = commandset.childNodes[i].getAttribute("id"); + if (commandID && + commandID != "cmd_InsertTable" && + commandID != "cmd_DeleteTable" && + commandID != "cmd_NormalizeTable") + { + goSetCommandEnabled(commandID, enabled); + } + } +} + +var nsSelectTableCommand = +{ + isCommandEnabled: function(aCommand, dummy) + { + return (window.editorShell && window.editorShell.documentEditable && + null != window.editorShell.GetElementOrParentByTagName("table")); + }, + doCommand: function(aCommand) + { + if (isCommandEnabled) + window.editorShell.SelectTable(); + } +}; + +var nsSelectTableRowCommand = +{ + isCommandEnabled: function(aCommand, dummy) + { + return (window.editorShell && window.editorShell.documentEditable && + null != window.editorShell.GetElementOrParentByTagName("td")); + }, + doCommand: function(aCommand) + { + if (isCommandEnabled) + window.editorShell.SelectTableRow(); + } +}; + +var nsSelectTableColumnCommand = +{ + isCommandEnabled: function(aCommand, dummy) + { +dump("nsSelectTableColumnCommand\n"); + return (window.editorShell && window.editorShell.documentEditable && + null != window.editorShell.GetElementOrParentByTagName("td")); + }, + doCommand: function(aCommand) + { + if (isCommandEnabled) + window.editorShell.SelectTableColumn(); + } +}; + +var nsSelectTableCellCommand = +{ + isCommandEnabled: function(aCommand, dummy) + { + return (window.editorShell && window.editorShell.documentEditable && + null != window.editorShell.GetElementOrParentByTagName("td")); + }, + doCommand: function(aCommand) + { + if (isCommandEnabled) + window.editorShell.SelectTableCell(); + } +}; + +var nsSelectAllTableCellsCommand = +{ + isCommandEnabled: function(aCommand, dummy) + { + return (window.editorShell && window.editorShell.documentEditable && + null != window.editorShell.GetElementOrParentByTagName("td")); + }, + doCommand: function(aCommand) + { + if (isCommandEnabled) + window.editorShell.SelectAllTableCells(); + } +}; + +var nsInsertTableCommand = +{ + isCommandEnabled: function(aCommand, dummy) + { + return (window.editorShell && window.editorShell.documentEditable); + }, + doCommand: function(aCommand) + { + if (isCommandEnabled) + window.editorShell.InsertTable(); + } +}; + +var nsInsertTableRowAboveCommand = +{ + isCommandEnabled: function(aCommand, dummy) + { + return (window.editorShell && window.editorShell.documentEditable && + null != window.editorShell.GetElementOrParentByTagName("td")); + }, + doCommand: function(aCommand) + { + if (isCommandEnabled) + window.editorShell.InsertTableRow(false); + } +}; + +var nsInsertTableRowBelowCommand = +{ + isCommandEnabled: function(aCommand, dummy) + { + return (window.editorShell && window.editorShell.documentEditable && + null != window.editorShell.GetElementOrParentByTagName("td")); + }, + doCommand: function(aCommand) + { + if (isCommandEnabled) + window.editorShell.InsertTableRow(true); + } +}; + +var nsInsertTableColumnBeforeCommand = +{ + isCommandEnabled: function(aCommand, dummy) + { + return (window.editorShell && window.editorShell.documentEditable && + null != window.editorShell.GetElementOrParentByTagName("td")); + }, + doCommand: function(aCommand) + { + if (isCommandEnabled) + window.editorShell.InsertTableColumn(false); + } +}; + +var nsInsertTableColumnAfterCommand = +{ + isCommandEnabled: function(aCommand, dummy) + { + return (window.editorShell && window.editorShell.documentEditable && + null != window.editorShell.GetElementOrParentByTagName("td")); + }, + doCommand: function(aCommand) + { + if (isCommandEnabled) + window.editorShell.InsertTableColumn(true); + } +}; + +var nsInsertTableCellBeforeCommand = +{ + isCommandEnabled: function(aCommand, dummy) + { + return (window.editorShell && window.editorShell.documentEditable && + null != window.editorShell.GetElementOrParentByTagName("td")); + }, + doCommand: function(aCommand) + { + if (isCommandEnabled) + window.editorShell.InsertTableCell(false); + } +}; + +var nsInsertTableCellAfterCommand = +{ + isCommandEnabled: function(aCommand, dummy) + { + return (window.editorShell && window.editorShell.documentEditable && + null != window.editorShell.GetElementOrParentByTagName("td")); + }, + doCommand: function(aCommand) + { + if (isCommandEnabled) + window.editorShell.InsertTableCell(true); + } +}; + +var nsDeleteTableCommand = +{ + isCommandEnabled: function(aCommand, dummy) + { + return (window.editorShell && window.editorShell.documentEditable && + null != window.editorShell.GetElementOrParentByTagName("table")); + }, + doCommand: function(aCommand) + { + if (isCommandEnabled) + window.editorShell.DeleteTable(); + } +}; + +var nsDeleteTableRowCommand = +{ + isCommandEnabled: function(aCommand, dummy) + { + return (window.editorShell && window.editorShell.documentEditable && + null != window.editorShell.GetElementOrParentByTagName("td")); + }, + doCommand: function(aCommand) + { + if (isCommandEnabled) + window.editorShell.DeleteTableRow(1); + } +}; + +var nsDeleteTableColumnCommand = +{ + isCommandEnabled: function(aCommand, dummy) + { + return (window.editorShell && window.editorShell.documentEditable && + null != window.editorShell.GetElementOrParentByTagName("td")); + }, + doCommand: function(aCommand) + { + if (isCommandEnabled) + window.editorShell.DeleteTableColumn(1); + } +}; + +var nsDeleteTableCellCommand = +{ + isCommandEnabled: function(aCommand, dummy) + { + return (window.editorShell && window.editorShell.documentEditable && + null != window.editorShell.GetElementOrParentByTagName("td")); + }, + doCommand: function(aCommand) + { + if (isCommandEnabled) + window.editorShell.DeleteTableCell(1); + } +}; + +var nsDeleteTableCellContentsCommand = +{ + isCommandEnabled: function(aCommand, dummy) + { + return (window.editorShell && window.editorShell.documentEditable && + null != window.editorShell.GetElementOrParentByTagName("td")); + }, + doCommand: function(aCommand) + { + if (isCommandEnabled) + window.editorShell.DeleteTableCellContents(); + } +}; + +var nsNormalizeTableCommand = +{ + isCommandEnabled: function(aCommand, dummy) + { + return (window.editorShell && window.editorShell.documentEditable && + null != window.editorShell.GetElementOrParentByTagName("table")); + }, + doCommand: function(aCommand) + { + if (isCommandEnabled) + window.editorShell.NormalizeTable(); + } +}; + +var nsJoinTableCellsCommand = +{ + isCommandEnabled: function(aCommand, dummy) + { + return (window.editorShell && window.editorShell.documentEditable && + null != window.editorShell.GetElementOrParentByTagName("td")); + }, + doCommand: function(aCommand) + { + if (isCommandEnabled) + window.editorShell.JoinTableCells(); + } +}; + +var nsSplitTableCellCommand = +{ + isCommandEnabled: function(aCommand, dummy) + { + return (window.editorShell && window.editorShell.documentEditable && + null != window.editorShell.GetElementOrParentByTagName("td")); + }, + doCommand: function(aCommand) + { + if (isCommandEnabled) + window.editorShell.SplitTableCell(); } }; @@ -621,91 +1087,3 @@ var nsPreferencesCommand = }; -//----------------------------------------------------------------------------------- -function GetComposerController() -{ - var numControllers = window.content.controllers.getControllerCount(); - - // count down to find a controller that supplies a nsIControllerCommandManager interface - for (var i = numControllers; i >= 0 ; i --) - { - var commandManager = null; - - try { - var controller = window.content.controllers.getControllerAt(i); - var interfaceRequestor = controller.QueryInterface(Components.interfaces.nsIInterfaceRequestor); - if (!interfaceRequestor) continue; - - commandManager = interfaceRequestor.getInterface(Components.interfaces.nsIControllerCommandManager); - } catch(ex) { - - } - - if (commandManager) - return commandManager; - } - - dump("Failed to find a controller to register commands with\n"); - return null; -} - - -//----------------------------------------------------------------------------------- -function SetupControllerCommands() -{ - gComposerCommandManager = GetComposerController(); - if (!gComposerCommandManager) - return; - - dump("Registering commands\n"); - - gComposerCommandManager.registerCommand("cmd_newEditor", nsNewEditorCommand); - - gComposerCommandManager.registerCommand("cmd_open", nsOpenCommand); - gComposerCommandManager.registerCommand("cmd_saveAsCharset", nsSaveAsCharsetCommand); - gComposerCommandManager.registerCommand("cmd_revert", nsRevertCommand); - gComposerCommandManager.registerCommand("cmd_openRemote", nsOpenRemoteCommand); - gComposerCommandManager.registerCommand("cmd_preview", nsPreviewCommand); - gComposerCommandManager.registerCommand("cmd_quit", nsQuitCommand); - - gComposerCommandManager.registerCommand("cmd_find", nsFindCommand); - gComposerCommandManager.registerCommand("cmd_findNext", nsFindNextCommand); - gComposerCommandManager.registerCommand("cmd_spelling", nsSpellingCommand); - - gComposerCommandManager.registerCommand("cmd_editHTML", nsEditHTMLCommand); - gComposerCommandManager.registerCommand("cmd_insertChars", nsInsertCharsCommand); - gComposerCommandManager.registerCommand("cmd_preferences", nsPreferencesCommand); - - gComposerCommandManager.registerCommand("cmd_listProperties", nsListPropertiesCommand); - gComposerCommandManager.registerCommand("cmd_pageProperties", nsPagePropertiesCommand); - gComposerCommandManager.registerCommand("cmd_colorProperties", nsColorPropertiesCommand); - gComposerCommandManager.registerCommand("cmd_advancedProperties", nsAdvancedPropertiesCommand); - - - gComposerCommandManager.registerCommand("cmd_image", nsImageCommand); - gComposerCommandManager.registerCommand("cmd_hline", nsHLineCommand); - gComposerCommandManager.registerCommand("cmd_table", nsTableCommand); // insert or edit - gComposerCommandManager.registerCommand("cmd_editTable", nsEditTableCommand); // edit - gComposerCommandManager.registerCommand("cmd_link", nsLinkCommand); - gComposerCommandManager.registerCommand("cmd_anchor", nsAnchorCommand); - gComposerCommandManager.registerCommand("cmd_insertHTML", nsInsertHTMLCommand); - gComposerCommandManager.registerCommand("cmd_insertBreak", nsInsertBreakCommand); - gComposerCommandManager.registerCommand("cmd_insertBreakAll", nsInsertBreakAllCommand); - -} - -//----------------------------------------------------------------------------------- -function goUpdateComposerMenuItems(commandset) -{ - // dump("Updating commands for " + commandset.id + "\n"); - - for (var i = 0; i < commandset.childNodes.length; i++) - { - var commandID = commandset.childNodes[i].getAttribute("id"); - if (commandID) - { - goUpdateCommand(commandID); - } - } -} - diff --git a/mozilla/editor/ui/composer/content/EditorCommandsOverlay.xul b/mozilla/editor/ui/composer/content/EditorCommandsOverlay.xul index 84e83551639..fe943dcfdd5 100644 --- a/mozilla/editor/ui/composer/content/EditorCommandsOverlay.xul +++ b/mozilla/editor/ui/composer/content/EditorCommandsOverlay.xul @@ -27,6 +27,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + @@ -44,41 +72,43 @@ - - - - - + + + + + - + - - + + - - + + - - + + - - - - - + + + + + - - - - + + + + + + diff --git a/mozilla/editor/ui/composer/content/EditorContextMenuOverlay.xul b/mozilla/editor/ui/composer/content/EditorContextMenuOverlay.xul index efadce72f50..c0a170f2b0a 100644 --- a/mozilla/editor/ui/composer/content/EditorContextMenuOverlay.xul +++ b/mozilla/editor/ui/composer/content/EditorContextMenuOverlay.xul @@ -61,7 +61,7 @@ --> - + diff --git a/mozilla/editor/ui/composer/content/editor.js b/mozilla/editor/ui/composer/content/editor.js index ed4438e5560..663b06861b3 100644 --- a/mozilla/editor/ui/composer/content/editor.js +++ b/mozilla/editor/ui/composer/content/editor.js @@ -44,7 +44,7 @@ var docWasModified = false; // Check if clean document, if clean then unload wh var contentWindow = 0; var sourceContentWindow = 0; var ContentWindowDeck; -var EditorToolbox; +var FormatToolbar; // Bummer! Can't get at enums from nsIDocumentEncoder.h var gOutputSelectionOnly = 1; var gOutputFormatted = 2; @@ -63,6 +63,7 @@ var gPreviewModeButton; var gIsWindows; var gIsMac; var gIsUNIX; +var gIsHTMLEditor = false; var gPrefs; // These must be kept in synch with the XUL lists @@ -99,6 +100,9 @@ function TextEditorOnLoad() function PageIsEmptyAndUntouched() { +dump("Editorshell="+editorShell+"\n"); +dump("DocumentIsEmpty="+editorShell.documentIsEmpty+"\n"); +dump("docWasModified="+docWasModified+"\n"); return (editorShell != null) && (editorShell.documentIsEmpty == true) && (docWasModified == false); } @@ -136,26 +140,32 @@ function EditorStartup(editorType, editorElement) { contentWindow = window.content; sourceContentWindow = document.getElementById("content-source"); - gEditModeLabel = document.getElementById("EditModeLabel"); - gNormalModeButton = document.getElementById("NormalModeButton"); - gTagModeButton = document.getElementById("TagModeButton"); - gSourceModeButton = document.getElementById("SourceModeButton"); - gPreviewModeButton = document.getElementById("PreviewModeButton"); + gIsHTMLEditor = (editorType == "html"); + + if (gIsHTMLEditor) + { + gEditModeLabel = document.getElementById("EditModeLabel"); + gNormalModeButton = document.getElementById("NormalModeButton"); + gTagModeButton = document.getElementById("TagModeButton"); + gSourceModeButton = document.getElementById("SourceModeButton"); + gPreviewModeButton = document.getElementById("PreviewModeButton"); + + // The "type" attribute persists, so use that value + // to setup edit mode buttons +dump("Edit Mode: "+gNormalModeButton.getAttribute('type')+"\n"); + ToggleEditModeType(gNormalModeButton.getAttribute("type")); + + // XUL elements we use when switching from normal editor to edit source + ContentWindowDeck = document.getElementById("ContentWindowDeck"); + FormatToolbar = document.getElementById("FormatToolbar"); + } gIsWin = navigator.appVersion.indexOf("Win") != -1; gIsUNIX = (navigator.appVersion.indexOf("X11") || navigator.appVersion.indexOf("nux")) != -1; gIsMac = !gIsWin && !gIsUNIX; -dump("IsWin="+gIsWin+", IsUNIX="+gIsUNIX+", IsMac="+gIsMac+"\n"); + dump("IsWin="+gIsWin+", IsUNIX="+gIsUNIX+", IsMac="+gIsMac+"\n"); - // The "type" attribute persists, so use that value - // to setup edit mode buttons - ToggleEditModeType(gNormalModeButton.getAttribute("type")); - - // XUL elements we use when switching from normal editor to edit source - ContentWindowDeck = document.getElementById("ContentWindowDeck"); - EditorToolbox = document.getElementById("EditorToolbox"); - // store the editor shell in the window, so that child windows can get to it. editorShell = editorElement.editorShell; @@ -177,8 +187,6 @@ dump("IsWin="+gIsWin+", IsUNIX="+gIsUNIX+", IsMac="+gIsMac+"\n"); // set up our global prefs object GetPrefsService(); -// editorShell.editorDocument.onDblClick = "EditorDblClick()"; - // Get url for editor content and load it. // the editor gets instantiated by the editor shell when the URL has finished loading. var url = document.getElementById("args").getAttribute("value"); @@ -727,51 +735,55 @@ function EditorAlign(commandID, alignType) function SetEditMode(mode) { - var bodyNode = editorShell.editorDocument.getElementsByTagName("body").item(0); - if (!bodyNode) + if (gIsHTMLEditor) { - dump("SetEditMode: We don't have a body node!\n"); - return; - } - // Switch the UI mode before inserting contents - // so user can't type in source window while new window is being filled - var previousMode = EditorDisplayMode; - if (!SetDisplayMode(mode)) - return; - - if (mode == DisplayModeSource) - { - // Get the current contents and output into the SourceWindow - if (bodyNode) + var bodyNode = editorShell.editorDocument.getElementsByTagName("body").item(0); + if (!bodyNode) { - var childCount = bodyNode.childNodes.length; - if( childCount) - { - // KLUDGE until we have an output flag that strips out and for us - var sourceContent = editorShell.GetContentsAs("text/html", gOutputBodyOnly); - sourceContentWindow.value = sourceContent.replace(//,"").replace(/<\/body>/,""); - sourceContentWindow.focus(); - setTimeout("sourceContentWindow.focus()", 10); - return; - } + dump("SetEditMode: We don't have a body node!\n"); + return; } - // If we fall through, revert to previous node - SetDisplayMode(PreviousNonSourceDisplayMode); - } - else if (previousMode == DisplayModeSource) - { - // We are comming from edit source mode, - // so transfer that back into the document - editorShell.SelectAll(); - editorShell.InsertSource(sourceContentWindow.value); - // Clear out the source editor buffer - sourceContentWindow.value = ""; - // reset selection to top of doc (wish we could preserve it!) - if (bodyNode) - editorShell.editorSelection.collapse(bodyNode, 0); + // Switch the UI mode before inserting contents + // so user can't type in source window while new window is being filled + var previousMode = EditorDisplayMode; + if (!SetDisplayMode(mode)) + return; - contentWindow.focus(); - setTimeout("contentWindow.focus()", 10); + if (mode == DisplayModeSource) + { + // Get the current contents and output into the SourceWindow + if (bodyNode) + { + var childCount = bodyNode.childNodes.length; + if( childCount) + { + // KLUDGE until we have an output flag that strips out and for us + //var sourceContent = editorShell.GetContentsAs("text/html", gOutputBodyOnly); + //sourceContentWindow.value = sourceContent.replace(//,"").replace(/<\/body>/,""); + sourceContentWindow.value = editorShell.GetContentsAs("text/html", gOutputBodyOnly); + sourceContentWindow.focus(); + setTimeout("sourceContentWindow.focus()", 10); + return; + } + } + // If we fall through, revert to previous node + SetDisplayMode(PreviousNonSourceDisplayMode); + } + else if (previousMode == DisplayModeSource) + { + // We are comming from edit source mode, + // so transfer that back into the document + editorShell.SelectAll(); + editorShell.InsertSource(sourceContentWindow.value); + // Clear out the source editor buffer + sourceContentWindow.value = ""; + // reset selection to top of doc (wish we could preserve it!) + if (bodyNode) + editorShell.editorSelection.collapse(bodyNode, 0); + + contentWindow.focus(); + setTimeout("contentWindow.focus()", 10); + } } } @@ -784,81 +796,81 @@ function CancelSourceEditing() function SetDisplayMode(mode) { - // Already in requested mode: - // return false to indicate we didn't switch - if (mode == EditorDisplayMode) - return false; + if (gIsHTMLEditor) + { + // Already in requested mode: + // return false to indicate we didn't switch + if (mode == EditorDisplayMode) + return false; - EditorDisplayMode = mode; + EditorDisplayMode = mode; - // Save the last non-source mode so we can cancel source editing easily - if (mode != DisplayModeSource) - PreviousNonSourceDisplayMode = mode; + // Save the last non-source mode so we can cancel source editing easily + if (mode != DisplayModeSource) + PreviousNonSourceDisplayMode = mode; - // Editorshell does the style sheet loading/unloading - editorShell.SetDisplayMode(mode); + // Editorshell does the style sheet loading/unloading + editorShell.SetDisplayMode(mode); - // Set the UI states - gPreviewModeButton.setAttribute("selected",Number(mode == DisplayModePreview)); - gNormalModeButton.setAttribute("selected",Number(mode == DisplayModeNormal)); - gTagModeButton.setAttribute("selected",Number(mode == DisplayModeAllTags)); - gSourceModeButton.setAttribute("selected", Number(mode == DisplayModeSource)); + // Set the UI states + gPreviewModeButton.setAttribute("selected",Number(mode == DisplayModePreview)); + gNormalModeButton.setAttribute("selected",Number(mode == DisplayModeNormal)); + gTagModeButton.setAttribute("selected",Number(mode == DisplayModeAllTags)); + gSourceModeButton.setAttribute("selected", Number(mode == DisplayModeSource)); - if (mode == DisplayModeSource) - { - // Switch to the sourceWindow (second in the deck) - ContentWindowDeck.setAttribute("index","1"); + if (mode == DisplayModeSource) + { + // Switch to the sourceWindow (second in the deck) + ContentWindowDeck.setAttribute("index","1"); - // Hide normal chrome - EditorToolbox.setAttribute("collapsed", "true"); + // TODO: WE MUST DISABLE ALL KEYBOARD COMMANDS! - // TODO: WE MUST DISABLE ALL KEYBOARD COMMANDS! + // THIS DOESN'T WORK! + sourceContentWindow.focus(); + } + else + { + // Switch to the normal editor (first in the deck) + ContentWindowDeck.setAttribute("index","0"); - // THIS DOESN'T WORK! - sourceContentWindow.focus(); + // TODO: WE MUST ENABLE ALL KEYBOARD COMMANDS! + + contentWindow.focus(); + } + return true; } - else - { - // Switch to the normal editor (first in the deck) - ContentWindowDeck.setAttribute("index","0"); - - // Show normal chrome - EditorToolbox.removeAttribute("collapsed"); - - // TODO: WE MUST ENABLE ALL KEYBOARD COMMANDS! - - contentWindow.focus(); - } - return true; } function ToggleEditModeType() { - if (EditModeType == "text") + if (gIsHTMLEditor) { - EditModeType = "image"; - gNormalModeButton.setAttribute("value",""); - gTagModeButton.setAttribute("value",""); - gSourceModeButton.setAttribute("value",""); - gPreviewModeButton.setAttribute("value",""); - // Advanced users don't need to see the label (cleaner look) - gEditModeLabel.setAttribute("hidden","true"); - } - else - { - EditModeType = "text"; - gNormalModeButton.setAttribute("value","Normal"); - gTagModeButton.setAttribute("value","Show All Tags"); - gSourceModeButton.setAttribute("value","HTML Source"); - gPreviewModeButton.setAttribute("value","Edit Preview"); - gEditModeLabel.removeAttribute("hidden"); - } + if (EditModeType == "text") + { + EditModeType = "image"; + gNormalModeButton.setAttribute("value",""); + gTagModeButton.setAttribute("value",""); + gSourceModeButton.setAttribute("value",""); + gPreviewModeButton.setAttribute("value",""); + // Advanced users don't need to see the label (cleaner look) + gEditModeLabel.setAttribute("hidden","true"); + } + else + { + EditModeType = "text"; + gNormalModeButton.setAttribute("value","Normal"); + gTagModeButton.setAttribute("value","Show All Tags"); + gSourceModeButton.setAttribute("value","HTML Source"); + gPreviewModeButton.setAttribute("value","Edit Preview"); + gEditModeLabel.removeAttribute("hidden"); + } - gNormalModeButton.setAttribute("type",EditModeType); - gTagModeButton.setAttribute("type",EditModeType); - gSourceModeButton.setAttribute("type",EditModeType); - gPreviewModeButton.setAttribute("type",EditModeType); + gNormalModeButton.setAttribute("type",EditModeType); + gTagModeButton.setAttribute("type",EditModeType); + gSourceModeButton.setAttribute("type",EditModeType); + gPreviewModeButton.setAttribute("type",EditModeType); + } } function EditorToggleParagraphMarks() @@ -989,38 +1001,6 @@ function EditorInitFormatMenu() } } -function EditorInitTableMenu() -{ - // Change text on the "Join..." item depending if we - // are joining selected cells or just cell to right - // TODO: What to do about normal selection that crosses - // table border? Try to figure out all cells - // included in the selection? - var menuText; - if (editorShell.GetFirstSelectedCell()) - menuText = GetString("JoinSelectedCells"); - else - menuText = GetString("JoinCellToRight"); - - document.getElementById("tableJoinCells").setAttribute("value",menuText); - - // Set platform-specific hints for how to select cells - if (gIsWin) osKey = "XulKeyWin"; - if (gIsMac) osKey = "XulKeyMac"; - if (gIsUNIX) osKey = "XulKeyUnix"; - - var DragStr = GetString(osKey)+GetString("Drag"); - var ClickStr = GetString(osKey)+GetString("Click"); - var DelStr = GetString(gIsMac ? "Clear" : "Del"); - - document.getElementById("menu_DeleteCell").setAttribute("acceltext",ClickStr); - document.getElementById("menu_SelectRow").setAttribute("acceltext",DragStr); - document.getElementById("menu_SelectColumn").setAttribute("acceltext",DragStr); - document.getElementById("menu_SelectAllCells").setAttribute("acceltext",DragStr); - // And add "Del" or "Clear" - document.getElementById("menu_DeleteCellContents").setAttribute("acceltext",DelStr); -} - function EditorInitToolbars() { // Nothing to do now, but we might want some state updating here @@ -1042,12 +1022,15 @@ function EditorSetDefaultPrefs() } // doctype - var newdoctype = domdoc.implementation.createDocumentType("html", "-//W3C//DTD HTML 4.01 Transitional//EN", - ""); + var newdoctype = domdoc.implementation.createDocumentType("html", "-//W3C//DTD HTML 4.01 Transitional//EN",""); if (!domdoc.doctype) + { domdoc.insertBefore(newdoctype, domdoc.firstChild); + } else + { domdoc.replaceChild(newdoctype, domdoc.doctype); + } // search for head; we'll need this for meta tag additions var headelement = 0; diff --git a/mozilla/editor/ui/composer/content/editor.xul b/mozilla/editor/ui/composer/content/editor.xul index 1f63c0e774d..ec7a8838cf5 100644 --- a/mozilla/editor/ui/composer/content/editor.xul +++ b/mozilla/editor/ui/composer/content/editor.xul @@ -68,6 +68,10 @@ + @@ -161,7 +165,7 @@ - + @@ -213,7 +217,7 @@