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