onClick callbacks for buttons don't execute
This is my first attempt at creating a dialog box using the "resource specification" method. Basically, I want the script to stop if the user clicks Cancel or continue if the user clicks OK. My function that handles the "OK to continue" always returns 0. Here is the code; any insights would be greatly appreciated.
#target framemaker
main();
function main () {
var vStartDir = ChooseFile("Select the folder containing the book you want to clone:", "", "", Constants.FV_ChooseOpenDir);
var vOutputDir = ChooseFile("Select (or create) the destination folder for the new book:", "", "", Constants.FV_ChooseOpenDir);
var okToOverwrite = fileOverwriteWarning(); // this always evaluates to 0
alert(okToOverwrite);
if (okToOverwrite == 0) { // STOP execution
return;
}
// Otherwise, continue execution (script never gets this far)
alert("okToOverwrite = " + okToOverwrite + ". Continuing...");
// etc.
}
function fileOverwriteWarning()
{
var result =0;
var resource = "dialog { properties:{ resizeable:true }, text:'Overwrite existing files?', msg: StaticText { text:'NOTE: If you chose an existing folder as the destination for the new book, existing files in that folder with the same name as a source file will be over-written. OK to continue?', preferredSize: [400, 80], minimumSize: [400, 80], alignment:['fill','fill'], properties:{multiline:true} }, btnGroup: Group { alignment:['center', 'bottom'] okBtn: Button { text:'OK', properties:{name:'ok'} }, cancelBtn: Button { text:'Cancel', properties:{name:'cancel'} } } }";
//Define the dialog resource based on the specification
var dlg = new Window (resource);
dlg.layout.layout(true);
dlg.show();
// callbacks...THESE NEVER EXECUTE
dlg.btnGroup.okBtn.onClick = function()
{
alert("OK clicked");
result = 1;
};
// Callback for clicking the Close button, just want to close the palette.
dlg.btnGroup.cancelBtn.onClick = function()
{
alert("Cancel clicked");
this.parent.parent.close(2)
dlg = null;
};
//This gets called by close() above and when
//you click X in the upper right corner.
dlg.onClose = function()
{
alert("Red X clicked");
dlg = null;
};
dlg.onResize = function()
{
dlg.layout.resize();
}
return result;
}
