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