author | Claus Gittinger <cg@exept.de> |
Fri, 19 Jul 1996 21:13:27 +0200 | |
changeset 800 | 0d8a2d42398d |
parent 746 | 4442a4d4121f |
child 842 | a27a1c6ddde0 |
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 |
||
800 | 20 |
!FileSelectionBox class methodsFor:'documentation'! |
7 | 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 |
|
800 | 251 |
!FileSelectionBox class methodsFor:'defaults'! |
12 | 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 |
initialize |
413 |
|corner| |
|
414 |
||
415 |
super initialize. |
|
351 | 416 |
selectingDirectory := false. |
197 | 417 |
|
418 |
label := resources string:'File dialog'. |
|
0 | 419 |
|
197 | 420 |
labelField extent:(0.7 @ labelField height). |
421 |
labelField label:(resources string:'select a file:'). |
|
422 |
labelField adjust:#left. |
|
423 |
||
424 |
patternField := EditField in:self. |
|
425 |
self is3D ifTrue:[ |
|
351 | 426 |
corner := (1.0 @ (labelField origin y+patternField heightIncludingBorder)). |
197 | 427 |
] ifFalse:[ |
351 | 428 |
corner := [(width - ViewSpacing - (patternField borderWidth * 2)) @ (labelField origin y+patternField height"IncludingBorder")]. |
197 | 429 |
]. |
430 |
patternField origin:(0.7 @ labelField origin y) corner:corner. |
|
431 |
patternField rightInset:ViewSpacing. |
|
432 |
patternField initialText:'*'. |
|
746
4442a4d4121f
dont want return in patternField to be accept of box
Claus Gittinger <cg@exept.de>
parents:
740
diff
changeset
|
433 |
patternField leaveAction:[:reason | self patternChanged]. |
4442a4d4121f
dont want return in patternField to be accept of box
Claus Gittinger <cg@exept.de>
parents:
740
diff
changeset
|
434 |
patternField crAction:[self patternChanged]. |
197 | 435 |
patternField hiddenOnRealize:true. "delay showing, until a pattern is defined" |
740
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
436 |
self makeTabable:patternField before:enterField. |
197 | 437 |
|
438 |
enterField addDependent:self. |
|
439 |
||
440 |
" |
|
441 |
FileSelectionBox open |
|
442 |
FileSelectionBox new show |
|
443 |
" |
|
740
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
444 |
|
746
4442a4d4121f
dont want return in patternField to be accept of box
Claus Gittinger <cg@exept.de>
parents:
740
diff
changeset
|
445 |
"Modified: 4.6.1996 / 20:30:46 / cg" |
38 | 446 |
! |
7 | 447 |
|
197 | 448 |
realize |
449 |
"if some default is present in the enterField, |
|
450 |
scroll to make this one visible" |
|
451 |
||
452 |
|contents| |
|
453 |
||
454 |
super realize. |
|
455 |
(contents := enterField contents) notNil ifTrue:[ |
|
456 |
contents notEmpty ifTrue:[ |
|
457 |
selectionList makeVisible:contents |
|
458 |
] |
|
459 |
] |
|
460 |
! ! |
|
461 |
||
462 |
!FileSelectionBox methodsFor:'private'! |
|
463 |
||
464 |
updateList |
|
465 |
selectionList updateList |
|
466 |
! ! |
|
38 | 467 |
|
197 | 468 |
!FileSelectionBox methodsFor:'queries'! |
469 |
||
470 |
preferredExtent |
|
471 |
"return my preferred extent - thats the minimum size |
|
472 |
to make everything visible" |
|
473 |
||
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
474 |
|wWanted hWanted mm| |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
475 |
|
800 | 476 |
"/ If I have an explicit preferredExtent .. |
477 |
||
713
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
682
diff
changeset
|
478 |
preferredExtent notNil ifTrue:[ |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
682
diff
changeset
|
479 |
^ preferredExtent |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
682
diff
changeset
|
480 |
]. |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
682
diff
changeset
|
481 |
|
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
482 |
mm := ViewSpacing. |
197 | 483 |
|
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
484 |
wWanted := mm + |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
485 |
labelField preferredExtent x + |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
486 |
(mm * 2) + |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
487 |
patternField preferredExtent x + |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
488 |
mm. |
197 | 489 |
(wWanted < width) ifTrue:[ |
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
490 |
wWanted := width |
197 | 491 |
]. |
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
492 |
hWanted := mm + labelField height + |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
493 |
mm + enterField height + |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
494 |
mm + selectionList height + |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
495 |
mm + buttonPanel preferredExtent y + |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
496 |
mm. |
38 | 497 |
|
197 | 498 |
(hWanted < height) ifTrue:[ |
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
499 |
hWanted := height |
197 | 500 |
]. |
501 |
^ (wWanted @ hWanted) |
|
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
502 |
|
800 | 503 |
"Modified: 19.7.1996 / 20:44:04 / cg" |
197 | 504 |
! ! |
505 |
||
506 |
!FileSelectionBox methodsFor:'user actions'! |
|
507 |
||
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
508 |
directoryChanged |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
509 |
selectingDirectory ifTrue:[ |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
510 |
selectionList changeDirectory. |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
511 |
enterField contents:(selectionList directory pathName). |
682 | 512 |
selectionList setSelection:nil. |
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
513 |
]. |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
514 |
|
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
515 |
"Created: 18.4.1996 / 18:38:21 / cg" |
682 | 516 |
"Modified: 25.5.1996 / 12:27:05 / cg" |
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
517 |
! |
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 |
directorySelected |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
520 |
selectingDirectory ifTrue:[ |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
521 |
enterField contents:(selectionList directory pathName |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
522 |
, '/' , selectionList selectionValue). |
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 |
|
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
525 |
"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
|
526 |
"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
|
527 |
! |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
528 |
|
197 | 529 |
doubleClick |
530 |
|entry| |
|
531 |
||
532 |
entry := selectionList selectionValue. |
|
533 |
entry notNil ifTrue:[ |
|
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
534 |
((selectionList directory typeOf:entry) == #directory) ifFalse:[ |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
535 |
selectingDirectory ifFalse:[ |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
536 |
enterField contents:entry. |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
537 |
self okPressed |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
538 |
] |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
539 |
] |
38 | 540 |
]. |
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
541 |
|
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
542 |
"Modified: 18.4.1996 / 18:33:14 / cg" |
197 | 543 |
! |
544 |
||
545 |
okPressed |
|
546 |
"called for both on ok-press and on return-key" |
|
547 |
||
548 |
|dir string fname| |
|
549 |
||
550 |
string := enterField contents. |
|
351 | 551 |
(string notNil and:[string notEmpty]) ifTrue:[ |
552 |
string := string withoutSeparators. |
|
553 |
string asFilename isAbsolute ifTrue:[ |
|
554 |
fname := string asFilename |
|
555 |
] ifFalse:[ |
|
556 |
dir := selectionList directory pathName asFilename. |
|
557 |
fname := dir construct:string |
|
558 |
]. |
|
559 |
fname isDirectory ifTrue:[ |
|
560 |
selectingDirectory ifFalse:[ |
|
561 |
selectionList directory:fname asString. |
|
562 |
self updateList. |
|
563 |
^ self |
|
564 |
] |
|
565 |
] |
|
566 |
] ifFalse:[ |
|
567 |
selectingDirectory ifTrue:[ |
|
568 |
enterField contents:(selectionList directory pathName). |
|
569 |
]. |
|
38 | 570 |
]. |
351 | 571 |
|
197 | 572 |
super okPressed |
351 | 573 |
|
197 | 574 |
! |
575 |
||
746
4442a4d4121f
dont want return in patternField to be accept of box
Claus Gittinger <cg@exept.de>
parents:
740
diff
changeset
|
576 |
patternChanged |
4442a4d4121f
dont want return in patternField to be accept of box
Claus Gittinger <cg@exept.de>
parents:
740
diff
changeset
|
577 |
selectionList pattern:patternField contents. |
4442a4d4121f
dont want return in patternField to be accept of box
Claus Gittinger <cg@exept.de>
parents:
740
diff
changeset
|
578 |
self updateList |
4442a4d4121f
dont want return in patternField to be accept of box
Claus Gittinger <cg@exept.de>
parents:
740
diff
changeset
|
579 |
|
4442a4d4121f
dont want return in patternField to be accept of box
Claus Gittinger <cg@exept.de>
parents:
740
diff
changeset
|
580 |
"Created: 4.6.1996 / 20:30:23 / cg" |
4442a4d4121f
dont want return in patternField to be accept of box
Claus Gittinger <cg@exept.de>
parents:
740
diff
changeset
|
581 |
! |
4442a4d4121f
dont want return in patternField to be accept of box
Claus Gittinger <cg@exept.de>
parents:
740
diff
changeset
|
582 |
|
197 | 583 |
selectionChanged |
584 |
|entry| |
|
585 |
||
586 |
entry := selectionList selectionValue. |
|
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
587 |
((selectionList directory typeOf:entry) == #directory) ifFalse:[ |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
588 |
selectingDirectory ifTrue:[ |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
589 |
enterField contents:(selectionList directory pathName). |
682 | 590 |
selectionList setSelection:nil. |
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
591 |
^ self |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
592 |
] |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
593 |
]. |
197 | 594 |
enterField contents:entry |
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
595 |
|
682 | 596 |
"Modified: 25.5.1996 / 12:27:08 / cg" |
0 | 597 |
! ! |
197 | 598 |
|
800 | 599 |
!FileSelectionBox class methodsFor:'documentation'! |
240 | 600 |
|
601 |
version |
|
800 | 602 |
^ '$Header: /cvs/stx/stx/libwidg/FileSelectionBox.st,v 1.39 1996-07-19 19:12:11 cg Exp $' |
240 | 603 |
! ! |