author | ca |
Fri, 09 Aug 2002 11:43:51 +0200 | |
changeset 2130 | 8b64928cd378 |
parent 2128 | f79308387ed7 |
child 2138 | 4175c127f9b8 |
permissions | -rw-r--r-- |
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 |
2130 | 17 |
instanceVariableNames:'icons matchBlock showCursor' |
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'Views-Support' |
|
1390 | 21 |
! |
22 |
||
23 |
HierarchicalItem subclass:#File |
|
2130 | 24 |
instanceVariableNames:'fileName baseName icon' |
25 |
classVariableNames:'' |
|
26 |
poolDictionaries:'' |
|
27 |
privateIn:HierarchicalFileList |
|
1390 | 28 |
! |
29 |
||
30 |
HierarchicalFileList::File subclass:#Directory |
|
2130 | 31 |
instanceVariableNames:'modificationTime' |
32 |
classVariableNames:'' |
|
33 |
poolDictionaries:'' |
|
34 |
privateIn:HierarchicalFileList::File |
|
1390 | 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 |
|
2130 | 57 |
" |
58 |
self test |
|
59 |
" |
|
60 |
|top sel list| |
|
1390 | 61 |
|
62 |
list := HierarchicalFileList new. |
|
63 |
list directory:(Filename homeDirectory). |
|
64 |
list showRoot:false. |
|
2130 | 65 |
list matchBlock:[:fn :isDir| true ]. |
1390 | 66 |
|
67 |
top := StandardSystemView new; extent:300@300. |
|
68 |
sel := ScrollableView for:HierarchicalListView miniScroller:true |
|
69 |
origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
70 |
||
71 |
sel list:list. |
|
72 |
list root expand. |
|
73 |
||
74 |
sel doubleClickAction:[:i| (list at:i) toggleExpand ]. |
|
75 |
sel indicatorAction:[:i| (list at:i) toggleExpand ]. |
|
76 |
||
77 |
top open. |
|
78 |
! ! |
|
79 |
||
80 |
!HierarchicalFileList class methodsFor:'resources'! |
|
81 |
||
82 |
icons |
|
1780 | 83 |
^ FileBrowser icons. |
1390 | 84 |
|
85 |
||
86 |
||
87 |
||
88 |
! ! |
|
89 |
||
90 |
!HierarchicalFileList methodsFor:'accessing'! |
|
91 |
||
92 |
directory |
|
93 |
"returns the root directory or nil |
|
94 |
" |
|
95 |
^ root notNil ifTrue:[root fileName] ifFalse:[nil] |
|
96 |
||
97 |
! |
|
98 |
||
99 |
directory:aDirectory |
|
100 |
"set the root directory or nil |
|
101 |
" |
|
102 |
|directory| |
|
103 |
||
1960
2363303c1c8c
monitoring must be enebled by user (no longer automatically)
ca
parents:
1867
diff
changeset
|
104 |
"/ must explicitly enabled by user: ca |
2363303c1c8c
monitoring must be enebled by user (no longer automatically)
ca
parents:
1867
diff
changeset
|
105 |
"/ monitoringTaskDelay := 1. |
1390 | 106 |
|
107 |
(aDirectory notNil and:[(directory := aDirectory asFilename) exists]) ifTrue:[ |
|
108 |
directory isDirectory ifFalse:[ |
|
109 |
directory := directory directory |
|
110 |
] |
|
111 |
] ifFalse:[ |
|
112 |
directory := nil |
|
113 |
]. |
|
114 |
||
115 |
directory = self directory ifFalse:[ |
|
116 |
directory notNil ifTrue:[ |
|
117 |
directory := File fileName:directory isDirectory:true |
|
118 |
]. |
|
119 |
self root:directory |
|
120 |
]. |
|
121 |
! ! |
|
122 |
||
123 |
!HierarchicalFileList methodsFor:'actions'! |
|
124 |
||
125 |
matchBlock |
|
126 |
"set the matchBlock - if non-nil, it controls which files are visible. |
|
127 |
" |
|
128 |
^ matchBlock |
|
129 |
||
130 |
! |
|
131 |
||
132 |
matchBlock:aBlock |
|
133 |
"set the matchBlock - if non-nil, it controls which files are visible. |
|
134 |
" |
|
135 |
matchBlock := aBlock. |
|
1866 | 136 |
|
137 |
root notNil ifTrue:[ |
|
1867 | 138 |
self recursionLock critical:[ |
139 |
self stopMonitoringTask. |
|
140 |
root matchBlockChanged. |
|
141 |
]. |
|
142 |
self startMonitoringTask. |
|
1866 | 143 |
]. |
1867 | 144 |
|
1390 | 145 |
! ! |
146 |
||
2104
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
147 |
!HierarchicalFileList methodsFor:'private monitoring task'! |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
148 |
|
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
149 |
monitoringCycle |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
150 |
"the block evaluated by the monitoring task; test whether directory is expanded |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
151 |
otherwise we have not to evaluate the directory contents. |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
152 |
think about remote file-systems |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
153 |
" |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
154 |
|index item| |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
155 |
|
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
156 |
item := root. |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
157 |
index := showRoot ifTrue:[1] ifFalse:[0]. |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
158 |
|
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
159 |
[item notNil] whileTrue:[ |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
160 |
(item isDirectory and:[item getChildren notNil]) ifTrue:[ |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
161 |
"/ children already initialized; thus we can update the contents |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
162 |
item monitoringCycle |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
163 |
]. |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
164 |
Processor yield. |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
165 |
index := index + 1. |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
166 |
item := self at:index ifAbsent:nil. |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
167 |
]. |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
168 |
! ! |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
169 |
|
1390 | 170 |
!HierarchicalFileList methodsFor:'protocol'! |
171 |
||
172 |
childrenFor:anItem |
|
173 |
"returns all visible children derived from the physical |
|
174 |
directory contents. |
|
175 |
" |
|
176 |
|contents list block| |
|
177 |
||
2130 | 178 |
anItem isDirectory ifFalse:[^ #()]. |
1390 | 179 |
|
1581 | 180 |
contents := DirectoryContents directoryNamed:(anItem fileName). |
2130 | 181 |
contents ifNil:[ ^ #() ]. |
1390 | 182 |
|
183 |
||
2130 | 184 |
list := SortedCollection sortBlock:[:a :b| |res| |
185 |
a isDirectory == b isDirectory ifTrue:[ res := a baseName <= b baseName ] |
|
186 |
ifFalse:[ res := a isDirectory ]. |
|
187 |
res |
|
188 |
]. |
|
189 |
block := self matchBlockFor:anItem. |
|
190 |
||
191 |
block isNil ifTrue:[ |
|
192 |
contents contentsDo:[:fn :isDir| |
|
193 |
list add:(File fileName:fn isDirectory:isDir) |
|
194 |
] |
|
195 |
] ifFalse:[ |
|
196 |
contents contentsDo:[:fn :isDir| |
|
197 |
(block value:fn value:isDir) ifTrue:[ |
|
1581 | 198 |
list add:(File fileName:fn isDirectory:isDir) |
199 |
] |
|
1390 | 200 |
] |
201 |
]. |
|
2130 | 202 |
list isEmpty ifTrue:[^ #()]. |
203 |
^ list asOrderedCollection |
|
1390 | 204 |
! |
205 |
||
206 |
hasChildrenFor:anItem |
|
207 |
"returns true if the physical directory contains at least |
|
208 |
one visible item otherwise false. |
|
209 |
" |
|
210 |
|block| |
|
211 |
||
212 |
anItem isDirectory ifFalse:[ |
|
213 |
^ false |
|
214 |
]. |
|
215 |
||
216 |
(block := self matchBlockFor:anItem) isNil ifTrue:[ |
|
217 |
block := [:aFilename :isDirectory| true ] |
|
218 |
]. |
|
219 |
^ DirectoryContents directoryNamed:(anItem fileName) detect:block |
|
220 |
! |
|
221 |
||
222 |
iconFor:anItem |
|
223 |
"returns the icon for an item |
|
224 |
" |
|
1867 | 225 |
|fn key suff mimeType icn| |
1390 | 226 |
|
227 |
fn := anItem fileName. |
|
1867 | 228 |
icons isNil ifTrue:[ icons := self class icons ]. |
1390 | 229 |
|
230 |
fn isDirectory ifTrue:[ |
|
231 |
(fn isReadable and:[fn isExecutable]) ifTrue:[ |
|
232 |
key := fn isSymbolicLink ifTrue:[#directoryLink] |
|
233 |
ifFalse:[#directory] |
|
234 |
] ifFalse:[ |
|
235 |
key := #directoryLocked |
|
1867 | 236 |
]. |
237 |
^ icons at:key ifAbsent:nil |
|
1390 | 238 |
]. |
1867 | 239 |
|
240 |
fn isReadable ifFalse:[ ^ icons at:#fileLocked ifAbsent:nil ]. |
|
241 |
fn isSymbolicLink ifTrue:[ ^ icons at:#fileLink ifAbsent:nil ]. |
|
242 |
||
243 |
suff := fn suffix. |
|
244 |
||
245 |
(suff = 'bak' or:[suff = 'sav']) ifTrue:[ |
|
246 |
suff := fn withoutSuffix suffix. |
|
1390 | 247 |
]. |
248 |
||
1867 | 249 |
suff size > 0 ifTrue:[ |
250 |
( #( 'o' 'so' 'a' ) includes:suff) ifTrue:[ |
|
251 |
^ icons at:#executableFile ifAbsent:nil |
|
252 |
]. |
|
253 |
mimeType := MIMETypes mimeTypeForSuffix:suff. |
|
254 |
||
255 |
mimeType notNil ifTrue:[ |
|
256 |
(icn := icons at:mimeType ifAbsent:nil) notNil ifTrue:[^ icn]. |
|
257 |
||
258 |
(mimeType startsWith:'image/') ifTrue:[ |
|
259 |
^ icons at:#imageFile ifAbsent:nil |
|
260 |
]. |
|
261 |
]. |
|
262 |
]. |
|
263 |
||
264 |
fn isExecutableProgram ifTrue:[ |
|
265 |
^ icons at:#executableFile ifAbsent:nil |
|
266 |
]. |
|
267 |
^ icons at:#file ifAbsent:nil |
|
1390 | 268 |
! |
269 |
||
270 |
matchBlockFor:anItem |
|
271 |
"get the matchBlock - if non-nil, it controls which files are |
|
272 |
visible within the physical directory |
|
273 |
" |
|
274 |
^ matchBlock |
|
2095 | 275 |
! |
276 |
||
277 |
validateIcon:anIcon for:anItem |
|
278 |
^ anIcon |
|
1390 | 279 |
! ! |
280 |
||
1581 | 281 |
!HierarchicalFileList methodsFor:'searching'! |
282 |
||
283 |
detectItemFor:aPathOrFilename |
|
284 |
"make a filename visible |
|
285 |
" |
|
286 |
|file node p1 p2 sz| |
|
287 |
||
1582 | 288 |
aPathOrFilename isNil ifTrue:[^ nil]. |
1581 | 289 |
|
290 |
file := aPathOrFilename asFilename. |
|
291 |
||
292 |
file exists ifFalse:[ |
|
1582 | 293 |
^ nil |
1581 | 294 |
]. |
1582 | 295 |
(node := root) isNil ifTrue:[^ nil]. |
1581 | 296 |
|
297 |
p1 := node pathName. |
|
298 |
p2 := file pathName. |
|
299 |
||
1582 | 300 |
(p2 startsWith:p1) ifFalse:[^ nil]. |
1581 | 301 |
sz := 1 + p1 size. |
302 |
||
303 |
(p1 last == Filename separator) ifFalse:[ |
|
304 |
sz := sz + 1. |
|
305 |
]. |
|
306 |
||
1582 | 307 |
p2 size > sz ifFalse:[^ nil]. |
1581 | 308 |
|
309 |
p2 := Filename components:(p2 copyFrom:sz). |
|
310 |
||
311 |
p2 do:[:bn| |
|
312 |
node := node detect:[:el| el baseName = bn] ifNone:nil. |
|
313 |
node isNil ifTrue:[^ nil ]. |
|
314 |
]. |
|
315 |
^ node |
|
316 |
! ! |
|
317 |
||
1390 | 318 |
!HierarchicalFileList::File class methodsFor:'instance creation'! |
319 |
||
320 |
fileName:aFileName isDirectory:isDirectory |
|
321 |
"instance creation |
|
322 |
" |
|
323 |
|item| |
|
324 |
||
325 |
item := isDirectory ifTrue:[Directory new] ifFalse:[HierarchicalFileList::File new]. |
|
326 |
item fileName:aFileName. |
|
327 |
^ item |
|
328 |
||
329 |
! ! |
|
330 |
||
331 |
!HierarchicalFileList::File methodsFor:'accessing'! |
|
332 |
||
333 |
baseName |
|
334 |
"returns the baseName |
|
335 |
" |
|
336 |
^ baseName |
|
337 |
||
338 |
||
339 |
! |
|
340 |
||
341 |
children |
|
342 |
"always returns an empty list |
|
343 |
" |
|
344 |
^ #() |
|
345 |
! |
|
346 |
||
347 |
fileName |
|
348 |
"returns the fileName |
|
349 |
" |
|
350 |
^ fileName |
|
351 |
||
352 |
||
353 |
! |
|
354 |
||
355 |
fileName:fname |
|
356 |
"instance creation |
|
357 |
" |
|
358 |
fileName := fname. |
|
359 |
baseName := fname baseName. |
|
360 |
! |
|
361 |
||
362 |
icon |
|
363 |
"returns the icon key |
|
364 |
" |
|
365 |
|model| |
|
366 |
||
2095 | 367 |
model := self model. |
368 |
model ifNil:[^ nil]. |
|
369 |
||
1390 | 370 |
icon isNil ifTrue:[ |
2095 | 371 |
icon := model iconFor:self |
1390 | 372 |
]. |
2095 | 373 |
^ model validateIcon:icon for:self |
1390 | 374 |
! |
375 |
||
376 |
label |
|
377 |
"returns the printable name, the baseName |
|
378 |
" |
|
379 |
^ baseName |
|
380 |
||
381 |
||
382 |
! |
|
383 |
||
384 |
pathName |
|
385 |
"returns the pathName |
|
386 |
" |
|
387 |
^ fileName pathName |
|
388 |
! ! |
|
389 |
||
390 |
!HierarchicalFileList::File methodsFor:'accessing hierarchy'! |
|
391 |
||
392 |
recursiveExpand |
|
393 |
"redefined to expand |
|
394 |
" |
|
395 |
self expand |
|
396 |
||
397 |
||
398 |
! ! |
|
399 |
||
400 |
!HierarchicalFileList::File methodsFor:'invalidate'! |
|
401 |
||
402 |
invalidate |
|
403 |
"invalidate the contents |
|
404 |
" |
|
405 |
self invalidateRepairNow:false |
|
406 |
||
407 |
! |
|
408 |
||
409 |
invalidateRepairNow |
|
410 |
"invalidate the contents; repair now |
|
411 |
" |
|
412 |
self invalidateRepairNow:true |
|
413 |
||
414 |
! |
|
415 |
||
416 |
invalidateRepairNow:doRepair |
|
417 |
"invalidate the contents; dependent on the boolean |
|
418 |
do repair immediately |
|
419 |
" |
|
420 |
||
421 |
||
1866 | 422 |
! |
423 |
||
424 |
matchBlockChanged |
|
425 |
"called if the matchBlock changed |
|
426 |
" |
|
427 |
||
1390 | 428 |
! ! |
429 |
||
2127 | 430 |
!HierarchicalFileList::File methodsFor:'printing'! |
431 |
||
432 |
printString |
|
433 |
||
434 |
^ super printString, ' for: ', self fileName asString |
|
435 |
! ! |
|
436 |
||
1390 | 437 |
!HierarchicalFileList::File methodsFor:'queries'! |
438 |
||
439 |
hasChildren |
|
440 |
"always returns false |
|
441 |
" |
|
442 |
^ false |
|
443 |
! |
|
444 |
||
445 |
isDirectory |
|
446 |
"always returns false |
|
447 |
" |
|
448 |
^ false |
|
449 |
||
450 |
! ! |
|
451 |
||
452 |
!HierarchicalFileList::File::Directory methodsFor:'accessing'! |
|
453 |
||
454 |
children |
|
455 |
"returns the list of children |
|
456 |
" |
|
457 |
|model list| |
|
458 |
||
1867 | 459 |
children notNil ifTrue:[ |
460 |
^ children |
|
461 |
]. |
|
1390 | 462 |
|
1867 | 463 |
(model := self model) isNil ifTrue:[ |
464 |
"/ must reread later |
|
465 |
modificationTime := children := nil. |
|
466 |
^ nil |
|
467 |
]. |
|
1390 | 468 |
|
1867 | 469 |
children := #(). |
470 |
modificationTime := fileName modificationTime. |
|
471 |
list := model childrenFor:self. |
|
472 |
||
473 |
list size ~~ 0 ifTrue:[ |
|
474 |
list do:[:aChild| aChild parent:self]. |
|
475 |
children := list. |
|
1390 | 476 |
]. |
477 |
^ children |
|
478 |
! |
|
479 |
||
480 |
icon |
|
481 |
"returns the icon |
|
482 |
" |
|
483 |
(isExpanded and:[children size ~~ 0]) ifTrue:[ |
|
484 |
^ nil |
|
485 |
]. |
|
486 |
^ super icon |
|
487 |
! ! |
|
488 |
||
2104
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
489 |
!HierarchicalFileList::File::Directory methodsFor:'accessing-hierarchy'! |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
490 |
|
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
491 |
expand |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
492 |
"expand children; must redefine to raise a notification |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
493 |
if children are not yet initialized and after initialization empty. |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
494 |
" |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
495 |
|notInit| |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
496 |
|
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
497 |
notInit := children isNil. |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
498 |
super expand. |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
499 |
|
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
500 |
notInit ifTrue:[ |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
501 |
(children notNil and:[children isEmpty]) ifTrue:[ |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
502 |
"/ no children exists |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
503 |
"/ indicator +/- has changed to unexistant |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
504 |
self changed:#redraw |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
505 |
] |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
506 |
]. |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
507 |
! ! |
327f2f77ec12
support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents:
2095
diff
changeset
|
508 |
|
1390 | 509 |
!HierarchicalFileList::File::Directory methodsFor:'queries'! |
510 |
||
511 |
hasChildren |
|
512 |
"returns true if children exists |
|
513 |
" |
|
514 |
^ children isNil or:[children notEmpty] |
|
515 |
! |
|
516 |
||
517 |
isDirectory |
|
518 |
"always returns true |
|
519 |
" |
|
520 |
^ true |
|
521 |
||
522 |
||
523 |
! ! |
|
524 |
||
525 |
!HierarchicalFileList::File::Directory methodsFor:'validation'! |
|
526 |
||
527 |
invalidateRepairNow:doRepair |
|
528 |
"invalidate contents |
|
529 |
" |
|
530 |
modificationTime := nil. |
|
531 |
||
532 |
doRepair ifTrue:[ |
|
533 |
self monitoringCycle |
|
534 |
] ifFalse:[ |
|
535 |
(isExpanded or:[children size == 0]) ifFalse:[ |
|
536 |
children := nil |
|
537 |
] |
|
538 |
]. |
|
539 |
||
540 |
! |
|
541 |
||
1866 | 542 |
matchBlockChanged |
543 |
"called if the matchBlock changed |
|
544 |
" |
|
545 |
modificationTime := nil. |
|
546 |
||
547 |
isExpanded ifFalse:[ |
|
548 |
children := nil. |
|
1867 | 549 |
] ifTrue:[ |
550 |
self monitoringCycle. |
|
1866 | 551 |
|
1867 | 552 |
children size ~~ 0 ifTrue:[ |
553 |
children do:[:aChild| aChild matchBlockChanged ] |
|
554 |
] |
|
1866 | 555 |
]. |
556 |
! |
|
557 |
||
1390 | 558 |
monitoringCycle |
559 |
"run monitoring cycle |
|
560 |
" |
|
561 |
|list size name modifyTime isNotEmpty wasNotEmpty model| |
|
562 |
||
563 |
modifyTime := fileName modificationTime. |
|
564 |
||
565 |
(modificationTime notNil and:[modifyTime <= modificationTime]) ifTrue:[ |
|
566 |
^ self |
|
567 |
]. |
|
568 |
model := self model. |
|
569 |
modificationTime := modifyTime. |
|
570 |
||
571 |
isExpanded ifFalse:[ |
|
572 |
||
573 |
"/ CHECK WHETHER CHILDREN EXIST( INDICATOR ) |
|
574 |
"/ ========================================= |
|
575 |
||
576 |
isNotEmpty := model hasChildrenFor:self. |
|
577 |
||
578 |
"/ check whether has changed durring evaluation |
|
579 |
(isExpanded or:[modificationTime ~= modifyTime]) ifFalse:[ |
|
580 |
wasNotEmpty := children isNil. |
|
581 |
children := isNotEmpty ifTrue:[nil] ifFalse:[#()]. |
|
582 |
||
583 |
wasNotEmpty ~~ isNotEmpty ifTrue:[ |
|
584 |
self changed |
|
585 |
] |
|
586 |
]. |
|
587 |
^ self |
|
588 |
||
589 |
]. |
|
590 |
||
591 |
"/ START MERGING( CONTENTS IS VISIBLE ) |
|
592 |
"/ ==================================== |
|
593 |
||
594 |
list := model childrenFor:self. |
|
595 |
||
596 |
list size == 0 ifTrue:[ "/ contents becomes empty |
|
597 |
^ self removeAll "/ clear contents |
|
598 |
]. |
|
599 |
(size := children size) == 0 ifTrue:[ "/ old contents was empty |
|
600 |
^ self addAll:list. "/ take over new contents |
|
601 |
]. |
|
602 |
||
603 |
size to:1 by:-1 do:[:anIndex| "/ remove invisible items |
|
604 |
name := (children at:anIndex) baseName. |
|
605 |
||
606 |
(list findFirst:[:i|i baseName = name]) == 0 ifTrue:[ |
|
607 |
self removeIndex:anIndex |
|
608 |
] |
|
609 |
]. |
|
610 |
||
611 |
list keysAndValuesDo:[:anIndex :anItem| "/ add new visible items |
|
612 |
name := anItem baseName. |
|
613 |
||
614 |
(children findFirst:[:i|i baseName = name]) == 0 ifTrue:[ |
|
615 |
self add:anItem beforeIndex:anIndex |
|
616 |
] |
|
617 |
]. |
|
618 |
! ! |
|
619 |
||
620 |
!HierarchicalFileList class methodsFor:'documentation'! |
|
621 |
||
622 |
version |
|
2130 | 623 |
^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalFileList.st,v 1.15 2002-08-09 09:43:51 ca Exp $' |
1390 | 624 |
! ! |