author | Claus Gittinger <cg@exept.de> |
Sat, 20 Jun 2009 10:47:07 +0200 | |
changeset 3901 | 113dd960ba11 |
parent 3891 | e1e2624accf8 |
child 4276 | 88d3182dc760 |
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 |
||
78 |
!CodeView methodsFor:'accessing'! |
|
79 |
||
80 |
explainAction:aBlock |
|
81 |
"set the action to be performed on explain" |
|
82 |
||
83 |
explainAction := aBlock |
|
1625 | 84 |
! |
85 |
||
86 |
formatAction:aBlock |
|
87 |
"set the action to be performed on format" |
|
88 |
||
89 |
formatAction := aBlock |
|
90 |
||
91 |
"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
|
92 |
! |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
93 |
|
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
94 |
pointerOverWordAction:aBlock |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
95 |
pointerOverWordAction := aBlock. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
96 |
pointerOverWordAction notNil ifTrue:[ |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
97 |
self enableMotionEvents. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
98 |
] ifFalse:[ |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
99 |
self disableMotionEvents |
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 |
|
201 | 103 |
! ! |
104 |
||
3021 | 105 |
!CodeView methodsFor:'cursor handling'! |
106 |
||
107 |
cursorReturn |
|
108 |
|wasOn line newCol | |
|
109 |
||
110 |
"/ make Jan's enhancement dependent on |
|
3022 | 111 |
"/ the st80EditMode-flag setting - to avoid confusing |
3291 | 112 |
"/ those who are used to the old behavior. |
3021 | 113 |
"/ for Jan: |
3291 | 114 |
"/ st80EditMode is configured in the settings-Editor dialog |
3022 | 115 |
"/ and saved/restored with the userPreferences. |
116 |
||
117 |
(self st80EditMode not |
|
3021 | 118 |
or:[cursorLine == 1]) ifTrue:[ |
119 |
super cursorReturn. |
|
120 |
^ self. |
|
121 |
]. |
|
122 |
wasOn := self hideCursor . |
|
123 |
line := self listAt:cursorLine. |
|
3022 | 124 |
newCol := line size == 0 |
125 |
ifTrue:[1] |
|
126 |
ifFalse:[line indexOfNonSeparator]. |
|
3021 | 127 |
super cursorReturn. |
128 |
line := self listAt:cursorLine. |
|
3022 | 129 |
|
3021 | 130 |
|
3022 | 131 |
newCol := line size == 0 |
132 |
ifTrue:[newCol] |
|
133 |
ifFalse:[line indexOfNonSeparator]. |
|
3021 | 134 |
|
3022 | 135 |
self setCursorCol:newCol. |
136 |
self makeCursorVisibleAndShowCursor:wasOn |
|
3021 | 137 |
|
138 |
"Created: / 8.8.2004 / 18:59:55 / janfrog" |
|
139 |
"Modified: / 8.8.2004 / 20:32:48 / janfrog" |
|
140 |
! ! |
|
141 |
||
201 | 142 |
!CodeView methodsFor:'event handling'! |
143 |
||
2382 | 144 |
buttonMotion:buttonState x:x y:y |
1749
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
145 |
|col line word| |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
146 |
|
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
147 |
pointerOverWordAction notNil ifTrue:[ |
2382 | 148 |
buttonState == 0 ifTrue:[ |
1749
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
149 |
line := self visibleLineOfY:y. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
150 |
col := self colOfX:x inVisibleLine:line. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
151 |
line := self visibleLineToAbsoluteLine:line. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
152 |
|
3891 | 153 |
self wordAtLine:line col:col do:[ |
154 |
:selectLine :beginCol :endLine :endCol :flag | |
|
155 |
||
1749
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
156 |
word := self listAt:selectLine from:beginCol to:endCol. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
157 |
word notNil ifTrue:[ |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
158 |
pointerOverWordAction value:word value:line value:col |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
159 |
] |
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 |
^ self |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
162 |
]. |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
163 |
]. |
2382 | 164 |
super buttonMotion:buttonState x:x y:y |
1749
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
165 |
! |
0d0f27322523
hook for pointerOverWord actions (quick explain)
Claus Gittinger <cg@exept.de>
parents:
1625
diff
changeset
|
166 |
|
201 | 167 |
keyPress:key x:x y:y |
168 |
"catch keyboard shortcuts" |
|
169 |
||
3224 | 170 |
<resource: #keyboard (#Format #Explain #Help |
171 |
#CommentSelection #UncommentSelection)> |
|
201 | 172 |
|
3798 | 173 |
(key == #Format) ifTrue:[self format. ^ self]. |
174 |
(key == #Explain) ifTrue:[self explain. ^ self]. |
|
175 |
(key == #Help) ifTrue:[self explain. ^ self]. |
|
176 |
(key == #CommentSelection) ifTrue:[self commentSelection. ^ self]. |
|
177 |
(key == #UncommentSelection) ifTrue:[self uncommentSelection. ^ self]. |
|
201 | 178 |
|
179 |
super keyPress:key x:x y:y |
|
922 | 180 |
|
1625 | 181 |
"Modified: / 17.2.1998 / 17:05:23 / cg" |
32 | 182 |
! ! |
183 |
||
419 | 184 |
!CodeView methodsFor:'menu & menu actions'! |
185 |
||
186 |
accept |
|
187 |
"redefined accept action; |
|
188 |
save cursor and selection to allow restore in case of an error |
|
189 |
(we are typically compiling here ... and the compiler may show |
|
190 |
errors by highlighting them)" |
|
191 |
||
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
192 |
acceptEnabled == false ifTrue:[ |
3047
24bcca846c20
Send #beep to window instead of device
Stefan Vogel <sv@exept.de>
parents:
3022
diff
changeset
|
193 |
self beep. |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
194 |
^ self |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
195 |
]. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
196 |
|
419 | 197 |
codeStartPosition := 1. |
198 |
[ |
|
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
199 |
AbortSignal handle:[:ex | |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
200 |
self cursor:Cursor normal. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
201 |
"redraw selection in normal color" |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
202 |
self selectFromLine:selectionStartLine col:selectionStartCol |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
203 |
toLine:selectionEndLine col:selectionEndCol. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
204 |
ex return |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
205 |
] do:[ |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
206 |
super accept. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
207 |
] |
2522
d80496af7eaf
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
2460
diff
changeset
|
208 |
] ensure:[ |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
209 |
self unselect. |
419 | 210 |
] |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
211 |
|
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
212 |
"Modified: 7.3.1997 / 11:06:13 / cg" |
419 | 213 |
! |
214 |
||
97 | 215 |
editMenu |
121 | 216 |
"return the popUpMenu; |
217 |
to make this independent from what is defined in superclasses, |
|
218 |
get the superclass menu and add my functions." |
|
131 | 219 |
|
2460 | 220 |
<resource: #keyboard ( |
2046 | 221 |
#Accept #Explain #Format)> |
1261
bdb18f73205c
resource flag: #menu -> #programMenu
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
222 |
<resource: #programMenu> |
489 | 223 |
|
3252 | 224 |
|m sub subsub sensor| |
38 | 225 |
|
97 | 226 |
m := super editMenu. |
3252 | 227 |
((sensor := self sensor) notNil and:[sensor ctrlDown and:[sensor shiftDown not]]) ifTrue:[ |
2460 | 228 |
sub := m. |
229 |
m := nil. |
|
230 |
] ifFalse:[ |
|
231 |
sub := m subMenuAt:#others. |
|
232 |
]. |
|
0 | 233 |
|
2460 | 234 |
m notNil ifTrue:[ |
430 | 235 |
" |
236 |
codeViews do support #accept |
|
237 |
... add it after #inspectIt |
|
238 |
" |
|
2867 | 239 |
m |
240 |
addItemList:#( |
|
241 |
('-') |
|
242 |
('Accept' accept Accept) |
|
243 |
) |
|
2922
70e3f3ec7980
oops - doIt and friends were not translated
Claus Gittinger <cg@exept.de>
parents:
2867
diff
changeset
|
244 |
resources:resources |
464 | 245 |
after:#inspectIt. |
131 | 246 |
|
1293
c0806b73dc48
disable accept menuItem, if there is no acceptAction
Claus Gittinger <cg@exept.de>
parents:
1261
diff
changeset
|
247 |
(acceptEnabled == false |
c0806b73dc48
disable accept menuItem, if there is no acceptAction
Claus Gittinger <cg@exept.de>
parents:
1261
diff
changeset
|
248 |
or:[acceptAction isNil]) ifTrue:[ |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
249 |
m disable:#accept |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
250 |
]. |
2460 | 251 |
]. |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
252 |
|
2460 | 253 |
sub notNil ifTrue:[ |
430 | 254 |
" |
255 |
and add #explain after $gotoLine in the extra menu |
|
256 |
" |
|
2867 | 257 |
sub |
258 |
addItemList:#( |
|
259 |
('-') |
|
260 |
('Explain' explain Explain) |
|
261 |
) |
|
2922
70e3f3ec7980
oops - doIt and friends were not translated
Claus Gittinger <cg@exept.de>
parents:
2867
diff
changeset
|
262 |
resources:resources |
2867 | 263 |
after:#gotoLine. |
430 | 264 |
|
2460 | 265 |
formatAction notNil ifTrue:[ |
2867 | 266 |
subsub := sub subMenuAt:#tools. |
267 |
||
268 |
subsub notNil ifTrue:[ |
|
269 |
subsub |
|
270 |
addItemList:#( |
|
271 |
('Format' format Format) |
|
272 |
) |
|
2922
70e3f3ec7980
oops - doIt and friends were not translated
Claus Gittinger <cg@exept.de>
parents:
2867
diff
changeset
|
273 |
resources:resources |
2867 | 274 |
after:#indent. |
275 |
]. |
|
2460 | 276 |
]. |
277 |
(self hasSelection not |
|
278 |
or:[explainAction isNil]) ifTrue:[ |
|
279 |
sub disable:#explain |
|
430 | 280 |
]. |
59 | 281 |
]. |
2460 | 282 |
^ m ? sub. |
430 | 283 |
|
2460 | 284 |
"Modified: / 12.11.2001 / 16:04:46 / cg" |
136 | 285 |
! |
286 |
||
201 | 287 |
explain |
288 |
"explain action; |
|
289 |
evaluate the explainBlock passing whole contents and |
|
290 |
selection as arguments." |
|
291 |
||
292 |
|text| |
|
293 |
||
294 |
explainAction notNil ifTrue:[ |
|
295 |
text := self selection. |
|
296 |
text notNil ifTrue:[ |
|
297 |
explainAction value:(self contents) value:(text asString) |
|
298 |
] |
|
299 |
] |
|
1625 | 300 |
! |
301 |
||
302 |
format |
|
303 |
"format action; |
|
304 |
evaluate the formatBlock passing whole contents as argument." |
|
305 |
||
306 |
|text| |
|
307 |
||
308 |
formatAction notNil ifTrue:[ |
|
3128 | 309 |
text := self contents. |
310 |
text notNil ifTrue:[ |
|
311 |
self |
|
312 |
undoableDo:[ formatAction value:(text asString) ] |
|
3784 | 313 |
info:'Format' |
3128 | 314 |
] |
1625 | 315 |
] |
316 |
||
317 |
"Created: / 17.2.1998 / 17:06:18 / cg" |
|
318 |
"Modified: / 17.2.1998 / 18:25:33 / cg" |
|
0 | 319 |
! ! |
320 |
||
206 | 321 |
!CodeView class methodsFor:'documentation'! |
322 |
||
323 |
version |
|
3891 | 324 |
^ '$Header: /cvs/stx/stx/libwidg/CodeView.st,v 1.61 2009-05-18 14:30:25 cg Exp $' |
206 | 325 |
! ! |