author | Claus Gittinger <cg@exept.de> |
Wed, 24 Sep 1997 06:10:11 +0200 | |
changeset 535 | 9a237ca905d2 |
parent 531 | e96d35bccd61 |
child 569 | 2a1014d6697c |
permissions | -rw-r--r-- |
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 |
|
493 | 16 |
instanceVariableNames:'matchAction isDirectory imageType invalidate' |
486 | 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 ). |
|
531
e96d35bccd61
care for non-existent image files
Claus Gittinger <cg@exept.de>
parents:
493
diff
changeset
|
144 |
image notNil ifTrue:[ |
e96d35bccd61
care for non-existent image files
Claus Gittinger <cg@exept.de>
parents:
493
diff
changeset
|
145 |
icons at:(el first) put:(image onDevice:aDevice). |
e96d35bccd61
care for non-existent image files
Claus Gittinger <cg@exept.de>
parents:
493
diff
changeset
|
146 |
] |
486 | 147 |
]. |
148 |
^ icons |
|
149 |
||
150 |
||
151 |
! ! |
|
152 |
||
153 |
!FileSelectionItem methodsFor:'accessing'! |
|
154 |
||
155 |
children |
|
156 |
"get's list of children |
|
157 |
" |
|
158 |
invalidate ifTrue:[ |
|
159 |
isDirectory ifTrue:[self updateChildren]. |
|
160 |
invalidate := false |
|
161 |
]. |
|
162 |
^ children |
|
163 |
! |
|
164 |
||
165 |
pathName |
|
166 |
"returns full pathname of node |
|
167 |
" |
|
168 |
^ contents asString |
|
169 |
||
170 |
||
171 |
! |
|
172 |
||
173 |
pathName:aPathname |
|
174 |
"initialze attributes associated with the full pathname, aPathname |
|
175 |
" |
|
176 |
contents := self class asFilename:aPathname. |
|
177 |
name := contents baseName. |
|
178 |
isDirectory := contents isDirectory. |
|
179 |
self updateImageType. |
|
180 |
||
181 |
isDirectory ifTrue:[ |
|
182 |
invalidate := imageType ~~ #directoryLocked |
|
183 |
] ifFalse:[ |
|
184 |
invalidate := false |
|
185 |
]. |
|
186 |
! ! |
|
187 |
||
188 |
!FileSelectionItem methodsFor:'images'! |
|
189 |
||
190 |
imageSelected |
|
191 |
"returns type or an image set for node in selected mode |
|
192 |
" |
|
193 |
"returns type or an image set for node in selected mode |
|
194 |
" |
|
195 |
(isDirectory and:[imageType ~~ #directoryLocked]) ifTrue:[ |
|
196 |
^ #directoryOpened |
|
197 |
]. |
|
198 |
^ imageType |
|
199 |
||
200 |
||
201 |
! |
|
202 |
||
203 |
imageUnselected |
|
204 |
"returns type or an image set for node in selected mode |
|
205 |
" |
|
206 |
^ imageType |
|
207 |
||
208 |
||
209 |
! ! |
|
210 |
||
211 |
!FileSelectionItem methodsFor:'initialization'! |
|
212 |
||
213 |
initialize |
|
214 |
"set default values |
|
215 |
" |
|
216 |
super initialize. |
|
493 | 217 |
|
218 |
matchAction := nil. |
|
486 | 219 |
invalidate := false. |
220 |
! ! |
|
221 |
||
222 |
!FileSelectionItem methodsFor:'queries'! |
|
223 |
||
224 |
hasChildren |
|
225 |
"returns true if the pathname assigned to this node is a directory |
|
226 |
otherwise false |
|
227 |
" |
|
228 |
^ isDirectory |
|
229 |
||
230 |
! |
|
231 |
||
232 |
isDirectory |
|
233 |
^ isDirectory |
|
234 |
! |
|
235 |
||
236 |
match:aFilename |
|
237 |
"returns true if file matched otherwise false |
|
238 |
" |
|
493 | 239 |
matchAction notNil ifTrue:[ |
240 |
^ matchAction value:aFilename |
|
241 |
]. |
|
486 | 242 |
^ true |
243 |
||
244 |
! ! |
|
245 |
||
246 |
!FileSelectionItem methodsFor:'update'! |
|
247 |
||
248 |
updateChildren |
|
249 |
"read children from directory |
|
250 |
" |
|
251 |
|pathName directory item aFilename| |
|
252 |
||
253 |
children := OrderedCollection new. |
|
254 |
pathName := self pathName. |
|
535 | 255 |
directory := pathName asFilename directoryContents. |
486 | 256 |
directory do:[:aName| |
257 |
((aName first == $.) and:[aName last == $.]) ifFalse:[ |
|
258 |
aFilename := contents construct:aName. |
|
259 |
(self match:aFilename) ifTrue:[ |
|
260 |
item := self class pathName:aFilename. |
|
261 |
item parent:self. |
|
262 |
children add:item |
|
263 |
] |
|
264 |
] |
|
265 |
]. |
|
266 |
children sort:[:a :b | a name < b name]. |
|
267 |
invalidate := false. |
|
268 |
||
269 |
! |
|
270 |
||
271 |
updateImageType |
|
272 |
"update image type |
|
273 |
" |
|
274 |
isDirectory ifTrue:[ |
|
275 |
contents isSymbolicLink ifTrue:[ |
|
276 |
imageType := #directoryLink |
|
277 |
] ifFalse:[ |
|
278 |
(contents isExecutable and:[contents isReadable]) ifTrue:[ |
|
279 |
imageType := #directory |
|
280 |
] ifFalse:[ |
|
281 |
imageType := #directoryLocked |
|
282 |
] |
|
283 |
]. |
|
284 |
^ self |
|
285 |
]. |
|
286 |
||
287 |
contents isSymbolicLink ifTrue:[ |
|
288 |
imageType := #fileLink |
|
289 |
] ifFalse:[ |
|
290 |
contents isReadable ifTrue:[ |
|
291 |
(Image isImageFileSuffix:(contents suffix)) ifFalse:[ |
|
292 |
imageType := #file |
|
293 |
] ifTrue:[ |
|
294 |
imageType := #imageFile |
|
295 |
] |
|
296 |
] ifFalse:[ |
|
297 |
imageType := #fileLocked |
|
298 |
] |
|
299 |
] |
|
300 |
! ! |
|
301 |
||
302 |
!FileSelectionItem::Directory class methodsFor:'documentation'! |
|
303 |
||
304 |
documentation |
|
305 |
" |
|
306 |
subtype of FileSelectionItem only showing directories; more an example to show |
|
307 |
how to implement filters |
|
308 |
||
309 |
[Author:] |
|
310 |
Claus Atzkern |
|
311 |
||
312 |
[See also:] |
|
313 |
FileSelectionItem |
|
314 |
" |
|
315 |
||
316 |
! ! |
|
317 |
||
493 | 318 |
!FileSelectionItem::Directory methodsFor:'initialization'! |
486 | 319 |
|
493 | 320 |
initialize |
321 |
super initialize. |
|
322 |
matchAction := [:aFilename| aFilename isDirectory ] |
|
486 | 323 |
! ! |
324 |
||
325 |
!FileSelectionItem::File class methodsFor:'documentation'! |
|
326 |
||
327 |
documentation |
|
328 |
" |
|
329 |
subtype of FileSelectionItem only showing files; more an example to show |
|
330 |
how to implement filters |
|
331 |
||
332 |
[Author:] |
|
333 |
Claus Atzkern |
|
334 |
||
335 |
[See also:] |
|
336 |
FileSelectionItem |
|
337 |
" |
|
338 |
||
339 |
||
340 |
! ! |
|
341 |
||
493 | 342 |
!FileSelectionItem::File methodsFor:'initialization'! |
486 | 343 |
|
493 | 344 |
initialize |
345 |
super initialize. |
|
346 |
matchAction := [:aFilename| aFilename isDirectory not ] |
|
486 | 347 |
|
348 |
||
349 |
! ! |
|
350 |
||
351 |
!FileSelectionItem class methodsFor:'documentation'! |
|
352 |
||
353 |
version |
|
535 | 354 |
^ '$Header: /cvs/stx/stx/libwidg2/FileSelectionItem.st,v 1.5 1997-09-24 04:10:11 cg Exp $' |
486 | 355 |
! ! |