author | Claus Gittinger <cg@exept.de> |
Tue, 05 Dec 1995 20:12:25 +0100 | |
changeset 238 | a81e517187e4 |
parent 209 | 7a6db7fac566 |
child 248 | c58fabf73c35 |
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 |
|
209
7a6db7fac566
dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
50 |
^ '$Header: /cvs/stx/stx/libwidg/TextView.st,v 1.29 1995-11-24 12:56:21 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 |
||
209
7a6db7fac566
dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
648 |
validateNewSelection |
7a6db7fac566
dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
649 |
^ self |
7a6db7fac566
dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
650 |
! |
7a6db7fac566
dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
651 |
|
0 | 652 |
unselectWithoutRedraw |
653 |
"forget selection but do not redraw the selection area |
|
120 | 654 |
- can be done when the selected area is redrawn anyway or |
0 | 655 |
known to be invisible." |
656 |
||
657 |
selectionStartLine := nil. |
|
658 |
! |
|
659 |
||
660 |
unselect |
|
38 | 661 |
"unselect - if there was a selection redraw that area" |
0 | 662 |
|
663 |
|startLine endLine startVisLine endVisLine| |
|
664 |
||
665 |
selectionStartLine notNil ifTrue:[ |
|
59 | 666 |
startLine := selectionStartLine. |
667 |
endLine := selectionEndLine. |
|
668 |
selectionStartLine := nil. |
|
0 | 669 |
|
59 | 670 |
"if selection is not visible, we are done" |
671 |
startLine >= (firstLineShown + nLinesShown) ifTrue:[^ self]. |
|
672 |
endLine < firstLineShown ifTrue:[^ self]. |
|
0 | 673 |
|
59 | 674 |
startLine < firstLineShown ifTrue:[ |
675 |
startVisLine := 1 |
|
676 |
] ifFalse:[ |
|
677 |
startVisLine := self listLineToVisibleLine:startLine |
|
678 |
]. |
|
679 |
endLine >= (firstLineShown + nLinesShown) ifTrue:[ |
|
680 |
endVisLine := nLinesShown |
|
681 |
] ifFalse:[ |
|
682 |
endVisLine := self listLineToVisibleLine:endLine |
|
683 |
]. |
|
684 |
"if its only part of a line, just redraw what has to be" |
|
685 |
(startVisLine == endVisLine) ifTrue:[ |
|
686 |
super redrawVisibleLine:startVisLine from:selectionStartCol to:selectionEndCol |
|
687 |
] ifFalse:[ |
|
688 |
super redrawFromVisibleLine:startVisLine to:endVisLine |
|
689 |
]. |
|
690 |
self unselectWithoutRedraw |
|
0 | 691 |
]. |
38 | 692 |
selectStyle := nil |
0 | 693 |
! |
694 |
||
695 |
selectFromLine:startLine col:startCol toLine:endLine col:endCol |
|
38 | 696 |
"select a piece of text and redraw that area" |
0 | 697 |
|
698 |
self unselect. |
|
699 |
startLine notNil ifTrue:[ |
|
59 | 700 |
"new:" |
701 |
endLine < startLine ifTrue:[ |
|
702 |
^ self selectFromLine:endLine col:endCol toLine:startLine col:startCol |
|
703 |
]. |
|
704 |
(endLine == startLine and:[endCol < startCol]) ifTrue:[ |
|
131 | 705 |
endCol ~~ 0 ifTrue:[ |
706 |
self selectFromLine:endLine col:endCol toLine:startLine col:startCol. |
|
707 |
]. |
|
708 |
^ self |
|
59 | 709 |
]. |
7 | 710 |
|
711 |
" old: |
|
59 | 712 |
endLine < startLine ifTrue:[^ self]. |
713 |
(startLine == endLine and:[endCol < startCol]) ifTrue:[^ self]. |
|
7 | 714 |
" |
59 | 715 |
selectionStartLine := startLine. |
716 |
selectionStartCol := startCol. |
|
717 |
selectionEndLine := endLine. |
|
718 |
selectionEndCol := endCol. |
|
719 |
(startLine == endLine) ifTrue:[ |
|
720 |
self redrawLine:startLine from:startCol to:endCol |
|
721 |
] ifFalse:[ |
|
722 |
startLine to:endLine do:[:lineNr | |
|
723 |
self redrawLine:lineNr |
|
724 |
] |
|
725 |
]. |
|
726 |
selectStyle := nil. |
|
0 | 727 |
] |
728 |
! |
|
729 |
||
730 |
selectLine:selectLine |
|
38 | 731 |
"select one line and redraw it" |
0 | 732 |
|
38 | 733 |
self selectFromLine:selectLine col:1 toLine:(selectLine + 1) col:0. |
734 |
wordStartCol := selectionStartCol. |
|
735 |
wordEndCol := selectionEndCol. |
|
736 |
wordStartLine := selectionStartLine. |
|
737 |
wordEndLine := selectionEndLine. |
|
738 |
selectStyle := #line |
|
0 | 739 |
! |
740 |
||
741 |
selectLineWhereCharacterPosition:pos |
|
742 |
"select the line, where characterPosition pos is living. |
|
38 | 743 |
The argument pos starts at 1 from the start of the text |
744 |
and counts characters (i.e. can be used to convert from |
|
745 |
character position within a string to line-position in view)." |
|
0 | 746 |
|
747 |
self selectLine:(self lineOfCharacterPosition:pos) |
|
748 |
! |
|
749 |
||
750 |
selectFromCharacterPosition:pos1 to:pos2 |
|
751 |
"compute line/col from character positions and select the text" |
|
752 |
||
753 |
|line1 col1 line2 col2| |
|
754 |
||
755 |
line1 := self lineOfCharacterPosition:pos1. |
|
756 |
col1 := pos1 - (self characterPositionOfLine:line1 col:1) + 1. |
|
757 |
line2 := self lineOfCharacterPosition:pos2. |
|
758 |
col2 := pos2 - (self characterPositionOfLine:line2 col:1) + 1. |
|
759 |
self selectFromLine:line1 col:col1 toLine:line2 col:col2 |
|
760 |
! |
|
761 |
||
59 | 762 |
wordAtLine:selectLine col:selectCol do:aFiveArgBlock |
763 |
"find word boundaries, evaluate the block argument with those. |
|
764 |
A helper for nextWord and selectWord functions." |
|
0 | 765 |
|
60 | 766 |
|beginCol endCol endLine thisCharacter flag| |
0 | 767 |
|
38 | 768 |
flag := #word. |
0 | 769 |
beginCol := selectCol. |
770 |
endCol := selectCol. |
|
38 | 771 |
endLine := selectLine. |
0 | 772 |
thisCharacter := self characterAtLine:selectLine col:beginCol. |
7 | 773 |
|
38 | 774 |
beginCol := self findBeginOfWordAtLine:selectLine col:selectCol. |
775 |
endCol := self findEndOfWordAtLine:selectLine col:selectCol. |
|
776 |
endCol == 0 ifTrue:[ |
|
59 | 777 |
endLine := selectLine + 1 |
38 | 778 |
]. |
779 |
||
780 |
"is the initial acharacter within a word ?" |
|
7 | 781 |
(wordCheck value:thisCharacter) ifTrue:[ |
59 | 782 |
" |
783 |
try to catch a blank ... |
|
784 |
" |
|
785 |
((beginCol == 1) |
|
786 |
or:[(self characterAtLine:selectLine col:(beginCol - 1)) |
|
787 |
~~ Character space]) ifTrue:[ |
|
788 |
((self characterAtLine:selectLine col:(endCol + 1)) |
|
789 |
== Character space) ifTrue:[ |
|
790 |
endCol := endCol + 1. |
|
791 |
flag := #wordRight |
|
792 |
] |
|
793 |
] ifFalse:[ |
|
794 |
beginCol := beginCol - 1. |
|
795 |
flag := #wordLeft |
|
796 |
]. |
|
0 | 797 |
]. |
59 | 798 |
aFiveArgBlock value:selectLine |
799 |
value:beginCol |
|
800 |
value:endLine |
|
801 |
value:endCol |
|
802 |
value:flag |
|
803 |
! |
|
804 |
||
805 |
selectWordAtLine:line col:col |
|
806 |
"select the word at given line/col" |
|
807 |
||
808 |
self wordAtLine:line col:col do:[ |
|
809 |
:beginLine :beginCol :endLine :endCol :style | |
|
810 |
||
811 |
self selectFromLine:beginLine col:beginCol toLine:endLine col:endCol. |
|
812 |
selectStyle := style |
|
813 |
] |
|
0 | 814 |
! |
815 |
||
816 |
selectWordAtX:x y:y |
|
817 |
"select the word at given x/y-(view-)coordinate" |
|
818 |
||
819 |
|selectVisibleLine selectLine selectCol| |
|
820 |
||
38 | 821 |
selectStyle := nil. |
0 | 822 |
selectVisibleLine := self visibleLineOfY:y. |
823 |
selectLine := self visibleLineToListLine:selectVisibleLine. |
|
824 |
selectLine notNil ifTrue:[ |
|
59 | 825 |
selectCol := self colOfX:x inVisibleLine:selectLine. |
826 |
self selectWordAtLine:selectLine col:selectCol |
|
0 | 827 |
] |
828 |
! |
|
829 |
||
830 |
selectLineAtY:y |
|
831 |
"select the line at given y-(view-)coordinate" |
|
832 |
||
833 |
|selectVisibleLine selectLine| |
|
834 |
||
835 |
selectVisibleLine := self visibleLineOfY:y. |
|
836 |
selectLine := self visibleLineToListLine:selectVisibleLine. |
|
837 |
selectLine notNil ifTrue:[ |
|
59 | 838 |
self selectLine:selectLine |
0 | 839 |
] |
840 |
! |
|
841 |
||
842 |
selectAll |
|
843 |
"select the whole text" |
|
844 |
||
845 |
self selectFromLine:1 col:1 toLine:(list size + 1) col:0 |
|
846 |
! |
|
847 |
||
38 | 848 |
hasSelection |
849 |
"return true, if there is a selection" |
|
850 |
||
851 |
^ selectionStartLine notNil |
|
852 |
! |
|
853 |
||
0 | 854 |
selection |
131 | 855 |
"return the selection as a collection of (line-)strings. |
856 |
If the selection ends in a full line, the last entry in the returned |
|
857 |
collection will be an empty string." |
|
0 | 858 |
|
131 | 859 |
|text sz index last |
81 | 860 |
startLine "{ Class: SmallInteger }" |
861 |
endLine "{ Class: SmallInteger }"| |
|
0 | 862 |
|
863 |
selectionStartLine isNil ifTrue:[^ nil]. |
|
81 | 864 |
startLine := selectionStartLine. |
865 |
endLine := selectionEndLine. |
|
866 |
||
867 |
(startLine == endLine) ifTrue:[ |
|
59 | 868 |
"part of a line" |
81 | 869 |
^ StringCollection with:(self listAt:startLine |
870 |
from:selectionStartCol |
|
871 |
to:selectionEndCol) |
|
0 | 872 |
]. |
81 | 873 |
sz := endLine - startLine + 1. |
874 |
text := StringCollection new:sz. |
|
0 | 875 |
|
876 |
"get 1st and last (possibly) partial lines" |
|
81 | 877 |
text at:1 put:(self listAt:startLine from:selectionStartCol). |
878 |
selectionEndCol == 0 ifTrue:[ |
|
131 | 879 |
last := '' |
81 | 880 |
] ifFalse:[ |
131 | 881 |
last := self listAt:selectionEndLine to:selectionEndCol. |
81 | 882 |
]. |
131 | 883 |
text at:sz put:last. |
0 | 884 |
|
885 |
"get bulk of text" |
|
886 |
index := 2. |
|
81 | 887 |
(startLine + 1) to:(endLine - 1) do:[:lineNr | |
59 | 888 |
text at:index put:(self listAt:lineNr). |
889 |
index := index + 1 |
|
0 | 890 |
]. |
891 |
^ text |
|
892 |
! |
|
893 |
||
131 | 894 |
selectionStartLine |
895 |
^ selectionStartLine |
|
896 |
! |
|
897 |
||
898 |
selectionStartCol |
|
899 |
^ selectionStartCol |
|
900 |
! |
|
901 |
||
902 |
selectionEndLine |
|
903 |
^ selectionEndLine |
|
904 |
! |
|
905 |
||
906 |
selectionEndCol |
|
907 |
^ selectionEndCol |
|
908 |
! |
|
909 |
||
0 | 910 |
makeSelectionVisible |
120 | 911 |
"scroll to make the selection visible" |
0 | 912 |
|
913 |
selectionStartLine notNil ifTrue:[ |
|
59 | 914 |
self makeLineVisible:selectionStartLine |
0 | 915 |
] |
916 |
! ! |
|
917 |
||
918 |
!TextView methodsFor:'searching'! |
|
919 |
||
920 |
search |
|
921 |
"show a box to enter searchpattern |
|
922 |
- currently no regular expressions are handled." |
|
923 |
||
63 | 924 |
" |
925 |
cache the searchBox |
|
926 |
Q: should we use one global searchBox for all textViews ? |
|
927 |
(we could then preserve the last searchstring between views) |
|
928 |
" |
|
126 | 929 |
|
930 |
"/ "soon to come: search & replace box ... |
|
931 |
"/ |box| |
|
932 |
"/ |
|
933 |
"/ box := Dialog new. |
|
934 |
"/ (box addTextLabel:(resources at:'searchPattern:')) layout:#left. |
|
935 |
"/ box addVerticalSpace. |
|
936 |
"/ box addInputFieldOn:'' asValue. |
|
937 |
"/ box addVerticalSpace. |
|
938 |
"/ (box addTextLabel:(resources at:'replace with:')) layout:#left. |
|
939 |
"/ box addVerticalSpace. |
|
940 |
"/ box addInputFieldOn:'' asValue. |
|
941 |
"/ box addAbortButtonLabelled:(resources at:'cancel'); |
|
942 |
"/ addButton:(Button label:(resources at:'all')); |
|
943 |
"/ addButton:(Button label:(resources at:'prev')); |
|
944 |
"/ addOkButtonLabelled:(resources at:'next'). |
|
945 |
"/ box open. |
|
946 |
||
0 | 947 |
searchBox isNil ifTrue:[ |
59 | 948 |
searchBox := |
949 |
EnterBox2 |
|
950 |
title:(resources at:'searchPattern:') |
|
951 |
okText1:(resources at:'prev') |
|
952 |
okText2:(resources at:'next') |
|
953 |
abortText:(resources at:'cancel') |
|
126 | 954 |
action1:[:pattern | pattern notEmpty ifTrue:[self searchBwd:(pattern withoutSeparators)]] |
955 |
action2:[:pattern | pattern notEmpty ifTrue:[self searchFwd:(pattern withoutSeparators)]] |
|
0 | 956 |
]. |
957 |
searchPattern notNil ifTrue:[ |
|
59 | 958 |
searchBox initialText:searchPattern |
0 | 959 |
]. |
63 | 960 |
self hasSelection ifTrue:[ |
961 |
selectionStartLine == selectionEndLine ifTrue:[ |
|
962 |
searchBox initialText:self selection |
|
963 |
] |
|
964 |
]. |
|
0 | 965 |
searchBox showAtPointer |
966 |
! |
|
967 |
||
63 | 968 |
setSearchPattern:aString |
969 |
"set the searchpattern for future searches" |
|
970 |
||
70 | 971 |
aString isNil ifTrue:[ |
972 |
searchPattern := aString |
|
973 |
] ifFalse:[ |
|
974 |
searchPattern := aString withoutSeparators |
|
975 |
] |
|
63 | 976 |
! |
977 |
||
0 | 978 |
setSearchPattern |
979 |
"set the searchpattern from the selection if there is one" |
|
980 |
||
981 |
|sel| |
|
982 |
||
983 |
sel := self selection. |
|
984 |
sel notNil ifTrue:[ |
|
59 | 985 |
searchPattern := sel asString withoutSeparators |
0 | 986 |
] |
987 |
! |
|
988 |
||
63 | 989 |
searchPattern |
990 |
"return the last search pattern" |
|
991 |
||
992 |
^ searchPattern |
|
993 |
! |
|
994 |
||
0 | 995 |
showNotFound |
996 |
"search not found - tell user by beeping and changing |
|
997 |
cursor for a while (sometimes I work with a headset :-) |
|
998 |
(used to be: tell user by changing cursor for a while)" |
|
999 |
||
1000 |
|savedCursor| |
|
1001 |
||
1002 |
device beep. |
|
77 | 1003 |
|
0 | 1004 |
" |
1005 |
uncomment if you want a CROSS cursor to be shown for a while .. |
|
1006 |
" |
|
1007 |
||
1008 |
" " |
|
1009 |
savedCursor := cursor. |
|
1010 |
self cursor:(Cursor cross). |
|
1011 |
OperatingSystem millisecondDelay:300. |
|
1012 |
self cursor:savedCursor |
|
1013 |
" " |
|
1014 |
! |
|
1015 |
||
131 | 1016 |
showMatch:pattern atLine:line col:col |
1017 |
"after a search, highlight the matched pattern. |
|
1018 |
The code below needs a rewrite to take care of match-characters |
|
1019 |
(for now, it only highlights simple patterns and '*string*' correctly)" |
|
1020 |
||
1021 |
|realPattern| |
|
1022 |
||
1023 |
realPattern := pattern. |
|
1024 |
(realPattern startsWith:$*) ifTrue:[ |
|
1025 |
realPattern := realPattern copyFrom:2 |
|
1026 |
]. |
|
1027 |
(realPattern endsWith:$*) ifTrue:[ |
|
1028 |
realPattern := realPattern copyWithoutLast:1 |
|
1029 |
]. |
|
1030 |
||
1031 |
self selectFromLine:line col:col |
|
1032 |
toLine:line col:(col + realPattern size - 1). |
|
1033 |
self makeLineVisible:line |
|
1034 |
! |
|
1035 |
||
0 | 1036 |
searchFwd |
1037 |
"search forward for pattern or selection" |
|
1038 |
||
63 | 1039 |
selectStyle == #wordLeft ifTrue:[ |
1040 |
" |
|
1041 |
remove the space from the selection |
|
1042 |
" |
|
1043 |
selectionStartCol := selectionStartCol + 1. |
|
1044 |
super redrawLine:selectionStartLine from:selectionStartCol-1 to:selectionStartCol-1. |
|
1045 |
]. |
|
0 | 1046 |
self setSearchPattern. |
1047 |
searchPattern notNil ifTrue:[ |
|
59 | 1048 |
self searchFwd:searchPattern |
0 | 1049 |
] |
1050 |
! |
|
1051 |
||
1052 |
searchBwd |
|
1053 |
"search backward and -if found- position cursor" |
|
1054 |
||
1055 |
self setSearchPattern. |
|
1056 |
searchPattern notNil ifTrue:[ |
|
59 | 1057 |
self searchBwd:searchPattern |
0 | 1058 |
] |
1059 |
! |
|
1060 |
||
1061 |
searchFwd:pattern |
|
63 | 1062 |
"do a forward search" |
1063 |
||
1064 |
self searchFwd:pattern ifAbsent:[self showNotFound]. |
|
1065 |
searchPattern := pattern |
|
1066 |
! |
|
1067 |
||
1068 |
searchBwd:pattern |
|
1069 |
"do a backward search" |
|
1070 |
||
1071 |
self searchBwd:pattern ifAbsent:[self showNotFound]. |
|
1072 |
searchPattern := pattern |
|
1073 |
||
1074 |
! |
|
1075 |
||
1076 |
searchFwd:pattern ifAbsent:aBlock |
|
1077 |
"do a forward search" |
|
0 | 1078 |
|
1079 |
|startLine startCol| |
|
1080 |
||
1081 |
selectionStartLine notNil ifTrue:[ |
|
59 | 1082 |
startLine := selectionStartLine. |
1083 |
startCol := selectionStartCol |
|
0 | 1084 |
] ifFalse:[ |
59 | 1085 |
startLine := 1. |
1086 |
startCol := 1 |
|
0 | 1087 |
]. |
1088 |
self searchForwardFor:pattern startingAtLine:startLine col:startCol |
|
1089 |
ifFound:[:line :col | |
|
131 | 1090 |
self showMatch:pattern atLine:line col:col |
63 | 1091 |
] ifAbsent:aBlock |
0 | 1092 |
! |
1093 |
||
63 | 1094 |
searchBwd:pattern ifAbsent:aBlock |
1095 |
"do a backward search" |
|
0 | 1096 |
|
1097 |
|startLine startCol| |
|
1098 |
||
1099 |
selectionStartLine notNil ifTrue:[ |
|
59 | 1100 |
startLine := selectionStartLine. |
1101 |
startCol := selectionStartCol |
|
0 | 1102 |
] ifFalse:[ |
59 | 1103 |
startLine := 1. |
1104 |
startCol := 1 |
|
0 | 1105 |
]. |
1106 |
self searchBackwardFor:pattern startingAtLine:startLine col:startCol |
|
1107 |
ifFound:[:line :col | |
|
131 | 1108 |
self showMatch:pattern atLine:line col:col |
63 | 1109 |
] ifAbsent:aBlock |
131 | 1110 |
! |
1111 |
||
1112 |
searchForMatchingParenthesisFromLine:startLine col:startCol |
|
1113 |
ifFound:foundBlock |
|
1114 |
ifNotFound:notFoundBlock |
|
1115 |
onError:failBlock |
|
1116 |
||
1117 |
"search for a matching parenthesis, parChar is one of '$( $[ ${ $) $] $}'. |
|
1118 |
Search for the corresponding character is done forward if its an opening, |
|
1119 |
backwards if its a closing parenthesis. |
|
1120 |
Performs foundBlock with line/col as argument if found, notFoundBlock if not. |
|
1121 |
If there is a nesting error, performs failBlock." |
|
1122 |
||
185
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1123 |
^ self |
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1124 |
searchForMatchingParenthesisFromLine:startLine col:startCol |
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1125 |
ifFound:foundBlock |
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1126 |
ifNotFound:notFoundBlock |
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1127 |
onError:failBlock |
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1128 |
ignoring:#( $' $" ) |
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1129 |
|
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1130 |
"Modified: 18.11.1995 / 16:28:23 / cg" |
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1131 |
! |
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1132 |
|
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1133 |
searchForMatchingParenthesisFromLine:startLine col:startCol |
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1134 |
ifFound:foundBlock |
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1135 |
ifNotFound:notFoundBlock |
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1136 |
onError:failBlock |
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1137 |
ignoring:ignoreSet |
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1138 |
"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
|
1139 |
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
|
1140 |
backwards if its a closing parenthesis. |
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1141 |
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
|
1142 |
If there is a nesting error, performs failBlock." |
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1143 |
|
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1144 |
|i direction lineString line col parChar charSet closingChar |
131 | 1145 |
ignoring delta endCol cc incSet decSet nesting maxLine| |
1146 |
||
1147 |
charSet := #( $( $) $[ $] ${ $} ). |
|
1148 |
||
1149 |
parChar := self characterAtLine:startLine col:startCol. |
|
1150 |
i := charSet indexOf:parChar. |
|
1151 |
i == 0 ifTrue:[ |
|
1152 |
^ failBlock value "not a parenthesis" |
|
1153 |
]. |
|
1154 |
direction := #( fwd bwd fwd bwd fwd bwd) at:i. |
|
1155 |
closingChar := #( $) $( $] $[ $} ${ ) at:i. |
|
1156 |
||
1157 |
col := startCol. |
|
1158 |
line := startLine. |
|
1159 |
direction == #fwd ifTrue:[ |
|
1160 |
delta := 1. |
|
1161 |
incSet := #( $( $[ ${ ). |
|
1162 |
decSet := #( $) $] $} ). |
|
1163 |
] ifFalse:[ |
|
1164 |
delta := -1. |
|
1165 |
incSet := #( $) $] $} ). |
|
1166 |
decSet := #( $( $[ ${ ). |
|
1167 |
]. |
|
1168 |
||
1169 |
nesting := 1. |
|
1170 |
ignoring := false. |
|
1171 |
lineString := list at:line. |
|
1172 |
maxLine := list size. |
|
1173 |
||
1174 |
col := col + delta. |
|
1175 |
[nesting ~~ 0] whileTrue:[ |
|
1176 |
lineString notNil ifTrue:[ |
|
1177 |
direction == #fwd ifTrue:[ |
|
1178 |
endCol := lineString size. |
|
1179 |
] ifFalse:[ |
|
1180 |
endCol := 1 |
|
1181 |
]. |
|
1182 |
col to:endCol by:delta do:[:runCol | |
|
1183 |
cc := lineString at:runCol. |
|
1184 |
||
1185 |
(ignoreSet includes:cc) ifTrue:[ |
|
1186 |
ignoring := ignoring not |
|
1187 |
]. |
|
1188 |
ignoring ifFalse:[ |
|
1189 |
(incSet includes:cc) ifTrue:[ |
|
1190 |
nesting := nesting + 1 |
|
1191 |
] ifFalse:[ |
|
1192 |
(decSet includes:cc) ifTrue:[ |
|
1193 |
nesting := nesting - 1 |
|
1194 |
] |
|
1195 |
] |
|
1196 |
]. |
|
1197 |
nesting == 0 ifTrue:[ |
|
1198 |
"check if legal" |
|
1199 |
||
1200 |
cc == closingChar ifFalse:[ |
|
1201 |
^ failBlock value |
|
1202 |
]. |
|
1203 |
^ foundBlock value:line value:runCol. |
|
1204 |
] |
|
1205 |
]. |
|
1206 |
]. |
|
1207 |
line := line + delta. |
|
1208 |
(line < 1 or:[line > maxLine]) ifTrue:[ |
|
1209 |
^ failBlock value |
|
1210 |
]. |
|
1211 |
lineString := list at:line. |
|
1212 |
direction == #fwd ifTrue:[ |
|
1213 |
col := 1 |
|
1214 |
] ifFalse:[ |
|
1215 |
col := lineString size |
|
1216 |
] |
|
1217 |
]. |
|
1218 |
||
1219 |
^ notFoundBlock value |
|
185
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1220 |
|
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1221 |
"Modified: 18.11.1995 / 16:30:56 / cg" |
0 | 1222 |
! ! |
1223 |
||
1224 |
!TextView methodsFor:'redrawing'! |
|
1225 |
||
1226 |
clearMarginOfVisible:visLine with:color |
|
1227 |
"if there is a margin, clear it - a helper for selection drawing" |
|
1228 |
||
1229 |
(leftMargin ~~ 0) ifTrue:[ |
|
59 | 1230 |
self paint:color. |
1231 |
self fillRectangleX:margin |
|
1232 |
y:(self yOfVisibleLine:visLine) |
|
1233 |
width:leftMargin |
|
1234 |
height:fontHeight |
|
0 | 1235 |
] |
1236 |
! |
|
1237 |
||
1238 |
redrawVisibleLine:visLine col:col |
|
1239 |
"redraw single character at col in visible line lineNr" |
|
1240 |
||
1241 |
|line| |
|
1242 |
||
1243 |
line := self visibleLineToAbsoluteLine:visLine. |
|
1244 |
selectionStartLine notNil ifTrue:[ |
|
59 | 1245 |
(line between:selectionStartLine and:selectionEndLine) ifTrue:[ |
1246 |
((line == selectionStartLine) |
|
1247 |
and: [col < selectionStartCol]) ifFalse:[ |
|
1248 |
((line == selectionEndLine) |
|
1249 |
and: [col > selectionEndCol]) ifFalse:[ |
|
1250 |
"its in the selection" |
|
1251 |
self drawVisibleLine:visLine col:col with:selectionFgColor |
|
1252 |
and:selectionBgColor. |
|
1253 |
^ self |
|
1254 |
] |
|
1255 |
] |
|
1256 |
] |
|
0 | 1257 |
]. |
1258 |
super redrawVisibleLine:visLine col:col |
|
1259 |
! |
|
1260 |
||
1261 |
redrawFromVisibleLine:startVisLineNr to:endVisLineNr |
|
1262 |
"redraw a visible line range" |
|
1263 |
||
1264 |
|startLine endLine specialCare end selVisStart line1 line2| |
|
1265 |
||
1266 |
shown ifFalse:[^ self]. |
|
1267 |
||
1268 |
end := endVisLineNr. |
|
1269 |
(end > nLinesShown) ifTrue:[ |
|
59 | 1270 |
end := nLinesShown |
0 | 1271 |
]. |
1272 |
||
1273 |
selectionStartLine isNil ifTrue:[ |
|
59 | 1274 |
specialCare := false |
0 | 1275 |
] ifFalse:[ |
59 | 1276 |
startLine := self visibleLineToAbsoluteLine:startVisLineNr. |
1277 |
(startLine > selectionEndLine) ifTrue:[ |
|
1278 |
specialCare := false |
|
1279 |
] ifFalse:[ |
|
1280 |
endLine := self visibleLineToAbsoluteLine:end. |
|
1281 |
(endLine < selectionStartLine) ifTrue:[ |
|
1282 |
specialCare := false |
|
1283 |
] ifFalse:[ |
|
1284 |
specialCare := true |
|
1285 |
] |
|
1286 |
] |
|
0 | 1287 |
]. |
1288 |
||
1289 |
"easy: nothing is selected" |
|
1290 |
specialCare ifFalse:[ |
|
59 | 1291 |
super redrawFromVisibleLine:startVisLineNr to:end. |
1292 |
^ self |
|
0 | 1293 |
]. |
1294 |
||
1295 |
"easy: all is selected" |
|
1296 |
((selectionStartLine < startLine) and:[selectionEndLine > endLine]) ifTrue:[ |
|
59 | 1297 |
self drawFromVisibleLine:startVisLineNr to:end with:selectionFgColor |
1298 |
and:selectionBgColor. |
|
1299 |
^ self |
|
0 | 1300 |
]. |
1301 |
||
1302 |
(selectionStartLine >= firstLineShown) ifTrue:[ |
|
59 | 1303 |
"draw unselected top part" |
0 | 1304 |
|
59 | 1305 |
selVisStart := self listLineToVisibleLine:selectionStartLine. |
1306 |
super redrawFromVisibleLine:startVisLineNr to:(selVisStart - 1). |
|
0 | 1307 |
|
59 | 1308 |
"and first partial selected line" |
1309 |
self redrawVisibleLine:selVisStart. |
|
0 | 1310 |
|
59 | 1311 |
"rest starts after this one" |
1312 |
line1 := selVisStart + 1 |
|
0 | 1313 |
] ifFalse:[ |
59 | 1314 |
line1 := 1 |
0 | 1315 |
]. |
1316 |
||
1317 |
(line1 > end) ifTrue:[^ self]. |
|
1318 |
(line1 < startVisLineNr) ifTrue:[ |
|
59 | 1319 |
line1 := startVisLineNr |
0 | 1320 |
]. |
1321 |
||
1322 |
"draw middle part of selection" |
|
1323 |
||
1324 |
(selectionEndLine >= (firstLineShown + nLinesShown)) ifTrue:[ |
|
59 | 1325 |
line2 := nLinesShown |
0 | 1326 |
] ifFalse:[ |
59 | 1327 |
line2 := (self listLineToVisibleLine:selectionEndLine) - 1 |
0 | 1328 |
]. |
1329 |
(line2 > end) ifTrue:[ |
|
59 | 1330 |
line2 := end |
0 | 1331 |
]. |
1332 |
||
1333 |
self drawFromVisibleLine:line1 to:line2 with:selectionFgColor |
|
59 | 1334 |
and:selectionBgColor. |
0 | 1335 |
|
1336 |
(line2 >= end) ifTrue:[^ self]. |
|
1337 |
||
1338 |
"last line of selection" |
|
1339 |
self redrawVisibleLine:(line2 + 1). |
|
1340 |
||
1341 |
((line2 + 2) <= end) ifTrue:[ |
|
59 | 1342 |
super redrawFromVisibleLine:(line2 + 2) to:end |
0 | 1343 |
] |
1344 |
! |
|
1345 |
||
1346 |
redrawVisibleLine:visLine |
|
1347 |
"redraw visible line lineNr" |
|
1348 |
||
1349 |
|len line l| |
|
1350 |
||
1351 |
selectionStartLine notNil ifTrue:[ |
|
59 | 1352 |
line := self visibleLineToAbsoluteLine:visLine. |
1353 |
(line between:selectionStartLine and:selectionEndLine) ifTrue:[ |
|
1354 |
(line == selectionStartLine) ifTrue:[ |
|
1355 |
(line == selectionEndLine) ifTrue:[ |
|
1356 |
"its part-of-single-line selection" |
|
1357 |
self clearMarginOfVisible:visLine with:bgColor. |
|
1358 |
(selectionStartCol > 1) ifTrue:[ |
|
1359 |
super redrawVisibleLine:visLine |
|
1360 |
from:1 |
|
1361 |
to:(selectionStartCol - 1) |
|
1362 |
]. |
|
1363 |
self drawVisibleLine:visLine from:selectionStartCol |
|
1364 |
to:selectionEndCol |
|
1365 |
with:selectionFgColor |
|
1366 |
and:selectionBgColor. |
|
1367 |
super redrawVisibleLine:visLine |
|
1368 |
from:(selectionEndCol + 1). |
|
1369 |
^ self |
|
1370 |
]. |
|
0 | 1371 |
|
59 | 1372 |
"its the first line of a multi-line selection" |
1373 |
(selectionStartCol ~~ 1) ifTrue:[ |
|
1374 |
self clearMarginOfVisible:visLine with:bgColor. |
|
1375 |
super redrawVisibleLine:visLine |
|
1376 |
from:1 |
|
1377 |
to:(selectionStartCol - 1) |
|
77 | 1378 |
] ifFalse:[ |
1379 |
leftOffset == 0 ifTrue:[ |
|
1380 |
self clearMarginOfVisible:visLine with:selectionBgColor. |
|
1381 |
] |
|
59 | 1382 |
]. |
1383 |
self drawVisibleLine:visLine from:selectionStartCol |
|
1384 |
with:selectionFgColor and:selectionBgColor. |
|
1385 |
^ self |
|
1386 |
]. |
|
0 | 1387 |
|
59 | 1388 |
(line == selectionEndLine) ifTrue:[ |
1389 |
"its the last line of a multi-line selection" |
|
1390 |
(selectionEndCol == 0) ifTrue:[ |
|
1391 |
^ super redrawVisibleLine:visLine |
|
1392 |
]. |
|
1393 |
l := self visibleAt:selectionEndLine. |
|
1394 |
len := l size. |
|
0 | 1395 |
|
59 | 1396 |
self clearMarginOfVisible:visLine with:selectionBgColor. |
1397 |
self drawVisibleLine:visLine from:1 to:selectionEndCol |
|
1398 |
with:selectionFgColor and:selectionBgColor. |
|
1399 |
super redrawVisibleLine:visLine from:(selectionEndCol + 1). |
|
1400 |
^ self |
|
1401 |
]. |
|
0 | 1402 |
|
59 | 1403 |
"its a full line in a multi-line selection" |
1404 |
self clearMarginOfVisible:visLine with:selectionBgColor. |
|
1405 |
self drawVisibleLine:visLine with:selectionFgColor and:selectionBgColor. |
|
1406 |
^ self |
|
1407 |
] |
|
0 | 1408 |
]. |
7 | 1409 |
super redrawVisibleLine:visLine |
0 | 1410 |
! |
1411 |
||
1412 |
redrawVisibleLine:visLine from:startCol |
|
1413 |
"redraw visible line lineNr from startCol to end of line" |
|
1414 |
||
1415 |
|line| |
|
1416 |
||
1417 |
line := self visibleLineToAbsoluteLine:visLine. |
|
1418 |
selectionStartLine notNil ifTrue:[ |
|
59 | 1419 |
(line between:selectionStartLine and:selectionEndLine) ifTrue:[ |
1420 |
((line == selectionStartLine) |
|
1421 |
or:[line == selectionEndLine]) ifTrue:[ |
|
1422 |
"since I'm lazy, redraw full line" |
|
1423 |
self redrawVisibleLine:visLine. |
|
1424 |
^ self |
|
1425 |
]. |
|
1426 |
"the line is fully within the selection" |
|
1427 |
self drawVisibleLine:visLine from:startCol with:selectionFgColor |
|
1428 |
and:selectionBgColor. |
|
1429 |
^ self |
|
1430 |
] |
|
0 | 1431 |
]. |
1432 |
super redrawVisibleLine:visLine from:startCol |
|
1433 |
! |
|
1434 |
||
1435 |
redrawVisibleLine:visLine from:startCol to:endCol |
|
1436 |
"redraw visible line lineNr from startCol to endCol" |
|
1437 |
||
1438 |
|line allOut allIn leftCol rightCol| |
|
1439 |
||
1440 |
line := self visibleLineToAbsoluteLine:visLine. |
|
1441 |
||
1442 |
allIn := false. |
|
1443 |
allOut := false. |
|
1444 |
selectionStartLine isNil ifTrue:[ |
|
59 | 1445 |
allOut := true |
0 | 1446 |
] ifFalse:[ |
59 | 1447 |
(line between:selectionStartLine and:selectionEndLine) ifFalse:[ |
1448 |
allOut := true |
|
1449 |
] ifTrue:[ |
|
1450 |
(selectionStartLine == selectionEndLine) ifTrue:[ |
|
1451 |
((endCol < selectionStartCol) |
|
1452 |
or:[startCol > selectionEndCol]) ifTrue:[ |
|
1453 |
allOut := true |
|
1454 |
] ifFalse:[ |
|
1455 |
((startCol >= selectionStartCol) |
|
1456 |
and:[endCol <= selectionEndCol]) ifTrue:[ |
|
1457 |
allIn := true |
|
1458 |
] |
|
1459 |
] |
|
1460 |
] ifFalse:[ |
|
1461 |
(line == selectionStartLine) ifTrue:[ |
|
1462 |
(endCol < selectionStartCol) ifTrue:[ |
|
1463 |
allOut := true |
|
1464 |
] ifFalse:[ |
|
1465 |
(startCol >= selectionStartCol) ifTrue:[ |
|
1466 |
allIn := true |
|
1467 |
] |
|
1468 |
] |
|
1469 |
] ifFalse:[ |
|
1470 |
(line == selectionEndLine) ifTrue:[ |
|
1471 |
(startCol > selectionEndCol) ifTrue:[ |
|
1472 |
allOut := true |
|
1473 |
] ifFalse:[ |
|
1474 |
(endCol <= selectionEndCol) ifTrue:[ |
|
1475 |
allIn := true |
|
1476 |
] |
|
1477 |
] |
|
1478 |
] ifFalse:[ |
|
1479 |
allIn := true |
|
1480 |
] |
|
1481 |
] |
|
1482 |
] |
|
1483 |
] |
|
0 | 1484 |
]. |
1485 |
allOut ifTrue:[ |
|
59 | 1486 |
super redrawVisibleLine:visLine from:startCol to:endCol. |
1487 |
^ self |
|
0 | 1488 |
]. |
1489 |
||
1490 |
allIn ifTrue:[ |
|
59 | 1491 |
self drawVisibleLine:visLine from:startCol to:endCol |
1492 |
with:selectionFgColor and:selectionBgColor |
|
0 | 1493 |
] ifFalse:[ |
59 | 1494 |
"redraw part before selection" |
1495 |
((line == selectionStartLine) |
|
1496 |
and:[startCol <= selectionStartCol]) ifTrue:[ |
|
1497 |
super redrawVisibleLine:visLine from:startCol |
|
1498 |
to:(selectionStartCol - 1). |
|
1499 |
leftCol := selectionStartCol |
|
1500 |
] ifFalse:[ |
|
1501 |
leftCol := startCol |
|
1502 |
]. |
|
1503 |
"redraw selected part" |
|
1504 |
(selectionEndLine > line) ifTrue:[ |
|
1505 |
rightCol := endCol |
|
1506 |
] ifFalse:[ |
|
1507 |
rightCol := selectionEndCol min:endCol |
|
1508 |
]. |
|
1509 |
self drawVisibleLine:visLine from:leftCol to:rightCol |
|
1510 |
with:selectionFgColor and:selectionBgColor. |
|
0 | 1511 |
|
59 | 1512 |
"redraw part after selection" |
1513 |
(rightCol < endCol) ifTrue:[ |
|
1514 |
super redrawVisibleLine:visLine from:(rightCol + 1) to:endCol |
|
1515 |
] |
|
0 | 1516 |
]. |
1517 |
||
1518 |
"special care for first and last line of selection: |
|
1519 |
must handle margin also" |
|
1520 |
||
1521 |
((line == selectionEndLine) |
|
1522 |
and:[(startCol == 1) |
|
1523 |
and:[selectionStartLine < selectionEndLine]]) |
|
1524 |
ifTrue:[ |
|
59 | 1525 |
self clearMarginOfVisible:visLine with:selectionBgColor. |
0 | 1526 |
]. |
1527 |
||
1528 |
((line == selectionStartLine) |
|
1529 |
and:[(startCol == 1) |
|
1530 |
and:[selectionStartLine < selectionEndLine]]) |
|
1531 |
ifTrue:[ |
|
59 | 1532 |
self clearMarginOfVisible:visLine with:bgColor. |
0 | 1533 |
] |
1534 |
! ! |
|
1535 |
||
1536 |
!TextView methodsFor:'event processing'! |
|
1537 |
||
45 | 1538 |
mapped |
1539 |
super mapped. |
|
1540 |
selectionFgColor := selectionFgColor on:device. |
|
1541 |
selectionBgColor := selectionBgColor on:device. |
|
1542 |
! |
|
1543 |
||
0 | 1544 |
keyPress:key x:x y:y |
1545 |
"handle some keyboard input (there is not much to be done here)" |
|
1546 |
||
132 | 1547 |
<resource: #keyboard (#Find #Copy #FindNext #FindPrev #SelectAll)> |
1548 |
||
0 | 1549 |
(key == #Find) ifTrue:[self search. ^self]. |
1550 |
(key == #Copy) ifTrue:[self copySelection. ^self]. |
|
1551 |
||
1552 |
(key == #FindNext) ifTrue:[self searchFwd. ^self]. |
|
1553 |
(key == #FindPrev) ifTrue:[self searchBwd. ^self]. |
|
1554 |
||
1555 |
(key == #SelectAll) ifTrue:[self selectAll. ^self]. |
|
1556 |
||
38 | 1557 |
" |
1558 |
shift-Fn defines a key-sequence |
|
1559 |
Fn pastes that sequence |
|
1560 |
cmd-Fn performs a 'doIt' on the sequence (Workspaces only) |
|
1561 |
||
1562 |
(see EditTextView>>keyPress:x:y and Workspace>>keyPress:x:y) |
|
1563 |
" |
|
131 | 1564 |
(('[fF][0-9]' match:key) |
1565 |
or:['[fF][0-9][0-9]' match:key]) ifTrue:[ |
|
59 | 1566 |
device shiftDown ifTrue:[ |
1567 |
(Smalltalk at:#FunctionKeySequences) isNil ifTrue:[ |
|
1568 |
Smalltalk at:#FunctionKeySequences put:Dictionary new |
|
1569 |
]. |
|
1570 |
(Smalltalk at:#FunctionKeySequences) at:key put:(self selection) |
|
1571 |
]. |
|
1572 |
^ self |
|
7 | 1573 |
]. |
1574 |
||
0 | 1575 |
super keyPress:key x:x y:y |
1576 |
! |
|
1577 |
||
1578 |
buttonPress:button x:x y:y |
|
1579 |
"mouse-click - prepare for selection change" |
|
1580 |
||
1581 |
|clickVisibleLine| |
|
1582 |
||
38 | 1583 |
((button == 1) or:[button == #select]) ifTrue:[ |
59 | 1584 |
clickVisibleLine := self visibleLineOfY:y. |
1585 |
clickCol := self colOfX:x inVisibleLine:clickVisibleLine. |
|
1586 |
clickLine := self visibleLineToAbsoluteLine:clickVisibleLine. |
|
1587 |
clickStartLine := clickLine. |
|
1588 |
clickStartCol := clickCol. |
|
1589 |
self unselect. |
|
1590 |
clickCount := 1 |
|
0 | 1591 |
] ifFalse:[ |
59 | 1592 |
super buttonPress:button x:x y:y |
0 | 1593 |
] |
1594 |
! |
|
1595 |
||
1596 |
buttonShiftPress:button x:x y:y |
|
1597 |
"mouse-click with shift - adding to selection" |
|
1598 |
||
1599 |
"very simple - just simulate a move" |
|
53 | 1600 |
^ self buttonMotion:(device button1MotionMask) x:x y:y |
0 | 1601 |
! |
1602 |
||
1603 |
buttonMultiPress:button x:x y:y |
|
1604 |
"multi-mouse-click - select word under pointer" |
|
1605 |
||
131 | 1606 |
|sel| |
1607 |
||
38 | 1608 |
((button == 1) or:[button == #select]) ifTrue:[ |
59 | 1609 |
clickCount notNil ifTrue:[ |
1610 |
clickCount := clickCount + 1. |
|
1611 |
(clickCount == 2) ifTrue:[ |
|
1612 |
self selectWordAtX:x y:y. |
|
1613 |
" |
|
131 | 1614 |
special - if clicked on a parenthesis, select to matching |
1615 |
" |
|
1616 |
((sel := self selection) size == 1 |
|
1617 |
and:[(sel := sel at:1) size == 1]) ifTrue:[ |
|
1618 |
('()[]{}<>' includes:(sel at:1)) ifTrue:[ |
|
1619 |
self searchForMatchingParenthesisFromLine:selectionStartLine col:selectionStartCol |
|
1620 |
ifFound:[:line :col | |
|
185
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1621 |
|prevLine prevCol| |
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1622 |
|
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1623 |
prevLine := firstLineShown. |
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1624 |
prevCol := leftOffset. |
131 | 1625 |
self selectFromLine:selectionStartLine col:selectionStartCol |
185
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1626 |
toLine:line col:col. |
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1627 |
"/ undo scroll operation ... |
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1628 |
(')]}>' includes:(sel at:1)) ifTrue:[ |
186 | 1629 |
(firstLineShown ~~ prevLine or:[prevCol ~~ leftOffset]) ifTrue:[ |
1630 |
(Delay forSeconds:MatchDelayTime) wait. |
|
1631 |
self scrollToLine:prevLine; scrollToCol:prevCol. |
|
1632 |
] |
|
1633 |
] ifFalse:[ |
|
1634 |
selectionEndLine > (firstLineShown + nFullLinesShown) ifTrue:[ |
|
1635 |
self makeLineVisible:selectionEndLine. |
|
1636 |
(Delay forSeconds:MatchDelayTime) wait. |
|
1637 |
self scrollToLine:prevLine; scrollToCol:prevCol. |
|
1638 |
] |
|
185
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1639 |
] |
131 | 1640 |
] |
1641 |
ifNotFound:[self showNotFound] |
|
1642 |
onError:[device beep]. |
|
1643 |
selectStyle := nil |
|
1644 |
] |
|
1645 |
]. |
|
1646 |
||
1647 |
" |
|
59 | 1648 |
remember words position in case of a drag following |
1649 |
" |
|
1650 |
wordStartLine := selectionStartLine. |
|
1651 |
wordEndLine := selectionEndLine. |
|
1652 |
selectStyle == #wordLeft ifTrue:[ |
|
1653 |
wordStartCol := selectionStartCol + 1 |
|
1654 |
] ifFalse:[ |
|
1655 |
wordStartCol := selectionStartCol. |
|
1656 |
]. |
|
1657 |
selectStyle == #wordRight ifTrue:[ |
|
1658 |
wordEndCol := selectionEndCol - 1 |
|
1659 |
] ifFalse:[ |
|
1660 |
wordEndCol := selectionEndCol |
|
1661 |
] |
|
1662 |
] ifFalse:[ |
|
1663 |
(clickCount == 3) ifTrue:[ |
|
1664 |
self selectLineAtY:y. |
|
1665 |
selectStyle := #line |
|
1666 |
] ifFalse:[ |
|
1667 |
(clickCount == 4) ifTrue:[ |
|
1668 |
self selectAll |
|
1669 |
] |
|
1670 |
] |
|
1671 |
] |
|
1672 |
] |
|
0 | 1673 |
] ifFalse:[ |
59 | 1674 |
super buttonMultiPress:button x:x y:y |
0 | 1675 |
] |
185
3bcf27f3ac8a
dont move when selecting a block
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1676 |
|
186 | 1677 |
"Modified: 18.11.1995 / 18:30:33 / cg" |
0 | 1678 |
! |
1679 |
||
53 | 1680 |
buttonMotion:buttonMask x:x y:y |
0 | 1681 |
"mouse-move while button was pressed - handle selection changes" |
1682 |
||
1683 |
|movedVisibleLine movedLine movedCol |
|
1684 |
movedUp |
|
1685 |
oldStartLine oldEndLine oldStartCol oldEndCol| |
|
1686 |
||
1687 |
clickLine isNil ifTrue:[^ self]. |
|
1688 |
||
63 | 1689 |
"is it the select or 1-button ?" |
1690 |
(device buttonMotionMask:buttonMask includesButton:#select) ifFalse:[ |
|
1691 |
(device buttonMotionMask:buttonMask includesButton:1) ifFalse:[ |
|
1692 |
^ self |
|
1693 |
]. |
|
53 | 1694 |
]. |
1695 |
||
0 | 1696 |
"if moved outside of view, start autoscroll" |
1697 |
(y < 0) ifTrue:[ |
|
59 | 1698 |
self compressMotionEvents:false. |
1699 |
self startAutoScrollUp:y. |
|
1700 |
^ self |
|
0 | 1701 |
]. |
1702 |
(y > height) ifTrue:[ |
|
59 | 1703 |
self compressMotionEvents:false. |
1704 |
self startAutoScrollDown:(y - height). |
|
1705 |
^ self |
|
1706 |
]. |
|
1707 |
((x < 0) and:[leftOffset ~~ 0]) ifTrue:[ |
|
1708 |
self compressMotionEvents:false. |
|
1709 |
self startAutoScrollLeft:x. |
|
1710 |
^ self |
|
1711 |
]. |
|
1712 |
(x > width) ifTrue:[ |
|
1713 |
self compressMotionEvents:false. |
|
1714 |
self startAutoScrollRight:(x - width). |
|
1715 |
^ self |
|
0 | 1716 |
]. |
1717 |
||
1718 |
"move inside - stop autoscroll if any" |
|
1719 |
autoScrollBlock notNil ifTrue:[ |
|
59 | 1720 |
self stopScrollSelect |
0 | 1721 |
]. |
1722 |
||
1723 |
movedVisibleLine := self visibleLineOfY:y. |
|
1724 |
movedLine := self visibleLineToAbsoluteLine:movedVisibleLine. |
|
1725 |
(x < leftMargin) ifTrue:[ |
|
59 | 1726 |
movedCol := 0 |
0 | 1727 |
] ifFalse:[ |
59 | 1728 |
movedCol := self colOfX:x inVisibleLine:movedVisibleLine |
0 | 1729 |
]. |
1730 |
((movedLine == clickLine) and:[movedCol == clickCol]) ifTrue:[^ self]. |
|
1731 |
||
1732 |
selectionStartLine isNil ifTrue:[ |
|
59 | 1733 |
selectionStartLine := clickLine. |
1734 |
selectionStartCol := clickCol. |
|
1735 |
selectionEndLine := selectionStartLine. |
|
1736 |
selectionEndCol := selectionStartCol |
|
0 | 1737 |
]. |
1738 |
oldStartLine := selectionStartLine. |
|
1739 |
oldEndLine := selectionEndLine. |
|
1740 |
oldStartCol := selectionStartCol. |
|
1741 |
oldEndCol := selectionEndCol. |
|
1742 |
||
1743 |
||
1744 |
"find out if we are before or after initial click" |
|
1745 |
movedUp := false. |
|
1746 |
(movedLine < clickStartLine) ifTrue:[ |
|
59 | 1747 |
movedUp := true |
0 | 1748 |
] ifFalse:[ |
59 | 1749 |
(movedLine == clickStartLine) ifTrue:[ |
1750 |
(movedCol < clickStartCol) ifTrue:[ |
|
1751 |
movedUp := true |
|
1752 |
] |
|
1753 |
] |
|
0 | 1754 |
]. |
1755 |
||
1756 |
movedUp ifTrue:[ |
|
59 | 1757 |
"change selectionStart" |
1758 |
selectionStartCol := movedCol. |
|
1759 |
selectionStartLine := movedLine. |
|
1760 |
selectionEndCol := clickStartCol. |
|
1761 |
selectionEndLine := clickStartLine. |
|
1762 |
selectStyle notNil ifTrue:[ |
|
1763 |
selectionEndCol := wordEndCol. |
|
1764 |
selectionEndLine := wordEndLine. |
|
1765 |
] |
|
0 | 1766 |
] ifFalse:[ |
59 | 1767 |
"change selectionEnd" |
1768 |
selectionEndCol := movedCol. |
|
1769 |
selectionEndLine := movedLine. |
|
1770 |
selectionStartCol := clickStartCol. |
|
1771 |
selectionStartLine := clickStartLine. |
|
1772 |
selectStyle notNil ifTrue:[ |
|
1773 |
selectionStartCol := wordStartCol. |
|
1774 |
selectionStartLine := wordStartLine. |
|
1775 |
] |
|
0 | 1776 |
]. |
1777 |
||
164 | 1778 |
selectionStartLine isNil ifTrue:[^ self]. |
1779 |
||
0 | 1780 |
(selectionStartCol == 0) ifTrue:[ |
59 | 1781 |
selectionStartCol := 1 |
0 | 1782 |
]. |
1783 |
||
38 | 1784 |
" |
1785 |
if in word-select, just catch the rest of the word |
|
1786 |
" |
|
1787 |
(selectStyle notNil and:[selectStyle startsWith:'word']) ifTrue:[ |
|
59 | 1788 |
movedUp ifTrue:[ |
1789 |
selectionStartCol := self findBeginOfWordAtLine:selectionStartLine col:selectionStartCol |
|
1790 |
] ifFalse:[ |
|
1791 |
selectionEndCol := self findEndOfWordAtLine:selectionEndLine col:selectionEndCol. |
|
1792 |
selectionEndCol == 0 ifTrue:[ |
|
1793 |
selectionEndLine := selectionEndLine + 1 |
|
1794 |
] |
|
1795 |
]. |
|
38 | 1796 |
]. |
1797 |
||
1798 |
selectStyle == #line ifTrue:[ |
|
59 | 1799 |
movedUp ifTrue:[ |
1800 |
selectionStartCol := 1. |
|
1801 |
] ifFalse:[ |
|
1802 |
selectionEndCol := 0. |
|
1803 |
selectionEndLine := selectionEndLine + 1 |
|
1804 |
] |
|
38 | 1805 |
]. |
1806 |
||
209
7a6db7fac566
dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
1807 |
self validateNewSelection. |
7a6db7fac566
dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
1808 |
|
0 | 1809 |
(oldStartLine == selectionStartLine) ifTrue:[ |
59 | 1810 |
(oldStartCol ~~ selectionStartCol) ifTrue:[ |
1811 |
self redrawLine:oldStartLine |
|
1812 |
from:((selectionStartCol min:oldStartCol) max:1) |
|
1813 |
to:((selectionStartCol max:oldStartCol) max:1) |
|
1814 |
] |
|
0 | 1815 |
] ifFalse:[ |
59 | 1816 |
self redrawFromLine:(oldStartLine min:selectionStartLine) |
1817 |
to:(oldStartLine max:selectionStartLine) |
|
0 | 1818 |
]. |
1819 |
||
1820 |
(oldEndLine == selectionEndLine) ifTrue:[ |
|
59 | 1821 |
(oldEndCol ~~ selectionEndCol) ifTrue:[ |
1822 |
self redrawLine:oldEndLine |
|
1823 |
from:((selectionEndCol min:oldEndCol) max:1) |
|
1824 |
to:((selectionEndCol max:oldEndCol) max:1) |
|
1825 |
] |
|
0 | 1826 |
] ifFalse:[ |
59 | 1827 |
self redrawFromLine:(oldEndLine min:selectionEndLine) |
1828 |
to:(oldEndLine max:selectionEndLine) |
|
0 | 1829 |
]. |
1830 |
clickLine := movedLine. |
|
1831 |
clickCol := movedCol |
|
1832 |
! |
|
1833 |
||
1834 |
buttonRelease:button x:x y:y |
|
1835 |
"mouse- button release - turn off autoScroll if any" |
|
1836 |
||
38 | 1837 |
((button == 1) or:[button == #select]) ifTrue:[ |
59 | 1838 |
autoScrollBlock notNil ifTrue:[ |
1839 |
self stopScrollSelect |
|
1840 |
]. |
|
0 | 1841 |
] ifFalse:[ |
59 | 1842 |
super buttonRelease:button x:x y:y |
0 | 1843 |
] |
1844 |
! ! |