From fb204e8246c39dc51669cda60ac8c2f27e605c91 Mon Sep 17 00:00:00 2001 From: "cmanske%netscape.com" Date: Tue, 7 Sep 1999 23:49:46 +0000 Subject: [PATCH] Adding Advanced Property Editing dialog work by Ben Goodger (rgoodger@ihug.co.nz) --- editor/ui/dialogs/content/EdAdvancedEdit.js | 177 +++++++++++++++--- editor/ui/dialogs/content/EdAdvancedEdit.xul | 86 ++++++--- editor/ui/dialogs/content/EdDialogCommon.js | 3 +- editor/ui/dialogs/content/EdMessage.js | 3 + .../ui/dialogs/content/EdNamedAnchorProps.js | 4 +- editor/ui/dialogs/content/EdTableProps.js | 35 ++-- editor/ui/dialogs/content/EdTableProps.xul | 2 +- .../dialogs/locale/en-US/EdAdvancedEdit.dtd | 13 +- editor/ui/dialogs/skin/EditorDialog.css | 106 +++++++++-- 9 files changed, 334 insertions(+), 95 deletions(-) diff --git a/editor/ui/dialogs/content/EdAdvancedEdit.js b/editor/ui/dialogs/content/EdAdvancedEdit.js index 162a80ae5e9..621af32fdf4 100644 --- a/editor/ui/dialogs/content/EdAdvancedEdit.js +++ b/editor/ui/dialogs/content/EdAdvancedEdit.js @@ -18,6 +18,7 @@ * Rights Reserved. * * Contributor(s): + * Ben Goodger */ @@ -25,10 +26,12 @@ // Note: This dialog var tagname; var element; +var elAttrs = new Array(); // dialog initialization code function Startup() { + dump("START DLG\n"); // This is the return value for the parent, // who only needs to know if OK was clicked window.opener.AdvancedEditOK = false; @@ -46,53 +49,173 @@ function Startup() } dump("*** Element passed into Advanced Edit: "+element+" ***\n"); - // Append tagname of element we are editing after the message text - // above the attribute editing treewidget - var msgParent = document.getElementById("AttributeMsgParent"); - - // Remove temporary place holder text: - // TODO: REMOVE THIS WHEN WE CAN RESIZE DIALOG AFTER CREATION - msgParent.removeChild(msgParent.firstChild); - - var msg = GetString("AttributesFor"); - dump("Tagname Msg = "+msg+"\n"); - msg +=(" "+element.nodeName); - dump("Tagname Msg = "+msg+"\n"); - - textNode = editorShell.editorDocument.createTextNode(msg); - if (textNode) { - msgParent.appendChild(textNode); + var tagLabel = document.getElementById("tagLabel"); + if(tagLabel.hasChildNodes()) { + tagLabel.removeChild(tagLabel.firstChild); } + var textLabel = document.createTextNode("<" + element.nodeName + ">"); + tagLabel.appendChild(textLabel); // Create dialog object to store controls for easy access dialog = new Object; dialog.AddAttributeNameInput = document.getElementById("AddAttributeNameInput"); - //TODO: We should disable this button if the AddAttributeNameInput editbox is empty + dialog.AddAttributeValueInput = document.getElementById("AddAttributeValueInput"); dialog.AddAttribute = document.getElementById("AddAttribute"); - //TODO: Get the list of attribute nodes, - // read each one, and use to build a text + editbox - // in a treewidget row for each attribute + // build an attribute tree + BuildAttributeTable(); + window.sizeToContent(); +} + +// build attribute list in tree form from element attributes +function BuildAttributeTable() +{ + dump("NODENAME: " + element.nodeName + "\n"); var nodeMap = element.attributes; var nodeMapCount = nodeMap.length; + var treekids = document.getElementById("attributelist"); - // SET FOCUS TO FIRST CONTROL + if(nodeMapCount > 0) { + for(i = 0; i < nodeMapCount; i++) + { + if(!CheckAttributeNameSimilarity(nodeMap[i].nodeName)) { + dump("repeated attribute!\n"); + continue; // repeated attribute, ignore this one and go to next + } + elAttrs[i] = nodeMap[i].nodeName; + var treeitem = document.createElement("treeitem"); + var treerow = document.createElement("treerow"); + var attrcell = document.createElement("treecell"); + var attrcontent = document.createTextNode(nodeMap[i].nodeName.toUpperCase()); + attrcell.appendChild(attrcontent); + treerow.appendChild(attrcell); + var valcell = document.createElement("treecell"); + valcell.setAttribute("class","value"); + var valField = document.createElement("html:input"); + var attrValue = element.getAttribute(nodeMap[i].nodeName); + valField.setAttribute("type","text"); + valField.setAttribute("id",nodeMap[i].nodeName.toLowerCase()); + valField.setAttribute("value",attrValue); + valField.setAttribute("flex","100%"); + valField.setAttribute("class","AttributesCell"); + valcell.appendChild(valField); + treerow.appendChild(valcell); + treeitem.appendChild(treerow); + treekids.appendChild(treeitem); + } + } } +// add an attribute to the tree widget function onAddAttribute() { - var name = dialog.AddAttributeNameInput.value; + //var name = TrimString(dialog.AddAttributeNameInput.value); + name = dialog.AddAttributeNameInput.value; + var value = TrimString(dialog.AddAttributeValueInput.value); + + // Must have a name to be able to add (Value may be empty) + if(name == "") + return; + + // WHAT'S GOING ON? NAME ALWAYS HAS A VALUE OF accented "a"??? + dump(name+"= New Attribute Name - SHOULD BE EMPTY\n"); + + + elAttrs[elAttrs.length] = name; + // TODO: Add a new text + editbox to the treewidget editing list + var treekids = document.getElementById("attributelist"); + var treeitem = document.createElement("treeitem"); + var treerow = document.createElement("treerow"); + var attrcell = document.createElement("treecell"); + var attrcontent = document.createTextNode(name.toUpperCase()); + attrcell.appendChild(attrcontent); + treerow.appendChild(attrcell); + var valcell = document.createElement("treecell"); + valcell.setAttribute("class","value"); + var valField = document.createElement("html:input"); + valField.setAttribute("type","text"); + valField.setAttribute("id",name); + valField.setAttribute("value",value); + valField.setAttribute("flex","100%"); + valField.setAttribute("class","AttributesCell"); + valcell.appendChild(valField); + treerow.appendChild(valcell); + treeitem.appendChild(treerow); + treekids.appendChild(treeitem); + dialog.AddAttributeNameInput.value = ""; + dialog.AddAttributeValueInput.value = ""; + + // Set focus to the value edit field just added: + valField.focus(); + + //Clear the edit boxes + dialog.AddAttributeNameInput.value = ""; + dialog.AddAttributeValueInput.value = ""; } - +// shut the dialog, apply changes and tidy up function onOK() { - //TODO: Get all children of the treewidget to get all - // name, value strings for all attributes. - // Set those attributes on "element" we are editing. - + UpdateObject(); // call UpdateObject fn to update element in document window.opener.AdvancedEditOK = true; + window.opener.globalElement = element; return true; // do close the window } + +// updates the element object with values set in the tree. +// TODO: make this work for many objects, so the "vicinity diagram" +// can be used. +function UpdateObject() +{ + var treekids = document.getElementById("attributelist"); + for(i = 0; i < treekids.childNodes.length; i++) + { + var item = treekids.childNodes[i]; + var name = item.firstChild.firstChild.firstChild.nodeValue; + var value = TrimString(item.firstChild.lastChild.firstChild.value); + element.setAttribute(name,value); + } +} + +// checks to see if any other attributes by the same name as the arg supplied +// already exist. +function CheckAttributeNameSimilarity(attName) +{ + for(i = 0; i < elAttrs.length; i++) + { + if(attName == elAttrs[i]) + return false; + } + return true; +} + +// does enabling based on any user input. +function doOverallEnabling() +{ + var name = TrimString(dialog.AddAttributeNameInput.value); + if( name == "" || !CheckAttributeNameSimilarity(name)) { + dialog.AddAttribute.setAttribute("disabled","true"); + } else { + dialog.AddAttribute.removeAttribute("disabled"); + } +} + +function doSort() +{ +/* UpdateObject(); + var treekids = document.getElementById("attributelist"); + var nameArray = [] + for(i = 0; i < treekids.childNodes.length; i++) + { + var item = treekids.childNodes[i]; + nameArray[i] = item.firstChild.firstChild.firstChild.nodeValue; + } + nameArray.sort(posval); + dump("nameArray: " + nameArray + "\n"); + nameArray.sort(negval); + dump("nameArray: " + nameArray + "\n"); +*/ +} + diff --git a/editor/ui/dialogs/content/EdAdvancedEdit.xul b/editor/ui/dialogs/content/EdAdvancedEdit.xul index ebf26c7a3c2..cc2e777d581 100644 --- a/editor/ui/dialogs/content/EdAdvancedEdit.xul +++ b/editor/ui/dialogs/content/EdAdvancedEdit.xul @@ -19,49 +19,73 @@ - Rights Reserved. - - Contributor(s): + - Ben Goodger --> - + - - - - -