8.3 Creating your own dialogs
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"))
Figure 8.9 A cancel button
The function abort-dialog
cancels the dialog returning the valuesnil
andnil
, which represent a return result ofnil
and the fact that the dialog was cancelled, respectively. Note also thatabort-dialog
accepts any values and just ignores them.
The next problem is to create a dialog that can return a result. Use the functionexit-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 calledpopup-confirmer
that adds all of the standard buttons for you. This function is discussed in the next section.
Generated with Harlequin WebMaker