486
|
1 |
"
|
489
|
2 |
COPYRIGHT (c) 1997 by eXept Software AG
|
486
|
3 |
All Rights Reserved
|
|
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 |
|
|
14 |
|
|
15 |
TreeItem subclass:#FileSelectionItem
|
|
16 |
instanceVariableNames:'isDirectory imageType invalidate'
|
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Interface-Support'
|
|
20 |
!
|
|
21 |
|
|
22 |
FileSelectionItem subclass:#Directory
|
|
23 |
instanceVariableNames:''
|
|
24 |
classVariableNames:''
|
|
25 |
poolDictionaries:''
|
|
26 |
privateIn:FileSelectionItem
|
|
27 |
!
|
|
28 |
|
|
29 |
FileSelectionItem subclass:#File
|
|
30 |
instanceVariableNames:''
|
|
31 |
classVariableNames:''
|
|
32 |
poolDictionaries:''
|
|
33 |
privateIn:FileSelectionItem
|
|
34 |
!
|
|
35 |
|
|
36 |
!FileSelectionItem class methodsFor:'documentation'!
|
|
37 |
|
|
38 |
copyright
|
|
39 |
"
|
489
|
40 |
COPYRIGHT (c) 1997 by eXept Software AG
|
486
|
41 |
All Rights Reserved
|
|
42 |
|
|
43 |
This software is furnished under a license and may be used
|
|
44 |
only in accordance with the terms of that license and with the
|
|
45 |
inclusion of the above copyright notice. This software may not
|
|
46 |
be provided or otherwise made available to, or used by, any
|
|
47 |
other person. No title to or ownership of the software is
|
|
48 |
hereby transferred.
|
|
49 |
"
|
|
50 |
|
|
51 |
|
|
52 |
!
|
|
53 |
|
|
54 |
documentation
|
|
55 |
"
|
|
56 |
class to build up file trees like structures. You can define your own
|
|
57 |
icons and filter. Redefinging the icons you have to look especially for
|
|
58 |
this methods:
|
|
59 |
|
|
60 |
class method: iconsOn: : returns a list of icons used
|
|
61 |
|
|
62 |
instance method: updateImageType : set default key into icon list
|
|
63 |
for the image associated with node
|
|
64 |
|
|
65 |
imageUnselected : image or key into icon list
|
|
66 |
used for unselected mode
|
|
67 |
|
|
68 |
imageSelected : image or key into icon directory
|
|
69 |
used for selected mode
|
|
70 |
|
|
71 |
Especially suited for use with FileSelectionTree.
|
|
72 |
|
|
73 |
[Author:]
|
|
74 |
Claus Atzkern
|
|
75 |
|
|
76 |
[See also:]
|
|
77 |
TreeItem
|
|
78 |
FileSelectionTree
|
|
79 |
"
|
|
80 |
! !
|
|
81 |
|
|
82 |
!FileSelectionItem class methodsFor:'instance creation'!
|
|
83 |
|
|
84 |
pathName:aPath
|
|
85 |
"create a new node entry associated with the full pathname, aPath
|
|
86 |
"
|
|
87 |
|node|
|
|
88 |
|
|
89 |
node := self new.
|
|
90 |
node pathName:aPath.
|
|
91 |
^ node
|
|
92 |
|
|
93 |
|
|
94 |
! !
|
|
95 |
|
|
96 |
!FileSelectionItem class methodsFor:'accessing class'!
|
|
97 |
|
|
98 |
directoriesOnly
|
|
99 |
^ Directory
|
|
100 |
!
|
|
101 |
|
|
102 |
filesOnly
|
|
103 |
^ File
|
|
104 |
! !
|
|
105 |
|
|
106 |
!FileSelectionItem class methodsFor:'converting'!
|
|
107 |
|
|
108 |
asFilename:aPathname
|
|
109 |
"convert pathname to an absolute path
|
|
110 |
"
|
|
111 |
|path|
|
|
112 |
|
|
113 |
path := aPathname asString.
|
|
114 |
|
|
115 |
(path size > 1 and:[path endsWith:(Filename separator)]) ifTrue:[
|
|
116 |
^ (path copyWithout:1) asFilename.
|
|
117 |
].
|
|
118 |
^ aPathname asFilename
|
|
119 |
! !
|
|
120 |
|
|
121 |
!FileSelectionItem class methodsFor:'defaults'!
|
|
122 |
|
|
123 |
iconsOn:aDevice
|
|
124 |
"returns an IdentityDictionary containing a list of images and keys used
|
|
125 |
by any file entry.
|
|
126 |
"
|
|
127 |
|icons image|
|
|
128 |
|
|
129 |
icons := IdentityDictionary new.
|
|
130 |
|
|
131 |
#(
|
|
132 |
(#directory 'tiny_yellow_dir.xpm')
|
|
133 |
(#directoryOpened 'tiny_yellow_dir_open.xpm')
|
|
134 |
(#directoryLocked 'tiny_yellow_dir_locked.xpm')
|
|
135 |
(#directoryLink 'tiny_yellow_dir_link.xpm' )
|
|
136 |
|
|
137 |
(#file 'tiny_file_plain.xpm' )
|
|
138 |
(#fileLink 'tiny_file_link.xpm' )
|
|
139 |
(#fileLocked 'tiny_file_lock.xpm' )
|
|
140 |
(#imageFile 'tiny_file_pix.xpm' )
|
|
141 |
|
|
142 |
) do:[:el |
|
|
143 |
image := Image fromFile:('xpmBitmaps/document_images/', el last ).
|
|
144 |
icons at:(el first) put:(image onDevice:aDevice).
|
|
145 |
].
|
|
146 |
^ icons
|
|
147 |
|
|
148 |
|
|
149 |
! !
|
|
150 |
|
|
151 |
!FileSelectionItem class methodsFor:'queries'!
|
|
152 |
|
|
153 |
isSelectableFile:aFilename
|
|
154 |
"checks whether file can be selected through filter
|
|
155 |
"
|
|
156 |
aFilename notNil ifTrue:[
|
|
157 |
^ aFilename asFilename exists
|
|
158 |
].
|
|
159 |
^ false
|
|
160 |
! !
|
|
161 |
|
|
162 |
!FileSelectionItem methodsFor:'accessing'!
|
|
163 |
|
|
164 |
children
|
|
165 |
"get's list of children
|
|
166 |
"
|
|
167 |
invalidate ifTrue:[
|
|
168 |
isDirectory ifTrue:[self updateChildren].
|
|
169 |
invalidate := false
|
|
170 |
].
|
|
171 |
^ children
|
|
172 |
!
|
|
173 |
|
|
174 |
pathName
|
|
175 |
"returns full pathname of node
|
|
176 |
"
|
|
177 |
^ contents asString
|
|
178 |
|
|
179 |
|
|
180 |
!
|
|
181 |
|
|
182 |
pathName:aPathname
|
|
183 |
"initialze attributes associated with the full pathname, aPathname
|
|
184 |
"
|
|
185 |
contents := self class asFilename:aPathname.
|
|
186 |
name := contents baseName.
|
|
187 |
isDirectory := contents isDirectory.
|
|
188 |
self updateImageType.
|
|
189 |
|
|
190 |
isDirectory ifTrue:[
|
|
191 |
invalidate := imageType ~~ #directoryLocked
|
|
192 |
] ifFalse:[
|
|
193 |
invalidate := false
|
|
194 |
].
|
|
195 |
! !
|
|
196 |
|
|
197 |
!FileSelectionItem methodsFor:'images'!
|
|
198 |
|
|
199 |
imageSelected
|
|
200 |
"returns type or an image set for node in selected mode
|
|
201 |
"
|
|
202 |
"returns type or an image set for node in selected mode
|
|
203 |
"
|
|
204 |
(isDirectory and:[imageType ~~ #directoryLocked]) ifTrue:[
|
|
205 |
^ #directoryOpened
|
|
206 |
].
|
|
207 |
^ imageType
|
|
208 |
|
|
209 |
|
|
210 |
!
|
|
211 |
|
|
212 |
imageUnselected
|
|
213 |
"returns type or an image set for node in selected mode
|
|
214 |
"
|
|
215 |
^ imageType
|
|
216 |
|
|
217 |
|
|
218 |
! !
|
|
219 |
|
|
220 |
!FileSelectionItem methodsFor:'initialization'!
|
|
221 |
|
|
222 |
initialize
|
|
223 |
"set default values
|
|
224 |
"
|
|
225 |
super initialize.
|
|
226 |
invalidate := false.
|
|
227 |
! !
|
|
228 |
|
|
229 |
!FileSelectionItem methodsFor:'queries'!
|
|
230 |
|
|
231 |
hasChildren
|
|
232 |
"returns true if the pathname assigned to this node is a directory
|
|
233 |
otherwise false
|
|
234 |
"
|
|
235 |
^ isDirectory
|
|
236 |
|
|
237 |
!
|
|
238 |
|
|
239 |
isDirectory
|
|
240 |
^ isDirectory
|
|
241 |
!
|
|
242 |
|
|
243 |
match:aFilename
|
|
244 |
"returns true if file matched otherwise false
|
|
245 |
"
|
|
246 |
^ true
|
|
247 |
|
|
248 |
! !
|
|
249 |
|
|
250 |
!FileSelectionItem methodsFor:'update'!
|
|
251 |
|
|
252 |
updateChildren
|
|
253 |
"read children from directory
|
|
254 |
"
|
|
255 |
|pathName directory item aFilename|
|
|
256 |
|
|
257 |
children := OrderedCollection new.
|
|
258 |
pathName := self pathName.
|
|
259 |
directory := FileDirectory new.
|
|
260 |
directory pathName:pathName.
|
|
261 |
|
|
262 |
directory do:[:aName|
|
|
263 |
((aName first == $.) and:[aName last == $.]) ifFalse:[
|
|
264 |
aFilename := contents construct:aName.
|
|
265 |
(self match:aFilename) ifTrue:[
|
|
266 |
item := self class pathName:aFilename.
|
|
267 |
item parent:self.
|
|
268 |
children add:item
|
|
269 |
]
|
|
270 |
]
|
|
271 |
].
|
|
272 |
children sort:[:a :b | a name < b name].
|
|
273 |
invalidate := false.
|
|
274 |
|
|
275 |
!
|
|
276 |
|
|
277 |
updateImageType
|
|
278 |
"update image type
|
|
279 |
"
|
|
280 |
isDirectory ifTrue:[
|
|
281 |
contents isSymbolicLink ifTrue:[
|
|
282 |
imageType := #directoryLink
|
|
283 |
] ifFalse:[
|
|
284 |
(contents isExecutable and:[contents isReadable]) ifTrue:[
|
|
285 |
imageType := #directory
|
|
286 |
] ifFalse:[
|
|
287 |
imageType := #directoryLocked
|
|
288 |
]
|
|
289 |
].
|
|
290 |
^ self
|
|
291 |
].
|
|
292 |
|
|
293 |
contents isSymbolicLink ifTrue:[
|
|
294 |
imageType := #fileLink
|
|
295 |
] ifFalse:[
|
|
296 |
contents isReadable ifTrue:[
|
|
297 |
(Image isImageFileSuffix:(contents suffix)) ifFalse:[
|
|
298 |
imageType := #file
|
|
299 |
] ifTrue:[
|
|
300 |
imageType := #imageFile
|
|
301 |
]
|
|
302 |
] ifFalse:[
|
|
303 |
imageType := #fileLocked
|
|
304 |
]
|
|
305 |
]
|
|
306 |
! !
|
|
307 |
|
|
308 |
!FileSelectionItem::Directory class methodsFor:'documentation'!
|
|
309 |
|
|
310 |
documentation
|
|
311 |
"
|
|
312 |
subtype of FileSelectionItem only showing directories; more an example to show
|
|
313 |
how to implement filters
|
|
314 |
|
|
315 |
[Author:]
|
|
316 |
Claus Atzkern
|
|
317 |
|
|
318 |
[See also:]
|
|
319 |
FileSelectionItem
|
|
320 |
"
|
|
321 |
|
|
322 |
! !
|
|
323 |
|
|
324 |
!FileSelectionItem::Directory class methodsFor:'queries'!
|
|
325 |
|
|
326 |
isSelectableFile:aFilename
|
|
327 |
"checks whether file can be selected through filter
|
|
328 |
"
|
|
329 |
(super isSelectableFile:aFilename) ifTrue:[
|
|
330 |
^ aFilename asFilename isDirectory
|
|
331 |
].
|
|
332 |
^ false
|
|
333 |
|
|
334 |
|
|
335 |
! !
|
|
336 |
|
|
337 |
!FileSelectionItem::Directory methodsFor:'queries'!
|
|
338 |
|
|
339 |
match:aFilename
|
|
340 |
^ aFilename isDirectory
|
|
341 |
! !
|
|
342 |
|
|
343 |
!FileSelectionItem::File class methodsFor:'documentation'!
|
|
344 |
|
|
345 |
documentation
|
|
346 |
"
|
|
347 |
subtype of FileSelectionItem only showing files; more an example to show
|
|
348 |
how to implement filters
|
|
349 |
|
|
350 |
[Author:]
|
|
351 |
Claus Atzkern
|
|
352 |
|
|
353 |
[See also:]
|
|
354 |
FileSelectionItem
|
|
355 |
"
|
|
356 |
|
|
357 |
|
|
358 |
! !
|
|
359 |
|
|
360 |
!FileSelectionItem::File class methodsFor:'queries'!
|
|
361 |
|
|
362 |
isSelectableFile:aFilename
|
|
363 |
"checks whether file can be selected through filter
|
|
364 |
"
|
|
365 |
(super isSelectableFile:aFilename) ifTrue:[
|
|
366 |
^ aFilename asFilename isDirectory not
|
|
367 |
].
|
|
368 |
^ false
|
|
369 |
|
|
370 |
|
|
371 |
! !
|
|
372 |
|
|
373 |
!FileSelectionItem::File methodsFor:'queries'!
|
|
374 |
|
|
375 |
match:aFilename
|
|
376 |
^ aFilename isDirectory not
|
|
377 |
|
|
378 |
|
|
379 |
! !
|
|
380 |
|
|
381 |
!FileSelectionItem class methodsFor:'documentation'!
|
|
382 |
|
|
383 |
version
|
489
|
384 |
^ '$Header: /cvs/stx/stx/libwidg2/FileSelectionItem.st,v 1.2 1997-08-07 13:29:28 cg Exp $'
|
486
|
385 |
! !
|