0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
3 |
All Rights Reserved
|
|
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
|
|
15 |
selectionEndLine selectionEndCol
|
|
16 |
clickStartLine clickStartCol
|
|
17 |
clickLine clickCol clickCount
|
38
|
18 |
wordStartCol wordStartLine wordEndCol wordEndLine
|
0
|
19 |
selectionFgColor selectionBgColor
|
|
20 |
fileBox searchBox lineNumberBox
|
38
|
21 |
selectStyle
|
0
|
22 |
directoryForFileDialog
|
|
23 |
contentsWasSaved'
|
38
|
24 |
classVariableNames:'MyFontPanel
|
|
25 |
DefaultSelectionForegroundColor
|
|
26 |
DefaultSelectionBackgroundColor'
|
0
|
27 |
poolDictionaries:''
|
|
28 |
category:'Views-Text'
|
|
29 |
!
|
|
30 |
|
|
31 |
TextView comment:'
|
5
|
32 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
33 |
All Rights Reserved
|
|
34 |
|
38
|
35 |
$Header: /cvs/stx/stx/libwidg/TextView.st,v 1.7 1994-08-07 13:23:28 claus Exp $
|
0
|
36 |
'!
|
|
37 |
|
|
38 |
!TextView class methodsFor:'documentation'!
|
|
39 |
|
38
|
40 |
copyright
|
|
41 |
"
|
|
42 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
|
43 |
All Rights Reserved
|
|
44 |
|
|
45 |
This software is furnished under a license and may be used
|
|
46 |
only in accordance with the terms of that license and with the
|
|
47 |
inclusion of the above copyright notice. This software may not
|
|
48 |
be provided or otherwise made available to, or used by, any
|
|
49 |
other person. No title to or ownership of the software is
|
|
50 |
hereby transferred.
|
|
51 |
"
|
|
52 |
!
|
|
53 |
|
|
54 |
version
|
|
55 |
"
|
|
56 |
$Header: /cvs/stx/stx/libwidg/TextView.st,v 1.7 1994-08-07 13:23:28 claus Exp $
|
|
57 |
"
|
|
58 |
!
|
|
59 |
|
22
|
60 |
documentation
|
0
|
61 |
"
|
38
|
62 |
a view for text - this class adds selections to a simple list.
|
|
63 |
The text is not editable and there is no cursor.
|
|
64 |
Use TextViews for readonly text.
|
0
|
65 |
|
38
|
66 |
Instance variables:
|
0
|
67 |
|
38
|
68 |
selectionStartLine <Number> the line of the selection start (or nil)
|
|
69 |
selectionStartCol <Number> the col of the selection start
|
|
70 |
selectionEndLine <Number> the line of the selection end
|
|
71 |
selectionEndCol <Number> the col of the selection end
|
|
72 |
clickStartLine <Number> temporary
|
|
73 |
clickStartCol <Number> temporary
|
|
74 |
clickLine <Number> temporary
|
|
75 |
clickCol <Number> temporary
|
|
76 |
clickCount <Number> temporary
|
|
77 |
selectionFgColor <Color> color used to draw selections
|
|
78 |
selectionBgColor <Color> color used to draw selections
|
|
79 |
fileBox <FileSelectionBox> box for save
|
|
80 |
searchBox <EnterBox2> box to enter searchpattern
|
|
81 |
lineNumberBox <EnterBox> box to enter linenumber
|
|
82 |
selectStyle <Symbol> how words are selected
|
0
|
83 |
"
|
|
84 |
! !
|
|
85 |
|
|
86 |
!TextView class methodsFor:'startup'!
|
|
87 |
|
|
88 |
setupEmpty
|
|
89 |
"create a textview - a helper for startWith: and startOn:"
|
|
90 |
|
|
91 |
|top frame label|
|
|
92 |
|
|
93 |
label := 'unnamed'.
|
|
94 |
top := StandardSystemView label:label
|
|
95 |
icon:(Form fromFile:'Editor.xbm' resolution:100).
|
|
96 |
|
|
97 |
frame := ScrollableView for:self in:top.
|
|
98 |
frame origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
|
|
99 |
^ frame scrolledView
|
|
100 |
!
|
|
101 |
|
38
|
102 |
open
|
0
|
103 |
"start an empty TextView"
|
|
104 |
|
38
|
105 |
^ self openWith:nil
|
0
|
106 |
!
|
|
107 |
|
38
|
108 |
openWith:aString
|
0
|
109 |
"start a textView with aString as initial contents"
|
|
110 |
|
|
111 |
|top textView|
|
|
112 |
|
|
113 |
textView := self setupEmpty.
|
|
114 |
top := textView topView.
|
|
115 |
aString notNil ifTrue:[
|
|
116 |
textView contents:aString
|
|
117 |
].
|
|
118 |
|
7
|
119 |
top open.
|
0
|
120 |
^ textView
|
|
121 |
|
38
|
122 |
"TextView openWith:'some text'"
|
|
123 |
"EditTextView openWith:'some text'"
|
0
|
124 |
!
|
|
125 |
|
38
|
126 |
openOn:aFileName
|
0
|
127 |
"start a textView on a file"
|
|
128 |
|
|
129 |
|top textView|
|
|
130 |
|
|
131 |
textView := self setupEmpty.
|
|
132 |
top := textView topView.
|
|
133 |
aFileName notNil ifTrue:[
|
|
134 |
top label:(OperatingSystem baseNameOf:aFileName).
|
3
|
135 |
textView contents:(aFileName asFilename readStream contents)
|
0
|
136 |
].
|
|
137 |
|
7
|
138 |
top open.
|
0
|
139 |
^ textView
|
|
140 |
|
38
|
141 |
"TextView openOn:'../doc/info.doc'"
|
|
142 |
"EditTextView openOn:'../doc/info.doc'"
|
|
143 |
! !
|
|
144 |
|
|
145 |
!TextView class methodsFor:'flushing cached resources'!
|
|
146 |
|
|
147 |
updateClassResources
|
|
148 |
"sent on style changes ..."
|
|
149 |
|
|
150 |
DefaultSelectionForegroundColor := nil.
|
|
151 |
super updateClassResources.
|
0
|
152 |
! !
|
|
153 |
|
|
154 |
!TextView methodsFor:'initialize & release'!
|
|
155 |
|
|
156 |
initialize
|
|
157 |
super initialize.
|
7
|
158 |
contentsWasSaved := false.
|
0
|
159 |
!
|
|
160 |
|
|
161 |
initStyle
|
38
|
162 |
|defFg defBg|
|
|
163 |
|
0
|
164 |
super initStyle.
|
|
165 |
|
|
166 |
viewBackground := White.
|
|
167 |
|
38
|
168 |
DefaultSelectionForegroundColor isNil ifTrue:[
|
|
169 |
"
|
|
170 |
if running on a color display, we hilight by drawing black on green
|
|
171 |
(looks like a text-marker) otherwise, we draw reverse.
|
|
172 |
"
|
|
173 |
|
|
174 |
device hasColors ifTrue:[
|
|
175 |
defFg := fgColor.
|
|
176 |
defBg := Color red:0 green:100 blue:0
|
0
|
177 |
] ifFalse:[
|
38
|
178 |
device hasGreyscales ifTrue:[
|
|
179 |
defFg := fgColor.
|
|
180 |
defBg := Color lightGrey
|
|
181 |
] ifFalse:[
|
|
182 |
defFg := bgColor.
|
|
183 |
defBg := fgColor
|
|
184 |
]
|
|
185 |
].
|
|
186 |
DefaultSelectionForegroundColor := resources at:'SELECTION_FOREGROUND_COLOR' default:defFg.
|
|
187 |
DefaultSelectionBackgroundColor := resources at:'SELECTION_BACKGROUND_COLOR' default:defBg.
|
|
188 |
].
|
|
189 |
selectionFgColor := DefaultSelectionForegroundColor.
|
|
190 |
selectionBgColor := DefaultSelectionBackgroundColor.
|
0
|
191 |
!
|
|
192 |
|
|
193 |
initEvents
|
|
194 |
super initEvents.
|
|
195 |
self enableButtonEvents.
|
|
196 |
self enableButtonMotionEvents
|
|
197 |
!
|
|
198 |
|
|
199 |
realize
|
|
200 |
super realize.
|
|
201 |
selectionFgColor := selectionFgColor on:device.
|
|
202 |
selectionBgColor := selectionBgColor on:device.
|
|
203 |
!
|
|
204 |
|
|
205 |
initializeMiddleButtonMenu
|
|
206 |
|labels|
|
|
207 |
|
|
208 |
labels := resources array:#(
|
|
209 |
'copy'
|
|
210 |
'-'
|
38
|
211 |
'font ...'
|
0
|
212 |
'-'
|
38
|
213 |
'search ...'
|
|
214 |
'goto ...'
|
0
|
215 |
'-'
|
22
|
216 |
'save as ...'
|
0
|
217 |
'print').
|
|
218 |
|
|
219 |
self middleButtonMenu:(PopUpMenu
|
|
220 |
labels:labels
|
|
221 |
selectors:#(copySelection
|
|
222 |
nil
|
|
223 |
changeFont
|
|
224 |
nil
|
|
225 |
search
|
|
226 |
gotoLine
|
|
227 |
nil
|
|
228 |
save
|
|
229 |
print)
|
|
230 |
receiver:self
|
|
231 |
for:self).
|
|
232 |
|
|
233 |
self enableOrDisableSelectionMenuEntries
|
|
234 |
!
|
|
235 |
|
|
236 |
destroy
|
|
237 |
fileBox notNil ifTrue:[
|
|
238 |
fileBox destroy.
|
|
239 |
fileBox := nil
|
|
240 |
].
|
|
241 |
searchBox notNil ifTrue:[
|
|
242 |
searchBox destroy.
|
|
243 |
searchBox := nil
|
|
244 |
].
|
|
245 |
lineNumberBox notNil ifTrue:[
|
|
246 |
lineNumberBox destroy.
|
|
247 |
lineNumberBox := nil
|
|
248 |
].
|
|
249 |
super destroy
|
|
250 |
! !
|
|
251 |
|
|
252 |
!TextView methodsFor:'accessing'!
|
|
253 |
|
|
254 |
selectionForegroundColor:color1 backgroundColor:color2
|
|
255 |
"set both selection-foreground and cursor background colors"
|
|
256 |
|
|
257 |
selectionFgColor := color1 on:device.
|
|
258 |
selectionBgColor := color2 on:device.
|
|
259 |
shown ifTrue:[
|
|
260 |
self redraw
|
|
261 |
]
|
|
262 |
!
|
|
263 |
|
|
264 |
setList:something
|
|
265 |
"set the displayed contents (a collection of strings)
|
|
266 |
without redraw.
|
|
267 |
Redefined since changing contents implies deselect"
|
|
268 |
|
|
269 |
self unselect.
|
|
270 |
super setList:something
|
|
271 |
!
|
|
272 |
|
|
273 |
list:something
|
|
274 |
"set the displayed contents (a collection of strings)
|
|
275 |
with redraw.
|
|
276 |
Redefined since changing contents implies deselect"
|
|
277 |
|
|
278 |
self unselect.
|
|
279 |
super list:something
|
|
280 |
!
|
|
281 |
|
|
282 |
characterAtLine:lineNr col:colNr
|
|
283 |
"return the character at physical line/col -
|
|
284 |
return space if nothing is there"
|
|
285 |
|
|
286 |
|line|
|
|
287 |
|
|
288 |
list notNil ifTrue:[
|
|
289 |
line := self listAt:lineNr.
|
|
290 |
line notNil ifTrue:[
|
|
291 |
(line size >= colNr) ifTrue:[
|
|
292 |
^ line at:colNr
|
|
293 |
]
|
|
294 |
]
|
|
295 |
].
|
|
296 |
^ Character space
|
|
297 |
!
|
|
298 |
|
|
299 |
characterPositionOfSelection
|
|
300 |
"return the character index of the first character in the selection"
|
|
301 |
|
|
302 |
selectionStartLine isNil ifTrue:[^ 1].
|
|
303 |
^ self characterPositionOfLine:selectionStartLine
|
|
304 |
col:selectionStartCol
|
|
305 |
!
|
|
306 |
|
|
307 |
directoryForFileDialog:aDirectory
|
|
308 |
"define the directory to use for save-box"
|
|
309 |
|
|
310 |
directoryForFileDialog := aDirectory
|
|
311 |
!
|
|
312 |
|
|
313 |
contentsWasSaved
|
|
314 |
"return true, if the contents was saved (by a save action),
|
|
315 |
false if not (or was modified again after the last save)."
|
|
316 |
|
|
317 |
^ contentsWasSaved
|
|
318 |
!
|
|
319 |
|
|
320 |
fromFile:aFileName
|
|
321 |
"take contents from a named file"
|
|
322 |
|
|
323 |
self directoryForFileDialog:(OperatingSystem directoryNameOf:aFileName).
|
|
324 |
self contents:(FileStream oldFileNamed:aFileName) contents
|
|
325 |
! !
|
|
326 |
|
|
327 |
!TextView methodsFor:'private'!
|
|
328 |
|
|
329 |
fileOutContentsOn:aStream
|
|
330 |
"save contents on a stream"
|
|
331 |
|
38
|
332 |
|startNr nLines string|
|
|
333 |
|
|
334 |
"on some systems, writing linewise is very slow (via NFS)
|
|
335 |
therefore we convert to a string and write it in chunks
|
|
336 |
to avoid creating huge strings, we do it in blocks of 1000 lines
|
|
337 |
"
|
|
338 |
startNr := 1.
|
|
339 |
nLines := list size.
|
|
340 |
[startNr <= nLines] whileTrue:[
|
|
341 |
string := list asStringFrom:startNr to:((startNr + 1000) min:nLines).
|
|
342 |
aStream nextPutAll:string.
|
|
343 |
startNr := startNr + 1000 + 1.
|
|
344 |
].
|
|
345 |
|
|
346 |
"/ list do:[:aLine |
|
|
347 |
"/ aLine notNil ifTrue:[
|
|
348 |
"/ aStream nextPutAll:aLine.
|
|
349 |
"/ ].
|
|
350 |
"/ aStream cr
|
|
351 |
"/ ]
|
0
|
352 |
!
|
|
353 |
|
|
354 |
widthForScrollBetween:firstLine and:lastLine
|
|
355 |
"return the width in pixels for a scroll between firstLine and lastLine"
|
|
356 |
|
|
357 |
selectionStartLine notNil ifTrue:[
|
|
358 |
(lastLine < selectionStartLine) ifFalse:[
|
|
359 |
(firstLine > selectionEndLine) ifFalse:[
|
|
360 |
^ width
|
|
361 |
]
|
|
362 |
]
|
|
363 |
].
|
|
364 |
^ super widthForScrollBetween:firstLine and:lastLine
|
|
365 |
!
|
|
366 |
|
|
367 |
scrollSelectUp
|
|
368 |
"auto scroll action; scroll and reinstall timed-block"
|
|
369 |
|
22
|
370 |
|prevStartLine|
|
|
371 |
|
38
|
372 |
"just to make certain ..."
|
|
373 |
selectionStartLine isNil ifTrue:[^ self].
|
|
374 |
|
22
|
375 |
self scrollUp.
|
|
376 |
|
|
377 |
"make new selection immediately visible"
|
|
378 |
prevStartLine := selectionStartLine.
|
|
379 |
selectionStartLine := firstLineShown.
|
|
380 |
selectionStartCol := 1.
|
|
381 |
selectionStartLine to:prevStartLine do:[:lineNr |
|
|
382 |
self redrawLine:lineNr
|
|
383 |
].
|
38
|
384 |
Processor addTimedBlock:autoScrollBlock afterSeconds:autoScrollDeltaT.
|
0
|
385 |
!
|
|
386 |
|
|
387 |
scrollSelectDown
|
|
388 |
"auto scroll action; scroll and reinstall timed-block"
|
|
389 |
|
22
|
390 |
|prevEndLine|
|
|
391 |
|
38
|
392 |
"just to make certain ..."
|
|
393 |
selectionEndLine isNil ifTrue:[^ self].
|
|
394 |
|
22
|
395 |
self scrollDown.
|
|
396 |
|
|
397 |
"make new selection immediately visible"
|
|
398 |
prevEndLine := selectionEndLine.
|
|
399 |
selectionEndLine := firstLineShown + nFullLinesShown.
|
|
400 |
selectionEndCol := 0.
|
|
401 |
prevEndLine to:selectionEndLine do:[:lineNr |
|
|
402 |
self redrawLine:lineNr
|
|
403 |
].
|
38
|
404 |
Processor addTimedBlock:autoScrollBlock afterSeconds:autoScrollDeltaT.
|
0
|
405 |
!
|
|
406 |
|
|
407 |
stopScrollSelect
|
|
408 |
"stop auto scroll; deinstall timed-block"
|
|
409 |
|
|
410 |
autoScrollBlock notNil ifTrue:[
|
38
|
411 |
Processor removeTimedBlock:autoScrollBlock.
|
15
|
412 |
self compressMotionEvents:true.
|
0
|
413 |
autoScrollBlock := nil.
|
|
414 |
autoScrollDeltaT := nil
|
|
415 |
]
|
|
416 |
! !
|
|
417 |
|
|
418 |
!TextView methodsFor:'menu actions'!
|
|
419 |
|
|
420 |
print
|
|
421 |
"print the contents on the printer"
|
|
422 |
|
|
423 |
|printStream|
|
|
424 |
|
|
425 |
list isNil ifTrue:[^ self].
|
|
426 |
printStream := Printer new.
|
|
427 |
printStream notNil ifTrue:[
|
|
428 |
self fileOutContentsOn:printStream.
|
|
429 |
printStream close
|
|
430 |
]
|
|
431 |
!
|
|
432 |
|
|
433 |
saveAs:fileName
|
|
434 |
"save contents into a file named fileName"
|
|
435 |
|
3
|
436 |
|aStream msg|
|
0
|
437 |
|
|
438 |
aStream := FileStream newFileNamed:fileName.
|
3
|
439 |
aStream isNil ifTrue:[
|
7
|
440 |
msg := resources string:'cannot write file %1 !!' with:fileName.
|
|
441 |
self warn:(msg , '\\(' , OperatingSystem lastErrorString , ')' ) withCRs
|
3
|
442 |
] ifFalse:[
|
0
|
443 |
self fileOutContentsOn:aStream.
|
|
444 |
aStream close.
|
|
445 |
contentsWasSaved := true
|
|
446 |
]
|
|
447 |
!
|
|
448 |
|
38
|
449 |
appendTo:fileName
|
|
450 |
"append contents to a file named fileName"
|
|
451 |
|
|
452 |
|aStream msg|
|
|
453 |
|
|
454 |
aStream := FileStream appendingOldFileNamed:fileName.
|
|
455 |
aStream isNil ifTrue:[
|
|
456 |
msg := resources string:'cannot append to file %1 !!' with:fileName.
|
|
457 |
self warn:(msg , '\\(' , OperatingSystem lastErrorString , ')' ) withCRs
|
|
458 |
] ifFalse:[
|
|
459 |
self fileOutContentsOn:aStream.
|
|
460 |
aStream close.
|
|
461 |
contentsWasSaved := true
|
|
462 |
]
|
|
463 |
!
|
|
464 |
|
0
|
465 |
save
|
|
466 |
"save contents into a file
|
|
467 |
- ask user for filename using a fileSelectionBox."
|
|
468 |
|
|
469 |
fileBox isNil ifTrue:[
|
38
|
470 |
fileBox := FileSaveBox
|
3
|
471 |
title:(resources string:'save contents in:')
|
|
472 |
okText:(resources string:'save')
|
|
473 |
abortText:(resources string:'cancel')
|
38
|
474 |
action:[:fileName | self saveAs:fileName].
|
|
475 |
fileBox appendAction:[:fileName | self appendTo:fileName].
|
0
|
476 |
].
|
|
477 |
directoryForFileDialog notNil ifTrue:[
|
|
478 |
fileBox directory:directoryForFileDialog
|
|
479 |
].
|
|
480 |
fileBox showAtPointer
|
|
481 |
!
|
|
482 |
|
|
483 |
copySelection
|
|
484 |
"copy contents into smalltalk copybuffer"
|
|
485 |
|
|
486 |
|text|
|
|
487 |
|
|
488 |
text := self selection.
|
|
489 |
text notNil ifTrue:[
|
|
490 |
Smalltalk at:#CopyBuffer put:text.
|
|
491 |
self unselect
|
|
492 |
]
|
|
493 |
!
|
|
494 |
|
|
495 |
changeFont
|
|
496 |
"pop up a fontPanel to change font"
|
|
497 |
|
22
|
498 |
MyFontPanel isNil ifTrue:[
|
|
499 |
MyFontPanel := FontPanel new
|
0
|
500 |
].
|
22
|
501 |
MyFontPanel action:[:family :face :style :size |
|
0
|
502 |
self font:(Font family:family
|
|
503 |
face:face
|
|
504 |
style:style
|
|
505 |
size:size)
|
|
506 |
].
|
22
|
507 |
MyFontPanel initialFont:font.
|
|
508 |
MyFontPanel showAtPointer
|
0
|
509 |
!
|
|
510 |
|
|
511 |
gotoLine
|
|
512 |
"show a box to enter lineNumber for positioning"
|
|
513 |
|
|
514 |
lineNumberBox isNil ifTrue:[
|
|
515 |
lineNumberBox :=
|
|
516 |
EnterBox
|
3
|
517 |
title:(resources string:'line number:')
|
|
518 |
okText:(resources string:'goto')
|
|
519 |
abortText:(resources string:'cancel')
|
0
|
520 |
action:[:l | self gotoLine:(Number readFromString:l)]
|
|
521 |
].
|
7
|
522 |
lineNumberBox initialText:''.
|
0
|
523 |
lineNumberBox showAtPointer
|
|
524 |
! !
|
|
525 |
|
|
526 |
!TextView methodsFor:'selections'!
|
|
527 |
|
|
528 |
enableOrDisableSelectionMenuEntries
|
|
529 |
"sent internally, whenever selection status changes to
|
|
530 |
update menu entries"
|
|
531 |
|
|
532 |
selectionStartLine isNil ifTrue:[
|
|
533 |
self disableSelectionMenuEntries
|
|
534 |
] ifFalse:[
|
|
535 |
self enableSelectionMenuEntries
|
|
536 |
]
|
|
537 |
!
|
|
538 |
|
|
539 |
disableSelectionMenuEntries
|
|
540 |
"disable relevant menu entries when no selection is
|
|
541 |
available - redefined in subclasses to disable more,
|
|
542 |
but do NOT forget a super disableSelectionMenuEntries there."
|
|
543 |
|
|
544 |
middleButtonMenu notNil ifTrue:[
|
|
545 |
middleButtonMenu disable:#copySelection
|
|
546 |
]
|
|
547 |
!
|
|
548 |
|
|
549 |
enableSelectionMenuEntries
|
|
550 |
"disable relevant menu entries when a selection is
|
|
551 |
available - redefined in subclasses to enable more,
|
|
552 |
but do NOT forget a super enableSelectionMenuEntries there."
|
|
553 |
|
|
554 |
middleButtonMenu notNil ifTrue:[
|
|
555 |
middleButtonMenu enable:#copySelection
|
|
556 |
]
|
|
557 |
!
|
|
558 |
|
|
559 |
unselectWithoutRedraw
|
|
560 |
"forget selection but do not redraw the selection area
|
|
561 |
- can be done when selected area is redrawn anyway or
|
|
562 |
known to be invisible."
|
|
563 |
|
|
564 |
selectionStartLine := nil.
|
|
565 |
self disableSelectionMenuEntries
|
|
566 |
!
|
|
567 |
|
|
568 |
unselect
|
38
|
569 |
"unselect - if there was a selection redraw that area"
|
0
|
570 |
|
|
571 |
|startLine endLine startVisLine endVisLine|
|
|
572 |
|
|
573 |
selectionStartLine notNil ifTrue:[
|
|
574 |
startLine := selectionStartLine.
|
|
575 |
endLine := selectionEndLine.
|
|
576 |
selectionStartLine := nil.
|
|
577 |
|
|
578 |
"if selection is not visible, we are done"
|
|
579 |
startLine >= (firstLineShown + nLinesShown) ifTrue:[^ self].
|
|
580 |
endLine < firstLineShown ifTrue:[^ self].
|
|
581 |
|
|
582 |
startLine < firstLineShown ifTrue:[
|
|
583 |
startVisLine := 1
|
|
584 |
] ifFalse:[
|
|
585 |
startVisLine := self listLineToVisibleLine:startLine
|
|
586 |
].
|
|
587 |
endLine >= (firstLineShown + nLinesShown) ifTrue:[
|
|
588 |
endVisLine := nLinesShown
|
|
589 |
] ifFalse:[
|
|
590 |
endVisLine := self listLineToVisibleLine:endLine
|
|
591 |
].
|
|
592 |
"if its only part of a line, just redraw what has to be"
|
|
593 |
(startVisLine == endVisLine) ifTrue:[
|
|
594 |
super redrawVisibleLine:startVisLine from:selectionStartCol to:selectionEndCol
|
|
595 |
] ifFalse:[
|
|
596 |
super redrawFromVisibleLine:startVisLine to:endVisLine
|
|
597 |
].
|
|
598 |
self unselectWithoutRedraw
|
|
599 |
].
|
38
|
600 |
selectStyle := nil
|
0
|
601 |
!
|
|
602 |
|
|
603 |
selectFromLine:startLine col:startCol toLine:endLine col:endCol
|
38
|
604 |
"select a piece of text and redraw that area"
|
0
|
605 |
|
|
606 |
self unselect.
|
|
607 |
startLine notNil ifTrue:[
|
7
|
608 |
"new:"
|
|
609 |
endLine < startLine ifTrue:[
|
|
610 |
^ self selectFromLine:endLine col:endCol toLine:startLine col:startCol
|
|
611 |
].
|
|
612 |
(endLine == startLine and:[endCol < startCol]) ifTrue:[
|
|
613 |
^ self selectFromLine:endLine col:endCol toLine:startLine col:startCol
|
|
614 |
].
|
|
615 |
|
|
616 |
" old:
|
|
617 |
endLine < startLine ifTrue:[^ self].
|
|
618 |
(startLine == endLine and:[endCol < startCol]) ifTrue:[^ self].
|
|
619 |
"
|
0
|
620 |
selectionStartLine := startLine.
|
|
621 |
selectionStartCol := startCol.
|
|
622 |
selectionEndLine := endLine.
|
|
623 |
selectionEndCol := endCol.
|
|
624 |
(startLine == endLine) ifTrue:[
|
|
625 |
self redrawLine:startLine from:startCol to:endCol
|
|
626 |
] ifFalse:[
|
|
627 |
startLine to:endLine do:[:lineNr |
|
|
628 |
self redrawLine:lineNr
|
|
629 |
]
|
|
630 |
].
|
38
|
631 |
selectStyle := nil.
|
0
|
632 |
self enableSelectionMenuEntries
|
|
633 |
]
|
|
634 |
!
|
|
635 |
|
|
636 |
selectLine:selectLine
|
38
|
637 |
"select one line and redraw it"
|
0
|
638 |
|
38
|
639 |
self selectFromLine:selectLine col:1 toLine:(selectLine + 1) col:0.
|
|
640 |
wordStartCol := selectionStartCol.
|
|
641 |
wordEndCol := selectionEndCol.
|
|
642 |
wordStartLine := selectionStartLine.
|
|
643 |
wordEndLine := selectionEndLine.
|
|
644 |
selectStyle := #line
|
0
|
645 |
!
|
|
646 |
|
|
647 |
selectLineWhereCharacterPosition:pos
|
|
648 |
"select the line, where characterPosition pos is living.
|
38
|
649 |
The argument pos starts at 1 from the start of the text
|
|
650 |
and counts characters (i.e. can be used to convert from
|
|
651 |
character position within a string to line-position in view)."
|
0
|
652 |
|
|
653 |
self selectLine:(self lineOfCharacterPosition:pos)
|
|
654 |
!
|
|
655 |
|
|
656 |
selectFromCharacterPosition:pos1 to:pos2
|
|
657 |
"compute line/col from character positions and select the text"
|
|
658 |
|
|
659 |
|line1 col1 line2 col2|
|
|
660 |
|
|
661 |
line1 := self lineOfCharacterPosition:pos1.
|
|
662 |
col1 := pos1 - (self characterPositionOfLine:line1 col:1) + 1.
|
|
663 |
line2 := self lineOfCharacterPosition:pos2.
|
|
664 |
col2 := pos2 - (self characterPositionOfLine:line2 col:1) + 1.
|
|
665 |
self selectFromLine:line1 col:col1 toLine:line2 col:col2
|
|
666 |
!
|
|
667 |
|
|
668 |
selectWordAtLine:selectLine col:selectCol
|
|
669 |
"select the word at given line/col"
|
|
670 |
|
38
|
671 |
|beginCol endCol endLine thisCharacter flag len|
|
0
|
672 |
|
38
|
673 |
flag := #word.
|
0
|
674 |
beginCol := selectCol.
|
|
675 |
endCol := selectCol.
|
38
|
676 |
endLine := selectLine.
|
0
|
677 |
thisCharacter := self characterAtLine:selectLine col:beginCol.
|
7
|
678 |
|
38
|
679 |
beginCol := self findBeginOfWordAtLine:selectLine col:selectCol.
|
|
680 |
endCol := self findEndOfWordAtLine:selectLine col:selectCol.
|
|
681 |
endCol == 0 ifTrue:[
|
|
682 |
endLine := selectLine + 1
|
|
683 |
].
|
|
684 |
|
|
685 |
"is the initial acharacter within a word ?"
|
7
|
686 |
(wordCheck value:thisCharacter) ifTrue:[
|
38
|
687 |
"
|
|
688 |
try to catch a blank ...
|
|
689 |
"
|
0
|
690 |
((beginCol == 1)
|
|
691 |
or:[(self characterAtLine:selectLine col:(beginCol - 1))
|
|
692 |
~~ Character space]) ifTrue:[
|
|
693 |
((self characterAtLine:selectLine col:(endCol + 1))
|
|
694 |
== Character space) ifTrue:[
|
|
695 |
endCol := endCol + 1.
|
38
|
696 |
flag := #wordRight
|
0
|
697 |
]
|
|
698 |
] ifFalse:[
|
|
699 |
beginCol := beginCol - 1.
|
38
|
700 |
flag := #wordLeft
|
7
|
701 |
].
|
0
|
702 |
].
|
38
|
703 |
self selectFromLine:selectLine col:beginCol toLine:endLine col:endCol.
|
|
704 |
selectStyle := flag
|
0
|
705 |
!
|
|
706 |
|
|
707 |
selectWordAtX:x y:y
|
|
708 |
"select the word at given x/y-(view-)coordinate"
|
|
709 |
|
|
710 |
|selectVisibleLine selectLine selectCol|
|
|
711 |
|
38
|
712 |
selectStyle := nil.
|
0
|
713 |
selectVisibleLine := self visibleLineOfY:y.
|
|
714 |
selectLine := self visibleLineToListLine:selectVisibleLine.
|
|
715 |
selectLine notNil ifTrue:[
|
|
716 |
selectCol := self colOfX:x inVisibleLine:selectLine.
|
|
717 |
self selectWordAtLine:selectLine col:selectCol
|
|
718 |
]
|
|
719 |
!
|
|
720 |
|
|
721 |
selectLineAtY:y
|
|
722 |
"select the line at given y-(view-)coordinate"
|
|
723 |
|
|
724 |
|selectVisibleLine selectLine|
|
|
725 |
|
|
726 |
selectVisibleLine := self visibleLineOfY:y.
|
|
727 |
selectLine := self visibleLineToListLine:selectVisibleLine.
|
|
728 |
selectLine notNil ifTrue:[
|
|
729 |
self selectLine:selectLine
|
|
730 |
]
|
|
731 |
!
|
|
732 |
|
|
733 |
selectAll
|
|
734 |
"select the whole text"
|
|
735 |
|
|
736 |
self selectFromLine:1 col:1 toLine:(list size + 1) col:0
|
|
737 |
!
|
|
738 |
|
38
|
739 |
hasSelection
|
|
740 |
"return true, if there is a selection"
|
|
741 |
|
|
742 |
^ selectionStartLine notNil
|
|
743 |
!
|
|
744 |
|
0
|
745 |
selection
|
38
|
746 |
"return the selection as a collection of (line-)strings"
|
0
|
747 |
|
|
748 |
|text sz index|
|
|
749 |
|
|
750 |
selectionStartLine isNil ifTrue:[^ nil].
|
|
751 |
(selectionStartLine == selectionEndLine) ifTrue:[
|
|
752 |
"part of a line"
|
|
753 |
^ Text with:(self listAt:selectionStartLine
|
|
754 |
from:selectionStartCol
|
|
755 |
to:selectionEndCol)
|
|
756 |
].
|
|
757 |
sz := selectionEndLine - selectionStartLine + 1.
|
|
758 |
text := Text new:sz.
|
|
759 |
|
|
760 |
"get 1st and last (possibly) partial lines"
|
|
761 |
text at:1 put:(self listAt:selectionStartLine from:selectionStartCol).
|
|
762 |
text at:sz put:(self listAt:selectionEndLine to:selectionEndCol).
|
|
763 |
|
|
764 |
"get bulk of text"
|
|
765 |
index := 2.
|
|
766 |
(selectionStartLine + 1) to:(selectionEndLine - 1) do:[:lineNr |
|
|
767 |
text at:index put:(self listAt:lineNr).
|
|
768 |
index := index + 1
|
|
769 |
].
|
|
770 |
^ text
|
|
771 |
!
|
|
772 |
|
|
773 |
makeSelectionVisible
|
|
774 |
"scroll to make selection visible"
|
|
775 |
|
|
776 |
selectionStartLine notNil ifTrue:[
|
|
777 |
self makeLineVisible:selectionStartLine
|
|
778 |
]
|
|
779 |
! !
|
|
780 |
|
|
781 |
!TextView methodsFor:'searching'!
|
|
782 |
|
|
783 |
search
|
|
784 |
"show a box to enter searchpattern
|
|
785 |
- currently no regular expressions are handled."
|
|
786 |
|
|
787 |
searchBox isNil ifTrue:[
|
|
788 |
searchBox :=
|
|
789 |
EnterBox2
|
|
790 |
title:(resources at:'searchPattern:')
|
|
791 |
okText1:(resources at:'prev')
|
|
792 |
okText2:(resources at:'next')
|
|
793 |
abortText:(resources at:'cancel')
|
|
794 |
action1:[:pattern | self searchBwd:(pattern withoutSeparators)]
|
|
795 |
action2:[:pattern | self searchFwd:(pattern withoutSeparators)]
|
|
796 |
].
|
|
797 |
searchPattern notNil ifTrue:[
|
|
798 |
searchBox initialText:searchPattern
|
|
799 |
].
|
|
800 |
searchBox showAtPointer
|
|
801 |
!
|
|
802 |
|
|
803 |
setSearchPattern
|
|
804 |
"set the searchpattern from the selection if there is one"
|
|
805 |
|
|
806 |
|sel|
|
|
807 |
|
|
808 |
sel := self selection.
|
|
809 |
sel notNil ifTrue:[
|
|
810 |
searchPattern := sel asString withoutSeparators
|
|
811 |
]
|
|
812 |
!
|
|
813 |
|
|
814 |
showNotFound
|
|
815 |
"search not found - tell user by beeping and changing
|
|
816 |
cursor for a while (sometimes I work with a headset :-)
|
|
817 |
(used to be: tell user by changing cursor for a while)"
|
|
818 |
|
|
819 |
|savedCursor|
|
|
820 |
|
|
821 |
device beep.
|
|
822 |
"
|
|
823 |
uncomment if you want a CROSS cursor to be shown for a while ..
|
|
824 |
"
|
|
825 |
|
|
826 |
" "
|
|
827 |
savedCursor := cursor.
|
|
828 |
self cursor:(Cursor cross).
|
|
829 |
OperatingSystem millisecondDelay:300.
|
|
830 |
self cursor:savedCursor
|
|
831 |
" "
|
|
832 |
!
|
|
833 |
|
|
834 |
searchFwd
|
|
835 |
"search forward for pattern or selection"
|
|
836 |
|
|
837 |
self setSearchPattern.
|
|
838 |
searchPattern notNil ifTrue:[
|
|
839 |
self searchFwd:searchPattern
|
|
840 |
]
|
|
841 |
!
|
|
842 |
|
|
843 |
searchBwd
|
|
844 |
"search backward and -if found- position cursor"
|
|
845 |
|
|
846 |
self setSearchPattern.
|
|
847 |
searchPattern notNil ifTrue:[
|
|
848 |
self searchBwd:searchPattern
|
|
849 |
]
|
|
850 |
!
|
|
851 |
|
|
852 |
searchFwd:pattern
|
|
853 |
"do the forward search"
|
|
854 |
|
|
855 |
|startLine startCol|
|
|
856 |
|
|
857 |
selectionStartLine notNil ifTrue:[
|
|
858 |
startLine := selectionStartLine.
|
|
859 |
startCol := selectionStartCol
|
|
860 |
] ifFalse:[
|
|
861 |
startLine := 1.
|
|
862 |
startCol := 1
|
|
863 |
].
|
|
864 |
self searchForwardFor:pattern startingAtLine:startLine col:startCol
|
|
865 |
ifFound:[:line :col |
|
|
866 |
self selectFromLine:line col:col
|
|
867 |
toLine:line col:(col + pattern size - 1).
|
|
868 |
self makeLineVisible:line
|
|
869 |
] else:[
|
|
870 |
self showNotFound
|
|
871 |
]
|
|
872 |
!
|
|
873 |
|
|
874 |
searchBwd:pattern
|
|
875 |
"do the backward search"
|
|
876 |
|
|
877 |
|startLine startCol|
|
|
878 |
|
|
879 |
selectionStartLine notNil ifTrue:[
|
|
880 |
startLine := selectionStartLine.
|
|
881 |
startCol := selectionStartCol
|
|
882 |
] ifFalse:[
|
|
883 |
startLine := 1.
|
|
884 |
startCol := 1
|
|
885 |
].
|
|
886 |
self searchBackwardFor:pattern startingAtLine:startLine col:startCol
|
|
887 |
ifFound:[:line :col |
|
|
888 |
self selectFromLine:line col:col
|
|
889 |
toLine:line col:(col + pattern size - 1).
|
|
890 |
self makeLineVisible:line
|
|
891 |
] else:[
|
|
892 |
self showNotFound
|
|
893 |
]
|
|
894 |
! !
|
|
895 |
|
|
896 |
!TextView methodsFor:'redrawing'!
|
|
897 |
|
|
898 |
clearMarginOfVisible:visLine with:color
|
|
899 |
"if there is a margin, clear it - a helper for selection drawing"
|
|
900 |
|
|
901 |
(leftMargin ~~ 0) ifTrue:[
|
|
902 |
self paint:color.
|
|
903 |
self fillRectangleX:margin
|
|
904 |
y:(self yOfLine:visLine)
|
|
905 |
width:leftMargin
|
|
906 |
height:fontHeight
|
|
907 |
]
|
|
908 |
!
|
|
909 |
|
|
910 |
redrawVisibleLine:visLine col:col
|
|
911 |
"redraw single character at col in visible line lineNr"
|
|
912 |
|
|
913 |
|line|
|
|
914 |
|
|
915 |
line := self visibleLineToAbsoluteLine:visLine.
|
|
916 |
selectionStartLine notNil ifTrue:[
|
|
917 |
(line between:selectionStartLine and:selectionEndLine) ifTrue:[
|
|
918 |
((line == selectionStartLine)
|
|
919 |
and: [col < selectionStartCol]) ifFalse:[
|
|
920 |
((line == selectionEndLine)
|
|
921 |
and: [col > selectionEndCol]) ifFalse:[
|
|
922 |
"its in the selection"
|
|
923 |
self drawVisibleLine:visLine col:col with:selectionFgColor
|
|
924 |
and:selectionBgColor.
|
|
925 |
^ self
|
|
926 |
]
|
|
927 |
]
|
|
928 |
]
|
|
929 |
].
|
|
930 |
super redrawVisibleLine:visLine col:col
|
|
931 |
!
|
|
932 |
|
|
933 |
redrawFromVisibleLine:startVisLineNr to:endVisLineNr
|
|
934 |
"redraw a visible line range"
|
|
935 |
|
|
936 |
|startLine endLine specialCare end selVisStart line1 line2|
|
|
937 |
|
|
938 |
shown ifFalse:[^ self].
|
|
939 |
|
|
940 |
end := endVisLineNr.
|
|
941 |
(end > nLinesShown) ifTrue:[
|
|
942 |
end := nLinesShown
|
|
943 |
].
|
|
944 |
|
|
945 |
selectionStartLine isNil ifTrue:[
|
|
946 |
specialCare := false
|
|
947 |
] ifFalse:[
|
|
948 |
startLine := self visibleLineToAbsoluteLine:startVisLineNr.
|
|
949 |
(startLine > selectionEndLine) ifTrue:[
|
|
950 |
specialCare := false
|
|
951 |
] ifFalse:[
|
|
952 |
endLine := self visibleLineToAbsoluteLine:end.
|
|
953 |
(endLine < selectionStartLine) ifTrue:[
|
|
954 |
specialCare := false
|
|
955 |
] ifFalse:[
|
|
956 |
specialCare := true
|
|
957 |
]
|
|
958 |
]
|
|
959 |
].
|
|
960 |
|
|
961 |
"easy: nothing is selected"
|
|
962 |
specialCare ifFalse:[
|
7
|
963 |
super redrawFromVisibleLine:startVisLineNr to:end.
|
|
964 |
^ self
|
0
|
965 |
].
|
|
966 |
|
|
967 |
"easy: all is selected"
|
|
968 |
((selectionStartLine < startLine) and:[selectionEndLine > endLine]) ifTrue:[
|
7
|
969 |
self drawFromVisibleLine:startVisLineNr to:end with:selectionFgColor
|
|
970 |
and:selectionBgColor.
|
|
971 |
^ self
|
0
|
972 |
].
|
|
973 |
|
|
974 |
(selectionStartLine >= firstLineShown) ifTrue:[
|
|
975 |
"draw unselected top part"
|
|
976 |
|
|
977 |
selVisStart := self listLineToVisibleLine:selectionStartLine.
|
|
978 |
super redrawFromVisibleLine:startVisLineNr to:(selVisStart - 1).
|
|
979 |
|
|
980 |
"and first partial selected line"
|
|
981 |
self redrawVisibleLine:selVisStart.
|
|
982 |
|
|
983 |
"rest starts after this one"
|
|
984 |
line1 := selVisStart + 1
|
|
985 |
] ifFalse:[
|
|
986 |
line1 := 1
|
|
987 |
].
|
|
988 |
|
|
989 |
(line1 > end) ifTrue:[^ self].
|
|
990 |
(line1 < startVisLineNr) ifTrue:[
|
|
991 |
line1 := startVisLineNr
|
|
992 |
].
|
|
993 |
|
|
994 |
"draw middle part of selection"
|
|
995 |
|
|
996 |
(selectionEndLine >= (firstLineShown + nLinesShown)) ifTrue:[
|
|
997 |
line2 := nLinesShown
|
|
998 |
] ifFalse:[
|
|
999 |
line2 := (self listLineToVisibleLine:selectionEndLine) - 1
|
|
1000 |
].
|
|
1001 |
(line2 > end) ifTrue:[
|
|
1002 |
line2 := end
|
|
1003 |
].
|
|
1004 |
|
|
1005 |
self drawFromVisibleLine:line1 to:line2 with:selectionFgColor
|
|
1006 |
and:selectionBgColor.
|
|
1007 |
|
|
1008 |
(line2 >= end) ifTrue:[^ self].
|
|
1009 |
|
|
1010 |
"last line of selection"
|
|
1011 |
self redrawVisibleLine:(line2 + 1).
|
|
1012 |
|
|
1013 |
((line2 + 2) <= end) ifTrue:[
|
|
1014 |
super redrawFromVisibleLine:(line2 + 2) to:end
|
|
1015 |
]
|
|
1016 |
!
|
|
1017 |
|
|
1018 |
redrawVisibleLine:visLine
|
|
1019 |
"redraw visible line lineNr"
|
|
1020 |
|
|
1021 |
|len line l|
|
|
1022 |
|
|
1023 |
selectionStartLine notNil ifTrue:[
|
|
1024 |
line := self visibleLineToAbsoluteLine:visLine.
|
|
1025 |
(line between:selectionStartLine and:selectionEndLine) ifTrue:[
|
|
1026 |
(line == selectionStartLine) ifTrue:[
|
|
1027 |
(line == selectionEndLine) ifTrue:[
|
|
1028 |
"its part-of-single-line selection"
|
|
1029 |
self clearMarginOfVisible:visLine with:bgColor.
|
|
1030 |
(selectionStartCol > 1) ifTrue:[
|
|
1031 |
super redrawVisibleLine:visLine
|
|
1032 |
from:1
|
|
1033 |
to:(selectionStartCol - 1)
|
|
1034 |
].
|
|
1035 |
self drawVisibleLine:visLine from:selectionStartCol
|
|
1036 |
to:selectionEndCol
|
|
1037 |
with:selectionFgColor
|
|
1038 |
and:selectionBgColor.
|
7
|
1039 |
super redrawVisibleLine:visLine
|
|
1040 |
from:(selectionEndCol + 1).
|
|
1041 |
^ self
|
0
|
1042 |
].
|
|
1043 |
|
|
1044 |
"its the first line of a multi-line selection"
|
|
1045 |
(selectionStartCol ~~ 1) ifTrue:[
|
|
1046 |
self clearMarginOfVisible:visLine with:bgColor.
|
|
1047 |
super redrawVisibleLine:visLine
|
|
1048 |
from:1
|
|
1049 |
to:(selectionStartCol - 1)
|
|
1050 |
].
|
7
|
1051 |
self drawVisibleLine:visLine from:selectionStartCol
|
|
1052 |
with:selectionFgColor and:selectionBgColor.
|
|
1053 |
^ self
|
0
|
1054 |
].
|
|
1055 |
|
|
1056 |
(line == selectionEndLine) ifTrue:[
|
|
1057 |
"its the last line of a multi-line selection"
|
|
1058 |
(selectionEndCol == 0) ifTrue:[
|
|
1059 |
^ super redrawVisibleLine:visLine
|
|
1060 |
].
|
|
1061 |
l := self visibleAt:selectionEndLine.
|
7
|
1062 |
len := l size.
|
0
|
1063 |
|
|
1064 |
self clearMarginOfVisible:visLine with:selectionBgColor.
|
|
1065 |
self drawVisibleLine:visLine from:1 to:selectionEndCol
|
|
1066 |
with:selectionFgColor and:selectionBgColor.
|
7
|
1067 |
super redrawVisibleLine:visLine from:(selectionEndCol + 1).
|
0
|
1068 |
^ self
|
|
1069 |
].
|
|
1070 |
|
|
1071 |
"its a full line in a multi-line selection"
|
|
1072 |
self clearMarginOfVisible:visLine with:selectionBgColor.
|
7
|
1073 |
self drawVisibleLine:visLine with:selectionFgColor and:selectionBgColor.
|
|
1074 |
^ self
|
0
|
1075 |
]
|
|
1076 |
].
|
7
|
1077 |
super redrawVisibleLine:visLine
|
0
|
1078 |
!
|
|
1079 |
|
|
1080 |
redrawVisibleLine:visLine from:startCol
|
|
1081 |
"redraw visible line lineNr from startCol to end of line"
|
|
1082 |
|
|
1083 |
|line|
|
|
1084 |
|
|
1085 |
line := self visibleLineToAbsoluteLine:visLine.
|
|
1086 |
selectionStartLine notNil ifTrue:[
|
|
1087 |
(line between:selectionStartLine and:selectionEndLine) ifTrue:[
|
|
1088 |
((line == selectionStartLine)
|
|
1089 |
or:[line == selectionEndLine]) ifTrue:[
|
|
1090 |
"since I'm lazy, redraw full line"
|
7
|
1091 |
self redrawVisibleLine:visLine.
|
|
1092 |
^ self
|
0
|
1093 |
].
|
|
1094 |
"the line is fully within the selection"
|
7
|
1095 |
self drawVisibleLine:visLine from:startCol with:selectionFgColor
|
|
1096 |
and:selectionBgColor.
|
|
1097 |
^ self
|
0
|
1098 |
]
|
|
1099 |
].
|
|
1100 |
super redrawVisibleLine:visLine from:startCol
|
|
1101 |
!
|
|
1102 |
|
|
1103 |
redrawVisibleLine:visLine from:startCol to:endCol
|
|
1104 |
"redraw visible line lineNr from startCol to endCol"
|
|
1105 |
|
|
1106 |
|line allOut allIn leftCol rightCol|
|
|
1107 |
|
|
1108 |
line := self visibleLineToAbsoluteLine:visLine.
|
|
1109 |
|
|
1110 |
allIn := false.
|
|
1111 |
allOut := false.
|
|
1112 |
selectionStartLine isNil ifTrue:[
|
|
1113 |
allOut := true
|
|
1114 |
] ifFalse:[
|
|
1115 |
(line between:selectionStartLine and:selectionEndLine) ifFalse:[
|
|
1116 |
allOut := true
|
|
1117 |
] ifTrue:[
|
|
1118 |
(selectionStartLine == selectionEndLine) ifTrue:[
|
|
1119 |
((endCol < selectionStartCol)
|
|
1120 |
or:[startCol > selectionEndCol]) ifTrue:[
|
|
1121 |
allOut := true
|
|
1122 |
] ifFalse:[
|
|
1123 |
((startCol >= selectionStartCol)
|
|
1124 |
and:[endCol <= selectionEndCol]) ifTrue:[
|
|
1125 |
allIn := true
|
|
1126 |
]
|
|
1127 |
]
|
|
1128 |
] ifFalse:[
|
|
1129 |
(line == selectionStartLine) ifTrue:[
|
|
1130 |
(endCol < selectionStartCol) ifTrue:[
|
|
1131 |
allOut := true
|
|
1132 |
] ifFalse:[
|
|
1133 |
(startCol >= selectionStartCol) ifTrue:[
|
|
1134 |
allIn := true
|
|
1135 |
]
|
|
1136 |
]
|
|
1137 |
] ifFalse:[
|
|
1138 |
(line == selectionEndLine) ifTrue:[
|
|
1139 |
(startCol > selectionEndCol) ifTrue:[
|
|
1140 |
allOut := true
|
|
1141 |
] ifFalse:[
|
|
1142 |
(endCol <= selectionEndCol) ifTrue:[
|
|
1143 |
allIn := true
|
|
1144 |
]
|
|
1145 |
]
|
|
1146 |
] ifFalse:[
|
|
1147 |
allIn := true
|
|
1148 |
]
|
|
1149 |
]
|
|
1150 |
]
|
|
1151 |
]
|
|
1152 |
].
|
|
1153 |
allOut ifTrue:[
|
7
|
1154 |
super redrawVisibleLine:visLine from:startCol to:endCol.
|
|
1155 |
^ self
|
0
|
1156 |
].
|
|
1157 |
|
|
1158 |
allIn ifTrue:[
|
|
1159 |
self drawVisibleLine:visLine from:startCol to:endCol
|
|
1160 |
with:selectionFgColor and:selectionBgColor
|
|
1161 |
] ifFalse:[
|
|
1162 |
"redraw part before selection"
|
|
1163 |
((line == selectionStartLine)
|
|
1164 |
and:[startCol <= selectionStartCol]) ifTrue:[
|
|
1165 |
super redrawVisibleLine:visLine from:startCol
|
|
1166 |
to:(selectionStartCol - 1).
|
|
1167 |
leftCol := selectionStartCol
|
|
1168 |
] ifFalse:[
|
|
1169 |
leftCol := startCol
|
|
1170 |
].
|
|
1171 |
"redraw selected part"
|
|
1172 |
(selectionEndLine > line) ifTrue:[
|
|
1173 |
rightCol := endCol
|
|
1174 |
] ifFalse:[
|
|
1175 |
rightCol := selectionEndCol min:endCol
|
|
1176 |
].
|
|
1177 |
self drawVisibleLine:visLine from:leftCol to:rightCol
|
|
1178 |
with:selectionFgColor and:selectionBgColor.
|
|
1179 |
|
|
1180 |
"redraw part after selection"
|
|
1181 |
(rightCol < endCol) ifTrue:[
|
|
1182 |
super redrawVisibleLine:visLine from:(rightCol + 1) to:endCol
|
|
1183 |
]
|
|
1184 |
].
|
|
1185 |
|
|
1186 |
"special care for first and last line of selection:
|
|
1187 |
must handle margin also"
|
|
1188 |
|
|
1189 |
((line == selectionEndLine)
|
|
1190 |
and:[(startCol == 1)
|
|
1191 |
and:[selectionStartLine < selectionEndLine]])
|
|
1192 |
ifTrue:[
|
|
1193 |
self clearMarginOfVisible:visLine with:selectionBgColor.
|
|
1194 |
].
|
|
1195 |
|
|
1196 |
((line == selectionStartLine)
|
|
1197 |
and:[(startCol == 1)
|
|
1198 |
and:[selectionStartLine < selectionEndLine]])
|
|
1199 |
ifTrue:[
|
|
1200 |
self clearMarginOfVisible:visLine with:bgColor.
|
|
1201 |
]
|
|
1202 |
! !
|
|
1203 |
|
|
1204 |
!TextView methodsFor:'event processing'!
|
|
1205 |
|
|
1206 |
keyPress:key x:x y:y
|
|
1207 |
"handle some keyboard input (there is not much to be done here)"
|
|
1208 |
|
|
1209 |
(key == #Find) ifTrue:[self search. ^self].
|
|
1210 |
(key == #Copy) ifTrue:[self copySelection. ^self].
|
|
1211 |
|
|
1212 |
(key == #FindNext) ifTrue:[self searchFwd. ^self].
|
|
1213 |
(key == #FindPrev) ifTrue:[self searchBwd. ^self].
|
|
1214 |
|
|
1215 |
(key == #SelectAll) ifTrue:[self selectAll. ^self].
|
|
1216 |
|
38
|
1217 |
"
|
|
1218 |
shift-Fn defines a key-sequence
|
|
1219 |
Fn pastes that sequence
|
|
1220 |
cmd-Fn performs a 'doIt' on the sequence (Workspaces only)
|
|
1221 |
|
|
1222 |
(see EditTextView>>keyPress:x:y and Workspace>>keyPress:x:y)
|
|
1223 |
"
|
7
|
1224 |
(#(F1 F2 F3 F4 F5 F6 F7 F8 F9) includes:key) ifTrue:[
|
|
1225 |
device shiftDown ifTrue:[
|
|
1226 |
(Smalltalk at:#FunctionKeySequences) isNil ifTrue:[
|
|
1227 |
Smalltalk at:#FunctionKeySequences put:Dictionary new
|
|
1228 |
].
|
|
1229 |
(Smalltalk at:#FunctionKeySequences) at:key put:(self selection)
|
|
1230 |
].
|
|
1231 |
^ self
|
|
1232 |
].
|
|
1233 |
|
0
|
1234 |
super keyPress:key x:x y:y
|
|
1235 |
!
|
|
1236 |
|
|
1237 |
buttonPress:button x:x y:y
|
|
1238 |
"mouse-click - prepare for selection change"
|
|
1239 |
|
|
1240 |
|clickVisibleLine|
|
|
1241 |
|
38
|
1242 |
((button == 1) or:[button == #select]) ifTrue:[
|
0
|
1243 |
clickVisibleLine := self visibleLineOfY:y.
|
|
1244 |
clickCol := self colOfX:x inVisibleLine:clickVisibleLine.
|
|
1245 |
clickLine := self visibleLineToAbsoluteLine:clickVisibleLine.
|
|
1246 |
clickStartLine := clickLine.
|
|
1247 |
clickStartCol := clickCol.
|
|
1248 |
self unselect.
|
|
1249 |
clickCount := 1
|
|
1250 |
] ifFalse:[
|
|
1251 |
super buttonPress:button x:x y:y
|
|
1252 |
]
|
|
1253 |
!
|
|
1254 |
|
|
1255 |
buttonShiftPress:button x:x y:y
|
|
1256 |
"mouse-click with shift - adding to selection"
|
|
1257 |
|
|
1258 |
"very simple - just simulate a move"
|
|
1259 |
^ self buttonMotion:button x:x y:y
|
|
1260 |
!
|
|
1261 |
|
|
1262 |
buttonMultiPress:button x:x y:y
|
|
1263 |
"multi-mouse-click - select word under pointer"
|
|
1264 |
|
38
|
1265 |
((button == 1) or:[button == #select]) ifTrue:[
|
0
|
1266 |
clickCount notNil ifTrue:[
|
|
1267 |
clickCount := clickCount + 1.
|
|
1268 |
(clickCount == 2) ifTrue:[
|
38
|
1269 |
self selectWordAtX:x y:y.
|
|
1270 |
"
|
|
1271 |
remember words position in case of a drag following
|
|
1272 |
"
|
|
1273 |
wordStartLine := selectionStartLine.
|
|
1274 |
wordEndLine := selectionEndLine.
|
|
1275 |
selectStyle == #wordLeft ifTrue:[
|
|
1276 |
wordStartCol := selectionStartCol + 1
|
|
1277 |
] ifFalse:[
|
|
1278 |
wordStartCol := selectionStartCol.
|
|
1279 |
].
|
|
1280 |
selectStyle == #wordRight ifTrue:[
|
|
1281 |
wordEndCol := selectionEndCol - 1
|
|
1282 |
] ifFalse:[
|
|
1283 |
wordEndCol := selectionEndCol
|
|
1284 |
]
|
0
|
1285 |
] ifFalse:[
|
|
1286 |
(clickCount == 3) ifTrue:[
|
38
|
1287 |
self selectLineAtY:y.
|
|
1288 |
selectStyle := #line
|
0
|
1289 |
] ifFalse:[
|
|
1290 |
(clickCount == 4) ifTrue:[
|
|
1291 |
self selectAll
|
|
1292 |
]
|
|
1293 |
]
|
|
1294 |
]
|
|
1295 |
]
|
|
1296 |
] ifFalse:[
|
|
1297 |
super buttonMultiPress:button x:x y:y
|
|
1298 |
]
|
|
1299 |
!
|
|
1300 |
|
|
1301 |
buttonMotion:button x:x y:y
|
|
1302 |
"mouse-move while button was pressed - handle selection changes"
|
|
1303 |
|
|
1304 |
|movedVisibleLine movedLine movedCol
|
|
1305 |
movedUp
|
|
1306 |
oldStartLine oldEndLine oldStartCol oldEndCol|
|
|
1307 |
|
|
1308 |
clickLine isNil ifTrue:[^ self].
|
|
1309 |
|
|
1310 |
"if moved outside of view, start autoscroll"
|
|
1311 |
(y < 0) ifTrue:[
|
15
|
1312 |
self compressMotionEvents:false.
|
0
|
1313 |
self startScrollUp:y.
|
|
1314 |
^ self
|
|
1315 |
].
|
|
1316 |
(y > height) ifTrue:[
|
15
|
1317 |
self compressMotionEvents:false.
|
0
|
1318 |
self startScrollDown:(y - height).
|
|
1319 |
^ self
|
|
1320 |
].
|
|
1321 |
|
|
1322 |
"move inside - stop autoscroll if any"
|
|
1323 |
autoScrollBlock notNil ifTrue:[
|
|
1324 |
self stopScrollSelect
|
|
1325 |
].
|
|
1326 |
|
|
1327 |
movedVisibleLine := self visibleLineOfY:y.
|
|
1328 |
movedLine := self visibleLineToAbsoluteLine:movedVisibleLine.
|
|
1329 |
(x < leftMargin) ifTrue:[
|
|
1330 |
movedCol := 0
|
|
1331 |
] ifFalse:[
|
|
1332 |
movedCol := self colOfX:x inVisibleLine:movedVisibleLine
|
|
1333 |
].
|
|
1334 |
((movedLine == clickLine) and:[movedCol == clickCol]) ifTrue:[^ self].
|
|
1335 |
|
|
1336 |
selectionStartLine isNil ifTrue:[
|
|
1337 |
selectionStartLine := clickLine.
|
|
1338 |
selectionStartCol := clickCol.
|
|
1339 |
selectionEndLine := selectionStartLine.
|
|
1340 |
selectionEndCol := selectionStartCol
|
|
1341 |
].
|
|
1342 |
oldStartLine := selectionStartLine.
|
|
1343 |
oldEndLine := selectionEndLine.
|
|
1344 |
oldStartCol := selectionStartCol.
|
|
1345 |
oldEndCol := selectionEndCol.
|
|
1346 |
|
|
1347 |
|
|
1348 |
"find out if we are before or after initial click"
|
|
1349 |
movedUp := false.
|
|
1350 |
(movedLine < clickStartLine) ifTrue:[
|
|
1351 |
movedUp := true
|
|
1352 |
] ifFalse:[
|
|
1353 |
(movedLine == clickStartLine) ifTrue:[
|
|
1354 |
(movedCol < clickStartCol) ifTrue:[
|
|
1355 |
movedUp := true
|
|
1356 |
]
|
|
1357 |
]
|
|
1358 |
].
|
|
1359 |
|
|
1360 |
movedUp ifTrue:[
|
|
1361 |
"change selectionStart"
|
|
1362 |
selectionStartCol := movedCol.
|
|
1363 |
selectionStartLine := movedLine.
|
|
1364 |
selectionEndCol := clickStartCol.
|
38
|
1365 |
selectionEndLine := clickStartLine.
|
|
1366 |
selectStyle notNil ifTrue:[
|
|
1367 |
selectionEndCol := wordEndCol.
|
|
1368 |
selectionEndLine := wordEndLine.
|
|
1369 |
]
|
0
|
1370 |
] ifFalse:[
|
|
1371 |
"change selectionEnd"
|
|
1372 |
selectionEndCol := movedCol.
|
|
1373 |
selectionEndLine := movedLine.
|
|
1374 |
selectionStartCol := clickStartCol.
|
38
|
1375 |
selectionStartLine := clickStartLine.
|
|
1376 |
selectStyle notNil ifTrue:[
|
|
1377 |
selectionStartCol := wordStartCol.
|
|
1378 |
selectionStartLine := wordStartLine.
|
|
1379 |
]
|
0
|
1380 |
].
|
|
1381 |
|
|
1382 |
(selectionStartCol == 0) ifTrue:[
|
|
1383 |
selectionStartCol := 1
|
|
1384 |
].
|
|
1385 |
|
38
|
1386 |
"
|
|
1387 |
if in word-select, just catch the rest of the word
|
|
1388 |
"
|
|
1389 |
(selectStyle notNil and:[selectStyle startsWith:'word']) ifTrue:[
|
|
1390 |
movedUp ifTrue:[
|
|
1391 |
selectionStartCol := self findBeginOfWordAtLine:selectionStartLine col:selectionStartCol
|
|
1392 |
] ifFalse:[
|
|
1393 |
selectionEndCol := self findEndOfWordAtLine:selectionEndLine col:selectionEndCol.
|
|
1394 |
selectionEndCol == 0 ifTrue:[
|
|
1395 |
selectionEndLine := selectionEndLine + 1
|
|
1396 |
]
|
|
1397 |
].
|
|
1398 |
].
|
|
1399 |
|
|
1400 |
selectStyle == #line ifTrue:[
|
|
1401 |
movedUp ifTrue:[
|
|
1402 |
selectionStartCol := 1.
|
|
1403 |
] ifFalse:[
|
|
1404 |
selectionEndCol := 0.
|
|
1405 |
selectionEndLine := selectionEndLine + 1
|
|
1406 |
]
|
|
1407 |
].
|
|
1408 |
|
0
|
1409 |
(oldStartLine == selectionStartLine) ifTrue:[
|
|
1410 |
(oldStartCol ~~ selectionStartCol) ifTrue:[
|
|
1411 |
self redrawLine:oldStartLine
|
|
1412 |
from:((selectionStartCol min:oldStartCol) max:1)
|
|
1413 |
to:((selectionStartCol max:oldStartCol) max:1)
|
|
1414 |
]
|
|
1415 |
] ifFalse:[
|
|
1416 |
self redrawFromLine:(oldStartLine min:selectionStartLine)
|
|
1417 |
to:(oldStartLine max:selectionStartLine)
|
|
1418 |
].
|
|
1419 |
|
|
1420 |
(oldEndLine == selectionEndLine) ifTrue:[
|
|
1421 |
(oldEndCol ~~ selectionEndCol) ifTrue:[
|
|
1422 |
self redrawLine:oldEndLine
|
|
1423 |
from:((selectionEndCol min:oldEndCol) max:1)
|
|
1424 |
to:((selectionEndCol max:oldEndCol) max:1)
|
|
1425 |
]
|
|
1426 |
] ifFalse:[
|
|
1427 |
self redrawFromLine:(oldEndLine min:selectionEndLine)
|
|
1428 |
to:(oldEndLine max:selectionEndLine)
|
|
1429 |
].
|
|
1430 |
clickLine := movedLine.
|
|
1431 |
clickCol := movedCol
|
|
1432 |
!
|
|
1433 |
|
|
1434 |
buttonRelease:button x:x y:y
|
|
1435 |
"mouse- button release - turn off autoScroll if any"
|
|
1436 |
|
38
|
1437 |
((button == 1) or:[button == #select]) ifTrue:[
|
0
|
1438 |
autoScrollBlock notNil ifTrue:[
|
|
1439 |
self stopScrollSelect
|
|
1440 |
].
|
38
|
1441 |
self enableOrDisableSelectionMenuEntries.
|
0
|
1442 |
] ifFalse:[
|
|
1443 |
super buttonRelease:button x:x y:y
|
|
1444 |
]
|
|
1445 |
! !
|