Chuck Uebele, thank you for your attention and for the instructions! By following each step, as far as I was about my little knowledge, the most I could do was to save the default DropdownList and all values in xmlTest.xml, but when I click the "+" button to add a new one, it does not load the values last saved preset, always loads the initial values. Is it where I'm going wrong? Here is the final script: var startNodes = new XML('<root><presets/></root>'); var prefXML = new XML();var presetList = new Array( ); var saveName; var xmlFile = new File('~/Desktop/xmlTest.xml'); if(xmlFile.exists){ prefXML = new XML(readXMLFile(xmlFile))}; else {prefXML = startNodes} ///////////////// MAIN WINDOW 1 /////////////////////////// DlgMain = new Window("dialog"); DlgMain.text = "XML Test Parte II"; DlgMain.orientation = "column"; DlgMain.alignChildren = ["center","top"]; group1 = DlgMain.add("group"); group1.orientation = "row"; panel1 = group1.add("panel"); panel1.text = "My presets"; panel1.orientation = "row"; presetListDrop = panel1.add("dropdownlist", undefined, ["No Presets"]); presetListDrop.selection = 0; presetListDrop.text = "Presets"; presetListDrop.preferredSize.width = 200; saveP = panel1.add("button"); saveP.text = "+"; saveP.preferredSize.width = 20; saveP.preferredSize.height = 20; deleteP = panel1.add("button"); deleteP.text = "-"; deleteP.preferredSize.width = 20; deleteP.preferredSize.height = 20; myOkButton = DlgMain.add("button"); myOkButton.text = "Close"; myOkButton.preferredSize.width = 80; myOkButton.preferredSize.height = 23; myOkButton.onClick = function(){DlgMain.close()}; //////////////////////////////////////////// /// The create button or Save preset saveP.onClick = function(){ SavePresets () } ////////////////////////////////////////// /////////////////////////////////////////// deleteP.onClick = function(){ if(isNaN(parseInt(presetListDrop.selection))){alert('You must select a preset to delete first')} else{ var delPre = confirm ('Do you want to delete the preset "' + presetListDrop.selection.text +'"?', 'Yes', 'Delete Preset') if(delPre){ delete prefXML.presets.preset[parseInt(presetListDrop.selection)]; setPresetList(); writeXMLFile(xmlFile,prefXML); presetListDrop.selection = 0 }} } if(prefXML.presets.children().length()>0){setPresetList(); setUIvar(prefXML,0, DlgMain)} DlgMain.show(); /////////////////////////////////////////////////////////////////////////////////////// ///////////////// ALL CONTROLS WINDOW 2 /////////////////////////// function SavePresets (){ DlgControls = new Window("dialog"); DlgControls.text = "Dialog Controls"; DlgControls.orientation = "column"; group1 = DlgControls.add("group"); group1.orientation = "row"; group1.spacing = 0 Presets = group1.add("statictext"); Presets.text = " Presets"; saveName = group1.add("edittext"); saveName.text = ["No Presets"]; saveName.preferredSize.width =100; saveName.alignment = ["center","top"]; panel1 = DlgControls.add("panel"); panel1.text = "Controls"; panel1.orientation = "column"; panel1.alignChildren = ["left","top"]; myCheckBox = panel1.add("checkbox"); myCheckBox.text = "Check "; myCheckBox.name="myCheckBox"; myCheckBox.alignment = ["center","top"]; myCheckBox.value = true; myRadio1 = panel1.add("radiobutton"); myRadio1.text = "Radio1"; myRadio1.name="myRadio2"; myRadio1.alignment = ["center","top"]; myRadio1.value = true; myRadio2 = panel1.add("radiobutton"); myRadio2.text = "Radio2"; myRadio2.name="myRadio2"; myRadio2.alignment = ["center","top"]; divider1 = panel1.add("panel"); divider1.alignment = "fill"; myEditT = panel1.add("edittext"); myEditT.text = "EditText"; myEditT.name="myEditT"; myEditT.alignment = ["center","top"]; myDropList_array = ["Item 1","Item 2","Item 3"]; myDropList = panel1.add("dropdownlist", undefined, myDropList_array); myDropList.name="myDropList"; myDropList.selection = 1; myDropList.alignment = ["center","top"]; divider2 = panel1.add("panel"); divider2.alignment = "fill"; mySlider = panel1.add("slider"); mySlider.name="mySlider"; mySlider.minvalue = 0; mySlider.maxvalue = 100; mySlider.value = 50; Done = DlgControls.add("button"); Done.text = "Save / Done"; Done.preferredSize.width = 80; ////////////////////////////////////////////////////////////////////////////////// //// save this information to the XML by doing a Done or Save button Done.onClick = function(){ var goodName = true; saveName = saveName.text for(var i=0;i<presetListDrop.items.length;i++){ if(presetListDrop.items.text==saveName){ goodName = false; alert(saveName +' is already in use. Choose another name.') } } if(saveName && goodName){ storePrefs(); presetListDrop.selection = presetListDrop.items.length -1} DlgControls.close(); } /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// DlgControls.show(); } ///////////////////////////////////////////////////// function storePrefs(){ var tempXML tempXML = new XML('<root><presets><preset presetName ="' + saveName + '"/></presets></root>'); setXML(tempXML,0, DlgControls); prefXML.presets.appendChild (XML(tempXML.presets.preset[0])) ////// Changed line setXML(tempXML,0, dlg) to setXML(tempXML,0, DlgControls); ////////////////////////////// setPresetList(); writeXMLFile(xmlFile,prefXML); }; function setXML(x,n,d){ for(var i = 0;i<d.children.length;i++){ if(d.children.type == 'panel' || d.children.type == 'group' || d.children.type == 'tabbedpanel' || d.children.type == 'tab'){setXML(x,n,d.children)} else{ if(d.children.name){ switch(d.children.type){ case 'radiobutton': x.presets.child(n).appendChild(XML('<' + d.children.name +' type="' + d.children.type + '">' + d.children.value + '</' + d.children.name + '>')); break; case 'checkbox': x.presets.child(n).appendChild(XML('<' + d.children.name +' type="' + d.children.type + '">' + d.children.value + '</' + d.children.name + '>')); break; case 'slider': x.presets.child(n).appendChild(XML('<' + d.children.name +' type="' + d.children.type + '">' + d.children.value + '</' + d.children.name + '>')); break; case 'edittext': x.presets.child(n).appendChild(XML('<' + d.children.name +' type="' + d.children.type + '"><![CDATA[' + d.children.text + ']]\></' + d.children.name + '>')); break; case 'dropdownlist': if(d.children.selection){varHold = d.children.selection.text} else{varHold = 'null'}; x.presets.child(n).appendChild(XML('<' + d.children.name +' selecIndex="' + d.children.selection + '" type="' + d.children.type + '"><![CDATA[' + varHold + ']]\></' + d.children.name + '>')); break; }}}} } function setUIvar(x,n,d){ var currentXMLVal; var noMatch = false for(var i = 0;i<d.children.length;i++){ noMatch = false; if(d.children.type == 'panel' || d.children.type == 'group' || d.children.type == 'tab' || d.children.type == 'tabbedpanel'){setUIvar(x,n,d.children)};//reruns function if child is container and not control item. else{if(d.children.name){try{ currentXMLVal = x.presets.preset .child(d.children.name); if(currentXMLVal == 'null'){currentXMLVal = null}} catch(e){currentXMLVal = 'no_good'}; if(x.presets.preset .child(d.children.name).length() > 0 || d.children.type == 'button'){ switch(d.children.type){ case 'radiobutton': d.children.value = returnBoolean(currentXMLVal); break; case 'checkbox': d.children.value = returnBoolean(currentXMLVal); break; case 'edittext': d.children.text = currentXMLVal; break; case 'slider': d.children.value = parseFloat(currentXMLVal); break; case 'dropdownlist': varHold = false; if(x.presets.preset .child(d.children.name).@selecIndex.toString() == 'null'){d.children.selection = null} else{d.children.selection = parseInt(x.presets.preset .child(d.children.name).@selecIndex)}; break; }}}}} } function returnBoolean(b){ if(b == 'true'){return true}; else{return false}} function setPresetList(){ presetList = new Array(); presetListDrop.removeAll(); for(var i=0;i<prefXML.presets.children().length();i++){presetListDrop.add('item',prefXML.presets.children().@presetName)} } function readXMLFile(file) { if (!file.exists) { alert( "Cannot find file: " + deodeURI(file.absoluteURI))} else{ file.encoding = "UTF8"; file.lineFeed = "unix"; file.open("r", "TEXT", "????"); var str = file.read(); file.close(); return new XML(str)}; } function writeXMLFile(file, xml) { file.encoding = "UTF8"; file.open("w", "TEXT", "????"); file.write("\uFEFF"); file.lineFeed = "unix"; if (!(xml instanceof XML)) { for(var g=0;g<scriptArray.length;g++){ try{file.writeln (scriptArray .toString())} catch(e){}}} else{file.write(xml.toXMLString())}; file.close(); }
... View more