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
|
121
|
17 |
acceptReturnAsOK yPosition leftIndent addedComponents
|
125
|
18 |
inputFieldGroup acceptOnLeave accepted tabableElements'
|
76
|
19 |
classVariableNames:''
|
|
20 |
poolDictionaries:''
|
|
21 |
category:'Views-DialogBoxes'
|
|
22 |
!
|
|
23 |
|
|
24 |
!DialogBox class methodsFor:'documentation'!
|
|
25 |
|
|
26 |
version
|
|
27 |
"
|
126
|
28 |
$Header: /cvs/stx/stx/libwidg/DialogBox.st,v 1.13 1995-05-10 02:29:19 claus 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 |
|
|
67 |
leftIndent <Integer> x position to use when adding components
|
|
68 |
|
|
69 |
addedComponents <Collection> programmatically added components
|
|
70 |
|
|
71 |
inputFieldGroup <EnterFieldGroup>
|
|
72 |
for added input fields
|
|
73 |
|
125
|
74 |
acceptOnLeave <Boolean> if true (the default) and there are
|
|
75 |
tabable inputFields, accept and close when
|
|
76 |
the last field is left. If false, the ok
|
|
77 |
button must be pressed to close the box.
|
|
78 |
|
121
|
79 |
accepted <Boolean> after close: true if box was accepted
|
|
80 |
(i.e. ok-Button was pressed)
|
|
81 |
|
|
82 |
|
100
|
83 |
For compatibility with ST-80, this class is also available under
|
|
84 |
the global names DialogView and Dialog (see patches file).
|
76
|
85 |
"
|
|
86 |
!
|
|
87 |
|
|
88 |
examples
|
|
89 |
"
|
118
|
90 |
mostly, DialogBox is used as an abstract class as a base for InfoBox,
|
|
91 |
YesNoBox etc.
|
125
|
92 |
For most simple standard dialogs, there are ready to use
|
|
93 |
methods in the class protocol.
|
|
94 |
For example:
|
|
95 |
|
|
96 |
info & warnings:
|
|
97 |
|
|
98 |
Dialog information:'hi there'
|
|
99 |
|
|
100 |
Dialog warn:'oops'
|
|
101 |
|
|
102 |
|
|
103 |
yes/no questions:
|
|
104 |
|
|
105 |
(Dialog confirm:'is this simple ?')
|
|
106 |
ifTrue:[
|
|
107 |
Transcript showCr:'thats what I expected'
|
|
108 |
] ifFalse:[
|
|
109 |
Transcript showCr:'read more examples and documentation'
|
|
110 |
]
|
|
111 |
|
|
112 |
|
|
113 |
yes/no question with cancel option:
|
|
114 |
|
|
115 |
|answer|
|
|
116 |
|
|
117 |
answer := Dialog confirmWithCancel:'is this simple ?'.
|
|
118 |
answer isNil ifTrue:[
|
|
119 |
Transcript showCr:'no easy decision'
|
|
120 |
] ifFalse:[
|
|
121 |
answer ifTrue:[
|
|
122 |
Transcript showCr:'thats what I expected'
|
|
123 |
] ifFalse:[
|
|
124 |
Transcript showCr:'read more examples and documentation'
|
|
125 |
]
|
|
126 |
]
|
|
127 |
|
|
128 |
|
|
129 |
asking for a string:
|
|
130 |
|
|
131 |
|s|
|
|
132 |
|
|
133 |
s := Dialog request:'enter your name, please:'.
|
|
134 |
s notNil ifTrue:[
|
|
135 |
Transcript showCr:'you entered: ' , s.
|
|
136 |
]
|
|
137 |
|
|
138 |
|
|
139 |
asking for a string with given default:
|
|
140 |
|
|
141 |
|s|
|
|
142 |
|
|
143 |
s := Dialog
|
|
144 |
request:'enter your name, please:'
|
|
145 |
initialAnswer:(OperatingSystem getLoginName).
|
|
146 |
s notNil ifTrue:[
|
|
147 |
Transcript showCr:'you entered: ' , s.
|
|
148 |
]
|
|
149 |
|
|
150 |
|
|
151 |
asking for a filename:
|
|
152 |
|
|
153 |
|s|
|
|
154 |
|
|
155 |
s := Dialog
|
|
156 |
requestFileName:'select a file, please:'
|
|
157 |
default:''.
|
|
158 |
Transcript show:'you entered: '; showCr:s.
|
|
159 |
|
|
160 |
|
|
161 |
with changed button label and pattern:
|
|
162 |
|
|
163 |
|s|
|
|
164 |
|
|
165 |
s := Dialog
|
|
166 |
requestFileName:'select a file, please:'
|
|
167 |
default:''
|
|
168 |
ok:'show'
|
|
169 |
abort:'cancel'
|
|
170 |
pattern:'*.rc'.
|
|
171 |
Transcript show:'you entered: '; showCr:s.
|
|
172 |
|
118
|
173 |
However, you can construct dialogs programmatically, as shown in
|
|
174 |
the following examples:
|
91
|
175 |
|
121
|
176 |
basic (unusable) example:
|
|
177 |
|
|
178 |
DialogBox new open
|
76
|
179 |
|
121
|
180 |
still unusable - only an ok-button:
|
76
|
181 |
|
121
|
182 |
DialogBox new addOkButton; open
|
|
183 |
|
|
184 |
both ok- and abortButtons:
|
118
|
185 |
|
121
|
186 |
DialogBox new addAbortButton; addOkButton; open
|
|
187 |
|
122
|
188 |
with different ok-label:
|
|
189 |
|
|
190 |
DialogBox new addAbortButton; addOkButtonLabelled:'yeah'; open
|
|
191 |
|
121
|
192 |
adding a textlabel gives an infoBox:
|
120
|
193 |
|
121
|
194 |
DialogBox new
|
|
195 |
addTextLabel:'hello';
|
|
196 |
addOkButton;
|
|
197 |
open
|
|
198 |
|
|
199 |
a textlabel with abort- and okButton gives a yesNoBox:
|
118
|
200 |
|
121
|
201 |
DialogBox new
|
|
202 |
addTextLabel:'hello';
|
|
203 |
addAbortButton;
|
|
204 |
addOkButton;
|
|
205 |
open
|
|
206 |
|
|
207 |
the same, adjusting the labels contents to the left:
|
|
208 |
|
|
209 |
|box|
|
118
|
210 |
|
121
|
211 |
box := DialogBox new.
|
|
212 |
(box addTextLabel:'hello') adjust:#left.
|
|
213 |
box addAbortButton;
|
|
214 |
addOkButton;
|
|
215 |
open
|
|
216 |
|
122
|
217 |
with modified buttons:
|
|
218 |
|
|
219 |
|box|
|
|
220 |
|
|
221 |
box := DialogBox new.
|
|
222 |
(box addTextLabel:'are you certain ?') adjust:#left.
|
|
223 |
box addAbortButtonLabelled:'not really'.
|
|
224 |
(box addOkButtonLabelled:'yes, absolutely')
|
|
225 |
activeBackgroundColor:Color red.
|
|
226 |
box open
|
|
227 |
|
|
228 |
|
121
|
229 |
two textlabels:
|
118
|
230 |
|
121
|
231 |
DialogBox new
|
|
232 |
addTextLabel:'hello';
|
|
233 |
addTextLabel:'world';
|
|
234 |
addAbortButton;
|
|
235 |
addOkButton;
|
|
236 |
open
|
118
|
237 |
|
121
|
238 |
fixing the dialogs size (suppres it calculating its size from the
|
|
239 |
preferedExtents of its components):
|
118
|
240 |
|
121
|
241 |
DialogBox new
|
|
242 |
label:'a simple dialog';
|
|
243 |
addTextLabel:'hello';
|
|
244 |
addAbortButton;
|
|
245 |
addOkButton;
|
|
246 |
extent:200@200;
|
|
247 |
sizeFixed:true;
|
|
248 |
open
|
118
|
249 |
|
121
|
250 |
asking the box if it was closed via ok:
|
118
|
251 |
|
121
|
252 |
(DialogBox new
|
|
253 |
label:'a simple dialog';
|
|
254 |
addTextLabel:'hello';
|
|
255 |
addAbortButton;
|
|
256 |
addOkButton;
|
|
257 |
extent:200@200;
|
|
258 |
sizeFixed:true;
|
|
259 |
open
|
|
260 |
) accepted ifTrue:[
|
|
261 |
Transcript showCr:'yes'
|
|
262 |
] ifFalse:[
|
|
263 |
Transcript showCr:'no'
|
|
264 |
]
|
118
|
265 |
|
121
|
266 |
textLabels are not limited to strings (although, the name which is
|
|
267 |
used for ST-80 compatibility, suggests it):
|
118
|
268 |
|
121
|
269 |
DialogBox new
|
|
270 |
addTextLabel:(Image fromFile:'bitmaps/garfield.gif');
|
|
271 |
addOkButton;
|
|
272 |
open
|
120
|
273 |
|
121
|
274 |
DialogBox new
|
|
275 |
addTextLabel:'hello';
|
125
|
276 |
addTextLabel:((Image fromFile:'bitmaps/garfield.gif')
|
|
277 |
magnifiedTo:200@150);
|
121
|
278 |
addTextLabel:'world';
|
|
279 |
addAbortButton;
|
|
280 |
addOkButton;
|
|
281 |
open
|
120
|
282 |
|
121
|
283 |
adding an input field (on a string model):
|
|
284 |
|
|
285 |
|stringModel|
|
120
|
286 |
|
121
|
287 |
stringModel := '' asValue.
|
|
288 |
(DialogBox new
|
|
289 |
addTextLabel:'Please enter a string:';
|
|
290 |
addInputFieldOn:stringModel;
|
|
291 |
addAbortButton;
|
|
292 |
addOkButton;
|
|
293 |
open
|
|
294 |
) accepted ifTrue:[
|
|
295 |
Transcript showCr:'entered: ', stringModel value
|
|
296 |
]
|
120
|
297 |
|
|
298 |
|
121
|
299 |
multiple input fields (notice, that the dialog connects the fields
|
|
300 |
in a group, so stepping is allowed via Cursor and Return keys):
|
|
301 |
|
|
302 |
|firstName lastName|
|
120
|
303 |
|
121
|
304 |
firstName := '' asValue.
|
|
305 |
lastName := '' asValue.
|
|
306 |
(DialogBox new
|
|
307 |
addTextLabel:'Please enter your name:';
|
|
308 |
addInputFieldOn:firstName;
|
122
|
309 |
addVerticalSpace;
|
121
|
310 |
addInputFieldOn:lastName;
|
|
311 |
addAbortButton;
|
|
312 |
addOkButton;
|
|
313 |
open
|
|
314 |
) accepted ifTrue:[
|
|
315 |
Transcript showCr:'entered: ', firstName value , ' ' , lastName value
|
|
316 |
]
|
|
317 |
|
|
318 |
|
|
319 |
of course, the model may contain a value initially:
|
|
320 |
|
|
321 |
|firstName lastName p line i name|
|
120
|
322 |
|
121
|
323 |
firstName := '' asValue.
|
|
324 |
lastName := '' asValue.
|
|
325 |
p := PipeStream readingFrom:'finger ' , OperatingSystem getLoginName.
|
|
326 |
p notNil ifTrue:[
|
|
327 |
line := p nextLine.
|
|
328 |
(i := line findString:'real life:') == 0 ifTrue:[
|
|
329 |
line := p nextLine.
|
|
330 |
].
|
|
331 |
(i := line findString:'real life:') ~~ 0 ifTrue:[
|
|
332 |
name := line copyFrom:(i + 'real life:' size).
|
|
333 |
firstName value: name asCollectionOfWords first.
|
|
334 |
lastName value: name asCollectionOfWords last
|
|
335 |
].
|
|
336 |
p close.
|
|
337 |
].
|
120
|
338 |
|
121
|
339 |
(DialogBox new
|
|
340 |
addTextLabel:'Please enter your name:';
|
|
341 |
addInputFieldOn:firstName;
|
122
|
342 |
addVerticalSpace;
|
121
|
343 |
addInputFieldOn:lastName;
|
|
344 |
addAbortButton;
|
|
345 |
addOkButton;
|
|
346 |
open
|
|
347 |
) accepted ifTrue:[
|
|
348 |
Transcript showCr:'entered: ', firstName value , ' ' , lastName value
|
|
349 |
]
|
|
350 |
|
120
|
351 |
|
121
|
352 |
constructing a dialog from other elements:
|
|
353 |
|
|
354 |
adding a fileSelectionList:
|
|
355 |
(since the dialog adds the component with its preferred extent,
|
|
356 |
ignoring the 300-height, this looks ugly ...
|
|
357 |
... especially when resized vertically)
|
|
358 |
|
|
359 |
|top l scr fileName|
|
|
360 |
|
|
361 |
fileName := '' asValue.
|
|
362 |
|
|
363 |
top := DialogBox new.
|
120
|
364 |
|
121
|
365 |
l := FileSelectionList on:fileName.
|
|
366 |
l useIndex:false.
|
|
367 |
l doubleClickAction:[:name | top okPressed].
|
|
368 |
scr := ScrollableView forView:l.
|
|
369 |
scr extent:(1.0 @ 300).
|
|
370 |
|
|
371 |
top addComponent:scr.
|
|
372 |
top addAbortButton; addOkButton.
|
|
373 |
top openModal.
|
|
374 |
|
|
375 |
top accepted ifTrue:[
|
|
376 |
Transcript show:'fileName: '; showCr:fileName value storeString.
|
|
377 |
]
|
|
378 |
|
|
379 |
same, looks better, since the height is made larger (not using
|
|
380 |
fileLists preferredExtent):
|
|
381 |
|
|
382 |
|top l scr fileName|
|
|
383 |
|
|
384 |
fileName := '' asValue.
|
|
385 |
|
|
386 |
top := DialogBox new.
|
|
387 |
|
|
388 |
l := FileSelectionList on:fileName.
|
|
389 |
l useIndex:false.
|
|
390 |
l doubleClickAction:[:name | top okPressed].
|
|
391 |
scr := ScrollableView forView:l.
|
|
392 |
|
|
393 |
top addComponent:scr withExtent:300@300.
|
|
394 |
top addAbortButton; addOkButton.
|
|
395 |
top openModal.
|
120
|
396 |
|
121
|
397 |
top accepted ifTrue:[
|
|
398 |
Transcript show:'fileName: '; showCr:fileName value storeString.
|
|
399 |
]
|
|
400 |
|
|
401 |
|
|
402 |
again, setting the boxes initial size and fixing it
|
|
403 |
(let it ignore the components' preferedExtent):
|
|
404 |
|
|
405 |
|top fixFrame l scr fileName|
|
|
406 |
|
|
407 |
fileName := '' asValue.
|
|
408 |
|
|
409 |
top := DialogBox new.
|
|
410 |
top extent:300@300.
|
120
|
411 |
|
121
|
412 |
fixFrame := View new.
|
|
413 |
fixFrame extent:(1.0 @ 300).
|
|
414 |
|
|
415 |
l := FileSelectionList on:fileName.
|
|
416 |
l useIndex:false.
|
|
417 |
l doubleClickAction:[:name | top okPressed].
|
|
418 |
scr := ScrollableView forView:l.
|
|
419 |
fixFrame add:scr in:(0.0@0.0 corner:1.0@1.0).
|
|
420 |
|
|
421 |
top addComponent:fixFrame.
|
|
422 |
top addAbortButton; addOkButton.
|
|
423 |
top openModal.
|
|
424 |
|
|
425 |
top accepted ifTrue:[
|
|
426 |
Transcript show:'fileName: '; showCr:fileName value storeString.
|
|
427 |
]
|
118
|
428 |
|
|
429 |
|
|
430 |
adding a panel with checkBoxes:
|
|
431 |
|
121
|
432 |
|top panel b value1 value2 value3 value4|
|
118
|
433 |
|
121
|
434 |
value1 := true asValue.
|
|
435 |
value2 := false asValue.
|
|
436 |
value3 := false asValue.
|
|
437 |
value4 := true asValue.
|
118
|
438 |
|
121
|
439 |
top := DialogBox new.
|
|
440 |
top extent:200@300.
|
118
|
441 |
|
121
|
442 |
panel := VerticalPanelView new.
|
118
|
443 |
|
121
|
444 |
b := CheckBox on:value1. b label:'check1'.
|
|
445 |
panel addSubView:b.
|
118
|
446 |
|
121
|
447 |
b := CheckBox on:value2. b label:'check2'.
|
|
448 |
panel addSubView:b.
|
118
|
449 |
|
121
|
450 |
b := CheckBox on:value3. b label:'check3'.
|
|
451 |
panel addSubView:b.
|
|
452 |
|
|
453 |
b := CheckBox on:value4. b label:'check4'.
|
|
454 |
panel addSubView:b.
|
118
|
455 |
|
121
|
456 |
top addComponent:panel.
|
|
457 |
top addAbortButton; addOkButton.
|
|
458 |
top open.
|
118
|
459 |
|
121
|
460 |
top accepted ifTrue:[
|
|
461 |
Transcript show:'value1: '; showCr:value1 value.
|
|
462 |
Transcript show:'value2: '; showCr:value2 value.
|
|
463 |
Transcript show:'value3: '; showCr:value3 value.
|
|
464 |
Transcript show:'value4: '; showCr:value4 value.
|
|
465 |
]
|
118
|
466 |
|
120
|
467 |
same, using a more convenient interface:
|
|
468 |
|
121
|
469 |
|box value1 value2 value3 value4|
|
120
|
470 |
|
121
|
471 |
value1 := true asValue.
|
|
472 |
value2 := false asValue.
|
|
473 |
value3 := false asValue.
|
|
474 |
value4 := true asValue.
|
120
|
475 |
|
121
|
476 |
box := DialogBox new.
|
|
477 |
box extent:200@300.
|
120
|
478 |
|
121
|
479 |
box addCheckBox:'check1' on:value1.
|
125
|
480 |
box addVerticalSpace.
|
121
|
481 |
box addCheckBox:'check2' on:value2.
|
125
|
482 |
box addVerticalSpace.
|
121
|
483 |
box addCheckBox:'check3' on:value3.
|
125
|
484 |
box addVerticalSpace.
|
121
|
485 |
box addCheckBox:'check4' on:value4.
|
120
|
486 |
|
121
|
487 |
box addAbortButton; addOkButton.
|
|
488 |
box open.
|
120
|
489 |
|
121
|
490 |
box accepted ifTrue:[
|
|
491 |
Transcript show:'value1: '; showCr:value1 value.
|
|
492 |
Transcript show:'value2: '; showCr:value2 value.
|
|
493 |
Transcript show:'value3: '; showCr:value3 value.
|
|
494 |
Transcript show:'value4: '; showCr:value4 value.
|
|
495 |
]
|
126
|
496 |
|
|
497 |
|
|
498 |
a full example:
|
|
499 |
|
|
500 |
|box warnSTX allowUnderscore immutableArrays logDoits
|
|
501 |
listOfLanguages listOfStyles styleNames
|
|
502 |
frame panel c resourceDir dir |
|
|
503 |
|
|
504 |
warnSTX := Compiler warnSTXSpecials asValue.
|
|
505 |
allowUnderscore := Compiler allowUnderscoreInIdentifier asValue.
|
|
506 |
immutableArrays := Compiler arraysAreImmutable asValue.
|
|
507 |
|
|
508 |
logDoits := Smalltalk logDoits asValue.
|
|
509 |
|
|
510 |
listOfLanguages := SelectionInList with:#('english'
|
|
511 |
'german'
|
|
512 |
'french'
|
|
513 |
'spanish'
|
|
514 |
'italian'
|
|
515 |
).
|
|
516 |
listOfLanguages selection:(Language asString).
|
|
517 |
|
|
518 |
|
|
519 |
resourceDir := Smalltalk getSystemFileName:'resources'.
|
|
520 |
dir := FileDirectory directoryNamed:resourceDir.
|
|
521 |
|
|
522 |
styleNames := dir select:[:aFileName | aFileName endsWith:'.style'].
|
|
523 |
styleNames := styleNames collect:[:aFileName | aFileName copyWithoutLast:6].
|
|
524 |
listOfStyles := SelectionInList with:styleNames.
|
|
525 |
listOfStyles selection:(View defaultStyle asString).
|
|
526 |
|
|
527 |
box := Dialog new.
|
|
528 |
box label:'Settings'.
|
|
529 |
|
|
530 |
frame := FramedBox label:'Compiler'.
|
|
531 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:frame.
|
|
532 |
panel horizontalLayout:#leftSpace.
|
|
533 |
|
|
534 |
panel add:((CheckBox on:warnSTX) label:'warn about ST/X language extensions'; resize).
|
|
535 |
panel add:((CheckBox on:allowUnderscore) label:'allow underscore in identifiers'; resize).
|
|
536 |
panel add:((CheckBox on:immutableArrays) label:'literal arrays are immutable'; resize).
|
|
537 |
box addComponent:frame.
|
|
538 |
|
|
539 |
frame := FramedBox label:'Misc'.
|
|
540 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:frame.
|
|
541 |
panel horizontalLayout:#leftSpace.
|
|
542 |
|
|
543 |
panel add:((CheckBox on:logDoits) label:'log doIts in changes file'; resize).
|
|
544 |
box addComponent:frame.
|
|
545 |
|
|
546 |
frame := FramedBox label:'Language'.
|
|
547 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:frame.
|
|
548 |
panel horizontalLayout:#leftSpace.
|
|
549 |
|
|
550 |
panel add:(PopUpList on:listOfLanguages).
|
|
551 |
box addComponent:frame.
|
|
552 |
|
|
553 |
frame := FramedBox label:'Style'.
|
|
554 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:frame.
|
|
555 |
panel horizontalLayout:#leftSpace.
|
|
556 |
|
|
557 |
panel add:(PopUpList on:listOfStyles).
|
|
558 |
box addComponent:frame.
|
|
559 |
|
|
560 |
box addAbortButton; addOkButton.
|
|
561 |
box showAtPointer.
|
|
562 |
|
|
563 |
box accepted ifTrue:[
|
|
564 |
Transcript topView withCursor:Cursor wait do:[
|
|
565 |
Compiler warnSTXSpecials:warnSTX value.
|
|
566 |
Compiler allowUnderscoreInIdentifier:allowUnderscore value.
|
|
567 |
Compiler arraysAreImmutable:immutableArrays value.
|
|
568 |
|
|
569 |
Smalltalk logDoits:logDoits value.
|
|
570 |
|
|
571 |
Transcript showCr:'change language to ' , listOfLanguages selection , ' ...'.
|
|
572 |
Smalltalk at:#Language put:listOfLanguages selection asSymbol.
|
|
573 |
Smalltalk changed:#Language.
|
|
574 |
ResourcePack flushCachedResourcePacks.
|
|
575 |
|
|
576 |
Transcript showCr:'change style to ' , listOfStyles selection , ' ...'.
|
|
577 |
View defaultStyle:listOfStyles selection asSymbol.
|
|
578 |
]
|
|
579 |
]
|
|
580 |
|
76
|
581 |
"
|
|
582 |
!
|
|
583 |
|
|
584 |
copyright
|
|
585 |
"
|
|
586 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
587 |
All Rights Reserved
|
|
588 |
|
|
589 |
This software is furnished under a license and may be used
|
|
590 |
only in accordance with the terms of that license and with the
|
|
591 |
inclusion of the above copyright notice. This software may not
|
|
592 |
be provided or otherwise made available to, or used by, any
|
|
593 |
other person. No title to or ownership of the software is
|
|
594 |
hereby transferred.
|
|
595 |
"
|
|
596 |
! !
|
|
597 |
|
100
|
598 |
!DialogBox class methodsFor:'startup'!
|
|
599 |
|
|
600 |
request:aString
|
|
601 |
"launch a Dialog, which allows user to enter something.
|
|
602 |
Return the entered string (may be empty string)
|
|
603 |
or nil (if cancel was pressed)"
|
|
604 |
|
|
605 |
^ self
|
|
606 |
request:aString
|
|
607 |
displayAt:nil
|
|
608 |
centered:true
|
|
609 |
action:nil
|
|
610 |
initialAnswer:''
|
|
611 |
|
|
612 |
"
|
|
613 |
Dialog
|
|
614 |
request:'enter a string:'
|
|
615 |
"
|
|
616 |
!
|
|
617 |
|
|
618 |
request:aString initialAnswer:initial
|
|
619 |
"launch a Dialog, which allows user to enter something.
|
|
620 |
Return the entered string (may be empty string) or nil (if cancel was pressed)"
|
|
621 |
|
|
622 |
^ self
|
|
623 |
request:aString
|
|
624 |
displayAt:nil
|
|
625 |
centered:true
|
|
626 |
action:nil
|
|
627 |
initialAnswer:initial
|
|
628 |
|
|
629 |
"
|
|
630 |
Dialog
|
|
631 |
request:'enter a string:'
|
|
632 |
initialAnswer:'the default'
|
|
633 |
"
|
|
634 |
!
|
|
635 |
|
118
|
636 |
request:aString initialAnswer:initial onCancel:cancelAction
|
|
637 |
"launch a Dialog, which allows user to enter something.
|
|
638 |
Return the entered string (may be empty string)
|
|
639 |
or cancelValue (if cancel was pressed)"
|
|
640 |
|
|
641 |
|val|
|
|
642 |
|
|
643 |
val :=self
|
|
644 |
request:aString
|
|
645 |
displayAt:nil
|
|
646 |
centered:true
|
|
647 |
action:[:result | ^ result]
|
|
648 |
initialAnswer:initial.
|
|
649 |
|
|
650 |
^ cancelAction value
|
|
651 |
|
|
652 |
"
|
|
653 |
Dialog
|
|
654 |
request:'enter a string:'
|
|
655 |
initialAnswer:'the default'
|
|
656 |
onCancel:['foooo']
|
|
657 |
"
|
|
658 |
!
|
|
659 |
|
100
|
660 |
request:aString displayAt:aPoint initialAnswer:initial
|
|
661 |
"launch a Dialog, which allows user to enter something.
|
|
662 |
Return the entered string (may be empty string) or nil (if cancel was pressed)"
|
|
663 |
|
|
664 |
^ self
|
|
665 |
request:aString
|
|
666 |
displayAt:aPoint
|
|
667 |
centered:true
|
|
668 |
action:nil
|
|
669 |
initialAnswer:initial
|
|
670 |
|
|
671 |
"
|
|
672 |
Dialog
|
|
673 |
request:'enter a string:'
|
|
674 |
displayAt:(50 @ 50)
|
|
675 |
initialAnswer:'the default'
|
|
676 |
"
|
|
677 |
!
|
|
678 |
|
120
|
679 |
confirm:aString
|
|
680 |
"launch a Dialog, which allows user to enter yes or no.
|
|
681 |
return true for yes, false for no"
|
|
682 |
|
|
683 |
|box answer|
|
|
684 |
|
|
685 |
box := YesNoBox title:aString.
|
|
686 |
box yesAction:[answer := true] noAction:[answer := false].
|
|
687 |
box showAtPointer.
|
|
688 |
box yesAction:nil noAction:nil.
|
|
689 |
^ answer
|
|
690 |
|
|
691 |
"
|
|
692 |
Dialog confirm:'really ?'
|
|
693 |
"
|
|
694 |
!
|
|
695 |
|
100
|
696 |
request:aString displayAt:aPoint centered:centered action:resultAction initialAnswer:initial
|
|
697 |
"launch a Dialog, which allows user to enter a string.
|
|
698 |
Return the string (may be empty string) or nil (if cancel was pressed)"
|
|
699 |
|
|
700 |
|box|
|
|
701 |
|
|
702 |
box := EnterBox title:aString.
|
|
703 |
box initialText:initial.
|
|
704 |
resultAction isNil ifTrue:[
|
|
705 |
box action:[:val | ^ val]
|
|
706 |
] ifFalse:[
|
|
707 |
box action:[:val | ^ resultAction value:val]
|
|
708 |
].
|
|
709 |
aPoint notNil ifTrue:[
|
|
710 |
box showAt:aPoint
|
|
711 |
] ifFalse:[
|
|
712 |
box showAtPointer
|
|
713 |
].
|
|
714 |
^ nil
|
|
715 |
|
|
716 |
"
|
|
717 |
Dialog request:'enter a string:'
|
|
718 |
displayAt:0@0
|
|
719 |
centered:true
|
|
720 |
action:[:result | result printNewline]
|
|
721 |
initialAnswer:'the default'
|
|
722 |
"
|
|
723 |
!
|
|
724 |
|
|
725 |
confirmWithCancel:aString
|
|
726 |
"launch a Dialog, which allows user to enter yes, no and cancel.
|
|
727 |
return true for 'yes', false for 'no', nil for 'cancel'"
|
|
728 |
|
|
729 |
|box answer|
|
|
730 |
|
|
731 |
box := OptionBox title:aString numberOfOptions:3.
|
|
732 |
box buttonTitles:(self classResources array:
|
|
733 |
#('cancel'
|
|
734 |
'no'
|
|
735 |
'yes')
|
|
736 |
)
|
|
737 |
actions:(Array with:[answer := nil]
|
|
738 |
with:[answer := false]
|
|
739 |
with:[answer := true]
|
|
740 |
).
|
|
741 |
box showAtPointer.
|
|
742 |
box actions:nil.
|
|
743 |
^ answer
|
|
744 |
|
|
745 |
"
|
|
746 |
Dialog confirmWithCancel:'really ?' nil
|
|
747 |
"
|
|
748 |
!
|
|
749 |
|
|
750 |
information:aString
|
|
751 |
"launch a Dialog to tell user something"
|
|
752 |
|
|
753 |
(InfoBox title:aString) showAtPointer
|
|
754 |
|
|
755 |
"
|
|
756 |
Dialog information:'help'
|
|
757 |
"
|
|
758 |
!
|
|
759 |
|
|
760 |
warn:aString
|
|
761 |
"launch a Dialog to warn user"
|
|
762 |
|
|
763 |
(WarningBox title:aString) showAtPointer
|
|
764 |
|
|
765 |
"
|
|
766 |
Dialog warn:'help'
|
|
767 |
"
|
|
768 |
!
|
|
769 |
|
|
770 |
requestFileName:titleString default:defaultName
|
|
771 |
"launch a Dialog, which allows user to enter a filename.
|
|
772 |
The box will not allow pressing 'ok' without an entered string.
|
|
773 |
Return the pathname string consisting of the full pathname of the filename,
|
|
774 |
or an empty string (if cancel was pressed)."
|
|
775 |
|
|
776 |
^ self requestFileName:titleString
|
|
777 |
default:defaultName
|
|
778 |
version:nil
|
|
779 |
ifFail:''
|
|
780 |
|
|
781 |
"
|
|
782 |
Dialog requestFileName:'enter a fileName:' default:''
|
|
783 |
Dialog requestFileName:'enter a fileName:' default:'Makefile.bak'
|
|
784 |
"
|
|
785 |
!
|
|
786 |
|
|
787 |
requestFileName:titleString default:defaultName version:versionSymbol
|
|
788 |
"launch a Dialog, which allows user to enter a filename.
|
|
789 |
The box will not allow pressing 'ok' without an entered string.
|
|
790 |
Return the pathname string or the empty string if cancel was pressed.
|
|
791 |
The version argument is ignored on Unix, but may at some time in the
|
|
792 |
future be used on systems like VMS (which support file versioning)."
|
|
793 |
|
|
794 |
^ self requestFileName:titleString
|
|
795 |
default:defaultName
|
|
796 |
version:versionSymbol
|
|
797 |
ifFail:''
|
|
798 |
|
|
799 |
"
|
|
800 |
Dialog requestFileName:'enter a fileName:'
|
|
801 |
default:''
|
|
802 |
version:nil
|
|
803 |
"
|
|
804 |
!
|
|
805 |
|
|
806 |
requestFileName:titleString default:defaultName version:versionSymbol ifFail:failBlock
|
|
807 |
"launch a Dialog, which allows user to enter a filename.
|
|
808 |
The box will not allow pressing 'ok' without an entered string.
|
|
809 |
Return the string or the value of failBlock if cancel was pressed.
|
|
810 |
The version argument is ignored on Unix, but may at some time in the
|
|
811 |
future be used on systems like VMS (which support file versioning)."
|
|
812 |
|
|
813 |
|box|
|
|
814 |
|
|
815 |
box := FileSelectionBox title:titleString.
|
|
816 |
box initialText:defaultName.
|
|
817 |
box action:[:name | ^ name].
|
|
818 |
box showAtPointer.
|
|
819 |
box action:nil.
|
|
820 |
^ failBlock value
|
|
821 |
|
|
822 |
"
|
|
823 |
Dialog requestFileName:'enter a fileName:'
|
|
824 |
default:''
|
|
825 |
version:nil
|
|
826 |
ifFail:['none']
|
|
827 |
"
|
|
828 |
!
|
|
829 |
|
|
830 |
requestFileName:titleString default:defaultName ok:okText abort:abortText pattern:pattern
|
|
831 |
"launch a Dialog, which allows user to enter a filename.
|
|
832 |
The box will show okText in its okButton, abortText in the abortButton.
|
|
833 |
The matchPattern is set to pattern initially.
|
|
834 |
Return the string or nil if cancel was pressed."
|
|
835 |
|
|
836 |
|box|
|
|
837 |
|
|
838 |
box := FileSelectionBox
|
|
839 |
title:titleString
|
|
840 |
okText:okText
|
|
841 |
abortText:abortText
|
|
842 |
action:[:fileName | ^ fileName].
|
|
843 |
box pattern:pattern.
|
|
844 |
box initialText:defaultName.
|
|
845 |
box showAtPointer.
|
|
846 |
box action:nil.
|
|
847 |
^ nil
|
|
848 |
|
|
849 |
"
|
|
850 |
Dialog requestFileName:'enter a fileName:'
|
|
851 |
default:''
|
|
852 |
ok:'yeah'
|
|
853 |
abort:'oh, no'
|
|
854 |
pattern:'*.st'
|
|
855 |
"
|
|
856 |
! !
|
|
857 |
|
76
|
858 |
!DialogBox methodsFor:'user actions'!
|
|
859 |
|
121
|
860 |
accept
|
|
861 |
"let all components accept (i.e. update their model from the values)"
|
|
862 |
|
|
863 |
addedComponents notNil ifTrue:[
|
|
864 |
addedComponents do:[:aComponent |
|
|
865 |
(aComponent respondsTo:#accept) ifTrue:[
|
|
866 |
aComponent accept
|
|
867 |
]
|
|
868 |
].
|
|
869 |
].
|
|
870 |
accepted := true.
|
|
871 |
!
|
|
872 |
|
125
|
873 |
lastFieldLeft
|
|
874 |
"if the dialog involves input fields, this is called
|
|
875 |
when the last field is left by Return-key or NextField-key"
|
|
876 |
|
|
877 |
acceptOnLeave ifTrue:[
|
|
878 |
accepted := true.
|
|
879 |
self okPressed
|
|
880 |
].
|
|
881 |
!
|
|
882 |
|
76
|
883 |
okPressed
|
|
884 |
"user pressed ok-button; make myself invisible and if an action was
|
|
885 |
specified do it"
|
|
886 |
|
122
|
887 |
okButton notNil ifTrue:[okButton turnOffWithoutRedraw].
|
121
|
888 |
self accept.
|
|
889 |
self hideAndEvaluate:okAction.
|
76
|
890 |
!
|
|
891 |
|
|
892 |
abortPressed
|
|
893 |
"user pressed abort button - hide myself and evaluate okAction"
|
|
894 |
|
95
|
895 |
abortButton turnOffWithoutRedraw.
|
121
|
896 |
accepted := false.
|
76
|
897 |
self hideAndEvaluate:abortAction
|
|
898 |
!
|
|
899 |
|
|
900 |
keyPress:aKey x:x y:y
|
|
901 |
"return-key dublicates ok-function if acceptReturnAsOK is true"
|
|
902 |
|
|
903 |
acceptReturnAsOK ifTrue:[
|
|
904 |
(aKey == #Return) ifTrue:[^ self okPressed]
|
|
905 |
].
|
|
906 |
super keyPress:aKey x:x y:y
|
|
907 |
! !
|
|
908 |
|
120
|
909 |
!DialogBox methodsFor:'construction-adding'!
|
|
910 |
|
|
911 |
addButton:aButton after:someOtherButtonOrNil
|
|
912 |
"add a button in the buttonPanel.
|
|
913 |
If the argument someOtherButtonOrNil is nil, the button is
|
|
914 |
added at the end."
|
|
915 |
|
|
916 |
buttonPanel addSubView:aButton after:someOtherButtonOrNil.
|
|
917 |
buttonPanel subViews size > 1 ifTrue:[
|
|
918 |
buttonPanel layout:#fitSpace.
|
|
919 |
].
|
122
|
920 |
^ aButton
|
120
|
921 |
!
|
|
922 |
|
122
|
923 |
addOkButtonLabelled:buttonLabel
|
|
924 |
"create an okButton with a label - to be sent from redefined initialize
|
|
925 |
methods in subclasses or when creating a box programmatically.
|
|
926 |
A nil argument creates one with the default text.
|
|
927 |
Returns the button."
|
|
928 |
|
|
929 |
okButton := Button okButton.
|
|
930 |
okButton model:self; change:#okPressed.
|
|
931 |
buttonLabel notNil ifTrue:[okButton label:buttonLabel].
|
|
932 |
okButton isReturnButton:acceptReturnAsOK.
|
|
933 |
^ self addButton:okButton.
|
|
934 |
!
|
|
935 |
|
|
936 |
XXaddOkButton:action
|
120
|
937 |
"create an okButton - to be sent from redefined initialize
|
122
|
938 |
methods in subclasses or when creating a box programmatically."
|
120
|
939 |
|
|
940 |
okButton := Button okButton.
|
|
941 |
action notNil ifTrue:[okButton action:action].
|
|
942 |
okButton model:self; change:#okPressed.
|
|
943 |
okButton isReturnButton:acceptReturnAsOK.
|
122
|
944 |
^ self addButton:okButton.
|
120
|
945 |
!
|
76
|
946 |
|
120
|
947 |
addOkButton
|
|
948 |
"create an okButton - to be sent from redefined initialize
|
122
|
949 |
methods in subclasses or when creating a box programmatically.
|
|
950 |
Returns the button."
|
120
|
951 |
|
122
|
952 |
^ self addOkButtonLabelled:nil
|
120
|
953 |
!
|
|
954 |
|
|
955 |
addButton:aButton
|
122
|
956 |
"add a button into the buttonPanel.
|
|
957 |
Returns the button."
|
|
958 |
|
|
959 |
^ self addButton:aButton after:nil
|
|
960 |
!
|
120
|
961 |
|
122
|
962 |
addAbortButtonLabelled:buttonLabel
|
|
963 |
"create an abortButton with a label - to be sent from redefined initialize
|
|
964 |
methods in subclasses or when creating a box programmatically.
|
|
965 |
A nil argument creates one with the default label.
|
|
966 |
Returns the button."
|
|
967 |
|
|
968 |
abortButton := Button abortButton.
|
|
969 |
abortButton model:self; change:#abortPressed.
|
|
970 |
buttonLabel notNil ifTrue:[abortButton label:buttonLabel].
|
|
971 |
^ self addButton:abortButton.
|
120
|
972 |
!
|
76
|
973 |
|
120
|
974 |
addAbortButton
|
|
975 |
"create an abortButton - to be sent from redefined initialize
|
122
|
976 |
methods in subclasses or when creating a box programmatically.
|
|
977 |
Returns the button."
|
120
|
978 |
|
122
|
979 |
^ self addAbortButtonLabelled:nil
|
120
|
980 |
!
|
|
981 |
|
121
|
982 |
addComponent:aComponent withHeight:height
|
122
|
983 |
"add a component with some given height and full width.
|
|
984 |
Returns the component."
|
121
|
985 |
|
|
986 |
self basicAddComponent:aComponent.
|
|
987 |
aComponent height:height.
|
|
988 |
aComponent origin:0.0@yPosition;
|
|
989 |
width:1.0;
|
|
990 |
leftInset:leftIndent+ViewSpacing;
|
|
991 |
rightInset:ViewSpacing.
|
|
992 |
yPosition := yPosition + aComponent height.
|
122
|
993 |
^ aComponent
|
121
|
994 |
!
|
|
995 |
|
|
996 |
addComponent:aComponent withExtent:ext
|
122
|
997 |
"add a component with some given extent.
|
|
998 |
Returns the component."
|
121
|
999 |
|
|
1000 |
self basicAddComponent:aComponent.
|
|
1001 |
aComponent extent:ext.
|
|
1002 |
aComponent origin:0.0@yPosition;
|
|
1003 |
leftInset:leftIndent;
|
|
1004 |
rightInset:ViewSpacing.
|
|
1005 |
yPosition := yPosition + aComponent height.
|
122
|
1006 |
^ aComponent
|
121
|
1007 |
!
|
|
1008 |
|
125
|
1009 |
addComponent:aComponent tabable:tabable
|
|
1010 |
"add a component with its prefered height and full width.
|
|
1011 |
Returns the component."
|
|
1012 |
|
|
1013 |
tabable ifTrue:[
|
|
1014 |
tabableElements isNil ifTrue:[
|
|
1015 |
tabableElements := OrderedCollection new
|
|
1016 |
].
|
|
1017 |
tabableElements add:aComponent
|
|
1018 |
].
|
|
1019 |
^ self addComponent:aComponent
|
|
1020 |
withHeight:(aComponent preferedExtent y).
|
|
1021 |
!
|
|
1022 |
|
120
|
1023 |
addComponent:aComponent
|
122
|
1024 |
"add a component with its prefered height and full width.
|
|
1025 |
Returns the component."
|
120
|
1026 |
|
125
|
1027 |
^ self addComponent:aComponent tabable:false
|
76
|
1028 |
!
|
|
1029 |
|
120
|
1030 |
addTextLabel:aString
|
|
1031 |
"create a text label - the name has been choosen for ST-80 compatibility;
|
122
|
1032 |
however, ST/X labels allow image labels too.
|
|
1033 |
Returns the label."
|
120
|
1034 |
|
|
1035 |
|l|
|
|
1036 |
|
|
1037 |
l := Label new label:aString.
|
|
1038 |
self addComponent:l.
|
|
1039 |
^ l
|
76
|
1040 |
|
120
|
1041 |
"
|
|
1042 |
|b|
|
|
1043 |
|
|
1044 |
b := DialogBox new.
|
|
1045 |
b addTextLabel:'hello'.
|
|
1046 |
b showAtPointer
|
|
1047 |
"
|
|
1048 |
"
|
|
1049 |
|b|
|
|
1050 |
|
|
1051 |
b := DialogBox new.
|
|
1052 |
b leftIndent:100.
|
|
1053 |
b addTextLabel:'hello'.
|
|
1054 |
b leftIndent:0.
|
|
1055 |
b addTextLabel:'world'.
|
|
1056 |
b showAtPointer
|
|
1057 |
"
|
|
1058 |
"
|
|
1059 |
|b|
|
76
|
1060 |
|
120
|
1061 |
b := DialogBox new.
|
|
1062 |
b addTextLabel:'hello'.
|
|
1063 |
b addTextLabel:'world'.
|
|
1064 |
b addOkButton.
|
|
1065 |
b showAtPointer
|
|
1066 |
"
|
|
1067 |
"
|
|
1068 |
|b|
|
|
1069 |
|
|
1070 |
b := DialogBox new.
|
|
1071 |
b addTextLabel:'hello'.
|
|
1072 |
(b addTextLabel:'world') foregroundColor:Color red.
|
|
1073 |
b addOkButton.
|
|
1074 |
b showAtPointer
|
|
1075 |
"
|
|
1076 |
"
|
|
1077 |
|b|
|
|
1078 |
|
|
1079 |
b := DialogBox new.
|
|
1080 |
b addTextLabel:'hello world\\How about this ?' withCRs.
|
|
1081 |
b addOkButton.
|
|
1082 |
b showAtPointer
|
|
1083 |
"
|
|
1084 |
"
|
|
1085 |
|b|
|
|
1086 |
|
|
1087 |
b := DialogBox new.
|
|
1088 |
b addTextLabel:'hello world\\How about this ?' withCRs.
|
|
1089 |
b addTextLabel:'not bad'.
|
|
1090 |
b addAbortButton.
|
|
1091 |
b addOkButton.
|
|
1092 |
b showAtPointer
|
|
1093 |
"
|
|
1094 |
!
|
|
1095 |
|
125
|
1096 |
addCheckBox:label on:aModel tabable:tabable
|
122
|
1097 |
"create a checkBox with label on aModel and add it.
|
|
1098 |
Returns the box."
|
|
1099 |
|
120
|
1100 |
|b|
|
76
|
1101 |
|
120
|
1102 |
b := CheckBox on:aModel.
|
|
1103 |
b label:label.
|
125
|
1104 |
self addComponent:b tabable:tabable.
|
120
|
1105 |
^ b
|
|
1106 |
!
|
|
1107 |
|
125
|
1108 |
addCheckBox:label on:aModel
|
|
1109 |
"create a checkBox with label on aModel and add it.
|
|
1110 |
Returns the box."
|
|
1111 |
|
|
1112 |
^ self addCheckBox:label on:aModel tabable:true
|
|
1113 |
!
|
|
1114 |
|
|
1115 |
addInputField:aField tabable:tabable
|
|
1116 |
"add an already created input field; return the field.
|
|
1117 |
If tabable is true, the field is put into a group, to allow
|
|
1118 |
stepping through the fields with #NextField/#PreviousField keys.
|
|
1119 |
Returns the field."
|
|
1120 |
|
|
1121 |
self addComponent:aField tabable:tabable.
|
|
1122 |
tabable ifTrue:[
|
|
1123 |
inputFieldGroup isNil ifTrue:[
|
|
1124 |
inputFieldGroup := EnterFieldGroup new.
|
|
1125 |
inputFieldGroup leaveAction:[self lastFieldLeft].
|
|
1126 |
aField hasKeyboardFocus:true.
|
|
1127 |
].
|
|
1128 |
inputFieldGroup add:aField.
|
|
1129 |
self delegate:(KeyboardForwarder to:inputFieldGroup condition:#noFocus).
|
|
1130 |
].
|
|
1131 |
^ aField
|
|
1132 |
!
|
|
1133 |
|
122
|
1134 |
addInputField:aField
|
|
1135 |
"add an already created input field; return the field.
|
|
1136 |
Returns the field."
|
120
|
1137 |
|
125
|
1138 |
^ self addInputField:aField tabable:true
|
120
|
1139 |
!
|
|
1140 |
|
125
|
1141 |
addInputFieldOn:aModel tabable:tabable
|
122
|
1142 |
"create an input field on aModel and add it.
|
|
1143 |
Returns the field."
|
|
1144 |
|
120
|
1145 |
|f|
|
|
1146 |
|
|
1147 |
f := EditField new.
|
|
1148 |
f model:aModel.
|
125
|
1149 |
self addInputField:f tabable:tabable.
|
120
|
1150 |
^ f
|
125
|
1151 |
!
|
|
1152 |
|
|
1153 |
addInputFieldOn:aModel
|
|
1154 |
"create an input field on aModel and add it.
|
|
1155 |
Returns the field."
|
|
1156 |
|
|
1157 |
^ self addInputFieldOn:aModel tabable:true
|
120
|
1158 |
|
|
1159 |
"
|
125
|
1160 |
|dialog model field|
|
120
|
1161 |
|
|
1162 |
model := '' asValue.
|
|
1163 |
|
|
1164 |
dialog := DialogBox new.
|
|
1165 |
dialog addTextLabel:'enter a string'.
|
121
|
1166 |
field := dialog addInputFieldOn:model.
|
125
|
1167 |
dialog addAbortButton; addOkButton.
|
120
|
1168 |
dialog open.
|
125
|
1169 |
dialog accepted ifTrue:[Transcript showCr:model value].
|
120
|
1170 |
"
|
122
|
1171 |
!
|
|
1172 |
|
|
1173 |
addVerticalSpace
|
|
1174 |
"add a default vertical space (1 mm)"
|
|
1175 |
|
|
1176 |
self addVerticalSpace:(ViewSpacing).
|
|
1177 |
!
|
|
1178 |
|
|
1179 |
addVerticalSpace:nPixel
|
|
1180 |
"add some pixels of space to the next component"
|
|
1181 |
|
|
1182 |
yPosition := yPosition + nPixel.
|
|
1183 |
!
|
|
1184 |
|
|
1185 |
yPosition
|
|
1186 |
"return the current y position (thats where the next component
|
|
1187 |
will be located)."
|
|
1188 |
|
|
1189 |
^ yPosition
|
|
1190 |
!
|
|
1191 |
|
|
1192 |
yPosition:aNumber
|
|
1193 |
"set the current y position (thats where the next component
|
|
1194 |
will be located)."
|
|
1195 |
|
|
1196 |
yPosition := aNumber.
|
|
1197 |
!
|
|
1198 |
|
|
1199 |
leftIndent:aNumber
|
|
1200 |
"set the left indent (current x position - thats where the next component
|
|
1201 |
will be located)."
|
|
1202 |
|
|
1203 |
leftIndent := aNumber.
|
76
|
1204 |
! !
|
|
1205 |
|
|
1206 |
!DialogBox methodsFor:'initialization'!
|
|
1207 |
|
|
1208 |
initialize
|
|
1209 |
|mm|
|
|
1210 |
|
|
1211 |
super initialize.
|
|
1212 |
|
|
1213 |
label := 'Dialog'.
|
121
|
1214 |
accepted := false.
|
76
|
1215 |
|
|
1216 |
mm := ViewSpacing.
|
|
1217 |
|
|
1218 |
acceptReturnAsOK := true.
|
125
|
1219 |
acceptOnLeave := true.
|
76
|
1220 |
|
|
1221 |
buttonPanel := HorizontalPanelView in:self.
|
118
|
1222 |
buttonPanel
|
|
1223 |
origin:(0.0 @ 1.0) corner:(1.0 @ 1.0);
|
|
1224 |
bottomInset:mm;
|
|
1225 |
topInset:(font height + mm * 2) negated;
|
|
1226 |
borderWidth:0;
|
|
1227 |
layout:#spread.
|
|
1228 |
|
122
|
1229 |
yPosition := ViewSpacing.
|
118
|
1230 |
leftIndent := 0.
|
76
|
1231 |
|
|
1232 |
"
|
|
1233 |
|b|
|
|
1234 |
b := DialogBox new.
|
118
|
1235 |
b addAbortButton;
|
|
1236 |
addOkButton;
|
|
1237 |
showAtPointer
|
76
|
1238 |
"
|
|
1239 |
"
|
|
1240 |
|b|
|
|
1241 |
b := DialogBox new.
|
118
|
1242 |
b addOkButton;
|
|
1243 |
showAtPointer
|
|
1244 |
"
|
76
|
1245 |
"
|
118
|
1246 |
|b|
|
|
1247 |
b := DialogBox new.
|
|
1248 |
b addTextLabel:'hello world';
|
|
1249 |
addOkButton;
|
|
1250 |
showAtPointer
|
|
1251 |
"
|
|
1252 |
"
|
|
1253 |
|b|
|
|
1254 |
b := DialogBox new.
|
|
1255 |
b addTextLabel:'hello world';
|
|
1256 |
addVerticalSpace:50;
|
|
1257 |
addOkButton;
|
|
1258 |
showAtPointer
|
|
1259 |
"
|
76
|
1260 |
!
|
|
1261 |
|
120
|
1262 |
focusSequence
|
125
|
1263 |
"return the elements through which we can step via
|
|
1264 |
NextField/PreviousField keys.
|
|
1265 |
Here we return all tabable fields followed by all buttons in
|
|
1266 |
the panel."
|
|
1267 |
|
|
1268 |
|fields buttons|
|
|
1269 |
|
|
1270 |
tabableElements isNil ifTrue:[
|
|
1271 |
fields := #()
|
|
1272 |
] ifFalse:[
|
|
1273 |
fields := tabableElements
|
|
1274 |
].
|
|
1275 |
buttonPanel notNil ifTrue:[
|
|
1276 |
buttons := buttonPanel subViews.
|
|
1277 |
buttons notNil ifTrue:[
|
|
1278 |
fields := fields , buttonPanel subViews
|
|
1279 |
]
|
|
1280 |
].
|
|
1281 |
^ fields
|
120
|
1282 |
!
|
|
1283 |
|
76
|
1284 |
reAdjustGeometry
|
|
1285 |
"sent late in snapin processing - gives me a chance
|
|
1286 |
to resize for changed font dimensions."
|
|
1287 |
|
|
1288 |
super reAdjustGeometry.
|
|
1289 |
okButton notNil ifTrue:[okButton resize].
|
|
1290 |
abortButton notNil ifTrue:[abortButton resize].
|
|
1291 |
self resize
|
|
1292 |
! !
|
|
1293 |
|
120
|
1294 |
!DialogBox methodsFor:'queries'!
|
118
|
1295 |
|
121
|
1296 |
accepted
|
125
|
1297 |
"after the box has closed: return true if accepted,
|
|
1298 |
false if canceled"
|
|
1299 |
|
121
|
1300 |
^ accepted
|
|
1301 |
!
|
|
1302 |
|
120
|
1303 |
positionOffset
|
|
1304 |
"return the delta, by which the box should be displayed
|
|
1305 |
from the mouse pointer. Value returned here makes center of
|
|
1306 |
okButton appear under the cursor"
|
118
|
1307 |
|
120
|
1308 |
okButton isNil ifTrue:[
|
|
1309 |
^ super positionOffset
|
118
|
1310 |
].
|
120
|
1311 |
buttonPanel setChildPositionsIfChanged.
|
|
1312 |
^ (okButton originRelativeTo:self) + (okButton extent // 2)
|
118
|
1313 |
!
|
|
1314 |
|
120
|
1315 |
preferedExtent
|
|
1316 |
"return my prefered extent"
|
118
|
1317 |
|
120
|
1318 |
|w h p|
|
118
|
1319 |
|
120
|
1320 |
addedComponents notNil ifTrue:[
|
121
|
1321 |
w := addedComponents
|
|
1322 |
inject:0
|
|
1323 |
into:[:max :element |
|
|
1324 |
|eExt|
|
118
|
1325 |
|
121
|
1326 |
eExt := element preferedExtent x. "/ max:element extent x.
|
|
1327 |
max max:(eExt + element leftInset)].
|
120
|
1328 |
] ifFalse:[
|
121
|
1329 |
w := super preferedExtent x.
|
120
|
1330 |
].
|
122
|
1331 |
h := yPosition
|
121
|
1332 |
+ ViewSpacing.
|
118
|
1333 |
|
120
|
1334 |
okButton notNil ifTrue:[
|
121
|
1335 |
p := buttonPanel preferedExtent.
|
|
1336 |
w := w max:p x.
|
|
1337 |
h := h
|
|
1338 |
+ p y
|
|
1339 |
+ ViewSpacing.
|
120
|
1340 |
].
|
118
|
1341 |
|
120
|
1342 |
"/ okButton isNil ifTrue:[
|
|
1343 |
"/ ^ super preferedExtent
|
|
1344 |
"/ ].
|
|
1345 |
"/ p := buttonPanel preferedExtent.
|
|
1346 |
"/ w := p x.
|
|
1347 |
"/ h := ViewSpacing
|
|
1348 |
"/ + p y
|
|
1349 |
"/ + ViewSpacing.
|
|
1350 |
"/
|
|
1351 |
^ w @ h
|
118
|
1352 |
! !
|
|
1353 |
|
76
|
1354 |
!DialogBox methodsFor:'private'!
|
|
1355 |
|
121
|
1356 |
realize
|
|
1357 |
"if any inputFields where added, activate the first one"
|
|
1358 |
|
|
1359 |
inputFieldGroup notNil ifTrue:[
|
|
1360 |
inputFieldGroup activateFirst
|
|
1361 |
].
|
|
1362 |
super realize
|
|
1363 |
!
|
|
1364 |
|
|
1365 |
basicAddComponent:aComponent
|
|
1366 |
"add a component, dont change its size"
|
|
1367 |
|
|
1368 |
addedComponents isNil ifTrue:[
|
|
1369 |
addedComponents := OrderedCollection new.
|
|
1370 |
].
|
|
1371 |
addedComponents add:aComponent.
|
|
1372 |
self addSubView:aComponent.
|
|
1373 |
!
|
|
1374 |
|
76
|
1375 |
hideAndEvaluate:aBlock
|
|
1376 |
"make myself invisible and evaluate aBlock"
|
|
1377 |
|
|
1378 |
self hide.
|
|
1379 |
aBlock notNil ifTrue:[aBlock value]
|
|
1380 |
! !
|
|
1381 |
|
|
1382 |
!DialogBox methodsFor:'accessing'!
|
|
1383 |
|
120
|
1384 |
okText:aString
|
|
1385 |
"define the text in the ok-button"
|
|
1386 |
|
|
1387 |
|oldSize|
|
76
|
1388 |
|
120
|
1389 |
aString ~= okButton label ifTrue:[
|
|
1390 |
oldSize := okButton extent.
|
|
1391 |
okButton label:aString.
|
|
1392 |
okButton resize.
|
|
1393 |
okButton extent ~= oldSize ifTrue:[
|
|
1394 |
shown ifTrue:[self resize]
|
|
1395 |
]
|
76
|
1396 |
]
|
|
1397 |
!
|
|
1398 |
|
|
1399 |
okAction:aBlock
|
|
1400 |
"define the action to be performed when ok is pressed"
|
|
1401 |
|
|
1402 |
okAction := aBlock
|
|
1403 |
!
|
|
1404 |
|
|
1405 |
action:aBlock
|
|
1406 |
"set the action to be performed when user presses ok-button;
|
|
1407 |
aBlock must be nil or a block. This method simply
|
|
1408 |
reuses okAction: and has been added for a consistent action-setting
|
|
1409 |
protocol."
|
|
1410 |
|
|
1411 |
self okAction:aBlock
|
|
1412 |
!
|
|
1413 |
|
120
|
1414 |
acceptReturnAsOK:aBoolean
|
|
1415 |
"turn on/off interpretation of return-key as ok.
|
|
1416 |
Default is on"
|
|
1417 |
|
|
1418 |
acceptReturnAsOK := aBoolean.
|
|
1419 |
okButton notNil ifTrue:[
|
|
1420 |
okButton isReturnButton:aBoolean.
|
|
1421 |
]
|
|
1422 |
!
|
|
1423 |
|
76
|
1424 |
okButton
|
|
1425 |
"return the okButton"
|
|
1426 |
|
|
1427 |
^ okButton
|
|
1428 |
!
|
|
1429 |
|
|
1430 |
abortAction:aBlock
|
|
1431 |
"define the action to be performed when abort is pressed"
|
|
1432 |
|
|
1433 |
abortAction := aBlock
|
|
1434 |
!
|
|
1435 |
|
|
1436 |
abortText:aString
|
|
1437 |
"define the label in the abort-button"
|
|
1438 |
|
|
1439 |
|oldSize|
|
|
1440 |
|
|
1441 |
aString ~= abortButton label ifTrue:[
|
|
1442 |
oldSize := abortButton extent.
|
|
1443 |
abortButton label:aString.
|
|
1444 |
abortButton resize.
|
|
1445 |
abortButton extent ~= oldSize ifTrue:[
|
97
|
1446 |
shown ifTrue:[self resize]
|
76
|
1447 |
]
|
|
1448 |
]
|
|
1449 |
!
|
|
1450 |
|
120
|
1451 |
abortButton
|
|
1452 |
"return the abortButton"
|
|
1453 |
|
|
1454 |
^ abortButton
|
|
1455 |
!
|
|
1456 |
|
76
|
1457 |
okText:okString abortText:abortString
|
|
1458 |
"set both texts displayed in the buttons"
|
|
1459 |
|
|
1460 |
(abortString ~= abortButton label
|
|
1461 |
or:[okString ~= okButton label]) ifTrue:[
|
|
1462 |
okButton label:okString.
|
|
1463 |
abortButton label:abortString.
|
|
1464 |
okButton resize.
|
|
1465 |
abortButton resize.
|
97
|
1466 |
shown ifTrue:[self resize]
|
76
|
1467 |
]
|
|
1468 |
! !
|