Problem
Many applications require prompting the user for inputs or choices and then acting on that input. This recipe creates a modeless (i.e., non-modal) dialog box with choices. When the user clicks the Okay button to dismiss the window, it stores the user inputs into variables and then does whatever work is required.
Solution
The New Window() function will create a window you can use to prompt the user for input. Inside the new window you can use input selector display boxes to collect the user choices.
You'll then use the Set Function or Set Script options on a Button Box to store the values from the display boxes into JSL variables.
The final part of the script in the Button Box does the work required after the user dismisses the window.
win = New Window( "Set the Value",
H List Box( Text Box( "Set this value" ), num_edit_box1 = Number Edit Box( 42 ) ),
check_box_1 = Check Box( "On" ),
combo_box1 = Combo Box( {"Choice 1", "Choice 2", "Choice 3"} ),
list_box1 = List Box( {"Choice 3", "Choice 4", "Choice 5"} ),
H List Box(
Button Box( "OK",
//store results in jsl variables
num_input = num_edit_box1 << get;
check_box_input = check_box_1 << get;
combo_box_input = combo_box1 << get selected;
list_box_input = list_box1 << get selected;
//close the window
//wait until you've unloaded the input boxes before you closing
//or else they'll be gone
win << close window;
//now do whatever work you want with the inputs
Show( num_input, check_box_input, combo_box_input, list_box_input );
),
//a cancel button that closes the window and doesn't store store the results
Button Box( "Cancel", win << close window )
)
);
Discussion
Modeless dialogs are a bit trickier than modal dialogs since any code after the New Window() will be executed before the dialog is dismissed. That's why you have to put the "work" to be done in the button box script.
See Also
Retrieve values from a modeless dialog box