0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
59
|
3 |
All Rights Reserved
|
0
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
77
|
13 |
'From Smalltalk/X, Version:2.10.4 on 28-dec-1994 at 2:45:44 pm'!
|
|
14 |
|
|
15 |
DialogBox subclass:#EnterBox
|
|
16 |
instanceVariableNames:'labelField enterField'
|
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Views-DialogBoxes'
|
0
|
20 |
!
|
|
21 |
|
3
|
22 |
!EnterBox class methodsFor:'documentation'!
|
|
23 |
|
38
|
24 |
copyright
|
|
25 |
"
|
|
26 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
59
|
27 |
All Rights Reserved
|
38
|
28 |
|
|
29 |
This software is furnished under a license and may be used
|
|
30 |
only in accordance with the terms of that license and with the
|
|
31 |
inclusion of the above copyright notice. This software may not
|
|
32 |
be provided or otherwise made available to, or used by, any
|
|
33 |
other person. No title to or ownership of the software is
|
|
34 |
hereby transferred.
|
|
35 |
"
|
|
36 |
!
|
|
37 |
|
|
38 |
version
|
181
|
39 |
^ '$Header: /cvs/stx/stx/libwidg/EnterBox.st,v 1.32 1995-11-16 20:34:12 cg Exp $'
|
38
|
40 |
!
|
|
41 |
|
3
|
42 |
documentation
|
|
43 |
"
|
38
|
44 |
this class implements a pop-up box to enter some string
|
|
45 |
with 2 buttons; a cancel button, and a trigger-action button.
|
|
46 |
The boxes title can be changed using:
|
3
|
47 |
|
59
|
48 |
aBox title:'some string'
|
38
|
49 |
|
|
50 |
The two button-labels default to 'abort' and 'ok';
|
|
51 |
they can be changed using:
|
3
|
52 |
|
59
|
53 |
aBox okText:'someString'
|
|
54 |
aBox abortText:'someString'
|
38
|
55 |
|
|
56 |
The initial text in the enterfield can be set using:
|
3
|
57 |
|
59
|
58 |
aBox initialText:'someString'
|
3
|
59 |
|
38
|
60 |
when the ok-button is pressed, an action is performed, which is
|
|
61 |
set using:
|
3
|
62 |
|
59
|
63 |
aBox action:[ ... ]
|
3
|
64 |
|
38
|
65 |
the abort-action defaults to no-action, but can also be set.
|
|
66 |
The box can be opened modal (i.e. the currently active view will
|
|
67 |
be suspended) or modeless. The default is modal (i.e. sending #open
|
|
68 |
is equivalent to #openModal).
|
62
|
69 |
"
|
|
70 |
!
|
3
|
71 |
|
62
|
72 |
examples
|
|
73 |
"
|
|
74 |
examples:
|
59
|
75 |
|box|
|
|
76 |
|
|
77 |
box := EnterBox new.
|
|
78 |
box title:'your name please:'.
|
|
79 |
box action:[:arg | Transcript showCr:'entered: ' , arg printString].
|
|
80 |
box open
|
|
81 |
|
181
|
82 |
non-modal:
|
59
|
83 |
|box|
|
8
|
84 |
|
59
|
85 |
box := EnterBox new.
|
|
86 |
box title:'your name please:'.
|
|
87 |
box action:[:arg | Transcript showCr:'entered: ' , arg printString].
|
|
88 |
box openModeless
|
|
89 |
|
62
|
90 |
for easier instance creation, there are also some combination
|
|
91 |
methods for instance creation:
|
|
92 |
|
|
93 |
|box|
|
|
94 |
|
|
95 |
box := EnterBox
|
|
96 |
title:'your name please:'
|
|
97 |
action:[:arg | Transcript showCr:'entered: ' , arg printString].
|
|
98 |
box openModeless
|
|
99 |
|
59
|
100 |
If the box is needed to ask for a simple string, you can also use the
|
|
101 |
#request method, to bring up a box, let it ask for something and return
|
|
102 |
the entered string. This method will return nil, if the box was
|
|
103 |
closed with the 'abort' button.
|
|
104 |
Example:
|
8
|
105 |
|
59
|
106 |
|box string|
|
|
107 |
|
60
|
108 |
box := EnterBox request:'input some string:'.
|
59
|
109 |
string isNil ifTrue:[
|
|
110 |
Transcript showCr:'no input'
|
|
111 |
] ifFalse:[
|
134
|
112 |
Transcript showCr:('the entered string was: ' , string)
|
59
|
113 |
]
|
38
|
114 |
|
59
|
115 |
of course, this can be written shorter as:
|
|
116 |
|
|
117 |
|string|
|
|
118 |
|
60
|
119 |
string := EnterBox request:'input some string:'.
|
59
|
120 |
string isNil ifTrue:[
|
|
121 |
Transcript showCr:'no input'
|
|
122 |
] ifFalse:[
|
134
|
123 |
Transcript showCr:('the entered string was: ' , string)
|
59
|
124 |
]
|
181
|
125 |
|
|
126 |
|
|
127 |
A box for passwords is created with:
|
|
128 |
|
|
129 |
|box|
|
|
130 |
|
|
131 |
box := EnterBox
|
|
132 |
title:'your name please:'
|
|
133 |
action:[:arg | Transcript showCr:'entered: ' , arg printString].
|
|
134 |
box enterField passwordCharacter:$*.
|
|
135 |
box showAtPointer
|
|
136 |
|
|
137 |
or simply:
|
|
138 |
|
|
139 |
|string|
|
|
140 |
|
|
141 |
string := EnterBox requestPassword:'enter your password:'.
|
|
142 |
Transcript showCr:string.
|
3
|
143 |
"
|
181
|
144 |
|
|
145 |
"Modified: 16.11.1995 / 21:28:11 / cg"
|
3
|
146 |
! !
|
|
147 |
|
0
|
148 |
!EnterBox class methodsFor:'instance creation'!
|
|
149 |
|
|
150 |
action:aBlock
|
|
151 |
"create and return a new EnterBox
|
|
152 |
which will evaluate aBlock when 'ok' is pressed"
|
|
153 |
|
|
154 |
^ (self new) action:aBlock
|
|
155 |
|
|
156 |
"(EnterBox action:[:string | Transcript showCr:string]) showAtPointer"
|
|
157 |
!
|
|
158 |
|
62
|
159 |
title:titleString
|
|
160 |
"create and return a new EnterBox with title aString"
|
|
161 |
|
|
162 |
^ self new title:titleString
|
|
163 |
!
|
|
164 |
|
101
|
165 |
title:titleString action:aBlock
|
|
166 |
"create and return a new EnterBox with title aString,
|
|
167 |
which will evaluate aBlock when 'ok' is pressed"
|
|
168 |
|
|
169 |
^ (self title:titleString) action:aBlock
|
|
170 |
!
|
|
171 |
|
|
172 |
title:titleString okText:okText action:aBlock
|
|
173 |
"create and return a new EnterBox with title aString, and ok button showing
|
|
174 |
okText; it will evaluate aBlock when 'ok' is pressed"
|
|
175 |
|
|
176 |
^ (self title:titleString action:aBlock) okText:okText
|
|
177 |
!
|
|
178 |
|
0
|
179 |
title:titleString okText:okText abortText:abortText action:aBlock
|
|
180 |
"create and return a new EnterBox with title aString, and buttons showing
|
|
181 |
okText and abortText; it will evaluate aBlock when 'ok' is pressed"
|
|
182 |
|
101
|
183 |
^ (self title:titleString okText:okText action:aBlock) abortText:abortText
|
77
|
184 |
! !
|
|
185 |
|
|
186 |
!EnterBox class methodsFor:'defaults'!
|
|
187 |
|
|
188 |
minExtent
|
|
189 |
^ self defaultExtent
|
|
190 |
!
|
|
191 |
|
|
192 |
defaultExtent
|
131
|
193 |
^ (Screen current pixelPerMillimeter * (60 @ 30)) rounded
|
77
|
194 |
! !
|
|
195 |
|
|
196 |
!EnterBox class methodsFor:'easy startup '!
|
|
197 |
|
|
198 |
request:aTitle
|
|
199 |
"create and show an enterBox asking for aTitle.
|
|
200 |
Return the enterred string or nil (if abort was pressed).
|
|
201 |
The string may be empty, in case return was pressed immediately."
|
|
202 |
|
|
203 |
^ self new request:aTitle
|
|
204 |
|
|
205 |
"
|
|
206 |
EnterBox request:'enter a string'
|
|
207 |
"
|
181
|
208 |
!
|
|
209 |
|
|
210 |
requestPassword:aTitle
|
|
211 |
"create and show an enterBox asking for aTitle.
|
|
212 |
The box is setup to NOT display entered characters (as with password entry).
|
|
213 |
Return the entered string or nil (if abort was pressed).
|
|
214 |
The string may be empty, in case return was pressed immediately."
|
|
215 |
|
|
216 |
^ self new requestPassword:aTitle
|
|
217 |
|
|
218 |
"
|
|
219 |
|s|
|
|
220 |
|
|
221 |
s := EnterBox requestPassword:'enter a string'.
|
|
222 |
Transcript showCr:'you entered: ' , s
|
|
223 |
"
|
|
224 |
|
|
225 |
"Created: 16.11.1995 / 21:25:08 / cg"
|
77
|
226 |
! !
|
|
227 |
|
|
228 |
!EnterBox methodsFor:'accessing'!
|
|
229 |
|
|
230 |
contents
|
|
231 |
"return my contents"
|
|
232 |
|
|
233 |
^ enterField contents
|
|
234 |
!
|
|
235 |
|
144
|
236 |
contents:aString
|
|
237 |
"set my contents"
|
|
238 |
|
|
239 |
enterField contents:aString
|
|
240 |
!
|
|
241 |
|
77
|
242 |
initialText:aString
|
|
243 |
"define the initial text in the enterfield. all will be selected initially"
|
|
244 |
|
|
245 |
enterField initialText:aString
|
|
246 |
!
|
|
247 |
|
144
|
248 |
entryCompletionBlock:aBlock
|
|
249 |
enterField entryCompletionBlock:aBlock
|
|
250 |
!
|
|
251 |
|
77
|
252 |
title:aString
|
|
253 |
"set the title to be displayed at top of enterBox"
|
|
254 |
|
|
255 |
|oldSize|
|
|
256 |
|
|
257 |
aString ~= labelField label ifTrue:[
|
|
258 |
oldSize := labelField extent.
|
|
259 |
labelField label:aString.
|
110
|
260 |
labelField forceResize.
|
77
|
261 |
|
118
|
262 |
shown ifTrue:[
|
|
263 |
labelField extent ~= oldSize ifTrue:[
|
|
264 |
self resize
|
|
265 |
]
|
77
|
266 |
]
|
|
267 |
]
|
|
268 |
!
|
|
269 |
|
|
270 |
initialText:aString selectFrom:start to:stop
|
|
271 |
"define the initial text in the enterfield, and the part to be selected"
|
|
272 |
|
|
273 |
enterField initialText:aString.
|
|
274 |
enterField selectFromLine:1 col:start toLine:1 col:stop
|
|
275 |
!
|
|
276 |
|
|
277 |
title:titleString okText:okString
|
|
278 |
"set title and text in okbutton"
|
|
279 |
|
|
280 |
(titleString ~= labelField label or:[okString ~= okButton label]) ifTrue:[
|
|
281 |
okButton label:okString.
|
|
282 |
okButton resize.
|
|
283 |
labelField label:titleString.
|
110
|
284 |
labelField forceResize.
|
97
|
285 |
shown ifTrue:[self resize].
|
77
|
286 |
]
|
|
287 |
!
|
|
288 |
|
|
289 |
title:titleString okText:okString abortText:abortString
|
|
290 |
"set title and texts in the buttons"
|
|
291 |
|
|
292 |
(titleString ~= labelField label
|
|
293 |
or:[okString ~= okButton label
|
|
294 |
or:[abortString ~= abortButton label]]) ifTrue:[
|
|
295 |
okButton label:okString.
|
|
296 |
okButton resize.
|
|
297 |
abortButton label:abortString.
|
|
298 |
abortButton resize.
|
|
299 |
labelField label:titleString.
|
110
|
300 |
labelField forceResize.
|
97
|
301 |
shown ifTrue:[self resize].
|
77
|
302 |
]
|
181
|
303 |
!
|
|
304 |
|
|
305 |
enterField
|
|
306 |
"provide access to the entryfield"
|
|
307 |
|
|
308 |
^ enterField
|
|
309 |
|
|
310 |
"Created: 16.11.1995 / 21:23:48 / cg"
|
|
311 |
!
|
|
312 |
|
|
313 |
labelField
|
|
314 |
"provide access to the labelfield"
|
|
315 |
|
|
316 |
^ labelField
|
|
317 |
|
|
318 |
"Created: 16.11.1995 / 21:23:48 / cg"
|
0
|
319 |
! !
|
|
320 |
|
|
321 |
!EnterBox methodsFor:'initialization'!
|
|
322 |
|
77
|
323 |
createEnterField
|
|
324 |
"this has been extracted from the initialize method
|
121
|
325 |
to allow redefinition in subclasses. (FilenameEnterBox for example).
|
|
326 |
It shall return a new instance of the desired editField class."
|
77
|
327 |
|
121
|
328 |
^ EditField new.
|
77
|
329 |
!
|
|
330 |
|
0
|
331 |
initialize
|
90
|
332 |
|space2 innerWidth|
|
0
|
333 |
|
|
334 |
super initialize.
|
|
335 |
|
77
|
336 |
self addAbortButton; addOkButton.
|
|
337 |
|
150
|
338 |
label := resources string:'Enter'.
|
73
|
339 |
|
0
|
340 |
space2 := 2 * ViewSpacing.
|
73
|
341 |
innerWidth := width - space2.
|
0
|
342 |
|
|
343 |
labelField := Label in:self.
|
118
|
344 |
labelField
|
|
345 |
label:'';
|
|
346 |
borderWidth:0;
|
|
347 |
adjust:#left;
|
|
348 |
origin:(0.0 @ ViewSpacing) extent:[1.0 @ labelField height];
|
|
349 |
leftInset:ViewSpacing;
|
|
350 |
rightInset:ViewSpacing.
|
0
|
351 |
|
121
|
352 |
self addComponent:(enterField := self createEnterField).
|
118
|
353 |
enterField
|
130
|
354 |
origin:[0.0 @ (space2 + labelField preferredExtent y "height")]
|
139
|
355 |
extent:(1.0 @ enterField height).
|
118
|
356 |
enterField
|
139
|
357 |
leftInset:ViewSpacing-enterField borderWidth;
|
118
|
358 |
rightInset:ViewSpacing;
|
|
359 |
leaveAction:[:key | self okPressed].
|
|
360 |
|
130
|
361 |
enterField addDependent:self. "to get preferredExtent-changes"
|
0
|
362 |
|
59
|
363 |
"
|
|
364 |
forward keyboard input to the enterfield
|
|
365 |
"
|
122
|
366 |
self delegate:(KeyboardForwarder toView:enterField condition:#noFocus).
|
121
|
367 |
enterField hasKeyboardFocus:true.
|
0
|
368 |
!
|
|
369 |
|
|
370 |
reAdjustGeometry
|
|
371 |
"sent late in snapin processing - gives me a chance
|
|
372 |
to resize for new font dimensions"
|
|
373 |
|
|
374 |
super reAdjustGeometry.
|
|
375 |
labelField resize.
|
|
376 |
okButton resize.
|
|
377 |
abortButton resize.
|
|
378 |
self resize
|
77
|
379 |
!
|
7
|
380 |
|
77
|
381 |
focusSequence
|
|
382 |
^ Array with:enterField with:abortButton with:okButton
|
7
|
383 |
! !
|
|
384 |
|
155
|
385 |
!EnterBox methodsFor:'change & update'!
|
59
|
386 |
|
77
|
387 |
update:something with:someArgument from:changedObject
|
|
388 |
"sent if my enterbox thinks it needs more real-estate ..."
|
59
|
389 |
|
77
|
390 |
changedObject == enterField ifTrue:[
|
130
|
391 |
something == #preferredExtent ifTrue:[
|
155
|
392 |
shown ifTrue:[self resizeUnderPointer].
|
105
|
393 |
^ self
|
77
|
394 |
]
|
105
|
395 |
].
|
|
396 |
super update:something with:someArgument from:changedObject
|
59
|
397 |
! !
|
|
398 |
|
62
|
399 |
!EnterBox methodsFor:'queries'!
|
0
|
400 |
|
130
|
401 |
preferredExtent
|
110
|
402 |
|wWanted hWanted wPanel vs2 min
|
|
403 |
labelPref enterPref panelPref|
|
59
|
404 |
|
130
|
405 |
panelPref := buttonPanel preferredExtent.
|
|
406 |
labelPref := labelField preferredExtent.
|
|
407 |
enterPref := enterField preferredExtent.
|
110
|
408 |
wWanted := (labelPref x max:enterPref x).
|
|
409 |
wPanel := panelPref x.
|
59
|
410 |
wPanel > wWanted ifTrue:[
|
|
411 |
wWanted := wPanel
|
|
412 |
].
|
110
|
413 |
|
|
414 |
hWanted := labelPref y + enterPref y +
|
73
|
415 |
(ViewSpacing * 6) + panelPref y + ViewSpacing.
|
59
|
416 |
|
|
417 |
min := self class minExtent.
|
|
418 |
wWanted < min x ifTrue:[
|
|
419 |
wWanted := min x
|
|
420 |
].
|
|
421 |
hWanted < min y ifTrue:[
|
|
422 |
hWanted := min y
|
|
423 |
].
|
110
|
424 |
vs2 := ViewSpacing * 2.
|
|
425 |
^ (wWanted + vs2) @ (hWanted + vs2)
|
0
|
426 |
! !
|
|
427 |
|
77
|
428 |
!EnterBox methodsFor:'user actions'!
|
0
|
429 |
|
|
430 |
hideAndEvaluate:aBlock
|
|
431 |
"common processing for all ok-actions (see subclasses);
|
155
|
432 |
if modal, shut down box.
|
|
433 |
Then fetch entered string and evaluate the passed action with it"
|
0
|
434 |
|
|
435 |
|string|
|
|
436 |
|
155
|
437 |
(windowGroup notNil and:[windowGroup isModal]) ifTrue:[
|
|
438 |
self hide.
|
|
439 |
].
|
0
|
440 |
aBlock notNil ifTrue:[
|
59
|
441 |
string := self contents.
|
|
442 |
string isNil ifTrue:[
|
|
443 |
string := ''
|
|
444 |
] ifFalse:[
|
|
445 |
string := string withoutSeparators
|
|
446 |
].
|
|
447 |
aBlock value:string
|
0
|
448 |
]
|
77
|
449 |
! !
|
|
450 |
|
|
451 |
!EnterBox methodsFor:'startup'!
|
|
452 |
|
|
453 |
request
|
|
454 |
"open the box and return the entered string or nil, if
|
|
455 |
abort was pressed"
|
|
456 |
|
|
457 |
self action:[:string | ^ string].
|
|
458 |
self open.
|
|
459 |
^ nil
|
0
|
460 |
!
|
|
461 |
|
77
|
462 |
request:title
|
|
463 |
"set the title, open the box and return the entered string or nil, if
|
|
464 |
abort was pressed"
|
0
|
465 |
|
77
|
466 |
self title:title.
|
|
467 |
^ self request
|
181
|
468 |
!
|
|
469 |
|
|
470 |
requestPassword
|
|
471 |
"open the box for a password (i.e. hide entered characters)
|
|
472 |
and return the entered string or nil, if abort was pressed"
|
|
473 |
|
|
474 |
enterField passwordCharacter:$*.
|
|
475 |
^ self request.
|
|
476 |
|
|
477 |
"Created: 16.11.1995 / 21:25:33 / cg"
|
|
478 |
!
|
|
479 |
|
|
480 |
requestPassword:title
|
|
481 |
"set the title, set password mode, open the box and return the entered string or nil, if
|
|
482 |
abort was pressed"
|
|
483 |
|
|
484 |
enterField passwordCharacter:$*.
|
|
485 |
^ self request:title
|
|
486 |
|
|
487 |
"Created: 16.11.1995 / 21:25:33 / cg"
|
77
|
488 |
! !
|