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
|
|
39 |
"
|
122
|
40 |
$Header: /cvs/stx/stx/libwidg/EnterBox.st,v 1.23 1995-05-07 00:16:00 claus Exp $
|
38
|
41 |
"
|
|
42 |
!
|
|
43 |
|
3
|
44 |
documentation
|
|
45 |
"
|
38
|
46 |
this class implements a pop-up box to enter some string
|
|
47 |
with 2 buttons; a cancel button, and a trigger-action button.
|
|
48 |
The boxes title can be changed using:
|
3
|
49 |
|
59
|
50 |
aBox title:'some string'
|
38
|
51 |
|
|
52 |
The two button-labels default to 'abort' and 'ok';
|
|
53 |
they can be changed using:
|
3
|
54 |
|
59
|
55 |
aBox okText:'someString'
|
|
56 |
aBox abortText:'someString'
|
38
|
57 |
|
|
58 |
The initial text in the enterfield can be set using:
|
3
|
59 |
|
59
|
60 |
aBox initialText:'someString'
|
3
|
61 |
|
38
|
62 |
when the ok-button is pressed, an action is performed, which is
|
|
63 |
set using:
|
3
|
64 |
|
59
|
65 |
aBox action:[ ... ]
|
3
|
66 |
|
38
|
67 |
the abort-action defaults to no-action, but can also be set.
|
|
68 |
The box can be opened modal (i.e. the currently active view will
|
|
69 |
be suspended) or modeless. The default is modal (i.e. sending #open
|
|
70 |
is equivalent to #openModal).
|
62
|
71 |
"
|
|
72 |
!
|
3
|
73 |
|
62
|
74 |
examples
|
|
75 |
"
|
|
76 |
examples:
|
59
|
77 |
|box|
|
|
78 |
|
|
79 |
box := EnterBox new.
|
|
80 |
box title:'your name please:'.
|
|
81 |
box action:[:arg | Transcript showCr:'entered: ' , arg printString].
|
|
82 |
box open
|
|
83 |
|
|
84 |
|box|
|
8
|
85 |
|
59
|
86 |
box := EnterBox new.
|
|
87 |
box title:'your name please:'.
|
|
88 |
box action:[:arg | Transcript showCr:'entered: ' , arg printString].
|
|
89 |
box openModeless
|
|
90 |
|
62
|
91 |
for easier instance creation, there are also some combination
|
|
92 |
methods for instance creation:
|
|
93 |
|
|
94 |
|box|
|
|
95 |
|
|
96 |
box := EnterBox
|
|
97 |
title:'your name please:'
|
|
98 |
action:[:arg | Transcript showCr:'entered: ' , arg printString].
|
|
99 |
box openModeless
|
|
100 |
|
59
|
101 |
If the box is needed to ask for a simple string, you can also use the
|
|
102 |
#request method, to bring up a box, let it ask for something and return
|
|
103 |
the entered string. This method will return nil, if the box was
|
|
104 |
closed with the 'abort' button.
|
|
105 |
Example:
|
8
|
106 |
|
59
|
107 |
|box string|
|
|
108 |
|
60
|
109 |
box := EnterBox request:'input some string:'.
|
59
|
110 |
string isNil ifTrue:[
|
|
111 |
Transcript showCr:'no input'
|
|
112 |
] ifFalse:[
|
|
113 |
Transcript showCr:('the enetered string was: ' , string)
|
|
114 |
]
|
38
|
115 |
|
59
|
116 |
of course, this can be written shorter as:
|
|
117 |
|
|
118 |
|string|
|
|
119 |
|
60
|
120 |
string := EnterBox request:'input some string:'.
|
59
|
121 |
string isNil ifTrue:[
|
|
122 |
Transcript showCr:'no input'
|
|
123 |
] ifFalse:[
|
|
124 |
Transcript showCr:('the enetered string was: ' , string)
|
|
125 |
]
|
3
|
126 |
"
|
|
127 |
! !
|
|
128 |
|
0
|
129 |
!EnterBox class methodsFor:'instance creation'!
|
|
130 |
|
|
131 |
action:aBlock
|
|
132 |
"create and return a new EnterBox
|
|
133 |
which will evaluate aBlock when 'ok' is pressed"
|
|
134 |
|
|
135 |
^ (self new) action:aBlock
|
|
136 |
|
|
137 |
"(EnterBox action:[:string | Transcript showCr:string]) showAtPointer"
|
|
138 |
!
|
|
139 |
|
62
|
140 |
title:titleString
|
|
141 |
"create and return a new EnterBox with title aString"
|
|
142 |
|
|
143 |
^ self new title:titleString
|
|
144 |
!
|
|
145 |
|
101
|
146 |
title:titleString action:aBlock
|
|
147 |
"create and return a new EnterBox with title aString,
|
|
148 |
which will evaluate aBlock when 'ok' is pressed"
|
|
149 |
|
|
150 |
^ (self title:titleString) action:aBlock
|
|
151 |
!
|
|
152 |
|
|
153 |
title:titleString okText:okText action:aBlock
|
|
154 |
"create and return a new EnterBox with title aString, and ok button showing
|
|
155 |
okText; it will evaluate aBlock when 'ok' is pressed"
|
|
156 |
|
|
157 |
^ (self title:titleString action:aBlock) okText:okText
|
|
158 |
!
|
|
159 |
|
0
|
160 |
title:titleString okText:okText abortText:abortText action:aBlock
|
|
161 |
"create and return a new EnterBox with title aString, and buttons showing
|
|
162 |
okText and abortText; it will evaluate aBlock when 'ok' is pressed"
|
|
163 |
|
101
|
164 |
^ (self title:titleString okText:okText action:aBlock) abortText:abortText
|
77
|
165 |
! !
|
|
166 |
|
|
167 |
!EnterBox class methodsFor:'defaults'!
|
|
168 |
|
|
169 |
minExtent
|
|
170 |
^ self defaultExtent
|
|
171 |
!
|
|
172 |
|
|
173 |
defaultExtent
|
|
174 |
^ (Display pixelPerMillimeter * (60 @ 30)) rounded
|
|
175 |
! !
|
|
176 |
|
|
177 |
!EnterBox class methodsFor:'easy startup '!
|
|
178 |
|
|
179 |
request:aTitle
|
|
180 |
"create and show an enterBox asking for aTitle.
|
|
181 |
Return the enterred string or nil (if abort was pressed).
|
|
182 |
The string may be empty, in case return was pressed immediately."
|
|
183 |
|
|
184 |
^ self new request:aTitle
|
|
185 |
|
|
186 |
"
|
|
187 |
EnterBox request:'enter a string'
|
|
188 |
"
|
|
189 |
! !
|
|
190 |
|
|
191 |
!EnterBox methodsFor:'accessing'!
|
|
192 |
|
|
193 |
contents
|
|
194 |
"return my contents"
|
|
195 |
|
|
196 |
^ enterField contents
|
|
197 |
!
|
|
198 |
|
|
199 |
initialText:aString
|
|
200 |
"define the initial text in the enterfield. all will be selected initially"
|
|
201 |
|
|
202 |
enterField initialText:aString
|
|
203 |
!
|
|
204 |
|
|
205 |
title:aString
|
|
206 |
"set the title to be displayed at top of enterBox"
|
|
207 |
|
|
208 |
|oldSize|
|
|
209 |
|
|
210 |
aString ~= labelField label ifTrue:[
|
|
211 |
oldSize := labelField extent.
|
|
212 |
labelField label:aString.
|
110
|
213 |
labelField forceResize.
|
77
|
214 |
|
118
|
215 |
shown ifTrue:[
|
|
216 |
labelField extent ~= oldSize ifTrue:[
|
|
217 |
self resize
|
|
218 |
]
|
77
|
219 |
]
|
|
220 |
]
|
|
221 |
!
|
|
222 |
|
|
223 |
initialText:aString selectFrom:start to:stop
|
|
224 |
"define the initial text in the enterfield, and the part to be selected"
|
|
225 |
|
|
226 |
enterField initialText:aString.
|
|
227 |
enterField selectFromLine:1 col:start toLine:1 col:stop
|
|
228 |
!
|
|
229 |
|
|
230 |
title:titleString okText:okString
|
|
231 |
"set title and text in okbutton"
|
|
232 |
|
|
233 |
(titleString ~= labelField label or:[okString ~= okButton label]) ifTrue:[
|
|
234 |
okButton label:okString.
|
|
235 |
okButton resize.
|
|
236 |
labelField label:titleString.
|
110
|
237 |
labelField forceResize.
|
97
|
238 |
shown ifTrue:[self resize].
|
77
|
239 |
]
|
|
240 |
!
|
|
241 |
|
|
242 |
title:titleString okText:okString abortText:abortString
|
|
243 |
"set title and texts in the buttons"
|
|
244 |
|
|
245 |
(titleString ~= labelField label
|
|
246 |
or:[okString ~= okButton label
|
|
247 |
or:[abortString ~= abortButton label]]) ifTrue:[
|
|
248 |
okButton label:okString.
|
|
249 |
okButton resize.
|
|
250 |
abortButton label:abortString.
|
|
251 |
abortButton resize.
|
|
252 |
labelField label:titleString.
|
110
|
253 |
labelField forceResize.
|
97
|
254 |
shown ifTrue:[self resize].
|
77
|
255 |
]
|
0
|
256 |
! !
|
|
257 |
|
|
258 |
!EnterBox methodsFor:'initialization'!
|
|
259 |
|
77
|
260 |
createEnterField
|
|
261 |
"this has been extracted from the initialize method
|
121
|
262 |
to allow redefinition in subclasses. (FilenameEnterBox for example).
|
|
263 |
It shall return a new instance of the desired editField class."
|
77
|
264 |
|
121
|
265 |
^ EditField new.
|
77
|
266 |
!
|
|
267 |
|
0
|
268 |
initialize
|
90
|
269 |
|space2 innerWidth|
|
0
|
270 |
|
|
271 |
super initialize.
|
|
272 |
|
77
|
273 |
self addAbortButton; addOkButton.
|
|
274 |
|
73
|
275 |
label := 'Enter'.
|
|
276 |
|
0
|
277 |
space2 := 2 * ViewSpacing.
|
73
|
278 |
innerWidth := width - space2.
|
0
|
279 |
|
|
280 |
labelField := Label in:self.
|
118
|
281 |
labelField
|
|
282 |
label:'';
|
|
283 |
borderWidth:0;
|
|
284 |
adjust:#left;
|
|
285 |
origin:(0.0 @ ViewSpacing) extent:[1.0 @ labelField height];
|
|
286 |
leftInset:ViewSpacing;
|
|
287 |
rightInset:ViewSpacing.
|
0
|
288 |
|
121
|
289 |
self addComponent:(enterField := self createEnterField).
|
118
|
290 |
enterField
|
|
291 |
origin:[0.0 @ (space2 + labelField preferedExtent y "height")]
|
|
292 |
extent:[1.0 @ enterField height].
|
|
293 |
enterField
|
|
294 |
leftInset:ViewSpacing;
|
|
295 |
rightInset:ViewSpacing;
|
|
296 |
leaveAction:[:key | self okPressed].
|
|
297 |
|
59
|
298 |
enterField addDependent:self. "to get preferedExtent-changes"
|
0
|
299 |
|
59
|
300 |
"
|
|
301 |
forward keyboard input to the enterfield
|
|
302 |
"
|
122
|
303 |
self delegate:(KeyboardForwarder toView:enterField condition:#noFocus).
|
121
|
304 |
enterField hasKeyboardFocus:true.
|
0
|
305 |
!
|
|
306 |
|
|
307 |
reAdjustGeometry
|
|
308 |
"sent late in snapin processing - gives me a chance
|
|
309 |
to resize for new font dimensions"
|
|
310 |
|
|
311 |
super reAdjustGeometry.
|
|
312 |
labelField resize.
|
|
313 |
okButton resize.
|
|
314 |
abortButton resize.
|
|
315 |
self resize
|
77
|
316 |
!
|
7
|
317 |
|
77
|
318 |
focusSequence
|
|
319 |
^ Array with:enterField with:abortButton with:okButton
|
7
|
320 |
! !
|
|
321 |
|
77
|
322 |
!EnterBox methodsFor:'dependencies'!
|
59
|
323 |
|
77
|
324 |
update:something with:someArgument from:changedObject
|
|
325 |
"sent if my enterbox thinks it needs more real-estate ..."
|
59
|
326 |
|
77
|
327 |
changedObject == enterField ifTrue:[
|
|
328 |
something == #preferedExtent ifTrue:[
|
105
|
329 |
shown ifTrue:[self resize].
|
|
330 |
^ self
|
77
|
331 |
]
|
105
|
332 |
].
|
|
333 |
super update:something with:someArgument from:changedObject
|
59
|
334 |
! !
|
|
335 |
|
62
|
336 |
!EnterBox methodsFor:'queries'!
|
0
|
337 |
|
59
|
338 |
preferedExtent
|
110
|
339 |
|wWanted hWanted wPanel vs2 min
|
|
340 |
labelPref enterPref panelPref|
|
59
|
341 |
|
73
|
342 |
panelPref := buttonPanel preferedExtent.
|
110
|
343 |
labelPref := labelField preferedExtent.
|
|
344 |
enterPref := enterField preferedExtent.
|
|
345 |
wWanted := (labelPref x max:enterPref x).
|
|
346 |
wPanel := panelPref x.
|
59
|
347 |
wPanel > wWanted ifTrue:[
|
|
348 |
wWanted := wPanel
|
|
349 |
].
|
110
|
350 |
|
|
351 |
hWanted := labelPref y + enterPref y +
|
73
|
352 |
(ViewSpacing * 6) + panelPref y + ViewSpacing.
|
59
|
353 |
|
|
354 |
min := self class minExtent.
|
|
355 |
wWanted < min x ifTrue:[
|
|
356 |
wWanted := min x
|
|
357 |
].
|
|
358 |
hWanted < min y ifTrue:[
|
|
359 |
hWanted := min y
|
|
360 |
].
|
110
|
361 |
vs2 := ViewSpacing * 2.
|
|
362 |
^ (wWanted + vs2) @ (hWanted + vs2)
|
0
|
363 |
! !
|
|
364 |
|
77
|
365 |
!EnterBox methodsFor:'user actions'!
|
0
|
366 |
|
|
367 |
hideAndEvaluate:aBlock
|
|
368 |
"common processing for all ok-actions (see subclasses);
|
|
369 |
shut down box, fetch entered string and evaluate the action with it"
|
|
370 |
|
|
371 |
|string|
|
|
372 |
|
|
373 |
self hide.
|
|
374 |
aBlock notNil ifTrue:[
|
59
|
375 |
string := self contents.
|
|
376 |
string isNil ifTrue:[
|
|
377 |
string := ''
|
|
378 |
] ifFalse:[
|
|
379 |
string := string withoutSeparators
|
|
380 |
].
|
|
381 |
aBlock value:string
|
0
|
382 |
]
|
77
|
383 |
! !
|
|
384 |
|
|
385 |
!EnterBox methodsFor:'startup'!
|
|
386 |
|
|
387 |
request
|
|
388 |
"open the box and return the entered string or nil, if
|
|
389 |
abort was pressed"
|
|
390 |
|
|
391 |
self action:[:string | ^ string].
|
|
392 |
self open.
|
|
393 |
^ nil
|
0
|
394 |
!
|
|
395 |
|
77
|
396 |
request:title
|
|
397 |
"set the title, open the box and return the entered string or nil, if
|
|
398 |
abort was pressed"
|
0
|
399 |
|
77
|
400 |
self title:title.
|
|
401 |
^ self request
|
|
402 |
! !
|