TextView.st
changeset 3318 ebd115677fd5
parent 3316 1ef036eee59f
child 3394 39086a24097b
equal deleted inserted replaced
3317:1a45a2a1a47c 3318:ebd115677fd5
     1 "
     1 "
     2  COPYRIGHT (c) 1989 by Claus Gittinger
     2  COPYRIGHT (c) 1989 by Claus Gittinger
     3 	      All Rights Reserved
     3               All Rights Reserved
     4 
     4 
     5  This software is furnished under a license and may be used
     5  This software is furnished under a license and may be used
     6  only in accordance with the terms of that license and with the
     6  only in accordance with the terms of that license and with the
     7  inclusion of the above copyright notice.   This software may not
     7  inclusion of the above copyright notice.   This software may not
     8  be provided or otherwise made available to, or used by, any
     8  be provided or otherwise made available to, or used by, any
    11 "
    11 "
    12 
    12 
    13 "{ Package: 'stx:libwidg' }"
    13 "{ Package: 'stx:libwidg' }"
    14 
    14 
    15 ListView subclass:#TextView
    15 ListView subclass:#TextView
    16 	instanceVariableNames:'selectionStartLine selectionStartCol selectionEndLine
    16         instanceVariableNames:'selectionStartLine selectionStartCol selectionEndLine
    17 		selectionEndCol clickPos clickStartLine clickStartCol clickLine
    17                 selectionEndCol clickPos clickStartLine clickStartCol clickLine
    18 		clickCol clickCount expandingTop wordStartCol wordStartLine
    18                 clickCol clickCount expandingTop wordStartCol wordStartLine
    19 		wordEndCol wordEndLine selectionFgColor selectionBgColor
    19                 wordEndCol wordEndLine selectionFgColor selectionBgColor
    20 		selectStyle directoryForFileDialog defaultFileNameForFileDialog
    20                 selectStyle directoryForFileDialog defaultFileNameForFileDialog
    21 		externalEncoding contentsWasSaved searchAction lastSearchPattern
    21                 externalEncoding contentsWasSaved searchAction lastSearchPattern
    22 		lastSearchIgnoredCase lastSearchDirection
    22                 lastSearchIgnoredCase lastSearchDirection
    23 		parenthesisSpecification dropSource dragIsActive saveAction
    23                 parenthesisSpecification dropSource dragIsActive saveAction
    24 		st80SelectMode'
    24                 st80SelectMode'
    25 	classVariableNames:'DefaultViewBackground DefaultSelectionForegroundColor
    25         classVariableNames:'DefaultViewBackground DefaultSelectionForegroundColor
    26 		DefaultSelectionBackgroundColor
    26                 DefaultSelectionBackgroundColor
    27 		DefaultAlternativeSelectionForegroundColor
    27                 DefaultAlternativeSelectionForegroundColor
    28 		DefaultAlternativeSelectionBackgroundColor MatchDelayTime
    28                 DefaultAlternativeSelectionBackgroundColor MatchDelayTime
    29 		WordSelectCatchesBlanks LastSearchPatterns
    29                 WordSelectCatchesBlanks LastSearchPatterns
    30 		NumRememberedSearchPatterns LastSearchIgnoredCase
    30                 NumRememberedSearchPatterns LastSearchIgnoredCase
    31 		DefaultParenthesisSpecification'
    31                 DefaultParenthesisSpecification'
    32 	poolDictionaries:''
    32         poolDictionaries:''
    33 	category:'Views-Text'
    33         category:'Views-Text'
    34 !
    34 !
    35 
    35 
    36 !TextView class methodsFor:'documentation'!
    36 !TextView class methodsFor:'documentation'!
    37 
    37 
    38 copyright
    38 copyright
    39 "
    39 "
    40  COPYRIGHT (c) 1989 by Claus Gittinger
    40  COPYRIGHT (c) 1989 by Claus Gittinger
    41 	      All Rights Reserved
    41               All Rights Reserved
    42 
    42 
    43  This software is furnished under a license and may be used
    43  This software is furnished under a license and may be used
    44  only in accordance with the terms of that license and with the
    44  only in accordance with the terms of that license and with the
    45  inclusion of the above copyright notice.   This software may not
    45  inclusion of the above copyright notice.   This software may not
    46  be provided or otherwise made available to, or used by, any
    46  be provided or otherwise made available to, or used by, any
   124     although textViews (and instances of subclasses) are mostly used
   124     although textViews (and instances of subclasses) are mostly used
   125     as components (in the fileBrowser, the browser, the launcher etc.),
   125     as components (in the fileBrowser, the browser, the launcher etc.),
   126     they may also be opened as a textEditor;
   126     they may also be opened as a textEditor;
   127 
   127 
   128     open a (readonly) textView on some information text:
   128     open a (readonly) textView on some information text:
   129 							[exBegin]
   129                                                         [exBegin]
   130 	TextView 
   130         TextView 
   131 	    openWith:'read this' 
   131             openWith:'read this' 
   132 	    title:'demonstration'
   132             title:'demonstration'
   133 							[exEnd]
   133                                                         [exEnd]
   134 
   134 
   135     the same, but open it modal:
   135     the same, but open it modal:
   136 							[exBegin]
   136                                                         [exBegin]
   137 	TextView 
   137         TextView 
   138 	    openModalWith:'read this first' 
   138             openModalWith:'read this first' 
   139 	    title:'demonstration'
   139             title:'demonstration'
   140 							[exEnd]
   140                                                         [exEnd]
   141 
   141 
   142 
   142 
   143     open it modal (but editable) on some text:
   143     open it modal (but editable) on some text:
   144     (must accept before closing)
   144     (must accept before closing)
   145     This is somewhat kludgy - when closed, the view has already
   145     This is somewhat kludgy - when closed, the view has already
   146     nilled its link to the model. Therefore, the accept must be
   146     nilled its link to the model. Therefore, the accept must be
   147     done 'manually' below.
   147     done 'manually' below.
   148     However, usually an applicationModel is installed as the
   148     However, usually an applicationModel is installed as the
   149     editor-topViews application. This would get a closeRequest,
   149     editor-topViews application. This would get a closeRequest,
   150     where it could handle things.
   150     where it could handle things.
   151 							[exBegin]
   151                                                         [exBegin]
   152 	|m textView|
   152         |m textView|
   153 
   153 
   154 	m := 'read this first' asValue.
   154         m := 'read this first' asValue.
   155 	textView := EditTextView openModalOnModel:m.
   155         textView := EditTextView openModalOnModel:m.
   156 	textView modified ifTrue:[
   156         textView modified ifTrue:[
   157 	    (self confirm:'text was not accepted - do it now ?')
   157             (self confirm:'text was not accepted - do it now ?')
   158 	    ifTrue:[
   158             ifTrue:[
   159 		m value:textView contents
   159                 m value:textView contents
   160 	    ]
   160             ]
   161 	].
   161         ].
   162 
   162 
   163 	Transcript showCR:m value.
   163         Transcript showCR:m value.
   164 							[exEnd]
   164                                                         [exEnd]
   165 
   165 
   166 
   166 
   167     open a textEditor on some file:
   167     open a textEditor on some file:
   168 							[exBegin]
   168                                                         [exBegin]
   169 	EditTextView openOn:'Makefile'
   169         EditTextView openOn:'Makefile'
   170 							[exEnd]
   170                                                         [exEnd]
   171 
   171 
   172 "
   172 "
   173 
   173 
   174 ! !
   174 ! !
   175 
   175 
   177 
   177 
   178 on:aModel aspect:aspect change:change menu:menu initialSelection:initial
   178 on:aModel aspect:aspect change:change menu:menu initialSelection:initial
   179     "for ST-80 compatibility"
   179     "for ST-80 compatibility"
   180 
   180 
   181     ^ (self new) 
   181     ^ (self new) 
   182 	on:aModel 
   182         on:aModel 
   183 	aspect:aspect
   183         aspect:aspect
   184 	list:aspect
   184         list:aspect
   185 	change:change 
   185         change:change 
   186 	menu:menu
   186         menu:menu
   187 	initialSelection:initial
   187         initialSelection:initial
   188 !
   188 !
   189 
   189 
   190 with:someText
   190 with:someText
   191     ^ (self new) 
   191     ^ (self new) 
   192         contents:someText 
   192         contents:someText 
   542 
   542 
   543     label := 'unnamed'.
   543     label := 'unnamed'.
   544     top := StandardSystemView label:label icon:self defaultIcon.
   544     top := StandardSystemView label:label icon:self defaultIcon.
   545 
   545 
   546     frame := HVScrollableView 
   546     frame := HVScrollableView 
   547 		for:self 
   547                 for:self 
   548 		miniScrollerH:true miniScrollerV:false
   548                 miniScrollerH:true miniScrollerV:false
   549 		in:top.
   549                 in:top.
   550     frame origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
   550     frame origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
   551     ^ frame scrolledView
   551     ^ frame scrolledView
   552 
   552 
   553     "Modified: 23.5.1965 / 14:12:32 / cg"
   553     "Modified: 23.5.1965 / 14:12:32 / cg"
   554 !
   554 !
   559     |top textView f|
   559     |top textView f|
   560 
   560 
   561     textView := self setupEmpty.
   561     textView := self setupEmpty.
   562     top := textView topView.
   562     top := textView topView.
   563     aFileName notNil ifTrue:[
   563     aFileName notNil ifTrue:[
   564 	f := aFileName asFilename.
   564         f := aFileName asFilename.
   565 	top label:(f baseName).
   565         top label:(f baseName).
   566 	textView contents:(f contents).
   566         textView contents:(f contents).
   567     ].
   567     ].
   568 
   568 
   569     ^ textView
   569     ^ textView
   570 
   570 
   571     "Created: 14.2.1997 / 15:21:43 / cg"
   571     "Created: 14.2.1997 / 15:21:43 / cg"
   591     textView := self setupEmpty.
   591     textView := self setupEmpty.
   592     top := textView topView.
   592     top := textView topView.
   593     aTitle notNil ifTrue:[top label:aTitle].
   593     aTitle notNil ifTrue:[top label:aTitle].
   594 
   594 
   595     aStringOrStringCollection notNil ifTrue:[
   595     aStringOrStringCollection notNil ifTrue:[
   596 	textView contents:aStringOrStringCollection
   596         textView contents:aStringOrStringCollection
   597     ].
   597     ].
   598 
   598 
   599     ^ textView
   599     ^ textView
   600 
   600 
   601     "Created: 9.9.1996 / 19:31:22 / cg"
   601     "Created: 9.9.1996 / 19:31:22 / cg"
   672     "return the character index of the first character in the selection.
   672     "return the character index of the first character in the selection.
   673      Returns 0 if there is no selection."
   673      Returns 0 if there is no selection."
   674 
   674 
   675     selectionStartLine isNil ifTrue:[^ 0].
   675     selectionStartLine isNil ifTrue:[^ 0].
   676     ^ self characterPositionOfLine:selectionStartLine
   676     ^ self characterPositionOfLine:selectionStartLine
   677 			       col:selectionStartCol
   677                                col:selectionStartCol
   678 
   678 
   679     "Modified: 14.8.1997 / 16:35:37 / cg"
   679     "Modified: 14.8.1997 / 16:35:37 / cg"
   680 !
   680 !
   681 
   681 
   682 characterPositionOfSelectionEnd
   682 characterPositionOfSelectionEnd
   817     selStyle := selectStyle.
   817     selStyle := selectStyle.
   818 
   818 
   819     super setContents:something.
   819     super setContents:something.
   820 
   820 
   821     selStartLine notNil ifTrue:[
   821     selStartLine notNil ifTrue:[
   822 	self 
   822         self 
   823 	    selectFromLine:selStartLine col:selStartCol
   823             selectFromLine:selStartLine col:selStartCol
   824 	    toLine:selEndLine col:selEndCol.
   824             toLine:selEndLine col:selEndCol.
   825     ].
   825     ].
   826 
   826 
   827     selectStyle := selStyle
   827     selectStyle := selStyle
   828 
   828 
   829     "Modified: / 31.3.1998 / 23:33:21 / cg"
   829     "Modified: / 31.3.1998 / 23:33:21 / cg"
   859     thisCharacter := self characterAtLine:selectLine col:beginCol.
   859     thisCharacter := self characterAtLine:selectLine col:beginCol.
   860 
   860 
   861     beginCol := self findBeginOfWordAtLine:selectLine col:selectCol.
   861     beginCol := self findBeginOfWordAtLine:selectLine col:selectCol.
   862     endCol := self findEndOfWordAtLine:selectLine col:selectCol.
   862     endCol := self findEndOfWordAtLine:selectLine col:selectCol.
   863     endCol == 0 ifTrue:[
   863     endCol == 0 ifTrue:[
   864 	endLine := selectLine + 1
   864         endLine := selectLine + 1
   865     ].
   865     ].
   866 
   866 
   867     "is the initial character within a word ?"
   867     "is the initial character within a word ?"
   868     (wordCheck value:thisCharacter) ifTrue:[
   868     (wordCheck value:thisCharacter) ifTrue:[
   869 	"
   869         "
   870 	 try to catch a blank ...
   870          try to catch a blank ...
   871 	"
   871         "
   872 
   872 
   873 	WordSelectCatchesBlanks ifTrue:[
   873         WordSelectCatchesBlanks ifTrue:[
   874 	    ((beginCol == 1)
   874             ((beginCol == 1)
   875 	    or:[(self characterAtLine:selectLine col:(beginCol - 1))
   875             or:[(self characterAtLine:selectLine col:(beginCol - 1))
   876 		 ~~ Character space]) ifTrue:[
   876                  ~~ Character space]) ifTrue:[
   877 		((self characterAtLine:selectLine col:(endCol + 1))
   877                 ((self characterAtLine:selectLine col:(endCol + 1))
   878 		  == Character space) ifTrue:[
   878                   == Character space) ifTrue:[
   879 		    endCol := endCol + 1.
   879                     endCol := endCol + 1.
   880 		    flag := #wordRight
   880                     flag := #wordRight
   881 		]
   881                 ]
   882 	    ] ifFalse:[
   882             ] ifFalse:[
   883 		beginCol := beginCol - 1.
   883                 beginCol := beginCol - 1.
   884 		flag := #wordLeft
   884                 flag := #wordLeft
   885 	    ].
   885             ].
   886 	].
   886         ].
   887     ].
   887     ].
   888     aFiveArgBlock value:selectLine 
   888     aFiveArgBlock value:selectLine 
   889 		  value:beginCol 
   889                   value:beginCol 
   890 		  value:endLine 
   890                   value:endLine 
   891 		  value:endCol
   891                   value:endCol
   892 		  value:flag
   892                   value:flag
   893 
   893 
   894     "Modified: 18.3.1996 / 17:31:04 / cg"
   894     "Modified: 18.3.1996 / 17:31:04 / cg"
   895 ! !
   895 ! !
   896 
   896 
   897 !TextView methodsFor:'accessing-look'!
   897 !TextView methodsFor:'accessing-look'!
   927 on:aModel aspect:aspectSym list:listSym change:changeSym menu:menuSym initialSelection:initial
   927 on:aModel aspect:aspectSym list:listSym change:changeSym menu:menuSym initialSelection:initial
   928     "set all of model, aspect, listMessage, changeSymbol, menySymbol
   928     "set all of model, aspect, listMessage, changeSymbol, menySymbol
   929      and selection. Added for ST-80 compatibility"
   929      and selection. Added for ST-80 compatibility"
   930 
   930 
   931     aspectSym notNil ifTrue:[aspectMsg := aspectSym. 
   931     aspectSym notNil ifTrue:[aspectMsg := aspectSym. 
   932 			     listMsg isNil ifTrue:[listMsg := aspectSym]].
   932                              listMsg isNil ifTrue:[listMsg := aspectSym]].
   933     changeSym notNil ifTrue:[changeMsg := changeSym].
   933     changeSym notNil ifTrue:[changeMsg := changeSym].
   934     listSym notNil ifTrue:[listMsg := listSym].
   934     listSym notNil ifTrue:[listMsg := listSym].
   935     menuSym notNil ifTrue:[menuMsg := menuSym].
   935     menuSym notNil ifTrue:[menuMsg := menuSym].
   936 "/    initial notNil ifTrue:[initialSelectionMsg := initial].
   936 "/    initial notNil ifTrue:[initialSelectionMsg := initial].
   937     self model:aModel.
   937     self model:aModel.
  1632     viewBackground := DefaultViewBackground.
  1632     viewBackground := DefaultViewBackground.
  1633     selectionFgColor := DefaultSelectionForegroundColor.
  1633     selectionFgColor := DefaultSelectionForegroundColor.
  1634     selectionFgColor isNil ifTrue:[selectionFgColor := bgColor].
  1634     selectionFgColor isNil ifTrue:[selectionFgColor := bgColor].
  1635     selectionBgColor := DefaultSelectionBackgroundColor.
  1635     selectionBgColor := DefaultSelectionBackgroundColor.
  1636     selectionBgColor isNil ifTrue:[
  1636     selectionBgColor isNil ifTrue:[
  1637 	device hasColors ifTrue:[
  1637         device hasColors ifTrue:[
  1638 	    DefaultSelectionForegroundColor isNil ifTrue:[
  1638             DefaultSelectionForegroundColor isNil ifTrue:[
  1639 		selectionFgColor := fgColor
  1639                 selectionFgColor := fgColor
  1640 	    ].
  1640             ].
  1641 	    selectionBgColor := Color green
  1641             selectionBgColor := Color green
  1642 	] ifFalse:[
  1642         ] ifFalse:[
  1643 	    device hasGrayscales ifTrue:[
  1643             device hasGrayscales ifTrue:[
  1644 		DefaultSelectionForegroundColor isNil ifTrue:[
  1644                 DefaultSelectionForegroundColor isNil ifTrue:[
  1645 		    selectionFgColor := fgColor
  1645                     selectionFgColor := fgColor
  1646 		].
  1646                 ].
  1647 		selectionBgColor := Color grey
  1647                 selectionBgColor := Color grey
  1648 	    ] ifFalse:[
  1648             ] ifFalse:[
  1649 		selectionBgColor := fgColor
  1649                 selectionBgColor := fgColor
  1650 	    ]
  1650             ]
  1651 	]
  1651         ]
  1652     ].
  1652     ].
  1653 
  1653 
  1654     "Modified: 22.1.1997 / 11:57:53 / cg"
  1654     "Modified: 22.1.1997 / 11:57:53 / cg"
  1655 !
  1655 !
  1656 
  1656 
  1920 
  1920 
  1921     "
  1921     "
  1922      Q: is it a good idea to preserve the last searchstring between views ?
  1922      Q: is it a good idea to preserve the last searchstring between views ?
  1923     "
  1923     "
  1924 
  1924 
  1925     |searchBox patternHolder caseHolder 
  1925     |searchBox patternHolder caseHolder fwd ign initialString
  1926      pattern fwd ign initialString
       
  1927      bindings bldr search modal|
  1926      bindings bldr search modal|
  1928 
  1927 
  1929     modal := (UserPreferences current searchDialogIsModal).   "/ thats experimental
  1928     modal := (UserPreferences current searchDialogIsModal).   "/ thats experimental
  1930 
  1929 
  1931     ign := lastSearchIgnoredCase ? LastSearchIgnoredCase ? true.
  1930     ign := lastSearchIgnoredCase ? LastSearchIgnoredCase ? true.
  1950     ].
  1949     ].
  1951 
  1950 
  1952     fwd := true. 
  1951     fwd := true. 
  1953 
  1952 
  1954     search := [:fwd |
  1953     search := [:fwd |
  1955         pattern := patternHolder value.
  1954         self search:patternHolder value ignoreCase:caseHolder value forward:fwd.
  1956         pattern := pattern string. "/ is that a good idea ?
       
  1957         pattern notEmpty ifTrue:[
       
  1958             self rememberSearchPattern:pattern.
       
  1959 
       
  1960             ign := caseHolder value.
       
  1961             LastSearchIgnoredCase := ign.
       
  1962 
       
  1963             fwd ifFalse:[
       
  1964                 lastSearchDirection := #backward.
       
  1965                 self searchBwd:pattern ignoreCase:ign.
       
  1966             ] ifTrue:[
       
  1967                 lastSearchDirection := #forward.
       
  1968                 self searchFwd:pattern ignoreCase:ign.
       
  1969             ]
       
  1970         ]
       
  1971     ].
  1955     ].
  1972 
  1956 
  1973     bindings := IdentityDictionary new.
  1957     bindings := IdentityDictionary new.
  1974     bindings at:#searchPattern put:patternHolder.
  1958     bindings at:#searchPattern put:patternHolder.
  1975     modal ifTrue:[
  1959     modal ifTrue:[
  2013                 openInGroup:(self windowGroup).
  1997                 openInGroup:(self windowGroup).
  2014 
  1998 
  2015         "/ searchBox window open.
  1999         "/ searchBox window open.
  2016         searchBox window assignKeyboardFocusToFirstInputField.
  2000         searchBox window assignKeyboardFocusToFirstInputField.
  2017     ]
  2001     ]
       
  2002 
       
  2003     "Modified: / 11-07-2006 / 11:18:38 / fm"
       
  2004 !
       
  2005 
       
  2006 search:patternArg ignoreCase:ign forward:fwd 
       
  2007     |pattern|
       
  2008 
       
  2009     pattern := patternArg string.
       
  2010     pattern notEmpty ifTrue:[
       
  2011         self rememberSearchPattern:pattern.
       
  2012         LastSearchIgnoredCase := ign.
       
  2013         fwd ifFalse:[
       
  2014             lastSearchDirection := #backward.
       
  2015             self searchBwd:pattern ignoreCase:ign.
       
  2016         ] ifTrue:[
       
  2017             lastSearchDirection := #forward.
       
  2018             self searchFwd:pattern ignoreCase:ign.
       
  2019         ]
       
  2020     ]
       
  2021 
       
  2022     "Created: / 11-07-2006 / 11:18:04 / fm"
  2018 ! !
  2023 ! !
  2019 
  2024 
  2020 !TextView methodsFor:'private'!
  2025 !TextView methodsFor:'private'!
  2021 
  2026 
  2022 currentSelectionBgColor
  2027 currentSelectionBgColor
  2029 
  2034 
  2030 fileOutContentsOn:aStream
  2035 fileOutContentsOn:aStream
  2031     "save contents on a stream, replacing leading spaces by tab-characters."
  2036     "save contents on a stream, replacing leading spaces by tab-characters."
  2032 
  2037 
  2033     self 
  2038     self 
  2034 	fileOutContentsOn:aStream 
  2039         fileOutContentsOn:aStream 
  2035 	compressTabs:true
  2040         compressTabs:true
  2036 !
  2041 !
  2037 
  2042 
  2038 fileOutContentsOn:aStream compressTabs:compressTabs
  2043 fileOutContentsOn:aStream compressTabs:compressTabs
  2039     "save contents on a stream. If compressTabs is true,
  2044     "save contents on a stream. If compressTabs is true,
  2040      leading spaces will be replaced by tab-characters in the output."
  2045      leading spaces will be replaced by tab-characters in the output."
  2041 
  2046 
  2042     self 
  2047     self 
  2043 	fileOutContentsOn:aStream 
  2048         fileOutContentsOn:aStream 
  2044 	compressTabs:compressTabs 
  2049         compressTabs:compressTabs 
  2045 	encoding:nil
  2050         encoding:nil
  2046 !
  2051 !
  2047 
  2052 
  2048 fileOutContentsOn:aStream compressTabs:compressTabs encoding:encodingSymOrNil
  2053 fileOutContentsOn:aStream compressTabs:compressTabs encoding:encodingSymOrNil
  2049     "save contents on a stream. If compressTabs is true,
  2054     "save contents on a stream. If compressTabs is true,
  2050      leading spaces will be replaced by tab-characters in the output."
  2055      leading spaces will be replaced by tab-characters in the output."
  2158     "make new selection immediately visible"
  2163     "make new selection immediately visible"
  2159     prevEndLine := selectionEndLine.
  2164     prevEndLine := selectionEndLine.
  2160     selectionEndLine := firstLineShown + nFullLinesShown.
  2165     selectionEndLine := firstLineShown + nFullLinesShown.
  2161     selectionEndCol := 0.
  2166     selectionEndCol := 0.
  2162     prevEndLine to:selectionEndLine do:[:lineNr |
  2167     prevEndLine to:selectionEndLine do:[:lineNr |
  2163 	self redrawLine:lineNr
  2168         self redrawLine:lineNr
  2164     ].
  2169     ].
  2165     Processor addTimedBlock:autoScrollBlock afterSeconds:autoScrollDeltaT.
  2170     Processor addTimedBlock:autoScrollBlock afterSeconds:autoScrollDeltaT.
  2166 !
  2171 !
  2167 
  2172 
  2168 scrollSelectLeft
  2173 scrollSelectLeft
  2210     "make new selection immediately visible"
  2215     "make new selection immediately visible"
  2211     prevStartLine := selectionStartLine.
  2216     prevStartLine := selectionStartLine.
  2212     selectionStartLine := firstLineShown.
  2217     selectionStartLine := firstLineShown.
  2213     selectionStartCol := 1.
  2218     selectionStartCol := 1.
  2214     selectionStartLine to:prevStartLine do:[:lineNr |
  2219     selectionStartLine to:prevStartLine do:[:lineNr |
  2215 	self redrawLine:lineNr
  2220         self redrawLine:lineNr
  2216     ].
  2221     ].
  2217     Processor addTimedBlock:autoScrollBlock afterSeconds:autoScrollDeltaT.
  2222     Processor addTimedBlock:autoScrollBlock afterSeconds:autoScrollDeltaT.
  2218 !
  2223 !
  2219 
  2224 
  2220 stopScrollSelect
  2225 stopScrollSelect
  2221     "stop auto scroll; deinstall timed-block"
  2226     "stop auto scroll; deinstall timed-block"
  2222 
  2227 
  2223     autoScrollBlock notNil ifTrue:[
  2228     autoScrollBlock notNil ifTrue:[
  2224 	Processor removeTimedBlock:autoScrollBlock.
  2229         Processor removeTimedBlock:autoScrollBlock.
  2225 	self compressMotionEvents:true.
  2230         self compressMotionEvents:true.
  2226 	autoScrollBlock := nil.
  2231         autoScrollBlock := nil.
  2227 	autoScrollDeltaT := nil
  2232         autoScrollDeltaT := nil
  2228     ]
  2233     ]
  2229 !
  2234 !
  2230 
  2235 
  2231 widthForScrollBetween:firstLine and:lastLine
  2236 widthForScrollBetween:firstLine and:lastLine
  2232     "return the width in pixels for a scroll between firstLine and lastLine"
  2237     "return the width in pixels for a scroll between firstLine and lastLine"
  2233 
  2238 
  2234     selectionStartLine notNil ifTrue:[
  2239     selectionStartLine notNil ifTrue:[
  2235 	(lastLine < selectionStartLine) ifFalse:[
  2240         (lastLine < selectionStartLine) ifFalse:[
  2236 	    (firstLine > selectionEndLine) ifFalse:[
  2241             (firstLine > selectionEndLine) ifFalse:[
  2237 		^ width
  2242                 ^ width
  2238 	    ]
  2243             ]
  2239 	]
  2244         ]
  2240     ].
  2245     ].
  2241     ^ super widthForScrollBetween:firstLine and:lastLine
  2246     ^ super widthForScrollBetween:firstLine and:lastLine
  2242 ! !
  2247 ! !
  2243 
  2248 
  2244 !TextView methodsFor:'queries'!
  2249 !TextView methodsFor:'queries'!
  2262 
  2267 
  2263 clearMarginOfVisibleLine:visLine with:color
  2268 clearMarginOfVisibleLine:visLine with:color
  2264     "if there is a margin, clear it - a helper for selection drawing"
  2269     "if there is a margin, clear it - a helper for selection drawing"
  2265 
  2270 
  2266     (leftMargin ~~ 0) ifTrue:[
  2271     (leftMargin ~~ 0) ifTrue:[
  2267 	self paint:color.
  2272         self paint:color.
  2268 	self fillRectangleX:margin
  2273         self fillRectangleX:margin
  2269 			  y:(self yOfVisibleLine:visLine)
  2274                           y:(self yOfVisibleLine:visLine)
  2270 		      width:leftMargin
  2275                       width:leftMargin
  2271 		     height:fontHeight
  2276                      height:fontHeight
  2272     ]
  2277     ]
  2273 
  2278 
  2274     "Created: 6.3.1996 / 14:22:55 / cg"
  2279     "Created: 6.3.1996 / 14:22:55 / cg"
  2275 !
  2280 !
  2276 
  2281 
  3359 
  3364 
  3360     |realPattern|
  3365     |realPattern|
  3361 
  3366 
  3362     realPattern := pattern.
  3367     realPattern := pattern.
  3363     (realPattern startsWith:$*) ifTrue:[
  3368     (realPattern startsWith:$*) ifTrue:[
  3364 	realPattern := realPattern copyFrom:2
  3369         realPattern := realPattern copyFrom:2
  3365     ].
  3370     ].
  3366     (realPattern endsWith:$*) ifTrue:[
  3371     (realPattern endsWith:$*) ifTrue:[
  3367 	realPattern := realPattern copyWithoutLast:1
  3372         realPattern := realPattern copyWithoutLast:1
  3368     ].
  3373     ].
  3369 
  3374 
  3370     self selectFromLine:line col:col
  3375     self selectFromLine:line col:col
  3371 		 toLine:line col:(col + realPattern size - 1).
  3376                  toLine:line col:(col + realPattern size - 1).
  3372     self makeLineVisible:line
  3377     self makeLineVisible:line
  3373 !
  3378 !
  3374 
  3379 
  3375 showNotFound
  3380 showNotFound
  3376     "search not found - tell user by beeping and changing
  3381     "search not found - tell user by beeping and changing
  3650 selectFromLine:startLine col:startCol toLine:endLine col:endCol
  3655 selectFromLine:startLine col:startCol toLine:endLine col:endCol
  3651     "select a piece of text and redraw that area"
  3656     "select a piece of text and redraw that area"
  3652 
  3657 
  3653     self unselect.
  3658     self unselect.
  3654     startLine notNil ifTrue:[
  3659     startLine notNil ifTrue:[
  3655 	"new:"
  3660         "new:"
  3656 	endLine < startLine ifTrue:[
  3661         endLine < startLine ifTrue:[
  3657 	    ^ self selectFromLine:endLine col:endCol toLine:startLine col:startCol
  3662             ^ self selectFromLine:endLine col:endCol toLine:startLine col:startCol
  3658 	].
  3663         ].
  3659 	(endLine == startLine and:[endCol < startCol]) ifTrue:[
  3664         (endLine == startLine and:[endCol < startCol]) ifTrue:[
  3660 	    endCol ~~ 0 ifTrue:[
  3665             endCol ~~ 0 ifTrue:[
  3661 		self selectFromLine:endLine col:endCol toLine:startLine col:startCol.
  3666                 self selectFromLine:endLine col:endCol toLine:startLine col:startCol.
  3662 	    ].
  3667             ].
  3663 	    ^ self
  3668             ^ self
  3664 	].
  3669         ].
  3665 
  3670 
  3666 " old:
  3671 " old:
  3667 	endLine < startLine ifTrue:[^ self].
  3672         endLine < startLine ifTrue:[^ self].
  3668 	(startLine == endLine and:[endCol < startCol]) ifTrue:[^ self].
  3673         (startLine == endLine and:[endCol < startCol]) ifTrue:[^ self].
  3669 "
  3674 "
  3670 	selectionStartLine := startLine.
  3675         selectionStartLine := startLine.
  3671 	selectionStartCol := startCol.
  3676         selectionStartCol := startCol.
  3672 	selectionEndLine := endLine.
  3677         selectionEndLine := endLine.
  3673 	selectionEndCol := endCol.
  3678         selectionEndCol := endCol.
  3674 	self validateNewSelection.
  3679         self validateNewSelection.
  3675 
  3680 
  3676 	(selectionStartLine == selectionEndLine) ifTrue:[
  3681         (selectionStartLine == selectionEndLine) ifTrue:[
  3677 	    self redrawLine:selectionStartLine from:selectionStartCol to:selectionEndCol
  3682             self redrawLine:selectionStartLine from:selectionStartCol to:selectionEndCol
  3678 	] ifFalse:[
  3683         ] ifFalse:[
  3679 	    selectionStartLine to:selectionEndLine do:[:lineNr |
  3684             selectionStartLine to:selectionEndLine do:[:lineNr |
  3680 		self redrawLine:lineNr
  3685                 self redrawLine:lineNr
  3681 	    ]
  3686             ]
  3682 	].
  3687         ].
  3683 	selectStyle := nil.
  3688         selectStyle := nil.
  3684     ]
  3689     ]
  3685 
  3690 
  3686     "
  3691     "
  3687      |v|
  3692      |v|
  3688 
  3693 
  3751 
  3756 
  3752 selectWordAtLine:line col:col
  3757 selectWordAtLine:line col:col
  3753     "select the word at given line/col"
  3758     "select the word at given line/col"
  3754 
  3759 
  3755     self wordAtLine:line col:col do:[
  3760     self wordAtLine:line col:col do:[
  3756 	:beginLine :beginCol :endLine :endCol :style |
  3761         :beginLine :beginCol :endLine :endCol :style |
  3757 
  3762 
  3758 	self selectFromLine:beginLine col:beginCol toLine:endLine col:endCol.
  3763         self selectFromLine:beginLine col:beginCol toLine:endLine col:endCol.
  3759 	selectStyle := style
  3764         selectStyle := style
  3760     ]
  3765     ]
  3761 
  3766 
  3762     "Modified: 18.3.1996 / 17:30:38 / cg"
  3767     "Modified: 18.3.1996 / 17:30:38 / cg"
  3763 !
  3768 !
  3764 
  3769 
  3769 
  3774 
  3770     selectStyle := nil.
  3775     selectStyle := nil.
  3771     selectVisibleLine := self visibleLineOfY:y.
  3776     selectVisibleLine := self visibleLineOfY:y.
  3772     selectLine := self visibleLineToListLine:selectVisibleLine.
  3777     selectLine := self visibleLineToListLine:selectVisibleLine.
  3773     selectLine notNil ifTrue:[
  3778     selectLine notNil ifTrue:[
  3774 	selectCol := self colOfX:x inVisibleLine:selectVisibleLine.
  3779         selectCol := self colOfX:x inVisibleLine:selectVisibleLine.
  3775 	self selectWordAtLine:selectLine col:selectCol
  3780         self selectWordAtLine:selectLine col:selectCol
  3776     ]
  3781     ]
  3777 
  3782 
  3778     "Modified: / 8.9.1998 / 21:22:46 / cg"
  3783     "Modified: / 8.9.1998 / 21:22:46 / cg"
  3779 !
  3784 !
  3780 
  3785 
  3833     "unselect - if there was a selection redraw that area"
  3838     "unselect - if there was a selection redraw that area"
  3834 
  3839 
  3835     |startLine endLine startVisLine endVisLine|
  3840     |startLine endLine startVisLine endVisLine|
  3836 
  3841 
  3837     selectionStartLine notNil ifTrue:[
  3842     selectionStartLine notNil ifTrue:[
  3838 	startLine := selectionStartLine.
  3843         startLine := selectionStartLine.
  3839 	endLine := selectionEndLine.
  3844         endLine := selectionEndLine.
  3840 
  3845 
  3841 	self unselectWithoutRedraw.
  3846         self unselectWithoutRedraw.
  3842 
  3847 
  3843 	"/ if the selection is not visible, we are done
  3848         "/ if the selection is not visible, we are done
  3844 
  3849 
  3845 	startLine >= (firstLineShown + nLinesShown) ifTrue:[^ self].
  3850         startLine >= (firstLineShown + nLinesShown) ifTrue:[^ self].
  3846 	endLine < firstLineShown ifTrue:[^ self].
  3851         endLine < firstLineShown ifTrue:[^ self].
  3847 
  3852 
  3848 	startLine < firstLineShown ifTrue:[
  3853         startLine < firstLineShown ifTrue:[
  3849 	    startVisLine := 1
  3854             startVisLine := 1
  3850 	] ifFalse:[
  3855         ] ifFalse:[
  3851 	    startVisLine := self listLineToVisibleLine:startLine
  3856             startVisLine := self listLineToVisibleLine:startLine
  3852 	].
  3857         ].
  3853 	endLine >= (firstLineShown + nLinesShown) ifTrue:[
  3858         endLine >= (firstLineShown + nLinesShown) ifTrue:[
  3854 	    endVisLine := nLinesShown
  3859             endVisLine := nLinesShown
  3855 	] ifFalse:[
  3860         ] ifFalse:[
  3856 	    endVisLine := self listLineToVisibleLine:endLine
  3861             endVisLine := self listLineToVisibleLine:endLine
  3857 	].
  3862         ].
  3858 
  3863 
  3859 	"/ if its only part of a line, just redraw what has to be
  3864         "/ if its only part of a line, just redraw what has to be
  3860 
  3865 
  3861 	(startLine == endLine) ifTrue:[
  3866         (startLine == endLine) ifTrue:[
  3862 	    super redrawVisibleLine:startVisLine from:selectionStartCol to:selectionEndCol
  3867             super redrawVisibleLine:startVisLine from:selectionStartCol to:selectionEndCol
  3863 	] ifFalse:[
  3868         ] ifFalse:[
  3864 	    self redrawFromVisibleLine:startVisLine to:endVisLine
  3869             self redrawFromVisibleLine:startVisLine to:endVisLine
  3865 	].
  3870         ].
  3866     ].
  3871     ].
  3867     selectStyle := nil
  3872     selectStyle := nil
  3868 
  3873 
  3869     "Modified: 29.5.1996 / 14:54:11 / cg"
  3874     "Modified: 29.5.1996 / 14:54:11 / cg"
  3870 !
  3875 !
  3888 ! !
  3893 ! !
  3889 
  3894 
  3890 !TextView class methodsFor:'documentation'!
  3895 !TextView class methodsFor:'documentation'!
  3891 
  3896 
  3892 version
  3897 version
  3893     ^ '$Header: /cvs/stx/stx/libwidg/TextView.st,v 1.269 2006-07-17 10:58:13 cg Exp $'
  3898     ^ '$Header: /cvs/stx/stx/libwidg/TextView.st,v 1.270 2006-07-24 12:25:32 fm Exp $'
  3894 ! !
  3899 ! !
  3895 
  3900 
  3896 TextView initialize!
  3901 TextView initialize!