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
|
12
|
14 |
instanceVariableNames:'patternField'
|
0
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
38
|
17 |
category:'Views-DialogBoxes'
|
0
|
18 |
!
|
|
19 |
|
|
20 |
FileSelectionBox comment:'
|
5
|
21 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
59
|
22 |
All Rights Reserved
|
0
|
23 |
|
62
|
24 |
$Header: /cvs/stx/stx/libwidg/FileSelectionBox.st,v 1.11 1994-11-17 14:34:08 claus Exp $
|
7
|
25 |
'!
|
|
26 |
|
|
27 |
!FileSelectionBox class methodsFor:'documentation'!
|
|
28 |
|
38
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
59
|
32 |
All Rights Reserved
|
38
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
62
|
45 |
$Header: /cvs/stx/stx/libwidg/FileSelectionBox.st,v 1.11 1994-11-17 14:34:08 claus Exp $
|
38
|
46 |
"
|
|
47 |
!
|
|
48 |
|
7
|
49 |
documentation
|
|
50 |
"
|
38
|
51 |
this class implements file selection boxes. Instances show a list of
|
|
52 |
files, and perform an action block with the selected pathname as
|
|
53 |
argument when ok is clicked.
|
|
54 |
|
|
55 |
There is an optional PatternField, which shows itself when a pattern
|
|
56 |
is defined (i.e. if there is no pattern, it is hidden).
|
|
57 |
If there is a pattern, only files matching the pattern will be shown in
|
|
58 |
the list (and directories).
|
|
59 |
|
|
60 |
In addition, there is an optional matchBlock (actually this is defined
|
|
61 |
in the FileSelectionList). Only filenames for which this matchblock
|
|
62 |
returns true will be presented.
|
62
|
63 |
"
|
|
64 |
!
|
38
|
65 |
|
62
|
66 |
examples
|
|
67 |
"
|
38
|
68 |
Example1:
|
|
69 |
|
59
|
70 |
FileSelectionBox open
|
38
|
71 |
|
|
72 |
Example2:
|
|
73 |
|
59
|
74 |
FileSelectionBox new open
|
12
|
75 |
|
38
|
76 |
Example3:
|
|
77 |
|
59
|
78 |
|box|
|
|
79 |
box := FileSelectionBox new.
|
|
80 |
box title:'Which file ?'.
|
|
81 |
box open
|
38
|
82 |
|
|
83 |
Example4:
|
|
84 |
|
59
|
85 |
|box|
|
|
86 |
box := FileSelectionBox new.
|
|
87 |
box title:'Which file ?'.
|
|
88 |
box pattern:'*.doc'.
|
|
89 |
box open
|
38
|
90 |
|
|
91 |
Example5:
|
|
92 |
|
59
|
93 |
|box|
|
|
94 |
box := FileSelectionBox new.
|
|
95 |
box title:'Which file ?'.
|
|
96 |
box pattern:'*'.
|
|
97 |
box matchBlock:[:name | name first isLowercase].
|
|
98 |
box open
|
44
|
99 |
|
|
100 |
Example5:
|
|
101 |
|
59
|
102 |
|box|
|
|
103 |
box := FileSelectionBox new.
|
|
104 |
box title:'Which directory ?'.
|
|
105 |
box pattern:'l*'.
|
|
106 |
box matchBlock:[:name | OperatingSystem isDirectory:name].
|
|
107 |
box open
|
7
|
108 |
"
|
|
109 |
! !
|
0
|
110 |
|
12
|
111 |
!FileSelectionBox class methodsFor:'defaults'!
|
|
112 |
|
|
113 |
listViewType
|
|
114 |
"return the type of listView - using a FileSelectionList here"
|
|
115 |
|
|
116 |
^ FileSelectionList
|
|
117 |
! !
|
|
118 |
|
0
|
119 |
!FileSelectionBox methodsFor:'initialization'!
|
|
120 |
|
|
121 |
initialize
|
|
122 |
super initialize.
|
|
123 |
|
3
|
124 |
labelField extent:(0.7 @ labelField height).
|
|
125 |
labelField label:(resources string:'select a file:').
|
|
126 |
labelField adjust:#left.
|
|
127 |
|
38
|
128 |
patternField := EditField in:self.
|
|
129 |
patternField
|
59
|
130 |
origin:(0.7 @ labelField origin y)
|
|
131 |
corner:(1.0 @ (labelField origin y+patternField heightIncludingBorder)).
|
|
132 |
patternField rightInset:(ViewSpacing // 2).
|
3
|
133 |
patternField initialText:'*'.
|
21
|
134 |
patternField leaveAction:[:reason |
|
59
|
135 |
selectionList pattern:patternField contents.
|
|
136 |
self updateList
|
21
|
137 |
].
|
38
|
138 |
patternField hidden:true. "delay showing, until a pattern is defined"
|
3
|
139 |
|
12
|
140 |
selectionList action:[:line |
|
59
|
141 |
|entry|
|
0
|
142 |
|
59
|
143 |
entry := selectionList selectionValue.
|
|
144 |
enterField contents:entry
|
12
|
145 |
].
|
38
|
146 |
|
12
|
147 |
selectionList doubleClickAction:[:line |
|
59
|
148 |
|entry|
|
12
|
149 |
|
59
|
150 |
entry := selectionList selectionValue.
|
|
151 |
entry notNil ifTrue:[
|
|
152 |
((selectionList directory typeOf:entry) == #directory) ifFalse:[
|
|
153 |
enterField contents:entry.
|
|
154 |
self okPressed
|
|
155 |
]
|
|
156 |
]
|
12
|
157 |
].
|
41
|
158 |
enterField addDependent:self.
|
0
|
159 |
|
|
160 |
"FileSelectionBox new show"
|
38
|
161 |
!
|
|
162 |
|
|
163 |
createEnterField
|
|
164 |
"
|
|
165 |
if the (optional) class FilenameEditField is present, use
|
|
166 |
it, since it provides filename completion. Otherwise, we have
|
|
167 |
to live with the dump field ...
|
|
168 |
"
|
|
169 |
FilenameEditField notNil ifTrue:[
|
59
|
170 |
enterField := FilenameEditField in:self.
|
38
|
171 |
] ifFalse:[
|
59
|
172 |
super createEnterField
|
38
|
173 |
]
|
|
174 |
! !
|
|
175 |
|
41
|
176 |
!FileSelectionBox methodsFor:'dependencies'!
|
|
177 |
|
|
178 |
update:something with:argument
|
|
179 |
|commonName index|
|
|
180 |
|
|
181 |
something == #directory ifTrue:[
|
59
|
182 |
"
|
|
183 |
sent by fileNameEnterField, if a filename
|
|
184 |
completion was not possible due to multiple
|
|
185 |
matches.
|
|
186 |
"
|
|
187 |
selectionList directory:argument.
|
|
188 |
commonName := enterField contents asFilename baseName.
|
|
189 |
commonName size > 0 ifTrue:[
|
|
190 |
index := selectionList list findFirst:[:entry | entry startsWith:commonName].
|
|
191 |
index ~~ 0 ifTrue:[
|
|
192 |
selectionList makeLineVisible:index
|
|
193 |
]
|
|
194 |
]
|
41
|
195 |
]
|
|
196 |
! !
|
|
197 |
|
38
|
198 |
!FileSelectionBox methodsFor:'user actions'!
|
|
199 |
|
|
200 |
okPressed
|
|
201 |
"called for both on ok-press and on return-key"
|
|
202 |
|
|
203 |
|dir string fname|
|
|
204 |
|
|
205 |
string := enterField contents.
|
|
206 |
string notNil ifTrue:[
|
59
|
207 |
string := string withoutSeparators.
|
|
208 |
string asFilename isAbsolute ifTrue:[
|
|
209 |
fname := string asFilename
|
|
210 |
] ifFalse:[
|
|
211 |
dir := selectionList directory pathName asFilename.
|
|
212 |
fname := dir construct:string
|
|
213 |
].
|
|
214 |
fname isDirectory ifTrue:[
|
|
215 |
selectionList directory:fname asString.
|
|
216 |
self updateList.
|
|
217 |
^ self
|
|
218 |
]
|
38
|
219 |
].
|
|
220 |
super okPressed
|
0
|
221 |
! !
|
|
222 |
|
21
|
223 |
!FileSelectionBox methodsFor:'private'!
|
|
224 |
|
|
225 |
updateList
|
|
226 |
selectionList updateList
|
|
227 |
! !
|
|
228 |
|
0
|
229 |
!FileSelectionBox methodsFor:'accessing'!
|
|
230 |
|
38
|
231 |
openOn:aPath
|
|
232 |
"open the box showing files in aPath.
|
|
233 |
This is only a shortcut message - no new functionality."
|
|
234 |
|
|
235 |
self directory:aPath.
|
|
236 |
self showAtPointer
|
|
237 |
!
|
|
238 |
|
0
|
239 |
directory:nameOrDirectory
|
38
|
240 |
"change the directory shown in the list."
|
0
|
241 |
|
12
|
242 |
selectionList directory:nameOrDirectory
|
3
|
243 |
!
|
|
244 |
|
|
245 |
pattern:aPattern
|
38
|
246 |
"set the pattern - this also enables the PatternField
|
|
247 |
(if the pattern is non-nil) or hides it (if nil)."
|
7
|
248 |
|
3
|
249 |
patternField initialText:aPattern.
|
12
|
250 |
selectionList pattern:aPattern.
|
|
251 |
aPattern isNil ifTrue:[
|
59
|
252 |
patternField hidden:true.
|
|
253 |
realized ifTrue:[
|
|
254 |
patternField hide.
|
|
255 |
]
|
12
|
256 |
] ifFalse:[
|
59
|
257 |
patternField hidden:false.
|
|
258 |
realized ifTrue:[
|
|
259 |
patternField realize.
|
|
260 |
].
|
0
|
261 |
].
|
38
|
262 |
!
|
0
|
263 |
|
38
|
264 |
matchBlock:aBlock
|
|
265 |
"set the matchBlock (in the selectionList). Only files
|
|
266 |
for which the block returns true are shown.
|
44
|
267 |
The matching is actually done in the fileSelectionList,
|
|
268 |
but we trick a bit to pass the full pathname instead of the
|
|
269 |
selection-name to the block."
|
0
|
270 |
|
44
|
271 |
selectionList matchBlock:[:name |
|
59
|
272 |
|dir fullPath|
|
44
|
273 |
|
59
|
274 |
dir := selectionList directory pathName asFilename.
|
|
275 |
fullPath := dir construct:name.
|
|
276 |
aBlock value:fullPath asString
|
44
|
277 |
]
|
38
|
278 |
!
|
7
|
279 |
|
38
|
280 |
contents
|
|
281 |
"return the current entered value (i.e. the enterFields string).
|
|
282 |
redefined to return the full pathname."
|
|
283 |
|
|
284 |
|string sep|
|
|
285 |
|
|
286 |
string := super contents.
|
|
287 |
string isNil ifTrue:[
|
59
|
288 |
^ selectionList directory pathName
|
38
|
289 |
].
|
|
290 |
sep := Filename separator.
|
|
291 |
(string startsWith:sep) ifTrue:[
|
59
|
292 |
^ string
|
38
|
293 |
].
|
|
294 |
^ (selectionList directory pathName asFilename construct:string) asString
|
0
|
295 |
! !
|