How do you ACTUALLY close a scriptUI dialog??
I've got a UI dialog written and I included a button for "more options". This button makes available options that are rarely needed (so i didn't want them available all the time so they could accidentally be changed).
What I tried to do was have that button's onClick function close the dialog, and then re-run the function that calls the dialog and feeds it a different argument.
The problem is, when i click the more options button, it doesn't close the original dialog, it just creates a new instance on top of it. The dialog doesn't actually close until the full script finishes executing... How do I do what I'm trying to do?
Here's the function that creates my UI dialog..
function arguments are:
info = garment's information layer. this layer holds the textframes that will be altered by this dialog.
opts = whether or not to include textFrames that are typically static in nature and shouldn't be changed unless there are extenuating circumstances.
opts is set to false upon initial execution and will only be "true" after the user clicks the "more options" button in the dialog.
//firstFunction Function Description
//create a scriptUI dialog to prompt user for input of all textFrames on the info layer for the current document;
function createDialog(info,opts)
{
//create a new dialog
var title = "Enter the info for " + info.parent.name;
var w = new Window("dialog", title);
w.alignChildren = "left";
var topTxt = w.add("statictext", undefined, "Enter the appropriate information below:");
var descTxt = w.add("statictext", undefined, "Change the fields if necessary. Otherwise, leave them as they are.")
var framesAdded = [];
var frameNames = [];
//loop the textFrames and create a group for each
for(var txt = info.textFrames.length-1;txt >-1; txt --)
{
var thisFrame = info.textFrames[txt];
if(!opts && (thisFrame.name == "Garment Code" || thisFrame.name == "Garment Description" || thisFrame.name == "Fabric Type"))
{
continue;
}
else if(opts && thisFrame.name == "Fabric Type")
{
continue;
}
var newGroup = w.add("group");
if(thisFrame.name.indexOf("rder") > -1)
{
//thisFrame is the order number and team name
var onContents = thisFrame.contents.substring(0,thisFrame.contents.indexOf(" "));
var onFrameTxt = newGroup.add("statictext", undefined, "Order Number");
framesAdded["Order Number"] = newGroup.add("edittext", undefined, onContents);
framesAdded["Order Number"].characters = 20;
framesAdded["Order Number"].alignment = "right";
frameNames["Order Number"] = "Order Number";
var newNewGroup = w.add("group");
var tnContents = thisFrame.contents.substring(thisFrame.contents.indexOf(" ") +1, thisFrame.contents.length)
var tnFrameTxt = newNewGroup.add("statictext", undefined, "Team Name");
framesAdded["Team Name"] = newNewGroup.add("edittext", undefined, tnContents);
framesAdded["Team Name"].characters = 20;
frameNames["Team Name"] = "Team Name";
}
else if(thisFrame.name == "Mockup Initials")
{
var miContents = thisFrame.contents.substring(0, thisFrame.contents.indexOf(" "));
var frameTxt = newGroup.add("statictext", undefined, thisFrame.name);
framesAdded[thisFrame.name] = newGroup.add("edittext", undefined, miContents);
framesAdded[thisFrame.name].characters = 20;
frameNames[thisFrame.name] = thisFrame.name;
}
else
{
var frameTxt = newGroup.add("statictext",undefined, thisFrame.name);
framesAdded[thisFrame.name] = newGroup.add("edittext", undefined, thisFrame.contents);
framesAdded[thisFrame.name].characters = 20;
frameNames[thisFrame.name] = thisFrame.name;
}
}
//add submit and cancel and more options buttons
var btnGroup = w.add("group");
var submit = btnGroup.add("button", undefined, "Submit");
submit.onClick = function()
{
for (var fa in framesAdded)
{
var thisFrame = framesAdded[fa];
var frameName = frameNames[fa];
//if this frame is the mockup initials frame, get the date and append it to the contents
if(frameName == "Mockup Initials")
{
var date = getDate();
info.textFrames[frameName].contents = thisFrame.text + " " + date;
}
else if(frameName == "Order Number")
{
info.textFrames["Order Number"].contents = thisFrame.text + " " + framesAdded["Team Name"].text
}
else if(frameName == "Team Name")
{
continue;
}
else
{
info.textFrames[frameName].contents = thisFrame.text;
}
}
w.close();
}
var cancel = btnGroup.add("button", undefined, "Cancel");
cancel.onClick = function()
{
w.close();
}
if(!opts)
{
//button to open up the ability to change generally static text frames such as garment description and garment code
var moreOptions = btnGroup.add("button", undefined, "More Options");
moreOptions.onClick = function()
{
w.close();
createDialog(info,true);
}
}
else
{
//button to close the ability to change generally static text frames
var lessOptions = btnGroup.add("button", undefined, "Less Options");
lessOptions.onClick = function()
{
w.close();
createDialog(info,false);
}
}
w.show();
}