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