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