TextView.st
changeset 2701 b77cc7cf3818
parent 2695 7e13db2802df
child 2721 c94666d11e8f
equal deleted inserted replaced
2700:d6bc43ddc80f 2701:b77cc7cf3818
  1473     self allowDrag:true.
  1473     self allowDrag:true.
  1474 ! !
  1474 ! !
  1475 
  1475 
  1476 !TextView methodsFor:'menu actions'!
  1476 !TextView methodsFor:'menu actions'!
  1477 
  1477 
  1478 appendTo:fileName
  1478 appendTo:aFileName
  1479     "append contents to a file named fileName"
  1479     "append contents to a file named fileName"
  1480 
  1480 
  1481     |aStream msg|
  1481     |aStream msg filename|
  1482 
  1482 
  1483     (FileStream userInitiatedFileSaveQuerySignal queryWith:fileName asFilename) ifFalse:[
  1483     filename := aFileName asFilename.
  1484         msg := resources string:'Refused to append to file ''%1'' !!' with:fileName.
  1484 
       
  1485     (FileStream userInitiatedFileSaveQuerySignal queryWith:filename) ifFalse:[
       
  1486         msg := resources string:'Refused to append to file ''%1'' !!' with:filename name.
  1485         self warn:(msg , '\\(ST/X internal permission check)' ) withCRs.
  1487         self warn:(msg , '\\(ST/X internal permission check)' ) withCRs.
  1486         ^ self
  1488         ^ self
  1487     ].
  1489     ].
  1488 
  1490 
  1489     aStream := FileStream appendingOldFileNamed:fileName.
  1491     [
  1490     aStream isNil ifTrue:[
  1492         aStream := filename appendingWriteStream.
  1491         msg := resources string:'cannot append to file %1 !!' with:fileName.
  1493         self fileOutContentsOn:aStream 
  1492         self warn:(msg , '\\(' , FileStream lastErrorString , ')' ) withCRs
  1494              compressTabs:true 
  1493     ] ifFalse:[
  1495              encoding:externalEncoding.
  1494         self 
       
  1495             fileOutContentsOn:aStream 
       
  1496             compressTabs:true 
       
  1497             encoding:externalEncoding.
       
  1498         aStream close.
  1496         aStream close.
  1499         contentsWasSaved := true
  1497         contentsWasSaved := true
       
  1498     ] on:FileStream openErrorSignal do:[:ex|
       
  1499         msg := resources string:'cannot append to file %1 !!' with:filename name.
       
  1500         self warn:(msg , '\\(' , FileStream lastErrorString , ')' ) withCRs
  1500     ]
  1501     ]
  1501 !
  1502 !
  1502 
  1503 
  1503 changeFont
  1504 changeFont
  1504     "pop up a fontPanel to change font"
  1505     "pop up a fontPanel to change font"
  1704     "save the contents into a file named fileName"
  1705     "save the contents into a file named fileName"
  1705  
  1706  
  1706     ^ self saveAs:fileName doAppend:false
  1707     ^ self saveAs:fileName doAppend:false
  1707 !
  1708 !
  1708 
  1709 
  1709 saveAs:fileName doAppend:doAppend
  1710 saveAs:aFilename doAppend:doAppend
  1710     "save the contents into a file named fileName;
  1711     "save the contents into a file named fileName;
  1711      if doAppend is true, the views contents is appended to the existing
  1712      if doAppend is true, the views contents is appended to the existing
  1712      contents - otherwise, it overwrites any previous file contents."
  1713      contents - otherwise, it overwrites any previous file contents."
  1713  
  1714 
       
  1715     |filename|
       
  1716 
       
  1717     filename := aFilename asFilename.
       
  1718 
  1714     self withCursor:Cursor write do:[
  1719     self withCursor:Cursor write do:[
  1715         |aStream msg|
  1720         |aStream msg|
  1716 
  1721 
  1717         (FileStream userInitiatedFileSaveQuerySignal queryWith:fileName asFilename) ifFalse:[
  1722         (FileStream userInitiatedFileSaveQuerySignal queryWith:filename) ifFalse:[
  1718             msg := resources string:'Refused to write file ''%1'' !!' with:fileName.
  1723             msg := resources string:'Refused to write file ''%1'' !!' with:filename name.
  1719             self warn:(msg , '\\(ST/X internal permission check)' ) withCRs.
  1724             self warn:(msg , '\\(ST/X internal permission check)' ) withCRs.
  1720             ^ self
  1725             ^ self
  1721         ].
  1726         ].
  1722 
  1727 
  1723         FileStream openErrorSignal catch:[
  1728         [
  1724             doAppend ifTrue:[
  1729             doAppend ifTrue:[
  1725                 aStream := FileStream appendingOldFileNamed:fileName
  1730                 aStream := filename appendingWriteStream.
  1726             ] ifFalse:[
  1731             ] ifFalse:[
  1727                 aStream := FileStream newFileNamed:fileName.
  1732                 aStream := filename newReadWriteStream.
  1728             ]
  1733             ].
  1729         ].
  1734             self fileOutContentsOn:aStream 
  1730         aStream isNil ifTrue:[
  1735                  compressTabs:true 
  1731             msg := resources string:'cannot write file ''%1'' !!' with:fileName.
  1736                  encoding:externalEncoding.
  1732             self warn:(msg , '\\(' , FileStream lastErrorString , ')' ) withCRs
       
  1733         ] ifFalse:[
       
  1734             self
       
  1735                 fileOutContentsOn:aStream 
       
  1736                 compressTabs:true 
       
  1737                 encoding:externalEncoding.
       
  1738             aStream close.
  1737             aStream close.
  1739             contentsWasSaved := true
  1738             contentsWasSaved := true
  1740         ]
  1739         ] on:FileStream openErrorSignal do:[:ex|
       
  1740             msg := resources string:'cannot write file ''%1'' !!' with:filename name.
       
  1741             self warn:(msg , '\\(' , FileStream lastErrorString , ')' ) withCRs
       
  1742         ].
  1741     ]
  1743     ]
  1742 
  1744 
  1743     "Modified: 22.10.1997 / 12:32:51 / cg"
  1745     "Modified: 22.10.1997 / 12:32:51 / cg"
  1744 !
  1746 !
  1745 
  1747 
  3614 ! !
  3616 ! !
  3615 
  3617 
  3616 !TextView class methodsFor:'documentation'!
  3618 !TextView class methodsFor:'documentation'!
  3617 
  3619 
  3618 version
  3620 version
  3619     ^ '$Header: /cvs/stx/stx/libwidg/TextView.st,v 1.193 2003-02-25 14:43:24 cg Exp $'
  3621     ^ '$Header: /cvs/stx/stx/libwidg/TextView.st,v 1.194 2003-03-02 18:46:28 stefan Exp $'
  3620 ! !
  3622 ! !
  3621 
  3623 
  3622 TextView initialize!
  3624 TextView initialize!