HierarchicalFileList.st
changeset 2475 1f90c55c4f78
parent 2457 d1505cba8e39
child 2479 82e797682bf9
equal deleted inserted replaced
2474:173a07117f56 2475:1f90c55c4f78
    33 	poolDictionaries:''
    33 	poolDictionaries:''
    34 	privateIn:HierarchicalFileList
    34 	privateIn:HierarchicalFileList
    35 !
    35 !
    36 
    36 
    37 HierarchicalFileList::HierarchicalFileItem subclass:#Directory
    37 HierarchicalFileList::HierarchicalFileItem subclass:#Directory
    38 	instanceVariableNames:'modificationTime fetchOperation makeIconGray'
    38 	instanceVariableNames:'modificationTime makeIconGray quickChildrenInfo'
    39 	classVariableNames:''
    39 	classVariableNames:'StateUnknown StateHasChildren StateHasNoChildren StateFetching'
    40 	poolDictionaries:''
    40 	poolDictionaries:''
    41 	privateIn:HierarchicalFileList
    41 	privateIn:HierarchicalFileList
    42 !
    42 !
    43 
    43 
    44 HierarchicalFileList::Directory subclass:#RemoteDirectory
    44 HierarchicalFileList::Directory subclass:#RemoteDirectory
   220 
   220 
   221     changeToParent ifTrue:[
   221     changeToParent ifTrue:[
   222         index := children findFirst:[:el| el fileName = oldDir ].
   222         index := children findFirst:[:el| el fileName = oldDir ].
   223         index ~~ 0 ifTrue:[ newRoot at:index put:oldRoot ].
   223         index ~~ 0 ifTrue:[ newRoot at:index put:oldRoot ].
   224     ].
   224     ].
   225     doExpand ifTrue:[ newRoot expand ].
   225     doExpand ifTrue:[ newRoot enforcedExpand ].
   226 !
   226 !
   227 
   227 
   228 root:aRoot
   228 root:aRoot
   229     "stop update-task
   229     "stop update-task
   230     "
   230     "
   470              and:[indicatorList size ~~ 0]      "/ nothing to do
   470              and:[indicatorList size ~~ 0]      "/ nothing to do
   471             ) ifTrue:[
   471             ) ifTrue:[
   472                 item := indicatorList removeFirst.
   472                 item := indicatorList removeFirst.
   473 
   473 
   474                 (self includesIdentical:item) ifFalse:[
   474                 (self includesIdentical:item) ifFalse:[
   475                     "/ no longer visible
   475                     "/ item is no longer visible
   476                     item resetFetchIndicator.
   476                     item resetFetchIndicator.
   477                     item := nil
   477                     item := nil
   478                 ]
   478                 ]
   479             ] ifFalse:[
   479             ] ifFalse:[
   480                 item := indicatorTask := task := nil
   480                 item := indicatorTask := task := nil
   781                                             #hasChildren    registered in list to be updated for indication
   781                                             #hasChildren    registered in list to be updated for indication
   782                                             #hasNoChildren  has children but children list might be nil (remote)
   782                                             #hasNoChildren  has children but children list might be nil (remote)
   783 "
   783 "
   784 ! !
   784 ! !
   785 
   785 
       
   786 !HierarchicalFileList::Directory class methodsFor:'initialization'!
       
   787 
       
   788 initialize
       
   789     StateUnknown := nil.
       
   790     StateHasChildren := #hasChildren.
       
   791     StateHasNoChildren := #hasNoChildren.
       
   792     StateFetching := #fetching
       
   793 
       
   794     "
       
   795      self initialize
       
   796     "
       
   797 ! !
       
   798 
   786 !HierarchicalFileList::Directory methodsFor:'accessing'!
   799 !HierarchicalFileList::Directory methodsFor:'accessing'!
   787 
   800 
   788 children
   801 children
   789     "returns the list of children
   802     "returns the list of children
   790     "
   803     "
   799         children isNil ifTrue:[ self readChildren ].
   812         children isNil ifTrue:[ self readChildren ].
   800     ].
   813     ].
   801     ^ children
   814     ^ children
   802 !
   815 !
   803 
   816 
   804 flushChildren
       
   805     "flush the children because node not visible ....
       
   806     "
       
   807     children notNil ifTrue:[
       
   808         "keep hasChildren information
       
   809         "
       
   810         children size ~~ 0 ifTrue:[ fetchOperation := #hasChildren ]
       
   811                           ifFalse:[ fetchOperation := #hasNoChildren ].
       
   812         children := nil.
       
   813     ].
       
   814 !
       
   815 
       
   816 icon
   817 icon
   817     "returns the icon key
   818     "returns the icon
   818     "
   819     "
       
   820 
       
   821     |nameKey|
       
   822 
   819     isExpanded ifTrue:[
   823     isExpanded ifTrue:[
       
   824         (makeIconGray == true) ifTrue:[
       
   825             nameKey := #directoryOpenGray
       
   826         ] ifFalse:[
       
   827             nameKey := #directoryOpen
       
   828         ]
       
   829     ] ifFalse:[
   820         makeIconGray == true ifTrue:[
   830         makeIconGray == true ifTrue:[
   821             ^ FileBrowser iconForKeyMatching:#directoryOpenGray
   831             nameKey := #directoryGray
   822         ].
   832         ]
   823         ^ FileBrowser iconForKeyMatching:#directoryOpen
   833     ].
   824     ].
   834 
   825     makeIconGray == true ifTrue:[
   835     nameKey notNil ifTrue:[
   826         ^ FileBrowser iconForKeyMatching:#directoryGray
   836         ^ FileBrowser iconForKeyMatching:nameKey
   827     ].
   837     ].
       
   838 
   828     icon isNil ifTrue:[
   839     icon isNil ifTrue:[
   829         ^ super icon
   840         ^ super icon
   830     ].
   841     ].
   831     ^ icon
   842     ^ icon
   832 !
   843 !
   841     ].
   852     ].
   842     ^ contentsItem fileName baseName
   853     ^ contentsItem fileName baseName
   843 !
   854 !
   844 
   855 
   845 makeIconGray:something
   856 makeIconGray:something
   846     "set the value of the instance variable 'makeIconGray' (automatically generated)"
   857     "set/clear the flag which enforces the icon to be shown in grey"
   847 
   858 
   848     makeIconGray := something.
   859     makeIconGray := something.
   849 !
   860 !
   850 
   861 
   851 modificationTime:something
   862 modificationTime:something
   857 readChildren
   868 readChildren
   858     "reads the list of children
   869     "reads the list of children
   859     "
   870     "
   860     |model list hadChildren hasChildren|
   871     |model list hadChildren hasChildren|
   861 
   872 
       
   873     self forgetAboutChildren.
       
   874 
   862     model := self model.
   875     model := self model.
   863 
       
   864     model isNil ifTrue:[
   876     model isNil ifTrue:[
   865         "/ must reread later
   877         "/ must reread later
   866         fetchOperation := modificationTime := children := nil.
   878         modificationTime := children := nil.
   867       ^ nil
   879         ^ nil
   868     ].
   880     ].
   869 
   881 
   870     hadChildren := children size ~~ 0.
   882     hadChildren := children size ~~ 0.
   871 
   883 
   872     "/ set to suppress reading of children
   884     "/ set to suppress reading of children
   873     children := #().
   885     children := #().
   874     fetchOperation   := nil.
       
   875     modificationTime := self fileName modificationTime.
   886     modificationTime := self fileName modificationTime.
   876     model stopIndicatorValidationFor:self.
   887     model stopIndicatorValidationFor:self.
   877 
   888 
   878     list := model childrenFor:self.
   889     list := model childrenFor:self.
   879 
   890 
   924 !HierarchicalFileList::Directory methodsFor:'fetching'!
   935 !HierarchicalFileList::Directory methodsFor:'fetching'!
   925 
   936 
   926 basicFetchIndicator
   937 basicFetchIndicator
   927     |hasChildren|
   938     |hasChildren|
   928 
   939 
   929     hasChildren := DirectoryContents directoryNamed:self fileName detect:(self model matchBlock).
   940     hasChildren := DirectoryContents directoryNamed:(self fileName) detect:(self model matchBlock).
   930     hasChildren ifTrue:[
   941     self knownToHaveChildren:hasChildren.
   931         fetchOperation := #hasChildren
   942     children notNil ifTrue:[self halt].
   932     ] ifFalse:[
   943 
   933         fetchOperation := #hasNoChildren
       
   934     ].
       
   935     children isNil ifTrue:[
   944     children isNil ifTrue:[
   936         "setup modification time to suppress monitorCycle
   945         "setup modification time to suppress monitorCycle
   937         "
   946         "
   938         modificationTime := self fileName modificationTime.
   947         modificationTime := self fileName modificationTime.
   939     ].
   948     ].
   940 !
   949 !
   941 
   950 
   942 fetchIndicator
   951 fetchIndicator
   943     "fetch the indicator value which indicates whether children exists or not
   952     "fetch the indicator value which indicates whether children exist or not.
   944      called by the list
   953      Called by the lists update process.
   945     "
   954     "
   946     children notNil ifTrue:[
   955     children notNil ifTrue:[
   947         "/ children already read
   956         "/ children already read
   948         fetchOperation := nil.
   957         self forgetAboutChildren.
   949       ^ self
       
   950     ].
       
   951 
       
   952     fetchOperation ~~ #fetching ifTrue:[
       
   953         "/ children will be updated ....
       
   954         ^ self
   958         ^ self
   955     ].
   959     ].
       
   960 
       
   961     self isFetchingChildrenInfo ifFalse:[
       
   962         "/ children will be updated in a second....
       
   963         ^ self
       
   964     ].
   956     "/ suppress restart of fetchIndicator
   965     "/ suppress restart of fetchIndicator
   957 
   966 
   958     self basicFetchIndicator.
   967     self basicFetchIndicator.
   959 
   968 
       
   969     children notNil ifTrue:[self halt].
       
   970 
   960     children notNil ifTrue:[
   971     children notNil ifTrue:[
   961         fetchOperation := nil.
   972         self forgetAboutChildren.
   962         children notEmpty ifTrue:[ self changed:#redraw ].
   973         children notEmpty ifTrue:[ self changed:#redraw ].
   963     ] ifFalse:[
   974     ] ifFalse:[
   964         "/ is a remote or very slow file system
   975         "/ is a remote or very slow file system
   965         fetchOperation == #hasChildren ifTrue:[
   976         self isKnownToHaveChildren ifTrue:[
   966             self changed:#redraw
   977             self changed:#redraw
   967         ].
   978         ].
   968     ].
   979     ].
   969 !
   980 !
   970 
   981 
   971 resetFetchIndicator
   982 resetFetchIndicator
   972     "update indication cycle has deregistered the item
   983     "update indication cycle has deregistered the item
   973     "
   984     "
   974     fetchOperation := nil.
   985 
       
   986     self forgetAboutChildren.
       
   987 ! !
       
   988 
       
   989 !HierarchicalFileList::Directory methodsFor:'private'!
       
   990 
       
   991 flushChildren
       
   992     "flush the children because the node is going to be invisible.
       
   993     "
       
   994     children notNil ifTrue:[
       
   995         self knownToHaveChildren:(children size ~~ 0).
       
   996         children := nil.
       
   997     ].
       
   998 ! !
       
   999 
       
  1000 !HierarchicalFileList::Directory methodsFor:'private - quick children info'!
       
  1001 
       
  1002 forgetAboutChildren
       
  1003     quickChildrenInfo := StateUnknown
       
  1004 !
       
  1005 
       
  1006 isChildrenInfoValid
       
  1007     ^ quickChildrenInfo ~~ StateUnknown and:[quickChildrenInfo ~~ StateFetching]
       
  1008 !
       
  1009 
       
  1010 isFetchingChildrenInfo
       
  1011     ^ quickChildrenInfo == StateFetching
       
  1012 !
       
  1013 
       
  1014 isKnownToHaveChildren
       
  1015     ^ quickChildrenInfo == StateHasChildren
       
  1016 !
       
  1017 
       
  1018 isKnownToHaveNoChildren
       
  1019     ^ quickChildrenInfo == StateHasNoChildren
       
  1020 !
       
  1021 
       
  1022 knownToHaveChildren:aBoolean
       
  1023     aBoolean ifTrue:[
       
  1024         quickChildrenInfo := StateHasChildren.
       
  1025     ] ifFalse:[
       
  1026         quickChildrenInfo := StateHasNoChildren.
       
  1027     ].
       
  1028 !
       
  1029 
       
  1030 setFetchingChildrenInfo
       
  1031     quickChildrenInfo := StateFetching
   975 ! !
  1032 ! !
   976 
  1033 
   977 !HierarchicalFileList::Directory methodsFor:'queries'!
  1034 !HierarchicalFileList::Directory methodsFor:'queries'!
   978 
  1035 
       
  1036 canExpand
       
  1037     super canExpand ifTrue:[^ true].
       
  1038     "/ in case we are fetching the subdirectory
       
  1039     self isFetchingChildrenInfo ifTrue:[
       
  1040 self halt.  
       
  1041     ].
       
  1042     
       
  1043     ^ false
       
  1044 !
       
  1045 
   979 hasChildren
  1046 hasChildren
   980     "returns true if children exists
  1047     "returns true if children exist
   981     "
  1048     "
   982     |model|
  1049     |model|
   983 
  1050 
   984     children notNil ifTrue:[
  1051     children notNil ifTrue:[
   985         fetchOperation := nil.
  1052         self forgetAboutChildren.
   986       ^ children size ~~ 0
  1053         ^ children size ~~ 0
   987     ].
  1054     ].
   988 
  1055 
   989     fetchOperation notNil ifTrue:[
  1056     self isFetchingChildrenInfo ifTrue:[
   990         ^ fetchOperation == #hasChildren
  1057         ^ false.
       
  1058     ].
       
  1059     self isChildrenInfoValid ifTrue:[
       
  1060         ^ self isKnownToHaveChildren
   991     ].
  1061     ].
   992 
  1062 
   993     model := self model.
  1063     model := self model.
   994 
  1064 
   995     model notNil ifTrue:[
  1065     model notNil ifTrue:[
   996         fetchOperation := #fetching.
  1066         self setFetchingChildrenInfo.
   997         model startIndicatorValidationFor:self.
  1067         model startIndicatorValidationFor:self.
   998     ] ifFalse:[
  1068     ] ifFalse:[
   999         self error:'should not happen' mayProceed:true.
  1069         self error:'should not happen' mayProceed:true.
  1000         fetchOperation := nil
  1070         self forgetAboutChildren
  1001     ].
  1071     ].
  1002     ^ children size ~~ 0
  1072     children size ~~ 0 ifTrue:[self halt. ^ true].
       
  1073     ^ false
  1003 !
  1074 !
  1004 
  1075 
  1005 isDirectory
  1076 isDirectory
  1006     "always returns true
  1077     "always returns true
  1007     "
  1078     "
  1013 !HierarchicalFileList::Directory methodsFor:'validation'!
  1084 !HierarchicalFileList::Directory methodsFor:'validation'!
  1014 
  1085 
  1015 invalidateRepairNow:doRepair
  1086 invalidateRepairNow:doRepair
  1016     "invalidate contents
  1087     "invalidate contents
  1017     "
  1088     "
  1018     fetchOperation := modificationTime := nil.
  1089     modificationTime := nil.
       
  1090     self forgetAboutChildren
  1019 
  1091 
  1020     isExpanded ifFalse:[
  1092     isExpanded ifFalse:[
  1021         children := nil
  1093         children := nil
  1022     ] ifTrue:[
  1094     ] ifTrue:[
  1023         doRepair ifTrue:[
  1095         doRepair ifTrue:[
  1035     "called if the matchBlock changed
  1107     "called if the matchBlock changed
  1036     "
  1108     "
  1037     modificationTime := nil.
  1109     modificationTime := nil.
  1038 
  1110 
  1039     isExpanded ifFalse:[
  1111     isExpanded ifFalse:[
  1040         fetchOperation := children := nil.
  1112         children := nil.
       
  1113         self forgetAboutChildren
  1041     ] ifTrue:[
  1114     ] ifTrue:[
  1042         self monitoringCycle.
  1115         self monitoringCycle.
  1043 
  1116 
  1044         children size ~~ 0 ifTrue:[
  1117         children size ~~ 0 ifTrue:[
  1045             children do:[:aChild| aChild matchBlockChanged ]
  1118             children do:[:aChild| aChild matchBlockChanged ]
  1062     children notNil ifTrue:[
  1135     children notNil ifTrue:[
  1063         timeChanged ifFalse:[
  1136         timeChanged ifFalse:[
  1064             ^ self
  1137             ^ self
  1065         ].
  1138         ].
  1066     ].
  1139     ].
       
  1140 
  1067     DirectoryContents flushCachedDirectoryFor:(self fileName).
  1141     DirectoryContents flushCachedDirectoryFor:(self fileName).
  1068     isExpanded ifFalse:[
  1142     isExpanded ifFalse:[
  1069         timeChanged ifTrue:[
  1143         timeChanged ifTrue:[
  1070             fetchOperation := children := nil.
  1144             children := nil.
       
  1145             self forgetAboutChildren.
  1071             self changed:#redraw.
  1146             self changed:#redraw.
  1072         ].
  1147         ].
  1073         ^ self
  1148         ^ self
  1074     ].
  1149     ].
       
  1150 
       
  1151     children isNil ifTrue:[ children := #() ].         "/ disable update during merge
       
  1152 
       
  1153     self forgetAboutChildren.
  1075     model := self model.
  1154     model := self model.
  1076     children isNil ifTrue:[ children := #() ].         "/ disable update during merge
  1155     mergedList := model childrenFor:self.
  1077 
       
  1078 
       
  1079     fetchOperation := nil.
       
  1080     mergedList     := model childrenFor:self.
       
  1081 
  1156 
  1082     mergedList size == 0 ifTrue:[
  1157     mergedList size == 0 ifTrue:[
  1083         self removeAll.
  1158         self removeAll.
  1084         ^ self
  1159         ^ self
  1085     ].
  1160     ].
  1086 
  1161 
  1087     size := children size.
  1162     size := children size.
  1088 
       
  1089     size == 0 ifTrue:[
  1163     size == 0 ifTrue:[
  1090         self addAll:mergedList.
  1164         self addAll:mergedList.
  1091         ^ self
  1165         ^ self
  1092     ].
  1166     ].
  1093 
  1167 
  1137 
  1211 
  1138 hasChildren
  1212 hasChildren
  1139     "returns true if children exists
  1213     "returns true if children exists
  1140     "
  1214     "
  1141     children notNil ifTrue:[
  1215     children notNil ifTrue:[
  1142         fetchOperation := nil.
  1216         self forgetAboutChildren.
  1143         ^ children size ~~ 0
  1217         ^ children size ~~ 0
  1144     ].
  1218     ].
  1145     fetchOperation := #hasChildren.
  1219 
  1146   ^ true
  1220     "/ assume that there are children;
       
  1221     "/ this might be wrong and clicking on the expand-icon
       
  1222     "/ will then not perform an expand, but remove the can-expand indicator.
       
  1223     self knownToHaveChildren:true.
       
  1224     ^ true
  1147 !
  1225 !
  1148 
  1226 
  1149 isRemoteDirectory
  1227 isRemoteDirectory
  1150     ^ true
  1228     ^ true
  1151 ! !
  1229 ! !
  1152 
  1230 
  1153 !HierarchicalFileList class methodsFor:'documentation'!
  1231 !HierarchicalFileList class methodsFor:'documentation'!
  1154 
  1232 
  1155 version
  1233 version
  1156     ^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalFileList.st,v 1.43 2003-03-03 10:21:56 penk Exp $'
  1234     ^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalFileList.st,v 1.44 2003-04-08 13:38:08 cg Exp $'
  1157 ! !
  1235 ! !
       
  1236 
       
  1237 HierarchicalFileList::Directory initialize!