TextView.st
changeset 5658 bfc80e89fb1a
parent 5612 513fa58e4761
child 5660 d6040b3f1a37
child 5675 7bf31ecf9aa3
equal deleted inserted replaced
5657:57b354293970 5658:bfc80e89fb1a
   883     "Created: / 19.6.1998 / 00:22:08 / cg"
   883     "Created: / 19.6.1998 / 00:22:08 / cg"
   884 ! !
   884 ! !
   885 
   885 
   886 !TextView methodsFor:'accessing'!
   886 !TextView methodsFor:'accessing'!
   887 
   887 
   888 characterEncoding:encodingArg
       
   889     "define how the contents is encoded internally.
       
   890      This should normally never be required, as ST/X now assumes
       
   891      unicode (of which iso8859-1 is a subset) encoding.
       
   892      The possibility to change the characterEncoding is provided as
       
   893      a backward compatibility hook for programs which want to use
       
   894      another encoding internally."
       
   895 
       
   896     |encodingSymOrNil|
       
   897 
       
   898     encodingSymOrNil := encodingArg isNil
       
   899                             ifTrue:[#'iso10646-1']
       
   900                             ifFalse:[encodingArg asSymbol].
       
   901 
       
   902     characterEncoding ~~ encodingSymOrNil ifTrue:[
       
   903         "/ TODO: reencode contents if required.
       
   904 "/        (list size ~~ 0
       
   905 "/        and:[ list contains:[:line | line size > 0]]) ifTrue:[
       
   906 "/            (self confirm:(resources stringWithCRs:'Your text may need to be re-coded - this is not yet supported.\\Proceed ?'))
       
   907 "/            ifFalse:[^ self].
       
   908 "/        ].
       
   909         characterEncoding := encodingSymOrNil.
       
   910     ].
       
   911 
       
   912     "Modified (format): / 25-01-2012 / 00:28:27 / cg"
       
   913 !
       
   914 
       
   915 characterPositionOfSelection
   888 characterPositionOfSelection
   916     "return the character index of the first character in the selection.
   889     "return the character index of the first character in the selection.
   917      Returns 0 if there is no selection."
   890      Returns 0 if there is no selection."
   918 
   891 
   919     selectionStartLine isNil ifTrue:[^ 0].
   892     selectionStartLine isNil ifTrue:[^ 0].
  2757 
  2730 
  2758     |startNr nLines string encoder|
  2731     |startNr nLines string encoder|
  2759 
  2732 
  2760     self removeTrailingWhitespace.
  2733     self removeTrailingWhitespace.
  2761 
  2734 
       
  2735     "/ This is now obsolete, as we are always using unicode internally.
       
  2736     "/ so the following line should be changed to encoderToEncodeFrom:unicode to:xxx.
  2762     encoder := CharacterEncoder encoderToEncodeFrom:characterEncoding into:encodingSymOrNil.
  2737     encoder := CharacterEncoder encoderToEncodeFrom:characterEncoding into:encodingSymOrNil.
  2763     encoder isNullEncoder ifTrue:[
  2738     encoder isNullEncoder ifTrue:[
  2764         (list contains:[:lineOrNil|
  2739         (list contains:[:lineOrNil|
  2765                             |s|
  2740                             |s|
  2766                             lineOrNil notNil
  2741                             lineOrNil notNil
  4991     |sel|
  4966     |sel|
  4992 
  4967 
  4993     selectionStartLine isNil ifTrue:[^ nil].
  4968     selectionStartLine isNil ifTrue:[^ nil].
  4994     sel := self textFromLine:selectionStartLine col:(selectionStartCol max:1) toLine:selectionEndLine col:selectionEndCol.
  4969     sel := self textFromLine:selectionStartLine col:(selectionStartCol max:1) toLine:selectionEndLine col:selectionEndCol.
  4995     sel notEmptyOrNil ifTrue:[
  4970     sel notEmptyOrNil ifTrue:[
       
  4971         "/ this is rubbish; we are now always using unicode internally
       
  4972         "/ any many more conversions would be needed at many places...
  4996         (characterEncoding ? #'iso10646-1' "eg unicode") ~~ #'iso10646-1' ifTrue:[
  4973         (characterEncoding ? #'iso10646-1' "eg unicode") ~~ #'iso10646-1' ifTrue:[
  4997             sel := sel encodeFrom:characterEncoding into:#'iso10646-1'
  4974             sel := sel encodeFrom:characterEncoding into:#'iso10646-1'
  4998         ].
  4975         ].
  4999     ].
  4976     ].
  5000     ^ sel
  4977     ^ sel
  5011     sel := sel collect:[:each| each isNil ifTrue:[nil] ifFalse:[each string]].
  4988     sel := sel collect:[:each| each isNil ifTrue:[nil] ifFalse:[each string]].
  5012     ^ (sel asStringWithCRsFrom:1 to:(sel size) compressTabs:false withCR:false) string
  4989     ^ (sel asStringWithCRsFrom:1 to:(sel size) compressTabs:false withCR:false) string
  5013 !
  4990 !
  5014 
  4991 
  5015 selectionChanged
  4992 selectionChanged
  5016     "can be redefined for notification or special actions"
  4993     "can be redefined for notification or special actions.
  5017 
  4994      If you do, do not forget to do a super selectionChanged"
  5018     "Modified: / 17-04-2012 / 20:59:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  4995 
       
  4996     self changed:#selection.
       
  4997 "/    self selectionHolder value:{ selectionStartCol @ selectionStartLine .
       
  4998 "/                                 selectionEndCol @ selectionEndLine }
  5019 !
  4999 !
  5020 
  5000 
  5021 selectionEndCol
  5001 selectionEndCol
  5022     ^ selectionEndCol
  5002     ^ selectionEndCol
  5023 !
  5003 !