FileBrowser.st
changeset 1145 0464625bbdbb
parent 1144 6bd7e0d7ca07
child 1147 d0e297f94b9b
--- a/FileBrowser.st	Fri Apr 18 12:47:45 1997 +0200
+++ b/FileBrowser.st	Fri Apr 18 13:05:43 1997 +0200
@@ -16,7 +16,7 @@
 		showVeryLongList showDotFiles myName killButton compressTabs
 		lockUpdate previousDirectory currentFileName timeOfFileRead
 		tabSpec commandView commandIndex fileEncoding tabRulerView
-		scrollView icons'
+		scrollView icons listUpdateProcess'
 	classVariableNames:'DirectoryHistory DirectoryHistoryWhere HistorySize DefaultIcon
 		CommandHistory CommandHistorySize Icons DefaultCommandPerSuffix'
 	poolDictionaries:''
@@ -114,6 +114,14 @@
     "Modified: 6.4.1997 / 14:57:12 / cg"
 ! !
 
+!FileBrowser class methodsFor:'class initialization'!
+
+initialize
+    Icons := IdentityDictionary new.
+
+    "Created: 18.4.1997 / 12:50:37 / cg"
+! !
+
 !FileBrowser class methodsFor:'command history'!
 
 addToCommandHistory:aCommandString for:aFilename
@@ -169,38 +177,78 @@
 !
 
 directoryIcon
-    ^ Image fromFile:'bitmaps/xpmBitmaps/document_images/tiny_yellow_dir.xpm'.
-
-    "Created: 17.4.1997 / 01:31:11 / cg"
-    "Modified: 17.4.1997 / 02:28:28 / cg"
+    |i|
+
+    i := Icons at:#directory ifAbsent:nil.
+    i isNil ifTrue:[
+        i := Image fromFile:'bitmaps/xpmBitmaps/document_images/tiny_yellow_dir.xpm'.
+        i notNil ifTrue:[
+            Icons at:#directory put:i
+        ]
+    ].
+    ^ i
+
+    "Modified: 18.4.1997 / 12:51:16 / cg"
 !
 
 directoryLinkIcon
-    ^ Image fromFile:'bitmaps/xpmBitmaps/document_images/tiny_yellow_dir_link.xpm'.
-
-    "Modified: 17.4.1997 / 02:28:28 / cg"
-    "Created: 17.4.1997 / 02:29:36 / cg"
+    |i|
+
+    i := Icons at:#directoryLink ifAbsent:nil.
+    i isNil ifTrue:[
+        i := Image fromFile:'bitmaps/xpmBitmaps/document_images/tiny_yellow_dir_link.xpm'.
+        i notNil ifTrue:[
+            Icons at:#directoryLink put:i
+        ]
+    ].
+    ^ i
+
+    "Modified: 18.4.1997 / 12:51:45 / cg"
 !
 
 fileIcon
-    ^ Image fromFile:'bitmaps/xpmBitmaps/document_images/tiny_file_plain.xpm'.
-
-    "Created: 17.4.1997 / 01:31:20 / cg"
-    "Modified: 17.4.1997 / 02:23:17 / cg"
+    |i|
+
+    i := Icons at:#file ifAbsent:nil.
+    i isNil ifTrue:[
+        i := Image fromFile:'bitmaps/xpmBitmaps/document_images/tiny_file_plain.xpm'.
+        i notNil ifTrue:[
+            Icons at:#file put:i
+        ]
+    ].
+    ^ i
+
+    "Modified: 18.4.1997 / 12:52:06 / cg"
 !
 
 fileLinkIcon
-    ^ Image fromFile:'bitmaps/xpmBitmaps/document_images/tiny_file_link.xpm'.
-
-    "Modified: 17.4.1997 / 02:23:17 / cg"
-    "Created: 17.4.1997 / 02:32:18 / cg"
+    |i|
+
+    i := Icons at:#fileLink ifAbsent:nil.
+    i isNil ifTrue:[
+        i := Image fromFile:'bitmaps/xpmBitmaps/document_images/tiny_file_link.xpm'.
+        i notNil ifTrue:[
+            Icons at:#fileLink put:i
+        ]
+    ].
+    ^ i
+
+    "Modified: 18.4.1997 / 12:52:26 / cg"
 !
 
 imageFileIcon
-    ^ Image fromFile:'bitmaps/xpmBitmaps/document_images/tiny_file_pix.xpm'.
-
-    "Created: 17.4.1997 / 01:31:20 / cg"
-    "Modified: 17.4.1997 / 04:01:06 / cg"
+    |i|
+
+    i := Icons at:#image ifAbsent:nil.
+    i isNil ifTrue:[
+        i := Image fromFile:'bitmaps/xpmBitmaps/document_images/tiny_file_pix.xpm'.
+        i notNil ifTrue:[
+            Icons at:#image put:i
+        ]
+    ].
+    ^ i
+
+    "Modified: 18.4.1997 / 12:52:45 / cg"
 ! !
 
 !FileBrowser methodsFor:'drag & drop'!
@@ -1331,8 +1379,14 @@
 
     ObjectMemory removeDependent:self.
     Processor removeTimedBlock:checkBlock.
+    listUpdateProcess notNil ifTrue:[
+        listUpdateProcess terminate.
+        listUpdateProcess := nil.
+    ].
     checkBlock := nil.
     super destroy
+
+    "Modified: 18.4.1997 / 13:05:14 / cg"
 !
 
 filterPatternChanged
@@ -2858,14 +2912,14 @@
     "the code below may look somewhat complex -
      it reads the directory first for the names,
      then (in a second sweep over the files) gets the
-     files type and info. This makes the Filebrowsers
-     list update seem faster, since the fileInfo (i.e. stat-calls)
-     may take long - especially on NFS-mounted directories.
+     files type and info in a forked subprocess. 
+     This makes the Filebrowsers list update faster, since the fileInfo 
+     (i.e. stat-calls) may take long - especially on NFS-mounted directories.
      The file reading is done at lower priority, to let user continue
      his work in other views. However, to be fair to other fileBrowser,
      which may also read directories at low prio, give up the processor
-     after every entry. This shares the cpu among all fileBrowsers, so
-     that browsers reading short directories will finish first.
+     after every entry. This shares the cpu among all fileBrowsers;
+     Therefore, browsers which read short directories will finish first.
      ST/X users love this behavior ;-)
     "
 
@@ -2873,6 +2927,10 @@
         |files matchPattern|
 
         Processor removeTimedBlock:checkBlock.
+        listUpdateProcess notNil ifTrue:[
+            listUpdateProcess terminate.
+            listUpdateProcess := nil.
+        ].
 
         timeOfLastCheck := AbsoluteTime now.
 
@@ -2902,31 +2960,47 @@
 
         "
          this is a time consuming operation (especially, if reading an
-         NFS-mounted directory); therefore lower my priority while getting
-         the files info ...
+         NFS-mounted directory); therefore, start a low prio process,
+         which fills in the remaining fields in the fileList ...
         "
-        Processor activeProcess withLowerPriorityDo:[
-            |prevUid prevGid nameString groupString modeString info line len text firstItem|
+
+        listUpdateProcess := [
+            |prevUid prevGid nameString groupString 
+             modeString info line len text firstItem list|
+
+            tabSpec isNil ifTrue:[
+                showLongList ifTrue:[
+                    self defineTabulatorsForLongList
+                ] ifFalse:[
+                    self defineTabulatorsForShortList
+                ].
+            ].
 
             "
              first show the names only - this is relatively fast
             "
-            fileListView setList:files expandTabs:false.
-            firstItem := true.
+            list := files collect:[:fileName |
+                        |entry|
+
+                        entry := MultiColListEntry new.
+                        entry tabulatorSpecification:tabSpec.
+                        entry colAt:1 put:nil.
+                        entry colAt:2 put:fileName.
+                    ].
+
+            fileListView setList:list expandTabs:false.
 
             "
              then walk over the files, adding more info
              (since we have to stat each file, this may take a while longer
             "
+            firstItem := true.
             showLongList ifTrue:[
-                tabSpec isNil ifTrue:[self defineTabulatorsForLongList].
-
                 text := OrderedCollection new.
                 files keysAndValuesDo:[:lineIndex :aFileName |
                     |entry col typ f p typeString|
 
-                    entry := MultiColListEntry new.
-                    entry tabulatorSpecification:tabSpec.
+                    entry := fileListView at:lineIndex.
 
                     "
                      if multiple FileBrowsers are reading, let others
@@ -3016,8 +3090,6 @@
                     fileListView at:lineIndex put:entry
                 ].
             ] ifFalse:[
-                tabSpec isNil ifTrue:[self defineTabulatorsForShortList].
-
                 files keysAndValuesDo:[:lineIndex :aName |
                     |entry fileName|
 
@@ -3042,17 +3114,16 @@
 "/                        fileListView redraw.
 "/                    ].
 
-                    entry := MultiColListEntry new.
+                    entry := fileListView at:lineIndex.
                     entry tabulatorSpecification:tabSpec.
                     entry colAt:1 put:(self iconForFile:aName).
                     entry colAt:2 put:fileName.
 
-                    fileListView 
-                        at:lineIndex 
-                        put:entry
+                    fileListView at:lineIndex put:entry
                 ].
             ].
-        ].
+            listUpdateProcess := nil.
+        ] forkAt:(Processor activePriority - 1).
 
         "
          install a new check after some time
@@ -3061,7 +3132,7 @@
     ]
 
     "Modified: 21.9.1995 / 11:40:23 / claus"
-    "Modified: 17.4.1997 / 02:59:28 / cg"
+    "Modified: 18.4.1997 / 13:04:20 / cg"
 ! !
 
 !FileBrowser methodsFor:'private-file-I/O'!
@@ -3331,5 +3402,6 @@
 !FileBrowser class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.142 1997-04-18 10:47:45 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.143 1997-04-18 11:05:43 cg Exp $'
 ! !
+FileBrowser initialize!