TextView.st
changeset 2916 7f1e089959a3
parent 2913 bdf4fb09cfc0
child 2929 8298734011b6
equal deleted inserted replaced
2915:8db67a5d1ccb 2916:7f1e089959a3
   644      (encoding is something like #'iso8859-5' #euc, #sjis, #jis7, #gb, #big5 or #ksc)"
   644      (encoding is something like #'iso8859-5' #euc, #sjis, #jis7, #gb, #big5 or #ksc)"
   645 
   645 
   646     ^ characterEncoding
   646     ^ characterEncoding
   647 !
   647 !
   648 
   648 
   649 characterEncoding:encodingSymOrNil
   649 characterEncoding:encodingArg
   650     "define how the contents is encoded internally.
   650     "define how the contents is encoded internally.
   651      For now, this should be the same encoding as my fonts encoding 
   651      This should normally never be required, as ST/X now assumes
   652      (otherwise, mappings would occur when drawing).
   652      unicode (of which iso8859-1 is a subset) encoding.
   653      This is (currently) only passed down from the fileBrowser,
   653      The possibility to change the characterEncoding is provided as
   654      and required when japanese/chinese/korean text is edited.
   654      a backward compatibility hook for programs which want to use
   655      (encoding is something like #'iso8859-5' #euc, #sjis, #jis7, #gb, #big5 or #ksc)"
   655      another encoding internally."
   656 
   656 
   657     characterEncoding := encodingSymOrNil
   657     |encodingSymOrNil|
       
   658 
       
   659     encodingSymOrNil := encodingArg isNil ifTrue:[#'iso10646-1'] ifFalse:[encodingArg asSymbol].
       
   660 
       
   661     characterEncoding ~~ encodingSymOrNil ifTrue:[
       
   662         "/ TODO: reencode contents if required.
       
   663         (list size ~~ 0
       
   664         and:[ list contains:[:line | line size > 0]]) ifTrue:[
       
   665             (self confirm:'Your text may need to be re-coded - this is not yet supported.\\Proceed ?')
       
   666             ifFalse:[^ self].
       
   667         ].
       
   668         characterEncoding := encodingSymOrNil.
       
   669     ].
   658 !
   670 !
   659 
   671 
   660 characterPositionOfSelection
   672 characterPositionOfSelection
   661     "return the character index of the first character in the selection.
   673     "return the character index of the first character in the selection.
   662      Returns 0 if there is no selection."
   674      Returns 0 if there is no selection."
   704 !
   716 !
   705 
   717 
   706 externalEncoding:encodingSymOrNil
   718 externalEncoding:encodingSymOrNil
   707     "define how the contents should be encoded when saved
   719     "define how the contents should be encoded when saved
   708      via the 'save / save as' dialog.
   720      via the 'save / save as' dialog.
   709      This is (currently) only passed down from the fileBrowser,
   721      This is (currently only) passed down from the fileBrowser,
   710      and required when japanese/chinese/korean text is edited.
   722      and required when  utf8/japanese/chinese/korean text is edited.
   711      (encoding is something like #'iso8859-5' #euc, #sjis, #jis7, #gb, #big5 or #ksc)"
   723      (encoding is something like #utf8 #'iso8859-5' #euc, #sjis, #jis7, #gb, #big5 or #ksc).
       
   724      Notice: this only affects the external representation of the text."
   712 
   725 
   713     externalEncoding := encodingSymOrNil
   726     externalEncoding := encodingSymOrNil
   714 !
   727 !
   715 
   728 
   716 parenthesisSpecification
   729 parenthesisSpecification
  1017             self warn:'Your display does not seem to provide any ' , newEncoding allBold , ' encoded font.\\Please select an appropriate font (iso10646-Unicode recommended)'.
  1030             self warn:'Your display does not seem to provide any ' , newEncoding allBold , ' encoded font.\\Please select an appropriate font (iso10646-Unicode recommended)'.
  1018             pref := #'iso10646-1'.
  1031             pref := #'iso10646-1'.
  1019         ]
  1032         ]
  1020     ].
  1033     ].
  1021 
  1034 
  1022     msg := 'switch to a %1 encoded font ?'.
  1035     msg := 'Switch to a %1 encoded font ?'.
  1023     (ask not or:[self confirm:(resources string:msg with:pref) withCRs])
  1036     (ask not or:[self confirm:(resources string:msg with:pref) withCRs])
  1024     ifTrue:[
  1037     ifTrue:[
  1025         self withWaitCursorDo:[
  1038         self withWaitCursorDo:[
  1026             f := FontPanel 
  1039             f := FontPanel 
  1027                     fontFromUserInitial:defaultFont
  1040                     fontFromUserInitial:defaultFont
  1029                     filter:filter
  1042                     filter:filter
  1030                     encoding:pref.
  1043                     encoding:pref.
  1031 
  1044 
  1032             f notNil ifTrue:[
  1045             f notNil ifTrue:[
  1033                 self font:f.
  1046                 self font:f.
  1034                 self characterEncoding:f encoding.
       
  1035             ]
  1047             ]
  1036         ]
  1048         ]
  1037     ]
  1049     ]
  1038 
  1050 
  1039     "Created: 26.10.1996 / 12:06:54 / cg"
  1051     "Created: 26.10.1996 / 12:06:54 / cg"
  1655     |newFont|
  1667     |newFont|
  1656 
  1668 
  1657     newFont := FontPanel fontFromUserInitial:font.
  1669     newFont := FontPanel fontFromUserInitial:font.
  1658     newFont notNil ifTrue:[
  1670     newFont notNil ifTrue:[
  1659         self font:newFont.
  1671         self font:newFont.
  1660         characterEncoding := newFont encoding.
       
  1661     ]
  1672     ]
  1662 
  1673 
  1663     "Modified: 27.2.1996 / 00:53:51 / cg"
  1674     "Modified: 27.2.1996 / 00:53:51 / cg"
  1664 !
  1675 !
  1665 
  1676 
  2000      leading spaces will be replaced by tab-characters in the output."
  2011      leading spaces will be replaced by tab-characters in the output."
  2001 
  2012 
  2002     |startNr nLines string encoder|
  2013     |startNr nLines string encoder|
  2003 
  2014 
  2004     encoder := CharacterEncoder encoderToEncodeFrom:characterEncoding into:encodingSymOrNil.
  2015     encoder := CharacterEncoder encoderToEncodeFrom:characterEncoding into:encodingSymOrNil.
       
  2016 
  2005     aStream isFileStream ifTrue:[
  2017     aStream isFileStream ifTrue:[
  2006         "on some systems, writing linewise is very slow (via NFS)
  2018         "on some systems, writing linewise is very slow (via NFS)
  2007          therefore we convert to a string and write it in big chunks.
  2019          therefore we convert to a string and write it in big chunks.
  2008          To avoid creating huge strings, we do it in blocks of 1000 lines,
  2020          To avoid creating huge strings, we do it in blocks of 1000 lines,
  2009          limiting temporary string creation to about 50-80k.
  2021          limiting temporary string creation to about 50-80k.
  3808 ! !
  3820 ! !
  3809 
  3821 
  3810 !TextView class methodsFor:'documentation'!
  3822 !TextView class methodsFor:'documentation'!
  3811 
  3823 
  3812 version
  3824 version
  3813     ^ '$Header: /cvs/stx/stx/libwidg/TextView.st,v 1.239 2004-02-26 12:18:10 cg Exp $'
  3825     ^ '$Header: /cvs/stx/stx/libwidg/TextView.st,v 1.240 2004-02-28 12:57:56 cg Exp $'
  3814 ! !
  3826 ! !
  3815 
  3827 
  3816 TextView initialize!
  3828 TextView initialize!