Fixed editor HTML source bugs 81227 and 66249; pref dialog busted bug 77517; Delete table rows/columns bug 78400. r=mjudge, sr=kin

This commit is contained in:
cmanske%netscape.com 2001-05-16 23:44:56 +00:00
parent 21e3c3faca
commit 84722f7afb
3 changed files with 148 additions and 36 deletions

View File

@ -286,7 +286,7 @@ var nsSaveCommand =
return window.editorShell &&
(window.editorShell.documentModified ||
window.editorShell.editorDocument.location == "about:blank" ||
gEditorDisplayMode == DisplayModeSource);
window.gHTMLSourceChanged);
},
doCommand: function(aCommand)
@ -1252,7 +1252,24 @@ var nsDeleteTableRowCommand =
},
doCommand: function(aCommand)
{
window.editorShell.DeleteTableRow(1);
var rows = GetNumberOfContiguousSelectedRows();
// Delete at least one row
if (rows == 0)
rows = 1;
try {
window.editorShell.BeginBatchChanges();
// Loop to delete all blocks of contiguous, selected rows
while (rows)
{
window.editorShell.DeleteTableRow(rows);
rows = GetNumberOfContiguousSelectedRows();
}
window.editorShell.EndBatchChanges();
} catch(ex) {
window.editorShell.EndBatchChanges();
}
window._content.focus();
}
};
@ -1265,7 +1282,24 @@ var nsDeleteTableColumnCommand =
},
doCommand: function(aCommand)
{
window.editorShell.DeleteTableColumn(1);
var columns = GetNumberOfContiguousSelectedColumns();
// Delete at least one column
if (columns == 0)
columns = 1;
try {
window.editorShell.BeginBatchChanges();
// Loop to delete all blocks of contiguous, selected columns
while (columns)
{
window.editorShell.DeleteTableColumn(columns);
columns = GetNumberOfContiguousSelectedColumns();
}
window.editorShell.EndBatchChanges();
} catch(ex) {
window.editorShell.EndBatchChanges();
}
window._content.focus();
}
};

View File

@ -42,6 +42,7 @@ var WebCompose = false; // Set true for Web Composer, leave false for Messen
var docWasModified = false; // Check if clean document, if clean then unload when user "Opens"
var gContentWindow = 0;
var gSourceContentWindow = 0;
var gHTMLSourceChanged = false;
var gContentWindowDeck;
var gFormatToolbar;
var gFormatToolbarHidden = false;
@ -1051,8 +1052,6 @@ function SetEditMode(mode)
if (!SetDisplayMode(mode))
return;
var source;
if (mode == DisplayModeSource)
{
// Display the DOCTYPE as a non-editable string above edit area
@ -1079,12 +1078,6 @@ function SetEditMode(mode)
doctypeNode.setAttribute("collapsed", "true");
}
}
// We can't monitor changes while in HTML Source,
// so the nsSaveCommand::isCommandEnabled() will always return true
// when in HTML Source mode
goUpdateCommand("cmd_save");
// Get the entire document's source string
var flags = gOutputEncodeEntities;
@ -1093,45 +1086,76 @@ function SetEditMode(mode)
if (prettyPrint)
flags |= gOutputFormatted;
source = editorShell.GetContentsAs("text/html", flags);
var source = editorShell.GetContentsAs("text/html", flags);
var start = source.search(/<html/i);
if (start == -1) start = 0;
gSourceContentWindow.value = source.slice(start);
gSourceContentWindow.focus();
// Set oninput handler so we know if user made any changes
gSourceContentWindow.setAttribute("oninput", "oninputHTMLSource();");
gHTMLSourceChanged = false;
}
else if (previousMode == DisplayModeSource)
{
// We are comming from edit source mode,
// so transfer that back into the document
source = gSourceContentWindow.value;
editorShell.RebuildDocumentFromSource(source);
// Get the text for the <title> from the newly-parsed document
// (must do this for proper conversion of "escaped" characters)
var title = "";
var titlenodelist = window.editorShell.editorDocument.getElementsByTagName("title");
if (titlenodelist)
// Only rebuild document if a change was made in source window
if (gHTMLSourceChanged)
{
var titleNode = titlenodelist.item(0);
if (titleNode && titleNode.firstChild && titleNode.firstChild.data)
title = titleNode.firstChild.data;
editorShell.BeginBatchChanges();
try {
// We are comming from edit source mode,
// so transfer that back into the document
source = gSourceContentWindow.value;
editorShell.RebuildDocumentFromSource(source);
// Get the text for the <title> from the newly-parsed document
// (must do this for proper conversion of "escaped" characters)
var title = "";
var titlenodelist = window.editorShell.editorDocument.getElementsByTagName("title");
if (titlenodelist)
{
var titleNode = titlenodelist.item(0);
if (titleNode && titleNode.firstChild && titleNode.firstChild.data)
title = titleNode.firstChild.data;
}
if (window.editorShell.editorDocument.title != title)
{
window.editorShell.editorDocument.title = title;
ResetWindowTitleWithFilename();
}
// reset selection to top of doc (wish we could preserve it!)
if (bodyNode)
editorShell.editorSelection.collapse(bodyNode, 0);
} catch (ex) {
dump(ex);
}
editorShell.EndBatchChanges();
}
window.editorShell.editorDocument.title = title;
gHTMLSourceChanged = false;
// Clear out the string buffers
source = null;
gSourceContentWindow.value = null;
// reset selection to top of doc (wish we could preserve it!)
if (bodyNode)
editorShell.editorSelection.collapse(bodyNode, 0);
gContentWindow.focus();
}
ResetWindowTitleWithFilename();
}
}
function oninputHTMLSource()
{
gHTMLSourceChanged = true;
// Trigger update of "Save" button
goUpdateCommand("cmd_save");
// We don't need to call this again, so remove handler
// (Note: using "removeAttribute" didn't work!)
gSourceContentWindow.setAttribute("oninput", null);
}
function ResetWindowTitleWithFilename()
{
// Calling this resets the "Title [filename]" that we show on window caption
@ -1142,9 +1166,8 @@ function CancelHTMLSource()
{
// Don't convert source text back into the DOM document
gSourceContentWindow.value = "";
gHTMLSourceChanged = false;
SetDisplayMode(PreviousNonSourceDisplayMode);
ResetWindowTitleWithFilename();
}
@ -2289,6 +2312,60 @@ function EditorTableCellProperties()
}
}
function GetNumberOfContiguousSelectedRows()
{
var cell = editorShell.GetFirstSelectedCell();
if (!cell)
return 0;
var rows = 1;
var lastIndex = editorShell.GetRowIndex(cell);
do {
cell = editorShell.GetNextSelectedCell();
if (cell)
{
var index = editorShell.GetRowIndex(cell);
if (index == lastIndex + 1)
{
lastIndex = index;
rows++;
}
}
}
while (cell);
return rows;
}
function GetNumberOfContiguousSelectedColumns()
{
var cell = editorShell.GetFirstSelectedCell();
if (!cell)
return 0;
var columns = 1;
var lastIndex = editorShell.GetColumnIndex(cell);
do {
cell = editorShell.GetNextSelectedCell();
if (cell)
{
var index = editorShell.GetColumnIndex(cell);
if (index == lastIndex +1)
{
lastIndex = index;
columns++;
}
}
}
while (cell);
return columns;
}
function EditorOnFocus()
{
// Current window already has the InsertCharWindow

View File

@ -53,7 +53,8 @@
prefattribute="value"/>
<spring flex="1"/>
</box>
</box>
</vbox>
<spring class="smallspacer"/>
<titledbox orient="vertical" autostretch="never">
<label value="&pageColorHeader;"/>
<radiogroup id="useCustomColors" orient="vertical" autostretch="never"
@ -146,7 +147,7 @@
<spring flex="1"/>
<text class="label larger" id="VisitedLinkText" value="&visitedLinkText.label;"/>
<spring flex="1"/>
</box>
</vbox>
<spring flex="1"/>
</box>
<spring class="spacer"/>