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