Here is a very simple example that displays a
Cancel
button in a dialog, and when that button is pressed the dialog is cancelled. Note that
display-dialog
must receive an interface, so an interface is created for the button by using the function
make-container
.
(display-dialog
(make-container
(make-instance
'push-button
:text "Press this button to cancel"
:callback 'abort-dialog)
:title "My Dialog"))
The function
abort-dialog
cancels the dialog returning the values
nil
and
nil
, which represent a return result of
nil
and the fact that the dialog was cancelled, respectively. Note also that
abort-dialog
accepts any values and just ignores them.
The next problem is to create a dialog that can return a result. Use the function
exit-dialog
which returns the value passed to it from the dialog. The example below shows a simple string prompter.
(display-dialog
(make-container
(make-instance
'text-input-pane
:callback-type :data
:callback 'exit-dialog)
:title "Enter a string:"))
Both of these examples are very simple, so here is a slightly more complicated one which creates a column containing both a text-input-pane and a Cancel button.
(display-dialog
(make-container
(list
(make-instance
'text-input-pane
:callback-type :data
:callback 'exit-dialog)
(make-instance
'push-button
:text "Cancel"
:callback 'abort-dialog))
:title "Enter a string:"))
Note that this looks very similar to the dialog created by
prompt-for-string
except for the fact that it does not provide the standard
OK
button. It would be simple enough to add the
OK
button, but since almost every dialog needs these standard buttons, the CAPI provides a higher level function called
popup-confirmer
that adds all of the standard buttons for you. This function is discussed in the next section.