author | Claus Gittinger <cg@exept.de> |
Tue, 28 May 2019 11:14:45 +0200 | |
changeset 6585 | a170fa1a195e |
parent 6411 | 04771f75a742 |
child 6596 | 38f70b9dbdd9 |
permissions | -rw-r--r-- |
6585 | 1 |
"{ Encoding: utf8 }" |
2 |
||
0 | 3 |
" |
4 | 4 |
COPYRIGHT (c) 1989 by Claus Gittinger |
70 | 5 |
All Rights Reserved |
0 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
2300
68fc714627e8
Remove leading and trailing whitwpsace when accepting a method.
Stefan Vogel <sv@exept.de>
parents:
2097
diff
changeset
|
14 |
"{ Package: 'stx:libwidg' }" |
68fc714627e8
Remove leading and trailing whitwpsace when accepting a method.
Stefan Vogel <sv@exept.de>
parents:
2097
diff
changeset
|
15 |
|
5530 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
0 | 18 |
Workspace subclass:#CodeView |
1749
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
19 |
instanceVariableNames:'explainAction formatAction pointerOverWordAction' |
3022 | 20 |
classVariableNames:'' |
419 | 21 |
poolDictionaries:'' |
2097 | 22 |
category:'Views-Text' |
0 | 23 |
! |
24 |
||
32 | 25 |
!CodeView class methodsFor:'documentation'! |
26 |
||
38 | 27 |
copyright |
28 |
" |
|
29 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
70 | 30 |
All Rights Reserved |
38 | 31 |
|
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! |
|
40 |
||
32 | 41 |
documentation |
42 |
" |
|
125 | 43 |
a view for text which is known to be smalltalk code. |
419 | 44 |
It adds 'explain' to the menu, and defines another action: |
125 | 45 |
explainAction to be performed for explain. |
32 | 46 |
|
125 | 47 |
This action is to be defined by the user of this view |
917
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
48 |
(i.e. usually the owning browser) |
121 | 49 |
|
419 | 50 |
In addition, uncomment/comment are added to the controlMenu. |
51 |
These are smalltalk specific - if you plan to edit other language code, |
|
52 |
you need a different kind of CodeView for that. |
|
53 |
||
125 | 54 |
If used with a model, accept sends the changeMsg to it (as defined in EditTextView). |
419 | 55 |
(however, it is possible to define both changeMsg and acceptAction) |
123 | 56 |
|
419 | 57 |
See how doIt/printIt/inspectIt are handled in the superclass: Workspace. |
123 | 58 |
|
59 |
Caveat: |
|
419 | 60 |
in this version, CodeView does not yet support MVC setups for doIt |
61 |
and explain. |
|
62 |
If required, simulate this by setting the doItAction and |
|
63 |
explainAction, to notify the model manually about whats going on. |
|
583 | 64 |
|
917
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
65 |
[instance variables:] |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
66 |
commentStrings <Array> an array with 2 entries; |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
67 |
the first defining the EOL-comment string, |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
68 |
the 2nd (another array) defining opening |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
69 |
and closing comment strings. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
70 |
Default to ST/X comments, |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
71 |
can be changed in an instance for other |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
72 |
programming languages. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
73 |
|
583 | 74 |
[author:] |
75 |
Claus Gittinger |
|
76 |
||
77 |
[see also:] |
|
78 |
Workspace EditTextView TextView |
|
32 | 79 |
" |
201 | 80 |
! ! |
81 |
||
4276 | 82 |
!CodeView class methodsFor:'others'! |
83 |
||
84 |
version_CVS |
|
5530 | 85 |
^ '$Header$' |
4276 | 86 |
! ! |
87 |
||
201 | 88 |
!CodeView methodsFor:'accessing'! |
89 |
||
90 |
explainAction:aBlock |
|
91 |
"set the action to be performed on explain" |
|
92 |
||
93 |
explainAction := aBlock |
|
1625 | 94 |
! |
95 |
||
96 |
formatAction:aBlock |
|
97 |
"set the action to be performed on format" |
|
98 |
||
99 |
formatAction := aBlock |
|
100 |
||
101 |
"Created: / 17.2.1998 / 17:05:13 / cg" |
|
1749
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
102 |
! |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
103 |
|
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
104 |
pointerOverWordAction:aBlock |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
105 |
pointerOverWordAction := aBlock. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
106 |
pointerOverWordAction notNil ifTrue:[ |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
107 |
self enableMotionEvents. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
108 |
] ifFalse:[ |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
109 |
self disableMotionEvents |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
110 |
] |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
111 |
|
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
112 |
|
201 | 113 |
! ! |
114 |
||
3021 | 115 |
!CodeView methodsFor:'cursor handling'! |
116 |
||
117 |
cursorReturn |
|
5530 | 118 |
self cursorReturn:false |
119 |
! |
|
120 |
||
121 |
cursorReturn:withPossibleAutoindent |
|
122 |
"added an argument to disable autoindent, because this method is called from other |
|
123 |
places as well..." |
|
124 |
||
3021 | 125 |
|wasOn line newCol | |
126 |
||
127 |
"/ make Jan's enhancement dependent on |
|
4594 | 128 |
"/ the autoIndent-flag setting - to avoid confusing |
3291 | 129 |
"/ those who are used to the old behavior. |
3021 | 130 |
"/ for Jan: |
4594 | 131 |
"/ autoIndent is configured in the settings-Editor dialog (for all new editors) |
132 |
"/ or in the per-editor popup menu (misc) |
|
133 |
"/ |
|
3022 | 134 |
"/ and saved/restored with the userPreferences. |
135 |
||
5530 | 136 |
(withPossibleAutoindent not |
137 |
or:[ autoIndent not |
|
4594 | 138 |
or:[ cursorLine == 1 |
5530 | 139 |
or:[ self sensor shiftDown]]]) ifTrue:[ |
3021 | 140 |
super cursorReturn. |
141 |
^ self. |
|
142 |
]. |
|
4813 | 143 |
"/ autoIndent |
4594 | 144 |
|
4813 | 145 |
wasOn := self hideCursor. |
146 |
"/ |
|
147 |
"/ line := self listAt:cursorLine. |
|
148 |
"/ newCol := line size == 0 |
|
149 |
"/ ifTrue:[1] |
|
150 |
"/ ifFalse:[line indexOfNonSeparator]. |
|
151 |
"/ super cursorReturn. |
|
152 |
"/ line := self listAt:cursorLine. |
|
153 |
"/ |
|
154 |
"/ newCol := line size == 0 |
|
155 |
"/ ifTrue:[newCol] |
|
156 |
"/ ifFalse:[line indexOfNonSeparator]. |
|
157 |
||
3021 | 158 |
super cursorReturn. |
4813 | 159 |
newCol := (self leftIndentForLine:cursorLine)+1. |
3021 | 160 |
|
3022 | 161 |
self setCursorCol:newCol. |
162 |
self makeCursorVisibleAndShowCursor:wasOn |
|
3021 | 163 |
|
164 |
"Created: / 8.8.2004 / 18:59:55 / janfrog" |
|
165 |
"Modified: / 8.8.2004 / 20:32:48 / janfrog" |
|
166 |
! ! |
|
167 |
||
201 | 168 |
!CodeView methodsFor:'event handling'! |
169 |
||
2382 | 170 |
buttonMotion:buttonState x:x y:y |
1749
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
171 |
|col line word| |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
172 |
|
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
173 |
pointerOverWordAction notNil ifTrue:[ |
2382 | 174 |
buttonState == 0 ifTrue:[ |
1749
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
175 |
line := self visibleLineOfY:y. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
176 |
col := self colOfX:x inVisibleLine:line. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
177 |
line := self visibleLineToAbsoluteLine:line. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
178 |
|
3891 | 179 |
self wordAtLine:line col:col do:[ |
180 |
:selectLine :beginCol :endLine :endCol :flag | |
|
181 |
||
1749
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
182 |
word := self listAt:selectLine from:beginCol to:endCol. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
183 |
word notNil ifTrue:[ |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
184 |
pointerOverWordAction value:word value:line value:col |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
185 |
] |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
186 |
]. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
187 |
^ self |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
188 |
]. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
189 |
]. |
2382 | 190 |
super buttonMotion:buttonState x:x y:y |
1749
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
191 |
! |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
192 |
|
201 | 193 |
keyPress:key x:x y:y |
194 |
"catch keyboard shortcuts" |
|
195 |
||
4586 | 196 |
<resource: #keyboard (#Format #Explain #Help)> |
201 | 197 |
|
3798 | 198 |
(key == #Format) ifTrue:[self format. ^ self]. |
199 |
(key == #Explain) ifTrue:[self explain. ^ self]. |
|
200 |
(key == #Help) ifTrue:[self explain. ^ self]. |
|
201 | 201 |
|
202 |
super keyPress:key x:x y:y |
|
922 | 203 |
|
1625 | 204 |
"Modified: / 17.2.1998 / 17:05:23 / cg" |
32 | 205 |
! ! |
206 |
||
419 | 207 |
!CodeView methodsFor:'menu & menu actions'! |
208 |
||
209 |
accept |
|
210 |
"redefined accept action; |
|
211 |
save cursor and selection to allow restore in case of an error |
|
212 |
(we are typically compiling here ... and the compiler may show |
|
213 |
errors by highlighting them)" |
|
214 |
||
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
215 |
acceptEnabled == false ifTrue:[ |
6265 | 216 |
self beepInEditor. |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
217 |
^ self |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
218 |
]. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
219 |
|
419 | 220 |
codeStartPosition := 1. |
221 |
[ |
|
4866
1c27f7ed2e77
AbortSignal -> AbortOperationRequest
Stefan Vogel <sv@exept.de>
parents:
4813
diff
changeset
|
222 |
AbortOperationRequest handle:[:ex | |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
223 |
self cursor:Cursor normal. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
224 |
"redraw selection in normal color" |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
225 |
self selectFromLine:selectionStartLine col:selectionStartCol |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
226 |
toLine:selectionEndLine col:selectionEndCol. |
4276 | 227 |
self invalidate. |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
228 |
ex return |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
229 |
] do:[ |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
230 |
super accept. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
231 |
] |
2522
d80496af7eaf
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
2460
diff
changeset
|
232 |
] ensure:[ |
4276 | 233 |
self cursor:Cursor normal. |
234 |
"/ self unselect. |
|
419 | 235 |
] |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
236 |
|
4276 | 237 |
"Modified: / 30-06-2011 / 19:41:39 / cg" |
419 | 238 |
! |
239 |
||
97 | 240 |
editMenu |
121 | 241 |
"return the popUpMenu; |
242 |
to make this independent from what is defined in superclasses, |
|
243 |
get the superclass menu and add my functions." |
|
131 | 244 |
|
2460 | 245 |
<resource: #keyboard ( |
2046 | 246 |
#Accept #Explain #Format)> |
1261
bdb18f73205c
resource flag: #menu -> #programMenu
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
247 |
<resource: #programMenu> |
489 | 248 |
|
3252 | 249 |
|m sub subsub sensor| |
38 | 250 |
|
97 | 251 |
m := super editMenu. |
6585 | 252 |
|
3252 | 253 |
((sensor := self sensor) notNil and:[sensor ctrlDown and:[sensor shiftDown not]]) ifTrue:[ |
2460 | 254 |
sub := m. |
255 |
m := nil. |
|
256 |
] ifFalse:[ |
|
257 |
sub := m subMenuAt:#others. |
|
258 |
]. |
|
0 | 259 |
|
2460 | 260 |
m notNil ifTrue:[ |
430 | 261 |
" |
262 |
codeViews do support #accept |
|
263 |
... add it after #inspectIt |
|
264 |
" |
|
6411 | 265 |
(m indexOf:#accept) == 0 ifTrue:[ |
6216 | 266 |
m |
267 |
addItemList:#( |
|
268 |
('-') |
|
269 |
('Accept' accept Accept) |
|
270 |
) |
|
271 |
resources:resources |
|
272 |
after:#inspectIt. |
|
273 |
]. |
|
274 |
||
1293
c0806b73dc48
disable accept menuItem, if there is no acceptAction
Claus Gittinger <cg@exept.de>
parents:
1261
diff
changeset
|
275 |
(acceptEnabled == false |
c0806b73dc48
disable accept menuItem, if there is no acceptAction
Claus Gittinger <cg@exept.de>
parents:
1261
diff
changeset
|
276 |
or:[acceptAction isNil]) ifTrue:[ |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
277 |
m disable:#accept |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
278 |
]. |
2460 | 279 |
]. |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
280 |
|
2460 | 281 |
sub notNil ifTrue:[ |
430 | 282 |
" |
283 |
and add #explain after $gotoLine in the extra menu |
|
284 |
" |
|
2867 | 285 |
sub |
286 |
addItemList:#( |
|
287 |
('-') |
|
288 |
('Explain' explain Explain) |
|
289 |
) |
|
2922
70e3f3ec7980
oops - doIt and friends were not translated
Claus Gittinger <cg@exept.de>
parents:
2867
diff
changeset
|
290 |
resources:resources |
2867 | 291 |
after:#gotoLine. |
430 | 292 |
|
2460 | 293 |
formatAction notNil ifTrue:[ |
2867 | 294 |
subsub := sub subMenuAt:#tools. |
295 |
||
296 |
subsub notNil ifTrue:[ |
|
297 |
subsub |
|
298 |
addItemList:#( |
|
299 |
('Format' format Format) |
|
300 |
) |
|
2922
70e3f3ec7980
oops - doIt and friends were not translated
Claus Gittinger <cg@exept.de>
parents:
2867
diff
changeset
|
301 |
resources:resources |
2867 | 302 |
after:#indent. |
303 |
]. |
|
2460 | 304 |
]. |
305 |
(self hasSelection not |
|
306 |
or:[explainAction isNil]) ifTrue:[ |
|
307 |
sub disable:#explain |
|
430 | 308 |
]. |
59 | 309 |
]. |
2460 | 310 |
^ m ? sub. |
430 | 311 |
|
6216 | 312 |
"Modified: / 20-10-2017 / 11:18:23 / cg" |
6411 | 313 |
"Modified: / 28-08-2018 / 21:56:21 / Claus Gittinger" |
6585 | 314 |
"Modified (format): / 28-05-2019 / 10:33:21 / Claus Gittinger" |
136 | 315 |
! |
316 |
||
201 | 317 |
explain |
318 |
"explain action; |
|
319 |
evaluate the explainBlock passing whole contents and |
|
320 |
selection as arguments." |
|
321 |
||
322 |
|text| |
|
323 |
||
324 |
explainAction notNil ifTrue:[ |
|
325 |
text := self selection. |
|
326 |
text notNil ifTrue:[ |
|
327 |
explainAction value:(self contents) value:(text asString) |
|
328 |
] |
|
329 |
] |
|
1625 | 330 |
! |
331 |
||
332 |
format |
|
333 |
"format action; |
|
334 |
evaluate the formatBlock passing whole contents as argument." |
|
335 |
||
336 |
|text| |
|
337 |
||
338 |
formatAction notNil ifTrue:[ |
|
3128 | 339 |
text := self contents. |
340 |
text notNil ifTrue:[ |
|
341 |
self |
|
342 |
undoableDo:[ formatAction value:(text asString) ] |
|
3784 | 343 |
info:'Format' |
3128 | 344 |
] |
1625 | 345 |
] |
346 |
||
347 |
"Created: / 17.2.1998 / 17:06:18 / cg" |
|
348 |
"Modified: / 17.2.1998 / 18:25:33 / cg" |
|
0 | 349 |
! ! |
350 |
||
206 | 351 |
!CodeView class methodsFor:'documentation'! |
352 |
||
353 |
version |
|
5530 | 354 |
^ '$Header$' |
206 | 355 |
! ! |
4586 | 356 |