Fixed object properties bug 39649, including moving methods involved (without change) from ComposerCommands.js to editor.js as suggested by sfraser. r=sfraser

This commit is contained in:
cmanske%netscape.com 2000-05-25 03:35:33 +00:00
Родитель cfd081d255
Коммит bb37359bbe
11 изменённых файлов: 288 добавлений и 260 удалений

Просмотреть файл

@ -32,7 +32,13 @@ a:link, a:visited, a:active, a:out-of-date {
cursor: text;
}
/* We want the default arrow when hover over the
various objects, such as the image that
represents the named anchor
*/
a:link img, a:visited img, a:active img,
a:out-of-date img, img[usemap], object[usemap] {
a:out-of-date img, img[usemap],
object[usemap],
a[name] {
cursor: default;
}

Просмотреть файл

@ -58,6 +58,7 @@ function SetupControllerCommands()
gComposerCommandManager.registerCommand("cmd_pageProperties", nsPagePropertiesCommand);
gComposerCommandManager.registerCommand("cmd_colorProperties", nsColorPropertiesCommand);
gComposerCommandManager.registerCommand("cmd_advancedProperties", nsAdvancedPropertiesCommand);
gComposerCommandManager.registerCommand("cmd_objectProperties", nsObjectPropertiesCommand);
gComposerCommandManager.registerCommand("cmd_image", nsImageCommand);
gComposerCommandManager.registerCommand("cmd_hline", nsHLineCommand);
@ -535,45 +536,6 @@ var nsHLineCommand =
}
};
//-----------------------------------------------------------------------------------
// Launch Object properties for appropriate selected element
function EditorObjectProperties()
{
var element = GetSelectedElementOrParentCell();
// dump("EditorObjectProperties: element="+element+"\n");
if (element)
{
// dump("TagName="+element.nodeName+"\n");
switch (element.nodeName)
{
case 'IMG':
goDoCommand("cmd_image");
break;
case 'HR':
goDoCommand("cmd_hline");
break;
case 'TABLE':
EditorInsertOrEditTable(false);
break;
case 'TD':
EditorTableCellProperties();
break;
case 'A':
if(element.href)
goDoCommand("cmd_link");
else if (element.name)
goDoCommand("cmd_anchor");
break;
}
} else {
// We get a partially-selected link if asked for specifically
element = editorShell.GetSelectedElement("href");
if (element)
goDoCommand("cmd_link");
}
}
//-----------------------------------------------------------------------------------
var nsLinkCommand =
{
@ -680,7 +642,67 @@ var nsPagePropertiesCommand =
};
//-----------------------------------------------------------------------------------
var nsObjectPropertiesCommand =
{
isCommandEnabled: function(aCommand, dummy)
{
if (window.editorShell && window.editorShell.documentEditable)
{
// Launch Object properties for appropriate selected element
var element = GetSelectedElementOrParentCell();
//dump("nsObjectProperties, isCommandEnabled: element="+element+",TagName="+element.nodeName+"\n");
return (element &&
(element.nodeName == "img" ||
element.nodeName == "hr" ||
element.nodeName == "table" ||
element.nodeName == "td" ||
element.nodeName == "a" ||
editorShell.GetSelectedElement("href")));
}
return false;
},
doCommand: function(aCommand)
{
// Launch Object properties for appropriate selected element
var element = GetSelectedElementOrParentCell();
if (element)
{
switch (element.nodeName)
{
case 'img':
goDoCommand("cmd_image");
break;
case 'hr':
goDoCommand("cmd_hline");
break;
case 'table':
EditorInsertOrEditTable(false);
break;
case 'td':
EditorTableCellProperties();
break;
case 'a':
if (element.name)
{
goDoCommand("cmd_anchor");
}
else if(element.href)
{
goDoCommand("cmd_link");
}
break;
}
} else {
// We get a partially-selected link if asked for specifically
element = editorShell.GetSelectedElement("href");
if (element)
goDoCommand("cmd_link");
}
window.content.focus();
}
};
//-----------------------------------------------------------------------------------
var nsAdvancedPropertiesCommand =
{
isCommandEnabled: function(aCommand, dummy)
@ -721,173 +743,15 @@ var nsEditHTMLCommand =
{
if (gEditorDisplayMode === DisplayModeSource)
{
dump(" *** Switch back to HTML Source mode\n");
SetEditMode(DisplayModeNormal);
}
else
{
dump(" *** Switch back to NORMAL\n");
SetEditMode(DisplayModeSource);
}
}
};
//-----------------------------------------------------------------------------------
// TABLE EDITING COMMANDS
// Command Updating Strategy:
// Don't update on on selection change, only when menu is displayed,
// with this "oncreate" hander:
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;
// Use "Join selected cells if there's more than 1 cell selected
var tagNameObj = new Object;
var countObj = new Object;
if (window.editorShell.GetSelectedOrParentTableElement(tagNameObj, countObj) && countObj.value > 1)
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);
// Set enable states for all table commands
goUpdateTableMenuItems(document.getElementById("composerTableMenuItems"));
}
function goUpdateTableMenuItems(commandset)
{
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)
{
// Value when we need to have a selected table or inside a table
enabledIfTable = true;
// All others require being inside a cell or selected cell
enabled = (tagNameObj.value == "td");
}
}
// Loop through command nodes
for (var i = 0; i < commandset.childNodes.length; i++)
{
var commandID = commandset.childNodes[i].getAttribute("id");
if (commandID)
{
if (commandID == "cmd_InsertTable" ||
commandID == "cmd_tableJoinCells" ||
commandID == "cmd_tableSplitCell")
{
// Call the update method in the command class
goUpdateCommand(commandID);
}
// Directly set with the values calculated here
else if (commandID == "cmd_DeleteTable" ||
commandID == "cmd_NormalizeTable")
{
goSetCommandEnabled(commandID, enabledIfTable);
} else {
goSetCommandEnabled(commandID, enabled);
}
}
}
}
//-----------------------------------------------------------------------------------
// Helpers for inserting and editing tables:
function IsInTable()
{
return (window.editorShell && window.editorShell.documentEditable &&
null != window.editorShell.GetElementOrParentByTagName("table", null));
}
function IsInTableCell()
{
return (window.editorShell && window.editorShell.documentEditable &&
null != window.editorShell.GetElementOrParentByTagName("td", null));
}
function IsSelectionInOneCell()
{
var selection = window.editorShell.editorSelection;
if (selection && selection.rangeCount == 1)
{
// We have a "normal" single-range selection
if (!selection.isCollapsed &&
selection.anchorNode != selection.focusNode)
{
// Check if both nodes are within the same cell
var anchorCell = window.editorShell.GetElementOrParentByTagName("td", selection.anchorNode);
var focusCell = window.editorShell.GetElementOrParentByTagName("td", selection.focusNode);
return (focusCell != null && anchorCell != null && (focusCell == anchorCell));
}
// Collapsed selection or anchor == focus (thus must be in 1 cell)
return true;
}
return false;
}
// Call this with insertAllowed = true to allow inserting if not in existing table,
// else use false to do nothing if not in a table
function EditorInsertOrEditTable(insertAllowed)
{
if (IsInTable()) {
// Edit properties of existing table
window.openDialog("chrome://editor/content/EdTableProps.xul", "_blank", "chrome,close,titlebar,modal", "","TablePanel");
window.content.focus();
} else if(insertAllowed) {
EditorInsertTable();
}
}
function EditorInsertTable()
{
dump("EditorInsertTable\n");
// Insert a new table
window.openDialog("chrome://editor/content/EdInsertTable.xul", "_blank", "chrome,close,titlebar,modal", "");
window.content.focus();
}
function EditorTableCellProperties()
{
var cell = editorShell.GetElementOrParentByTagName("td", null);
if (cell) {
// Start Table Properties dialog on the "Cell" panel
window.openDialog("chrome://editor/content/EdTableProps.xul", "_blank", "chrome,close,titlebar,modal", "", "CellPanel");
window.content.focus();
}
}
//-----------------------------------------------------------------------------------
var nsInsertOrEditTableCommand =
{

Просмотреть файл

@ -62,7 +62,7 @@
<menuitem id="objectProperties" value="&properties.label;"
accesskey="&properties.accesskey;"
oncommand="EditorObjectProperties()"/>
observes="cmd_objectProperties"/>
<menu id="tableMenu" value="&tableMenu.label;" accesskey="&tablemenu.accesskey;">
<menupopup oncreate="EditorInitTableMenu()">

Просмотреть файл

@ -53,11 +53,3 @@ table[border="0"] * td, table[border="0"] * th {
border: 1px dotted red;
}
/* For ease in caret placement,
have a minimum cell width
BUG - DOESN'T WORK!
Note: Setting "width" works
*/
td, th {
min-width: 10px;
}

Просмотреть файл

@ -64,8 +64,7 @@
<menuitem id="tableProperties_cm" value="&tableProperties.label;"/>
<menuseparator id="tableMenu-separator"/>
<menuitem id="objectProperties_cm" value="&properties.label;"
oncommand="EditorObjectProperties()"/>
<menuitem id="objectProperties_cm" value="&properties.label;" observes="cmd_objectProperties"/>
</popup>
</popupset>

Просмотреть файл

@ -32,7 +32,13 @@ a:link, a:visited, a:active, a:out-of-date {
cursor: text;
}
/* We want the default arrow when hover over the
various objects, such as the image that
represents the named anchor
*/
a:link img, a:visited img, a:active img,
a:out-of-date img, img[usemap], object[usemap] {
a:out-of-date img, img[usemap],
object[usemap],
a[name] {
cursor: default;
}

Просмотреть файл

@ -439,6 +439,8 @@ function onParagraphFormatChange(paraMenuList, commandID)
{
var commandNode = document.getElementById(commandID);
var state = commandNode.getAttribute("state");
var menuList = document.getElementById("ParagraphSelect");
if (!menuList) return;
dump("Updating font face with " + state + "\n");
@ -450,7 +452,7 @@ function onParagraphFormatChange(paraMenuList, commandID)
{
//Selection is the "mixed" ( > 1 style) state
paraMenuList.selectedItem = null;
paraMenuList.setAttribute("value",GetString('MixedFormats'));
paraMenuList.setAttribute("value",GetString('Mixed'));
}
else
{
@ -488,7 +490,7 @@ function onFontFaceChange(fontFaceMenuList, commandID)
{
//Selection is the "mixed" ( > 1 style) state
fontFaceMenuList.selectedItem = null;
fontFaceMenuList.setAttribute("value",GetString('MixedFormats'));
fontFaceMenuList.setAttribute("value",GetString('Mixed'));
}
else
{
@ -915,32 +917,6 @@ function EditorToggleParagraphMarks()
}
}
function SetBackColorString(xulElementID)
{
var xulElement = document.getElementById(xulElementID);
if (xulElement)
{
var textVal;
var selectedCountObj = new Object();
var tagNameObj = new Object();
var element = editorShell.GetSelectedOrParentTableElement(tagNameObj, selectedCountObj);
if (tagNameObj.value == "table")
textVal = GetString("TableBackColor");
else if (tagNameObj.value == "td")
textVal = GetString("CellBackColor");
else
textVal = GetString("PageBackColor");
xulElement.setAttribute("value",textVal);
}
}
function InitBackColorPopup()
{
SetBackColorString("BackColorCaption");
}
function EditorInitEditMenu()
{
var DelStr = GetString(gIsMac ? "Clear" : "Delete");
@ -981,6 +957,9 @@ function EditorInitFormatMenu()
// Set the string for the background color menu item
SetBackColorString("backgroundColorMenu");
// Set strings and enable for the [Object] Properties item
// Note that we directly do the enabling instead of
// using goSetCommandEnabled since we already have the menuitem
var menuItem = document.getElementById("objectProperties");
if (menuItem)
{
@ -992,23 +971,23 @@ function EditorInitFormatMenu()
menuItem.removeAttribute("disabled");
switch (element.nodeName)
{
case 'IMG':
case 'img':
objStr = GetString("Image");
break;
case 'HR':
case 'hr':
objStr = GetString("HLine");
break;
case 'TABLE':
case 'table':
objStr = GetString("Table");
break;
case 'TD':
case 'td':
objStr = GetString("TableCell");
break;
case 'A':
if(element.href)
objStr = GetString("Link");
else if (element.name)
case 'a':
if (element.name)
objStr = GetString("NamedAnchor");
else if(element.href)
objStr = GetString("Link");
break;
}
menuStr = menuStr.replace(/%obj%/,objStr);
@ -1025,6 +1004,32 @@ function EditorInitFormatMenu()
}
}
function SetBackColorString(xulElementID)
{
var xulElement = document.getElementById(xulElementID);
if (xulElement)
{
var textVal;
var selectedCountObj = new Object();
var tagNameObj = new Object();
var element = editorShell.GetSelectedOrParentTableElement(tagNameObj, selectedCountObj);
if (tagNameObj.value == "table")
textVal = GetString("TableBackColor");
else if (tagNameObj.value == "td")
textVal = GetString("CellBackColor");
else
textVal = GetString("PageBackColor");
xulElement.setAttribute("value",textVal);
}
}
function InitBackColorPopup()
{
SetBackColorString("BackColorCaption");
}
function EditorInitToolbars()
{
// Nothing to do now, but we might want some state updating here
@ -1452,3 +1457,158 @@ function GetPrefsService()
dump("failed to get prefs service!\n");
}
}
// Command Updating Strategy:
// Don't update on on selection change, only when menu is displayed,
// with this "oncreate" hander:
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;
// Use "Join selected cells if there's more than 1 cell selected
var tagNameObj = new Object;
var countObj = new Object;
if (window.editorShell.GetSelectedOrParentTableElement(tagNameObj, countObj) && countObj.value > 1)
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);
// Set enable states for all table commands
goUpdateTableMenuItems(document.getElementById("composerTableMenuItems"));
}
function goUpdateTableMenuItems(commandset)
{
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)
{
// Value when we need to have a selected table or inside a table
enabledIfTable = true;
// All others require being inside a cell or selected cell
enabled = (tagNameObj.value == "td");
}
}
// Loop through command nodes
for (var i = 0; i < commandset.childNodes.length; i++)
{
var commandID = commandset.childNodes[i].getAttribute("id");
if (commandID)
{
if (commandID == "cmd_InsertTable" ||
commandID == "cmd_tableJoinCells" ||
commandID == "cmd_tableSplitCell")
{
// Call the update method in the command class
goUpdateCommand(commandID);
}
// Directly set with the values calculated here
else if (commandID == "cmd_DeleteTable" ||
commandID == "cmd_NormalizeTable")
{
goSetCommandEnabled(commandID, enabledIfTable);
} else {
goSetCommandEnabled(commandID, enabled);
}
}
}
}
//-----------------------------------------------------------------------------------
// Helpers for inserting and editing tables:
function IsInTable()
{
return (window.editorShell && window.editorShell.documentEditable &&
null != window.editorShell.GetElementOrParentByTagName("table", null));
}
function IsInTableCell()
{
return (window.editorShell && window.editorShell.documentEditable &&
null != window.editorShell.GetElementOrParentByTagName("td", null));
}
function IsSelectionInOneCell()
{
var selection = window.editorShell.editorSelection;
if (selection && selection.rangeCount == 1)
{
// We have a "normal" single-range selection
if (!selection.isCollapsed &&
selection.anchorNode != selection.focusNode)
{
// Check if both nodes are within the same cell
var anchorCell = window.editorShell.GetElementOrParentByTagName("td", selection.anchorNode);
var focusCell = window.editorShell.GetElementOrParentByTagName("td", selection.focusNode);
return (focusCell != null && anchorCell != null && (focusCell == anchorCell));
}
// Collapsed selection or anchor == focus (thus must be in 1 cell)
return true;
}
return false;
}
// Call this with insertAllowed = true to allow inserting if not in existing table,
// else use false to do nothing if not in a table
function EditorInsertOrEditTable(insertAllowed)
{
if (IsInTable()) {
// Edit properties of existing table
window.openDialog("chrome://editor/content/EdTableProps.xul", "_blank", "chrome,close,titlebar,modal", "","TablePanel");
window.content.focus();
} else if(insertAllowed) {
EditorInsertTable();
}
}
function EditorInsertTable()
{
dump("EditorInsertTable\n");
// Insert a new table
window.openDialog("chrome://editor/content/EdInsertTable.xul", "_blank", "chrome,close,titlebar,modal", "");
window.content.focus();
}
function EditorTableCellProperties()
{
var cell = editorShell.GetElementOrParentByTagName("td", null);
if (cell) {
// Start Table Properties dialog on the "Cell" panel
window.openDialog("chrome://editor/content/EdTableProps.xul", "_blank", "chrome,close,titlebar,modal", "", "CellPanel");
window.content.focus();
}
}

Просмотреть файл

@ -100,17 +100,18 @@
<command id="cmd_pageProperties" oncommand="goDoCommand('cmd_pageProperties')"/>
<command id="cmd_colorProperties" oncommand="goDoCommand('cmd_colorProperties')"/>
<command id="cmd_link" oncommand="goDoCommand('cmd_link')"/>
<command id="cmd_anchor" oncommand="goDoCommand('cmd_anchor')"/>
<command id="cmd_image" oncommand="goDoCommand('cmd_image')"/>
<command id="cmd_hline" oncommand="goDoCommand('cmd_hline')"/>
<command id="cmd_table" oncommand="goDoCommand('cmd_table')"/>
<command id="cmd_insertChars" oncommand="goDoCommand('cmd_insertChars')" value="&insertCharsCmd.label;"/>
<command id="cmd_link" oncommand="goDoCommand('cmd_link')"/>
<command id="cmd_anchor" oncommand="goDoCommand('cmd_anchor')"/>
<command id="cmd_image" oncommand="goDoCommand('cmd_image')"/>
<command id="cmd_hline" oncommand="goDoCommand('cmd_hline')"/>
<command id="cmd_table" oncommand="goDoCommand('cmd_table')"/>
<command id="cmd_objectProperties" oncommand="goDoCommand('cmd_objectProperties')"/>
<command id="cmd_insertChars" oncommand="goDoCommand('cmd_insertChars')" value="&insertCharsCmd.label;"/>
<command id="cmd_editTable"/>
<command id="cmd_insertHTML" oncommand="goDoCommand('cmd_insertHTML')" value="&HTMLSourceCmd.label;"/>
<command id="cmd_editHTML" oncommand="goDoCommand('cmd_editHTML')" value="&HTMLSourceCmd.label;"/>
<command id="cmd_insertBreak" oncommand="goDoCommand('cmd_insertBreak')" value="&insertLineBreakCmd.label;"/>
<command id="cmd_insertBreakAll" oncommand="goDoCommand('cmd_insertBreakAll')" value="&insertBreakBelowImagesCmd.label;"/>
<command id="cmd_insertHTML" oncommand="goDoCommand('cmd_insertHTML')" value="&HTMLSourceCmd.label;"/>
<command id="cmd_editHTML" oncommand="goDoCommand('cmd_editHTML')" value="&HTMLSourceCmd.label;"/>
<command id="cmd_insertBreak" oncommand="goDoCommand('cmd_insertBreak')" value="&insertLineBreakCmd.label;"/>
<command id="cmd_insertBreakAll" oncommand="goDoCommand('cmd_insertBreakAll')" value="&insertBreakBelowImagesCmd.label;"/>
</commandset>
<commandset id="composerSaveMenuItems"
@ -610,7 +611,8 @@
</menupopup>
<!-- Items to append at the bottom of the formatMenuPopup -->
<menuitem id="objectProperties" value="&properties.label;" accesskey="&properties.accesskey;" oncommand="EditorObjectProperties()"/>
<menuitem id="objectProperties" value="&properties.label;" accesskey="&properties.accesskey;"
observes="cmd_objectProperties"/>
<menuitem id="pageProperties" value="&pageProperties.label;"
accesskey="&pageproperties.accesskey;"
oncommand="goDoCommand('cmd_pageProperties')"/>

Двоичные данные
editor/ui/composer/content/images/tag-ol.gif

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 178 B

После

Ширина:  |  Высота:  |  Размер: 169 B

Двоичные данные
editor/ui/composer/content/images/tag-ul.gif

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 169 B

После

Ширина:  |  Высота:  |  Размер: 154 B

Просмотреть файл

@ -60,8 +60,7 @@ EmptyHREFError=You must enter or choose a location (URL) to create a new link.
LinkText=Link text:
LinkImage=Link image:
MixedSelection=[Mixed selection]
MixedFormats=(mixed)
MixedFonts=(mixed)
Mixed=(mixed)
EnterLinkText=Enter text to display for the link:
EmptyLinkTextError=You must enter some text for this link.
#Don't translate: %n% %min% %max%