author | Claus Gittinger <cg@exept.de> |
Tue, 24 Feb 2015 16:46:36 +0100 | |
changeset 5282 | 382e6cfb447d |
parent 4866 | 1c27f7ed2e77 |
child 5530 | 6e888d60be5a |
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 |
|
4866
1c27f7ed2e77
AbortSignal -> AbortOperationRequest
Stefan Vogel <sv@exept.de>
parents:
4813
diff
changeset
|
81 |
^ '$Header: /cvs/stx/stx/libwidg/CodeView.st,v 1.66 2014-01-23 16:11:20 stefan 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 |
]. |
|
4813 | 131 |
"/ autoIndent |
4594 | 132 |
|
4813 | 133 |
wasOn := self hideCursor. |
134 |
"/ |
|
135 |
"/ line := self listAt:cursorLine. |
|
136 |
"/ newCol := line size == 0 |
|
137 |
"/ ifTrue:[1] |
|
138 |
"/ ifFalse:[line indexOfNonSeparator]. |
|
139 |
"/ super cursorReturn. |
|
140 |
"/ line := self listAt:cursorLine. |
|
141 |
"/ |
|
142 |
"/ newCol := line size == 0 |
|
143 |
"/ ifTrue:[newCol] |
|
144 |
"/ ifFalse:[line indexOfNonSeparator]. |
|
145 |
||
3021 | 146 |
super cursorReturn. |
4813 | 147 |
newCol := (self leftIndentForLine:cursorLine)+1. |
3021 | 148 |
|
3022 | 149 |
self setCursorCol:newCol. |
150 |
self makeCursorVisibleAndShowCursor:wasOn |
|
3021 | 151 |
|
152 |
"Created: / 8.8.2004 / 18:59:55 / janfrog" |
|
153 |
"Modified: / 8.8.2004 / 20:32:48 / janfrog" |
|
154 |
! ! |
|
155 |
||
201 | 156 |
!CodeView methodsFor:'event handling'! |
157 |
||
2382 | 158 |
buttonMotion:buttonState x:x y:y |
1749
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
159 |
|col line word| |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
160 |
|
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
161 |
pointerOverWordAction notNil ifTrue:[ |
2382 | 162 |
buttonState == 0 ifTrue:[ |
1749
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
163 |
line := self visibleLineOfY:y. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
164 |
col := self colOfX:x inVisibleLine:line. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
165 |
line := self visibleLineToAbsoluteLine:line. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
166 |
|
3891 | 167 |
self wordAtLine:line col:col do:[ |
168 |
:selectLine :beginCol :endLine :endCol :flag | |
|
169 |
||
1749
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
170 |
word := self listAt:selectLine from:beginCol to:endCol. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
171 |
word notNil ifTrue:[ |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
172 |
pointerOverWordAction value:word value:line value:col |
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 |
]. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
175 |
^ self |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
176 |
]. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
177 |
]. |
2382 | 178 |
super buttonMotion:buttonState x:x y:y |
1749
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
179 |
! |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
180 |
|
201 | 181 |
keyPress:key x:x y:y |
182 |
"catch keyboard shortcuts" |
|
183 |
||
4586 | 184 |
<resource: #keyboard (#Format #Explain #Help)> |
201 | 185 |
|
3798 | 186 |
(key == #Format) ifTrue:[self format. ^ self]. |
187 |
(key == #Explain) ifTrue:[self explain. ^ self]. |
|
188 |
(key == #Help) ifTrue:[self explain. ^ self]. |
|
201 | 189 |
|
190 |
super keyPress:key x:x y:y |
|
922 | 191 |
|
1625 | 192 |
"Modified: / 17.2.1998 / 17:05:23 / cg" |
32 | 193 |
! ! |
194 |
||
419 | 195 |
!CodeView methodsFor:'menu & menu actions'! |
196 |
||
197 |
accept |
|
198 |
"redefined accept action; |
|
199 |
save cursor and selection to allow restore in case of an error |
|
200 |
(we are typically compiling here ... and the compiler may show |
|
201 |
errors by highlighting them)" |
|
202 |
||
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
203 |
acceptEnabled == false ifTrue:[ |
3047
24bcca846c20
Send #beep to window instead of device
Stefan Vogel <sv@exept.de>
parents:
3022
diff
changeset
|
204 |
self beep. |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
205 |
^ self |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
206 |
]. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
207 |
|
419 | 208 |
codeStartPosition := 1. |
209 |
[ |
|
4866
1c27f7ed2e77
AbortSignal -> AbortOperationRequest
Stefan Vogel <sv@exept.de>
parents:
4813
diff
changeset
|
210 |
AbortOperationRequest handle:[:ex | |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
211 |
self cursor:Cursor normal. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
212 |
"redraw selection in normal color" |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
213 |
self selectFromLine:selectionStartLine col:selectionStartCol |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
214 |
toLine:selectionEndLine col:selectionEndCol. |
4276 | 215 |
self invalidate. |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
216 |
ex return |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
217 |
] do:[ |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
218 |
super accept. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
219 |
] |
2522
d80496af7eaf
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
2460
diff
changeset
|
220 |
] ensure:[ |
4276 | 221 |
self cursor:Cursor normal. |
222 |
"/ self unselect. |
|
419 | 223 |
] |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
224 |
|
4276 | 225 |
"Modified: / 30-06-2011 / 19:41:39 / cg" |
419 | 226 |
! |
227 |
||
97 | 228 |
editMenu |
121 | 229 |
"return the popUpMenu; |
230 |
to make this independent from what is defined in superclasses, |
|
231 |
get the superclass menu and add my functions." |
|
131 | 232 |
|
2460 | 233 |
<resource: #keyboard ( |
2046 | 234 |
#Accept #Explain #Format)> |
1261
bdb18f73205c
resource flag: #menu -> #programMenu
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
235 |
<resource: #programMenu> |
489 | 236 |
|
3252 | 237 |
|m sub subsub sensor| |
38 | 238 |
|
97 | 239 |
m := super editMenu. |
3252 | 240 |
((sensor := self sensor) notNil and:[sensor ctrlDown and:[sensor shiftDown not]]) ifTrue:[ |
2460 | 241 |
sub := m. |
242 |
m := nil. |
|
243 |
] ifFalse:[ |
|
244 |
sub := m subMenuAt:#others. |
|
245 |
]. |
|
0 | 246 |
|
2460 | 247 |
m notNil ifTrue:[ |
430 | 248 |
" |
249 |
codeViews do support #accept |
|
250 |
... add it after #inspectIt |
|
251 |
" |
|
2867 | 252 |
m |
253 |
addItemList:#( |
|
254 |
('-') |
|
255 |
('Accept' accept Accept) |
|
256 |
) |
|
2922
70e3f3ec7980
oops - doIt and friends were not translated
Claus Gittinger <cg@exept.de>
parents:
2867
diff
changeset
|
257 |
resources:resources |
464 | 258 |
after:#inspectIt. |
131 | 259 |
|
1293
c0806b73dc48
disable accept menuItem, if there is no acceptAction
Claus Gittinger <cg@exept.de>
parents:
1261
diff
changeset
|
260 |
(acceptEnabled == false |
c0806b73dc48
disable accept menuItem, if there is no acceptAction
Claus Gittinger <cg@exept.de>
parents:
1261
diff
changeset
|
261 |
or:[acceptAction isNil]) ifTrue:[ |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
262 |
m disable:#accept |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
263 |
]. |
2460 | 264 |
]. |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
265 |
|
2460 | 266 |
sub notNil ifTrue:[ |
430 | 267 |
" |
268 |
and add #explain after $gotoLine in the extra menu |
|
269 |
" |
|
2867 | 270 |
sub |
271 |
addItemList:#( |
|
272 |
('-') |
|
273 |
('Explain' explain Explain) |
|
274 |
) |
|
2922
70e3f3ec7980
oops - doIt and friends were not translated
Claus Gittinger <cg@exept.de>
parents:
2867
diff
changeset
|
275 |
resources:resources |
2867 | 276 |
after:#gotoLine. |
430 | 277 |
|
2460 | 278 |
formatAction notNil ifTrue:[ |
2867 | 279 |
subsub := sub subMenuAt:#tools. |
280 |
||
281 |
subsub notNil ifTrue:[ |
|
282 |
subsub |
|
283 |
addItemList:#( |
|
284 |
('Format' format Format) |
|
285 |
) |
|
2922
70e3f3ec7980
oops - doIt and friends were not translated
Claus Gittinger <cg@exept.de>
parents:
2867
diff
changeset
|
286 |
resources:resources |
2867 | 287 |
after:#indent. |
288 |
]. |
|
2460 | 289 |
]. |
290 |
(self hasSelection not |
|
291 |
or:[explainAction isNil]) ifTrue:[ |
|
292 |
sub disable:#explain |
|
430 | 293 |
]. |
59 | 294 |
]. |
2460 | 295 |
^ m ? sub. |
430 | 296 |
|
2460 | 297 |
"Modified: / 12.11.2001 / 16:04:46 / cg" |
136 | 298 |
! |
299 |
||
201 | 300 |
explain |
301 |
"explain action; |
|
302 |
evaluate the explainBlock passing whole contents and |
|
303 |
selection as arguments." |
|
304 |
||
305 |
|text| |
|
306 |
||
307 |
explainAction notNil ifTrue:[ |
|
308 |
text := self selection. |
|
309 |
text notNil ifTrue:[ |
|
310 |
explainAction value:(self contents) value:(text asString) |
|
311 |
] |
|
312 |
] |
|
1625 | 313 |
! |
314 |
||
315 |
format |
|
316 |
"format action; |
|
317 |
evaluate the formatBlock passing whole contents as argument." |
|
318 |
||
319 |
|text| |
|
320 |
||
321 |
formatAction notNil ifTrue:[ |
|
3128 | 322 |
text := self contents. |
323 |
text notNil ifTrue:[ |
|
324 |
self |
|
325 |
undoableDo:[ formatAction value:(text asString) ] |
|
3784 | 326 |
info:'Format' |
3128 | 327 |
] |
1625 | 328 |
] |
329 |
||
330 |
"Created: / 17.2.1998 / 17:06:18 / cg" |
|
331 |
"Modified: / 17.2.1998 / 18:25:33 / cg" |
|
0 | 332 |
! ! |
333 |
||
206 | 334 |
!CodeView class methodsFor:'documentation'! |
335 |
||
336 |
version |
|
4866
1c27f7ed2e77
AbortSignal -> AbortOperationRequest
Stefan Vogel <sv@exept.de>
parents:
4813
diff
changeset
|
337 |
^ '$Header: /cvs/stx/stx/libwidg/CodeView.st,v 1.66 2014-01-23 16:11:20 stefan Exp $' |
206 | 338 |
! ! |
4586 | 339 |