the best way to bring JSON and UI together
Hello again,
JSON is good for saving presets. However, I am looking for an easy way to bring JSON and the UI variables together.
My project: I have over 50 JSON entries in a javascript project for Illustrator that need to be loaded, changed and saved again in a UI.
It is very annoying to have to call a function like 'function fJSON2UI()' every time a change is made, which transfers the values from JSON to the variables for the UI and back again.
The wish: It would be simpler if I could write in the UI:
JO.uiFile = gInput1.add ("statictext", undefined, "(no file)"); But this does not work.
QUESTION: Is there a trick or shortcut to connect the JSON and the variables of the UI more easily?
Part of my Javascript:
var vJSON = {
uiFile: "~/Desktop/"
};
var w = new Window ('dialog {text: "Preferences", orientation: "column", alignChildren:["fill","fill"], properties: {closeButton: false}}');
gInput1 = w.add ('group {orientation: "row"}'); gInput1.alignment = "left";
bInput1 = gInput1.add ("button", undefined, "Load");
vInput1 = gInput1.add ("statictext", undefined, "(no file)"); vInput1.characters = 40;
bInput2 = gInput1.add ("button", undefined, "Save");
bInput1.onClick = function () {
vResult = File.openDialog( "Select a JSON-file:", "JSON:*.json" );
if (vResult != null) { vInput1.text = vResult; fReadJSON(vResult);
fJSON2UI();
}
else { vInput1.text = "(keine Datei gewählt)"; vResult = null; }
bInput1.active = false; // reset button
} // end of bInput1.onClick function ()
bInput2.onClick = function () {
if (vInput1.text != "(keine Datei gewählt)") {
vFile = new File(vResult); vResultSave = vFile.saveDlg( "Save as JSON-file:", "JSON:*.json" ); }
else { vResultSave = File.saveDialog( "Save as JSON-file:", "JSON:*.json" ); }
if (vResultSave != null) { vInput1.text = vResultSave; fWriteJSON(vResultSave);
fUI2JSON();
}
bInput2.active = false; // reset button
} // end of bInput2.onClick function ()
w.show();
function fReadJSON(pFile){ } // read the JSON file
function fWriteJSON(pFile){ } // write the JSON file
function fJSON2UI() {
vInput1.text = vJSON.uiFile; // and 49 variables more
}
function fUI2JSON() {
vJSON.uiFile = vInput1.text; // and 49 variables more
}Looking forward to your help,
– j.
