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
|
786
|
16 |
instanceVariableNames:'modificationTime matchAction isDirectory imageType showIndicator'
|
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 |
|
786
|
60 |
class method: keysAndIcons : returns a list of icons and access keys used
|
486
|
61 |
|
569
|
62 |
instance method: imageType : get type of icon assigned to file
|
486
|
63 |
|
786
|
64 |
icon : get the type of image to be drawn
|
486
|
65 |
|
|
66 |
Especially suited for use with FileSelectionTree.
|
|
67 |
|
|
68 |
[Author:]
|
|
69 |
Claus Atzkern
|
|
70 |
|
|
71 |
[See also:]
|
|
72 |
TreeItem
|
|
73 |
FileSelectionTree
|
|
74 |
"
|
|
75 |
! !
|
|
76 |
|
|
77 |
!FileSelectionItem class methodsFor:'instance creation'!
|
|
78 |
|
|
79 |
pathName:aPath
|
|
80 |
"create a new node entry associated with the full pathname, aPath
|
|
81 |
"
|
|
82 |
|node|
|
|
83 |
|
|
84 |
node := self new.
|
|
85 |
node pathName:aPath.
|
|
86 |
^ node
|
|
87 |
|
|
88 |
|
|
89 |
! !
|
|
90 |
|
|
91 |
!FileSelectionItem class methodsFor:'accessing class'!
|
|
92 |
|
731
|
93 |
filterClassForDirectoriesOnly
|
486
|
94 |
^ Directory
|
|
95 |
!
|
|
96 |
|
731
|
97 |
filterClassForFilesOnly
|
486
|
98 |
^ File
|
|
99 |
! !
|
|
100 |
|
|
101 |
!FileSelectionItem class methodsFor:'converting'!
|
|
102 |
|
|
103 |
asFilename:aPathname
|
|
104 |
"convert pathname to an absolute path
|
|
105 |
"
|
|
106 |
|path|
|
|
107 |
|
|
108 |
path := aPathname asString.
|
|
109 |
|
|
110 |
(path size > 1 and:[path endsWith:(Filename separator)]) ifTrue:[
|
|
111 |
^ (path copyWithout:1) asFilename.
|
|
112 |
].
|
|
113 |
^ aPathname asFilename
|
|
114 |
! !
|
|
115 |
|
786
|
116 |
!FileSelectionItem class methodsFor:'default icons'!
|
486
|
117 |
|
786
|
118 |
keysAndIcons
|
486
|
119 |
"returns an IdentityDictionary containing a list of images and keys used
|
|
120 |
by any file entry.
|
|
121 |
"
|
|
122 |
|icons image|
|
|
123 |
|
|
124 |
icons := IdentityDictionary new.
|
|
125 |
|
|
126 |
#(
|
|
127 |
(#directory 'tiny_yellow_dir.xpm')
|
|
128 |
(#directoryOpened 'tiny_yellow_dir_open.xpm')
|
|
129 |
(#directoryLocked 'tiny_yellow_dir_locked.xpm')
|
|
130 |
(#directoryLink 'tiny_yellow_dir_link.xpm' )
|
|
131 |
|
|
132 |
(#file 'tiny_file_plain.xpm' )
|
|
133 |
(#fileLink 'tiny_file_link.xpm' )
|
|
134 |
(#fileLocked 'tiny_file_lock.xpm' )
|
|
135 |
(#imageFile 'tiny_file_pix.xpm' )
|
|
136 |
|
|
137 |
) do:[:el |
|
|
138 |
image := Image fromFile:('xpmBitmaps/document_images/', el last ).
|
786
|
139 |
|
569
|
140 |
image notNil ifTrue:[
|
|
141 |
icons at:(el first) put:image.
|
|
142 |
]
|
486
|
143 |
].
|
|
144 |
^ icons
|
|
145 |
|
|
146 |
|
|
147 |
! !
|
|
148 |
|
|
149 |
!FileSelectionItem methodsFor:'accessing'!
|
|
150 |
|
|
151 |
children
|
|
152 |
"get's list of children
|
|
153 |
"
|
786
|
154 |
readChildren ifTrue:[
|
569
|
155 |
children := self readInChildren
|
486
|
156 |
].
|
|
157 |
^ children
|
|
158 |
!
|
|
159 |
|
811
|
160 |
fileName
|
|
161 |
"returns the fileName of node
|
|
162 |
"
|
|
163 |
^ contents
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
!
|
|
168 |
|
786
|
169 |
icon
|
569
|
170 |
"returns type of image to be drawn
|
|
171 |
"
|
|
172 |
(children size ~~ 0 and:[hide == false]) ifTrue:[
|
|
173 |
^ #directoryOpened
|
|
174 |
].
|
|
175 |
^ self imageType
|
|
176 |
!
|
|
177 |
|
|
178 |
match:aOneArgBlock
|
|
179 |
|
|
180 |
aOneArgBlock isNil ifTrue:[
|
|
181 |
self discardFiles ifTrue:[
|
|
182 |
matchAction := [:aFile :isDirectory| isDirectory ]
|
|
183 |
] ifFalse:[
|
|
184 |
self discardDirectories ifTrue:[
|
|
185 |
matchAction := [:aFile :isDirectory| isDirectory not ]
|
|
186 |
] ifFalse:[
|
|
187 |
matchAction := [:aFile :isDir| true ]
|
|
188 |
]
|
|
189 |
]
|
|
190 |
] ifFalse:[
|
|
191 |
self discardFiles ifTrue:[
|
|
192 |
matchAction := [:aFile :isDirectory| (isDirectory and:[aOneArgBlock value:aFile]) ]
|
|
193 |
] ifFalse:[
|
|
194 |
self discardDirectories ifTrue:[
|
|
195 |
matchAction := [:aFile :isDirectory| (isDirectory not and:[aOneArgBlock value:aFile]) ]
|
|
196 |
] ifFalse:[
|
|
197 |
matchAction := [:aFile :isDir| aOneArgBlock value:aFile ]
|
|
198 |
]
|
|
199 |
]
|
|
200 |
]
|
|
201 |
!
|
|
202 |
|
486
|
203 |
pathName
|
|
204 |
"returns full pathname of node
|
|
205 |
"
|
569
|
206 |
^ contents asString
|
486
|
207 |
|
|
208 |
|
|
209 |
!
|
|
210 |
|
|
211 |
pathName:aPathname
|
|
212 |
"initialze attributes associated with the full pathname, aPathname
|
|
213 |
"
|
569
|
214 |
|file|
|
|
215 |
|
|
216 |
file := self class asFilename:aPathname.
|
|
217 |
self fileName:file baseName:(file baseName) parent:nil isDirectory:(file isDirectory)
|
|
218 |
! !
|
|
219 |
|
|
220 |
!FileSelectionItem methodsFor:'accessing hierarchy'!
|
|
221 |
|
|
222 |
collapse
|
811
|
223 |
"check to release children
|
569
|
224 |
"
|
811
|
225 |
self stopIndicatorValidation.
|
569
|
226 |
hide := true.
|
486
|
227 |
|
811
|
228 |
children notEmpty ifTrue:[
|
569
|
229 |
children do:[:aChild|
|
811
|
230 |
aChild releaseCollapsedChildren ifFalse:[ ^ self ]
|
569
|
231 |
].
|
811
|
232 |
self canReleaseChildren ifTrue:[
|
|
233 |
self releaseChildren
|
569
|
234 |
]
|
|
235 |
]
|
811
|
236 |
|
569
|
237 |
!
|
|
238 |
|
|
239 |
collapseAll
|
|
240 |
"release my childrens
|
|
241 |
"
|
811
|
242 |
self stopIndicatorValidation.
|
569
|
243 |
hide := true.
|
|
244 |
|
811
|
245 |
children notEmpty ifTrue:[
|
|
246 |
self canReleaseChildren ifTrue:[
|
|
247 |
self releaseChildren
|
569
|
248 |
] ifFalse:[
|
811
|
249 |
children do:[:c| c releaseChildren ]
|
569
|
250 |
]
|
486
|
251 |
].
|
811
|
252 |
|
844
|
253 |
!
|
|
254 |
|
|
255 |
expandAll
|
|
256 |
"not allowed for a file directory
|
|
257 |
"
|
|
258 |
self expand
|
486
|
259 |
! !
|
|
260 |
|
569
|
261 |
!FileSelectionItem methodsFor:'private'!
|
486
|
262 |
|
569
|
263 |
fileName:aFilenname baseName:aBaseName parent:aParent isDirectory:aBool
|
|
264 |
"initialze attributes associated with the full pathname, aPathname
|
486
|
265 |
"
|
569
|
266 |
contents := aFilenname.
|
|
267 |
name := aBaseName.
|
|
268 |
parent := aParent.
|
786
|
269 |
isDirectory := readChildren := aBool.
|
486
|
270 |
|
569
|
271 |
isDirectory ifFalse:[
|
|
272 |
showIndicator := false
|
|
273 |
] ifTrue:[
|
|
274 |
showIndicator := nil
|
|
275 |
].
|
|
276 |
|
|
277 |
parent notNil ifTrue:[
|
|
278 |
matchAction := parent matchAction "/ same as from parent
|
|
279 |
] ifFalse:[
|
|
280 |
self match:nil "/ setup matchAction new
|
|
281 |
]
|
486
|
282 |
|
|
283 |
!
|
|
284 |
|
569
|
285 |
matchAction
|
|
286 |
"returns my match action
|
486
|
287 |
"
|
569
|
288 |
^ matchAction
|
811
|
289 |
!
|
|
290 |
|
|
291 |
releaseChildren
|
|
292 |
"release my childrens without tests and deregistration from
|
|
293 |
update task
|
|
294 |
"
|
|
295 |
hide := true.
|
|
296 |
readChildren := true.
|
|
297 |
modificationTime := nil.
|
|
298 |
children := OrderedCollection new.
|
|
299 |
|
|
300 |
|
|
301 |
!
|
|
302 |
|
|
303 |
stopIndicatorValidation
|
|
304 |
"called to stop indicator validation on each child
|
|
305 |
"
|
|
306 |
|model|
|
|
307 |
|
|
308 |
(hide or:[children isEmpty]) ifFalse:[
|
|
309 |
(model := self model) notNil ifTrue:[
|
|
310 |
children do:[:c| c stopIndicatorValidation:model ].
|
|
311 |
model stopIndicatorValidationFor:children
|
|
312 |
]
|
|
313 |
]
|
|
314 |
|
|
315 |
|
|
316 |
!
|
|
317 |
|
|
318 |
stopIndicatorValidation:aModel
|
|
319 |
"called to stop indicator validation on each child
|
|
320 |
"
|
|
321 |
(hide or:[children isEmpty]) ifFalse:[
|
|
322 |
children do:[:c| c stopIndicatorValidation:aModel ].
|
|
323 |
aModel stopIndicatorValidationFor:children
|
|
324 |
]
|
|
325 |
|
|
326 |
|
486
|
327 |
! !
|
|
328 |
|
|
329 |
!FileSelectionItem methodsFor:'queries'!
|
|
330 |
|
811
|
331 |
canReleaseChildren
|
|
332 |
"returns true if children could be released
|
|
333 |
"
|
|
334 |
^ (parent notNil and:[parent parent notNil])
|
|
335 |
|
|
336 |
|
|
337 |
!
|
|
338 |
|
569
|
339 |
discardDirectories
|
|
340 |
"returns true if children are not type of directory; could be
|
|
341 |
reimplemented for speed in any subclass
|
|
342 |
"
|
|
343 |
^ false
|
|
344 |
!
|
|
345 |
|
|
346 |
discardFiles
|
|
347 |
"returns true if children are not type of file; could be
|
|
348 |
reimplemented for speed in any subclass
|
|
349 |
"
|
|
350 |
^ false
|
|
351 |
!
|
|
352 |
|
486
|
353 |
hasChildren
|
|
354 |
"returns true if the pathname assigned to this node is a directory
|
|
355 |
otherwise false
|
|
356 |
"
|
569
|
357 |
^ isDirectory
|
486
|
358 |
|
|
359 |
!
|
|
360 |
|
811
|
361 |
hasValidIndicator
|
|
362 |
"returns true if indication flag is uptodate
|
|
363 |
"
|
|
364 |
^ showIndicator notNil
|
|
365 |
|
|
366 |
!
|
|
367 |
|
486
|
368 |
isDirectory
|
|
369 |
^ isDirectory
|
|
370 |
!
|
|
371 |
|
569
|
372 |
releaseCollapsedChildren
|
|
373 |
"release collapsed children
|
|
374 |
"
|
811
|
375 |
|canCollapse model|
|
569
|
376 |
|
811
|
377 |
children isEmpty ifTrue:[
|
569
|
378 |
^ true
|
|
379 |
].
|
|
380 |
canCollapse := true.
|
|
381 |
|
|
382 |
children do:[:aChild|
|
|
383 |
aChild releaseCollapsedChildren ifFalse:[
|
|
384 |
canCollapse := false
|
|
385 |
]
|
|
386 |
].
|
811
|
387 |
|
569
|
388 |
(canCollapse and:[self isExpandable]) ifTrue:[
|
811
|
389 |
self canReleaseChildren ifTrue:[
|
|
390 |
self releaseChildren.
|
569
|
391 |
^ true.
|
|
392 |
]
|
|
393 |
].
|
|
394 |
^ false
|
811
|
395 |
|
|
396 |
!
|
|
397 |
|
|
398 |
setShowIndicator:aBool
|
|
399 |
"set indication; raise no change notification
|
|
400 |
"
|
|
401 |
showIndicator := aBool.
|
569
|
402 |
!
|
|
403 |
|
|
404 |
showIndicator
|
786
|
405 |
"returns true if the node is a not empty directory
|
|
406 |
"
|
811
|
407 |
|model|
|
|
408 |
|
569
|
409 |
showIndicator isNil ifTrue:[
|
|
410 |
(self imageType == #directoryLocked) ifTrue:[
|
786
|
411 |
showIndicator := readChildren := false.
|
569
|
412 |
] ifFalse:[
|
811
|
413 |
(model := self model) notNil ifTrue:[
|
|
414 |
model startIndicatorValidationFor:self.
|
|
415 |
].
|
|
416 |
^ false
|
569
|
417 |
]
|
|
418 |
].
|
|
419 |
^ showIndicator
|
|
420 |
|
811
|
421 |
|
|
422 |
!
|
|
423 |
|
|
424 |
showIndicator:aBool
|
|
425 |
"indication might change; raise a change notification
|
|
426 |
"
|
|
427 |
self showIndicator ~~ aBool ifTrue:[
|
|
428 |
showIndicator := aBool.
|
|
429 |
self changed:#indication
|
|
430 |
].
|
|
431 |
|
|
432 |
|
569
|
433 |
! !
|
|
434 |
|
|
435 |
!FileSelectionItem methodsFor:'repair mechanism'!
|
|
436 |
|
|
437 |
hasObsoleteNodes
|
|
438 |
"check whether node or any child node is obsolete
|
486
|
439 |
"
|
569
|
440 |
modificationTime notNil ifTrue:[
|
|
441 |
modificationTime < contents modificationTime ifTrue:[
|
|
442 |
^ true
|
|
443 |
].
|
811
|
444 |
(self discardDirectories or:[children isEmpty]) ifFalse:[
|
569
|
445 |
children do:[:aChild| aChild hasObsoleteNodes ifTrue:[^ true]]
|
|
446 |
]
|
|
447 |
].
|
|
448 |
^ false
|
811
|
449 |
|
569
|
450 |
!
|
|
451 |
|
|
452 |
repairObsoleteNodes
|
|
453 |
"repair nodes
|
|
454 |
"
|
|
455 |
|list chd hasChanged|
|
|
456 |
|
|
457 |
modificationTime isNil ifTrue:[
|
|
458 |
^ false
|
493
|
459 |
].
|
569
|
460 |
|
|
461 |
modificationTime < contents modificationTime ifTrue:[
|
|
462 |
list := self readInChildren.
|
|
463 |
hasChanged := list size ~~ children size.
|
|
464 |
|
|
465 |
children do:[:aChild||i|
|
|
466 |
i := list findFirst:[:f| f name = aChild name ].
|
|
467 |
|
|
468 |
i ~~ 0 ifTrue:[
|
|
469 |
list at:i put:aChild
|
|
470 |
] ifFalse:[
|
|
471 |
hasChanged := true
|
|
472 |
].
|
|
473 |
].
|
|
474 |
hasChanged ifTrue:[
|
811
|
475 |
self stopIndicatorValidation.
|
569
|
476 |
children := list
|
|
477 |
]
|
|
478 |
] ifFalse:[
|
|
479 |
hasChanged := false
|
|
480 |
].
|
|
481 |
children size ~~ 0 ifTrue:[
|
|
482 |
children do:[:aChild|
|
|
483 |
(aChild repairObsoleteNodes) ifTrue:[hasChanged := true]
|
|
484 |
]
|
|
485 |
].
|
|
486 |
^ self shown ifTrue:[hasChanged]
|
|
487 |
ifFalse:[false]
|
486
|
488 |
|
811
|
489 |
|
486
|
490 |
! !
|
|
491 |
|
|
492 |
!FileSelectionItem methodsFor:'update'!
|
|
493 |
|
569
|
494 |
imageType
|
|
495 |
|
|
496 |
|readable|
|
|
497 |
|
|
498 |
imageType isNil ifTrue:[
|
|
499 |
readable := contents isReadable.
|
486
|
500 |
|
569
|
501 |
isDirectory ifTrue:[
|
|
502 |
(readable and:[contents isExecutable]) ifTrue:[
|
|
503 |
contents isSymbolicLink ifFalse:[imageType := #directory]
|
|
504 |
ifTrue:[imageType := #directoryLink]
|
|
505 |
] ifFalse:[
|
|
506 |
imageType := #directoryLocked
|
|
507 |
]
|
|
508 |
] ifFalse:[
|
|
509 |
readable ifFalse:[
|
|
510 |
imageType := #fileLocked
|
|
511 |
] ifTrue:[
|
|
512 |
contents isSymbolicLink ifFalse:[
|
|
513 |
(Image isImageFileSuffix:(contents suffix)) ifFalse:[
|
|
514 |
imageType := #file
|
|
515 |
] ifTrue:[
|
|
516 |
imageType := #imageFile
|
|
517 |
]
|
|
518 |
] ifTrue:[
|
|
519 |
imageType := #fileLink
|
|
520 |
]
|
486
|
521 |
]
|
|
522 |
]
|
|
523 |
].
|
569
|
524 |
^ imageType
|
486
|
525 |
|
|
526 |
!
|
|
527 |
|
569
|
528 |
readInChildren
|
|
529 |
"read children from directory
|
486
|
530 |
"
|
569
|
531 |
|list directory node|
|
|
532 |
|
|
533 |
list := OrderedCollection new.
|
811
|
534 |
readChildren := false.
|
|
535 |
showIndicator := false.
|
569
|
536 |
|
|
537 |
self imageType == #directoryLocked ifFalse:[
|
811
|
538 |
Cursor wait showWhile:[
|
|
539 |
directory := DirectoryContents directoryNamed:contents.
|
569
|
540 |
|
811
|
541 |
directory isNil ifTrue:[
|
|
542 |
self stopIndicatorValidation.
|
|
543 |
self releaseChildren.
|
|
544 |
imageType := #directoryLocked.
|
|
545 |
] ifFalse:[
|
|
546 |
modificationTime := directory modificationTime.
|
|
547 |
|
|
548 |
directory contentsAndBaseNamesDo:[:f :n :d|
|
|
549 |
(matchAction value:f value:d) ifTrue:[
|
|
550 |
list add:(self class new fileName:f baseName:n parent:self isDirectory:d)
|
|
551 |
]
|
|
552 |
].
|
|
553 |
showIndicator := list size ~~ 0.
|
486
|
554 |
]
|
569
|
555 |
]
|
486
|
556 |
].
|
569
|
557 |
^ list
|
811
|
558 |
|
486
|
559 |
! !
|
|
560 |
|
|
561 |
!FileSelectionItem::Directory class methodsFor:'documentation'!
|
|
562 |
|
|
563 |
documentation
|
|
564 |
"
|
|
565 |
subtype of FileSelectionItem only showing directories; more an example to show
|
|
566 |
how to implement filters
|
|
567 |
|
|
568 |
[Author:]
|
|
569 |
Claus Atzkern
|
|
570 |
|
|
571 |
[See also:]
|
|
572 |
FileSelectionItem
|
|
573 |
"
|
|
574 |
|
|
575 |
! !
|
|
576 |
|
569
|
577 |
!FileSelectionItem::Directory methodsFor:'queries'!
|
486
|
578 |
|
569
|
579 |
discardFiles
|
|
580 |
^ true
|
486
|
581 |
! !
|
|
582 |
|
|
583 |
!FileSelectionItem::File class methodsFor:'documentation'!
|
|
584 |
|
|
585 |
documentation
|
|
586 |
"
|
|
587 |
subtype of FileSelectionItem only showing files; more an example to show
|
|
588 |
how to implement filters
|
|
589 |
|
|
590 |
[Author:]
|
|
591 |
Claus Atzkern
|
|
592 |
|
|
593 |
[See also:]
|
|
594 |
FileSelectionItem
|
|
595 |
"
|
|
596 |
|
|
597 |
|
|
598 |
! !
|
|
599 |
|
569
|
600 |
!FileSelectionItem::File methodsFor:'queries'!
|
486
|
601 |
|
569
|
602 |
discardDirectories
|
|
603 |
^ true
|
486
|
604 |
|
|
605 |
|
|
606 |
! !
|
|
607 |
|
|
608 |
!FileSelectionItem class methodsFor:'documentation'!
|
|
609 |
|
|
610 |
version
|
844
|
611 |
^ '$Header: /cvs/stx/stx/libwidg2/FileSelectionItem.st,v 1.10 1998-04-08 05:33:46 ca Exp $'
|
486
|
612 |
! !
|