author | Claus Gittinger <cg@exept.de> |
Sat, 27 Jan 1996 16:37:22 +0100 | |
changeset 309 | b5c9d68e95e1 |
parent 292 | f46dea5bdd51 |
child 326 | f04c328526c4 |
permissions | -rw-r--r-- |
0 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
59 | 3 |
All Rights Reserved |
0 | 4 |
|
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 |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
ListView subclass:#TextView |
|
259
837ccdc138ea
use non-blocking millisecondDelay
Claus Gittinger <cg@exept.de>
parents:
248
diff
changeset
|
14 |
instanceVariableNames:'selectionStartLine selectionStartCol selectionEndLine |
248 | 15 |
selectionEndCol clickStartLine clickStartCol clickLine clickCol |
16 |
clickCount wordStartCol wordStartLine wordEndCol wordEndLine |
|
17 |
selectionFgColor selectionBgColor fileBox searchBox lineNumberBox |
|
18 |
selectStyle directoryForFileDialog contentsWasSaved' |
|
259
837ccdc138ea
use non-blocking millisecondDelay
Claus Gittinger <cg@exept.de>
parents:
248
diff
changeset
|
19 |
classVariableNames:'DefaultFont DefaultViewBackground DefaultSelectionForegroundColor |
248 | 20 |
DefaultSelectionBackgroundColor MatchDelayTime' |
259
837ccdc138ea
use non-blocking millisecondDelay
Claus Gittinger <cg@exept.de>
parents:
248
diff
changeset
|
21 |
poolDictionaries:'' |
837ccdc138ea
use non-blocking millisecondDelay
Claus Gittinger <cg@exept.de>
parents:
248
diff
changeset
|
22 |
category:'Views-Text' |
0 | 23 |
! |
24 |
||
25 |
!TextView class methodsFor:'documentation'! |
|
26 |
||
38 | 27 |
copyright |
28 |
" |
|
29 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
59 | 30 |
All Rights Reserved |
38 | 31 |
|
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! |
|
40 |
||
22 | 41 |
documentation |
0 | 42 |
" |
120 | 43 |
a view for readOnly text - this class adds selections to a simple list. |
38 | 44 |
The text is not editable and there is no cursor. |
120 | 45 |
Use TextViews for readonly text, EditTextView for editable text. |
0 | 46 |
|
309
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
47 |
Please read the historic notice in the ListView class. |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
48 |
|
38 | 49 |
Instance variables: |
0 | 50 |
|
120 | 51 |
selectionStartLine <Number> the line of the selection start (or nil) |
52 |
selectionStartCol <Number> the col of the selection start |
|
53 |
selectionEndLine <Number> the line of the selection end |
|
54 |
selectionEndCol <Number> the col of the selection end |
|
55 |
clickStartLine <Number> temporary |
|
56 |
clickStartCol <Number> temporary |
|
57 |
clickLine <Number> temporary |
|
58 |
clickCol <Number> temporary |
|
59 |
clickCount <Number> temporary |
|
60 |
selectionFgColor <Color> color used to draw selections |
|
61 |
selectionBgColor <Color> color used to draw selections |
|
62 |
fileBox <FileSelectionBox> box for save |
|
63 |
searchBox <EnterBox2> box to enter searchpattern |
|
64 |
lineNumberBox <EnterBox> box to enter linenumber |
|
65 |
selectStyle <Symbol> how words are selected |
|
66 |
directoryForFileDialog <nil|pathName> directory where save dialog should start |
|
67 |
contentsWasSaved <Boolean> set to true, whenever saved in a file |
|
77 | 68 |
|
69 |
StyleSheet parameters: |
|
70 |
||
120 | 71 |
textViewBackground defaults to viewBackground |
72 |
textSelectionForegroundColor defaults to textBackgroundColor |
|
73 |
textSelectionBackgroundColor defaults to textForegroundColor |
|
74 |
textViewFont defaults to textFont |
|
0 | 75 |
" |
76 |
! ! |
|
77 |
||
119 | 78 |
!TextView class methodsFor:'instance creation'! |
79 |
||
80 |
on:aModel aspect:aspect change:change menu:menu initialSelection:initial |
|
81 |
"for ST-80 compatibility" |
|
82 |
||
120 | 83 |
^ (self new) |
84 |
on:aModel |
|
85 |
aspect:aspect |
|
86 |
list:aspect |
|
87 |
change:change |
|
88 |
menu:menu |
|
89 |
initialSelection:initial |
|
119 | 90 |
! ! |
91 |
||
59 | 92 |
!TextView class methodsFor:'defaults'! |
38 | 93 |
|
59 | 94 |
updateStyleCache |
60 | 95 |
DefaultViewBackground := StyleSheet colorAt:'textViewBackground' default:White. |
96 |
DefaultSelectionForegroundColor := StyleSheet colorAt:'textSelectionForegroundColor'. |
|
97 |
DefaultSelectionBackgroundColor := StyleSheet colorAt:'textSelectionBackgroundColor'. |
|
77 | 98 |
DefaultFont := StyleSheet fontAt:'textViewFont'. |
186 | 99 |
MatchDelayTime := 0.6 |
0 | 100 |
! ! |
101 |
||
248 | 102 |
!TextView class methodsFor:'startup'! |
121 | 103 |
|
248 | 104 |
open |
105 |
"start an empty TextView" |
|
106 |
||
107 |
^ self openWith:nil |
|
0 | 108 |
! |
109 |
||
248 | 110 |
openOn:aFileName |
111 |
"start a textView on a file" |
|
112 |
||
113 |
|top textView stream| |
|
0 | 114 |
|
248 | 115 |
textView := self setupEmpty. |
116 |
top := textView topView. |
|
117 |
aFileName notNil ifTrue:[ |
|
118 |
top label:(OperatingSystem baseNameOf:aFileName). |
|
119 |
stream := aFileName asFilename readStream. |
|
120 |
stream notNil ifTrue:[ |
|
121 |
textView contents:(stream contents) |
|
59 | 122 |
] |
123 |
]. |
|
248 | 124 |
|
125 |
top open. |
|
126 |
^ textView |
|
127 |
||
128 |
" |
|
129 |
TextView openOn:'../doc/info.doc' |
|
130 |
EditTextView openOn:'../doc/info.doc' |
|
131 |
" |
|
0 | 132 |
! |
133 |
||
248 | 134 |
openWith:aString |
135 |
"start a textView with aString as initial contents" |
|
136 |
||
137 |
^ self openWith:aString title:nil |
|
0 | 138 |
|
248 | 139 |
" |
140 |
TextView openWith:'some text' |
|
141 |
EditTextView openWith:'some text' |
|
142 |
" |
|
119 | 143 |
|
248 | 144 |
"Created: 10.12.1995 / 17:41:32 / cg" |
126 | 145 |
! |
146 |
||
248 | 147 |
openWith:aString title:aTitle |
148 |
"start a textView with aString as initial contents" |
|
149 |
||
150 |
|top textView| |
|
151 |
||
152 |
textView := self setupEmpty. |
|
153 |
top := textView topView. |
|
154 |
aTitle notNil ifTrue:[top label:aTitle]. |
|
155 |
||
156 |
aString notNil ifTrue:[ |
|
259
837ccdc138ea
use non-blocking millisecondDelay
Claus Gittinger <cg@exept.de>
parents:
248
diff
changeset
|
157 |
textView contents:aString |
248 | 158 |
]. |
159 |
||
160 |
top open. |
|
161 |
^ textView |
|
162 |
||
163 |
" |
|
164 |
TextView openWith:'some text' title:'testing' |
|
165 |
EditTextView openWith:'some text' title:'testing' |
|
166 |
" |
|
126 | 167 |
|
248 | 168 |
"Created: 10.12.1995 / 17:40:02 / cg" |
169 |
"Modified: 10.12.1995 / 17:41:13 / cg" |
|
170 |
! |
|
171 |
||
172 |
setupEmpty |
|
173 |
"create a textview in a topview, with horizontal and |
|
174 |
vertical scrollbars - a helper for #startWith: and #startOn:" |
|
175 |
||
176 |
|top frame label| |
|
177 |
||
178 |
label := 'unnamed'. |
|
179 |
top := StandardSystemView |
|
180 |
label:label |
|
181 |
icon:(Form fromFile:'Editor.xbm' resolution:100). |
|
182 |
||
183 |
frame := HVScrollableView |
|
184 |
for:self |
|
185 |
miniScrollerH:true miniScrollerV:false |
|
186 |
in:top. |
|
187 |
frame origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
188 |
^ frame scrolledView |
|
119 | 189 |
! ! |
190 |
||
0 | 191 |
!TextView methodsFor:'accessing'! |
192 |
||
193 |
characterAtLine:lineNr col:colNr |
|
194 |
"return the character at physical line/col - |
|
195 |
return space if nothing is there" |
|
196 |
||
197 |
|line| |
|
198 |
||
199 |
list notNil ifTrue:[ |
|
59 | 200 |
line := self listAt:lineNr. |
201 |
line notNil ifTrue:[ |
|
202 |
(line size >= colNr) ifTrue:[ |
|
203 |
^ line at:colNr |
|
204 |
] |
|
205 |
] |
|
0 | 206 |
]. |
207 |
^ Character space |
|
208 |
! |
|
209 |
||
210 |
characterPositionOfSelection |
|
211 |
"return the character index of the first character in the selection" |
|
212 |
||
213 |
selectionStartLine isNil ifTrue:[^ 1]. |
|
214 |
^ self characterPositionOfLine:selectionStartLine |
|
59 | 215 |
col:selectionStartCol |
0 | 216 |
! |
217 |
||
218 |
contentsWasSaved |
|
219 |
"return true, if the contents was saved (by a save action), |
|
220 |
false if not (or was modified again after the last save)." |
|
221 |
||
222 |
^ contentsWasSaved |
|
223 |
! |
|
224 |
||
248 | 225 |
directoryForFileDialog:aDirectory |
226 |
"define the directory to use for save-box" |
|
227 |
||
228 |
directoryForFileDialog := aDirectory |
|
229 |
! |
|
230 |
||
0 | 231 |
fromFile:aFileName |
232 |
"take contents from a named file" |
|
233 |
||
234 |
self directoryForFileDialog:(OperatingSystem directoryNameOf:aFileName). |
|
235 |
self contents:(FileStream oldFileNamed:aFileName) contents |
|
236 |
! |
|
237 |
||
248 | 238 |
list:something |
239 |
"set the displayed contents (a collection of strings) |
|
240 |
with redraw. |
|
241 |
Redefined since changing contents implies deselect" |
|
0 | 242 |
|
243 |
self unselect. |
|
248 | 244 |
super list:something |
0 | 245 |
! |
246 |
||
248 | 247 |
selectionForegroundColor:color1 backgroundColor:color2 |
248 |
"set both selection-foreground and cursor background colors" |
|
131 | 249 |
|
248 | 250 |
selectionFgColor := color1 on:device. |
251 |
selectionBgColor := color2 on:device. |
|
252 |
shown ifTrue:[ |
|
253 |
self redraw |
|
0 | 254 |
] |
255 |
! |
|
256 |
||
248 | 257 |
setList:something |
258 |
"set the displayed contents (a collection of strings) |
|
259 |
without redraw. |
|
260 |
Redefined since changing contents implies deselect" |
|
0 | 261 |
|
248 | 262 |
self unselect. |
263 |
super setList:something |
|
0 | 264 |
! ! |
265 |
||
248 | 266 |
!TextView methodsFor:'accessing-mvc'! |
0 | 267 |
|
248 | 268 |
model:aModel |
269 |
"when my model is set, and I am the menuPerformer/menuHolder, |
|
270 |
reset holder to the model. This is a compatibility kludge, |
|
271 |
since typically, ST-80 code expects the model to provide a menu |
|
272 |
and the view to perform it. |
|
273 |
Those apps which want the TextView to provide the menu have to reset |
|
274 |
this by sending menuHolder: (again)" |
|
275 |
||
276 |
super model:aModel. |
|
277 |
(menuPerformer == self and:[menuHolder == self]) ifTrue:[ |
|
278 |
menuHolder := model |
|
0 | 279 |
] |
280 |
! |
|
281 |
||
248 | 282 |
on:aModel aspect:aspectSym list:listSym change:changeSym menu:menuSym initialSelection:initial |
283 |
"ST-80 compatibility" |
|
0 | 284 |
|
248 | 285 |
aspectSym notNil ifTrue:[aspectMsg := aspectSym. listMsg := aspectSym]. |
286 |
changeSym notNil ifTrue:[changeMsg := changeSym]. |
|
287 |
listSym notNil ifTrue:[listMsg := listSym]. |
|
288 |
menuSym notNil ifTrue:[menuMsg := menuSym]. |
|
289 |
"/ initial notNil ifTrue:[initialSelectionMsg := initial]. |
|
290 |
self model:aModel. |
|
0 | 291 |
|
248 | 292 |
listMsg notNil ifTrue:[ |
293 |
self getListFromModel |
|
0 | 294 |
]. |
295 |
! ! |
|
296 |
||
297 |
!TextView methodsFor:'event processing'! |
|
298 |
||
53 | 299 |
buttonMotion:buttonMask x:x y:y |
0 | 300 |
"mouse-move while button was pressed - handle selection changes" |
301 |
||
302 |
|movedVisibleLine movedLine movedCol |
|
303 |
movedUp |
|
304 |
oldStartLine oldEndLine oldStartCol oldEndCol| |
|
305 |
||
306 |
clickLine isNil ifTrue:[^ self]. |
|
307 |
||
63 | 308 |
"is it the select or 1-button ?" |
309 |
(device buttonMotionMask:buttonMask includesButton:#select) ifFalse:[ |
|
310 |
(device buttonMotionMask:buttonMask includesButton:1) ifFalse:[ |
|
311 |
^ self |
|
312 |
]. |
|
53 | 313 |
]. |
314 |
||
0 | 315 |
"if moved outside of view, start autoscroll" |
316 |
(y < 0) ifTrue:[ |
|
59 | 317 |
self compressMotionEvents:false. |
318 |
self startAutoScrollUp:y. |
|
319 |
^ self |
|
0 | 320 |
]. |
321 |
(y > height) ifTrue:[ |
|
59 | 322 |
self compressMotionEvents:false. |
323 |
self startAutoScrollDown:(y - height). |
|
324 |
^ self |
|
325 |
]. |
|
326 |
((x < 0) and:[leftOffset ~~ 0]) ifTrue:[ |
|
327 |
self compressMotionEvents:false. |
|
328 |
self startAutoScrollLeft:x. |
|
329 |
^ self |
|
330 |
]. |
|
331 |
(x > width) ifTrue:[ |
|
332 |
self compressMotionEvents:false. |
|
333 |
self startAutoScrollRight:(x - width). |
|
334 |
^ self |
|
0 | 335 |
]. |
336 |
||
337 |
"move inside - stop autoscroll if any" |
|
338 |
autoScrollBlock notNil ifTrue:[ |
|
59 | 339 |
self stopScrollSelect |
0 | 340 |
]. |
341 |
||
342 |
movedVisibleLine := self visibleLineOfY:y. |
|
343 |
movedLine := self visibleLineToAbsoluteLine:movedVisibleLine. |
|
344 |
(x < leftMargin) ifTrue:[ |
|
59 | 345 |
movedCol := 0 |
0 | 346 |
] ifFalse:[ |
59 | 347 |
movedCol := self colOfX:x inVisibleLine:movedVisibleLine |
0 | 348 |
]. |
349 |
((movedLine == clickLine) and:[movedCol == clickCol]) ifTrue:[^ self]. |
|
350 |
||
351 |
selectionStartLine isNil ifTrue:[ |
|
59 | 352 |
selectionStartLine := clickLine. |
353 |
selectionStartCol := clickCol. |
|
354 |
selectionEndLine := selectionStartLine. |
|
355 |
selectionEndCol := selectionStartCol |
|
0 | 356 |
]. |
357 |
oldStartLine := selectionStartLine. |
|
358 |
oldEndLine := selectionEndLine. |
|
359 |
oldStartCol := selectionStartCol. |
|
360 |
oldEndCol := selectionEndCol. |
|
361 |
||
362 |
||
363 |
"find out if we are before or after initial click" |
|
364 |
movedUp := false. |
|
365 |
(movedLine < clickStartLine) ifTrue:[ |
|
59 | 366 |
movedUp := true |
0 | 367 |
] ifFalse:[ |
59 | 368 |
(movedLine == clickStartLine) ifTrue:[ |
369 |
(movedCol < clickStartCol) ifTrue:[ |
|
370 |
movedUp := true |
|
371 |
] |
|
372 |
] |
|
0 | 373 |
]. |
374 |
||
375 |
movedUp ifTrue:[ |
|
59 | 376 |
"change selectionStart" |
377 |
selectionStartCol := movedCol. |
|
378 |
selectionStartLine := movedLine. |
|
379 |
selectionEndCol := clickStartCol. |
|
380 |
selectionEndLine := clickStartLine. |
|
381 |
selectStyle notNil ifTrue:[ |
|
382 |
selectionEndCol := wordEndCol. |
|
383 |
selectionEndLine := wordEndLine. |
|
384 |
] |
|
0 | 385 |
] ifFalse:[ |
59 | 386 |
"change selectionEnd" |
387 |
selectionEndCol := movedCol. |
|
388 |
selectionEndLine := movedLine. |
|
389 |
selectionStartCol := clickStartCol. |
|
390 |
selectionStartLine := clickStartLine. |
|
391 |
selectStyle notNil ifTrue:[ |
|
392 |
selectionStartCol := wordStartCol. |
|
393 |
selectionStartLine := wordStartLine. |
|
394 |
] |
|
0 | 395 |
]. |
396 |
||
164 | 397 |
selectionStartLine isNil ifTrue:[^ self]. |
398 |
||
0 | 399 |
(selectionStartCol == 0) ifTrue:[ |
59 | 400 |
selectionStartCol := 1 |
0 | 401 |
]. |
402 |
||
38 | 403 |
" |
404 |
if in word-select, just catch the rest of the word |
|
405 |
" |
|
406 |
(selectStyle notNil and:[selectStyle startsWith:'word']) ifTrue:[ |
|
59 | 407 |
movedUp ifTrue:[ |
408 |
selectionStartCol := self findBeginOfWordAtLine:selectionStartLine col:selectionStartCol |
|
409 |
] ifFalse:[ |
|
410 |
selectionEndCol := self findEndOfWordAtLine:selectionEndLine col:selectionEndCol. |
|
411 |
selectionEndCol == 0 ifTrue:[ |
|
412 |
selectionEndLine := selectionEndLine + 1 |
|
413 |
] |
|
414 |
]. |
|
38 | 415 |
]. |
416 |
||
417 |
selectStyle == #line ifTrue:[ |
|
59 | 418 |
movedUp ifTrue:[ |
419 |
selectionStartCol := 1. |
|
420 |
] ifFalse:[ |
|
421 |
selectionEndCol := 0. |
|
422 |
selectionEndLine := selectionEndLine + 1 |
|
423 |
] |
|
38 | 424 |
]. |
425 |
||
209
7a6db7fac566
dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
426 |
self validateNewSelection. |
7a6db7fac566
dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
427 |
|
0 | 428 |
(oldStartLine == selectionStartLine) ifTrue:[ |
59 | 429 |
(oldStartCol ~~ selectionStartCol) ifTrue:[ |
430 |
self redrawLine:oldStartLine |
|
431 |
from:((selectionStartCol min:oldStartCol) max:1) |
|
432 |
to:((selectionStartCol max:oldStartCol) max:1) |
|
433 |
] |
|
0 | 434 |
] ifFalse:[ |
59 | 435 |
self redrawFromLine:(oldStartLine min:selectionStartLine) |
436 |
to:(oldStartLine max:selectionStartLine) |
|
0 | 437 |
]. |
438 |
||
439 |
(oldEndLine == selectionEndLine) ifTrue:[ |
|
59 | 440 |
(oldEndCol ~~ selectionEndCol) ifTrue:[ |
441 |
self redrawLine:oldEndLine |
|
442 |
from:((selectionEndCol min:oldEndCol) max:1) |
|
443 |
to:((selectionEndCol max:oldEndCol) max:1) |
|
444 |
] |
|
0 | 445 |
] ifFalse:[ |
59 | 446 |
self redrawFromLine:(oldEndLine min:selectionEndLine) |
447 |
to:(oldEndLine max:selectionEndLine) |
|
0 | 448 |
]. |
449 |
clickLine := movedLine. |
|
450 |
clickCol := movedCol |
|
451 |
! |
|
452 |
||
248 | 453 |
buttonMultiPress:button x:x y:y |
454 |
"multi-mouse-click - select word under pointer" |
|
455 |
||
456 |
|sel| |
|
457 |
||
458 |
((button == 1) or:[button == #select]) ifTrue:[ |
|
459 |
clickCount notNil ifTrue:[ |
|
460 |
clickCount := clickCount + 1. |
|
461 |
(clickCount == 2) ifTrue:[ |
|
462 |
self selectWordAtX:x y:y. |
|
463 |
" |
|
464 |
special - if clicked on a parenthesis, select to matching |
|
465 |
" |
|
466 |
((sel := self selection) size == 1 |
|
467 |
and:[(sel := sel at:1) size == 1]) ifTrue:[ |
|
468 |
('()[]{}<>' includes:(sel at:1)) ifTrue:[ |
|
469 |
self searchForMatchingParenthesisFromLine:selectionStartLine col:selectionStartCol |
|
470 |
ifFound:[:line :col | |
|
471 |
|prevLine prevCol| |
|
472 |
||
473 |
prevLine := firstLineShown. |
|
474 |
prevCol := leftOffset. |
|
475 |
self selectFromLine:selectionStartLine col:selectionStartCol |
|
476 |
toLine:line col:col. |
|
477 |
"/ undo scroll operation ... |
|
478 |
(')]}>' includes:(sel at:1)) ifTrue:[ |
|
479 |
(firstLineShown ~~ prevLine or:[prevCol ~~ leftOffset]) ifTrue:[ |
|
292 | 480 |
Delay waitForSeconds:MatchDelayTime. |
248 | 481 |
self scrollToLine:prevLine; scrollToCol:prevCol. |
482 |
] |
|
483 |
] ifFalse:[ |
|
484 |
selectionEndLine > (firstLineShown + nFullLinesShown) ifTrue:[ |
|
485 |
self makeLineVisible:selectionEndLine. |
|
292 | 486 |
Delay waitForSeconds:MatchDelayTime. |
248 | 487 |
self scrollToLine:prevLine; scrollToCol:prevCol. |
488 |
] |
|
489 |
] |
|
490 |
] |
|
491 |
ifNotFound:[self showNotFound] |
|
492 |
onError:[device beep]. |
|
493 |
selectStyle := nil |
|
494 |
] |
|
495 |
]. |
|
496 |
||
497 |
" |
|
498 |
remember words position in case of a drag following |
|
499 |
" |
|
500 |
wordStartLine := selectionStartLine. |
|
501 |
wordEndLine := selectionEndLine. |
|
502 |
selectStyle == #wordLeft ifTrue:[ |
|
503 |
wordStartCol := selectionStartCol + 1 |
|
504 |
] ifFalse:[ |
|
505 |
wordStartCol := selectionStartCol. |
|
506 |
]. |
|
507 |
selectStyle == #wordRight ifTrue:[ |
|
508 |
wordEndCol := selectionEndCol - 1 |
|
509 |
] ifFalse:[ |
|
510 |
wordEndCol := selectionEndCol |
|
511 |
] |
|
512 |
] ifFalse:[ |
|
513 |
(clickCount == 3) ifTrue:[ |
|
514 |
self selectLineAtY:y. |
|
515 |
selectStyle := #line |
|
516 |
] ifFalse:[ |
|
517 |
(clickCount == 4) ifTrue:[ |
|
518 |
self selectAll |
|
519 |
] |
|
520 |
] |
|
521 |
] |
|
522 |
] |
|
523 |
] ifFalse:[ |
|
524 |
super buttonMultiPress:button x:x y:y |
|
525 |
] |
|
526 |
||
527 |
"Modified: 18.11.1995 / 18:30:33 / cg" |
|
528 |
! |
|
529 |
||
530 |
buttonPress:button x:x y:y |
|
531 |
"mouse-click - prepare for selection change" |
|
532 |
||
533 |
|clickVisibleLine| |
|
534 |
||
535 |
((button == 1) or:[button == #select]) ifTrue:[ |
|
536 |
clickVisibleLine := self visibleLineOfY:y. |
|
537 |
clickCol := self colOfX:x inVisibleLine:clickVisibleLine. |
|
538 |
clickLine := self visibleLineToAbsoluteLine:clickVisibleLine. |
|
539 |
clickStartLine := clickLine. |
|
540 |
clickStartCol := clickCol. |
|
541 |
self unselect. |
|
542 |
clickCount := 1 |
|
543 |
] ifFalse:[ |
|
544 |
super buttonPress:button x:x y:y |
|
545 |
] |
|
546 |
! |
|
547 |
||
0 | 548 |
buttonRelease:button x:x y:y |
549 |
"mouse- button release - turn off autoScroll if any" |
|
550 |
||
38 | 551 |
((button == 1) or:[button == #select]) ifTrue:[ |
59 | 552 |
autoScrollBlock notNil ifTrue:[ |
553 |
self stopScrollSelect |
|
554 |
]. |
|
0 | 555 |
] ifFalse:[ |
59 | 556 |
super buttonRelease:button x:x y:y |
0 | 557 |
] |
248 | 558 |
! |
559 |
||
560 |
buttonShiftPress:button x:x y:y |
|
561 |
"mouse-click with shift - adding to selection" |
|
562 |
||
563 |
"very simple - just simulate a move" |
|
564 |
^ self buttonMotion:(device button1MotionMask) x:x y:y |
|
565 |
! |
|
566 |
||
567 |
keyPress:key x:x y:y |
|
568 |
"handle some keyboard input (there is not much to be done here)" |
|
569 |
||
570 |
<resource: #keyboard (#Find #Copy #FindNext #FindPrev #SelectAll)> |
|
571 |
||
572 |
(key == #Find) ifTrue:[self search. ^self]. |
|
573 |
(key == #Copy) ifTrue:[self copySelection. ^self]. |
|
574 |
||
575 |
(key == #FindNext) ifTrue:[self searchFwd. ^self]. |
|
576 |
(key == #FindPrev) ifTrue:[self searchBwd. ^self]. |
|
577 |
||
578 |
(key == #SelectAll) ifTrue:[self selectAll. ^self]. |
|
579 |
||
580 |
" |
|
581 |
shift-Fn defines a key-sequence |
|
582 |
Fn pastes that sequence |
|
583 |
cmd-Fn performs a 'doIt' on the sequence (Workspaces only) |
|
584 |
||
585 |
(see EditTextView>>keyPress:x:y and Workspace>>keyPress:x:y) |
|
586 |
" |
|
587 |
(('[fF][0-9]' match:key) |
|
588 |
or:['[fF][0-9][0-9]' match:key]) ifTrue:[ |
|
589 |
device shiftDown ifTrue:[ |
|
590 |
(Smalltalk at:#FunctionKeySequences) isNil ifTrue:[ |
|
591 |
Smalltalk at:#FunctionKeySequences put:Dictionary new |
|
592 |
]. |
|
593 |
(Smalltalk at:#FunctionKeySequences) at:key put:(self selection) |
|
594 |
]. |
|
595 |
^ self |
|
596 |
]. |
|
597 |
||
598 |
super keyPress:key x:x y:y |
|
599 |
! |
|
600 |
||
601 |
mapped |
|
602 |
super mapped. |
|
603 |
selectionFgColor := selectionFgColor on:device. |
|
604 |
selectionBgColor := selectionBgColor on:device. |
|
0 | 605 |
! ! |
248 | 606 |
|
607 |
!TextView methodsFor:'initialize & release'! |
|
608 |
||
609 |
destroy |
|
610 |
fileBox notNil ifTrue:[ |
|
611 |
fileBox destroy. |
|
612 |
fileBox := nil |
|
613 |
]. |
|
614 |
searchBox notNil ifTrue:[ |
|
615 |
searchBox destroy. |
|
616 |
searchBox := nil |
|
617 |
]. |
|
618 |
lineNumberBox notNil ifTrue:[ |
|
619 |
lineNumberBox destroy. |
|
620 |
lineNumberBox := nil |
|
621 |
]. |
|
622 |
super destroy |
|
623 |
! |
|
624 |
||
625 |
initStyle |
|
626 |
super initStyle. |
|
627 |
||
628 |
DefaultFont notNil ifTrue:[ |
|
629 |
font := DefaultFont on:device |
|
630 |
]. |
|
631 |
viewBackground := DefaultViewBackground. |
|
632 |
selectionFgColor := DefaultSelectionForegroundColor. |
|
633 |
selectionFgColor isNil ifTrue:[selectionFgColor := bgColor]. |
|
634 |
selectionBgColor := DefaultSelectionBackgroundColor. |
|
635 |
selectionBgColor isNil ifTrue:[ |
|
636 |
device hasColors ifTrue:[ |
|
637 |
DefaultSelectionForegroundColor isNil ifTrue:[ |
|
638 |
selectionFgColor := fgColor |
|
639 |
]. |
|
640 |
selectionBgColor := Color green |
|
641 |
] ifFalse:[ |
|
642 |
device hasGreyscales ifTrue:[ |
|
643 |
DefaultSelectionForegroundColor isNil ifTrue:[ |
|
644 |
selectionFgColor := fgColor |
|
645 |
]. |
|
646 |
selectionBgColor := Color grey |
|
647 |
] ifFalse:[ |
|
648 |
selectionBgColor := fgColor |
|
649 |
] |
|
650 |
] |
|
651 |
]. |
|
652 |
! |
|
653 |
||
654 |
initialize |
|
655 |
super initialize. |
|
656 |
contentsWasSaved := false. |
|
657 |
||
658 |
" |
|
659 |
initialize menu to be provided and performed by myself. |
|
660 |
This allows textViews without a model to provide a |
|
661 |
reasonable menu AND allows models to provide their own menu. |
|
662 |
" |
|
663 |
menuHolder := menuPerformer := self. |
|
664 |
menuMsg := #editMenu |
|
665 |
! ! |
|
666 |
||
667 |
!TextView methodsFor:'menu actions'! |
|
668 |
||
669 |
appendTo:fileName |
|
670 |
"append contents to a file named fileName" |
|
671 |
||
672 |
|aStream msg| |
|
673 |
||
674 |
aStream := FileStream appendingOldFileNamed:fileName. |
|
675 |
aStream isNil ifTrue:[ |
|
676 |
msg := resources string:'cannot append to file %1 !!' with:fileName. |
|
677 |
self warn:(msg , '\\(' , FileStream lastErrorString , ')' ) withCRs |
|
678 |
] ifFalse:[ |
|
679 |
self fileOutContentsOn:aStream. |
|
680 |
aStream close. |
|
681 |
contentsWasSaved := true |
|
682 |
] |
|
683 |
! |
|
684 |
||
685 |
changeFont |
|
686 |
"pop up a fontPanel to change font" |
|
687 |
||
688 |
|panel| |
|
689 |
||
690 |
panel := FontPanel new. |
|
691 |
panel action:[:family :face :style :size | |
|
692 |
self font:(Font family:family |
|
693 |
face:face |
|
694 |
style:style |
|
695 |
size:size) |
|
696 |
]. |
|
697 |
panel initialFont:font. |
|
698 |
panel showAtPointer |
|
699 |
! |
|
700 |
||
701 |
copySelection |
|
702 |
"copy contents into smalltalk copybuffer" |
|
703 |
||
704 |
|text| |
|
705 |
||
706 |
text := self selection. |
|
707 |
text notNil ifTrue:[ |
|
708 |
self unselect. |
|
709 |
self setTextSelection:text |
|
710 |
] |
|
711 |
! |
|
712 |
||
713 |
defaultForGotoLine |
|
714 |
"return a default value to show in the gotoLine box" |
|
715 |
||
716 |
^ nil |
|
717 |
! |
|
718 |
||
719 |
editMenu |
|
720 |
|labels selectors m| |
|
721 |
||
722 |
labels := #( |
|
723 |
'copy' |
|
724 |
'-' |
|
725 |
'font ...' |
|
726 |
'-' |
|
727 |
'search ...' |
|
728 |
'goto ...' |
|
729 |
'-' |
|
730 |
'save as ...' |
|
731 |
'print' |
|
732 |
). |
|
733 |
||
734 |
selectors := #( |
|
735 |
copySelection |
|
736 |
nil |
|
737 |
changeFont |
|
738 |
nil |
|
739 |
search |
|
740 |
gotoLine |
|
741 |
nil |
|
742 |
save |
|
743 |
||
744 |
). |
|
745 |
||
746 |
m := PopUpMenu |
|
747 |
labels:(resources array:labels) |
|
748 |
selectors:selectors. |
|
749 |
||
750 |
self hasSelection ifFalse:[ |
|
751 |
m disable:#copySelection. |
|
752 |
]. |
|
753 |
^ m |
|
754 |
! |
|
755 |
||
756 |
gotoLine |
|
757 |
"show a box to enter lineNumber for positioning" |
|
758 |
||
759 |
|l| |
|
760 |
||
761 |
lineNumberBox isNil ifTrue:[ |
|
762 |
lineNumberBox := |
|
763 |
EnterBox |
|
764 |
title:(resources string:'line number:') |
|
765 |
okText:(resources string:'goto') |
|
766 |
abortText:(resources string:'cancel') |
|
767 |
action:[:l | |num| |
|
768 |
num := Integer readFromString:l onError:nil. |
|
769 |
num notNil ifTrue:[self gotoLine:num] |
|
770 |
] |
|
771 |
]. |
|
772 |
l := self defaultForGotoLine. |
|
773 |
l notNil ifTrue:[ |
|
774 |
l := l printString |
|
775 |
]. |
|
776 |
lineNumberBox initialText:l . |
|
777 |
lineNumberBox showAtPointer |
|
778 |
! |
|
779 |
||
780 |
||
781 |
"print the contents on the printer" |
|
782 |
||
783 |
|printStream| |
|
784 |
||
785 |
list isNil ifTrue:[^ self]. |
|
786 |
printStream := Printer new. |
|
787 |
printStream notNil ifTrue:[ |
|
788 |
self fileOutContentsOn:printStream. |
|
789 |
printStream close |
|
790 |
] |
|
791 |
! |
|
792 |
||
793 |
save |
|
794 |
"save contents into a file |
|
795 |
- ask user for filename using a fileSelectionBox." |
|
796 |
||
797 |
fileBox isNil ifTrue:[ |
|
798 |
fileBox := FileSaveBox |
|
799 |
title:(resources string:'save contents in:') |
|
800 |
okText:(resources string:'save') |
|
801 |
abortText:(resources string:'cancel') |
|
802 |
action:[:fileName | self saveAs:fileName]. |
|
803 |
fileBox appendAction:[:fileName | self appendTo:fileName]. |
|
804 |
]. |
|
805 |
directoryForFileDialog notNil ifTrue:[ |
|
806 |
fileBox directory:directoryForFileDialog |
|
807 |
]. |
|
808 |
fileBox showAtPointer |
|
809 |
! |
|
810 |
||
811 |
saveAs:fileName |
|
812 |
"save contents into a file named fileName" |
|
813 |
||
814 |
|aStream msg| |
|
815 |
||
816 |
aStream := FileStream newFileNamed:fileName. |
|
817 |
aStream isNil ifTrue:[ |
|
818 |
msg := resources string:'cannot write file %1 !!' with:fileName. |
|
819 |
self warn:(msg , '\\(' , FileStream lastErrorString , ')' ) withCRs |
|
820 |
] ifFalse:[ |
|
821 |
self fileOutContentsOn:aStream. |
|
822 |
aStream close. |
|
823 |
contentsWasSaved := true |
|
824 |
] |
|
825 |
! ! |
|
826 |
||
827 |
!TextView methodsFor:'private'! |
|
828 |
||
829 |
fileOutContentsOn:aStream |
|
830 |
"save contents on a stream, replacing leading spaces by tab-characters." |
|
831 |
||
832 |
self fileOutContentsOn:aStream compressTabs:true |
|
833 |
! |
|
834 |
||
835 |
fileOutContentsOn:aStream compressTabs:compressTabs |
|
836 |
"save contents on a stream. If compressTabs is true, |
|
837 |
leading spaces will be replaced by tab-characters in the output." |
|
838 |
||
839 |
|startNr nLines string| |
|
840 |
||
841 |
"on some systems, writing linewise is very slow (via NFS) |
|
842 |
therefore we convert to a string and write it in big chunks. |
|
843 |
To avoid creating huge strings, we do it in blocks of 1000 lines, |
|
844 |
limiting temporary string creation to about 50-80k. |
|
845 |
" |
|
846 |
startNr := 1. |
|
847 |
nLines := list size. |
|
848 |
[startNr <= nLines] whileTrue:[ |
|
849 |
string := list asStringWithCRsFrom:startNr |
|
850 |
to:((startNr + 1000) min:nLines) |
|
851 |
compressTabs:compressTabs. |
|
852 |
aStream nextPutAll:string. |
|
853 |
startNr := startNr + 1000 + 1. |
|
854 |
]. |
|
855 |
||
856 |
"/ "the old (obsolete) code:" |
|
857 |
"/ |
|
858 |
"/ list do:[:aLine | |
|
859 |
"/ aLine notNil ifTrue:[ |
|
860 |
"/ aStream nextPutAll:aLine. |
|
861 |
"/ ]. |
|
862 |
"/ aStream cr |
|
863 |
"/ ] |
|
864 |
||
865 |
! |
|
866 |
||
867 |
scrollSelectDown |
|
868 |
"auto scroll action; scroll and reinstall timed-block" |
|
869 |
||
870 |
|prevEndLine| |
|
871 |
||
872 |
"just to make certain ..." |
|
873 |
selectionEndLine isNil ifTrue:[^ self]. |
|
874 |
||
875 |
self scrollDown. |
|
876 |
||
877 |
"make new selection immediately visible" |
|
878 |
prevEndLine := selectionEndLine. |
|
879 |
selectionEndLine := firstLineShown + nFullLinesShown. |
|
880 |
selectionEndCol := 0. |
|
881 |
prevEndLine to:selectionEndLine do:[:lineNr | |
|
882 |
self redrawLine:lineNr |
|
883 |
]. |
|
884 |
Processor addTimedBlock:autoScrollBlock afterSeconds:autoScrollDeltaT. |
|
885 |
! |
|
886 |
||
887 |
scrollSelectLeft |
|
888 |
"auto scroll action; scroll and reinstall timed-block" |
|
889 |
||
890 |
|prevStartLine| |
|
891 |
||
892 |
"just to make certain ..." |
|
893 |
selectionStartLine isNil ifTrue:[^ self]. |
|
894 |
selectionStartCol isNil ifTrue:[^ self]. |
|
895 |
||
896 |
"make new selection immediately visible" |
|
897 |
prevStartLine := selectionStartLine. |
|
898 |
selectionStartCol := selectionStartCol - 1 max:1. |
|
899 |
self scrollLeft. |
|
900 |
||
901 |
Processor addTimedBlock:autoScrollBlock afterSeconds:autoScrollDeltaT. |
|
902 |
! |
|
903 |
||
904 |
scrollSelectRight |
|
905 |
"auto scroll action; scroll and reinstall timed-block" |
|
906 |
||
907 |
|prevEndCol| |
|
908 |
||
909 |
"just to make certain ..." |
|
910 |
selectionEndCol isNil ifTrue:[^ self]. |
|
911 |
||
912 |
prevEndCol := selectionEndCol. |
|
913 |
selectionEndCol := selectionEndCol + 1. |
|
914 |
self scrollRight. |
|
915 |
||
916 |
Processor addTimedBlock:autoScrollBlock afterSeconds:autoScrollDeltaT. |
|
917 |
! |
|
918 |
||
919 |
scrollSelectUp |
|
920 |
"auto scroll action; scroll and reinstall timed-block" |
|
921 |
||
922 |
|prevStartLine| |
|
923 |
||
924 |
"just to make certain ..." |
|
925 |
selectionStartLine isNil ifTrue:[^ self]. |
|
926 |
||
927 |
self scrollUp. |
|
928 |
||
929 |
"make new selection immediately visible" |
|
930 |
prevStartLine := selectionStartLine. |
|
931 |
selectionStartLine := firstLineShown. |
|
932 |
selectionStartCol := 1. |
|
933 |
selectionStartLine to:prevStartLine do:[:lineNr | |
|
934 |
self redrawLine:lineNr |
|
935 |
]. |
|
936 |
Processor addTimedBlock:autoScrollBlock afterSeconds:autoScrollDeltaT. |
|
937 |
! |
|
938 |
||
939 |
stopScrollSelect |
|
940 |
"stop auto scroll; deinstall timed-block" |
|
941 |
||
942 |
autoScrollBlock notNil ifTrue:[ |
|
943 |
Processor removeTimedBlock:autoScrollBlock. |
|
944 |
self compressMotionEvents:true. |
|
945 |
autoScrollBlock := nil. |
|
946 |
autoScrollDeltaT := nil |
|
947 |
] |
|
948 |
! |
|
949 |
||
950 |
widthForScrollBetween:firstLine and:lastLine |
|
951 |
"return the width in pixels for a scroll between firstLine and lastLine" |
|
952 |
||
953 |
selectionStartLine notNil ifTrue:[ |
|
954 |
(lastLine < selectionStartLine) ifFalse:[ |
|
955 |
(firstLine > selectionEndLine) ifFalse:[ |
|
956 |
^ width |
|
957 |
] |
|
958 |
] |
|
959 |
]. |
|
960 |
^ super widthForScrollBetween:firstLine and:lastLine |
|
961 |
! ! |
|
962 |
||
963 |
!TextView methodsFor:'redrawing'! |
|
964 |
||
965 |
clearMarginOfVisible:visLine with:color |
|
966 |
"if there is a margin, clear it - a helper for selection drawing" |
|
967 |
||
968 |
(leftMargin ~~ 0) ifTrue:[ |
|
969 |
self paint:color. |
|
970 |
self fillRectangleX:margin |
|
971 |
y:(self yOfVisibleLine:visLine) |
|
972 |
width:leftMargin |
|
973 |
height:fontHeight |
|
974 |
] |
|
975 |
! |
|
976 |
||
977 |
redrawFromVisibleLine:startVisLineNr to:endVisLineNr |
|
978 |
"redraw a visible line range" |
|
979 |
||
980 |
|startLine endLine specialCare end selVisStart line1 line2| |
|
981 |
||
982 |
shown ifFalse:[^ self]. |
|
983 |
||
984 |
end := endVisLineNr. |
|
985 |
(end > nLinesShown) ifTrue:[ |
|
986 |
end := nLinesShown |
|
987 |
]. |
|
988 |
||
989 |
selectionStartLine isNil ifTrue:[ |
|
990 |
specialCare := false |
|
991 |
] ifFalse:[ |
|
992 |
startLine := self visibleLineToAbsoluteLine:startVisLineNr. |
|
993 |
(startLine > selectionEndLine) ifTrue:[ |
|
994 |
specialCare := false |
|
995 |
] ifFalse:[ |
|
996 |
endLine := self visibleLineToAbsoluteLine:end. |
|
997 |
(endLine < selectionStartLine) ifTrue:[ |
|
998 |
specialCare := false |
|
999 |
] ifFalse:[ |
|
1000 |
specialCare := true |
|
1001 |
] |
|
1002 |
] |
|
1003 |
]. |
|
1004 |
||
1005 |
"easy: nothing is selected" |
|
1006 |
specialCare ifFalse:[ |
|
1007 |
super redrawFromVisibleLine:startVisLineNr to:end. |
|
1008 |
^ self |
|
1009 |
]. |
|
1010 |
||
1011 |
"easy: all is selected" |
|
1012 |
((selectionStartLine < startLine) and:[selectionEndLine > endLine]) ifTrue:[ |
|
1013 |
self drawFromVisibleLine:startVisLineNr to:end with:selectionFgColor |
|
1014 |
and:selectionBgColor. |
|
1015 |
^ self |
|
1016 |
]. |
|
1017 |
||
1018 |
(selectionStartLine >= firstLineShown) ifTrue:[ |
|
1019 |
"draw unselected top part" |
|
1020 |
||
1021 |
selVisStart := self listLineToVisibleLine:selectionStartLine. |
|
1022 |
super redrawFromVisibleLine:startVisLineNr to:(selVisStart - 1). |
|
1023 |
||
1024 |
"and first partial selected line" |
|
1025 |
self redrawVisibleLine:selVisStart. |
|
1026 |
||
1027 |
"rest starts after this one" |
|
1028 |
line1 := selVisStart + 1 |
|
1029 |
] ifFalse:[ |
|
1030 |
line1 := 1 |
|
1031 |
]. |
|
1032 |
||
1033 |
(line1 > end) ifTrue:[^ self]. |
|
1034 |
(line1 < startVisLineNr) ifTrue:[ |
|
1035 |
line1 := startVisLineNr |
|
1036 |
]. |
|
1037 |
||
1038 |
"draw middle part of selection" |
|
1039 |
||
1040 |
(selectionEndLine >= (firstLineShown + nLinesShown)) ifTrue:[ |
|
1041 |
line2 := nLinesShown |
|
1042 |
] ifFalse:[ |
|
1043 |
line2 := (self listLineToVisibleLine:selectionEndLine) - 1 |
|
1044 |
]. |
|
1045 |
(line2 > end) ifTrue:[ |
|
1046 |
line2 := end |
|
1047 |
]. |
|
1048 |
||
1049 |
self drawFromVisibleLine:line1 to:line2 with:selectionFgColor |
|
1050 |
and:selectionBgColor. |
|
1051 |
||
1052 |
(line2 >= end) ifTrue:[^ self]. |
|
1053 |
||
1054 |
"last line of selection" |
|
1055 |
self redrawVisibleLine:(line2 + 1). |
|
1056 |
||
1057 |
((line2 + 2) <= end) ifTrue:[ |
|
1058 |
super redrawFromVisibleLine:(line2 + 2) to:end |
|
1059 |
] |
|
1060 |
! |
|
1061 |
||
1062 |
redrawVisibleLine:visLine |
|
1063 |
"redraw visible line lineNr" |
|
1064 |
||
1065 |
|len line l| |
|
1066 |
||
1067 |
selectionStartLine notNil ifTrue:[ |
|
1068 |
line := self visibleLineToAbsoluteLine:visLine. |
|
1069 |
(line between:selectionStartLine and:selectionEndLine) ifTrue:[ |
|
1070 |
(line == selectionStartLine) ifTrue:[ |
|
1071 |
(line == selectionEndLine) ifTrue:[ |
|
1072 |
"its part-of-single-line selection" |
|
1073 |
self clearMarginOfVisible:visLine with:bgColor. |
|
1074 |
(selectionStartCol > 1) ifTrue:[ |
|
1075 |
super redrawVisibleLine:visLine |
|
1076 |
from:1 |
|
1077 |
to:(selectionStartCol - 1) |
|
1078 |
]. |
|
1079 |
self drawVisibleLine:visLine from:selectionStartCol |
|
1080 |
to:selectionEndCol |
|
1081 |
with:selectionFgColor |
|
1082 |
and:selectionBgColor. |
|
1083 |
super redrawVisibleLine:visLine |
|
1084 |
from:(selectionEndCol + 1). |
|
1085 |
^ self |
|
1086 |
]. |
|
1087 |
||
1088 |
"its the first line of a multi-line selection" |
|
1089 |
(selectionStartCol ~~ 1) ifTrue:[ |
|
1090 |
self clearMarginOfVisible:visLine with:bgColor. |
|
1091 |
super redrawVisibleLine:visLine |
|
1092 |
from:1 |
|
1093 |
to:(selectionStartCol - 1) |
|
1094 |
] ifFalse:[ |
|
1095 |
leftOffset == 0 ifTrue:[ |
|
1096 |
self clearMarginOfVisible:visLine with:selectionBgColor. |
|
1097 |
] |
|
1098 |
]. |
|
1099 |
self drawVisibleLine:visLine from:selectionStartCol |
|
1100 |
with:selectionFgColor and:selectionBgColor. |
|
1101 |
^ self |
|
1102 |
]. |
|
1103 |
||
1104 |
(line == selectionEndLine) ifTrue:[ |
|
1105 |
"its the last line of a multi-line selection" |
|
1106 |
(selectionEndCol == 0) ifTrue:[ |
|
1107 |
^ super redrawVisibleLine:visLine |
|
1108 |
]. |
|
1109 |
l := self visibleAt:selectionEndLine. |
|
1110 |
len := l size. |
|
1111 |
||
1112 |
self clearMarginOfVisible:visLine with:selectionBgColor. |
|
1113 |
self drawVisibleLine:visLine from:1 to:selectionEndCol |
|
1114 |
with:selectionFgColor and:selectionBgColor. |
|
1115 |
super redrawVisibleLine:visLine from:(selectionEndCol + 1). |
|
1116 |
^ self |
|
1117 |
]. |
|
1118 |
||
1119 |
"its a full line in a multi-line selection" |
|
1120 |
self clearMarginOfVisible:visLine with:selectionBgColor. |
|
1121 |
self drawVisibleLine:visLine with:selectionFgColor and:selectionBgColor. |
|
1122 |
^ self |
|
1123 |
] |
|
1124 |
]. |
|
1125 |
super redrawVisibleLine:visLine |
|
1126 |
! |
|
1127 |
||
1128 |
redrawVisibleLine:visLine col:col |
|
1129 |
"redraw single character at col in visible line lineNr" |
|
1130 |
||
1131 |
|line| |
|
1132 |
||
1133 |
line := self visibleLineToAbsoluteLine:visLine. |
|
1134 |
selectionStartLine notNil ifTrue:[ |
|
1135 |
(line between:selectionStartLine and:selectionEndLine) ifTrue:[ |
|
1136 |
((line == selectionStartLine) |
|
1137 |
and: [col < selectionStartCol]) ifFalse:[ |
|
1138 |
((line == selectionEndLine) |
|
1139 |
and: [col > selectionEndCol]) ifFalse:[ |
|
1140 |
"its in the selection" |
|
1141 |
self drawVisibleLine:visLine col:col with:selectionFgColor |
|
1142 |
and:selectionBgColor. |
|
1143 |
^ self |
|
1144 |
] |
|
1145 |
] |
|
1146 |
] |
|
1147 |
]. |
|
1148 |
super redrawVisibleLine:visLine col:col |
|
1149 |
! |
|
1150 |
||
1151 |
redrawVisibleLine:visLine from:startCol |
|
1152 |
"redraw visible line lineNr from startCol to end of line" |
|
1153 |
||
1154 |
|line| |
|
1155 |
||
1156 |
line := self visibleLineToAbsoluteLine:visLine. |
|
1157 |
selectionStartLine notNil ifTrue:[ |
|
1158 |
(line between:selectionStartLine and:selectionEndLine) ifTrue:[ |
|
1159 |
((line == selectionStartLine) |
|
1160 |
or:[line == selectionEndLine]) ifTrue:[ |
|
1161 |
"since I'm lazy, redraw full line" |
|
1162 |
self redrawVisibleLine:visLine. |
|
1163 |
^ self |
|
1164 |
]. |
|
1165 |
"the line is fully within the selection" |
|
1166 |
self drawVisibleLine:visLine from:startCol with:selectionFgColor |
|
1167 |
and:selectionBgColor. |
|
1168 |
^ self |
|
1169 |
] |
|
1170 |
]. |
|
1171 |
super redrawVisibleLine:visLine from:startCol |
|
1172 |
! |
|
1173 |
||
1174 |
redrawVisibleLine:visLine from:startCol to:endCol |
|
1175 |
"redraw visible line lineNr from startCol to endCol" |
|
1176 |
||
1177 |
|line allOut allIn leftCol rightCol| |
|
1178 |
||
1179 |
line := self visibleLineToAbsoluteLine:visLine. |
|
1180 |
||
1181 |
allIn := false. |
|
1182 |
allOut := false. |
|
1183 |
selectionStartLine isNil ifTrue:[ |
|
1184 |
allOut := true |
|
1185 |
] ifFalse:[ |
|
1186 |
(line between:selectionStartLine and:selectionEndLine) ifFalse:[ |
|
1187 |
allOut := true |
|
1188 |
] ifTrue:[ |
|
1189 |
(selectionStartLine == selectionEndLine) ifTrue:[ |
|
1190 |
((endCol < selectionStartCol) |
|
1191 |
or:[startCol > selectionEndCol]) ifTrue:[ |
|
1192 |
allOut := true |
|
1193 |
] ifFalse:[ |
|
1194 |
((startCol >= selectionStartCol) |
|
1195 |
and:[endCol <= selectionEndCol]) ifTrue:[ |
|
1196 |
allIn := true |
|
1197 |
] |
|
1198 |
] |
|
1199 |
] ifFalse:[ |
|
1200 |
(line == selectionStartLine) ifTrue:[ |
|
1201 |
(endCol < selectionStartCol) ifTrue:[ |
|
1202 |
allOut := true |
|
1203 |
] ifFalse:[ |
|
1204 |
(startCol >= selectionStartCol) ifTrue:[ |
|
1205 |
allIn := true |
|
1206 |
] |
|
1207 |
] |
|
1208 |
] ifFalse:[ |
|
1209 |
(line == selectionEndLine) ifTrue:[ |
|
1210 |
(startCol > selectionEndCol) ifTrue:[ |
|
1211 |
allOut := true |
|
1212 |
] ifFalse:[ |
|
1213 |
(endCol <= selectionEndCol) ifTrue:[ |
|
1214 |
allIn := true |
|
1215 |
] |
|
1216 |
] |
|
1217 |
] ifFalse:[ |
|
1218 |
allIn := true |
|
1219 |
] |
|
1220 |
] |
|
1221 |
] |
|
1222 |
] |
|
1223 |
]. |
|
1224 |
allOut ifTrue:[ |
|
1225 |
super redrawVisibleLine:visLine from:startCol to:endCol. |
|
1226 |
^ self |
|
1227 |
]. |
|
1228 |
||
1229 |
allIn ifTrue:[ |
|
1230 |
self drawVisibleLine:visLine from:startCol to:endCol |
|
1231 |
with:selectionFgColor and:selectionBgColor |
|
1232 |
] ifFalse:[ |
|
1233 |
"redraw part before selection" |
|
1234 |
((line == selectionStartLine) |
|
1235 |
and:[startCol <= selectionStartCol]) ifTrue:[ |
|
1236 |
super redrawVisibleLine:visLine from:startCol |
|
1237 |
to:(selectionStartCol - 1). |
|
1238 |
leftCol := selectionStartCol |
|
1239 |
] ifFalse:[ |
|
1240 |
leftCol := startCol |
|
1241 |
]. |
|
1242 |
"redraw selected part" |
|
1243 |
(selectionEndLine > line) ifTrue:[ |
|
1244 |
rightCol := endCol |
|
1245 |
] ifFalse:[ |
|
1246 |
rightCol := selectionEndCol min:endCol |
|
1247 |
]. |
|
1248 |
self drawVisibleLine:visLine from:leftCol to:rightCol |
|
1249 |
with:selectionFgColor and:selectionBgColor. |
|
1250 |
||
1251 |
"redraw part after selection" |
|
1252 |
(rightCol < endCol) ifTrue:[ |
|
1253 |
super redrawVisibleLine:visLine from:(rightCol + 1) to:endCol |
|
1254 |
] |
|
1255 |
]. |
|
1256 |
||
1257 |
"special care for first and last line of selection: |
|
1258 |
must handle margin also" |
|
1259 |
||
1260 |
((line == selectionEndLine) |
|
1261 |
and:[(startCol == 1) |
|
1262 |
and:[selectionStartLine < selectionEndLine]]) |
|
1263 |
ifTrue:[ |
|
1264 |
self clearMarginOfVisible:visLine with:selectionBgColor. |
|
1265 |
]. |
|
1266 |
||
1267 |
((line == selectionStartLine) |
|
1268 |
and:[(startCol == 1) |
|
1269 |
and:[selectionStartLine < selectionEndLine]]) |
|
1270 |
ifTrue:[ |
|
1271 |
self clearMarginOfVisible:visLine with:bgColor. |
|
1272 |
] |
|
1273 |
! ! |
|
1274 |
||
1275 |
!TextView methodsFor:'searching'! |
|
1276 |
||
1277 |
search |
|
1278 |
"show a box to enter searchpattern |
|
1279 |
- currently no regular expressions are handled." |
|
1280 |
||
1281 |
" |
|
1282 |
cache the searchBox |
|
1283 |
Q: should we use one global searchBox for all textViews ? |
|
1284 |
(we could then preserve the last searchstring between views) |
|
1285 |
" |
|
1286 |
||
1287 |
"/ "soon to come: search & replace box ... |
|
1288 |
"/ |box| |
|
1289 |
"/ |
|
1290 |
"/ box := Dialog new. |
|
1291 |
"/ (box addTextLabel:(resources at:'searchPattern:')) layout:#left. |
|
1292 |
"/ box addVerticalSpace. |
|
1293 |
"/ box addInputFieldOn:'' asValue. |
|
1294 |
"/ box addVerticalSpace. |
|
1295 |
"/ (box addTextLabel:(resources at:'replace with:')) layout:#left. |
|
1296 |
"/ box addVerticalSpace. |
|
1297 |
"/ box addInputFieldOn:'' asValue. |
|
1298 |
"/ box addAbortButtonLabelled:(resources at:'cancel'); |
|
1299 |
"/ addButton:(Button label:(resources at:'all')); |
|
1300 |
"/ addButton:(Button label:(resources at:'prev')); |
|
1301 |
"/ addOkButtonLabelled:(resources at:'next'). |
|
1302 |
"/ box open. |
|
1303 |
||
1304 |
searchBox isNil ifTrue:[ |
|
1305 |
searchBox := |
|
1306 |
EnterBox2 |
|
1307 |
title:(resources at:'searchPattern:') |
|
1308 |
okText1:(resources at:'prev') |
|
1309 |
okText2:(resources at:'next') |
|
1310 |
abortText:(resources at:'cancel') |
|
1311 |
action1:[:pattern | pattern notEmpty ifTrue:[self searchBwd:(pattern withoutSeparators)]] |
|
1312 |
action2:[:pattern | pattern notEmpty ifTrue:[self searchFwd:(pattern withoutSeparators)]] |
|
1313 |
]. |
|
1314 |
searchPattern notNil ifTrue:[ |
|
1315 |
searchBox initialText:searchPattern |
|
1316 |
]. |
|
1317 |
self hasSelection ifTrue:[ |
|
1318 |
selectionStartLine == selectionEndLine ifTrue:[ |
|
1319 |
searchBox initialText:self selection |
|
1320 |
] |
|
1321 |
]. |
|
1322 |
searchBox showAtPointer |
|
1323 |
! |
|
1324 |
||
1325 |
searchBwd |
|
1326 |
"search backward and -if found- position cursor" |
|
1327 |
||
1328 |
self setSearchPattern. |
|
1329 |
searchPattern notNil ifTrue:[ |
|
1330 |
self searchBwd:searchPattern |
|
1331 |
] |
|
1332 |
! |
|
1333 |
||
1334 |
searchBwd:pattern |
|
1335 |
"do a backward search" |
|
1336 |
||
1337 |
self searchBwd:pattern ifAbsent:[self showNotFound]. |
|
1338 |
searchPattern := pattern |
|
1339 |
||
1340 |
! |
|
1341 |
||
1342 |
searchBwd:pattern ifAbsent:aBlock |
|
1343 |
"do a backward search" |
|
1344 |
||
1345 |
|startLine startCol| |
|
1346 |
||
1347 |
selectionStartLine notNil ifTrue:[ |
|
1348 |
startLine := selectionStartLine. |
|
1349 |
startCol := selectionStartCol |
|
1350 |
] ifFalse:[ |
|
1351 |
startLine := 1. |
|
1352 |
startCol := 1 |
|
1353 |
]. |
|
1354 |
self searchBackwardFor:pattern startingAtLine:startLine col:startCol |
|
1355 |
ifFound:[:line :col | |
|
1356 |
self showMatch:pattern atLine:line col:col |
|
1357 |
] ifAbsent:aBlock |
|
1358 |
! |
|
1359 |
||
1360 |
searchForMatchingParenthesisFromLine:startLine col:startCol |
|
1361 |
ifFound:foundBlock |
|
1362 |
ifNotFound:notFoundBlock |
|
1363 |
onError:failBlock |
|
1364 |
||
1365 |
"search for a matching parenthesis, parChar is one of '$( $[ ${ $) $] $}'. |
|
1366 |
Search for the corresponding character is done forward if its an opening, |
|
1367 |
backwards if its a closing parenthesis. |
|
1368 |
Performs foundBlock with line/col as argument if found, notFoundBlock if not. |
|
1369 |
If there is a nesting error, performs failBlock." |
|
1370 |
||
1371 |
^ self |
|
1372 |
searchForMatchingParenthesisFromLine:startLine col:startCol |
|
1373 |
ifFound:foundBlock |
|
1374 |
ifNotFound:notFoundBlock |
|
1375 |
onError:failBlock |
|
1376 |
ignoring:#( $' $" ) |
|
1377 |
||
1378 |
"Modified: 18.11.1995 / 16:28:23 / cg" |
|
1379 |
! |
|
1380 |
||
1381 |
searchForMatchingParenthesisFromLine:startLine col:startCol |
|
1382 |
ifFound:foundBlock |
|
1383 |
ifNotFound:notFoundBlock |
|
1384 |
onError:failBlock |
|
1385 |
ignoring:ignoreSet |
|
1386 |
"search for a matching parenthesis, parChar is one of '$( $[ ${ $) $] $}'. |
|
1387 |
Search for the corresponding character is done forward if its an opening, |
|
1388 |
backwards if its a closing parenthesis. |
|
1389 |
Performs foundBlock with line/col as argument if found, notFoundBlock if not. |
|
1390 |
If there is a nesting error, performs failBlock." |
|
1391 |
||
1392 |
|i direction lineString line col parChar charSet closingChar |
|
1393 |
ignoring delta endCol cc incSet decSet nesting maxLine| |
|
1394 |
||
1395 |
charSet := #( $( $) $[ $] ${ $} ). |
|
1396 |
||
1397 |
parChar := self characterAtLine:startLine col:startCol. |
|
1398 |
i := charSet indexOf:parChar. |
|
1399 |
i == 0 ifTrue:[ |
|
1400 |
^ failBlock value "not a parenthesis" |
|
1401 |
]. |
|
1402 |
direction := #( fwd bwd fwd bwd fwd bwd) at:i. |
|
1403 |
closingChar := #( $) $( $] $[ $} ${ ) at:i. |
|
1404 |
||
1405 |
col := startCol. |
|
1406 |
line := startLine. |
|
1407 |
direction == #fwd ifTrue:[ |
|
1408 |
delta := 1. |
|
1409 |
incSet := #( $( $[ ${ ). |
|
1410 |
decSet := #( $) $] $} ). |
|
1411 |
] ifFalse:[ |
|
1412 |
delta := -1. |
|
1413 |
incSet := #( $) $] $} ). |
|
1414 |
decSet := #( $( $[ ${ ). |
|
1415 |
]. |
|
1416 |
||
1417 |
nesting := 1. |
|
1418 |
ignoring := false. |
|
1419 |
lineString := list at:line. |
|
1420 |
maxLine := list size. |
|
1421 |
||
1422 |
col := col + delta. |
|
1423 |
[nesting ~~ 0] whileTrue:[ |
|
1424 |
lineString notNil ifTrue:[ |
|
1425 |
direction == #fwd ifTrue:[ |
|
1426 |
endCol := lineString size. |
|
1427 |
] ifFalse:[ |
|
1428 |
endCol := 1 |
|
1429 |
]. |
|
1430 |
col to:endCol by:delta do:[:runCol | |
|
1431 |
cc := lineString at:runCol. |
|
1432 |
||
1433 |
(ignoreSet includes:cc) ifTrue:[ |
|
1434 |
ignoring := ignoring not |
|
1435 |
]. |
|
1436 |
ignoring ifFalse:[ |
|
1437 |
(incSet includes:cc) ifTrue:[ |
|
1438 |
nesting := nesting + 1 |
|
1439 |
] ifFalse:[ |
|
1440 |
(decSet includes:cc) ifTrue:[ |
|
1441 |
nesting := nesting - 1 |
|
1442 |
] |
|
1443 |
] |
|
1444 |
]. |
|
1445 |
nesting == 0 ifTrue:[ |
|
1446 |
"check if legal" |
|
1447 |
||
1448 |
cc == closingChar ifFalse:[ |
|
1449 |
^ failBlock value |
|
1450 |
]. |
|
1451 |
^ foundBlock value:line value:runCol. |
|
1452 |
] |
|
1453 |
]. |
|
1454 |
]. |
|
1455 |
line := line + delta. |
|
1456 |
(line < 1 or:[line > maxLine]) ifTrue:[ |
|
1457 |
^ failBlock value |
|
1458 |
]. |
|
1459 |
lineString := list at:line. |
|
1460 |
direction == #fwd ifTrue:[ |
|
1461 |
col := 1 |
|
1462 |
] ifFalse:[ |
|
1463 |
col := lineString size |
|
1464 |
] |
|
1465 |
]. |
|
1466 |
||
1467 |
^ notFoundBlock value |
|
1468 |
||
1469 |
"Modified: 18.11.1995 / 16:30:56 / cg" |
|
1470 |
! |
|
1471 |
||
1472 |
searchFwd |
|
1473 |
"search forward for pattern or selection" |
|
1474 |
||
1475 |
selectStyle == #wordLeft ifTrue:[ |
|
1476 |
" |
|
1477 |
remove the space from the selection |
|
1478 |
" |
|
1479 |
selectionStartCol := selectionStartCol + 1. |
|
1480 |
super redrawLine:selectionStartLine from:selectionStartCol-1 to:selectionStartCol-1. |
|
259
837ccdc138ea
use non-blocking millisecondDelay
Claus Gittinger <cg@exept.de>
parents:
248
diff
changeset
|
1481 |
selectStyle := #word. |
248 | 1482 |
]. |
1483 |
self setSearchPattern. |
|
1484 |
searchPattern notNil ifTrue:[ |
|
1485 |
self searchFwd:searchPattern |
|
1486 |
] |
|
1487 |
! |
|
1488 |
||
1489 |
searchFwd:pattern |
|
1490 |
"do a forward search" |
|
1491 |
||
1492 |
self searchFwd:pattern ifAbsent:[self showNotFound]. |
|
1493 |
searchPattern := pattern |
|
1494 |
! |
|
1495 |
||
1496 |
searchFwd:pattern ifAbsent:aBlock |
|
1497 |
"do a forward search" |
|
1498 |
||
1499 |
|startLine startCol| |
|
1500 |
||
1501 |
selectionStartLine notNil ifTrue:[ |
|
1502 |
startLine := selectionStartLine. |
|
1503 |
startCol := selectionStartCol |
|
1504 |
] ifFalse:[ |
|
1505 |
startLine := 1. |
|
1506 |
startCol := 1 |
|
1507 |
]. |
|
1508 |
self searchForwardFor:pattern startingAtLine:startLine col:startCol |
|
1509 |
ifFound:[:line :col | |
|
1510 |
self showMatch:pattern atLine:line col:col |
|
1511 |
] ifAbsent:aBlock |
|
1512 |
! |
|
1513 |
||
1514 |
searchPattern |
|
1515 |
"return the last search pattern" |
|
1516 |
||
1517 |
^ searchPattern |
|
1518 |
! |
|
1519 |
||
1520 |
setSearchPattern |
|
1521 |
"set the searchpattern from the selection if there is one" |
|
1522 |
||
1523 |
|sel| |
|
1524 |
||
1525 |
sel := self selection. |
|
1526 |
sel notNil ifTrue:[ |
|
1527 |
searchPattern := sel asString withoutSeparators |
|
1528 |
] |
|
1529 |
! |
|
1530 |
||
1531 |
setSearchPattern:aString |
|
1532 |
"set the searchpattern for future searches" |
|
1533 |
||
1534 |
aString isNil ifTrue:[ |
|
1535 |
searchPattern := aString |
|
1536 |
] ifFalse:[ |
|
1537 |
searchPattern := aString withoutSeparators |
|
1538 |
] |
|
1539 |
! |
|
1540 |
||
1541 |
showMatch:pattern atLine:line col:col |
|
1542 |
"after a search, highlight the matched pattern. |
|
1543 |
The code below needs a rewrite to take care of match-characters |
|
1544 |
(for now, it only highlights simple patterns and '*string*' correctly)" |
|
1545 |
||
1546 |
|realPattern| |
|
1547 |
||
1548 |
realPattern := pattern. |
|
1549 |
(realPattern startsWith:$*) ifTrue:[ |
|
1550 |
realPattern := realPattern copyFrom:2 |
|
1551 |
]. |
|
1552 |
(realPattern endsWith:$*) ifTrue:[ |
|
1553 |
realPattern := realPattern copyWithoutLast:1 |
|
1554 |
]. |
|
1555 |
||
1556 |
self selectFromLine:line col:col |
|
1557 |
toLine:line col:(col + realPattern size - 1). |
|
1558 |
self makeLineVisible:line |
|
1559 |
! |
|
1560 |
||
1561 |
showNotFound |
|
1562 |
"search not found - tell user by beeping and changing |
|
1563 |
cursor for a while (sometimes I work with a headset :-) |
|
1564 |
(used to be: tell user by changing cursor for a while)" |
|
1565 |
||
1566 |
|savedCursor| |
|
1567 |
||
1568 |
device beep. |
|
1569 |
||
1570 |
" |
|
1571 |
uncomment if you want a CROSS cursor to be shown for a while .. |
|
1572 |
" |
|
1573 |
||
1574 |
" " |
|
1575 |
savedCursor := cursor. |
|
1576 |
self cursor:(Cursor cross). |
|
259
837ccdc138ea
use non-blocking millisecondDelay
Claus Gittinger <cg@exept.de>
parents:
248
diff
changeset
|
1577 |
Processor activeProcess millisecondDelay:300. |
248 | 1578 |
self cursor:savedCursor |
1579 |
" " |
|
259
837ccdc138ea
use non-blocking millisecondDelay
Claus Gittinger <cg@exept.de>
parents:
248
diff
changeset
|
1580 |
|
837ccdc138ea
use non-blocking millisecondDelay
Claus Gittinger <cg@exept.de>
parents:
248
diff
changeset
|
1581 |
"Modified: 16.12.1995 / 13:11:31 / cg" |
248 | 1582 |
! ! |
1583 |
||
1584 |
!TextView methodsFor:'selections'! |
|
1585 |
||
1586 |
hasSelection |
|
1587 |
"return true, if there is a selection" |
|
1588 |
||
1589 |
^ selectionStartLine notNil |
|
1590 |
! |
|
1591 |
||
1592 |
makeSelectionVisible |
|
1593 |
"scroll to make the selection visible" |
|
1594 |
||
1595 |
selectionStartLine notNil ifTrue:[ |
|
1596 |
self makeLineVisible:selectionStartLine |
|
1597 |
] |
|
1598 |
! |
|
1599 |
||
1600 |
selectAll |
|
1601 |
"select the whole text" |
|
1602 |
||
1603 |
self selectFromLine:1 col:1 toLine:(list size + 1) col:0 |
|
1604 |
! |
|
1605 |
||
1606 |
selectFromCharacterPosition:pos1 to:pos2 |
|
1607 |
"compute line/col from character positions and select the text" |
|
1608 |
||
1609 |
|line1 col1 line2 col2| |
|
1610 |
||
1611 |
line1 := self lineOfCharacterPosition:pos1. |
|
1612 |
col1 := pos1 - (self characterPositionOfLine:line1 col:1) + 1. |
|
1613 |
line2 := self lineOfCharacterPosition:pos2. |
|
1614 |
col2 := pos2 - (self characterPositionOfLine:line2 col:1) + 1. |
|
1615 |
self selectFromLine:line1 col:col1 toLine:line2 col:col2 |
|
1616 |
! |
|
1617 |
||
1618 |
selectFromLine:startLine col:startCol toLine:endLine col:endCol |
|
1619 |
"select a piece of text and redraw that area" |
|
1620 |
||
1621 |
self unselect. |
|
1622 |
startLine notNil ifTrue:[ |
|
1623 |
"new:" |
|
1624 |
endLine < startLine ifTrue:[ |
|
1625 |
^ self selectFromLine:endLine col:endCol toLine:startLine col:startCol |
|
1626 |
]. |
|
1627 |
(endLine == startLine and:[endCol < startCol]) ifTrue:[ |
|
1628 |
endCol ~~ 0 ifTrue:[ |
|
1629 |
self selectFromLine:endLine col:endCol toLine:startLine col:startCol. |
|
1630 |
]. |
|
1631 |
^ self |
|
1632 |
]. |
|
1633 |
||
1634 |
" old: |
|
1635 |
endLine < startLine ifTrue:[^ self]. |
|
1636 |
(startLine == endLine and:[endCol < startCol]) ifTrue:[^ self]. |
|
1637 |
" |
|
1638 |
selectionStartLine := startLine. |
|
1639 |
selectionStartCol := startCol. |
|
1640 |
selectionEndLine := endLine. |
|
1641 |
selectionEndCol := endCol. |
|
1642 |
(startLine == endLine) ifTrue:[ |
|
1643 |
self redrawLine:startLine from:startCol to:endCol |
|
1644 |
] ifFalse:[ |
|
1645 |
startLine to:endLine do:[:lineNr | |
|
1646 |
self redrawLine:lineNr |
|
1647 |
] |
|
1648 |
]. |
|
1649 |
selectStyle := nil. |
|
1650 |
] |
|
1651 |
! |
|
1652 |
||
1653 |
selectLine:selectLine |
|
1654 |
"select one line and redraw it" |
|
1655 |
||
1656 |
self selectFromLine:selectLine col:1 toLine:(selectLine + 1) col:0. |
|
1657 |
wordStartCol := selectionStartCol. |
|
1658 |
wordEndCol := selectionEndCol. |
|
1659 |
wordStartLine := selectionStartLine. |
|
1660 |
wordEndLine := selectionEndLine. |
|
1661 |
selectStyle := #line |
|
1662 |
! |
|
1663 |
||
1664 |
selectLineAtY:y |
|
1665 |
"select the line at given y-(view-)coordinate" |
|
1666 |
||
1667 |
|selectVisibleLine selectLine| |
|
1668 |
||
1669 |
selectVisibleLine := self visibleLineOfY:y. |
|
1670 |
selectLine := self visibleLineToListLine:selectVisibleLine. |
|
1671 |
selectLine notNil ifTrue:[ |
|
1672 |
self selectLine:selectLine |
|
1673 |
] |
|
1674 |
! |
|
1675 |
||
1676 |
selectLineWhereCharacterPosition:pos |
|
1677 |
"select the line, where characterPosition pos is living. |
|
1678 |
The argument pos starts at 1 from the start of the text |
|
1679 |
and counts characters (i.e. can be used to convert from |
|
1680 |
character position within a string to line-position in view)." |
|
1681 |
||
1682 |
self selectLine:(self lineOfCharacterPosition:pos) |
|
1683 |
! |
|
1684 |
||
1685 |
selectWordAtLine:line col:col |
|
1686 |
"select the word at given line/col" |
|
1687 |
||
1688 |
self wordAtLine:line col:col do:[ |
|
1689 |
:beginLine :beginCol :endLine :endCol :style | |
|
1690 |
||
1691 |
self selectFromLine:beginLine col:beginCol toLine:endLine col:endCol. |
|
1692 |
selectStyle := style |
|
1693 |
] |
|
1694 |
! |
|
1695 |
||
1696 |
selectWordAtX:x y:y |
|
1697 |
"select the word at given x/y-(view-)coordinate" |
|
1698 |
||
1699 |
|selectVisibleLine selectLine selectCol| |
|
1700 |
||
1701 |
selectStyle := nil. |
|
1702 |
selectVisibleLine := self visibleLineOfY:y. |
|
1703 |
selectLine := self visibleLineToListLine:selectVisibleLine. |
|
1704 |
selectLine notNil ifTrue:[ |
|
1705 |
selectCol := self colOfX:x inVisibleLine:selectLine. |
|
1706 |
self selectWordAtLine:selectLine col:selectCol |
|
1707 |
] |
|
1708 |
! |
|
1709 |
||
1710 |
selection |
|
1711 |
"return the selection as a collection of (line-)strings. |
|
1712 |
If the selection ends in a full line, the last entry in the returned |
|
1713 |
collection will be an empty string." |
|
1714 |
||
1715 |
|text sz index last |
|
1716 |
startLine "{ Class: SmallInteger }" |
|
1717 |
endLine "{ Class: SmallInteger }"| |
|
1718 |
||
1719 |
selectionStartLine isNil ifTrue:[^ nil]. |
|
1720 |
startLine := selectionStartLine. |
|
1721 |
endLine := selectionEndLine. |
|
1722 |
||
1723 |
(startLine == endLine) ifTrue:[ |
|
1724 |
"part of a line" |
|
1725 |
^ StringCollection with:(self listAt:startLine |
|
1726 |
from:selectionStartCol |
|
1727 |
to:selectionEndCol) |
|
1728 |
]. |
|
1729 |
sz := endLine - startLine + 1. |
|
1730 |
text := StringCollection new:sz. |
|
1731 |
||
1732 |
"get 1st and last (possibly) partial lines" |
|
1733 |
text at:1 put:(self listAt:startLine from:selectionStartCol). |
|
1734 |
selectionEndCol == 0 ifTrue:[ |
|
1735 |
last := '' |
|
1736 |
] ifFalse:[ |
|
1737 |
last := self listAt:selectionEndLine to:selectionEndCol. |
|
1738 |
]. |
|
1739 |
text at:sz put:last. |
|
1740 |
||
1741 |
"get bulk of text" |
|
1742 |
index := 2. |
|
1743 |
(startLine + 1) to:(endLine - 1) do:[:lineNr | |
|
1744 |
text at:index put:(self listAt:lineNr). |
|
1745 |
index := index + 1 |
|
1746 |
]. |
|
1747 |
^ text |
|
1748 |
! |
|
1749 |
||
1750 |
selectionEndCol |
|
1751 |
^ selectionEndCol |
|
1752 |
! |
|
1753 |
||
1754 |
selectionEndLine |
|
1755 |
^ selectionEndLine |
|
1756 |
! |
|
1757 |
||
1758 |
selectionStartCol |
|
1759 |
^ selectionStartCol |
|
1760 |
! |
|
1761 |
||
1762 |
selectionStartLine |
|
1763 |
^ selectionStartLine |
|
1764 |
! |
|
1765 |
||
1766 |
unselect |
|
1767 |
"unselect - if there was a selection redraw that area" |
|
1768 |
||
1769 |
|startLine endLine startVisLine endVisLine| |
|
1770 |
||
1771 |
selectionStartLine notNil ifTrue:[ |
|
1772 |
startLine := selectionStartLine. |
|
1773 |
endLine := selectionEndLine. |
|
1774 |
selectionStartLine := nil. |
|
1775 |
||
1776 |
"if selection is not visible, we are done" |
|
1777 |
startLine >= (firstLineShown + nLinesShown) ifTrue:[^ self]. |
|
1778 |
endLine < firstLineShown ifTrue:[^ self]. |
|
1779 |
||
1780 |
startLine < firstLineShown ifTrue:[ |
|
1781 |
startVisLine := 1 |
|
1782 |
] ifFalse:[ |
|
1783 |
startVisLine := self listLineToVisibleLine:startLine |
|
1784 |
]. |
|
1785 |
endLine >= (firstLineShown + nLinesShown) ifTrue:[ |
|
1786 |
endVisLine := nLinesShown |
|
1787 |
] ifFalse:[ |
|
1788 |
endVisLine := self listLineToVisibleLine:endLine |
|
1789 |
]. |
|
1790 |
"if its only part of a line, just redraw what has to be" |
|
1791 |
(startVisLine == endVisLine) ifTrue:[ |
|
1792 |
super redrawVisibleLine:startVisLine from:selectionStartCol to:selectionEndCol |
|
1793 |
] ifFalse:[ |
|
1794 |
super redrawFromVisibleLine:startVisLine to:endVisLine |
|
1795 |
]. |
|
1796 |
self unselectWithoutRedraw |
|
1797 |
]. |
|
1798 |
selectStyle := nil |
|
1799 |
! |
|
1800 |
||
1801 |
unselectWithoutRedraw |
|
1802 |
"forget selection but do not redraw the selection area |
|
1803 |
- can be done when the selected area is redrawn anyway or |
|
1804 |
known to be invisible." |
|
1805 |
||
1806 |
selectionStartLine := nil. |
|
1807 |
! |
|
1808 |
||
1809 |
validateNewSelection |
|
1810 |
^ self |
|
1811 |
! |
|
1812 |
||
1813 |
wordAtLine:selectLine col:selectCol do:aFiveArgBlock |
|
1814 |
"find word boundaries, evaluate the block argument with those. |
|
1815 |
A helper for nextWord and selectWord functions." |
|
1816 |
||
1817 |
|beginCol endCol endLine thisCharacter flag| |
|
1818 |
||
1819 |
flag := #word. |
|
1820 |
beginCol := selectCol. |
|
1821 |
endCol := selectCol. |
|
1822 |
endLine := selectLine. |
|
1823 |
thisCharacter := self characterAtLine:selectLine col:beginCol. |
|
1824 |
||
1825 |
beginCol := self findBeginOfWordAtLine:selectLine col:selectCol. |
|
1826 |
endCol := self findEndOfWordAtLine:selectLine col:selectCol. |
|
1827 |
endCol == 0 ifTrue:[ |
|
1828 |
endLine := selectLine + 1 |
|
1829 |
]. |
|
1830 |
||
1831 |
"is the initial acharacter within a word ?" |
|
1832 |
(wordCheck value:thisCharacter) ifTrue:[ |
|
1833 |
" |
|
1834 |
try to catch a blank ... |
|
1835 |
" |
|
1836 |
((beginCol == 1) |
|
1837 |
or:[(self characterAtLine:selectLine col:(beginCol - 1)) |
|
1838 |
~~ Character space]) ifTrue:[ |
|
1839 |
((self characterAtLine:selectLine col:(endCol + 1)) |
|
1840 |
== Character space) ifTrue:[ |
|
1841 |
endCol := endCol + 1. |
|
1842 |
flag := #wordRight |
|
1843 |
] |
|
1844 |
] ifFalse:[ |
|
1845 |
beginCol := beginCol - 1. |
|
1846 |
flag := #wordLeft |
|
1847 |
]. |
|
1848 |
]. |
|
1849 |
aFiveArgBlock value:selectLine |
|
1850 |
value:beginCol |
|
1851 |
value:endLine |
|
1852 |
value:endCol |
|
1853 |
value:flag |
|
1854 |
! ! |
|
1855 |
||
1856 |
!TextView class methodsFor:'documentation'! |
|
1857 |
||
1858 |
version |
|
309
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
1859 |
^ '$Header: /cvs/stx/stx/libwidg/TextView.st,v 1.33 1996-01-27 15:37:22 cg Exp $' |
248 | 1860 |
! ! |