FileBrowser.st
changeset 2345 ac8a951e07e9
parent 2339 46603ba745c6
child 2346 a4ffb45a53ea
--- a/FileBrowser.st	Thu Aug 19 14:45:46 1999 +0200
+++ b/FileBrowser.st	Fri Aug 20 12:07:33 1999 +0200
@@ -4560,123 +4560,136 @@
 initialCommandFor:fileName into:aBox
     "set a useful initial command for execute box."
 
-    |cmd select path suffix|
+    |mime cmd select path suffix|
+
+    path := currentDirectory filenameFor:fileName.
+
+    mime := MIMETypes mimeTypeForSuffix:fileName asFilename suffix.
+"/    mime notNil ifTrue:[
+"/        cmd := self initialCommandForMIME:mime file:path
+"/    ].
 
     "/ XXX should be changed to take stuff from a config file
     "/ XXX or from resources.
 
-    path := currentDirectory filenameFor:fileName.
     (path type == #regular) ifTrue:[
-	path isExecutableProgram ifTrue:[
-	    aBox initialText:(fileName , ' <arguments>').
-	    ^ self
-	].
-
-	select := true.
-
-	"some heuristics - my personal preferences ...
-	 (actually this should come from a configfile)"
-
-	(fileName endsWith:'akefile') ifTrue:[
-	    aBox initialText:'make target' selectFrom:6 to:11.
-	    ^ self
-	].
-
-	suffix := path suffix.
-	(suffix = 'C') ifTrue:[
-	    cmd := 'g++ -c %1'.
-	    select := 6.
-	] ifFalse:[
-	    suffix := suffix asLowercase.
-	    (suffix = 'taz') ifTrue:[
-		aBox initialText:'zcat %1 | tar tvf -'.
-		select := false.
-	    ].
-	    (suffix = 'tar') ifTrue:[
-		cmd := 'tar tvf %1'.
-		select := 7.
-	    ].
-	    (suffix = 'zoo') ifTrue:[
-		cmd := 'zoo -list %1'.
-		select := 9.
-	    ].
-	    (suffix = 'zip') ifTrue:[
-		cmd := 'unzip -l %1'.
-		select := 8.
-	    ].
-	    (suffix = 'jar') ifTrue:[
-		cmd := 'unzip -l %1'.
-		select := 8.
-	    ].
-	    (suffix = 'z') ifTrue:[
-		(fileName asLowercase endsWith:'tar.z') ifTrue:[
-		    cmd := 'zcat %1 | tar tvf -'.
-		    select := false.
-		] ifFalse:[
-		    cmd := 'uncompress %1'
-		].
-	    ].
-	    (suffix = 'gz') ifTrue:[
-		(fileName asLowercase endsWith:'tar.gz') ifTrue:[
-		    cmd := ('gunzip < %1 | tar tvf -' ).
-		    select := false.
-		] ifFalse:[
-		    cmd := 'gunzip %1'.
-		].
-	    ].
-	    (suffix = 'tgz') ifTrue:[
-		cmd := ('gunzip < %1 | tar tvf -' ).
-		select := false.
-	    ].
-	    (suffix = 'html') ifTrue:[
-		cmd := 'netscape %1'
-	    ].
-	    (suffix = 'htm') ifTrue:[
-		cmd := 'netscape %1'
-	    ].
-	    (suffix = 'uue') ifTrue:[
-		cmd := 'uudecode %1'
-	    ].
-	    (suffix = 'c') ifTrue:[
-		cmd := 'cc -c %1'.
-		select := 5.
-	    ].
-	    (suffix = 'cc') ifTrue:[
-		cmd := 'g++ -c %1'.
-		select := 6.
-	    ].
-	    (suffix = 'xbm') ifTrue:[
-		cmd := 'bitmap %1'
-	    ].
-	    (suffix = 'ps') ifTrue:[
-		cmd := 'ghostview %1'
-	    ].
-	    ((suffix = '1') or:[suffix = 'man']) ifTrue:[
-		cmd := 'nroff -man %1'.
-		select := 10.
-	    ].
-	].
-
-	cmd isNil ifTrue:[
-	    DefaultCommandPerSuffix isNil ifTrue:[
-		cmd := '<cmd>'
-	    ] ifFalse:[
-		cmd := DefaultCommandPerSuffix 
-			at:suffix
-			ifAbsent:'<cmd>'.
-	    ].
-	    cmd := cmd , ' %1'.
-	].
-
-	cmd := cmd bindWith:fileName.
-	select == false ifTrue:[
-	    aBox initialText:cmd
-	] ifFalse:[
-	    select isInteger ifFalse:[
-		select := (cmd indexOf:Character space ifAbsent:[cmd size + 1]) - 1.
-	    ].
-	    aBox initialText:cmd selectFrom:1 to:select
-	]
+        path isExecutableProgram ifTrue:[
+            aBox initialText:(fileName , ' <arguments>').
+            ^ self
+        ].
+
+        select := true.
+
+        "some heuristics - my personal preferences ...
+         (actually this should come from a configfile)"
+
+        (fileName endsWith:'akefile') ifTrue:[
+            aBox initialText:'make target' selectFrom:6 to:11.
+            ^ self
+        ].
+
+        suffix := path suffix.
+        (suffix = 'C') ifTrue:[
+            cmd := 'g++ -c %1'.
+            select := 6.
+        ] ifFalse:[
+            suffix := suffix asLowercase.
+            (suffix = 'taz') ifTrue:[
+                aBox initialText:'zcat %1 | tar tvf -'.
+                select := false.
+            ].
+            (suffix = 'tar') ifTrue:[
+                cmd := 'tar tvf %1'.
+                select := 7.
+            ].
+            (suffix = 'zoo') ifTrue:[
+                cmd := 'zoo -list %1'.
+                select := 9.
+            ].
+            (suffix = 'zip') ifTrue:[
+                cmd := 'unzip -l %1'.
+                select := 8.
+            ].
+            (suffix = 'jar') ifTrue:[
+                cmd := 'unzip -l %1'.
+                select := 8.
+            ].
+            (suffix = 'z') ifTrue:[
+                (fileName asLowercase endsWith:'tar.z') ifTrue:[
+                    cmd := 'zcat %1 | tar tvf -'.
+                    select := false.
+                ] ifFalse:[
+                    cmd := 'uncompress %1'
+                ].
+            ].
+            (suffix = 'gz') ifTrue:[
+                (fileName asLowercase endsWith:'tar.gz') ifTrue:[
+                    cmd := ('gunzip < %1 | tar tvf -' ).
+                    select := false.
+                ] ifFalse:[
+                    cmd := 'gunzip %1'.
+                ].
+            ].
+            (suffix = 'tgz') ifTrue:[
+                cmd := ('gunzip < %1 | tar tvf -' ).
+                select := false.
+            ].
+            (suffix = 'html') ifTrue:[
+                cmd := 'netscape %1'
+            ].
+            (suffix = 'htm') ifTrue:[
+                cmd := 'netscape %1'
+            ].
+            (suffix = 'uue') ifTrue:[
+                cmd := 'uudecode %1'
+            ].
+            (suffix = 'pdf') ifTrue:[
+                cmd := 'acroread %1'
+            ].
+            (suffix = 'c') ifTrue:[
+                cmd := 'cc -c %1'.
+                select := 5.
+            ].
+            (suffix = 'cc') ifTrue:[
+                cmd := 'g++ -c %1'.
+                select := 6.
+            ].
+            (suffix = 'xbm') ifTrue:[
+                cmd := 'bitmap %1'
+            ].
+            (suffix = 'ps') ifTrue:[
+                cmd := 'ghostview %1'
+            ].
+            ((suffix = '1') or:[suffix = 'man']) ifTrue:[
+                cmd := 'nroff -man %1'.
+                select := 10.
+            ].
+        ].
+
+        cmd isNil ifTrue:[
+            DefaultCommandPerSuffix isNil ifTrue:[
+                cmd := '<cmd>'
+            ] ifFalse:[
+                cmd := DefaultCommandPerSuffix 
+                        at:suffix
+                        ifAbsent:'<cmd>'.
+            ].
+            cmd := cmd , ' %1'.
+        ].
+
+        cmd := cmd bindWith:fileName.
+        select == false ifTrue:[
+            aBox initialText:cmd
+        ] ifFalse:[
+            select class == Interval ifTrue:[
+                aBox initialText:cmd selectFrom:select start to:select stop
+            ] ifFalse:[
+                select isInteger ifFalse:[
+                    select := (cmd indexOf:Character space ifAbsent:[cmd size + 1]) - 1.
+                ].
+                aBox initialText:cmd selectFrom:1 to:select
+            ].
+        ]
     ]
 
     "Modified: / 24.9.1997 / 16:34:52 / stefan"
@@ -6741,5 +6754,5 @@
 !FileBrowser class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.339 1999-08-18 14:59:03 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.340 1999-08-20 10:07:33 cg Exp $'
 ! !