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