30 |
30 |
31 EditTextView comment:' |
31 EditTextView comment:' |
32 COPYRIGHT (c) 1989 by Claus Gittinger |
32 COPYRIGHT (c) 1989 by Claus Gittinger |
33 All Rights Reserved |
33 All Rights Reserved |
34 |
34 |
35 $Header: /cvs/stx/stx/libwidg/Attic/ETxtView.st,v 1.21 1995-02-22 01:20:41 claus Exp $ |
35 $Header: /cvs/stx/stx/libwidg/Attic/ETxtView.st,v 1.22 1995-03-06 19:28:18 claus Exp $ |
36 '! |
36 '! |
37 |
37 |
38 !EditTextView class methodsFor:'documentation'! |
38 !EditTextView class methodsFor:'documentation'! |
39 |
39 |
40 copyright |
40 copyright |
139 |
139 |
140 super initEvents. |
140 super initEvents. |
141 self enableEnterLeaveEvents |
141 self enableEnterLeaveEvents |
142 ! |
142 ! |
143 |
143 |
144 initializeMiddleButtonMenu |
144 editMenu |
145 "initialize the views middleButtonMenu" |
145 "return the views middleButtonMenu" |
146 |
146 |
147 |labels| |
147 |labels selectors m sub| |
148 |
148 |
149 labels := resources array:#( |
149 labels := #( |
150 "/ 'undo' |
150 "/ 'undo' |
151 'again' |
151 'again' |
152 '-' |
152 '-' |
153 'copy' |
153 'copy' |
154 'cut' |
154 'cut' |
155 'paste' |
155 'paste' |
156 '-' |
156 '-' |
157 'accept' |
157 'accept' |
158 '=' |
158 '=' |
159 'others' |
159 'others' |
160 ). |
160 ). |
161 |
161 |
162 self middleButtonMenu:(PopUpMenu |
162 selectors := #( |
163 labels:labels |
163 "/ undo |
164 selectors:#( |
164 again |
165 "/ undo |
165 nil |
166 again |
166 copySelection |
167 nil |
167 cut |
168 copySelection |
168 paste |
169 cut |
169 nil |
170 paste |
170 accept |
171 nil |
171 nil |
172 accept |
172 others |
173 nil |
173 ). |
174 others |
174 |
175 ) |
175 m := PopUpMenu |
176 receiver:self |
176 labels:(resources array:labels) |
177 for:self). |
177 selectors:selectors. |
178 |
178 |
179 middleButtonMenu subMenuAt:#others put:(PopUpMenu |
179 labels := #( |
180 labels:(resources array:#( |
180 'search ...' |
181 'search ...' |
181 'goto ...' |
182 'goto ...' |
182 '-' |
183 '-' |
183 'font ...' |
184 'font ...' |
184 '-' |
185 '-' |
185 'indent' |
186 'indent' |
186 '-' |
187 '-' |
187 'save as ...' |
188 'save as ...' |
188 'print' |
189 'print' |
189 ). |
190 )) |
190 |
191 selectors:#( |
191 selectors := #( |
192 search |
192 search |
193 gotoLine |
193 gotoLine |
194 nil |
194 nil |
195 changeFont |
195 changeFont |
196 nil |
196 nil |
197 indent |
197 indent |
198 nil |
198 nil |
199 save |
199 save |
200 print |
200 print |
201 ) |
201 ). |
202 receiver:self |
202 |
203 for:self). |
203 sub := PopUpMenu |
204 |
204 labels:(resources array:labels) |
205 self enableOrDisableSelectionMenuEntries |
205 selectors:selectors |
|
206 receiver:model. |
|
207 |
|
208 m subMenuAt:#others put:sub. |
|
209 |
|
210 readOnly ifTrue:[ |
|
211 m disable:#paste |
|
212 ]. |
|
213 self hasSelection not ifTrue:[ |
|
214 m disable:#copySelection. |
|
215 ]. |
|
216 (self hasSelection not or:[readOnly]) ifTrue:[ |
|
217 m disable:#cut. |
|
218 sub disable:#indent. |
|
219 ]. |
|
220 ^ m. |
206 ! |
221 ! |
207 |
222 |
208 realize |
223 realize |
209 "make the view visible" |
224 "make the view visible" |
210 |
225 |
351 "split the line linNr before colNr; the right part (from colNr) |
363 "split the line linNr before colNr; the right part (from colNr) |
352 is cut off and inserted after lineNr; the view is redrawn" |
364 is cut off and inserted after lineNr; the view is redrawn" |
353 |
365 |
354 |line lineSize leftRest rightRest visLine w |
366 |line lineSize leftRest rightRest visLine w |
355 srcY "{ Class: SmallInteger }" | |
367 srcY "{ Class: SmallInteger }" | |
356 |
368 |
357 list isNil ifFalse:[ |
369 list isNil ifFalse:[ |
358 lineNr > (list size) ifFalse:[ |
370 lineNr > (list size) ifFalse:[ |
359 (colNr == 1) ifTrue:[ |
371 (colNr == 1) ifTrue:[ |
360 self insertLine:nil before:lineNr. |
372 self insertLine:nil before:lineNr. |
361 ^ self |
373 ^ self |
447 dstY "{ Class: SmallInteger }" | |
459 dstY "{ Class: SmallInteger }" | |
448 |
460 |
449 visLine := self listLineToVisibleLine:lineNr. |
461 visLine := self listLineToVisibleLine:lineNr. |
450 (shown not or:[visLine isNil]) ifTrue:[ |
462 (shown not or:[visLine isNil]) ifTrue:[ |
451 self withoutRedrawInsertLine:aString before:lineNr. |
463 self withoutRedrawInsertLine:aString before:lineNr. |
|
464 self contentsChanged. |
452 ^ self |
465 ^ self |
453 ]. |
466 ]. |
454 |
467 |
455 w := self widthForScrollBetween:lineNr |
468 w := self widthForScrollBetween:lineNr |
456 and:(firstLineShown + nLinesShown). |
469 and:(firstLineShown + nLinesShown). |
460 self copyFrom:self x:textStartLeft y:(dstY - fontHeight) |
473 self copyFrom:self x:textStartLeft y:(dstY - fontHeight) |
461 toX:textStartLeft y:dstY |
474 toX:textStartLeft y:dstY |
462 width:w |
475 width:w |
463 height:((nLinesShown - visLine "- 1") * fontHeight). |
476 height:((nLinesShown - visLine "- 1") * fontHeight). |
464 self redrawVisibleLine:visLine. |
477 self redrawVisibleLine:visLine. |
465 self waitForExpose |
478 self waitForExpose. |
|
479 self contentsChanged. |
466 ! |
480 ! |
467 |
481 |
468 insertLines:someText from:start to:end before:lineNr |
482 insertLines:someText from:start to:end before:lineNr |
469 "insert a bunch of lines before line lineNr" |
483 "insert a bunch of lines before line lineNr" |
470 |
484 |
478 visLine := self listLineToVisibleLine:lineNr. |
492 visLine := self listLineToVisibleLine:lineNr. |
479 (shown not or:[visLine isNil]) ifTrue:[ |
493 (shown not or:[visLine isNil]) ifTrue:[ |
480 self withoutRedrawInsertLines:someText |
494 self withoutRedrawInsertLines:someText |
481 from:start to:end |
495 from:start to:end |
482 before:lineNr. |
496 before:lineNr. |
|
497 self contentsChanged. |
483 ^ self |
498 ^ self |
484 ]. |
499 ]. |
485 |
500 |
486 nLines := end - start + 1. |
501 nLines := end - start + 1. |
487 ((visLine + nLines) >= nLinesShown) ifTrue:[ |
502 ((visLine + nLines) >= nLinesShown) ifTrue:[ |
506 toX:textStartLeft y:dstY |
521 toX:textStartLeft y:dstY |
507 width:w |
522 width:w |
508 height:(height - dstY). |
523 height:(height - dstY). |
509 self redrawFromVisibleLine:visLine to:(visLine + nLines - 1). |
524 self redrawFromVisibleLine:visLine to:(visLine + nLines - 1). |
510 self waitForExpose |
525 self waitForExpose |
511 ] |
526 ]. |
|
527 self contentsChanged. |
512 ! |
528 ! |
513 |
529 |
514 insert:aCharacter atLine:lineNr col:colNr |
530 insert:aCharacter atLine:lineNr col:colNr |
515 "insert a single character at lineNr/colNr" |
531 "insert a single character at lineNr/colNr" |
516 |
532 |
2015 v topView label:'deleted text'. |
2030 v topView label:'deleted text'. |
2016 ! ! |
2031 ! ! |
2017 |
2032 |
2018 !EditTextView methodsFor:'selections'! |
2033 !EditTextView methodsFor:'selections'! |
2019 |
2034 |
2020 disableSelectionMenuEntries |
|
2021 "disable relevant menu entries for a selection" |
|
2022 |
|
2023 middleButtonMenu notNil ifTrue:[ |
|
2024 super disableSelectionMenuEntries. |
|
2025 middleButtonMenu disable:#cut. |
|
2026 middleButtonMenu disable:#replace. |
|
2027 middleButtonMenu disable:#indent |
|
2028 ] |
|
2029 ! |
|
2030 |
|
2031 enableSelectionMenuEntries |
|
2032 "enable relevant menu entries for a selection" |
|
2033 |
|
2034 middleButtonMenu notNil ifTrue:[ |
|
2035 "if readonly, never enable destructive functions" |
|
2036 readOnly ifTrue:[ |
|
2037 super enableSelectionMenuEntries. |
|
2038 middleButtonMenu disable:#cut. |
|
2039 middleButtonMenu disable:#replace. |
|
2040 middleButtonMenu disable:#indent. |
|
2041 middleButtonMenu disable:#paste. |
|
2042 ] ifFalse:[ |
|
2043 super enableSelectionMenuEntries. |
|
2044 middleButtonMenu enable:#cut. |
|
2045 middleButtonMenu enable:#replace. |
|
2046 middleButtonMenu enable:#indent. |
|
2047 ] |
|
2048 ] |
|
2049 ! |
|
2050 |
|
2051 unselect |
2035 unselect |
2052 "forget and unhilight selection - must take care of cursor here" |
2036 "forget and unhilight selection - must take care of cursor here" |
2053 |
2037 |
2054 self withCursorOffDo:[ |
2038 self withCursorOffDo:[ |
2055 super unselect |
2039 super unselect |