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