1431
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1999 by eXept Software AG
|
|
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 |
|
1390
|
14 |
HierarchicalList subclass:#HierarchicalFileList
|
1581
|
15 |
instanceVariableNames:'icons matchBlock showCursor'
|
1390
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
1430
|
18 |
category:'Views-Support'
|
1390
|
19 |
!
|
|
20 |
|
|
21 |
HierarchicalItem subclass:#File
|
|
22 |
instanceVariableNames:'fileName baseName icon'
|
|
23 |
classVariableNames:''
|
|
24 |
poolDictionaries:''
|
|
25 |
privateIn:HierarchicalFileList
|
|
26 |
!
|
|
27 |
|
|
28 |
HierarchicalFileList::File subclass:#Directory
|
|
29 |
instanceVariableNames:'modificationTime'
|
|
30 |
classVariableNames:''
|
|
31 |
poolDictionaries:''
|
|
32 |
privateIn:HierarchicalFileList::File
|
|
33 |
!
|
|
34 |
|
1431
|
35 |
!HierarchicalFileList class methodsFor:'documentation'!
|
|
36 |
|
|
37 |
copyright
|
|
38 |
"
|
|
39 |
COPYRIGHT (c) 1999 by eXept Software AG
|
|
40 |
All Rights Reserved
|
|
41 |
|
|
42 |
This software is furnished under a license and may be used
|
|
43 |
only in accordance with the terms of that license and with the
|
|
44 |
inclusion of the above copyright notice. This software may not
|
|
45 |
be provided or otherwise made available to, or used by, any
|
|
46 |
other person. No title to or ownership of the software is
|
|
47 |
hereby transferred.
|
|
48 |
"
|
|
49 |
|
|
50 |
! !
|
1390
|
51 |
|
|
52 |
!HierarchicalFileList class methodsFor:'examples'!
|
|
53 |
|
|
54 |
test
|
|
55 |
|top sel list item|
|
|
56 |
|
|
57 |
list := HierarchicalFileList new.
|
|
58 |
list directory:(Filename homeDirectory).
|
|
59 |
list showRoot:false.
|
|
60 |
list matchBlock:[:fn :isDir| |suf rslt|
|
|
61 |
(rslt := isDir) ifFalse:[
|
|
62 |
suf := fn suffix.
|
|
63 |
|
|
64 |
suf size ~~ 0 ifTrue:[
|
|
65 |
rslt := ( suf = 'c'
|
|
66 |
or:[suf = 'h'
|
|
67 |
or:[suf = 'hi']]
|
|
68 |
)
|
|
69 |
]
|
|
70 |
].
|
|
71 |
rslt
|
|
72 |
].
|
|
73 |
|
|
74 |
top := StandardSystemView new; extent:300@300.
|
|
75 |
sel := ScrollableView for:HierarchicalListView miniScroller:true
|
|
76 |
origin:0.0@0.0 corner:1.0@1.0 in:top.
|
|
77 |
|
|
78 |
sel list:list.
|
|
79 |
list root expand.
|
|
80 |
|
|
81 |
sel doubleClickAction:[:i| (list at:i) toggleExpand ].
|
|
82 |
sel indicatorAction:[:i| (list at:i) toggleExpand ].
|
|
83 |
|
|
84 |
top open.
|
|
85 |
|
|
86 |
|
|
87 |
! !
|
|
88 |
|
|
89 |
!HierarchicalFileList class methodsFor:'resources'!
|
|
90 |
|
|
91 |
icons
|
|
92 |
"returns set of icons
|
|
93 |
"
|
|
94 |
|icons resources fileKey resource baseName pathName|
|
|
95 |
|
|
96 |
resources := FileBrowser classResources.
|
|
97 |
icons := Dictionary new.
|
|
98 |
|
|
99 |
#(
|
|
100 |
(#directory 'ICON_DIRECTORY' 'tiny_yellow_dir.xpm' )
|
|
101 |
(#directoryLocked 'ICON_DIRECTORY_LOCKED' 'tiny_yellow_dir_locked.xpm')
|
|
102 |
(#directoryLink 'ICON_DIRECTORY_LINK' 'tiny_yellow_dir_link.xpm' )
|
|
103 |
(#file 'ICON_FILE' 'tiny_file_plain.xpm' )
|
|
104 |
(#fileLink 'ICON_FILE_LINK' 'tiny_file_link.xpm' )
|
|
105 |
(#fileLocked 'ICON_FILE_LOCKED' 'tiny_file_lock.xpm' )
|
|
106 |
(#imageFile 'ICON_IMAGE_FILE' 'tiny_file_pix.xpm' )
|
|
107 |
(#textFile 'ICON_TEXT_FILE' 'tiny_file_text.xpm' )
|
|
108 |
(#executableFile 'ICON_EXECUTABLEFILE' 'tiny_file_exec.xpm' )
|
|
109 |
|
|
110 |
) do:[:entry|
|
|
111 |
fileKey := entry at:1.
|
|
112 |
resource := entry at:2.
|
|
113 |
baseName := entry at:3.
|
|
114 |
|
|
115 |
(pathName := resources at:(entry at:2) default:nil) isNil ifTrue:[
|
|
116 |
pathName := 'bitmaps/xpmBitmaps/document_images/' , baseName
|
|
117 |
].
|
|
118 |
icons at:fileKey put:(Image fromFile:pathName).
|
|
119 |
].
|
|
120 |
^ icons
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
! !
|
|
126 |
|
|
127 |
!HierarchicalFileList methodsFor:'accessing'!
|
|
128 |
|
|
129 |
directory
|
|
130 |
"returns the root directory or nil
|
|
131 |
"
|
|
132 |
^ root notNil ifTrue:[root fileName] ifFalse:[nil]
|
|
133 |
|
|
134 |
!
|
|
135 |
|
|
136 |
directory:aDirectory
|
|
137 |
"set the root directory or nil
|
|
138 |
"
|
|
139 |
|directory|
|
|
140 |
|
|
141 |
monitoringTaskDelay := 1.
|
|
142 |
|
|
143 |
(aDirectory notNil and:[(directory := aDirectory asFilename) exists]) ifTrue:[
|
|
144 |
directory isDirectory ifFalse:[
|
|
145 |
directory := directory directory
|
|
146 |
]
|
|
147 |
] ifFalse:[
|
|
148 |
directory := nil
|
|
149 |
].
|
|
150 |
|
|
151 |
directory = self directory ifFalse:[
|
|
152 |
directory notNil ifTrue:[
|
|
153 |
directory := File fileName:directory isDirectory:true
|
|
154 |
].
|
|
155 |
self root:directory
|
|
156 |
].
|
|
157 |
! !
|
|
158 |
|
|
159 |
!HierarchicalFileList methodsFor:'actions'!
|
|
160 |
|
|
161 |
matchBlock
|
|
162 |
"set the matchBlock - if non-nil, it controls which files are visible.
|
|
163 |
"
|
|
164 |
^ matchBlock
|
|
165 |
|
|
166 |
!
|
|
167 |
|
|
168 |
matchBlock:aBlock
|
|
169 |
"set the matchBlock - if non-nil, it controls which files are visible.
|
|
170 |
"
|
|
171 |
matchBlock := aBlock.
|
|
172 |
|
|
173 |
! !
|
|
174 |
|
|
175 |
!HierarchicalFileList methodsFor:'protocol'!
|
|
176 |
|
|
177 |
childrenFor:anItem
|
|
178 |
"returns all visible children derived from the physical
|
|
179 |
directory contents.
|
|
180 |
"
|
|
181 |
|contents list block|
|
|
182 |
|
|
183 |
list := #().
|
|
184 |
|
|
185 |
anItem isDirectory ifFalse:[
|
|
186 |
^ list
|
|
187 |
].
|
|
188 |
|
1581
|
189 |
contents := DirectoryContents directoryNamed:(anItem fileName).
|
1390
|
190 |
|
1581
|
191 |
contents notNil ifTrue:[
|
|
192 |
list := OrderedCollection new.
|
|
193 |
block := self matchBlockFor:anItem.
|
1390
|
194 |
|
1581
|
195 |
block isNil ifTrue:[
|
|
196 |
contents contentsDo:[:fn :isDir|
|
|
197 |
list add:(File fileName:fn isDirectory:isDir)
|
|
198 |
]
|
|
199 |
] ifFalse:[
|
|
200 |
contents contentsDo:[:fn :isDir|
|
|
201 |
(block value:fn value:isDir) ifTrue:[
|
1390
|
202 |
list add:(File fileName:fn isDirectory:isDir)
|
|
203 |
]
|
|
204 |
]
|
|
205 |
]
|
|
206 |
].
|
|
207 |
^ list
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
!
|
|
213 |
|
|
214 |
hasChildrenFor:anItem
|
|
215 |
"returns true if the physical directory contains at least
|
|
216 |
one visible item otherwise false.
|
|
217 |
"
|
|
218 |
|block|
|
|
219 |
|
|
220 |
anItem isDirectory ifFalse:[
|
|
221 |
^ false
|
|
222 |
].
|
|
223 |
|
|
224 |
(block := self matchBlockFor:anItem) isNil ifTrue:[
|
|
225 |
block := [:aFilename :isDirectory| true ]
|
|
226 |
].
|
|
227 |
^ DirectoryContents directoryNamed:(anItem fileName) detect:block
|
|
228 |
!
|
|
229 |
|
|
230 |
iconFor:anItem
|
|
231 |
"returns the icon for an item
|
|
232 |
"
|
|
233 |
|fn key|
|
|
234 |
|
|
235 |
fn := anItem fileName.
|
|
236 |
|
|
237 |
fn isDirectory ifTrue:[
|
|
238 |
(fn isReadable and:[fn isExecutable]) ifTrue:[
|
|
239 |
key := fn isSymbolicLink ifTrue:[#directoryLink]
|
|
240 |
ifFalse:[#directory]
|
|
241 |
] ifFalse:[
|
|
242 |
key := #directoryLocked
|
|
243 |
]
|
|
244 |
] ifFalse:[
|
|
245 |
fn isReadable ifTrue:[
|
|
246 |
fn isSymbolicLink ifTrue:[
|
|
247 |
key := #fileLink
|
|
248 |
] ifFalse:[
|
|
249 |
(Image isImageFileSuffix:(fn suffix)) ifTrue:[
|
|
250 |
key := #imageFile
|
|
251 |
] ifFalse:[
|
|
252 |
key := #file
|
|
253 |
]
|
|
254 |
]
|
|
255 |
] ifFalse:[
|
|
256 |
key := #fileLocked
|
|
257 |
]
|
|
258 |
].
|
|
259 |
icons isNil ifTrue:[
|
|
260 |
icons := self class icons
|
|
261 |
].
|
|
262 |
|
|
263 |
^ icons at:key ifAbsent:nil
|
|
264 |
!
|
|
265 |
|
|
266 |
matchBlockFor:anItem
|
|
267 |
"get the matchBlock - if non-nil, it controls which files are
|
|
268 |
visible within the physical directory
|
|
269 |
"
|
|
270 |
^ matchBlock
|
|
271 |
! !
|
|
272 |
|
1581
|
273 |
!HierarchicalFileList methodsFor:'searching'!
|
|
274 |
|
|
275 |
detectItemFor:aPathOrFilename
|
|
276 |
"make a filename visible
|
|
277 |
"
|
|
278 |
|file node p1 p2 sz|
|
|
279 |
|
1582
|
280 |
aPathOrFilename isNil ifTrue:[^ nil].
|
1581
|
281 |
|
|
282 |
file := aPathOrFilename asFilename.
|
|
283 |
|
|
284 |
file exists ifFalse:[
|
1582
|
285 |
^ nil
|
1581
|
286 |
].
|
1582
|
287 |
(node := root) isNil ifTrue:[^ nil].
|
1581
|
288 |
|
|
289 |
p1 := node pathName.
|
|
290 |
p2 := file pathName.
|
|
291 |
|
1582
|
292 |
(p2 startsWith:p1) ifFalse:[^ nil].
|
1581
|
293 |
sz := 1 + p1 size.
|
|
294 |
|
|
295 |
(p1 last == Filename separator) ifFalse:[
|
|
296 |
sz := sz + 1.
|
|
297 |
].
|
|
298 |
|
1582
|
299 |
p2 size > sz ifFalse:[^ nil].
|
1581
|
300 |
|
|
301 |
p2 := Filename components:(p2 copyFrom:sz).
|
|
302 |
|
|
303 |
p2 do:[:bn|
|
|
304 |
node := node detect:[:el| el baseName = bn] ifNone:nil.
|
|
305 |
node isNil ifTrue:[^ nil ].
|
|
306 |
].
|
|
307 |
^ node
|
|
308 |
! !
|
|
309 |
|
1390
|
310 |
!HierarchicalFileList::File class methodsFor:'instance creation'!
|
|
311 |
|
|
312 |
fileName:aFileName isDirectory:isDirectory
|
|
313 |
"instance creation
|
|
314 |
"
|
|
315 |
|item|
|
|
316 |
|
|
317 |
item := isDirectory ifTrue:[Directory new] ifFalse:[HierarchicalFileList::File new].
|
|
318 |
item fileName:aFileName.
|
|
319 |
^ item
|
|
320 |
|
|
321 |
! !
|
|
322 |
|
|
323 |
!HierarchicalFileList::File methodsFor:'accessing'!
|
|
324 |
|
|
325 |
baseName
|
|
326 |
"returns the baseName
|
|
327 |
"
|
|
328 |
^ baseName
|
|
329 |
|
|
330 |
|
|
331 |
!
|
|
332 |
|
|
333 |
children
|
|
334 |
"always returns an empty list
|
|
335 |
"
|
|
336 |
^ #()
|
|
337 |
!
|
|
338 |
|
|
339 |
fileName
|
|
340 |
"returns the fileName
|
|
341 |
"
|
|
342 |
^ fileName
|
|
343 |
|
|
344 |
|
|
345 |
!
|
|
346 |
|
|
347 |
fileName:fname
|
|
348 |
"instance creation
|
|
349 |
"
|
|
350 |
fileName := fname.
|
|
351 |
baseName := fname baseName.
|
|
352 |
!
|
|
353 |
|
|
354 |
icon
|
|
355 |
"returns the icon key
|
|
356 |
"
|
|
357 |
|model|
|
|
358 |
|
|
359 |
icon isNil ifTrue:[
|
|
360 |
(model := self model) notNil ifTrue:[
|
|
361 |
icon := model iconFor:self
|
|
362 |
]
|
|
363 |
].
|
|
364 |
^ icon
|
|
365 |
|
|
366 |
|
|
367 |
!
|
|
368 |
|
|
369 |
label
|
|
370 |
"returns the printable name, the baseName
|
|
371 |
"
|
|
372 |
^ baseName
|
|
373 |
|
|
374 |
|
|
375 |
!
|
|
376 |
|
|
377 |
pathName
|
|
378 |
"returns the pathName
|
|
379 |
"
|
|
380 |
^ fileName pathName
|
|
381 |
! !
|
|
382 |
|
|
383 |
!HierarchicalFileList::File methodsFor:'accessing hierarchy'!
|
|
384 |
|
|
385 |
recursiveExpand
|
|
386 |
"redefined to expand
|
|
387 |
"
|
|
388 |
self expand
|
|
389 |
|
|
390 |
|
|
391 |
! !
|
|
392 |
|
|
393 |
!HierarchicalFileList::File methodsFor:'invalidate'!
|
|
394 |
|
|
395 |
invalidate
|
|
396 |
"invalidate the contents
|
|
397 |
"
|
|
398 |
self invalidateRepairNow:false
|
|
399 |
|
|
400 |
!
|
|
401 |
|
|
402 |
invalidateRepairNow
|
|
403 |
"invalidate the contents; repair now
|
|
404 |
"
|
|
405 |
self invalidateRepairNow:true
|
|
406 |
|
|
407 |
!
|
|
408 |
|
|
409 |
invalidateRepairNow:doRepair
|
|
410 |
"invalidate the contents; dependent on the boolean
|
|
411 |
do repair immediately
|
|
412 |
"
|
|
413 |
|
|
414 |
|
|
415 |
! !
|
|
416 |
|
|
417 |
!HierarchicalFileList::File methodsFor:'queries'!
|
|
418 |
|
|
419 |
hasChildren
|
|
420 |
"always returns false
|
|
421 |
"
|
|
422 |
^ false
|
|
423 |
!
|
|
424 |
|
|
425 |
isDirectory
|
|
426 |
"always returns false
|
|
427 |
"
|
|
428 |
^ false
|
|
429 |
|
|
430 |
! !
|
|
431 |
|
|
432 |
!HierarchicalFileList::File::Directory methodsFor:'accessing'!
|
|
433 |
|
|
434 |
children
|
|
435 |
"returns the list of children
|
|
436 |
"
|
|
437 |
|model list|
|
|
438 |
|
|
439 |
children isNil ifTrue:[
|
|
440 |
children := #(). "/ disable reread
|
|
441 |
modificationTime := fileName modificationTime.
|
|
442 |
|
|
443 |
(model := self model) notNil ifTrue:[
|
|
444 |
list := model childrenFor:self.
|
|
445 |
|
|
446 |
list size ~~ 0 ifTrue:[
|
|
447 |
list do:[:aChild| aChild parent:self].
|
|
448 |
children := list.
|
|
449 |
]
|
|
450 |
].
|
|
451 |
].
|
|
452 |
^ children
|
|
453 |
!
|
|
454 |
|
|
455 |
icon
|
|
456 |
"returns the icon
|
|
457 |
"
|
|
458 |
(isExpanded and:[children size ~~ 0]) ifTrue:[
|
|
459 |
^ nil
|
|
460 |
].
|
|
461 |
^ super icon
|
|
462 |
! !
|
|
463 |
|
|
464 |
!HierarchicalFileList::File::Directory methodsFor:'queries'!
|
|
465 |
|
|
466 |
hasChildren
|
|
467 |
"returns true if children exists
|
|
468 |
"
|
|
469 |
^ children isNil or:[children notEmpty]
|
|
470 |
!
|
|
471 |
|
|
472 |
isDirectory
|
|
473 |
"always returns true
|
|
474 |
"
|
|
475 |
^ true
|
|
476 |
|
|
477 |
|
|
478 |
! !
|
|
479 |
|
|
480 |
!HierarchicalFileList::File::Directory methodsFor:'validation'!
|
|
481 |
|
|
482 |
invalidateRepairNow:doRepair
|
|
483 |
"invalidate contents
|
|
484 |
"
|
|
485 |
modificationTime := nil.
|
|
486 |
|
|
487 |
doRepair ifTrue:[
|
|
488 |
self monitoringCycle
|
|
489 |
] ifFalse:[
|
|
490 |
(isExpanded or:[children size == 0]) ifFalse:[
|
|
491 |
children := nil
|
|
492 |
]
|
|
493 |
].
|
|
494 |
|
|
495 |
!
|
|
496 |
|
|
497 |
monitoringCycle
|
|
498 |
"run monitoring cycle
|
|
499 |
"
|
|
500 |
|list size name modifyTime isNotEmpty wasNotEmpty model|
|
|
501 |
|
|
502 |
modifyTime := fileName modificationTime.
|
|
503 |
|
|
504 |
(modificationTime notNil and:[modifyTime <= modificationTime]) ifTrue:[
|
|
505 |
^ self
|
|
506 |
].
|
|
507 |
model := self model.
|
|
508 |
modificationTime := modifyTime.
|
|
509 |
|
|
510 |
isExpanded ifFalse:[
|
|
511 |
|
|
512 |
"/ CHECK WHETHER CHILDREN EXIST( INDICATOR )
|
|
513 |
"/ =========================================
|
|
514 |
|
|
515 |
isNotEmpty := model hasChildrenFor:self.
|
|
516 |
|
|
517 |
"/ check whether has changed durring evaluation
|
|
518 |
(isExpanded or:[modificationTime ~= modifyTime]) ifFalse:[
|
|
519 |
wasNotEmpty := children isNil.
|
|
520 |
children := isNotEmpty ifTrue:[nil] ifFalse:[#()].
|
|
521 |
|
|
522 |
wasNotEmpty ~~ isNotEmpty ifTrue:[
|
|
523 |
self changed
|
|
524 |
]
|
|
525 |
].
|
|
526 |
^ self
|
|
527 |
|
|
528 |
].
|
|
529 |
|
|
530 |
"/ START MERGING( CONTENTS IS VISIBLE )
|
|
531 |
"/ ====================================
|
|
532 |
|
|
533 |
list := model childrenFor:self.
|
|
534 |
|
|
535 |
list size == 0 ifTrue:[ "/ contents becomes empty
|
|
536 |
^ self removeAll "/ clear contents
|
|
537 |
].
|
|
538 |
(size := children size) == 0 ifTrue:[ "/ old contents was empty
|
|
539 |
^ self addAll:list. "/ take over new contents
|
|
540 |
].
|
|
541 |
|
|
542 |
size to:1 by:-1 do:[:anIndex| "/ remove invisible items
|
|
543 |
name := (children at:anIndex) baseName.
|
|
544 |
|
|
545 |
(list findFirst:[:i|i baseName = name]) == 0 ifTrue:[
|
|
546 |
self removeIndex:anIndex
|
|
547 |
]
|
|
548 |
].
|
|
549 |
|
|
550 |
list keysAndValuesDo:[:anIndex :anItem| "/ add new visible items
|
|
551 |
name := anItem baseName.
|
|
552 |
|
|
553 |
(children findFirst:[:i|i baseName = name]) == 0 ifTrue:[
|
|
554 |
self add:anItem beforeIndex:anIndex
|
|
555 |
]
|
|
556 |
].
|
|
557 |
! !
|
|
558 |
|
|
559 |
!HierarchicalFileList class methodsFor:'documentation'!
|
|
560 |
|
|
561 |
version
|
1582
|
562 |
^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalFileList.st,v 1.6 1999-10-07 05:25:55 ca Exp $'
|
1390
|
563 |
! !
|