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 gc 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 super 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:gc characterEncoding into:encodingSymOrNil. |
2737 encoder := CharacterEncoder encoderToEncodeFrom:gc 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 |
4998 |sel| |
4973 |sel| |
4999 |
4974 |
5000 selectionStartLine isNil ifTrue:[^ nil]. |
4975 selectionStartLine isNil ifTrue:[^ nil]. |
5001 sel := self textFromLine:selectionStartLine col:(selectionStartCol max:1) toLine:selectionEndLine col:selectionEndCol. |
4976 sel := self textFromLine:selectionStartLine col:(selectionStartCol max:1) toLine:selectionEndLine col:selectionEndCol. |
5002 sel notEmptyOrNil ifTrue:[ |
4977 sel notEmptyOrNil ifTrue:[ |
5003 (gc characterEncoding ? #'iso10646-1' "eg unicode") ~~ #'iso10646-1' ifTrue:[ |
4978 "/ this is rubbish; we are now always using unicode internally |
5004 sel := sel encodeFrom:gc characterEncoding into:#'iso10646-1' |
4979 "/ any many more conversions would be needed at many places... |
|
4980 (gc characterEncoding ? #'iso10646-1' "eg unicode") ~~ #'iso10646-1' ifTrue:[ |
|
4981 sel := sel encodeFrom:gc characterEncoding into:#'iso10646-1' |
5005 ]. |
4982 ]. |
5006 ]. |
4983 ]. |
5007 ^ sel |
4984 ^ sel |
5008 |
4985 |
5009 "Modified (comment): / 25-01-2012 / 00:29:09 / cg" |
4986 "Modified (comment): / 25-01-2012 / 00:29:09 / cg" |
5018 sel := sel collect:[:each| each isNil ifTrue:[nil] ifFalse:[each string]]. |
4995 sel := sel collect:[:each| each isNil ifTrue:[nil] ifFalse:[each string]]. |
5019 ^ (sel asStringWithCRsFrom:1 to:(sel size) compressTabs:false withCR:false) string |
4996 ^ (sel asStringWithCRsFrom:1 to:(sel size) compressTabs:false withCR:false) string |
5020 ! |
4997 ! |
5021 |
4998 |
5022 selectionChanged |
4999 selectionChanged |
5023 "can be redefined for notification or special actions" |
5000 "can be redefined for notification or special actions. |
5024 |
5001 If you do, do not forget to do a super selectionChanged" |
5025 "Modified: / 17-04-2012 / 20:59:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
5002 |
|
5003 self changed:#selection. |
|
5004 "/ self selectionHolder value:{ selectionStartCol @ selectionStartLine . |
|
5005 "/ selectionEndCol @ selectionEndLine } |
5026 ! |
5006 ! |
5027 |
5007 |
5028 selectionEndCol |
5008 selectionEndCol |
5029 ^ selectionEndCol |
5009 ^ selectionEndCol |
5030 ! |
5010 ! |