CHAPTER 7: User Interfaces Your First InDesign Dialog 112
The dialog object itself does not directly contain the controls; that is the purpose of the dialogColumn
object.
dialogColumns give you a way to control the positioning of controls within a dialog box. Inside
dialogColumns, you can further subdivide the dialog box into other dialogColumns or borderPanels
(both of which can, if necessary, contain more
dialogColumns and borderPanels).
Like any other InDesign scripting object, each part of a dialog box has its own properties. A
checkboxControl, for example, has a property for its text (staticLabel) and another property for its
state (
checkedState). The dropdown control has a property (stringList) for setting the list of options
that appears on the control’s menu.
To use a dialog box in your script, create the
dialog object, populate it with various controls, display the
dialog box, and then gather values from the dialog-box controls to use in your script. Dialog boxes remain
in InDesign’s memory until they are destroyed. This means you can keep a dialog box in memory and have
data stored in its properties used by multiple scripts, but it also means the dialog boxes take up memory
and should be disposed of when they are not in use. In general, you should destroy a dialog-box object
before your script finishes executing.
Your First InDesign Dialog
The process of creating an InDesign dialog is very simple: add a dialog, add a dialog column to the dialog,
and add controls to the dialog column. The following script demonstrates the process (for the complete
script, see SimpleDialog):
var myDialog = app.dialogs.add({name:"Simple Dialog"});
//Add a dialog column.
with(myDialog.dialogColumns.add()){
staticTexts.add({staticLabel:"This is a very simple dialog box."});
}
//Show the dialog box.
var myResult = myDialog.show();
//If the user clicked OK, display one message;
//if they clicked Cancel, display a different message.
if(myResult == true){
alert("You clicked the OK button.");
}
else{
alert("You clicked the Cancel button.");
}
//Remove the dialog box from memory.
myDialog.destroy();
Dialog box element InDesign name
Text-edit fields Text editbox control
Numeric-entry fields Real editbox, integer editbox, measurement
editbox, percent editbox, angle editbox
Pop-up menus Drop-down control
Control that combines a text-edit field with a
pop-up menu
Combo-box control
Check box Check-box control
Radio buttons Radio-button control