date: 2018/11/09 23:37:54
- user: cg
- file: YesNoBox.st directory: libwidg
- module: stx stc-classLibrary: libwidg
- Claus Gittinger
originally, ST/X had separate classes for the various entry methods;
there were YesNoBox, EnterBox, InfoBox and so on.
In the meantime, the DialogBox class (and therefore its alias: Dialog)
is going to duplicate most functionality found in these classes.
In the future, those existing subclasses' functionality is going to
be moved fully into Dialog, and the subclasses will be replaced by dummy
delegators. (They will be kept for backward compatibility, though).
New applications should use corresponding confirmation
methods from DialogBox.
This class implements yes-no boxes by adding another (no-) Button to the WarnBox-View.
They are created with:
aBox := YesNoBox title:'some title'.
aBox okAction:[ .. some action to be performed when ok is pressed ].
and finally shown with:
The default box shows 'yes' and 'no' in its buttons; this can be changed with:
aBox yesText:'some string'.
aBox noText:'some string'.
There is also protocol to set both button titles in one message.
Also, the action associated to the noButton can be changed.
For very simple yes/no queries, you can also use the much simpler confirm:.
Since implemented in Object, everyone understands confirm. You can pass
a question message (but not change the buttons labels).
self confirm:'some question'
and will return true or false.
For compatibility with ST-80, use:
return the bitmap shown as icon in my instances.
This is the default image; you can overwrite this in a concrete
instance with the #image: message.
title: titleString yesText: yesString noText: noString
return a new YesNoBox with title, and buttonLabels yesString/noString
extract values from the styleSheet and cache them in class variables.
Here, the cached infoBitmap is simply flushed.
looks better; should it come from the StyleSheet ?
compute the boxes preferredExtent from the components' sizes
open the receiver and return true for yes, false for no.
This is an easier interface to use, since no action blocks
have to be defined. The title is used as previously defined.
open a modal yes-no dialog.
Return true for yes, false for no.
This is an easier interface to use, since no action blocks have to be defined.
YesNoBox new confirm:'really?'
for ST-80 compatibility, you should use Dialogs confirm
(which simply forwards the request to the YesNoBox anyway):
user pressed the no-button;
hide myself and evaluate the action
Notice, the preferred use is via the DialogBox class messages,
these (DialogBox) mesages are compatible with VW and should therefore
be used for portability.
Direct reference to YesNoBox is only required for highly specialized boxes.
Dialog confirm:'Coffee ?'
Dialog confirmWithCancel:'Coffee ?'
aBox := YesNoBox title:'Coffee or tee ?'.
aBox yesAction:[Transcript showCR:'make coffee'].
aBox noAction:[Transcript showCR:'make tee'].
Also, have a look at the inherited protocol; for example, this allows changing
the bitmap (default: a question mark) and other properties.
If the box is needed to ask for a simple boolean, you can also use the
#confirm method, to bring up a box, let it ask for something and return
true or false.
aBox := YesNoBox new.
aBox title:'Coffee or Tee?'
yesAction:[Transcript showCR:'make coffee']
noAction:[Transcript showCR:'make tee'].
aBox yesText:'Coffee' noText:'Tee'.
of course, this can also be written shorter as:
box := YesNoBox new.
value := box confirm:'yes or no:'.
(YesNoBox new confirm:'yes or no:') ifTrue:[
(Dialog confirm:'yes or no:') ifTrue:[
(Dialog confirm:'yes or no:')