FileBrowser.st
changeset 1156 f3df28086973
parent 1154 c02ebe91ba11
child 1157 667a57034e40
--- a/FileBrowser.st	Sat Apr 19 11:22:13 1997 +0200
+++ b/FileBrowser.st	Sat Apr 19 15:23:34 1997 +0200
@@ -349,23 +349,10 @@
     "toggle from long to short listing (and vice-versa)"
 
     showLongList := showLongList not.
-    showLongList ifTrue:[
-        false "self is3D" ifTrue:[
-            scrollView topInset:(tabRulerView superView height).
-            tabRulerView superView leftInset:(fileListView originRelativeTo:scrollView) x.
-        ] ifFalse:[
-            scrollView topInset:(tabRulerView height).
-            tabRulerView leftInset:(fileListView originRelativeTo:scrollView) x.
-        ].
-        tabRulerView hiddenTabs:#(1).
-        tabRulerView fixedTabs:#(1).
-    ] ifFalse:[
-        scrollView topInset:0
-    ].
-    tabSpec := nil.
+    self showOrHideTabView.
     self updateCurrentDirectory
 
-    "Modified: 28.3.1997 / 17:07:56 / cg"
+    "Modified: 19.4.1997 / 09:50:14 / cg"
 !
 
 changeDotFileVisibility
@@ -989,6 +976,27 @@
     ].
 
     "Modified: 14.11.1996 / 16:01:32 / cg"
+!
+
+showOrHideTabView
+    "depending on the showLongList setting, show or hde the tabSpec view"
+
+    showLongList ifTrue:[
+        false "self is3D" ifTrue:[
+            scrollView topInset:(tabRulerView superView height).
+            tabRulerView superView leftInset:(fileListView originRelativeTo:scrollView) x.
+        ] ifFalse:[
+            scrollView topInset:(tabRulerView height).
+            tabRulerView leftInset:(fileListView originRelativeTo:scrollView) x.
+        ].
+        tabRulerView hiddenTabs:#(1).
+        tabRulerView fixedTabs:#(1).
+    ] ifFalse:[
+        scrollView topInset:0
+    ].
+    tabSpec := nil.
+
+    "Created: 19.4.1997 / 09:50:02 / cg"
 ! !
 
 !FileBrowser methodsFor:'help '!
@@ -1191,20 +1199,26 @@
     fileListView delegate:self.
     fileListView menuHolder:self; menuPerformer:self; menuMessage:#fileListMenu.
     fileListView allowDrag:true.
-    fileListView dragObjectConverter:[:obj | |str o dir nm path idx|
+    fileListView dragObjectConverter:[:obj | 
+                                        |dir nm path idx|
+obj printCR.
                                         nm := obj theObject asString.
                                         idx := fileListView list indexOf:nm.
+idx printCR.
                                         idx == 0 ifTrue:[
                                             "/ cannot happen ...
                                             nil
                                         ] ifFalse:[
                                             nm := fileList at:idx.
+nm printCR.
                                             dir := currentDirectory pathName asFilename.
                                             path := dir constructString:nm.
+path printCR.
                                             DropObject newFile:path.
                                         ]
                                      ].
     tabRulerView leftInset:(fileListView originRelativeTo:scrollView) x.
+    self showOrHideTabView.
 
     v := self initializeSubViewIn:frame.
 
@@ -1218,7 +1232,7 @@
 
     "Modified: 6.9.1995 / 20:26:06 / claus"
     "Modified: 27.3.1997 / 11:04:31 / stefan"
-    "Modified: 18.4.1997 / 18:18:26 / cg"
+    "Modified: 19.4.1997 / 09:56:06 / cg"
 !
 
 initializeCommandViewIn:frame
@@ -1318,15 +1332,11 @@
     "destroy view and boxes"
 
     ObjectMemory removeDependent:self.
-    Processor removeTimedBlock:checkBlock.
-    listUpdateProcess notNil ifTrue:[
-        listUpdateProcess terminate.
-        listUpdateProcess := nil.
-    ].
+    self stopUpdateProcess.
     checkBlock := nil.
     super destroy
 
-    "Modified: 18.4.1997 / 13:05:14 / cg"
+    "Modified: 19.4.1997 / 13:51:48 / cg"
 !
 
 filterPatternChanged
@@ -1978,7 +1988,16 @@
 doRemove
     "remove the selected file(s) - no questions asked"
 
-    |ok msg dir|
+    |ok msg dir idx needUpdate toRemove updateRunning|
+
+    updateRunning := listUpdateProcess notNil.
+    self stopUpdateProcess.
+    toRemove := OrderedCollection new.
+
+    "/
+    "/ did the directory change in the meanwhile ?
+    "/
+    needUpdate := (currentDirectory timeOfLastChange > timeOfLastCheck).
 
     lockUpdate := true.
     [
@@ -2008,15 +2027,37 @@
 "
                 self show:nil
 "
+                idx := fileList indexOf:fileName.
+                idx ~~ 0 ifTrue:[
+                    toRemove add:idx.
+                ]
             ]
         ].
     ] valueNowOrOnUnwindDo:[
         lockUpdate := false.
         fileListView setSelection:nil.
-        self updateCurrentDirectory.
+
+        "/
+        "/ remove reverse - otherwise indices are wrong
+        "/
+        toRemove sort.
+        toRemove reverseDo:[:idx |
+            fileList removeIndex:idx.
+            fileListView removeIndex:idx.
+        ].
+
+        updateRunning ifTrue:[
+            self updateCurrentDirectory
+        ] ifFalse:[
+            "
+             install a new check after some time
+            "
+            needUpdate ifFalse:[timeOfLastCheck := AbsoluteTime now].
+            Processor addTimedBlock:checkBlock afterSeconds:checkDelta
+        ]
     ]
 
-    "Modified: 17.1.1997 / 16:19:29 / cg"
+    "Modified: 19.4.1997 / 14:03:55 / cg"
 !
 
 doRename:oldName to:newName
@@ -2751,6 +2792,16 @@
     "Modified: 18.4.1997 / 15:18:38 / cg"
 !
 
+stopUpdateProcess
+    Processor removeTimedBlock:checkBlock.
+    listUpdateProcess notNil ifTrue:[
+        listUpdateProcess terminate.
+        listUpdateProcess := nil.
+    ].
+
+    "Created: 19.4.1997 / 13:51:34 / cg"
+!
+
 updateCurrentDirectory
     "update listView with directory contents"
 
@@ -2771,11 +2822,7 @@
     self withReadCursorDo:[
         |files matchPattern|
 
-        Processor removeTimedBlock:checkBlock.
-        listUpdateProcess notNil ifTrue:[
-            listUpdateProcess terminate.
-            listUpdateProcess := nil.
-        ].
+        self stopUpdateProcess.
 
         timeOfLastCheck := AbsoluteTime now.
 
@@ -2814,7 +2861,8 @@
              modeString info line len list
              anyImages passDone lineIndex aFileName
              entry typ f p typeString done endIndex 
-             state stopAtEnd nextState img prevFirstLine prevLastLine|
+             state stopAtEnd nextState img prevFirstLine prevLastLine
+             numVisible|
 
             tabSpec isNil ifTrue:[
                 showLongList ifTrue:[
@@ -2846,27 +2894,32 @@
 
             "/
             "/ the state machine
-            "/   #visibleIcons 
-            "/   #visibleAttributes 
-            "/   #visibleTypes
-            "/   #visibleImages
-            "/   #remainingIcons 
-            "/   #remainingAttributes
-            "/   #remainingTypes
-            "/   #remainingImages
             "/
             nextState := IdentityDictionary new.
             showLongList ifTrue:[
                 nextState add:(#visibleIcons -> #visibleAttributes).
                 nextState add:(#visibleAttributes -> #visibleTypes).
                 nextState add:(#visibleTypes -> #visibleImages).
-                nextState add:(#visibleImages -> #remainingIcons).
+                nextState add:(#visibleImages -> #nextPageIcons).
+
+                nextState add:(#nextPageIcons -> #nextPageAttributes).
+                nextState add:(#nextPageAttributes -> #nextPageTypes).
+                nextState add:(#nextPageTypes -> #nextPageImages).
+                nextState add:(#nextPageImages -> #previousPageIcons).
+
+                nextState add:(#previousPageIcons -> #previousPageAttributes).
+                nextState add:(#previousPageAttributes -> #previousPageTypes).
+                nextState add:(#previousPageTypes -> #previousPageImages).
+                nextState add:(#previousPageImages -> #remainingIcons).
+
                 nextState add:(#remainingIcons -> #remainingAttributes).
                 nextState add:(#remainingAttributes -> #remainingTypes).
                 nextState add:(#remainingTypes -> #remainingImages).
                 nextState add:(#remainingImages -> nil).
             ] ifFalse:[
-                nextState add:(#visibleIcons -> #remainingIcons).
+                nextState add:(#visibleIcons -> #nextPageIcons).
+                nextState add:(#nextPageIcons -> #previousPageIcons).
+                nextState add:(#previousPageIcons -> #remainingIcons).
                 nextState add:(#remainingIcons -> nil).
             ].
 
@@ -2902,146 +2955,145 @@
                     state := #visibleIcons.
                 ].
 
-                "/
-                "/ expand the next entry ...
-                "/
-                aFileName := files at:lineIndex.
-                entry := fileListView at:lineIndex.
-
-                ((state == #visibleIcons)
-                or:[state == #remainingIcons]) ifTrue:[
-                    "/
-                    "/ pass 1 - icons
+                (lineIndex between:1 and:(files size)) ifTrue:[
+
                     "/
-                    (passDone at:lineIndex) < 1 ifTrue:[
-                        ((currentDirectory isDirectory:aFileName) and:[
-                        (aFileName ~= '..') and:[aFileName ~= '.']]) ifTrue:[
-                            fileNameString := aFileName , ' ...'
-                        ] ifFalse:[
-                            fileNameString := aFileName
-                        ].
-
-                        showLongList ifTrue:[
-                            len := fileNameString size.
-                            (len > 20) ifTrue:[
-                                fileNameString := (fileNameString contractTo:20)
-                            ].
-                        ].
-
-                        entry colAt:1 put:(self iconForFile:aFileName).
-                        entry colAt:2 put:fileNameString.
-
-                        fileListView at:lineIndex put:entry.
-
-                        anyImages ifFalse:[
-                            (Image isImageFileSuffix:(aFileName asFilename suffix))
-                            ifTrue:[
-                                anyImages := true
-                            ]
-                        ].
-                        passDone at:lineIndex put:1
-                    ]
-                ].
-
-                ((state == #visibleAttributes)
-                or:[state == #remainingAttributes]) ifTrue:[
-                    "/
-                    "/ pass 2 - everything except fileType (which takes very long)
+                    "/ expand the next entry ...
                     "/
-                    (passDone at:lineIndex) < 2 ifTrue:[
-
-                        info := currentDirectory infoOf:aFileName.
-                        info isNil ifTrue:[
-                            "not accessable - usually a symlink,
-                             to a nonexisting/nonreadable file
-                            "
-                            entry colAt:7 put:'(bad symbolic link ?)'.
-                        ] ifFalse:[
-                            typ := (info type).
-
-                            modeString := self getModeString:(info at:#mode)
-                                                        with:#( '' $r $w $x 
-                                                                '  ' $r $w $x 
-                                                                '  ' $r $w $x ).
-                            entry colAt:3 put:modeString.
-
-                            ((info uid) ~~ prevUid) ifTrue:[
-                                prevUid := (info uid).
-                                nameString := OperatingSystem getUserNameFromID:prevUid.
-                                nameString := nameString , (String new:(10 - nameString size))
+                    aFileName := files at:lineIndex.
+                    entry := fileListView at:lineIndex.
+
+                    (state endsWith:'Icons') ifTrue:[
+                        "/
+                        "/ pass 1 - icons
+                        "/
+                        (passDone at:lineIndex) < 1 ifTrue:[
+                            ((currentDirectory isDirectory:aFileName) and:[
+                            (aFileName ~= '..') and:[aFileName ~= '.']]) ifTrue:[
+                                fileNameString := aFileName , ' ...'
+                            ] ifFalse:[
+                                fileNameString := aFileName
                             ].
-                            entry colAt:4 put:nameString withoutSpaces.
-
-                            ((info gid) ~~ prevGid) ifTrue:[
-                                prevGid := (info gid).
-                                groupString := OperatingSystem getGroupNameFromID:prevGid.
-                                groupString := groupString , (String new:(10 - groupString size))
+
+                            showLongList ifTrue:[
+                                len := fileNameString size.
+                                (len > 20) ifTrue:[
+                                    fileNameString := (fileNameString contractTo:20)
+                                ].
+                            ].
+
+                            entry colAt:1 put:(self iconForFile:aFileName).
+                            entry colAt:2 put:fileNameString.
+
+                            fileListView at:lineIndex put:entry.
+
+                            anyImages ifFalse:[
+                                (Image isImageFileSuffix:(aFileName asFilename suffix))
+                                ifTrue:[
+                                    anyImages := true
+                                ]
                             ].
-                            entry colAt:5 put:groupString withoutSpaces.
-
-                            (typ == #regular) ifTrue:[
-                                entry colAt:6 put:(self sizePrintString:(info size)).
-                            ].
-
-                            f := currentDirectory asFilename:aFileName.
-                            f isSymbolicLink ifTrue:[
-                                p := f linkInfo path.    
-                                typeString := 'symbolic link to ' , p
-                            ] ifFalse:[
-                                typeString := typ asString
-                            ].
-                            entry colAt:7 put:typeString
-                        ].
-                        fileListView at:lineIndex put:entry.
-                        passDone at:lineIndex put:2.
+                            passDone at:lineIndex put:1
+                        ]
                     ].
-                ].
-
-                ((state == #visibleTypes)
-                or:[state == #remainingTypes]) ifTrue:[
-                    "/
-                    "/ pass 3: add fileType
-                    "/
-                    (passDone at:lineIndex) < 3 ifTrue:[
-                        info := currentDirectory infoOf:aFileName.
-                        info notNil ifTrue:[
-                            f := currentDirectory asFilename:aFileName.
-                            f isSymbolicLink ifFalse:[
-                                typ := info type.
-                                typ ~~ #directory ifTrue:[
-                                    (Image isImageFileSuffix:(f suffix)) ifFalse:[
-                                        typeString := f fileType.
-
-                                        entry colAt:7 put:typeString.
+
+                    (state endsWith:'Attributes') ifTrue:[
+                        "/
+                        "/ pass 2 - everything except fileType (which takes very long)
+                        "/
+                        (passDone at:lineIndex) < 2 ifTrue:[
+
+                            info := currentDirectory infoOf:aFileName.
+                            info isNil ifTrue:[
+                                "not accessable - usually a symlink,
+                                 to a nonexisting/nonreadable file
+                                "
+                                entry colAt:7 put:'(bad symbolic link ?)'.
+                            ] ifFalse:[
+                                typ := (info type).
+
+                                modeString := self getModeString:(info at:#mode)
+                                                            with:#( '' $r $w $x 
+                                                                    '  ' $r $w $x 
+                                                                    '  ' $r $w $x ).
+                                entry colAt:3 put:modeString.
+
+                                ((info uid) ~~ prevUid) ifTrue:[
+                                    prevUid := (info uid).
+                                    nameString := OperatingSystem getUserNameFromID:prevUid.
+                                    nameString := nameString , (String new:(10 - nameString size))
+                                ].
+                                entry colAt:4 put:nameString withoutSpaces.
+
+                                ((info gid) ~~ prevGid) ifTrue:[
+                                    prevGid := (info gid).
+                                    groupString := OperatingSystem getGroupNameFromID:prevGid.
+                                    groupString := groupString , (String new:(10 - groupString size))
+                                ].
+                                entry colAt:5 put:groupString withoutSpaces.
+
+                                (typ == #regular) ifTrue:[
+                                    entry colAt:6 put:(self sizePrintString:(info size)).
+                                ].
+
+                                f := currentDirectory asFilename:aFileName.
+                                f isSymbolicLink ifTrue:[
+                                    p := f linkInfo path.    
+                                    typeString := 'symbolic link to ' , p
+                                ] ifFalse:[
+                                    typeString := typ asString
+                                ].
+                                entry colAt:7 put:typeString
+                            ].
+                            fileListView at:lineIndex put:entry.
+                            passDone at:lineIndex put:2.
+                        ].
+                    ].
+
+                    (state endsWith:'Types') ifTrue:[
+                        "/
+                        "/ pass 3: add fileType
+                        "/
+                        (passDone at:lineIndex) < 3 ifTrue:[
+                            info := currentDirectory infoOf:aFileName.
+                            info notNil ifTrue:[
+                                f := currentDirectory asFilename:aFileName.
+                                f isSymbolicLink ifFalse:[
+                                    typ := info type.
+                                    typ ~~ #directory ifTrue:[
+                                        (Image isImageFileSuffix:(f suffix)) ifFalse:[
+                                            typeString := f fileType.
+
+                                            entry colAt:7 put:typeString.
+                                            fileListView at:lineIndex put:entry
+                                        ]
+                                    ].
+                                ].
+                            ].
+
+                            passDone at:lineIndex put:3
+                        ].
+                    ].
+
+                    (state endsWith:'Images') ifTrue:[
+                        "/
+                        "/ pass 4: read images
+                        "/
+                        (passDone at:lineIndex) < 4 ifTrue:[
+                            f := currentDirectory asFilename construct:aFileName.
+                            (Image isImageFileSuffix:(f suffix)) ifTrue:[
+                                f isDirectory ifFalse:[
+                                    img := Image fromFile:(f pathName).
+                                    img notNil ifTrue:[
+                                        img := img magnifiedTo:16@16.
+                                        img := img on:self device.
+                                        entry colAt:7 put:img.
                                         fileListView at:lineIndex put:entry
                                     ]
-                                ].
+                                ]
                             ].
+                            passDone at:lineIndex put:4
                         ].
-
-                        passDone at:lineIndex put:3
-                    ].
-                ].
-
-                ((state == #visibleImages)
-                or:[state == #remainingImages]) ifTrue:[
-                    "/
-                    "/ pass 4: read images
-                    "/
-                    (passDone at:lineIndex) < 4 ifTrue:[
-                        f := currentDirectory asFilename construct:aFileName.
-                        (Image isImageFileSuffix:(f suffix)) ifTrue:[
-                            f isDirectory ifFalse:[
-                                img := Image fromFile:(f pathName).
-                                img notNil ifTrue:[
-                                    img := img magnifiedTo:16@16.
-                                    img := img on:self device.
-                                    entry colAt:7 put:img.
-                                    fileListView at:lineIndex put:entry
-                                ]
-                            ]
-                        ].
-                        passDone at:lineIndex put:4
                     ].
                 ].
 
@@ -3051,8 +3103,11 @@
                 lineIndex := lineIndex + 1.
                 lineIndex > endIndex ifTrue:[
                     "/ finished this round ...
+                    "/ see what we are going for ...
+                    numVisible := (fileListView lastLineShown - fileListView firstLineShown + 1).
 
                     state := nextState at:state ifAbsent:nil.
+
                     state isNil ifTrue:[
                         done := true
                     ] ifFalse:[
@@ -3061,8 +3116,24 @@
                             endIndex := fileListView lastLineShown.
                             endIndex := endIndex min:(files size).
                         ] ifFalse:[
-                            lineIndex := 1.
-                            endIndex := files size.
+                            (state startsWith:'nextPage') ifTrue:[
+                                lineIndex := fileListView lastLineShown + 1.
+                                endIndex := lineIndex + numVisible.
+                                endIndex := endIndex min:(files size).
+                                lineIndex := lineIndex min:(files size).
+                            ] ifFalse:[
+                                (state startsWith:'previousPage') ifTrue:[
+                                    endIndex := fileListView firstLineShown - 1.
+                                    lineIndex := endIndex - numVisible.
+                                    lineIndex := lineIndex max:1.
+                                    endIndex := endIndex min:(files size).
+                                    endIndex := endIndex max:1.
+                                ] ifFalse:[ 
+                                    "/ remaining
+                                    lineIndex := 1.
+                                    endIndex := files size.
+                                ]
+                            ]
                         ]
                     ]
                 ]
@@ -3079,7 +3150,7 @@
     ]
 
     "Modified: 21.9.1995 / 11:40:23 / claus"
-    "Modified: 19.4.1997 / 09:24:37 / cg"
+    "Modified: 19.4.1997 / 14:35:43 / cg"
 ! !
 
 !FileBrowser methodsFor:'private-file-I/O'!
@@ -3349,6 +3420,6 @@
 !FileBrowser class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.146 1997-04-19 07:25:11 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.147 1997-04-19 13:23:34 cg Exp $'
 ! !
 FileBrowser initialize!