--- a/FileBrowser.st Sat Feb 24 20:22:00 1996 +0100
+++ b/FileBrowser.st Mon Feb 26 19:34:12 1996 +0100
@@ -1847,6 +1847,30 @@
^ nil
!
+guessEncodingFrom:aBuffer
+ |n "{Class: SmallInteger }"
+ binary|
+
+ binary := false.
+ n := aBuffer size.
+
+ 1 to:n do:[:i |
+ (aBuffer at:i) isPrintable ifFalse:[binary := true].
+ ].
+ binary ifTrue:[
+ "/ look for JIS7 / EUC encoding
+
+ (aBuffer findString:(JISEncodedString jis7KanjiEscapeSequence)) ~~ 0 ifTrue:[
+ ^ #jis7
+ ].
+ ^ #binary
+ ].
+ ^ #ascii
+
+ "Created: 26.2.1996 / 17:43:08 / cg"
+ "Modified: 26.2.1996 / 17:46:29 / cg"
+!
+
initialCommandFor:fileName into:aBox
"set a useful initial command for execute box.
@@ -2341,7 +2365,7 @@
showFile:fileName insert:insert encoding:encoding
"show/insert contents of fileName in subView"
- |buffer s n i ok convert text msg eol|
+ |buffer s n i ok convert text msg eol guess|
((currentDirectory typeOf:fileName) == #regular) ifFalse:[
"asked for a non-file - ignore it ..."
@@ -2368,13 +2392,19 @@
s close.
ok := true.
- 1 to:n do:[:i |
- (buffer at:i) isPrintable ifFalse:[ok := false].
- ].
- ok ifFalse:[
+ guess := self guessEncodingFrom:buffer.
+ guess == #binary ifTrue:[
+ ok := false.
(self binaryFileAction:fileName) ifTrue:[^ self].
(self confirm:(resources string:'''%1'' seems to be a binary file - show anyway ?' with:fileName))
ifFalse:[^ self]
+ ] ifFalse:[
+ guess ~~ #ascii ifTrue:[
+ fileEncoding ~~ guess ifTrue:[
+ (self confirm:(resources string:'''%1'' seems to be ' , guess , ' encoded - show anyway ?' with:fileName))
+ ifFalse:[^ self]
+ ]
+ ].
].
convert := false.
@@ -2397,6 +2427,7 @@
insert ifFalse:[
"release old text first - we might need the memory in case of huge files
(helps if you have a 4Mb file in the view, and click on another biggy)"
+
subView contents:nil.
].
@@ -2414,7 +2445,7 @@
].
"Created: 22.2.1996 / 14:46:57 / cg"
- "Modified: 22.2.1996 / 14:56:41 / cg"
+ "Modified: 26.2.1996 / 17:48:24 / cg"
!
writeFile:fileName text:someText encoding:encoding
@@ -2472,5 +2503,5 @@
!FileBrowser class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.75 1996-02-23 18:16:40 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.76 1996-02-26 18:34:12 cg Exp $'
! !