NextPrevUpTopContentsIndex

10.5.1 Using display-dialog

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"))

Figure 10.9 A cancel button

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 to add an OK button in the code above, but since almost every dialog needs these standard buttons, the CAPI provides a higher level function called popup-confirmer that adds the standard buttons for you. Also it arranges for the OK and Cancel buttons to respond to the Return and Escape keys respectively. popup-confirmer is discussed in the next section.


LispWorks CAPI User Guide (Macintosh version) - 17 Mar 2008

NextPrevUpTopContentsIndex