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