--- a/FileBrowser.st Thu Apr 17 04:05:25 1997 +0200
+++ b/FileBrowser.st Thu Apr 17 19:27:12 1997 +0200
@@ -18,7 +18,7 @@
tabSpec commandView commandIndex fileEncoding tabRulerView
scrollView icons'
classVariableNames:'DirectoryHistory DirectoryHistoryWhere HistorySize DefaultIcon
- CommandHistory CommandHistorySize Icons'
+ CommandHistory CommandHistorySize Icons DefaultCommandPerSuffix'
poolDictionaries:''
category:'Interface-Browsers'
!
@@ -116,7 +116,9 @@
!FileBrowser class methodsFor:'command history'!
-addToCommandHistory:aCommandString
+addToCommandHistory:aCommandString for:aFilename
+ |cmd suffix|
+
(aCommandString notNil and:[aCommandString notEmpty]) ifTrue:[
CommandHistory notNil ifTrue:[
CommandHistory addFirst:aCommandString.
@@ -124,6 +126,16 @@
CommandHistory removeLast
]
].
+ aFilename notNil ifTrue:[
+ cmd := aCommandString copyTo:(aCommandString indexOf:Character space ifAbsent:[aCommandString size + 1])-1.
+ DefaultCommandPerSuffix isNil ifTrue:[
+ DefaultCommandPerSuffix := Dictionary new.
+ ].
+ suffix := aFilename asFilename suffix.
+ suffix notNil ifTrue:[
+ DefaultCommandPerSuffix at:suffix put:cmd.
+ ]
+ ]
]
"Created: 14.11.1996 / 14:58:13 / cg"
@@ -412,13 +424,13 @@
"if text was modified show a queryBox,
otherwise pop up execute box immediately"
- |action|
+ |action sel fileName|
"
this replaces everything by the commands output ...
"
action := [:command |
- self class addToCommandHistory:command.
+ self class addToCommandHistory:command for:fileName.
self doExecuteCommand:command replace:true
].
@@ -430,7 +442,12 @@
"/ "
"/ action := [:command| self doExecuteCommand:command replace:false].
"/
- self askForCommandThenDo:action
+
+ sel := fileListView selection.
+ sel size == 1 ifTrue:[
+ fileName := fileList at:sel first
+ ].
+ self askForCommandFor:fileName thenDo:action
"Modified: 14.11.1996 / 14:59:34 / cg"
!
@@ -1282,7 +1299,7 @@
"/ subView insertCharAtCursor:(Character cr).
(cmd notNil and:[cmd notEmpty]) ifTrue:[
- self class addToCommandHistory:cmd.
+ self class addToCommandHistory:cmd for:nil.
self doExecuteCommand:cmd replace:false.
commandView contents:nil.
commandIndex := 0
@@ -1492,26 +1509,23 @@
"Modified: 21.2.1996 / 01:19:21 / cg"
!
-askForCommandThenDo:aBlock
+askForCommandFor:fileName thenDo:aBlock
"setup and launch a querybox to ask for unix command.
Then evaluate aBlock passing the command-string as argument."
- |fileName sel box|
+ |sel box|
box := FilenameEnterBox
title:(resources at:'execute unix command:')
okText:(resources at:'execute')
action:aBlock.
- sel := fileListView selection.
- sel size == 1 ifTrue:[
- fileName := fileList at:sel first
- ].
fileName notNil ifTrue:[
self initialCommandFor:fileName into:box.
].
box directory:currentDirectory pathName asFilename.
- box showAtPointer
+ box showAtPointer.
+ box destroy.
"Modified: 7.9.1995 / 10:31:54 / claus"
!
@@ -2260,6 +2274,124 @@
"Modified: 23.1.1997 / 20:39:25 / cg"
!
+initialCommandFor:fileName into:aBox
+ "set a useful initial command for execute box."
+
+ |lcFilename cmd select|
+
+ "/ XXX should be changed to take stuff from a config file
+ "/ XXX or from resources.
+
+ ((currentDirectory typeOf:fileName) == #regular) ifTrue:[
+
+ (currentDirectory isExecutable:fileName) ifTrue:[
+ aBox initialText:(fileName , ' <arguments>').
+ ^ self
+ ].
+
+ lcFilename := fileName asLowercase.
+
+ 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
+ ].
+ (lcFilename endsWith:'tar.z') ifTrue:[
+ cmd := 'zcat %1 | tar tvf -'.
+ select := false.
+ ].
+ (fileName endsWith:'.taz') ifTrue:[
+ aBox initialText:'zcat %1 | tar tvf -'.
+ select := false.
+ ].
+ (fileName endsWith:'.tar') ifTrue:[
+ cmd := 'tar tvf %1'.
+ select := 7.
+ ].
+ (fileName endsWith:'.zoo') ifTrue:[
+ cmd := 'zoo -list %1'.
+ select := 9.
+ ].
+ (lcFilename endsWith:'.zip') ifTrue:[
+ cmd := 'unzip -l %1'.
+ select := 8.
+ ].
+ (lcFilename endsWith:'.z') ifTrue:[
+ cmd := 'uncompress %1'
+ ].
+ (fileName endsWith:'tar.gz') ifTrue:[
+ cmd := ('gunzip < %1 | tar tvf -' ).
+ select := false.
+ ].
+ (fileName endsWith:'.tgz') ifTrue:[
+ cmd := ('gunzip < %1 | tar tvf -' ).
+ select := false.
+ ].
+ (fileName endsWith:'.gz') ifTrue:[
+ cmd := 'gunzip %1'.
+ ].
+ (lcFilename endsWith:'.html') ifTrue:[
+ cmd := 'netscape %1'
+ ].
+ (lcFilename endsWith:'.htm') ifTrue:[
+ cmd := 'netscape %1'
+ ].
+ (fileName endsWith:'.uue') ifTrue:[
+ cmd := 'uudecode %1'
+ ].
+ (fileName endsWith:'.c') ifTrue:[
+ cmd := 'cc -c %1'.
+ select := 5.
+ ].
+ (fileName endsWith:'.cc') ifTrue:[
+ cmd := 'g++ -c %1'.
+ select := 6.
+ ].
+ (fileName endsWith:'.C') ifTrue:[
+ cmd := 'g++ -c %1'.
+ select := 6.
+ ].
+ (fileName endsWith:'.xbm') ifTrue:[
+ cmd := 'bitmap %1'
+ ].
+ (lcFilename endsWith:'.ps') ifTrue:[
+ cmd := 'ghostview %1'
+ ].
+ ((fileName endsWith:'.1')
+ or:[fileName endsWith:'.man']) ifTrue:[
+ cmd := 'nroff -man %1'.
+ select := 10.
+ ].
+
+ cmd isNil ifTrue:[
+ DefaultCommandPerSuffix isNil ifTrue:[
+ cmd := '<cmd>'
+ ] ifFalse:[
+ cmd := DefaultCommandPerSuffix
+ at:(lcFilename asFilename 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
+ ]
+ ]
+
+ "Modified: 4.4.1997 / 12:26:40 / cg"
+!
+
onlyOneSelection
"show a warning, that only one file must be selected for
this operation"
@@ -2524,109 +2656,6 @@
"Modified: 16.4.1997 / 13:56:21 / cg"
!
-initialCommandFor:fileName into:aBox
- "set a useful initial command for execute box."
-
- |lcFilename|
-
- "/ XXX should be changed to take stuff from a config file
- "/ XXX or from resources.
-
- ((currentDirectory typeOf:fileName) == #regular) ifTrue:[
-
- (currentDirectory isExecutable:fileName) ifTrue:[
- aBox initialText:(fileName , '<arguments>').
- ^ self
- ].
-
- lcFilename := fileName asLowercase.
-
- "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
- ].
- (lcFilename endsWith:'tar.z') ifTrue:[
- aBox initialText:'zcat ' , fileName , ' | tar tvf -'.
- ^ self
- ].
- (fileName endsWith:'.taz') ifTrue:[
- aBox initialText:'zcat ' , fileName , ' | tar tvf -'.
- ^ self
- ].
- (fileName endsWith:'.tar') ifTrue:[
- aBox initialText:'tar tvf ' , fileName selectFrom:1 to:7.
- ^ self
- ].
- (fileName endsWith:'.zoo') ifTrue:[
- aBox initialText:'zoo -list ' , fileName selectFrom:1 to:9.
- ^ self
- ].
- (lcFilename endsWith:'.zip') ifTrue:[
- aBox initialText:'unzip -l ' , fileName selectFrom:1 to:8.
- ^ self
- ].
- (lcFilename endsWith:'.z') ifTrue:[
- aBox initialText:'uncompress ' , fileName selectFrom:1 to:10.
- ^ self
- ].
- (fileName endsWith:'tar.gz') ifTrue:[
- aBox initialText:('gunzip <' , fileName , ' | tar tvf -' ).
- ^ self
- ].
- (fileName endsWith:'.tgz') ifTrue:[
- aBox initialText:('gunzip <' , fileName , ' | tar tvf -' ).
- ^ self
- ].
- (fileName endsWith:'.gz') ifTrue:[
- aBox initialText:('gunzip <' , fileName , ' >' , (fileName copyWithoutLast:3 "copyTo:(fileName size - 3)")).
- ^ self
- ].
- (lcFilename endsWith:'.html') ifTrue:[
- aBox initialText:'netscape ' , fileName .
- ^ self
- ].
- (lcFilename endsWith:'.htm') ifTrue:[
- aBox initialText:'netscape ' , fileName .
- ^ self
- ].
- (fileName endsWith:'.uue') ifTrue:[
- aBox initialText:'uudecode ' , fileName selectFrom:1 to:8.
- ^ self
- ].
- (fileName endsWith:'.c') ifTrue:[
- aBox initialText:'cc -c ' , fileName selectFrom:1 to:5.
- ^ self
- ].
- (fileName endsWith:'.cc') ifTrue:[
- aBox initialText:'g++ -c ' , fileName selectFrom:1 to:6.
- ^ self
- ].
- (fileName endsWith:'.C') ifTrue:[
- aBox initialText:'g++ -c ' , fileName selectFrom:1 to:6.
- ^ self
- ].
- (fileName endsWith:'.xbm') ifTrue:[
- aBox initialText:'bitmap ' , fileName selectFrom:1 to:6.
- ^ self
- ].
- (lcFilename endsWith:'.ps') ifTrue:[
- aBox initialText:'ghostview ' , fileName selectFrom:1 to:9.
- ^ self
- ].
- ((fileName endsWith:'.1')
- or:[fileName endsWith:'.man']) ifTrue:[
- aBox initialText:'nroff -man ' , fileName selectFrom:1 to:10.
- ^ self
- ].
- aBox initialText:'<cmd> ' , fileName selectFrom:1 to:5
- ]
-
- "Modified: 4.4.1997 / 12:26:40 / cg"
-!
-
nonBinaryFileAction:aFilename
"for some nonBinary files, if double clicked, we can do some useful
action ..."
@@ -3287,5 +3316,5 @@
!FileBrowser class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.140 1997-04-17 02:05:25 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.141 1997-04-17 17:27:12 cg Exp $'
! !