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