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