author | Claus Gittinger <cg@exept.de> |
Mon, 15 Jul 2019 20:00:30 +0200 | |
changeset 6633 | b86193ed635b |
parent 6617 | 129dbcededf3 |
child 6664 | 4aac73d9fe64 |
permissions | -rw-r--r-- |
6617 | 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 |
6617 | 137 |
or:[ self 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 |
|
6617 | 164 |
"Created: / 08-08-2004 / 18:59:55 / janfrog" |
165 |
"Modified: / 08-08-2004 / 20:32:48 / janfrog" |
|
166 |
"Modified: / 26-06-2019 / 23:19:09 / Claus Gittinger" |
|
3021 | 167 |
! ! |
168 |
||
201 | 169 |
!CodeView methodsFor:'event handling'! |
170 |
||
2382 | 171 |
buttonMotion:buttonState x:x y:y |
1749
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
172 |
|col line word| |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
173 |
|
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
174 |
pointerOverWordAction notNil ifTrue:[ |
2382 | 175 |
buttonState == 0 ifTrue:[ |
1749
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
176 |
line := self visibleLineOfY:y. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
177 |
col := self colOfX:x inVisibleLine:line. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
178 |
line := self visibleLineToAbsoluteLine:line. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
179 |
|
3891 | 180 |
self wordAtLine:line col:col do:[ |
181 |
:selectLine :beginCol :endLine :endCol :flag | |
|
182 |
||
1749
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
183 |
word := self listAt:selectLine from:beginCol to:endCol. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
184 |
word notNil ifTrue:[ |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
185 |
pointerOverWordAction value:word value:line value:col |
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 |
]. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
188 |
^ self |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
189 |
]. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
190 |
]. |
2382 | 191 |
super buttonMotion:buttonState x:x y:y |
1749
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
192 |
! |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
193 |
|
201 | 194 |
keyPress:key x:x y:y |
195 |
"catch keyboard shortcuts" |
|
196 |
||
4586 | 197 |
<resource: #keyboard (#Format #Explain #Help)> |
201 | 198 |
|
3798 | 199 |
(key == #Format) ifTrue:[self format. ^ self]. |
200 |
(key == #Explain) ifTrue:[self explain. ^ self]. |
|
201 |
(key == #Help) ifTrue:[self explain. ^ self]. |
|
201 | 202 |
|
203 |
super keyPress:key x:x y:y |
|
922 | 204 |
|
1625 | 205 |
"Modified: / 17.2.1998 / 17:05:23 / cg" |
32 | 206 |
! ! |
207 |
||
419 | 208 |
!CodeView methodsFor:'menu & menu actions'! |
209 |
||
210 |
accept |
|
211 |
"redefined accept action; |
|
212 |
save cursor and selection to allow restore in case of an error |
|
213 |
(we are typically compiling here ... and the compiler may show |
|
214 |
errors by highlighting them)" |
|
215 |
||
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
216 |
acceptEnabled == false ifTrue:[ |
6265 | 217 |
self beepInEditor. |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
218 |
^ self |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
219 |
]. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
220 |
|
419 | 221 |
codeStartPosition := 1. |
222 |
[ |
|
4866
1c27f7ed2e77
AbortSignal -> AbortOperationRequest
Stefan Vogel <sv@exept.de>
parents:
4813
diff
changeset
|
223 |
AbortOperationRequest handle:[:ex | |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
224 |
self cursor:Cursor normal. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
225 |
"redraw selection in normal color" |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
226 |
self selectFromLine:selectionStartLine col:selectionStartCol |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
227 |
toLine:selectionEndLine col:selectionEndCol. |
4276 | 228 |
self invalidate. |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
229 |
ex return |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
230 |
] do:[ |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
231 |
super accept. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
232 |
] |
2522
d80496af7eaf
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
2460
diff
changeset
|
233 |
] ensure:[ |
4276 | 234 |
self cursor:Cursor normal. |
235 |
"/ self unselect. |
|
419 | 236 |
] |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
237 |
|
4276 | 238 |
"Modified: / 30-06-2011 / 19:41:39 / cg" |
419 | 239 |
! |
240 |
||
97 | 241 |
editMenu |
121 | 242 |
"return the popUpMenu; |
243 |
to make this independent from what is defined in superclasses, |
|
244 |
get the superclass menu and add my functions." |
|
131 | 245 |
|
2460 | 246 |
<resource: #keyboard ( |
2046 | 247 |
#Accept #Explain #Format)> |
1261
bdb18f73205c
resource flag: #menu -> #programMenu
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
248 |
<resource: #programMenu> |
489 | 249 |
|
3252 | 250 |
|m sub subsub sensor| |
38 | 251 |
|
97 | 252 |
m := super editMenu. |
6585 | 253 |
|
3252 | 254 |
((sensor := self sensor) notNil and:[sensor ctrlDown and:[sensor shiftDown not]]) ifTrue:[ |
2460 | 255 |
sub := m. |
256 |
m := nil. |
|
257 |
] ifFalse:[ |
|
258 |
sub := m subMenuAt:#others. |
|
259 |
]. |
|
0 | 260 |
|
2460 | 261 |
m notNil ifTrue:[ |
430 | 262 |
" |
263 |
codeViews do support #accept |
|
264 |
... add it after #inspectIt |
|
265 |
" |
|
6411 | 266 |
(m indexOf:#accept) == 0 ifTrue:[ |
6216 | 267 |
m |
268 |
addItemList:#( |
|
269 |
('-') |
|
270 |
('Accept' accept Accept) |
|
271 |
) |
|
272 |
resources:resources |
|
273 |
after:#inspectIt. |
|
274 |
]. |
|
275 |
||
1293
c0806b73dc48
disable accept menuItem, if there is no acceptAction
Claus Gittinger <cg@exept.de>
parents:
1261
diff
changeset
|
276 |
(acceptEnabled == false |
c0806b73dc48
disable accept menuItem, if there is no acceptAction
Claus Gittinger <cg@exept.de>
parents:
1261
diff
changeset
|
277 |
or:[acceptAction isNil]) ifTrue:[ |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
278 |
m disable:#accept |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
279 |
]. |
2460 | 280 |
]. |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
281 |
|
2460 | 282 |
sub notNil ifTrue:[ |
430 | 283 |
" |
284 |
and add #explain after $gotoLine in the extra menu |
|
285 |
" |
|
2867 | 286 |
sub |
287 |
addItemList:#( |
|
288 |
('-') |
|
289 |
('Explain' explain Explain) |
|
290 |
) |
|
2922
70e3f3ec7980
oops - doIt and friends were not translated
Claus Gittinger <cg@exept.de>
parents:
2867
diff
changeset
|
291 |
resources:resources |
2867 | 292 |
after:#gotoLine. |
430 | 293 |
|
2460 | 294 |
formatAction notNil ifTrue:[ |
2867 | 295 |
subsub := sub subMenuAt:#tools. |
296 |
||
297 |
subsub notNil ifTrue:[ |
|
298 |
subsub |
|
299 |
addItemList:#( |
|
300 |
('Format' format Format) |
|
301 |
) |
|
2922
70e3f3ec7980
oops - doIt and friends were not translated
Claus Gittinger <cg@exept.de>
parents:
2867
diff
changeset
|
302 |
resources:resources |
2867 | 303 |
after:#indent. |
304 |
]. |
|
2460 | 305 |
]. |
306 |
(self hasSelection not |
|
307 |
or:[explainAction isNil]) ifTrue:[ |
|
308 |
sub disable:#explain |
|
430 | 309 |
]. |
59 | 310 |
]. |
2460 | 311 |
^ m ? sub. |
430 | 312 |
|
6216 | 313 |
"Modified: / 20-10-2017 / 11:18:23 / cg" |
6411 | 314 |
"Modified: / 28-08-2018 / 21:56:21 / Claus Gittinger" |
6585 | 315 |
"Modified (format): / 28-05-2019 / 10:33:21 / Claus Gittinger" |
136 | 316 |
! |
317 |
||
201 | 318 |
explain |
319 |
"explain action; |
|
320 |
evaluate the explainBlock passing whole contents and |
|
321 |
selection as arguments." |
|
322 |
||
323 |
|text| |
|
324 |
||
325 |
explainAction notNil ifTrue:[ |
|
6601 | 326 |
text := self selection. |
327 |
text notNil ifTrue:[ |
|
328 |
explainAction value:(self contents string) value:(text asString string) |
|
329 |
] |
|
201 | 330 |
] |
6601 | 331 |
|
332 |
"Modified: / 08-06-2019 / 17:33:40 / Claus Gittinger" |
|
1625 | 333 |
! |
334 |
||
335 |
format |
|
336 |
"format action; |
|
337 |
evaluate the formatBlock passing whole contents as argument." |
|
338 |
||
339 |
|text| |
|
340 |
||
341 |
formatAction notNil ifTrue:[ |
|
3128 | 342 |
text := self contents. |
343 |
text notNil ifTrue:[ |
|
344 |
self |
|
345 |
undoableDo:[ formatAction value:(text asString) ] |
|
3784 | 346 |
info:'Format' |
3128 | 347 |
] |
1625 | 348 |
] |
349 |
||
350 |
"Created: / 17.2.1998 / 17:06:18 / cg" |
|
351 |
"Modified: / 17.2.1998 / 18:25:33 / cg" |
|
6596 | 352 |
! |
353 |
||
354 |
showLineLimitInMenu |
|
355 |
^ false. |
|
356 |
||
357 |
"Created: / 06-06-2019 / 11:23:20 / Claus Gittinger" |
|
0 | 358 |
! ! |
359 |
||
206 | 360 |
!CodeView class methodsFor:'documentation'! |
361 |
||
362 |
version |
|
5530 | 363 |
^ '$Header$' |
206 | 364 |
! ! |
4586 | 365 |