|
Class: YesNoBox
Object
|
+--GraphicsMedium
|
+--DisplaySurface
|
+--SimpleView
|
+--View
|
+--TopView
|
+--StandardSystemView
|
+--ModalBox
|
+--DialogBox
|
+--InfoBox
|
+--WarningBox
|
+--YesNoBox
- Package:
- stx:libwidg
- Category:
- Views-DialogBoxes
- Version:
- rev:
1.70
date: 2022/07/08 06:27:24
- user: cg
- file: YesNoBox.st directory: libwidg
- module: stx stc-classLibrary: libwidg
aHistoric note:
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:
aBox showAtPointer
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).
Use is:
self confirm:'some question'
and will return true or false.
For compatibility with ST-80, use:
Dialog confirm:'hello'
copyrightCOPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
icon bitmap
-
iconBitmap
-
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.
instance creation
-
title: titleString yesText: yesString noText: noString
-
return a new YesNoBox with title, and buttonLabels yesString/noString
styles
-
updateStyleCache
-
extract values from the styleSheet and cache them in class variables.
Here, the cached infoBitmap is simply flushed.
initialization
-
initialize
-
looks better; should it come from the StyleSheet ?
queries
-
beepWhenOpening
-
-
computePreferredExtent
-
compute the boxes preferredExtent from the components' sizes
startup
-
confirm
-
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.
Usage example(s):
-
confirm: aString
-
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.
Usage example(s):
YesNoBox new confirm:'really?'
YesNoBox confirm:'really?'
self confirm:'really?'
for ST-80 compatibility, you should use Dialogs confirm
(which simply forwards the request to the YesNoBox anyway):
Dialog confirm:'really?'
|
testing
-
isWarningBox
-
user interaction
-
noPressed
-
user pressed the no-button;
hide myself and evaluate the action
Notice, the preferred use is via the DialogBox class messages,
such as
Dialog confirm:'Coffee ?'
Dialog confirmWithCancel:'Coffee ?'
| these (DialogBox) messages are compatible with VW and should therefore
be used for portability.
Direct reference to YesNoBox is only required for highly specialized boxes.
Examples:
|aBox|
aBox := YesNoBox title:'Coffee or tee ?'.
aBox noText:'tee'.
aBox yesText:'coffee'.
aBox yesAction:[Transcript showCR:'make coffee'].
aBox noAction:[Transcript showCR:'make tee'].
aBox showAtPointer.
| or, shorter:
|aBox|
aBox := YesNoBox new.
aBox title:'Coffee or Tee?'
yesAction:[Transcript showCR:'make coffee']
noAction:[Transcript showCR:'make tee'].
aBox yesText:'Coffee' noText:'Tee'.
aBox showAtPointer
|
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.
Example:
|box value|
box := YesNoBox new.
value := box confirm:'yes or no:'.
value ifTrue:[
Transcript showCR:'yes'
] ifFalse:[
Transcript showCR:'no'
]
|
of course, this can also be written shorter as:
(YesNoBox new confirm:'yes or no:') ifTrue:[
Transcript showCR:'yes'
] ifFalse:[
Transcript showCR:'no'
]
| or:
(Dialog confirm:'yes or no:') ifTrue:[
Transcript showCR:'yes'
] ifFalse:[
Transcript showCR:'no'
]
|
or even:
Transcript showCR:(
(Dialog confirm:'yes or no:')
ifTrue:['yes']
ifFalse:['no'])
|
|