FSelList.st
changeset 350 e3512322cb87
parent 338 9cbc51998a23
child 467 ecf956d44135
equal deleted inserted replaced
349:e4382398fc59 350:e3512322cb87
   527 !
   527 !
   528 
   528 
   529 updateList
   529 updateList
   530     "set the lists contents to the filenames in the directory"
   530     "set the lists contents to the filenames in the directory"
   531 
   531 
   532     |oldCursor files newList index path obsolete|
   532     |oldCursor files newList index path obsolete matching patternList|
   533 
   533 
   534     directory isNil ifTrue:[
   534     directory isNil ifTrue:[
   535 	super list:nil.
   535         super list:nil.
   536 	files :=  newList := fileTypes := nil.
   536         files :=  newList := fileTypes := nil.
   537 	^ self
   537         ^ self
   538     ].
   538     ].
   539 
   539 
   540     oldCursor := cursor.
   540     oldCursor := cursor.
   541     self cursor:(Cursor read).
   541     self cursor:(Cursor read).
   542 
   542 
   544      if the directory-id changed, MUST update.
   544      if the directory-id changed, MUST update.
   545      (can happen after a restart, when a file is no longer
   545      (can happen after a restart, when a file is no longer
   546       there, has moved or is NFS-mounted differently)
   546       there, has moved or is NFS-mounted differently)
   547     "
   547     "
   548     obsolete := directoryId ~~ directory id
   548     obsolete := directoryId ~~ directory id
   549 		or:[directoryName ~= directory pathName
   549                 or:[directoryName ~= directory pathName
   550 		or:[timeStamp notNil
   550                 or:[timeStamp notNil
   551 		    and:[directory timeOfLastChange > timeStamp]]].
   551                     and:[directory timeOfLastChange > timeStamp]]].
   552 
   552 
   553     obsolete ifTrue:[
   553     obsolete ifTrue:[
   554 	timeStamp := directory timeOfLastChange.
   554         timeStamp := directory timeOfLastChange.
   555 	directoryId := directory id.
   555         directoryId := directory id.
   556 	directoryName := directory pathName.
   556         directoryName := directory pathName.
   557 	directoryContents := directory asStringCollection sort.
   557         directoryContents := directory asStringCollection sort.
   558 	directoryFileTypes := OrderedCollection new.
   558         directoryFileTypes := OrderedCollection new.
   559 	directoryContents do:[:name | directoryFileTypes add:(directory typeOf:name)].
   559         directoryContents do:[:name | directoryFileTypes add:(directory typeOf:name)].
   560     ].
   560     ].
   561 
   561 
   562     files := directoryContents.
   562     files := directoryContents.
   563     newList := OrderedCollection new.
   563     newList := OrderedCollection new.
   564     fileTypes := OrderedCollection new.
   564     fileTypes := OrderedCollection new.
   565     index := 1.
   565     index := 1.
   566 
   566 
   567     path := directory pathName , Filename separator asString.
   567     path := directory pathName , Filename separator asString.
   568     files do:[:name |
   568     files do:[:name |
   569 	|type|
   569         |type|
   570 
   570 
   571 	(matchBlock isNil or:[matchBlock value:(path , name)]) ifTrue:[
   571         (matchBlock isNil or:[matchBlock value:(path , name)]) ifTrue:[
   572 	    type := directoryFileTypes at:index.
   572             type := directoryFileTypes at:index.
   573 	    type == #directory ifTrue:[
   573             type == #directory ifTrue:[
   574 		ignoreDirectories ifFalse:[
   574                 ignoreDirectories ifFalse:[
   575 		    name = '..' ifTrue:[
   575                     name = '..' ifTrue:[
   576 			ignoreParentDirectory ifFalse:[
   576                         ignoreParentDirectory ifFalse:[
   577 			    newList add:name.
   577                             newList add:name.
   578 			    fileTypes add:type
   578                             fileTypes add:type
   579 			]
   579                         ]
   580 		    ] ifFalse:[
   580                     ] ifFalse:[
   581 			name = '.' ifTrue:[
   581                         name = '.' ifTrue:[
   582 			    "ignore"
   582                             "ignore"
   583 			] ifFalse:[
   583                         ] ifFalse:[
   584 			    newList add:(name ", ' ...'").
   584                             newList add:(name ", ' ...'").
   585 			    fileTypes add:type
   585                             fileTypes add:type
   586 			]
   586                         ]
   587 		    ]
   587                     ]
   588 		]
   588                 ]
   589 	    ] ifFalse:[
   589             ] ifFalse:[
   590 		(pattern isNil 
   590                 matching := true.
   591 		or:[pattern isEmpty 
   591 
   592 		or:[pattern = '*' 
   592                 (pattern isNil 
   593 		or:[pattern match:name]]]) ifTrue:[
   593                 or:[pattern isEmpty]) ifFalse:[
   594 		    newList add:name.
   594                     pattern = '*' ifFalse:[
   595 		    fileTypes add:type
   595                         (pattern includes:$;) ifTrue:[
   596 		]
   596                             patternList := pattern asCollectionOfSubstringsSeparatedBy:$;.
   597 	    ].
   597                             matching := (patternList findFirst:[:subPattern | subPattern match:name]) ~~ 0.
   598 	].
   598                         ] ifFalse:[
   599 	index := index + 1
   599                             matching := pattern match:name
       
   600                         ]
       
   601                     ]
       
   602                 ].
       
   603                                 
       
   604                 matching ifTrue:[
       
   605                     newList add:name.
       
   606                     fileTypes add:type
       
   607                 ]
       
   608             ].
       
   609         ].
       
   610         index := index + 1
   600     ].
   611     ].
   601     super list:newList.
   612     super list:newList.
   602 
   613 
   603     self cursor:oldCursor.
   614     self cursor:oldCursor.
   604 
       
   605 !
   615 !
   606 
   616 
   607 visibleLineNeedsSpecialCare:visLineNr
   617 visibleLineNeedsSpecialCare:visLineNr
   608     |l|
   618     |l|
   609 
   619 
   639 ! !
   649 ! !
   640 
   650 
   641 !FileSelectionList class methodsFor:'documentation'!
   651 !FileSelectionList class methodsFor:'documentation'!
   642 
   652 
   643 version
   653 version
   644     ^ '$Header: /cvs/stx/stx/libwidg/Attic/FSelList.st,v 1.23 1996-02-09 12:48:15 ca Exp $'
   654     ^ '$Header: /cvs/stx/stx/libwidg/Attic/FSelList.st,v 1.24 1996-02-10 09:32:49 ca Exp $'
   645 ! !
   655 ! !