76
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
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 |
|
120
|
13 |
'From Smalltalk/X, Version:2.10.5 on 3-may-1995 at 2:41:07 am'!
|
76
|
14 |
|
|
15 |
ModalBox subclass:#DialogBox
|
|
16 |
instanceVariableNames:'buttonPanel okButton okAction abortButton abortAction
|
128
|
17 |
acceptReturnAsOK yPosition leftIndent rightIndent bindings addedComponents
|
|
18 |
inputFieldGroup acceptOnLeave acceptValue tabableElements'
|
76
|
19 |
classVariableNames:''
|
|
20 |
poolDictionaries:''
|
|
21 |
category:'Views-DialogBoxes'
|
|
22 |
!
|
|
23 |
|
|
24 |
!DialogBox class methodsFor:'documentation'!
|
|
25 |
|
|
26 |
version
|
|
27 |
"
|
164
|
28 |
$Header: /cvs/stx/stx/libwidg/DialogBox.st,v 1.24 1995-10-23 20:06:06 cg Exp $
|
76
|
29 |
"
|
|
30 |
!
|
|
31 |
|
|
32 |
documentation
|
|
33 |
"
|
|
34 |
this class implements the common behavior of dialogboxes.
|
|
35 |
|
|
36 |
DialogBox is an (abstract) superclass of many other boxes - see InfoBox,
|
|
37 |
WarningBox, YesNoBox etc. for concrete examples.
|
|
38 |
Most of them simply add buttons or other elements.
|
|
39 |
|
121
|
40 |
For programmatically created boxes, instances support adding of components
|
|
41 |
in a top-to-bottom fashion, and also keep track of added text-fields and,
|
|
42 |
since they are most common, automatically create an EnterFieldGroup for
|
|
43 |
them.
|
122
|
44 |
Caveat: more adding support is required - especially for row-wise
|
|
45 |
construction.
|
|
46 |
|
121
|
47 |
|
76
|
48 |
instance variables:
|
|
49 |
|
|
50 |
buttonPanel <PanelView> contains the button(s)
|
|
51 |
|
|
52 |
okButton <Button> the ok-Button
|
|
53 |
|
|
54 |
okAction <Block> the action to be performed when ok is pressed,
|
|
55 |
or return is pressed.
|
|
56 |
|
|
57 |
acceptReturnAsOK <Boolean> if true, pressing the return-key counts
|
|
58 |
as if ok was pressed. Default is true.
|
|
59 |
|
|
60 |
abortButton <Button> the cancel-Button
|
|
61 |
|
|
62 |
abortAction <Block> the action to be performed when cancel is
|
|
63 |
pressed.
|
100
|
64 |
|
121
|
65 |
yPosisition <Integer> current y position when adding components
|
|
66 |
|
128
|
67 |
leftIndent <Integer> left inset to use when adding components
|
|
68 |
|
|
69 |
rightIndent <Integer> right inset to use when adding components
|
121
|
70 |
|
|
71 |
addedComponents <Collection> programmatically added components
|
|
72 |
|
|
73 |
inputFieldGroup <EnterFieldGroup>
|
|
74 |
for added input fields
|
|
75 |
|
125
|
76 |
acceptOnLeave <Boolean> if true (the default) and there are
|
|
77 |
tabable inputFields, accept and close when
|
|
78 |
the last field is left. If false, the ok
|
|
79 |
button must be pressed to close the box.
|
|
80 |
|
128
|
81 |
acceptedValue v(<Boolean>) valueHolder on a boolean
|
|
82 |
after close: holds true if box was accepted
|
|
83 |
(i.e. ok-Button was pressed), false if box was
|
|
84 |
closed via cancel or window manager.
|
121
|
85 |
|
|
86 |
|
100
|
87 |
For compatibility with ST-80, this class is also available under
|
|
88 |
the global names DialogView and Dialog (see patches file).
|
76
|
89 |
"
|
|
90 |
!
|
|
91 |
|
|
92 |
examples
|
|
93 |
"
|
118
|
94 |
mostly, DialogBox is used as an abstract class as a base for InfoBox,
|
|
95 |
YesNoBox etc.
|
125
|
96 |
For most simple standard dialogs, there are ready to use
|
|
97 |
methods in the class protocol.
|
|
98 |
For example:
|
|
99 |
|
|
100 |
info & warnings:
|
|
101 |
|
|
102 |
Dialog information:'hi there'
|
|
103 |
|
|
104 |
Dialog warn:'oops'
|
|
105 |
|
|
106 |
|
|
107 |
yes/no questions:
|
|
108 |
|
|
109 |
(Dialog confirm:'is this simple ?')
|
|
110 |
ifTrue:[
|
|
111 |
Transcript showCr:'thats what I expected'
|
|
112 |
] ifFalse:[
|
|
113 |
Transcript showCr:'read more examples and documentation'
|
|
114 |
]
|
|
115 |
|
|
116 |
|
|
117 |
yes/no question with cancel option:
|
|
118 |
|
|
119 |
|answer|
|
|
120 |
|
|
121 |
answer := Dialog confirmWithCancel:'is this simple ?'.
|
|
122 |
answer isNil ifTrue:[
|
|
123 |
Transcript showCr:'no easy decision'
|
|
124 |
] ifFalse:[
|
|
125 |
answer ifTrue:[
|
|
126 |
Transcript showCr:'thats what I expected'
|
|
127 |
] ifFalse:[
|
|
128 |
Transcript showCr:'read more examples and documentation'
|
|
129 |
]
|
|
130 |
]
|
|
131 |
|
|
132 |
|
|
133 |
asking for a string:
|
|
134 |
|
|
135 |
|s|
|
|
136 |
|
|
137 |
s := Dialog request:'enter your name, please:'.
|
133
|
138 |
s notEmpty ifTrue:[
|
125
|
139 |
Transcript showCr:'you entered: ' , s.
|
|
140 |
]
|
|
141 |
|
|
142 |
|
|
143 |
asking for a string with given default:
|
|
144 |
|
|
145 |
|s|
|
|
146 |
|
|
147 |
s := Dialog
|
|
148 |
request:'enter your name, please:'
|
|
149 |
initialAnswer:(OperatingSystem getLoginName).
|
133
|
150 |
s notEmpty ifTrue:[
|
125
|
151 |
Transcript showCr:'you entered: ' , s.
|
|
152 |
]
|
|
153 |
|
|
154 |
|
|
155 |
asking for a filename:
|
|
156 |
|
|
157 |
|s|
|
|
158 |
|
|
159 |
s := Dialog
|
|
160 |
requestFileName:'select a file, please:'
|
|
161 |
default:''.
|
|
162 |
Transcript show:'you entered: '; showCr:s.
|
|
163 |
|
|
164 |
|
|
165 |
with changed button label and pattern:
|
|
166 |
|
|
167 |
|s|
|
|
168 |
|
|
169 |
s := Dialog
|
|
170 |
requestFileName:'select a file, please:'
|
|
171 |
default:''
|
|
172 |
ok:'show'
|
|
173 |
abort:'cancel'
|
|
174 |
pattern:'*.rc'.
|
|
175 |
Transcript show:'you entered: '; showCr:s.
|
|
176 |
|
118
|
177 |
However, you can construct dialogs programmatically, as shown in
|
|
178 |
the following examples:
|
91
|
179 |
|
121
|
180 |
basic (unusable) example:
|
|
181 |
|
|
182 |
DialogBox new open
|
76
|
183 |
|
121
|
184 |
still unusable - only an ok-button:
|
76
|
185 |
|
121
|
186 |
DialogBox new addOkButton; open
|
|
187 |
|
|
188 |
both ok- and abortButtons:
|
118
|
189 |
|
121
|
190 |
DialogBox new addAbortButton; addOkButton; open
|
|
191 |
|
122
|
192 |
with different ok-label:
|
|
193 |
|
|
194 |
DialogBox new addAbortButton; addOkButtonLabelled:'yeah'; open
|
|
195 |
|
121
|
196 |
adding a textlabel gives an infoBox:
|
120
|
197 |
|
121
|
198 |
DialogBox new
|
|
199 |
addTextLabel:'hello';
|
|
200 |
addOkButton;
|
|
201 |
open
|
|
202 |
|
|
203 |
a textlabel with abort- and okButton gives a yesNoBox:
|
118
|
204 |
|
121
|
205 |
DialogBox new
|
|
206 |
addTextLabel:'hello';
|
|
207 |
addAbortButton;
|
|
208 |
addOkButton;
|
|
209 |
open
|
|
210 |
|
|
211 |
the same, adjusting the labels contents to the left:
|
|
212 |
|
|
213 |
|box|
|
118
|
214 |
|
121
|
215 |
box := DialogBox new.
|
|
216 |
(box addTextLabel:'hello') adjust:#left.
|
|
217 |
box addAbortButton;
|
|
218 |
addOkButton;
|
|
219 |
open
|
|
220 |
|
122
|
221 |
with modified buttons:
|
|
222 |
|
|
223 |
|box|
|
|
224 |
|
|
225 |
box := DialogBox new.
|
|
226 |
(box addTextLabel:'are you certain ?') adjust:#left.
|
|
227 |
box addAbortButtonLabelled:'not really'.
|
|
228 |
(box addOkButtonLabelled:'yes, absolutely')
|
|
229 |
activeBackgroundColor:Color red.
|
|
230 |
box open
|
|
231 |
|
|
232 |
|
162
|
233 |
mswindows style:
|
|
234 |
|
|
235 |
|b box|
|
|
236 |
|
|
237 |
box := DialogBox new.
|
|
238 |
(box addTextLabel:'are you certain ?') adjust:#left.
|
|
239 |
b := Button new.
|
|
240 |
b activeLogo:(Image fromFile:'bitmaps/cancel_down.bmp').
|
|
241 |
b passiveLogo:(Image fromFile:'bitmaps/cancel_up.bmp').
|
|
242 |
b focusLogo:(Image fromFile:'bitmaps/cancel_focus.bmp').
|
|
243 |
b beImageButton.
|
|
244 |
box addAbortButton:b.
|
|
245 |
|
|
246 |
b := Button new.
|
|
247 |
b activeLogo:(Image fromFile:'bitmaps/ok_down.bmp').
|
|
248 |
b passiveLogo:(Image fromFile:'bitmaps/ok_up.bmp').
|
|
249 |
b focusLogo:(Image fromFile:'bitmaps/ok_focus.bmp').
|
|
250 |
b beImageButton.
|
|
251 |
box addOkButton:b.
|
|
252 |
box open
|
|
253 |
|
|
254 |
|
121
|
255 |
two textlabels:
|
118
|
256 |
|
121
|
257 |
DialogBox new
|
|
258 |
addTextLabel:'hello';
|
|
259 |
addTextLabel:'world';
|
|
260 |
addAbortButton;
|
|
261 |
addOkButton;
|
|
262 |
open
|
118
|
263 |
|
121
|
264 |
fixing the dialogs size (suppres it calculating its size from the
|
130
|
265 |
preferredExtents of its components):
|
118
|
266 |
|
121
|
267 |
DialogBox new
|
|
268 |
label:'a simple dialog';
|
|
269 |
addTextLabel:'hello';
|
|
270 |
addAbortButton;
|
|
271 |
addOkButton;
|
|
272 |
extent:200@200;
|
|
273 |
sizeFixed:true;
|
|
274 |
open
|
118
|
275 |
|
121
|
276 |
asking the box if it was closed via ok:
|
118
|
277 |
|
121
|
278 |
(DialogBox new
|
|
279 |
label:'a simple dialog';
|
|
280 |
addTextLabel:'hello';
|
|
281 |
addAbortButton;
|
|
282 |
addOkButton;
|
|
283 |
extent:200@200;
|
|
284 |
sizeFixed:true;
|
|
285 |
open
|
|
286 |
) accepted ifTrue:[
|
|
287 |
Transcript showCr:'yes'
|
|
288 |
] ifFalse:[
|
|
289 |
Transcript showCr:'no'
|
|
290 |
]
|
118
|
291 |
|
121
|
292 |
textLabels are not limited to strings (although, the name which is
|
|
293 |
used for ST-80 compatibility, suggests it):
|
118
|
294 |
|
121
|
295 |
DialogBox new
|
|
296 |
addTextLabel:(Image fromFile:'bitmaps/garfield.gif');
|
|
297 |
addOkButton;
|
|
298 |
open
|
120
|
299 |
|
121
|
300 |
DialogBox new
|
|
301 |
addTextLabel:'hello';
|
125
|
302 |
addTextLabel:((Image fromFile:'bitmaps/garfield.gif')
|
|
303 |
magnifiedTo:200@150);
|
121
|
304 |
addTextLabel:'world';
|
|
305 |
addAbortButton;
|
|
306 |
addOkButton;
|
|
307 |
open
|
120
|
308 |
|
121
|
309 |
adding an input field (on a string model):
|
|
310 |
|
|
311 |
|stringModel|
|
120
|
312 |
|
121
|
313 |
stringModel := '' asValue.
|
|
314 |
(DialogBox new
|
|
315 |
addTextLabel:'Please enter a string:';
|
|
316 |
addInputFieldOn:stringModel;
|
|
317 |
addAbortButton;
|
|
318 |
addOkButton;
|
|
319 |
open
|
|
320 |
) accepted ifTrue:[
|
|
321 |
Transcript showCr:'entered: ', stringModel value
|
|
322 |
]
|
120
|
323 |
|
|
324 |
|
121
|
325 |
multiple input fields (notice, that the dialog connects the fields
|
|
326 |
in a group, so stepping is allowed via Cursor and Return keys):
|
|
327 |
|
|
328 |
|firstName lastName|
|
120
|
329 |
|
121
|
330 |
firstName := '' asValue.
|
|
331 |
lastName := '' asValue.
|
|
332 |
(DialogBox new
|
|
333 |
addTextLabel:'Please enter your name:';
|
|
334 |
addInputFieldOn:firstName;
|
122
|
335 |
addVerticalSpace;
|
121
|
336 |
addInputFieldOn:lastName;
|
|
337 |
addAbortButton;
|
|
338 |
addOkButton;
|
|
339 |
open
|
|
340 |
) accepted ifTrue:[
|
|
341 |
Transcript showCr:'entered: ', firstName value , ' ' , lastName value
|
|
342 |
]
|
|
343 |
|
|
344 |
|
|
345 |
of course, the model may contain a value initially:
|
|
346 |
|
|
347 |
|firstName lastName p line i name|
|
120
|
348 |
|
121
|
349 |
firstName := '' asValue.
|
|
350 |
lastName := '' asValue.
|
|
351 |
p := PipeStream readingFrom:'finger ' , OperatingSystem getLoginName.
|
|
352 |
p notNil ifTrue:[
|
|
353 |
line := p nextLine.
|
130
|
354 |
(i := line findString:'Name:') ~~ 0 ifTrue:[
|
|
355 |
name := line copyFrom:(i + 'Name:' size).
|
|
356 |
] ifFalse:[
|
|
357 |
(i := line findString:'real life:') == 0 ifTrue:[
|
|
358 |
line := p nextLine.
|
|
359 |
].
|
|
360 |
(i := line findString:'real life:') ~~ 0 ifTrue:[
|
|
361 |
name := line copyFrom:(i + 'real life:' size).
|
|
362 |
]
|
121
|
363 |
].
|
130
|
364 |
name notNil ifTrue:[
|
121
|
365 |
firstName value: name asCollectionOfWords first.
|
130
|
366 |
lastName value: name asCollectionOfWords last.
|
|
367 |
Transcript showCr:'initially ' , firstName value , ' ' , lastName value.
|
121
|
368 |
].
|
|
369 |
p close.
|
|
370 |
].
|
120
|
371 |
|
121
|
372 |
(DialogBox new
|
|
373 |
addTextLabel:'Please enter your name:';
|
|
374 |
addInputFieldOn:firstName;
|
122
|
375 |
addVerticalSpace;
|
121
|
376 |
addInputFieldOn:lastName;
|
|
377 |
addAbortButton;
|
|
378 |
addOkButton;
|
|
379 |
open
|
|
380 |
) accepted ifTrue:[
|
|
381 |
Transcript showCr:'entered: ', firstName value , ' ' , lastName value
|
|
382 |
]
|
|
383 |
|
120
|
384 |
|
121
|
385 |
constructing a dialog from other elements:
|
|
386 |
|
|
387 |
adding a fileSelectionList:
|
|
388 |
(since the dialog adds the component with its preferred extent,
|
|
389 |
ignoring the 300-height, this looks ugly ...
|
|
390 |
... especially when resized vertically)
|
|
391 |
|
|
392 |
|top l scr fileName|
|
|
393 |
|
|
394 |
fileName := '' asValue.
|
|
395 |
|
|
396 |
top := DialogBox new.
|
120
|
397 |
|
146
|
398 |
l := FileSelectionList new.
|
121
|
399 |
l useIndex:false.
|
|
400 |
l doubleClickAction:[:name | top okPressed].
|
131
|
401 |
l action:[:name | fileName value:name].
|
121
|
402 |
scr := ScrollableView forView:l.
|
|
403 |
scr extent:(1.0 @ 300).
|
|
404 |
|
|
405 |
top addComponent:scr.
|
|
406 |
top addAbortButton; addOkButton.
|
|
407 |
top openModal.
|
|
408 |
|
|
409 |
top accepted ifTrue:[
|
|
410 |
Transcript show:'fileName: '; showCr:fileName value storeString.
|
|
411 |
]
|
|
412 |
|
|
413 |
same, looks better, since the height is made larger (not using
|
|
414 |
fileLists preferredExtent):
|
|
415 |
|
|
416 |
|top l scr fileName|
|
|
417 |
|
|
418 |
fileName := '' asValue.
|
|
419 |
|
|
420 |
top := DialogBox new.
|
|
421 |
|
146
|
422 |
l := FileSelectionList new.
|
121
|
423 |
l useIndex:false.
|
|
424 |
l doubleClickAction:[:name | top okPressed].
|
131
|
425 |
l action:[:name | fileName value:name].
|
121
|
426 |
scr := ScrollableView forView:l.
|
|
427 |
|
|
428 |
top addComponent:scr withExtent:300@300.
|
|
429 |
top addAbortButton; addOkButton.
|
|
430 |
top openModal.
|
120
|
431 |
|
121
|
432 |
top accepted ifTrue:[
|
|
433 |
Transcript show:'fileName: '; showCr:fileName value storeString.
|
|
434 |
]
|
|
435 |
|
|
436 |
|
|
437 |
again, setting the boxes initial size and fixing it
|
130
|
438 |
(let it ignore the components' preferredExtent):
|
121
|
439 |
|
|
440 |
|top fixFrame l scr fileName|
|
|
441 |
|
|
442 |
fileName := '' asValue.
|
|
443 |
|
|
444 |
top := DialogBox new.
|
|
445 |
top extent:300@300.
|
120
|
446 |
|
121
|
447 |
fixFrame := View new.
|
|
448 |
fixFrame extent:(1.0 @ 300).
|
|
449 |
|
146
|
450 |
l := FileSelectionList new.
|
121
|
451 |
l useIndex:false.
|
|
452 |
l doubleClickAction:[:name | top okPressed].
|
131
|
453 |
l action:[:name | fileName value:name].
|
121
|
454 |
scr := ScrollableView forView:l.
|
146
|
455 |
scr origin:0.0@0.0 corner:1.0@1.0.
|
|
456 |
fixFrame add:scr.
|
121
|
457 |
|
|
458 |
top addComponent:fixFrame.
|
|
459 |
top addAbortButton; addOkButton.
|
|
460 |
top openModal.
|
|
461 |
|
|
462 |
top accepted ifTrue:[
|
|
463 |
Transcript show:'fileName: '; showCr:fileName value storeString.
|
|
464 |
]
|
118
|
465 |
|
|
466 |
|
|
467 |
adding a panel with checkBoxes:
|
|
468 |
|
121
|
469 |
|top panel b value1 value2 value3 value4|
|
118
|
470 |
|
121
|
471 |
value1 := true asValue.
|
|
472 |
value2 := false asValue.
|
|
473 |
value3 := false asValue.
|
|
474 |
value4 := true asValue.
|
118
|
475 |
|
121
|
476 |
top := DialogBox new.
|
|
477 |
top extent:200@300.
|
118
|
478 |
|
121
|
479 |
panel := VerticalPanelView new.
|
118
|
480 |
|
121
|
481 |
b := CheckBox on:value1. b label:'check1'.
|
|
482 |
panel addSubView:b.
|
118
|
483 |
|
121
|
484 |
b := CheckBox on:value2. b label:'check2'.
|
|
485 |
panel addSubView:b.
|
118
|
486 |
|
121
|
487 |
b := CheckBox on:value3. b label:'check3'.
|
|
488 |
panel addSubView:b.
|
|
489 |
|
|
490 |
b := CheckBox on:value4. b label:'check4'.
|
|
491 |
panel addSubView:b.
|
118
|
492 |
|
121
|
493 |
top addComponent:panel.
|
|
494 |
top addAbortButton; addOkButton.
|
|
495 |
top open.
|
118
|
496 |
|
121
|
497 |
top accepted ifTrue:[
|
|
498 |
Transcript show:'value1: '; showCr:value1 value.
|
|
499 |
Transcript show:'value2: '; showCr:value2 value.
|
|
500 |
Transcript show:'value3: '; showCr:value3 value.
|
|
501 |
Transcript show:'value4: '; showCr:value4 value.
|
|
502 |
]
|
118
|
503 |
|
120
|
504 |
same, using a more convenient interface:
|
|
505 |
|
121
|
506 |
|box value1 value2 value3 value4|
|
120
|
507 |
|
121
|
508 |
value1 := true asValue.
|
|
509 |
value2 := false asValue.
|
|
510 |
value3 := false asValue.
|
|
511 |
value4 := true asValue.
|
120
|
512 |
|
121
|
513 |
box := DialogBox new.
|
|
514 |
box extent:200@300.
|
120
|
515 |
|
121
|
516 |
box addCheckBox:'check1' on:value1.
|
125
|
517 |
box addVerticalSpace.
|
121
|
518 |
box addCheckBox:'check2' on:value2.
|
125
|
519 |
box addVerticalSpace.
|
121
|
520 |
box addCheckBox:'check3' on:value3.
|
125
|
521 |
box addVerticalSpace.
|
121
|
522 |
box addCheckBox:'check4' on:value4.
|
120
|
523 |
|
121
|
524 |
box addAbortButton; addOkButton.
|
|
525 |
box open.
|
120
|
526 |
|
121
|
527 |
box accepted ifTrue:[
|
|
528 |
Transcript show:'value1: '; showCr:value1 value.
|
|
529 |
Transcript show:'value2: '; showCr:value2 value.
|
|
530 |
Transcript show:'value3: '; showCr:value3 value.
|
|
531 |
Transcript show:'value4: '; showCr:value4 value.
|
|
532 |
]
|
126
|
533 |
|
|
534 |
|
164
|
535 |
adding two panels in a frame:
|
|
536 |
|
|
537 |
|box frame vPanel1 vPanel2 m1 m2 m3 m4 chk ef|
|
|
538 |
|
|
539 |
box := Dialog new.
|
|
540 |
box label:'example'.
|
|
541 |
|
|
542 |
frame := FramedBox label:'frame'.
|
|
543 |
|
|
544 |
vPanel1 := VerticalPanelView origin:0.0@0.0 corner:0.5@1.0 in:frame.
|
|
545 |
vPanel1 horizontalLayout:#leftSpace.
|
|
546 |
vPanel1 verticalLayout:#top.
|
|
547 |
|
|
548 |
vPanel2 := VerticalPanelView origin:0.5@0.0 corner:1.0@1.0 in:frame.
|
|
549 |
vPanel2 horizontalLayout:#leftSpace.
|
|
550 |
vPanel2 verticalLayout:#top.
|
|
551 |
|
|
552 |
m1 := true asValue.
|
|
553 |
m2 := true asValue.
|
|
554 |
m3 := true asValue.
|
|
555 |
m4 := 'hello' asValue.
|
|
556 |
|
|
557 |
vPanel1 add:(Label label:'check1').
|
|
558 |
vPanel1 add:(Label label:'m2').
|
|
559 |
vPanel1 add:(Label label:'m3').
|
|
560 |
vPanel1 add:(Label label:'enter').
|
|
561 |
vPanel1 add:(Label label:'lbl1').
|
|
562 |
vPanel1 add:(Label label:'lbl2').
|
|
563 |
|
|
564 |
vPanel2 add:(chk := CheckToggle on:m1).
|
|
565 |
box makeTabable:chk.
|
|
566 |
|
|
567 |
vPanel2 add:(chk := CheckToggle on:m2).
|
|
568 |
box makeTabable:chk.
|
|
569 |
|
|
570 |
vPanel2 add:(chk := CheckToggle on:m3).
|
|
571 |
box makeTabable:chk.
|
|
572 |
|
|
573 |
vPanel2 add:(chk := CheckToggle on:m3).
|
|
574 |
box makeTabable:chk.
|
|
575 |
|
|
576 |
vPanel2 add:(chk := CheckToggle on:m3).
|
|
577 |
box makeTabable:chk.
|
|
578 |
|
|
579 |
vPanel2 add:(ef := EditField on:m4).
|
|
580 |
ef immediateAccept:true.
|
|
581 |
box makeTabable:ef.
|
|
582 |
|
|
583 |
box addComponent:frame.
|
|
584 |
|
|
585 |
box addAbortButton; addOkButton.
|
|
586 |
box openModal.
|
|
587 |
box accepted ifTrue:[
|
|
588 |
Transcript showCr:'accepted with:'.
|
|
589 |
Transcript showCr:' m1: ' , m1 value printString.
|
|
590 |
Transcript showCr:' m2: ' , m2 value printString.
|
|
591 |
Transcript showCr:' m3: ' , m3 value printString.
|
|
592 |
Transcript showCr:' m4: ' , m4 value printString.
|
|
593 |
]
|
|
594 |
|
|
595 |
|
|
596 |
|
126
|
597 |
a full example:
|
|
598 |
|
|
599 |
|box warnSTX allowUnderscore immutableArrays logDoits
|
|
600 |
listOfLanguages listOfStyles styleNames
|
|
601 |
frame panel c resourceDir dir |
|
|
602 |
|
|
603 |
warnSTX := Compiler warnSTXSpecials asValue.
|
|
604 |
allowUnderscore := Compiler allowUnderscoreInIdentifier asValue.
|
|
605 |
immutableArrays := Compiler arraysAreImmutable asValue.
|
|
606 |
|
|
607 |
logDoits := Smalltalk logDoits asValue.
|
|
608 |
|
|
609 |
listOfLanguages := SelectionInList with:#('english'
|
128
|
610 |
'french'
|
126
|
611 |
'german'
|
128
|
612 |
'italian'
|
126
|
613 |
'spanish'
|
|
614 |
).
|
|
615 |
listOfLanguages selection:(Language asString).
|
|
616 |
|
|
617 |
|
|
618 |
resourceDir := Smalltalk getSystemFileName:'resources'.
|
|
619 |
dir := FileDirectory directoryNamed:resourceDir.
|
|
620 |
|
|
621 |
styleNames := dir select:[:aFileName | aFileName endsWith:'.style'].
|
|
622 |
styleNames := styleNames collect:[:aFileName | aFileName copyWithoutLast:6].
|
128
|
623 |
listOfStyles := SelectionInList with:styleNames sort.
|
126
|
624 |
listOfStyles selection:(View defaultStyle asString).
|
|
625 |
|
|
626 |
box := Dialog new.
|
|
627 |
box label:'Settings'.
|
|
628 |
|
|
629 |
frame := FramedBox label:'Compiler'.
|
|
630 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:frame.
|
|
631 |
panel horizontalLayout:#leftSpace.
|
|
632 |
|
|
633 |
panel add:((CheckBox on:warnSTX) label:'warn about ST/X language extensions'; resize).
|
|
634 |
panel add:((CheckBox on:allowUnderscore) label:'allow underscore in identifiers'; resize).
|
|
635 |
panel add:((CheckBox on:immutableArrays) label:'literal arrays are immutable'; resize).
|
|
636 |
box addComponent:frame.
|
|
637 |
|
|
638 |
frame := FramedBox label:'Misc'.
|
|
639 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:frame.
|
|
640 |
panel horizontalLayout:#leftSpace.
|
|
641 |
|
|
642 |
panel add:((CheckBox on:logDoits) label:'log doIts in changes file'; resize).
|
|
643 |
box addComponent:frame.
|
|
644 |
|
|
645 |
frame := FramedBox label:'Language'.
|
|
646 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:frame.
|
|
647 |
panel horizontalLayout:#leftSpace.
|
|
648 |
|
128
|
649 |
panel add:((PopUpList on:listOfLanguages) width:0.5).
|
126
|
650 |
box addComponent:frame.
|
|
651 |
|
|
652 |
frame := FramedBox label:'Style'.
|
|
653 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:frame.
|
|
654 |
panel horizontalLayout:#leftSpace.
|
|
655 |
|
128
|
656 |
panel add:((PopUpList on:listOfStyles) width:0.5).
|
126
|
657 |
box addComponent:frame.
|
|
658 |
|
|
659 |
box addAbortButton; addOkButton.
|
|
660 |
box showAtPointer.
|
|
661 |
|
|
662 |
box accepted ifTrue:[
|
|
663 |
Transcript topView withCursor:Cursor wait do:[
|
|
664 |
Compiler warnSTXSpecials:warnSTX value.
|
|
665 |
Compiler allowUnderscoreInIdentifier:allowUnderscore value.
|
|
666 |
Compiler arraysAreImmutable:immutableArrays value.
|
|
667 |
|
|
668 |
Smalltalk logDoits:logDoits value.
|
|
669 |
|
|
670 |
Transcript showCr:'change language to ' , listOfLanguages selection , ' ...'.
|
|
671 |
Smalltalk at:#Language put:listOfLanguages selection asSymbol.
|
|
672 |
Smalltalk changed:#Language.
|
|
673 |
ResourcePack flushCachedResourcePacks.
|
|
674 |
|
|
675 |
Transcript showCr:'change style to ' , listOfStyles selection , ' ...'.
|
|
676 |
View defaultStyle:listOfStyles selection asSymbol.
|
|
677 |
]
|
|
678 |
]
|
76
|
679 |
"
|
|
680 |
!
|
|
681 |
|
|
682 |
copyright
|
|
683 |
"
|
|
684 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
685 |
All Rights Reserved
|
|
686 |
|
|
687 |
This software is furnished under a license and may be used
|
|
688 |
only in accordance with the terms of that license and with the
|
|
689 |
inclusion of the above copyright notice. This software may not
|
|
690 |
be provided or otherwise made available to, or used by, any
|
|
691 |
other person. No title to or ownership of the software is
|
|
692 |
hereby transferred.
|
|
693 |
"
|
|
694 |
! !
|
|
695 |
|
128
|
696 |
!DialogBox class methodsFor:'common dialogs'!
|
100
|
697 |
|
|
698 |
request:aString
|
|
699 |
"launch a Dialog, which allows user to enter something.
|
|
700 |
Return the entered string (may be empty string)
|
|
701 |
or nil (if cancel was pressed)"
|
|
702 |
|
|
703 |
^ self
|
|
704 |
request:aString
|
|
705 |
displayAt:nil
|
|
706 |
centered:true
|
|
707 |
action:nil
|
|
708 |
initialAnswer:''
|
|
709 |
|
|
710 |
"
|
|
711 |
Dialog
|
|
712 |
request:'enter a string:'
|
|
713 |
"
|
|
714 |
!
|
|
715 |
|
|
716 |
request:aString initialAnswer:initial
|
|
717 |
"launch a Dialog, which allows user to enter something.
|
|
718 |
Return the entered string (may be empty string) or nil (if cancel was pressed)"
|
|
719 |
|
|
720 |
^ self
|
|
721 |
request:aString
|
|
722 |
displayAt:nil
|
|
723 |
centered:true
|
|
724 |
action:nil
|
|
725 |
initialAnswer:initial
|
|
726 |
|
|
727 |
"
|
|
728 |
Dialog
|
|
729 |
request:'enter a string:'
|
|
730 |
initialAnswer:'the default'
|
|
731 |
"
|
|
732 |
!
|
|
733 |
|
118
|
734 |
request:aString initialAnswer:initial onCancel:cancelAction
|
|
735 |
"launch a Dialog, which allows user to enter something.
|
|
736 |
Return the entered string (may be empty string)
|
|
737 |
or cancelValue (if cancel was pressed)"
|
|
738 |
|
|
739 |
|val|
|
|
740 |
|
|
741 |
val :=self
|
|
742 |
request:aString
|
|
743 |
displayAt:nil
|
|
744 |
centered:true
|
|
745 |
action:[:result | ^ result]
|
|
746 |
initialAnswer:initial.
|
|
747 |
|
|
748 |
^ cancelAction value
|
|
749 |
|
|
750 |
"
|
|
751 |
Dialog
|
|
752 |
request:'enter a string:'
|
|
753 |
initialAnswer:'the default'
|
|
754 |
onCancel:['foooo']
|
|
755 |
"
|
|
756 |
!
|
|
757 |
|
100
|
758 |
request:aString displayAt:aPoint initialAnswer:initial
|
|
759 |
"launch a Dialog, which allows user to enter something.
|
|
760 |
Return the entered string (may be empty string) or nil (if cancel was pressed)"
|
|
761 |
|
|
762 |
^ self
|
|
763 |
request:aString
|
|
764 |
displayAt:aPoint
|
|
765 |
centered:true
|
|
766 |
action:nil
|
|
767 |
initialAnswer:initial
|
|
768 |
|
|
769 |
"
|
|
770 |
Dialog
|
|
771 |
request:'enter a string:'
|
|
772 |
displayAt:(50 @ 50)
|
|
773 |
initialAnswer:'the default'
|
|
774 |
"
|
|
775 |
!
|
|
776 |
|
120
|
777 |
confirm:aString
|
|
778 |
"launch a Dialog, which allows user to enter yes or no.
|
|
779 |
return true for yes, false for no"
|
|
780 |
|
|
781 |
|box answer|
|
|
782 |
|
|
783 |
box := YesNoBox title:aString.
|
|
784 |
box yesAction:[answer := true] noAction:[answer := false].
|
|
785 |
box showAtPointer.
|
|
786 |
box yesAction:nil noAction:nil.
|
|
787 |
^ answer
|
|
788 |
|
|
789 |
"
|
|
790 |
Dialog confirm:'really ?'
|
|
791 |
"
|
|
792 |
!
|
|
793 |
|
100
|
794 |
request:aString displayAt:aPoint centered:centered action:resultAction initialAnswer:initial
|
|
795 |
"launch a Dialog, which allows user to enter a string.
|
|
796 |
Return the string (may be empty string) or nil (if cancel was pressed)"
|
|
797 |
|
|
798 |
|box|
|
|
799 |
|
|
800 |
box := EnterBox title:aString.
|
|
801 |
box initialText:initial.
|
|
802 |
resultAction isNil ifTrue:[
|
|
803 |
box action:[:val | ^ val]
|
|
804 |
] ifFalse:[
|
|
805 |
box action:[:val | ^ resultAction value:val]
|
|
806 |
].
|
|
807 |
aPoint notNil ifTrue:[
|
|
808 |
box showAt:aPoint
|
|
809 |
] ifFalse:[
|
|
810 |
box showAtPointer
|
|
811 |
].
|
133
|
812 |
^ '' "/ used to be nil - but that is incompatible to ST-80
|
100
|
813 |
|
|
814 |
"
|
|
815 |
Dialog request:'enter a string:'
|
|
816 |
displayAt:0@0
|
|
817 |
centered:true
|
|
818 |
action:[:result | result printNewline]
|
|
819 |
initialAnswer:'the default'
|
|
820 |
"
|
|
821 |
!
|
|
822 |
|
|
823 |
confirmWithCancel:aString
|
|
824 |
"launch a Dialog, which allows user to enter yes, no and cancel.
|
|
825 |
return true for 'yes', false for 'no', nil for 'cancel'"
|
|
826 |
|
|
827 |
|box answer|
|
|
828 |
|
|
829 |
box := OptionBox title:aString numberOfOptions:3.
|
|
830 |
box buttonTitles:(self classResources array:
|
|
831 |
#('cancel'
|
|
832 |
'no'
|
|
833 |
'yes')
|
|
834 |
)
|
|
835 |
actions:(Array with:[answer := nil]
|
|
836 |
with:[answer := false]
|
|
837 |
with:[answer := true]
|
|
838 |
).
|
|
839 |
box showAtPointer.
|
|
840 |
box actions:nil.
|
|
841 |
^ answer
|
|
842 |
|
|
843 |
"
|
|
844 |
Dialog confirmWithCancel:'really ?' nil
|
|
845 |
"
|
|
846 |
!
|
|
847 |
|
133
|
848 |
confirm:aString initialAnswer:what
|
|
849 |
"launch a Dialog, which allows user to enter yes or no.
|
|
850 |
return true for yes, false for no"
|
|
851 |
|
|
852 |
|box answer|
|
|
853 |
|
|
854 |
box := YesNoBox title:aString.
|
|
855 |
box yesAction:[answer := true] noAction:[answer := false].
|
|
856 |
what == false ifTrue:[
|
|
857 |
box okButton isReturnButton:false.
|
|
858 |
box acceptReturnAsOK:false.
|
|
859 |
].
|
|
860 |
box showAtPointer.
|
|
861 |
box yesAction:nil noAction:nil.
|
|
862 |
^ answer
|
|
863 |
|
|
864 |
"
|
|
865 |
Dialog confirm:'really ?' initialAnswer:false
|
|
866 |
"
|
|
867 |
!
|
|
868 |
|
100
|
869 |
information:aString
|
|
870 |
"launch a Dialog to tell user something"
|
|
871 |
|
|
872 |
(InfoBox title:aString) showAtPointer
|
|
873 |
|
|
874 |
"
|
|
875 |
Dialog information:'help'
|
|
876 |
"
|
|
877 |
!
|
|
878 |
|
|
879 |
warn:aString
|
|
880 |
"launch a Dialog to warn user"
|
|
881 |
|
|
882 |
(WarningBox title:aString) showAtPointer
|
|
883 |
|
|
884 |
"
|
|
885 |
Dialog warn:'help'
|
|
886 |
"
|
|
887 |
!
|
|
888 |
|
|
889 |
requestFileName:titleString default:defaultName
|
|
890 |
"launch a Dialog, which allows user to enter a filename.
|
|
891 |
The box will not allow pressing 'ok' without an entered string.
|
|
892 |
Return the pathname string consisting of the full pathname of the filename,
|
|
893 |
or an empty string (if cancel was pressed)."
|
|
894 |
|
|
895 |
^ self requestFileName:titleString
|
|
896 |
default:defaultName
|
|
897 |
version:nil
|
|
898 |
ifFail:''
|
|
899 |
|
|
900 |
"
|
|
901 |
Dialog requestFileName:'enter a fileName:' default:''
|
|
902 |
Dialog requestFileName:'enter a fileName:' default:'Makefile.bak'
|
|
903 |
"
|
|
904 |
!
|
|
905 |
|
|
906 |
requestFileName:titleString default:defaultName version:versionSymbol
|
|
907 |
"launch a Dialog, which allows user to enter a filename.
|
|
908 |
The box will not allow pressing 'ok' without an entered string.
|
|
909 |
Return the pathname string or the empty string if cancel was pressed.
|
|
910 |
The version argument is ignored on Unix, but may at some time in the
|
|
911 |
future be used on systems like VMS (which support file versioning)."
|
|
912 |
|
|
913 |
^ self requestFileName:titleString
|
|
914 |
default:defaultName
|
|
915 |
version:versionSymbol
|
|
916 |
ifFail:''
|
|
917 |
|
|
918 |
"
|
|
919 |
Dialog requestFileName:'enter a fileName:'
|
|
920 |
default:''
|
|
921 |
version:nil
|
|
922 |
"
|
|
923 |
!
|
|
924 |
|
|
925 |
requestFileName:titleString default:defaultName version:versionSymbol ifFail:failBlock
|
|
926 |
"launch a Dialog, which allows user to enter a filename.
|
|
927 |
The box will not allow pressing 'ok' without an entered string.
|
|
928 |
Return the string or the value of failBlock if cancel was pressed.
|
|
929 |
The version argument is ignored on Unix, but may at some time in the
|
|
930 |
future be used on systems like VMS (which support file versioning)."
|
|
931 |
|
|
932 |
|box|
|
|
933 |
|
|
934 |
box := FileSelectionBox title:titleString.
|
|
935 |
box initialText:defaultName.
|
|
936 |
box action:[:name | ^ name].
|
|
937 |
box showAtPointer.
|
|
938 |
box action:nil.
|
|
939 |
^ failBlock value
|
|
940 |
|
|
941 |
"
|
|
942 |
Dialog requestFileName:'enter a fileName:'
|
|
943 |
default:''
|
|
944 |
version:nil
|
|
945 |
ifFail:['none']
|
|
946 |
"
|
|
947 |
!
|
|
948 |
|
|
949 |
requestFileName:titleString default:defaultName ok:okText abort:abortText pattern:pattern
|
|
950 |
"launch a Dialog, which allows user to enter a filename.
|
|
951 |
The box will show okText in its okButton, abortText in the abortButton.
|
|
952 |
The matchPattern is set to pattern initially.
|
|
953 |
Return the string or nil if cancel was pressed."
|
|
954 |
|
|
955 |
|box|
|
|
956 |
|
|
957 |
box := FileSelectionBox
|
|
958 |
title:titleString
|
|
959 |
okText:okText
|
|
960 |
abortText:abortText
|
|
961 |
action:[:fileName | ^ fileName].
|
|
962 |
box pattern:pattern.
|
|
963 |
box initialText:defaultName.
|
|
964 |
box showAtPointer.
|
|
965 |
box action:nil.
|
|
966 |
^ nil
|
|
967 |
|
|
968 |
"
|
|
969 |
Dialog requestFileName:'enter a fileName:'
|
|
970 |
default:''
|
|
971 |
ok:'yeah'
|
|
972 |
abort:'oh, no'
|
|
973 |
pattern:'*.st'
|
|
974 |
"
|
133
|
975 |
!
|
|
976 |
|
|
977 |
choose:aString labels:buttonLabels values:values default:default
|
|
978 |
"launch a Dialog, which allows user to enter any of buttonLabels.
|
|
979 |
Returning a corresponding value from the values-array."
|
|
980 |
|
|
981 |
|box answer idx|
|
|
982 |
|
|
983 |
box := OptionBox title:aString numberOfOptions:buttonLabels size.
|
|
984 |
box buttonTitles:(self classResources array:buttonLabels)
|
|
985 |
actions:(values collect:[:val | [answer := val]]).
|
|
986 |
answer := default.
|
|
987 |
box buttons last isReturnButton:false.
|
|
988 |
idx := values indexOf:default.
|
|
989 |
idx ~~ 0 ifTrue:[box defaultButtonIndex:idx].
|
|
990 |
box showAtPointer.
|
|
991 |
box actions:nil.
|
|
992 |
^ answer
|
|
993 |
|
|
994 |
"
|
|
995 |
Dialog
|
|
996 |
choose:'choose any'
|
|
997 |
labels:#('one' 'two' 'three' 'four')
|
|
998 |
values:#(1 2 3 4)
|
|
999 |
default:2
|
|
1000 |
"
|
|
1001 |
"
|
|
1002 |
Dialog
|
|
1003 |
choose:'choose any'
|
|
1004 |
labels:#('one' 'two' 'three' 'four')
|
|
1005 |
values:#(1 2 3 4)
|
|
1006 |
default:nil
|
|
1007 |
"
|
100
|
1008 |
! !
|
|
1009 |
|
76
|
1010 |
!DialogBox methodsFor:'user actions'!
|
|
1011 |
|
128
|
1012 |
doAccept
|
|
1013 |
"let all components accept (i.e. update their model from the values),
|
|
1014 |
then set my accept value to true.
|
|
1015 |
This is confusing: this method was originally called #accept,
|
|
1016 |
but renamed for compatibility with ST-80, where #accept returns the
|
|
1017 |
accept-valueHolder (which looks like a bad name to me ...)."
|
121
|
1018 |
|
|
1019 |
addedComponents notNil ifTrue:[
|
|
1020 |
addedComponents do:[:aComponent |
|
|
1021 |
(aComponent respondsTo:#accept) ifTrue:[
|
|
1022 |
aComponent accept
|
|
1023 |
]
|
|
1024 |
].
|
|
1025 |
].
|
128
|
1026 |
acceptValue value:true.
|
121
|
1027 |
!
|
|
1028 |
|
125
|
1029 |
lastFieldLeft
|
|
1030 |
"if the dialog involves input fields, this is called
|
|
1031 |
when the last field is left by Return-key or NextField-key"
|
|
1032 |
|
|
1033 |
acceptOnLeave ifTrue:[
|
128
|
1034 |
acceptValue value:true.
|
125
|
1035 |
self okPressed
|
|
1036 |
].
|
|
1037 |
!
|
|
1038 |
|
76
|
1039 |
okPressed
|
128
|
1040 |
"sent by the okButton; user pressed ok-button
|
|
1041 |
- make myself invisible and if an action was specified do it"
|
76
|
1042 |
|
122
|
1043 |
okButton notNil ifTrue:[okButton turnOffWithoutRedraw].
|
128
|
1044 |
self doAccept.
|
133
|
1045 |
|
155
|
1046 |
"/ actually, only hides if I have been opened modal
|
|
1047 |
self hideAndEvaluate:okAction.
|
76
|
1048 |
!
|
|
1049 |
|
|
1050 |
abortPressed
|
128
|
1051 |
"sent by the cancel button; user pressed abort button
|
|
1052 |
- hide myself and evaluate okAction"
|
76
|
1053 |
|
95
|
1054 |
abortButton turnOffWithoutRedraw.
|
128
|
1055 |
acceptValue value:false.
|
155
|
1056 |
|
|
1057 |
"/ actually, only hides if I have been opened modal
|
76
|
1058 |
self hideAndEvaluate:abortAction
|
|
1059 |
!
|
|
1060 |
|
|
1061 |
keyPress:aKey x:x y:y
|
|
1062 |
"return-key dublicates ok-function if acceptReturnAsOK is true"
|
|
1063 |
|
|
1064 |
acceptReturnAsOK ifTrue:[
|
|
1065 |
(aKey == #Return) ifTrue:[^ self okPressed]
|
|
1066 |
].
|
|
1067 |
super keyPress:aKey x:x y:y
|
|
1068 |
! !
|
|
1069 |
|
120
|
1070 |
!DialogBox methodsFor:'construction-adding'!
|
|
1071 |
|
|
1072 |
addButton:aButton after:someOtherButtonOrNil
|
|
1073 |
"add a button in the buttonPanel.
|
|
1074 |
If the argument someOtherButtonOrNil is nil, the button is
|
|
1075 |
added at the end."
|
|
1076 |
|
162
|
1077 |
|h|
|
|
1078 |
|
120
|
1079 |
buttonPanel addSubView:aButton after:someOtherButtonOrNil.
|
|
1080 |
buttonPanel subViews size > 1 ifTrue:[
|
130
|
1081 |
buttonPanel horizontalLayout:#fitSpace.
|
120
|
1082 |
].
|
162
|
1083 |
(h := (aButton heightIncludingBorder + (ViewSpacing * 2))) > buttonPanel topInset ifTrue:[
|
|
1084 |
buttonPanel topInset:h negated
|
|
1085 |
].
|
122
|
1086 |
^ aButton
|
120
|
1087 |
!
|
|
1088 |
|
162
|
1089 |
addOkButton:aButton
|
|
1090 |
"add an already created okButton - to be sent from redefined initialize
|
|
1091 |
methods in subclasses or when creating a box programmatically.
|
|
1092 |
Returns the button."
|
|
1093 |
|
|
1094 |
okButton := aButton.
|
|
1095 |
aButton model:self; change:#okPressed.
|
|
1096 |
^ self addButton:aButton.
|
|
1097 |
|
|
1098 |
"Modified: 17.9.1995 / 20:20:41 / claus"
|
|
1099 |
!
|
|
1100 |
|
122
|
1101 |
addOkButtonLabelled:buttonLabel
|
|
1102 |
"create an okButton with a label - to be sent from redefined initialize
|
|
1103 |
methods in subclasses or when creating a box programmatically.
|
|
1104 |
A nil argument creates one with the default text.
|
|
1105 |
Returns the button."
|
|
1106 |
|
162
|
1107 |
|aButton|
|
|
1108 |
|
|
1109 |
aButton := Button okButton.
|
|
1110 |
buttonLabel notNil ifTrue:[aButton label:buttonLabel].
|
|
1111 |
aButton isReturnButton:acceptReturnAsOK.
|
|
1112 |
^ self addOkButton:aButton.
|
|
1113 |
|
|
1114 |
"Modified: 17.9.1995 / 20:19:49 / claus"
|
122
|
1115 |
!
|
|
1116 |
|
120
|
1117 |
addOkButton
|
|
1118 |
"create an okButton - to be sent from redefined initialize
|
122
|
1119 |
methods in subclasses or when creating a box programmatically.
|
|
1120 |
Returns the button."
|
120
|
1121 |
|
122
|
1122 |
^ self addOkButtonLabelled:nil
|
120
|
1123 |
!
|
|
1124 |
|
|
1125 |
addButton:aButton
|
122
|
1126 |
"add a button into the buttonPanel.
|
|
1127 |
Returns the button."
|
|
1128 |
|
|
1129 |
^ self addButton:aButton after:nil
|
|
1130 |
!
|
120
|
1131 |
|
162
|
1132 |
addAbortButton:aButton
|
|
1133 |
"add an already created abortButton - to be sent from redefined initialize
|
|
1134 |
methods in subclasses or when creating a box programmatically.
|
|
1135 |
Returns the button."
|
|
1136 |
|
|
1137 |
abortButton := aButton.
|
|
1138 |
aButton model:self; change:#abortPressed.
|
|
1139 |
^ self addButton:aButton.
|
|
1140 |
|
|
1141 |
"Created: 17.9.1995 / 20:17:26 / claus"
|
|
1142 |
!
|
|
1143 |
|
122
|
1144 |
addAbortButtonLabelled:buttonLabel
|
|
1145 |
"create an abortButton with a label - to be sent from redefined initialize
|
|
1146 |
methods in subclasses or when creating a box programmatically.
|
|
1147 |
A nil argument creates one with the default label.
|
|
1148 |
Returns the button."
|
|
1149 |
|
162
|
1150 |
|aButton|
|
|
1151 |
|
|
1152 |
aButton := Button abortButton.
|
|
1153 |
buttonLabel notNil ifTrue:[aButton label:buttonLabel].
|
|
1154 |
^ self addAbortButton:aButton
|
|
1155 |
|
|
1156 |
"Modified: 17.9.1995 / 20:18:00 / claus"
|
120
|
1157 |
!
|
76
|
1158 |
|
120
|
1159 |
addAbortButton
|
|
1160 |
"create an abortButton - to be sent from redefined initialize
|
122
|
1161 |
methods in subclasses or when creating a box programmatically.
|
|
1162 |
Returns the button."
|
120
|
1163 |
|
122
|
1164 |
^ self addAbortButtonLabelled:nil
|
120
|
1165 |
!
|
|
1166 |
|
130
|
1167 |
addColumn:aRow fromX:leftX toX:rightX collect:aBlock
|
|
1168 |
"add some elements in a vertical column.
|
|
1169 |
Equally space elements as returned from aBlock."
|
|
1170 |
|
|
1171 |
|helper component|
|
|
1172 |
|
|
1173 |
helper := VerticalPanelView new.
|
|
1174 |
|
|
1175 |
aRow do:[:el |
|
|
1176 |
component := aBlock value:el.
|
|
1177 |
helper add:component.
|
|
1178 |
component resize.
|
|
1179 |
].
|
|
1180 |
|
|
1181 |
helper resize.
|
|
1182 |
self addComponent:helper.
|
|
1183 |
width < helper preferredExtent x ifTrue:[
|
|
1184 |
self width:helper preferredExtent x.
|
|
1185 |
Transcript show:'w now: '; showCr:helper preferredExtent x
|
|
1186 |
].
|
|
1187 |
helper horizontalLayout:#fit.
|
|
1188 |
helper left:leftX asFloat;
|
|
1189 |
right:rightX asFloat.
|
|
1190 |
|
|
1191 |
"
|
|
1192 |
|dialog|
|
|
1193 |
|
|
1194 |
dialog := Dialog new.
|
|
1195 |
dialog
|
|
1196 |
addColumn:#('a' 'b' 'c' 'd')
|
|
1197 |
fromX:0
|
|
1198 |
toX:1
|
|
1199 |
collect:[:label | Label label:label].
|
|
1200 |
|
|
1201 |
dialog addOkButton.
|
|
1202 |
dialog open.
|
|
1203 |
"
|
|
1204 |
|
|
1205 |
"
|
|
1206 |
|dialog y|
|
|
1207 |
|
|
1208 |
dialog := Dialog new.
|
|
1209 |
y := dialog yPosition.
|
|
1210 |
dialog
|
|
1211 |
addColumn:#('a1' 'b1' 'c1' 'd1')
|
|
1212 |
fromX:0
|
|
1213 |
toX:(1/3)
|
|
1214 |
collect:[:label | Label label:label].
|
|
1215 |
|
|
1216 |
dialog yPosition:y.
|
|
1217 |
dialog
|
|
1218 |
addColumn:#('a2' 'b2' 'c2' 'd2')
|
|
1219 |
fromX:(1/3)
|
|
1220 |
toX:(2/3)
|
|
1221 |
collect:[:label | Label label:label].
|
|
1222 |
|
|
1223 |
dialog yPosition:y.
|
|
1224 |
dialog
|
|
1225 |
addColumn:#('a3' 'b3' 'c3' 'd3')
|
|
1226 |
fromX:(2/3)
|
|
1227 |
toX:1
|
|
1228 |
collect:[:label | Label label:label].
|
|
1229 |
|
|
1230 |
dialog addOkButton.
|
|
1231 |
dialog open.
|
|
1232 |
"
|
|
1233 |
!
|
|
1234 |
|
|
1235 |
addRow:aCol fromX:leftX toX:rightX collect:aBlock
|
|
1236 |
"add some elements in a horizontal row.
|
|
1237 |
Equally space elements as returned from aBlock.
|
|
1238 |
Advance y."
|
|
1239 |
|
|
1240 |
|helper component|
|
|
1241 |
|
|
1242 |
helper := HorizontalPanelView new.
|
|
1243 |
|
|
1244 |
aCol do:[:el |
|
|
1245 |
component := aBlock value:el.
|
|
1246 |
component resize.
|
|
1247 |
helper add:component.
|
|
1248 |
].
|
|
1249 |
|
|
1250 |
helper resize.
|
|
1251 |
self addComponent:helper.
|
|
1252 |
width < helper preferredExtent x ifTrue:[
|
|
1253 |
self width:helper preferredExtent x.
|
|
1254 |
Transcript show:'w now: '; showCr:helper preferredExtent x
|
|
1255 |
].
|
|
1256 |
helper verticalLayout:#fit.
|
|
1257 |
helper left:leftX asFloat;
|
|
1258 |
right:rightX asFloat.
|
|
1259 |
|
|
1260 |
"
|
|
1261 |
|dialog|
|
|
1262 |
|
|
1263 |
dialog := Dialog new.
|
|
1264 |
dialog
|
|
1265 |
addRow:#('a' 'b' 'c' 'd')
|
|
1266 |
fromX:0
|
|
1267 |
toX:1
|
|
1268 |
collect:[:label | Label label:label].
|
|
1269 |
|
|
1270 |
dialog addOkButton.
|
|
1271 |
dialog open.
|
|
1272 |
"
|
|
1273 |
|
|
1274 |
"
|
|
1275 |
|dialog|
|
|
1276 |
|
|
1277 |
dialog := Dialog new.
|
|
1278 |
dialog
|
|
1279 |
addRow:#('a1' 'b1' 'c1' 'd1')
|
|
1280 |
fromX:0
|
|
1281 |
toX:1
|
|
1282 |
collect:[:label | Label label:label].
|
|
1283 |
|
|
1284 |
dialog
|
|
1285 |
addRow:#('a2' 'b2' 'c2' 'd2')
|
|
1286 |
fromX:0
|
|
1287 |
toX:0.5
|
|
1288 |
collect:[:label | Label label:label].
|
|
1289 |
|
|
1290 |
dialog
|
|
1291 |
addRow:#('a3' 'b3' 'c3' 'd3')
|
|
1292 |
fromX:0.5
|
|
1293 |
toX:1
|
|
1294 |
collect:[:label | Label label:label].
|
|
1295 |
|
|
1296 |
dialog addOkButton.
|
|
1297 |
dialog open.
|
|
1298 |
"
|
|
1299 |
!
|
|
1300 |
|
133
|
1301 |
makeTabable:aComponentOrSubcomponent
|
|
1302 |
"add a component (usually a subcomponent, of which the dialog
|
|
1303 |
does not know) to the list of tabable ones (i.e. those, that can be
|
|
1304 |
stepped through via FocusNext/FocusPrevious)"
|
|
1305 |
|
|
1306 |
tabableElements isNil ifTrue:[
|
|
1307 |
tabableElements := OrderedCollection new
|
|
1308 |
].
|
|
1309 |
tabableElements add:aComponentOrSubcomponent
|
|
1310 |
!
|
|
1311 |
|
121
|
1312 |
addComponent:aComponent withHeight:height
|
122
|
1313 |
"add a component with some given height and full width.
|
|
1314 |
Returns the component."
|
121
|
1315 |
|
|
1316 |
self basicAddComponent:aComponent.
|
|
1317 |
aComponent height:height.
|
|
1318 |
aComponent origin:0.0@yPosition;
|
|
1319 |
width:1.0;
|
128
|
1320 |
leftInset:leftIndent;
|
|
1321 |
rightInset:rightIndent.
|
131
|
1322 |
yPosition := yPosition + "aComponent" height + ViewSpacing.
|
122
|
1323 |
^ aComponent
|
121
|
1324 |
!
|
|
1325 |
|
|
1326 |
addComponent:aComponent withExtent:ext
|
122
|
1327 |
"add a component with some given extent.
|
|
1328 |
Returns the component."
|
121
|
1329 |
|
132
|
1330 |
|fullSize|
|
|
1331 |
|
121
|
1332 |
self basicAddComponent:aComponent.
|
132
|
1333 |
fullSize := ext + (leftIndent + rightIndent @ 0).
|
|
1334 |
aComponent extent:fullSize.
|
121
|
1335 |
aComponent origin:0.0@yPosition;
|
|
1336 |
leftInset:leftIndent;
|
128
|
1337 |
rightInset:rightIndent.
|
131
|
1338 |
yPosition := yPosition + aComponent height + ViewSpacing.
|
132
|
1339 |
width := fullSize x max:width.
|
122
|
1340 |
^ aComponent
|
121
|
1341 |
!
|
|
1342 |
|
136
|
1343 |
addComponent:aComponent tabable:tabable tabbedComponent:subComponent
|
130
|
1344 |
"add a component with its preferred height and full width.
|
125
|
1345 |
Returns the component."
|
|
1346 |
|
|
1347 |
tabable ifTrue:[
|
|
1348 |
tabableElements isNil ifTrue:[
|
|
1349 |
tabableElements := OrderedCollection new
|
|
1350 |
].
|
136
|
1351 |
tabableElements add:subComponent
|
125
|
1352 |
].
|
|
1353 |
^ self addComponent:aComponent
|
130
|
1354 |
withHeight:(aComponent preferredExtent y).
|
125
|
1355 |
!
|
|
1356 |
|
136
|
1357 |
addComponent:aComponent tabable:tabable
|
|
1358 |
"add a component with its preferred height and full width.
|
|
1359 |
Returns the component."
|
|
1360 |
|
|
1361 |
^ self addComponent:aComponent tabable:tabable tabbedComponent:aComponent
|
|
1362 |
!
|
|
1363 |
|
120
|
1364 |
addComponent:aComponent
|
130
|
1365 |
"add a component with its preferred height and full width.
|
122
|
1366 |
Returns the component."
|
120
|
1367 |
|
125
|
1368 |
^ self addComponent:aComponent tabable:false
|
76
|
1369 |
!
|
|
1370 |
|
120
|
1371 |
addTextLabel:aString
|
|
1372 |
"create a text label - the name has been choosen for ST-80 compatibility;
|
122
|
1373 |
however, ST/X labels allow image labels too.
|
|
1374 |
Returns the label."
|
120
|
1375 |
|
|
1376 |
|l|
|
|
1377 |
|
|
1378 |
l := Label new label:aString.
|
|
1379 |
self addComponent:l.
|
|
1380 |
^ l
|
76
|
1381 |
|
120
|
1382 |
"
|
|
1383 |
|b|
|
|
1384 |
|
|
1385 |
b := DialogBox new.
|
|
1386 |
b addTextLabel:'hello'.
|
|
1387 |
b showAtPointer
|
|
1388 |
"
|
|
1389 |
"
|
|
1390 |
|b|
|
|
1391 |
|
|
1392 |
b := DialogBox new.
|
|
1393 |
b leftIndent:100.
|
|
1394 |
b addTextLabel:'hello'.
|
|
1395 |
b leftIndent:0.
|
|
1396 |
b addTextLabel:'world'.
|
|
1397 |
b showAtPointer
|
|
1398 |
"
|
|
1399 |
"
|
|
1400 |
|b|
|
76
|
1401 |
|
120
|
1402 |
b := DialogBox new.
|
|
1403 |
b addTextLabel:'hello'.
|
|
1404 |
b addTextLabel:'world'.
|
|
1405 |
b addOkButton.
|
|
1406 |
b showAtPointer
|
|
1407 |
"
|
|
1408 |
"
|
|
1409 |
|b|
|
|
1410 |
|
|
1411 |
b := DialogBox new.
|
|
1412 |
b addTextLabel:'hello'.
|
|
1413 |
(b addTextLabel:'world') foregroundColor:Color red.
|
|
1414 |
b addOkButton.
|
|
1415 |
b showAtPointer
|
|
1416 |
"
|
|
1417 |
"
|
|
1418 |
|b|
|
|
1419 |
|
|
1420 |
b := DialogBox new.
|
|
1421 |
b addTextLabel:'hello world\\How about this ?' withCRs.
|
|
1422 |
b addOkButton.
|
|
1423 |
b showAtPointer
|
|
1424 |
"
|
|
1425 |
"
|
|
1426 |
|b|
|
|
1427 |
|
|
1428 |
b := DialogBox new.
|
|
1429 |
b addTextLabel:'hello world\\How about this ?' withCRs.
|
|
1430 |
b addTextLabel:'not bad'.
|
|
1431 |
b addAbortButton.
|
|
1432 |
b addOkButton.
|
|
1433 |
b showAtPointer
|
|
1434 |
"
|
|
1435 |
!
|
|
1436 |
|
125
|
1437 |
addCheckBox:label on:aModel tabable:tabable
|
122
|
1438 |
"create a checkBox with label on aModel and add it.
|
|
1439 |
Returns the box."
|
|
1440 |
|
120
|
1441 |
|b|
|
76
|
1442 |
|
120
|
1443 |
b := CheckBox on:aModel.
|
|
1444 |
b label:label.
|
125
|
1445 |
self addComponent:b tabable:tabable.
|
120
|
1446 |
^ b
|
|
1447 |
!
|
|
1448 |
|
125
|
1449 |
addCheckBox:label on:aModel
|
|
1450 |
"create a checkBox with label on aModel and add it.
|
|
1451 |
Returns the box."
|
|
1452 |
|
|
1453 |
^ self addCheckBox:label on:aModel tabable:true
|
|
1454 |
!
|
|
1455 |
|
136
|
1456 |
addPopUpListOn:aModel tabable:tabable
|
|
1457 |
"create a popUpList on aModel and add it.
|
|
1458 |
Returns the popUpList."
|
|
1459 |
|
|
1460 |
^ self addPopUpList:nil on:aModel tabable:tabable
|
|
1461 |
!
|
|
1462 |
|
|
1463 |
addPopUpList:labelString on:aModel
|
|
1464 |
"create a popUpList with a label on aModel and add it.
|
|
1465 |
Returns the box."
|
|
1466 |
|
|
1467 |
^ self addPopUpList:labelString on:aModel tabable:true
|
|
1468 |
!
|
|
1469 |
|
|
1470 |
addPopUpListOn:aModel
|
|
1471 |
"create a popUpList on aModel and add it.
|
|
1472 |
Returns the box."
|
|
1473 |
|
|
1474 |
^ self addPopUpList:nil on:aModel tabable:true
|
|
1475 |
!
|
|
1476 |
|
|
1477 |
addPopUpList:labelString on:aModel tabable:tabable
|
|
1478 |
"create a popUpList on aModel and add it.
|
|
1479 |
Returns the popUpList."
|
|
1480 |
|
|
1481 |
|p box l|
|
|
1482 |
|
|
1483 |
p := PopUpList on:aModel.
|
|
1484 |
p resize; sizeFixed:true.
|
|
1485 |
labelString notNil ifTrue:[
|
|
1486 |
box := HorizontalPanelView new.
|
157
|
1487 |
box borderWidth:0; horizontalLayout:#rightSpace.
|
136
|
1488 |
box add:(l := Label label:labelString).
|
|
1489 |
l borderWidth:0.
|
|
1490 |
box add:p.
|
|
1491 |
] ifFalse:[
|
|
1492 |
box := p.
|
|
1493 |
].
|
|
1494 |
self addComponent:box tabable:tabable tabbedComponent:p.
|
|
1495 |
^ p
|
|
1496 |
!
|
|
1497 |
|
125
|
1498 |
addInputField:aField tabable:tabable
|
|
1499 |
"add an already created input field; return the field.
|
|
1500 |
If tabable is true, the field is put into a group, to allow
|
|
1501 |
stepping through the fields with #NextField/#PreviousField keys.
|
|
1502 |
Returns the field."
|
|
1503 |
|
|
1504 |
self addComponent:aField tabable:tabable.
|
|
1505 |
tabable ifTrue:[
|
|
1506 |
inputFieldGroup isNil ifTrue:[
|
|
1507 |
inputFieldGroup := EnterFieldGroup new.
|
|
1508 |
inputFieldGroup leaveAction:[self lastFieldLeft].
|
|
1509 |
aField hasKeyboardFocus:true.
|
|
1510 |
].
|
|
1511 |
inputFieldGroup add:aField.
|
|
1512 |
self delegate:(KeyboardForwarder to:inputFieldGroup condition:#noFocus).
|
|
1513 |
].
|
|
1514 |
^ aField
|
|
1515 |
!
|
|
1516 |
|
122
|
1517 |
addInputField:aField
|
|
1518 |
"add an already created input field; return the field.
|
|
1519 |
Returns the field."
|
120
|
1520 |
|
125
|
1521 |
^ self addInputField:aField tabable:true
|
120
|
1522 |
!
|
|
1523 |
|
125
|
1524 |
addInputFieldOn:aModel tabable:tabable
|
122
|
1525 |
"create an input field on aModel and add it.
|
|
1526 |
Returns the field."
|
|
1527 |
|
120
|
1528 |
|f|
|
|
1529 |
|
|
1530 |
f := EditField new.
|
|
1531 |
f model:aModel.
|
125
|
1532 |
self addInputField:f tabable:tabable.
|
120
|
1533 |
^ f
|
125
|
1534 |
!
|
|
1535 |
|
|
1536 |
addInputFieldOn:aModel
|
|
1537 |
"create an input field on aModel and add it.
|
|
1538 |
Returns the field."
|
|
1539 |
|
|
1540 |
^ self addInputFieldOn:aModel tabable:true
|
120
|
1541 |
|
|
1542 |
"
|
125
|
1543 |
|dialog model field|
|
120
|
1544 |
|
|
1545 |
model := '' asValue.
|
|
1546 |
|
|
1547 |
dialog := DialogBox new.
|
|
1548 |
dialog addTextLabel:'enter a string'.
|
121
|
1549 |
field := dialog addInputFieldOn:model.
|
125
|
1550 |
dialog addAbortButton; addOkButton.
|
120
|
1551 |
dialog open.
|
125
|
1552 |
dialog accepted ifTrue:[Transcript showCr:model value].
|
120
|
1553 |
"
|
122
|
1554 |
!
|
|
1555 |
|
128
|
1556 |
addHorizontalLine
|
|
1557 |
"add a horizontal line as separator"
|
|
1558 |
|
|
1559 |
self addComponent:(Separator new extent:1.0 @ 5).
|
|
1560 |
!
|
|
1561 |
|
122
|
1562 |
addVerticalSpace
|
|
1563 |
"add a default vertical space (1 mm)"
|
|
1564 |
|
|
1565 |
self addVerticalSpace:(ViewSpacing).
|
|
1566 |
!
|
|
1567 |
|
|
1568 |
addVerticalSpace:nPixel
|
|
1569 |
"add some pixels of space to the next component"
|
|
1570 |
|
|
1571 |
yPosition := yPosition + nPixel.
|
|
1572 |
!
|
|
1573 |
|
|
1574 |
yPosition
|
|
1575 |
"return the current y position (thats where the next component
|
|
1576 |
will be located)."
|
|
1577 |
|
|
1578 |
^ yPosition
|
|
1579 |
!
|
|
1580 |
|
|
1581 |
yPosition:aNumber
|
|
1582 |
"set the current y position (thats where the next component
|
|
1583 |
will be located)."
|
|
1584 |
|
|
1585 |
yPosition := aNumber.
|
|
1586 |
!
|
|
1587 |
|
|
1588 |
leftIndent:aNumber
|
|
1589 |
"set the left indent (current x position - thats where the next component
|
|
1590 |
will be located)."
|
|
1591 |
|
|
1592 |
leftIndent := aNumber.
|
128
|
1593 |
!
|
|
1594 |
|
|
1595 |
rightIndent:aNumber
|
|
1596 |
"set the right indent"
|
|
1597 |
|
|
1598 |
rightIndent := aNumber.
|
76
|
1599 |
! !
|
|
1600 |
|
|
1601 |
!DialogBox methodsFor:'initialization'!
|
|
1602 |
|
|
1603 |
initialize
|
|
1604 |
|mm|
|
|
1605 |
|
|
1606 |
super initialize.
|
|
1607 |
|
|
1608 |
label := 'Dialog'.
|
128
|
1609 |
acceptValue := false asValue.
|
76
|
1610 |
|
|
1611 |
mm := ViewSpacing.
|
|
1612 |
|
|
1613 |
acceptReturnAsOK := true.
|
125
|
1614 |
acceptOnLeave := true.
|
76
|
1615 |
|
|
1616 |
buttonPanel := HorizontalPanelView in:self.
|
118
|
1617 |
buttonPanel
|
|
1618 |
origin:(0.0 @ 1.0) corner:(1.0 @ 1.0);
|
|
1619 |
bottomInset:mm;
|
|
1620 |
topInset:(font height + mm * 2) negated;
|
|
1621 |
borderWidth:0;
|
130
|
1622 |
horizontalLayout:#spread.
|
118
|
1623 |
|
122
|
1624 |
yPosition := ViewSpacing.
|
128
|
1625 |
leftIndent := rightIndent := ViewSpacing.
|
76
|
1626 |
|
|
1627 |
"
|
|
1628 |
|b|
|
|
1629 |
b := DialogBox new.
|
118
|
1630 |
b addAbortButton;
|
|
1631 |
addOkButton;
|
|
1632 |
showAtPointer
|
76
|
1633 |
"
|
|
1634 |
"
|
|
1635 |
|b|
|
|
1636 |
b := DialogBox new.
|
118
|
1637 |
b addOkButton;
|
|
1638 |
showAtPointer
|
|
1639 |
"
|
76
|
1640 |
"
|
118
|
1641 |
|b|
|
|
1642 |
b := DialogBox new.
|
|
1643 |
b addTextLabel:'hello world';
|
|
1644 |
addOkButton;
|
|
1645 |
showAtPointer
|
|
1646 |
"
|
|
1647 |
"
|
|
1648 |
|b|
|
|
1649 |
b := DialogBox new.
|
|
1650 |
b addTextLabel:'hello world';
|
|
1651 |
addVerticalSpace:50;
|
|
1652 |
addOkButton;
|
|
1653 |
showAtPointer
|
|
1654 |
"
|
76
|
1655 |
!
|
|
1656 |
|
120
|
1657 |
focusSequence
|
125
|
1658 |
"return the elements through which we can step via
|
|
1659 |
NextField/PreviousField keys.
|
|
1660 |
Here we return all tabable fields followed by all buttons in
|
|
1661 |
the panel."
|
|
1662 |
|
|
1663 |
|fields buttons|
|
|
1664 |
|
|
1665 |
tabableElements isNil ifTrue:[
|
|
1666 |
fields := #()
|
|
1667 |
] ifFalse:[
|
|
1668 |
fields := tabableElements
|
|
1669 |
].
|
|
1670 |
buttonPanel notNil ifTrue:[
|
|
1671 |
buttons := buttonPanel subViews.
|
|
1672 |
buttons notNil ifTrue:[
|
|
1673 |
fields := fields , buttonPanel subViews
|
|
1674 |
]
|
|
1675 |
].
|
|
1676 |
^ fields
|
120
|
1677 |
!
|
|
1678 |
|
76
|
1679 |
reAdjustGeometry
|
|
1680 |
"sent late in snapin processing - gives me a chance
|
|
1681 |
to resize for changed font dimensions."
|
|
1682 |
|
|
1683 |
super reAdjustGeometry.
|
|
1684 |
okButton notNil ifTrue:[okButton resize].
|
|
1685 |
abortButton notNil ifTrue:[abortButton resize].
|
|
1686 |
self resize
|
|
1687 |
! !
|
|
1688 |
|
120
|
1689 |
!DialogBox methodsFor:'queries'!
|
118
|
1690 |
|
121
|
1691 |
accepted
|
128
|
1692 |
"after the box has closed:
|
|
1693 |
return true if accepted, false if canceled"
|
125
|
1694 |
|
128
|
1695 |
^ acceptValue value
|
121
|
1696 |
!
|
|
1697 |
|
120
|
1698 |
positionOffset
|
|
1699 |
"return the delta, by which the box should be displayed
|
|
1700 |
from the mouse pointer. Value returned here makes center of
|
|
1701 |
okButton appear under the cursor"
|
118
|
1702 |
|
120
|
1703 |
okButton isNil ifTrue:[
|
|
1704 |
^ super positionOffset
|
118
|
1705 |
].
|
120
|
1706 |
buttonPanel setChildPositionsIfChanged.
|
|
1707 |
^ (okButton originRelativeTo:self) + (okButton extent // 2)
|
118
|
1708 |
!
|
|
1709 |
|
130
|
1710 |
preferredExtent
|
132
|
1711 |
"return my preferred extent.
|
|
1712 |
That is the max component width, or my current width (default);
|
|
1713 |
whichever is larger, by the sum of the components heights."
|
118
|
1714 |
|
120
|
1715 |
|w h p|
|
118
|
1716 |
|
120
|
1717 |
addedComponents notNil ifTrue:[
|
121
|
1718 |
w := addedComponents
|
|
1719 |
inject:0
|
|
1720 |
into:[:max :element |
|
|
1721 |
|eExt|
|
118
|
1722 |
|
130
|
1723 |
eExt := element preferredExtent x. "/ max:element extent x.
|
121
|
1724 |
max max:(eExt + element leftInset)].
|
120
|
1725 |
] ifFalse:[
|
130
|
1726 |
w := super preferredExtent x.
|
120
|
1727 |
].
|
132
|
1728 |
w := w max:width.
|
122
|
1729 |
h := yPosition
|
121
|
1730 |
+ ViewSpacing.
|
118
|
1731 |
|
130
|
1732 |
buttonPanel subViews size ~~ 0 ifTrue:[
|
|
1733 |
p := buttonPanel preferredExtent.
|
121
|
1734 |
w := w max:p x.
|
|
1735 |
h := h
|
|
1736 |
+ p y
|
|
1737 |
+ ViewSpacing.
|
120
|
1738 |
].
|
118
|
1739 |
|
120
|
1740 |
"/ okButton isNil ifTrue:[
|
130
|
1741 |
"/ ^ super preferredExtent
|
120
|
1742 |
"/ ].
|
130
|
1743 |
"/ p := buttonPanel preferredExtent.
|
120
|
1744 |
"/ w := p x.
|
|
1745 |
"/ h := ViewSpacing
|
|
1746 |
"/ + p y
|
|
1747 |
"/ + ViewSpacing.
|
|
1748 |
"/
|
|
1749 |
^ w @ h
|
118
|
1750 |
! !
|
|
1751 |
|
76
|
1752 |
!DialogBox methodsFor:'private'!
|
|
1753 |
|
121
|
1754 |
realize
|
|
1755 |
"if any inputFields where added, activate the first one"
|
|
1756 |
|
|
1757 |
inputFieldGroup notNil ifTrue:[
|
|
1758 |
inputFieldGroup activateFirst
|
|
1759 |
].
|
|
1760 |
super realize
|
|
1761 |
!
|
|
1762 |
|
|
1763 |
basicAddComponent:aComponent
|
|
1764 |
"add a component, dont change its size"
|
|
1765 |
|
|
1766 |
addedComponents isNil ifTrue:[
|
|
1767 |
addedComponents := OrderedCollection new.
|
|
1768 |
].
|
|
1769 |
addedComponents add:aComponent.
|
|
1770 |
self addSubView:aComponent.
|
|
1771 |
!
|
|
1772 |
|
76
|
1773 |
hideAndEvaluate:aBlock
|
155
|
1774 |
"if I am modal, make myself invisible and evaluate aBlock.
|
|
1775 |
If nonModal, stay up, but also evaluate the block."
|
76
|
1776 |
|
155
|
1777 |
(windowGroup notNil and:[windowGroup isModal]) ifTrue:[
|
|
1778 |
self hide.
|
|
1779 |
].
|
76
|
1780 |
aBlock notNil ifTrue:[aBlock value]
|
155
|
1781 |
|
|
1782 |
"Modified: 5.9.1995 / 19:06:33 / claus"
|
76
|
1783 |
! !
|
|
1784 |
|
128
|
1785 |
!DialogBox methodsFor:'accessing-elements'!
|
76
|
1786 |
|
128
|
1787 |
name:element as:name
|
|
1788 |
bindings isNil ifTrue:[
|
|
1789 |
bindings := IdentityDictionary new.
|
|
1790 |
].
|
|
1791 |
bindings at:name put:element
|
|
1792 |
!
|
120
|
1793 |
|
128
|
1794 |
componentAt:name
|
|
1795 |
bindings isNil ifTrue:[^ nil].
|
|
1796 |
^ bindings at:name ifAbsent:nil
|
|
1797 |
! !
|
76
|
1798 |
|
128
|
1799 |
!DialogBox methodsFor:'accessing-models'!
|
|
1800 |
|
|
1801 |
accept
|
|
1802 |
"return the valueHolder holding true when the box
|
|
1803 |
is accepted, false if closed via the windowManager or
|
|
1804 |
the cancel button.
|
|
1805 |
This is confusing: this method was originally called #acceptValue,
|
|
1806 |
but renamed for compatibility with ST-80.
|
|
1807 |
This looks like a bad name to me, since in most other situations, #accept
|
|
1808 |
is used to force an accept, not to return some valueHolder ...)."
|
|
1809 |
|
|
1810 |
^ acceptValue
|
|
1811 |
! !
|
|
1812 |
|
|
1813 |
!DialogBox methodsFor:'accessing-behavior'!
|
76
|
1814 |
|
|
1815 |
okAction:aBlock
|
|
1816 |
"define the action to be performed when ok is pressed"
|
|
1817 |
|
|
1818 |
okAction := aBlock
|
|
1819 |
!
|
|
1820 |
|
128
|
1821 |
abortAction:aBlock
|
|
1822 |
"define the action to be performed when abort is pressed"
|
|
1823 |
|
|
1824 |
abortAction := aBlock
|
|
1825 |
!
|
|
1826 |
|
76
|
1827 |
action:aBlock
|
|
1828 |
"set the action to be performed when user presses ok-button;
|
|
1829 |
aBlock must be nil or a block. This method simply
|
|
1830 |
reuses okAction: and has been added for a consistent action-setting
|
|
1831 |
protocol."
|
|
1832 |
|
|
1833 |
self okAction:aBlock
|
|
1834 |
!
|
|
1835 |
|
120
|
1836 |
acceptReturnAsOK:aBoolean
|
|
1837 |
"turn on/off interpretation of return-key as ok.
|
|
1838 |
Default is on"
|
|
1839 |
|
|
1840 |
acceptReturnAsOK := aBoolean.
|
|
1841 |
okButton notNil ifTrue:[
|
|
1842 |
okButton isReturnButton:aBoolean.
|
|
1843 |
]
|
128
|
1844 |
! !
|
|
1845 |
|
|
1846 |
!DialogBox methodsFor:'accessing-components'!
|
120
|
1847 |
|
76
|
1848 |
okButton
|
128
|
1849 |
"return the okButton - this access is provided to allow
|
|
1850 |
setting the buttons look (for example: colors or font)"
|
76
|
1851 |
|
|
1852 |
^ okButton
|
|
1853 |
!
|
|
1854 |
|
128
|
1855 |
abortButton
|
|
1856 |
"return the abortButton - this access is provided to allow
|
|
1857 |
setting the buttons look (for example: colors or font)"
|
|
1858 |
|
|
1859 |
^ abortButton
|
|
1860 |
! !
|
|
1861 |
|
|
1862 |
!DialogBox methodsFor:'accessing'!
|
76
|
1863 |
|
128
|
1864 |
okText:aString
|
|
1865 |
"define the text in the ok-button"
|
|
1866 |
|
|
1867 |
|oldSize|
|
|
1868 |
|
|
1869 |
aString ~= okButton label ifTrue:[
|
|
1870 |
oldSize := okButton extent.
|
|
1871 |
okButton label:aString.
|
|
1872 |
okButton resize.
|
|
1873 |
okButton extent ~= oldSize ifTrue:[
|
|
1874 |
shown ifTrue:[self resize]
|
|
1875 |
]
|
|
1876 |
]
|
76
|
1877 |
!
|
|
1878 |
|
|
1879 |
abortText:aString
|
|
1880 |
"define the label in the abort-button"
|
|
1881 |
|
|
1882 |
|oldSize|
|
|
1883 |
|
|
1884 |
aString ~= abortButton label ifTrue:[
|
|
1885 |
oldSize := abortButton extent.
|
|
1886 |
abortButton label:aString.
|
|
1887 |
abortButton resize.
|
|
1888 |
abortButton extent ~= oldSize ifTrue:[
|
97
|
1889 |
shown ifTrue:[self resize]
|
76
|
1890 |
]
|
|
1891 |
]
|
|
1892 |
!
|
|
1893 |
|
|
1894 |
okText:okString abortText:abortString
|
|
1895 |
"set both texts displayed in the buttons"
|
|
1896 |
|
|
1897 |
(abortString ~= abortButton label
|
|
1898 |
or:[okString ~= okButton label]) ifTrue:[
|
|
1899 |
okButton label:okString.
|
|
1900 |
abortButton label:abortString.
|
|
1901 |
okButton resize.
|
|
1902 |
abortButton resize.
|
97
|
1903 |
shown ifTrue:[self resize]
|
76
|
1904 |
]
|
|
1905 |
! !
|