author | Claus Gittinger <cg@exept.de> |
Fri, 01 Mar 1996 19:44:55 +0100 | |
changeset 447 | ed41e1bbd9a1 |
parent 444 | ef26eba8c854 |
child 572 | 121735c2aff6 |
permissions | -rw-r--r-- |
0 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
59 | 3 |
All Rights Reserved |
0 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
WarningBox subclass:#YesNoBox |
|
253
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
14 |
instanceVariableNames:'' |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
15 |
classVariableNames:'RequestBitmap' |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
16 |
poolDictionaries:'' |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
17 |
category:'Views-DialogBoxes' |
0 | 18 |
! |
19 |
||
38 | 20 |
!YesNoBox class methodsFor:'documentation'! |
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
59 | 25 |
All Rights Reserved |
38 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
documentation |
|
37 |
" |
|
355 | 38 |
Historic note: |
39 |
originally, ST/X had separate classes for the various entry methods; |
|
40 |
there were YesNoBox, EnterBox, InfoBox and so on. |
|
41 |
In the meantime, the DialogBox class (and therefore its alias: Dialog) |
|
42 |
is going to duplicate most funcionality found in these classes. |
|
43 |
||
44 |
In the future, those existing subclasses' functionality is going to |
|
45 |
be moved fully into Dialog, and the subclasses will be replaced by dummy |
|
46 |
delegators. (They will be kept for backward compatibility, though). |
|
47 |
||
48 |
||
49 |
||
38 | 50 |
this class implements yes-no boxes by adding another (no-) Button to the WarnBox-View. |
51 |
They are created with: |
|
52 |
||
355 | 53 |
aBox := YesNoBox title:'some title'. |
54 |
aBox okAction:[ .. some action to be performed when ok is pressed ]. |
|
38 | 55 |
|
56 |
and finally shown with: |
|
0 | 57 |
|
355 | 58 |
aBox showAtPointer |
38 | 59 |
|
60 |
The default box shows 'yes' and 'no' in its buttons; this can be changed with: |
|
61 |
||
355 | 62 |
aBox yesText:'some string'. |
63 |
aBox noText:'some string'. |
|
38 | 64 |
|
65 |
There is also protocol to set both button titles in one message. |
|
66 |
Also, the action associated to the noButton can be changed. |
|
67 |
||
63 | 68 |
For very simple yes/no queries, you can also use the much simpler confirm:. |
69 |
Since implemented in Object, everyone understands confirm. You can pass |
|
70 |
a question message (but not change the buttons labels). |
|
71 |
Use is: |
|
355 | 72 |
self confirm:'some question' |
63 | 73 |
and will return true or false. |
125 | 74 |
|
75 |
For compatibility with ST-80, use: |
|
355 | 76 |
Dialog confirm:'hello' |
63 | 77 |
" |
78 |
! |
|
79 |
||
80 |
examples |
|
81 |
" |
|
38 | 82 |
Examples: |
83 |
||
59 | 84 |
|aBox| |
38 | 85 |
|
59 | 86 |
aBox := YesNoBox title:'Coffee or tee ?'. |
87 |
aBox noText:'tee'. |
|
88 |
aBox yesText:'coffee'. |
|
89 |
aBox yesAction:[Transcript showCr:'make coffee']. |
|
90 |
aBox noAction:[Transcript showCr:'make tee']. |
|
91 |
aBox showAtPointer. |
|
38 | 92 |
|
93 |
or, shorter: |
|
94 |
||
59 | 95 |
|aBox| |
38 | 96 |
|
59 | 97 |
aBox := YesNoBox new. |
98 |
aBox title:'Coffee or Tee ?' |
|
99 |
yesAction:[Transcript showCr:'make coffee'] |
|
100 |
noAction:[Transcript showCr:'make tee']. |
|
101 |
aBox yesText:'Coffee' noText:'Tee'. |
|
102 |
aBox showAtPointer |
|
38 | 103 |
|
104 |
Also, have a look at the inherited protocol; for example, this allows changing |
|
105 |
the bitmap (default: a question mark) and other properties. |
|
59 | 106 |
|
107 |
If the box is needed to ask for a simple boolean, you can also use the |
|
108 |
#confirm method, to bring up a box, let it ask for something and return |
|
109 |
true or false. |
|
110 |
Example: |
|
111 |
||
112 |
|box value| |
|
113 |
||
114 |
box := YesNoBox new. |
|
115 |
value := box confirm:'yes or no:'. |
|
116 |
value ifTrue:[ |
|
117 |
Transcript showCr:'yes' |
|
118 |
] ifFalse:[ |
|
119 |
Transcript showCr:'no' |
|
120 |
] |
|
121 |
||
122 |
of course, this can also be written shorter as: |
|
123 |
||
124 |
(YesNoBox new confirm:'yes or no:') ifTrue:[ |
|
125 |
Transcript showCr:'yes' |
|
126 |
] ifFalse:[ |
|
127 |
Transcript showCr:'no' |
|
128 |
] |
|
125 | 129 |
|
130 |
or: |
|
131 |
||
132 |
(Dialog confirm:'yes or no:') ifTrue:[ |
|
133 |
Transcript showCr:'yes' |
|
134 |
] ifFalse:[ |
|
135 |
Transcript showCr:'no' |
|
136 |
] |
|
38 | 137 |
" |
138 |
! ! |
|
0 | 139 |
|
197 | 140 |
!YesNoBox class methodsFor:'instance creation'! |
59 | 141 |
|
197 | 142 |
title:t yesText:yesString noText:noString |
143 |
^ (self new) title:t yesText:yesString noText:noString |
|
59 | 144 |
! ! |
145 |
||
146 |
!YesNoBox class methodsFor:'icon bitmap'! |
|
147 |
||
148 |
iconBitmap |
|
149 |
"return the bitmap shown as icon in my instances" |
|
150 |
||
151 |
RequestBitmap isNil ifTrue:[ |
|
109 | 152 |
RequestBitmap := Image fromFile:'bitmaps/Request.xbm'. |
153 |
RequestBitmap notNil ifTrue:[ |
|
154 |
RequestBitmap := RequestBitmap on:Display |
|
155 |
]. |
|
59 | 156 |
]. |
157 |
^ RequestBitmap |
|
158 |
! ! |
|
159 |
||
197 | 160 |
!YesNoBox class methodsFor:'styles'! |
161 |
||
162 |
updateStyleCache |
|
444
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
373
diff
changeset
|
163 |
"extract values from the styleSheet and cache them in class variables" |
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
373
diff
changeset
|
164 |
|
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
373
diff
changeset
|
165 |
<resource: #style (#requestBoxIcon)> |
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
373
diff
changeset
|
166 |
|
197 | 167 |
|img| |
168 |
||
169 |
img := StyleSheet at:'requestBoxIcon'. |
|
170 |
img notNil ifTrue:[RequestBitmap := img on:Display]. |
|
444
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
373
diff
changeset
|
171 |
|
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
373
diff
changeset
|
172 |
"Modified: 1.3.1996 / 13:52:18 / cg" |
197 | 173 |
! ! |
174 |
||
175 |
!YesNoBox methodsFor:'accessing'! |
|
176 |
||
177 |
noAction:aBlock |
|
178 |
"define the action to be performed when no is pressed" |
|
179 |
||
180 |
abortAction := aBlock |
|
181 |
! |
|
182 |
||
183 |
noButton |
|
184 |
"return the no-button" |
|
185 |
||
186 |
^ abortButton |
|
187 |
! |
|
188 |
||
253
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
189 |
noLabel:aString |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
190 |
"define the label of the no-button" |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
191 |
|
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
192 |
self noText:aString. |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
193 |
|
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
194 |
"Created: 13.12.1995 / 16:21:57 / cg" |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
195 |
! |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
196 |
|
197 | 197 |
noText:aString |
198 |
"define the label of the no-button" |
|
199 |
||
200 |
aString ~= abortButton label ifTrue:[ |
|
201 |
abortButton label:aString. |
|
202 |
abortButton resize. |
|
203 |
shown ifTrue:[self resize] |
|
204 |
] |
|
205 |
! |
|
206 |
||
207 |
okText:yesString noText:noString |
|
208 |
"define the labels of both buttons - same as yesText:noText" |
|
209 |
||
210 |
^ self yesText:yesString noText:noString |
|
211 |
! |
|
212 |
||
213 |
title:aString yesAction:yesBlock noAction:noBlock |
|
214 |
"define title and actions" |
|
59 | 215 |
|
197 | 216 |
self title:aString. |
217 |
okAction := yesBlock. |
|
218 |
abortAction := noBlock |
|
219 |
! |
|
220 |
||
221 |
title:aString yesText:yesString noText:noString |
|
222 |
"define title and button labels" |
|
223 |
||
224 |
self title:aString. |
|
225 |
self yesText:yesString noText:noString |
|
226 |
! |
|
227 |
||
228 |
yesAction:aBlock |
|
229 |
"define the action to be performed when yes is pressed" |
|
230 |
||
231 |
okAction := aBlock |
|
232 |
! |
|
233 |
||
234 |
yesAction:yesBlock noAction:noBlock |
|
235 |
"define both actions" |
|
236 |
||
237 |
okAction := yesBlock. |
|
238 |
abortAction := noBlock |
|
239 |
! |
|
240 |
||
241 |
yesButton |
|
242 |
"return the yes-button" |
|
243 |
||
244 |
^ okButton |
|
245 |
! |
|
246 |
||
253
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
247 |
yesLabel:aString |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
248 |
"define the label of the yes-button" |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
249 |
|
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
250 |
self yesText:aString. |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
251 |
|
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
252 |
"Created: 13.12.1995 / 16:22:05 / cg" |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
253 |
! |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
254 |
|
197 | 255 |
yesText:aString |
256 |
"define the label of the yes-button" |
|
257 |
||
258 |
self okText:aString |
|
259 |
! |
|
260 |
||
261 |
yesText:yesString noText:noString |
|
262 |
"define the labels of both buttons" |
|
263 |
||
264 |
((yesString ~= okButton label) or:[noString ~= abortButton label]) ifTrue:[ |
|
373 | 265 |
okButton label:yesString. |
266 |
abortButton label:noString. |
|
267 |
okButton resize. |
|
268 |
abortButton resize. |
|
269 |
shown ifTrue:[self resize] |
|
197 | 270 |
] |
373 | 271 |
|
272 |
"Modified: 21.2.1996 / 00:58:38 / cg" |
|
59 | 273 |
! ! |
274 |
||
0 | 275 |
!YesNoBox methodsFor:'initialization'! |
276 |
||
197 | 277 |
focusSequence |
278 |
^ Array with:abortButton with:okButton |
|
279 |
! |
|
280 |
||
0 | 281 |
initialize |
282 |
super initialize. |
|
283 |
||
150 | 284 |
label := resources string:'Choose'. |
79 | 285 |
|
130 | 286 |
buttonPanel horizontalLayout:#fitSpace. "/ looks better; should it come from the StyleSheet ? |
63 | 287 |
|
59 | 288 |
textLabel label:'please Confirm'. |
162 | 289 |
okButton logo:(resources at:'yes'). |
0 | 290 |
|
162 | 291 |
abortButton := Button abortButton. |
292 |
buttonPanel addSubView:abortButton before:okButton. |
|
293 |
abortButton logo:(resources at:'no'). |
|
294 |
abortButton height:(okButton height). |
|
295 |
abortButton model:self; change:#noPressed |
|
197 | 296 |
! ! |
297 |
||
298 |
!YesNoBox methodsFor:'queries'! |
|
299 |
||
300 |
preferredExtent |
|
373 | 301 |
|w h max mm| |
302 |
||
303 |
mm := ViewSpacing. |
|
79 | 304 |
|
197 | 305 |
" |
306 |
make the two buttons of equal size |
|
307 |
" |
|
308 |
max := okButton preferredExtent x max:abortButton preferredExtent x. |
|
309 |
okButton width:max. |
|
310 |
abortButton width:max. |
|
373 | 311 |
|
197 | 312 |
w := (formLabel width + textLabel width) max:max * 2. |
373 | 313 |
w := w + (3 * mm) + (okButton borderWidth + abortButton borderWidth * 2). |
314 |
h := (mm * 5) |
|
315 |
+ ((formLabel height) max:(textLabel height)) |
|
316 |
+ okButton heightIncludingBorder. |
|
197 | 317 |
|
318 |
^ (w @ h). |
|
373 | 319 |
|
320 |
"Modified: 21.2.1996 / 00:58:04 / cg" |
|
59 | 321 |
! ! |
38 | 322 |
|
59 | 323 |
!YesNoBox methodsFor:'startup'! |
324 |
||
325 |
confirm |
|
326 |
"open the receiver and return true for yes, false for no. |
|
327 |
This is an easier interface to use, since no action blocks |
|
328 |
have to be defined. The title is used as previously defined." |
|
38 | 329 |
|
59 | 330 |
self yesAction:[^ true] noAction:[^ false]. |
63 | 331 |
self showAtPointer. |
332 |
self yesAction:nil noAction:nil. "/ clear actions for earlier release of context |
|
38 | 333 |
|
59 | 334 |
" |
335 |
YesNoBox new confirm |
|
336 |
" |
|
0 | 337 |
! |
338 |
||
59 | 339 |
confirm:aString |
340 |
"open the receiver and return true for yes, false for no. |
|
341 |
This is an easier interface to use, since no action blocks |
|
342 |
have to be defined." |
|
38 | 343 |
|
59 | 344 |
self title:aString. |
345 |
^ self confirm |
|
346 |
||
347 |
" |
|
348 |
YesNoBox new confirm:'really ?' |
|
253
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
349 |
YesNoBox confirm:'really ?' |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
350 |
self confirm:'really ?' |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
351 |
|
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
352 |
for ST-80 compatibility, you should use Dialogs confirm |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
353 |
(which simply forwards the request to the YesNoBox anyway): |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
354 |
|
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
355 |
Dialog confirm:'really ?' |
59 | 356 |
" |
253
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
357 |
|
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
358 |
"Modified: 13.12.1995 / 16:20:01 / cg" |
0 | 359 |
! ! |
360 |
||
361 |
!YesNoBox methodsFor:'user interaction'! |
|
362 |
||
363 |
noPressed |
|
364 |
"user pressed the no-button; |
|
365 |
hide myself and evaluate the action" |
|
366 |
||
162 | 367 |
abortButton turnOffWithoutRedraw. |
368 |
self hideAndEvaluate:abortAction |
|
0 | 369 |
! ! |
370 |
||
243 | 371 |
!YesNoBox class methodsFor:'documentation'! |
372 |
||
373 |
version |
|
444
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
373
diff
changeset
|
374 |
^ '$Header: /cvs/stx/stx/libwidg/YesNoBox.st,v 1.25 1996-03-01 13:05:52 cg Exp $' |
243 | 375 |
! ! |