FileSelectionBox.st
changeset 12 1c8e8c53e8cf
parent 7 15a9291b9bd0
child 21 9ef599238fea
--- a/FileSelectionBox.st	Thu Dec 16 12:02:42 1993 +0100
+++ b/FileSelectionBox.st	Thu Dec 16 12:04:09 1993 +0100
@@ -11,8 +11,7 @@
 "
 
 ListSelectionBox subclass:#FileSelectionBox
-       instanceVariableNames:'patternField directory timeStamp directoryId
-                              directoryContents directoryFileTypes'
+       instanceVariableNames:'patternField'
        classVariableNames:''
        poolDictionaries:''
        category:'Views-Interactors'
@@ -23,7 +22,7 @@
 COPYRIGHT (c) 1990 by Claus Gittinger
               All Rights Reserved
 
-$Header: /cvs/stx/stx/libwidg/FileSelectionBox.st,v 1.4 1993-12-11 01:44:10 claus Exp $
+$Header: /cvs/stx/stx/libwidg/FileSelectionBox.st,v 1.5 1993-12-16 11:02:38 claus Exp $
 written Jan 90 by claus
 '!
 
@@ -31,19 +30,27 @@
 
 documentation
 "
-this class implements file selection boxes. They show a list of
+this class implements file selection boxes. Instances show a list of
 files, and perform an action block with the selected pathname as
 argument when ok is clicked.
+
 There is an optional PatternField, which shows itself when a pattern
 is defined. If there is such a pattern, only files matching the pattern
 will be shown in the list (and directories).
 "
 ! !
 
+!FileSelectionBox class methodsFor:'defaults'!
+
+listViewType
+    "return the type of listView - using a FileSelectionList here"
+
+    ^ FileSelectionList
+! !
+
 !FileSelectionBox methodsFor:'initialization'!
 
 initialize
-    directory := FileDirectory currentDirectory.
     super initialize.
 
     labelField extent:(0.7 @ labelField height).
@@ -58,127 +65,47 @@
     patternField leaveAction:[:p | self updateList].
     patternField hidden:true.
 
-    "selections in list get forwarded to enterfield if not a directory;
-     otherwise directory is changed"
-
-    selectionList action:[:lineNr |
+    selectionList action:[:line |
         |entry|
 
         entry := selectionList selectionValue.
-        (entry endsWith:' ...') ifTrue:[
-            entry := entry copyTo:(entry size - 4).
-        ].
-        ((directory typeOf:entry) == #directory) ifTrue:[
-            (directory isReadable:entry) ifFalse:[
-                self warn:(resources string:'not allowed to read directory %1' with:entry)
-            ] ifTrue:[
-                (directory isExecutable:entry) ifFalse:[
-                    self warn:(resources string:'not allowed to change to directory %1' with:entry)
-                ] ifTrue:[
-                    self directory:(directory pathName , Filename separator asString , entry)
-                ]
-            ].
-        ] ifFalse:[
-            enterField contents:entry
-        ]
-    ]
+        enterField contents:entry
+    ].
+    selectionList doubleClickAction:[:line |
+        |entry|
+
+        entry := selectionList selectionValue.
+        enterField contents:entry.
+        self okPressed
+    ].
 
     "FileSelectionBox new show"
-!
-
-reinitialize
-    directory := FileDirectory currentDirectory.
-    super reinitialize
 ! !
 
 !FileSelectionBox methodsFor:'accessing'!
 
 directory:nameOrDirectory
-    "set the lists contents to the filenames in the directory name"
-
-    |oldPath name|
+    "change the directory shown in the list"
 
-    (nameOrDirectory isKindOf:String) ifTrue:[
-        name := nameOrDirectory
-    ] ifFalse:[
-        name := nameOrDirectory pathName
-    ].
-    oldPath := directory pathName.
-    directory pathName:name.
-    (directory pathName = oldPath) ifFalse:[
-        self updateList
-    ]
+    selectionList directory:nameOrDirectory
 !
 
 pattern:aPattern
     "set the pattern - this enables the PatternField."
 
     patternField initialText:aPattern.
-    patternField hidden:false.
-    realized ifTrue:[
-        patternField realize.
-        self updateList
-    ].
-! !
-
-!FileSelectionBox methodsFor:'private'!
-
-updateList
-    "set the lists contents to the filenames in the directory"
-
-    |oldCursor oldListCursor files pattern newList index|
-
-    oldCursor := cursor.
-    oldListCursor := selectionList cursor.
-    self cursor:(Cursor read).
-    selectionList cursor:(Cursor read).
-    directoryId == directory id ifFalse:[
-        timeStamp := directory timeOfLastChange.
-        directoryId := directory id.
-        directoryContents := directory asText sort.
-        directoryFileTypes := OrderedCollection new.
-        directoryContents do:[:name | directoryFileTypes add:(directory typeOf:name)].
+    selectionList pattern:aPattern.
+    aPattern isNil ifTrue:[
+        patternField hidden:true.
+        realized ifTrue:[
+            patternField hide.
+        ]
+    ] ifFalse:[
+        patternField hidden:false.
+        realized ifTrue:[
+            patternField realize.
+        ].
     ].
-    files := directoryContents.
-    pattern := patternField contents.
-    newList := OrderedCollection new.
-    index := 1.
-    files do:[:name |
-        (directoryFileTypes at:index) == #directory ifTrue:[
-            name = '..' ifTrue:[
-                newList add:name
-            ] ifFalse:[
-                name = '.' ifTrue:[
-                ] ifFalse:[
-                    newList add:(name , ' ...')
-                ]
-            ]
-        ] ifFalse:[
-            (pattern isEmpty or:[pattern match:name]) ifTrue:[
-                newList add:name
-            ]
-        ].
-        index := index + 1
-    ].
-    self list:newList.
-    self cursor:oldCursor.
-    selectionList cursor:oldListCursor
-! !
-
-!FileSelectionBox methodsFor:'events'!
-
-show
-    "make the box visible; redefined to check if directory is still 
-     valid (using timestamp and inode numbers) - reread if not"
-
-    (timeStamp isNil 
-     or:[(directory timeOfLastChange > timeStamp) 
-     or:[(directoryId isNil)
-     or:[directoryId ~~ directory id]]]) ifTrue:[
-        directoryId := nil.
-        self updateList
-    ].
-    super show
 ! !
 
 !FileSelectionBox methodsFor:'user interaction'!
@@ -194,7 +121,7 @@
             (string startsWith:(Filename separator)) ifTrue:[
                 absPath := string
             ] ifFalse:[
-                absPath := directory pathName , Filename separator asString , string
+                absPath := selectionList directory pathName , Filename separator asString , string
             ].
             okAction value:absPath
         ]