FileBrowser.st
changeset 5514 a9e6eb4214bd
parent 5513 4cf44154150d
child 5515 3ff121346fc1
equal deleted inserted replaced
5513:4cf44154150d 5514:a9e6eb4214bd
  6365     "Modified: / 18.9.1997 / 17:10:20 / stefan"
  6365     "Modified: / 18.9.1997 / 17:10:20 / stefan"
  6366     "Modified: / 15.11.2001 / 17:15:27 / cg"
  6366     "Modified: / 15.11.2001 / 17:15:27 / cg"
  6367 !
  6367 !
  6368 
  6368 
  6369 writeFile:fileName text:someText encoding:encoding
  6369 writeFile:fileName text:someText encoding:encoding
  6370     |stream msg startNr nLines string|
  6370     |stream msg startNr nLines string encoder|
  6371 
  6371 
  6372     [
  6372     [
  6373         stream := (currentDirectory filenameFor:fileName) writeStream.
  6373         stream := (currentDirectory filenameFor:fileName) writeStream.
  6374     ] on:FileStream openErrorSignal do:[:ex|
  6374     ] on:FileStream openErrorSignal do:[:ex|
  6375         msg := (resources string:'cannot write file ''%1'' !!' with:fileName).
  6375         msg := (resources string:'cannot write file ''%1'' !!' with:fileName).
  6376         self showAlert:msg with:ex description.
  6376         self showAlert:msg with:ex description.
  6377         ^ self.
  6377         ^ self.
  6378     ].
  6378     ].
  6379 
  6379 
       
  6380     encoder := CharacterEncoder encoderToEncodeFrom:(subView characterEncoding) into:encoding.
       
  6381 
  6380     dosEOLMode value == true ifTrue:[
  6382     dosEOLMode value == true ifTrue:[
  6381         stream eolMode:#crlf.
  6383         stream eolMode:#crlf.
  6382         "/ must do it lineWise ...
  6384         "/ must do it lineWise ...
  6383         someText asStringCollection do:[:line |
  6385         someText asStringCollection do:[:line |
  6384             line notNil ifTrue:[
  6386             line notNil ifTrue:[
  6385                 string := line.
  6387                 stream nextPutAll:(encoder encodeString:line)
  6386                 encoding notNil ifTrue:[
       
  6387                     string := string encodeInto:encoding
       
  6388                 ].
       
  6389                 stream nextPutAll:line
       
  6390             ].
  6388             ].
  6391             stream cr
  6389             stream cr
  6392         ]
  6390         ]
  6393     ] ifFalse:[
  6391     ] ifFalse:[
  6394         (someText isString) ifTrue:[
  6392         (someText isString) ifTrue:[
  6395             string := someText.
  6393             stream nextPutAll:(encoder encodeString:someText).
  6396             encoding notNil ifTrue:[
       
  6397                 string := string encodeInto:encoding
       
  6398             ].
       
  6399             stream nextPutAll:string.
       
  6400         ] ifFalse:[
  6394         ] ifFalse:[
  6401             "/
  6395             "/
  6402             "/ on some systems, writing linewise is very slow (via NFS)
  6396             "/ on some systems, writing linewise is very slow (via NFS)
  6403             "/ therefore we convert to a string and write it in chunks.
  6397             "/ therefore we convert to a string and write it in chunks.
  6404             "/ To avoid creating huge strings, we do it in blocks of 1000 lines.
  6398             "/ To avoid creating huge strings, we do it in blocks of 1000 lines.
  6407             nLines := someText size.
  6401             nLines := someText size.
  6408             [startNr <= nLines] whileTrue:[
  6402             [startNr <= nLines] whileTrue:[
  6409                 string := someText asStringWithCRsFrom:startNr
  6403                 string := someText asStringWithCRsFrom:startNr
  6410                                                     to:((startNr + 1000) min:nLines)
  6404                                                     to:((startNr + 1000) min:nLines)
  6411                                           compressTabs:compressTabs.
  6405                                           compressTabs:compressTabs.
  6412                 encoding notNil ifTrue:[
  6406                 stream nextPutAll:(encoder encodeString:string).
  6413                     string := string encodeInto:encoding
       
  6414                 ].
       
  6415                 stream nextPutAll:string.
       
  6416                 startNr := startNr + 1000 + 1.
  6407                 startNr := startNr + 1000 + 1.
  6417             ].
  6408             ].
  6418         ].
  6409         ].
  6419     ].
  6410     ].
  6420 
  6411 
  7619 ! !
  7610 ! !
  7620 
  7611 
  7621 !FileBrowser class methodsFor:'documentation'!
  7612 !FileBrowser class methodsFor:'documentation'!
  7622 
  7613 
  7623 version
  7614 version
  7624     ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.567 2004-02-13 00:42:29 cg Exp $'
  7615     ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.568 2004-02-13 00:49:48 cg Exp $'
  7625 ! !
  7616 ! !