FileBrowser.st
changeset 2998 48eb938bbb7e
parent 2989 7bc80b96c24c
child 2999 e9a5c559080f
--- a/FileBrowser.st	Mon Mar 26 17:51:52 2001 +0200
+++ b/FileBrowser.st	Fri Mar 30 12:12:53 2001 +0200
@@ -3629,26 +3629,15 @@
 "/    commandView contents:'** no commands which require input here **'.
 
     commandView entryCompletionBlock:[:contents |
-        |newString words lastWord expandedWord|
-
-        words := contents asCollectionOfWords.
-        words size == 0 ifTrue:[
-            commandView flash
-        ] ifFalse:[
-            "/ actually: should expand the word before the cursor here ...
-            lastWord := words last.
-            expandedWord := Filename 
-                            filenameCompletionFor:lastWord 
-                            directory:currentDirectory 
-                            directoriesOnly:false 
-                            filesOnly:false 
-                            ifMultiple:[:dir | commandView flash.].
-            words at:(words size) put:expandedWord.
-            newString := words asStringCollection asStringWith:Character space.
+        |newString|
+
+        newString := self entryCompletion:contents.
+        newString notNil ifTrue:[
             commandView contents:newString.
             commandView cursorToEndOfLine.
-        ]
-    ].
+        ].
+    ].
+
     commandView leaveAction:[:key | 
         |cmd nCmd empty|
 
@@ -4138,6 +4127,59 @@
     "Created: 2.10.1997 / 14:08:37 / stefan"
 !
 
+entryCompletion:contents
+    |newString words lastWord expandedWord idx|
+
+    "/ find the last word.
+    "/ used to be 'contents asCollectionOfWords last',
+    "/ but we have to care for escaped spaces here (unix) ...
+
+    idx := contents size.
+    OperatingSystem isUNIXlike ifFalse:[
+        "/ under MSDOS, the backslash is a directory separator
+        idx := contents lastIndexOf:Character space startingAt:idx.
+    ] ifTrue:[
+        "/ under UNIX, the backslash is a special character escape
+        idx := idx + 1.
+        [
+            idx := contents lastIndexOf:Character space startingAt:idx-1.
+        ] doWhile:[
+            idx > 1 and:[ (contents at:idx-1) = $\ ]
+        ].
+    ].
+    idx == 0 ifTrue:[
+        commandView flash.
+        ^ nil.
+    ].
+
+    lastWord := contents copyFrom:idx + 1.
+    OperatingSystem isUNIXlike ifTrue:[
+        (lastWord includes:$\) ifTrue:[
+            lastWord := lastWord copyReplaceAll:$\ withAll:''.
+        ].
+    ].
+
+    expandedWord := Filename 
+                    filenameCompletionFor:lastWord 
+                    directory:currentDirectory 
+                    directoriesOnly:false 
+                    filesOnly:false 
+                    ifMultiple:[:dir | commandView flash.].
+
+    OperatingSystem isUNIXlike ifTrue:[
+        expandedWord := expandedWord copyReplaceAll:(Character space) withAll:'\ '.
+        expandedWord := expandedWord copyReplaceAll:($') withAll:'\'''.
+        expandedWord := expandedWord copyReplaceAll:($() withAll:'\('.
+        expandedWord := expandedWord copyReplaceAll:($)) withAll:'\)'.
+        expandedWord := expandedWord copyReplaceAll:($[) withAll:'\['.
+        expandedWord := expandedWord copyReplaceAll:($]) withAll:'\]'.
+    ].
+
+    newString := (contents copyTo:idx) ,  expandedWord.
+
+    ^ newString
+!
+
 filterPatternChanged
     fileListView scrollToTop.
     fileListView deselect.
@@ -7191,5 +7233,5 @@
 !FileBrowser class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.396 2001-03-06 14:13:13 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.397 2001-03-30 10:12:53 cg Exp $'
 ! !