The CAPI provides a number of different dialogs for accepting values from the user, ranging from accepting strings to accepting whole Lisp forms to be evaluated.
The simplest of the CAPI prompting dialogs is prompt-for-string which returns the string you enter into the dialog.
The CAPI also provides a number of more specific dialogs that allow you to enter other types of data. For example, to enter an integer, use the function prompt-for-integer. Only integers are accepted as valid input for this function.
There are a number of extra options which allow you to specify more strictly which integers are acceptable. Firstly, there are two arguments
:max which specify the minimum and maximum acceptable integers.
If this does not provide enough flexibility you can specify a function that validates the result with the keyword argument
:ok-check. This function is passed the current value and must return non-nil if it is a valid result.
Try also the function prompt-for-number.
If you would like the user to select an item from a list of items, the function
prompt-with-list should handle the majority of cases. The simplest form just passes a list to the function and expects a single item to be returned.
You can also specify the interaction style that you would like for your dialog, which can be any of the interactions accepted by a choice. The specification of the interaction style to this choice is made using the keyword argument
By default, the dialog is created using a list-panel to display the items, but the keyword argument
:choice-class can be specified with any choice pane. Thus, for instance, you can present a list of buttons.
Finally, as with any of the prompting functions, you can specify additional arguments to the pane that has been created in the dialog. Thus to create a column of buttons instead of the default row, use:
To prompt for a file, use the function prompt-for-file:
Try also the function prompt-for-directory.
To obtain a
gp:font object from the user call prompt-for-font.
To obtain a color specification from the user call prompt-for-color.
The CAPI provides a number of dialogs specifically designed for creating Lisp aware applications. The simplest is the function prompt-for-form which accepts an arbitrary Lisp form and optionally evaluates it.
Another useful function is prompt-for-symbol which prompts the user for an existing symbol. The simplest usage accepts any symbol, as follows:
If you have a list of symbols from which to choose, then you can pass prompt-for-symbol this list with the keyword argument
Cocoa programmers will notice that the dialog sheet displayed by this form prevents input to other LispWorks windows while it is displayed. For information about creating dialog sheets which are not application-modal, see Window-modal Cocoa dialogs.
CAPI User Guide and Reference Manual (Macintosh version) - 25 Feb 2015