FileSelectionItem.st
changeset 811 a688e8f11bc6
parent 786 bf1885e29419
child 844 0984af742b46
--- a/FileSelectionItem.st	Mon Mar 09 17:07:25 1998 +0100
+++ b/FileSelectionItem.st	Mon Mar 09 17:08:44 1998 +0100
@@ -157,6 +157,15 @@
   ^ children
 !
 
+fileName
+    "returns the fileName of node
+    "
+    ^ contents
+
+
+
+!
+
 icon
     "returns type of image to be drawn
     "
@@ -211,38 +220,36 @@
 !FileSelectionItem methodsFor:'accessing hierarchy'!
 
 collapse
-    "chech to release children
+    "check to release children
     "
+    self stopIndicatorValidation.
     hide := true.
 
-    children size ~~ 0 ifTrue:[
+    children notEmpty ifTrue:[
         children do:[:aChild|
-            aChild releaseCollapsedChildren ifFalse:[
-                ^ self
-            ]
+            aChild releaseCollapsedChildren ifFalse:[ ^ self ]
         ].
-        parent notNil ifTrue:[                  "/ not for root
-            readChildren     := true.
-            modificationTime := nil.
-            children := OrderedCollection new.
+        self canReleaseChildren ifTrue:[
+            self releaseChildren
         ]
     ]
+
 !
 
 collapseAll
     "release my childrens
     "
+    self stopIndicatorValidation.
     hide := true.
 
-    children size ~~ 0 ifTrue:[
-        parent isNil ifTrue:[
-            self allChildrenDo:[:aChild| aChild collapseAll ]
+    children notEmpty ifTrue:[
+        self canReleaseChildren ifTrue:[
+            self releaseChildren
         ] ifFalse:[
-            readChildren     := true.
-            modificationTime := nil.
-            children := OrderedCollection new.
+            children do:[:c| c releaseChildren ]
         ]
     ].
+
 ! !
 
 !FileSelectionItem methodsFor:'private'!
@@ -273,10 +280,56 @@
     "returns my match action
     "
     ^ matchAction
+!
+
+releaseChildren
+    "release my childrens without tests and deregistration from
+     update task
+    "
+    hide := true.
+    readChildren := true.
+    modificationTime := nil.
+    children := OrderedCollection new.
+
+
+!
+
+stopIndicatorValidation
+    "called to stop indicator validation on each child
+    "
+    |model|
+
+    (hide or:[children isEmpty]) ifFalse:[
+        (model := self model) notNil ifTrue:[
+            children do:[:c| c stopIndicatorValidation:model ].
+            model stopIndicatorValidationFor:children
+        ]
+    ]
+
+
+!
+
+stopIndicatorValidation:aModel
+    "called to stop indicator validation on each child
+    "
+    (hide or:[children isEmpty]) ifFalse:[
+        children do:[:c| c stopIndicatorValidation:aModel ].
+        aModel stopIndicatorValidationFor:children
+    ]
+
+
 ! !
 
 !FileSelectionItem methodsFor:'queries'!
 
+canReleaseChildren
+    "returns true if children could be released
+    "
+    ^ (parent notNil and:[parent parent notNil])
+
+
+!
+
 discardDirectories
     "returns true if children are not type of directory; could be
      reimplemented for speed in any subclass
@@ -299,6 +352,13 @@
 
 !
 
+hasValidIndicator
+    "returns true if indication flag is uptodate
+    "
+    ^ showIndicator notNil
+
+!
+
 isDirectory
     ^ isDirectory
 !
@@ -306,9 +366,9 @@
 releaseCollapsedChildren
     "release collapsed children
     "
-    |canCollapse|
+    |canCollapse model|
 
-    children size == 0 ifTrue:[
+    children isEmpty ifTrue:[
         ^ true
     ].
     canCollapse := true.
@@ -318,29 +378,52 @@
             canCollapse := false
         ]
     ].
+
     (canCollapse and:[self isExpandable]) ifTrue:[
-        parent notNil ifTrue:[                          "/ not the root directory
-            readChildren := true.
-            modificationTime := nil.
-            children := OrderedCollection new.
+        self canReleaseChildren ifTrue:[
+            self releaseChildren.
           ^ true.
         ]
     ].
     ^ false
+
+!
+
+setShowIndicator:aBool
+    "set indication; raise no change notification
+    "
+    showIndicator := aBool.
 !
 
 showIndicator
     "returns true if the node is a not empty directory
     "
+    |model|
+
     showIndicator isNil ifTrue:[
         (self imageType == #directoryLocked) ifTrue:[
             showIndicator := readChildren := false.
         ] ifFalse:[
-            showIndicator := DirectoryContents directoryNamed:contents detect:matchAction
+            (model := self model) notNil ifTrue:[
+                model startIndicatorValidationFor:self.
+            ].
+            ^ false
         ]
     ].
     ^ showIndicator
 
+
+!
+
+showIndicator:aBool
+    "indication might change; raise a change notification
+    "
+    self showIndicator ~~ aBool ifTrue:[
+        showIndicator := aBool.
+        self changed:#indication
+    ].
+
+
 ! !
 
 !FileSelectionItem methodsFor:'repair mechanism'!
@@ -352,11 +435,12 @@
         modificationTime < contents modificationTime ifTrue:[
             ^ true
         ].
-        (self discardDirectories or:[children size == 0]) ifFalse:[
+        (self discardDirectories or:[children isEmpty]) ifFalse:[
             children do:[:aChild| aChild hasObsoleteNodes ifTrue:[^ true]]
         ]
     ].
     ^ false
+
 !
 
 repairObsoleteNodes
@@ -382,6 +466,7 @@
             ].
         ].
         hasChanged ifTrue:[
+            self stopIndicatorValidation.
             children := list
         ]
     ] ifFalse:[
@@ -395,6 +480,7 @@
     ^ self shown ifTrue:[hasChanged]
                 ifFalse:[false]
 
+
 ! !
 
 !FileSelectionItem methodsFor:'update'!
@@ -439,20 +525,31 @@
     |list directory node|
 
     list := OrderedCollection new.
+    readChildren  := false.
+    showIndicator := false.
 
     self imageType == #directoryLocked ifFalse:[
-        directory := DirectoryContents directoryNamed:contents.
-        modificationTime := directory modificationTime.
+        Cursor wait showWhile:[
+            directory := DirectoryContents directoryNamed:contents.
 
-        directory contentsAndBaseNamesDo:[:f :n :d|
-            (matchAction value:f value:d) ifTrue:[
-                list add:(self class new fileName:f baseName:n parent:self isDirectory:d)
+            directory isNil ifTrue:[
+                self stopIndicatorValidation.
+                self releaseChildren.
+                imageType := #directoryLocked.
+            ] ifFalse:[
+                modificationTime := directory modificationTime.
+
+                directory contentsAndBaseNamesDo:[:f :n :d|
+                    (matchAction value:f value:d) ifTrue:[
+                        list add:(self class new fileName:f baseName:n parent:self isDirectory:d)
+                    ]
+                ].
+                showIndicator := list size ~~ 0.
             ]
         ]
     ].
-    readChildren  := false.
-    showIndicator := list size ~~ 0.
   ^ list
+
 ! !
 
 !FileSelectionItem::Directory class methodsFor:'documentation'!
@@ -505,5 +602,5 @@
 !FileSelectionItem class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/FileSelectionItem.st,v 1.8 1998-02-25 14:54:48 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/FileSelectionItem.st,v 1.9 1998-03-09 16:08:11 ca Exp $'
 ! !