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
|
197
|
14 |
instanceVariableNames:'patternField'
|
|
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
|
|
40 |
argument when ok is clicked.
|
|
41 |
|
|
42 |
There is an optional PatternField, which shows itself when a pattern
|
|
43 |
is defined (i.e. if there is no pattern, it is hidden).
|
|
44 |
If there is a pattern, only files matching the pattern will be shown in
|
|
45 |
the list (and directories).
|
|
46 |
|
|
47 |
In addition, there is an optional matchBlock (actually this is defined
|
|
48 |
in the FileSelectionList). Only filenames for which this matchblock
|
|
49 |
returns true will be presented.
|
62
|
50 |
"
|
|
51 |
!
|
38
|
52 |
|
62
|
53 |
examples
|
|
54 |
"
|
38
|
55 |
Example1:
|
|
56 |
|
59
|
57 |
FileSelectionBox open
|
38
|
58 |
|
|
59 |
Example2:
|
|
60 |
|
59
|
61 |
FileSelectionBox new open
|
12
|
62 |
|
38
|
63 |
Example3:
|
|
64 |
|
59
|
65 |
|box|
|
|
66 |
box := FileSelectionBox new.
|
|
67 |
box title:'Which file ?'.
|
|
68 |
box open
|
38
|
69 |
|
|
70 |
Example4:
|
|
71 |
|
59
|
72 |
|box|
|
|
73 |
box := FileSelectionBox new.
|
|
74 |
box title:'Which file ?'.
|
|
75 |
box pattern:'*.doc'.
|
|
76 |
box open
|
38
|
77 |
|
|
78 |
Example5:
|
|
79 |
|
59
|
80 |
|box|
|
|
81 |
box := FileSelectionBox new.
|
|
82 |
box title:'Which file ?'.
|
|
83 |
box pattern:'*'.
|
|
84 |
box matchBlock:[:name | name first isLowercase].
|
|
85 |
box open
|
44
|
86 |
|
120
|
87 |
Example6:
|
44
|
88 |
|
59
|
89 |
|box|
|
|
90 |
box := FileSelectionBox new.
|
|
91 |
box title:'Which directory ?'.
|
|
92 |
box pattern:'l*'.
|
|
93 |
box matchBlock:[:name | OperatingSystem isDirectory:name].
|
|
94 |
box open
|
7
|
95 |
"
|
197
|
96 |
!
|
|
97 |
|
|
98 |
version
|
|
99 |
^ '$Header: /cvs/stx/stx/libwidg/Attic/FSelBox.st,v 1.23 1995-11-23 02:25:26 cg Exp $'
|
7
|
100 |
! !
|
0
|
101 |
|
12
|
102 |
!FileSelectionBox class methodsFor:'defaults'!
|
|
103 |
|
77
|
104 |
requestFilename
|
|
105 |
^ self requestFilename:'filename:'
|
|
106 |
|
|
107 |
"
|
|
108 |
FileSelectionBox requestFilename
|
|
109 |
"
|
|
110 |
!
|
|
111 |
|
|
112 |
requestFilename:title
|
|
113 |
|fileBox|
|
|
114 |
|
|
115 |
fileBox := self
|
|
116 |
title:title
|
|
117 |
okText:'ok'
|
|
118 |
abortText:'cancel'
|
|
119 |
action:[:fileName | ^ fileName].
|
|
120 |
|
|
121 |
fileBox showAtPointer.
|
|
122 |
^ nil
|
|
123 |
|
|
124 |
"
|
|
125 |
FileSelectionBox requestFilename:'which file ?'
|
|
126 |
"
|
|
127 |
! !
|
|
128 |
|
|
129 |
!FileSelectionBox class methodsFor:'requests'!
|
|
130 |
|
12
|
131 |
listViewType
|
|
132 |
"return the type of listView - using a FileSelectionList here"
|
|
133 |
|
|
134 |
^ FileSelectionList
|
|
135 |
! !
|
|
136 |
|
197
|
137 |
!FileSelectionBox methodsFor:'accessing'!
|
3
|
138 |
|
197
|
139 |
contents
|
|
140 |
"return the current entered value (i.e. the enterFields string).
|
|
141 |
redefined to return the full pathname."
|
|
142 |
|
|
143 |
|string sep|
|
3
|
144 |
|
197
|
145 |
string := super contents.
|
|
146 |
string isNil ifTrue:[
|
|
147 |
^ selectionList directory pathName
|
121
|
148 |
].
|
197
|
149 |
sep := Filename separator.
|
|
150 |
(string startsWith:sep) ifTrue:[
|
|
151 |
^ string
|
77
|
152 |
].
|
197
|
153 |
^ (selectionList directory pathName asFilename construct:string) asString
|
132
|
154 |
!
|
|
155 |
|
197
|
156 |
directory:directoryName
|
|
157 |
"change the directory shown in the list."
|
41
|
158 |
|
197
|
159 |
selectionList directory:directoryName
|
132
|
160 |
!
|
|
161 |
|
197
|
162 |
matchBlock:aBlock
|
|
163 |
"set the matchBlock (in the selectionList). Only files
|
|
164 |
for which the block returns true are shown.
|
|
165 |
The matching is actually done in the fileSelectionList."
|
77
|
166 |
|
197
|
167 |
selectionList matchBlock:aBlock
|
|
168 |
!
|
0
|
169 |
|
38
|
170 |
openOn:aPath
|
|
171 |
"open the box showing files in aPath.
|
|
172 |
This is only a shortcut message - no new functionality."
|
|
173 |
|
|
174 |
self directory:aPath.
|
|
175 |
self showAtPointer
|
|
176 |
!
|
|
177 |
|
3
|
178 |
pattern:aPattern
|
38
|
179 |
"set the pattern - this also enables the PatternField
|
|
180 |
(if the pattern is non-nil) or hides it (if nil)."
|
7
|
181 |
|
130
|
182 |
|hidePatternField focusSequence|
|
|
183 |
|
3
|
184 |
patternField initialText:aPattern.
|
12
|
185 |
selectionList pattern:aPattern.
|
|
186 |
aPattern isNil ifTrue:[
|
130
|
187 |
hidePatternField := true.
|
59
|
188 |
realized ifTrue:[
|
|
189 |
patternField hide.
|
77
|
190 |
].
|
130
|
191 |
focusSequence := (Array
|
|
192 |
with:enterField
|
|
193 |
with:selectionList
|
|
194 |
with:okButton
|
|
195 |
with:abortButton)
|
12
|
196 |
] ifFalse:[
|
130
|
197 |
hidePatternField := false.
|
59
|
198 |
realized ifTrue:[
|
|
199 |
patternField realize.
|
|
200 |
].
|
130
|
201 |
focusSequence := (Array
|
|
202 |
with:patternField
|
|
203 |
with:enterField
|
|
204 |
with:selectionList
|
|
205 |
with:okButton
|
|
206 |
with:abortButton)
|
|
207 |
].
|
|
208 |
|
|
209 |
patternField hiddenOnRealize:hidePatternField.
|
|
210 |
windowGroup notNil ifTrue:[
|
|
211 |
windowGroup focusSequence:focusSequence
|
0
|
212 |
].
|
197
|
213 |
! !
|
|
214 |
|
|
215 |
!FileSelectionBox methodsFor:'change & update'!
|
|
216 |
|
|
217 |
update:something with:argument from:changedObject
|
|
218 |
|commonName index s|
|
|
219 |
|
|
220 |
something == #directory ifTrue:[
|
|
221 |
"
|
|
222 |
sent by fileNameEnterField, if a filename
|
|
223 |
completion was not possible due to multiple
|
|
224 |
matches.
|
|
225 |
"
|
|
226 |
selectionList directory:argument.
|
|
227 |
s := enterField contents.
|
|
228 |
s notNil ifTrue:[
|
|
229 |
commonName := s asFilename baseName.
|
|
230 |
commonName size > 0 ifTrue:[
|
|
231 |
index := selectionList list findFirst:[:entry | entry startsWith:commonName].
|
|
232 |
index ~~ 0 ifTrue:[
|
|
233 |
selectionList makeLineVisible:index
|
|
234 |
]
|
|
235 |
]
|
|
236 |
]
|
|
237 |
]
|
|
238 |
! !
|
|
239 |
|
|
240 |
!FileSelectionBox methodsFor:'initialization'!
|
|
241 |
|
|
242 |
createEnterField
|
|
243 |
"if the (optional) class FilenameEditField is present, use
|
|
244 |
it, since it provides filename completion. Otherwise, we have
|
|
245 |
to live with the dump (default) field ...
|
|
246 |
"
|
|
247 |
FilenameEditField notNil ifTrue:[
|
|
248 |
^ FilenameEditField new.
|
|
249 |
].
|
|
250 |
^ super createEnterField
|
38
|
251 |
!
|
0
|
252 |
|
197
|
253 |
focusSequence
|
|
254 |
patternField shown ifTrue:[
|
|
255 |
^ Array
|
|
256 |
with:patternField
|
|
257 |
with:enterField
|
|
258 |
with:selectionList
|
|
259 |
with:abortButton
|
|
260 |
with:okButton
|
|
261 |
].
|
|
262 |
^ super focusSequence
|
|
263 |
!
|
|
264 |
|
|
265 |
initialize
|
|
266 |
|corner|
|
|
267 |
|
|
268 |
super initialize.
|
|
269 |
|
|
270 |
label := resources string:'File dialog'.
|
0
|
271 |
|
197
|
272 |
labelField extent:(0.7 @ labelField height).
|
|
273 |
labelField label:(resources string:'select a file:').
|
|
274 |
labelField adjust:#left.
|
|
275 |
|
|
276 |
patternField := EditField in:self.
|
|
277 |
self is3D ifTrue:[
|
|
278 |
corner := (1.0 @ (labelField origin y+patternField heightIncludingBorder)).
|
|
279 |
] ifFalse:[
|
|
280 |
corner := [(width - ViewSpacing - (patternField borderWidth * 2)) @ (labelField origin y+patternField height"IncludingBorder")].
|
|
281 |
].
|
|
282 |
patternField origin:(0.7 @ labelField origin y) corner:corner.
|
|
283 |
patternField rightInset:ViewSpacing.
|
|
284 |
patternField initialText:'*'.
|
|
285 |
patternField leaveAction:[:reason |
|
|
286 |
selectionList pattern:patternField contents.
|
|
287 |
self updateList
|
|
288 |
].
|
|
289 |
patternField hiddenOnRealize:true. "delay showing, until a pattern is defined"
|
|
290 |
|
|
291 |
enterField addDependent:self.
|
|
292 |
|
|
293 |
"
|
|
294 |
FileSelectionBox open
|
|
295 |
FileSelectionBox new show
|
|
296 |
"
|
38
|
297 |
!
|
7
|
298 |
|
197
|
299 |
realize
|
|
300 |
"if some default is present in the enterField,
|
|
301 |
scroll to make this one visible"
|
|
302 |
|
|
303 |
|contents|
|
|
304 |
|
|
305 |
super realize.
|
|
306 |
(contents := enterField contents) notNil ifTrue:[
|
|
307 |
contents notEmpty ifTrue:[
|
|
308 |
selectionList makeVisible:contents
|
|
309 |
]
|
|
310 |
]
|
|
311 |
! !
|
|
312 |
|
|
313 |
!FileSelectionBox methodsFor:'private'!
|
|
314 |
|
|
315 |
updateList
|
|
316 |
selectionList updateList
|
|
317 |
! !
|
38
|
318 |
|
197
|
319 |
!FileSelectionBox methodsFor:'queries'!
|
|
320 |
|
|
321 |
preferredExtent
|
|
322 |
"return my preferred extent - thats the minimum size
|
|
323 |
to make everything visible"
|
|
324 |
|
|
325 |
|wWanted hWanted|
|
|
326 |
|
|
327 |
wWanted := ViewSpacing +
|
|
328 |
labelField preferredExtent x +
|
|
329 |
(ViewSpacing * 2) +
|
|
330 |
patternField preferredExtent x +
|
|
331 |
ViewSpacing.
|
|
332 |
(wWanted < width) ifTrue:[
|
|
333 |
wWanted := width
|
|
334 |
].
|
|
335 |
hWanted := ViewSpacing + labelField height +
|
|
336 |
ViewSpacing + enterField height +
|
|
337 |
ViewSpacing + selectionList height +
|
|
338 |
ViewSpacing + buttonPanel preferredExtent y +
|
|
339 |
ViewSpacing.
|
38
|
340 |
|
197
|
341 |
(hWanted < height) ifTrue:[
|
|
342 |
hWanted := height
|
|
343 |
].
|
|
344 |
^ (wWanted @ hWanted)
|
|
345 |
! !
|
|
346 |
|
|
347 |
!FileSelectionBox methodsFor:'user actions'!
|
|
348 |
|
|
349 |
doubleClick
|
|
350 |
|entry|
|
|
351 |
|
|
352 |
entry := selectionList selectionValue.
|
|
353 |
entry notNil ifTrue:[
|
|
354 |
((selectionList directory typeOf:entry) == #directory) ifFalse:[
|
|
355 |
enterField contents:entry.
|
|
356 |
self okPressed
|
|
357 |
]
|
38
|
358 |
].
|
197
|
359 |
!
|
|
360 |
|
|
361 |
okPressed
|
|
362 |
"called for both on ok-press and on return-key"
|
|
363 |
|
|
364 |
|dir string fname|
|
|
365 |
|
|
366 |
string := enterField contents.
|
|
367 |
string notNil ifTrue:[
|
|
368 |
string := string withoutSeparators.
|
|
369 |
string asFilename isAbsolute ifTrue:[
|
|
370 |
fname := string asFilename
|
|
371 |
] ifFalse:[
|
|
372 |
dir := selectionList directory pathName asFilename.
|
|
373 |
fname := dir construct:string
|
|
374 |
].
|
|
375 |
fname isDirectory ifTrue:[
|
|
376 |
selectionList directory:fname asString.
|
|
377 |
self updateList.
|
|
378 |
^ self
|
|
379 |
]
|
38
|
380 |
].
|
197
|
381 |
super okPressed
|
|
382 |
!
|
|
383 |
|
|
384 |
selectionChanged
|
|
385 |
|entry|
|
|
386 |
|
|
387 |
entry := selectionList selectionValue.
|
|
388 |
enterField contents:entry
|
0
|
389 |
! !
|
197
|
390 |
|