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