author | Claus Gittinger <cg@exept.de> |
Fri, 01 Mar 1996 14:02:46 +0100 | |
changeset 441 | e170bca66a78 |
parent 438 | 8df6f72d1569 |
child 548 | c418699a90c0 |
permissions | -rw-r--r-- |
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 |
||
13 |
ListSelectionBox subclass:#FileSelectionBox |
|
351 | 14 |
instanceVariableNames:'patternField selectingDirectory' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Views-DialogBoxes' |
|
0 | 18 |
! |
19 |
||
7 | 20 |
!FileSelectionBox class methodsFor:'documentation'! |
21 |
||
38 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1990 by Claus Gittinger |
|
59 | 25 |
All Rights Reserved |
38 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
7 | 36 |
documentation |
37 |
" |
|
38 | 38 |
this class implements file selection boxes. Instances show a list of |
39 |
files, and perform an action block with the selected pathname as |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
40 |
argument when ok is clicked. It is also possible, to open the box |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
41 |
without action and ask it afterward if it has been left with ok |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
42 |
(i.e. the ST-80 way, asking 'aBox accepted ifTrue:[...]') |
38 | 43 |
|
44 |
There is an optional PatternField, which shows itself when a pattern |
|
45 |
is defined (i.e. if there is no pattern, it is hidden). |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
46 |
If there is a pattern, only files matching the pattern are shown in |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
47 |
the list. Directories are not affected by the patternField. |
38 | 48 |
|
49 |
In addition, there is an optional matchBlock (actually this is defined |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
50 |
in the FileSelectionList). Only names for which this matchblock |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
51 |
returns true will be presented. The matchBlock affects both regular files |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
52 |
and names of directories. The argument passed to the matchBlock is the full |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
53 |
pathname. |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
54 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
55 |
All of the actual work is done in the fileList; see the documentation |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
56 |
of FileSelectionList for more options |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
57 |
(you can access a boxes fileList via 'aBox>>listView' and get access to all |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
58 |
of those fancy settings) |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
59 |
For example, by accessing the list, it is possible to hide all directories |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
60 |
('aBox listView ignoreDirectories:true'), to hide the parentDirectory alone |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
61 |
('aBox listView ignoreParentDirectory') and to turn off the marking |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
62 |
of subdirectories ('aBox listView markSubdirectories:false'). |
62 | 63 |
" |
64 |
! |
|
38 | 65 |
|
62 | 66 |
examples |
67 |
" |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
68 |
simple standard queries |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
69 |
|
238 | 70 |
very simple: |
351 | 71 |
|name| |
238 | 72 |
|
351 | 73 |
name := FileSelectionBox requestFilename. |
74 |
Transcript showCr:name |
|
38 | 75 |
|
238 | 76 |
|
77 |
simple: |
|
351 | 78 |
|name| |
238 | 79 |
|
351 | 80 |
name := FileSelectionBox requestFilename:'which file ?'. |
81 |
Transcript showCr:name |
|
38 | 82 |
|
238 | 83 |
|
84 |
with initial selection: |
|
351 | 85 |
|name| |
238 | 86 |
|
351 | 87 |
name := FileSelectionBox requestFilename:'which file ?' default:'Make.proto'. |
88 |
Transcript showCr:name |
|
38 | 89 |
|
238 | 90 |
|
12 | 91 |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
92 |
more detailed setup |
238 | 93 |
|
94 |
setting title: |
|
38 | 95 |
|
351 | 96 |
|box| |
97 |
box := FileSelectionBox new. |
|
98 |
box title:'Which file ?'. |
|
99 |
box open. |
|
100 |
box accepted ifTrue:[ |
|
101 |
Transcript showCr:'you selected: ' , box |
|
102 |
] |
|
38 | 103 |
|
238 | 104 |
setting a matchpattern: |
38 | 105 |
|
351 | 106 |
|box| |
107 |
box := FileSelectionBox new. |
|
108 |
box title:'Which file ?'. |
|
109 |
box pattern:'*.rc'. |
|
110 |
box open |
|
111 |
||
112 |
setting multiple patterns: |
|
113 |
||
114 |
|box| |
|
115 |
box := FileSelectionBox new. |
|
116 |
box title:'Which file ?'. |
|
117 |
box pattern:'*.rc;*.st'. |
|
118 |
box open |
|
38 | 119 |
|
238 | 120 |
setting a matchblock: |
38 | 121 |
|
351 | 122 |
|box| |
123 |
box := FileSelectionBox new. |
|
124 |
box title:'Which file ?'. |
|
125 |
box directory:'/etc'. |
|
126 |
box pattern:'*'. |
|
127 |
box matchBlock:[:name | name asFilename baseName first between:$a and:$z]. |
|
128 |
box open |
|
44 | 129 |
|
238 | 130 |
both pattern and matchBlock: |
44 | 131 |
|
351 | 132 |
|box| |
133 |
box := FileSelectionBox new. |
|
134 |
box title:'Which directory ?'. |
|
135 |
box selectingDirectory:true. |
|
136 |
box pattern:'l*'. |
|
137 |
box matchBlock:[:name | OperatingSystem isDirectory:name]. |
|
138 |
box action:[:fn | Transcript showCr:fn]. |
|
139 |
box open |
|
238 | 140 |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
141 |
dont show the parent directory: |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
142 |
|
351 | 143 |
|box| |
144 |
box := FileSelectionBox new. |
|
145 |
box title:'Which directory ?'. |
|
146 |
box listView ignoreParentDirectory:true. |
|
147 |
box open |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
148 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
149 |
dont show any directory: |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
150 |
|
351 | 151 |
|box| |
152 |
box := FileSelectionBox new. |
|
153 |
box title:'Which file ?'. |
|
154 |
box listView ignoreDirectories:true. |
|
155 |
box open |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
156 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
157 |
dont show any directory or hidden file: |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
158 |
(notice the basename extraction - we are not interrested in the full pathName) |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
159 |
|
351 | 160 |
|box| |
161 |
box := FileSelectionBox new. |
|
162 |
box title:'Which file ?'. |
|
163 |
box listView ignoreDirectories:true. |
|
164 |
box matchBlock:[:name | (name asFilename baseName startsWith:'.') not]. |
|
165 |
box open |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
166 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
167 |
dont allow direct filename entry: |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
168 |
(i.e. avoid the user choosing files from other directories) |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
169 |
|
351 | 170 |
|box| |
171 |
box := FileSelectionBox new. |
|
172 |
box title:'Which one ?'. |
|
173 |
box enterField beInvisible. |
|
174 |
box open. |
|
175 |
box accepted ifTrue:[ |
|
176 |
Transcript showCr:'path is ' , box pathName |
|
177 |
]. |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
178 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
179 |
combined with above directory ignoring, |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
180 |
this limits selection of files from a single directory: |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
181 |
|
351 | 182 |
|box| |
183 |
box := FileSelectionBox new. |
|
184 |
box title:'Which file ?'. |
|
185 |
box enterField beInvisible. |
|
186 |
box listView ignoreDirectories:true. |
|
187 |
box open. |
|
188 |
box accepted ifTrue:[ |
|
189 |
Transcript showCr:'path is ' , box pathName |
|
190 |
]. |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
191 |
|
238 | 192 |
finally, an action: |
193 |
||
351 | 194 |
|box| |
195 |
box := FileSelectionBox new. |
|
196 |
box title:'Which directory ?'. |
|
197 |
box pattern:'l*'. |
|
198 |
box matchBlock:[:name | OperatingSystem isDirectory:name]. |
|
199 |
box action:[:name | Transcript showCr:name]. |
|
200 |
box open |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
201 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
202 |
concrete examples: |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
203 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
204 |
only show files beginning with lowercase characters |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
205 |
and ending in '.c': |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
206 |
|
351 | 207 |
|box| |
208 |
box := FileSelectionBox new. |
|
209 |
box title:'Which directory ?'. |
|
210 |
box matchBlock:[:name | |
|
211 |
box pathName asFilename isDirectory |
|
212 |
or:[name first isLowercase |
|
213 |
and:[name endsWith:'.c']] |
|
214 |
]. |
|
215 |
box open. |
|
216 |
box accepted ifTrue:[ |
|
217 |
Transcript showCr:'full path: ' , box pathName. |
|
218 |
Transcript showCr:'files name: ' , box fileName. |
|
219 |
Transcript showCr:'directory : ' , box directory. |
|
220 |
] |
|
7 | 221 |
" |
222 |
! ! |
|
0 | 223 |
|
12 | 224 |
!FileSelectionBox class methodsFor:'defaults'! |
225 |
||
77 | 226 |
requestFilename |
227 |
^ self requestFilename:'filename:' |
|
228 |
||
229 |
" |
|
230 |
FileSelectionBox requestFilename |
|
231 |
" |
|
232 |
! |
|
233 |
||
234 |
requestFilename:title |
|
235 |
|fileBox| |
|
236 |
||
237 |
fileBox := self |
|
238 |
title:title |
|
239 |
okText:'ok' |
|
240 |
abortText:'cancel' |
|
241 |
action:[:fileName | ^ fileName]. |
|
242 |
||
243 |
fileBox showAtPointer. |
|
244 |
^ nil |
|
245 |
||
246 |
" |
|
247 |
FileSelectionBox requestFilename:'which file ?' |
|
248 |
" |
|
235 | 249 |
! |
250 |
||
251 |
requestFilename:title default:aFileName |
|
252 |
|fileBox| |
|
253 |
||
254 |
fileBox := self |
|
255 |
title:title |
|
256 |
okText:'ok' |
|
257 |
abortText:'cancel' |
|
258 |
action:[:fileName | ^ fileName]. |
|
259 |
||
260 |
fileBox initialText:aFileName. |
|
261 |
fileBox showAtPointer. |
|
262 |
^ nil |
|
263 |
||
264 |
" |
|
265 |
FileSelectionBox requestFilename:'which file ?' default:'Makefile' |
|
266 |
" |
|
267 |
! |
|
268 |
||
269 |
requestFilename:title fromDirectory: aDirectory |
|
270 |
||
271 |
|fileBox| |
|
272 |
||
273 |
fileBox := self |
|
274 |
title:title |
|
275 |
okText:'ok' |
|
276 |
abortText:'cancel' |
|
277 |
action:[:fileName | ^ fileName]. |
|
278 |
||
279 |
fileBox directory: aDirectory. |
|
280 |
fileBox showAtPointer. |
|
281 |
^ nil |
|
282 |
||
283 |
" |
|
284 |
FileSelectionBox requestFilename:'which file ?' fromDirectory:'/etc' |
|
285 |
" |
|
286 |
||
287 |
"Modified: 12.10.1995 / 11:47:27 / markus" |
|
77 | 288 |
! ! |
289 |
||
290 |
!FileSelectionBox class methodsFor:'requests'! |
|
291 |
||
12 | 292 |
listViewType |
293 |
"return the type of listView - using a FileSelectionList here" |
|
294 |
||
295 |
^ FileSelectionList |
|
296 |
! ! |
|
297 |
||
197 | 298 |
!FileSelectionBox methodsFor:'accessing'! |
3 | 299 |
|
197 | 300 |
contents |
301 |
"return the current entered value (i.e. the enterFields string). |
|
302 |
redefined to return the full pathname." |
|
303 |
||
304 |
|string sep| |
|
3 | 305 |
|
197 | 306 |
string := super contents. |
307 |
string isNil ifTrue:[ |
|
308 |
^ selectionList directory pathName |
|
121 | 309 |
]. |
197 | 310 |
sep := Filename separator. |
311 |
(string startsWith:sep) ifTrue:[ |
|
312 |
^ string |
|
77 | 313 |
]. |
197 | 314 |
^ (selectionList directory pathName asFilename construct:string) asString |
132 | 315 |
! |
316 |
||
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
317 |
directory |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
318 |
"return the directory which is currently shown" |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
319 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
320 |
^ selectionList directory |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
321 |
! |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
322 |
|
197 | 323 |
directory:directoryName |
324 |
"change the directory shown in the list." |
|
41 | 325 |
|
197 | 326 |
selectionList directory:directoryName |
132 | 327 |
! |
328 |
||
351 | 329 |
fileName |
330 |
"if some filename has been entered, return it (without the directory path) |
|
331 |
otherwise, return nil" |
|
332 |
||
333 |
|string| |
|
334 |
||
335 |
string := super contents. |
|
336 |
string isNil ifTrue:[^ nil]. |
|
337 |
^ self pathName |
|
338 |
! |
|
339 |
||
197 | 340 |
matchBlock:aBlock |
341 |
"set the matchBlock (in the selectionList). Only files |
|
342 |
for which the block returns true are shown. |
|
343 |
The matching is actually done in the fileSelectionList." |
|
77 | 344 |
|
197 | 345 |
selectionList matchBlock:aBlock |
346 |
! |
|
0 | 347 |
|
38 | 348 |
openOn:aPath |
349 |
"open the box showing files in aPath. |
|
350 |
This is only a shortcut message - no new functionality." |
|
351 |
||
352 |
self directory:aPath. |
|
353 |
self showAtPointer |
|
354 |
! |
|
355 |
||
351 | 356 |
pathName |
357 |
"same as contents - return the full pathname of the selected file, |
|
358 |
or the pathname of the directory if nothing has been entered" |
|
359 |
||
360 |
^ self contents |
|
361 |
! |
|
362 |
||
3 | 363 |
pattern:aPattern |
38 | 364 |
"set the pattern - this also enables the PatternField |
365 |
(if the pattern is non-nil) or hides it (if nil)." |
|
7 | 366 |
|
130 | 367 |
|hidePatternField focusSequence| |
368 |
||
3 | 369 |
patternField initialText:aPattern. |
12 | 370 |
selectionList pattern:aPattern. |
371 |
aPattern isNil ifTrue:[ |
|
130 | 372 |
hidePatternField := true. |
59 | 373 |
realized ifTrue:[ |
374 |
patternField hide. |
|
77 | 375 |
]. |
130 | 376 |
focusSequence := (Array |
377 |
with:enterField |
|
378 |
with:selectionList |
|
379 |
with:okButton |
|
380 |
with:abortButton) |
|
12 | 381 |
] ifFalse:[ |
130 | 382 |
hidePatternField := false. |
59 | 383 |
realized ifTrue:[ |
384 |
patternField realize. |
|
385 |
]. |
|
130 | 386 |
focusSequence := (Array |
387 |
with:patternField |
|
388 |
with:enterField |
|
389 |
with:selectionList |
|
390 |
with:okButton |
|
391 |
with:abortButton) |
|
392 |
]. |
|
393 |
||
394 |
patternField hiddenOnRealize:hidePatternField. |
|
395 |
windowGroup notNil ifTrue:[ |
|
396 |
windowGroup focusSequence:focusSequence |
|
0 | 397 |
]. |
351 | 398 |
! |
399 |
||
400 |
selectingDirectory:aBoolean |
|
401 |
selectingDirectory := aBoolean |
|
197 | 402 |
! ! |
403 |
||
404 |
!FileSelectionBox methodsFor:'change & update'! |
|
405 |
||
406 |
update:something with:argument from:changedObject |
|
407 |
|commonName index s| |
|
408 |
||
409 |
something == #directory ifTrue:[ |
|
410 |
" |
|
411 |
sent by fileNameEnterField, if a filename |
|
412 |
completion was not possible due to multiple |
|
413 |
matches. |
|
414 |
" |
|
415 |
selectionList directory:argument. |
|
416 |
s := enterField contents. |
|
417 |
s notNil ifTrue:[ |
|
418 |
commonName := s asFilename baseName. |
|
419 |
commonName size > 0 ifTrue:[ |
|
420 |
index := selectionList list findFirst:[:entry | entry startsWith:commonName]. |
|
421 |
index ~~ 0 ifTrue:[ |
|
422 |
selectionList makeLineVisible:index |
|
423 |
] |
|
424 |
] |
|
425 |
] |
|
426 |
] |
|
427 |
! ! |
|
428 |
||
429 |
!FileSelectionBox methodsFor:'initialization'! |
|
430 |
||
431 |
createEnterField |
|
432 |
"if the (optional) class FilenameEditField is present, use |
|
433 |
it, since it provides filename completion. Otherwise, we have |
|
434 |
to live with the dump (default) field ... |
|
435 |
" |
|
436 |
FilenameEditField notNil ifTrue:[ |
|
437 |
^ FilenameEditField new. |
|
438 |
]. |
|
439 |
^ super createEnterField |
|
38 | 440 |
! |
0 | 441 |
|
197 | 442 |
focusSequence |
443 |
patternField shown ifTrue:[ |
|
444 |
^ Array |
|
445 |
with:patternField |
|
446 |
with:enterField |
|
447 |
with:selectionList |
|
448 |
with:abortButton |
|
449 |
with:okButton |
|
450 |
]. |
|
451 |
^ super focusSequence |
|
452 |
! |
|
453 |
||
454 |
initialize |
|
455 |
|corner| |
|
456 |
||
457 |
super initialize. |
|
351 | 458 |
selectingDirectory := false. |
197 | 459 |
|
460 |
label := resources string:'File dialog'. |
|
0 | 461 |
|
197 | 462 |
labelField extent:(0.7 @ labelField height). |
463 |
labelField label:(resources string:'select a file:'). |
|
464 |
labelField adjust:#left. |
|
465 |
||
466 |
patternField := EditField in:self. |
|
467 |
self is3D ifTrue:[ |
|
351 | 468 |
corner := (1.0 @ (labelField origin y+patternField heightIncludingBorder)). |
197 | 469 |
] ifFalse:[ |
351 | 470 |
corner := [(width - ViewSpacing - (patternField borderWidth * 2)) @ (labelField origin y+patternField height"IncludingBorder")]. |
197 | 471 |
]. |
472 |
patternField origin:(0.7 @ labelField origin y) corner:corner. |
|
473 |
patternField rightInset:ViewSpacing. |
|
474 |
patternField initialText:'*'. |
|
475 |
patternField leaveAction:[:reason | |
|
351 | 476 |
selectionList pattern:patternField contents. |
477 |
self updateList |
|
197 | 478 |
]. |
479 |
patternField hiddenOnRealize:true. "delay showing, until a pattern is defined" |
|
480 |
||
481 |
enterField addDependent:self. |
|
482 |
||
483 |
" |
|
484 |
FileSelectionBox open |
|
485 |
FileSelectionBox new show |
|
486 |
" |
|
38 | 487 |
! |
7 | 488 |
|
197 | 489 |
realize |
490 |
"if some default is present in the enterField, |
|
491 |
scroll to make this one visible" |
|
492 |
||
493 |
|contents| |
|
494 |
||
495 |
super realize. |
|
496 |
(contents := enterField contents) notNil ifTrue:[ |
|
497 |
contents notEmpty ifTrue:[ |
|
498 |
selectionList makeVisible:contents |
|
499 |
] |
|
500 |
] |
|
501 |
! ! |
|
502 |
||
503 |
!FileSelectionBox methodsFor:'private'! |
|
504 |
||
505 |
updateList |
|
506 |
selectionList updateList |
|
507 |
! ! |
|
38 | 508 |
|
197 | 509 |
!FileSelectionBox methodsFor:'queries'! |
510 |
||
511 |
preferredExtent |
|
512 |
"return my preferred extent - thats the minimum size |
|
513 |
to make everything visible" |
|
514 |
||
515 |
|wWanted hWanted| |
|
516 |
||
517 |
wWanted := ViewSpacing + |
|
518 |
labelField preferredExtent x + |
|
519 |
(ViewSpacing * 2) + |
|
520 |
patternField preferredExtent x + |
|
521 |
ViewSpacing. |
|
522 |
(wWanted < width) ifTrue:[ |
|
523 |
wWanted := width |
|
524 |
]. |
|
525 |
hWanted := ViewSpacing + labelField height + |
|
526 |
ViewSpacing + enterField height + |
|
527 |
ViewSpacing + selectionList height + |
|
528 |
ViewSpacing + buttonPanel preferredExtent y + |
|
529 |
ViewSpacing. |
|
38 | 530 |
|
197 | 531 |
(hWanted < height) ifTrue:[ |
532 |
hWanted := height |
|
533 |
]. |
|
534 |
^ (wWanted @ hWanted) |
|
535 |
! ! |
|
536 |
||
537 |
!FileSelectionBox methodsFor:'user actions'! |
|
538 |
||
539 |
doubleClick |
|
540 |
|entry| |
|
541 |
||
542 |
entry := selectionList selectionValue. |
|
543 |
entry notNil ifTrue:[ |
|
544 |
((selectionList directory typeOf:entry) == #directory) ifFalse:[ |
|
545 |
enterField contents:entry. |
|
546 |
self okPressed |
|
547 |
] |
|
38 | 548 |
]. |
197 | 549 |
! |
550 |
||
551 |
okPressed |
|
552 |
"called for both on ok-press and on return-key" |
|
553 |
||
554 |
|dir string fname| |
|
555 |
||
556 |
string := enterField contents. |
|
351 | 557 |
(string notNil and:[string notEmpty]) ifTrue:[ |
558 |
string := string withoutSeparators. |
|
559 |
string asFilename isAbsolute ifTrue:[ |
|
560 |
fname := string asFilename |
|
561 |
] ifFalse:[ |
|
562 |
dir := selectionList directory pathName asFilename. |
|
563 |
fname := dir construct:string |
|
564 |
]. |
|
565 |
fname isDirectory ifTrue:[ |
|
566 |
selectingDirectory ifFalse:[ |
|
567 |
selectionList directory:fname asString. |
|
568 |
self updateList. |
|
569 |
^ self |
|
570 |
] |
|
571 |
] |
|
572 |
] ifFalse:[ |
|
573 |
selectingDirectory ifTrue:[ |
|
574 |
enterField contents:(selectionList directory pathName). |
|
575 |
]. |
|
38 | 576 |
]. |
351 | 577 |
|
197 | 578 |
super okPressed |
351 | 579 |
|
197 | 580 |
! |
581 |
||
582 |
selectionChanged |
|
583 |
|entry| |
|
584 |
||
585 |
entry := selectionList selectionValue. |
|
586 |
enterField contents:entry |
|
0 | 587 |
! ! |
197 | 588 |
|
240 | 589 |
!FileSelectionBox class methodsFor:'documentation'! |
590 |
||
591 |
version |
|
438 | 592 |
^ '$Header: /cvs/stx/stx/libwidg/Attic/FSelBox.st,v 1.29 1996-02-29 22:04:54 cg Exp $' |
240 | 593 |
! ! |