問題
多くのアプリケーションでは、ユーザーに入力または選択を求めるプロンプトを出し、その入力に基づいて操作する必要があります。 このレシピは、モードレス(つまり、非モーダル) ダイアログ ボックスに選択肢が表示されます。 ユーザーがわかったボタンをクリックしてウィンドウを閉じると、ユーザー入力が変数に保存され、必要な作業がすべて実行されます。
解決
の新しい窓()関数は、ユーザーに入力を促すために使用できるウィンドウを作成します。 新しいウィンドウ内で使用できます入力セレクタ表示ボックスユーザーの選択を収集します。
次に、関数の設定またはスクリプトの設定オプションボタンボックス表示ボックスの値をJSL変数に保存します。
ボタン ボックス内のスクリプトの最後の部分は、ユーザーがウィンドウを閉じた後に必要な作業を行います。
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 )
)
);
議論
モードレス ダイアログは、モーダル ダイアログよりも少しトリッキーです。新しい窓()ダイアログが閉じられる前に実行されます。 そのため、実行する「作業」をボタン ボックス スクリプトに入れる必要があります。
関連項目
モードレス ダイアログ ボックスから値を取得する