author | Claus Gittinger <cg@exept.de> |
Tue, 27 Feb 1996 15:35:33 +0100 | |
changeset 419 | 2bd5f73fffd2 |
parent 365 | cb7a40a691f3 |
child 430 | 022b667e0d70 |
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 |
||
13 |
Workspace subclass:#CodeView |
|
419 | 14 |
instanceVariableNames:'explainAction' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Interface-Workspace' |
|
0 | 18 |
! |
19 |
||
32 | 20 |
!CodeView class methodsFor:'documentation'! |
21 |
||
38 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
70 | 25 |
All Rights Reserved |
38 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
32 | 36 |
documentation |
37 |
" |
|
125 | 38 |
a view for text which is known to be smalltalk code. |
419 | 39 |
It adds 'explain' to the menu, and defines another action: |
125 | 40 |
explainAction to be performed for explain. |
32 | 41 |
|
125 | 42 |
This action is to be defined by the user of this view |
38 | 43 |
(i.e. ususally the owning browser) |
121 | 44 |
|
419 | 45 |
In addition, uncomment/comment are added to the controlMenu. |
46 |
These are smalltalk specific - if you plan to edit other language code, |
|
47 |
you need a different kind of CodeView for that. |
|
48 |
||
125 | 49 |
If used with a model, accept sends the changeMsg to it (as defined in EditTextView). |
419 | 50 |
(however, it is possible to define both changeMsg and acceptAction) |
123 | 51 |
|
419 | 52 |
See how doIt/printIt/inspectIt are handled in the superclass: Workspace. |
123 | 53 |
|
54 |
Caveat: |
|
419 | 55 |
in this version, CodeView does not yet support MVC setups for doIt |
56 |
and explain. |
|
57 |
If required, simulate this by setting the doItAction and |
|
58 |
explainAction, to notify the model manually about whats going on. |
|
32 | 59 |
" |
201 | 60 |
! ! |
61 |
||
62 |
!CodeView methodsFor:'accessing'! |
|
63 |
||
64 |
explainAction:aBlock |
|
65 |
"set the action to be performed on explain" |
|
66 |
||
67 |
explainAction := aBlock |
|
68 |
! ! |
|
69 |
||
70 |
!CodeView methodsFor:'editing'! |
|
71 |
||
72 |
commentFrom:line1 to:line2 |
|
73 |
"convenient function to comment out a block. |
|
74 |
All lines from line1 to line2 get an end-of-line comment |
|
75 |
in the first col." |
|
76 |
||
77 |
line1 to:line2 do:[:lineNr | |
|
78 |
|l| |
|
79 |
||
80 |
l := self listAt:lineNr. |
|
81 |
l isNil ifTrue:[l := '']. |
|
82 |
self at:lineNr put:(('"' , '/') , l) |
|
83 |
]. |
|
84 |
self textChanged. |
|
85 |
! |
|
86 |
||
87 |
uncommentFrom:line1 to:line2 |
|
88 |
"convenient function to comment out a block. |
|
89 |
All lines from line1 to line2 get an end-of-line comment |
|
90 |
in the first col." |
|
91 |
||
92 |
line1 to:line2 do:[:lineNr | |
|
93 |
|l| |
|
94 |
||
95 |
l := self listAt:lineNr. |
|
96 |
(l notNil and:[l startsWith:('"' ,'/')]) ifTrue:[ |
|
97 |
self at:lineNr put:(l copyFrom:3) |
|
98 |
] |
|
99 |
]. |
|
100 |
self textChanged. |
|
101 |
! ! |
|
102 |
||
103 |
!CodeView methodsFor:'event handling'! |
|
104 |
||
105 |
keyPress:key x:x y:y |
|
106 |
"catch keyboard shortcuts" |
|
107 |
||
274
6df4bb990f04
handle accept where acceptAction is define (this was a historic leftover)
Claus Gittinger <cg@exept.de>
parents:
206
diff
changeset
|
108 |
<resource: #keyboard (#Explain #Help |
201 | 109 |
#CommentSelection #UncommentSelection)> |
110 |
||
111 |
(key == #Explain) ifTrue:[^ self explain]. |
|
112 |
(key == #Help) ifTrue:[^ self explain]. |
|
113 |
(key == #CommentSelection) ifTrue:[^ self commentSelection]. |
|
114 |
(key == #UncommentSelection) ifTrue:[^ self uncommentSelection]. |
|
115 |
||
116 |
super keyPress:key x:x y:y |
|
32 | 117 |
! ! |
118 |
||
419 | 119 |
!CodeView methodsFor:'menu & menu actions'! |
120 |
||
121 |
accept |
|
122 |
"redefined accept action; |
|
123 |
save cursor and selection to allow restore in case of an error |
|
124 |
(we are typically compiling here ... and the compiler may show |
|
125 |
errors by highlighting them)" |
|
126 |
||
127 |
codeStartPosition := 1. |
|
128 |
[ |
|
129 |
AbortSignal handle:[:ex | |
|
130 |
self cursor:Cursor normal. |
|
131 |
"redraw selection in normal color" |
|
132 |
self selectFromLine:selectionStartLine col:selectionStartCol |
|
133 |
toLine:selectionEndLine col:selectionEndCol. |
|
134 |
ex return |
|
135 |
] do:[ |
|
136 |
super accept. |
|
137 |
] |
|
138 |
] valueNowOrOnUnwindDo:[ |
|
139 |
self unselect. |
|
140 |
] |
|
141 |
! |
|
142 |
||
143 |
commentSelection |
|
144 |
"convenient function to comment out a block. |
|
145 |
All lines from line1 to line2 get an end-of-line comment |
|
146 |
in the first col." |
|
147 |
||
148 |
|e| |
|
149 |
||
150 |
(selectionStartCol == 1 and:[selectionEndCol == 0]) ifTrue:[ |
|
151 |
self commentFrom:selectionStartLine to:selectionEndLine-1 |
|
152 |
] ifFalse:[ |
|
153 |
self insert:$" atLine:selectionStartLine col:selectionStartCol. |
|
154 |
e := selectionEndCol + 1. |
|
155 |
selectionStartLine == selectionEndLine ifTrue:[e := e + 1]. |
|
156 |
self insert:$" atLine:selectionEndLine col:e. |
|
157 |
self selectFromLine:selectionStartLine col:selectionStartCol |
|
158 |
toLine:selectionEndLine col:e. |
|
159 |
] |
|
160 |
! |
|
0 | 161 |
|
97 | 162 |
editMenu |
121 | 163 |
"return the popUpMenu; |
164 |
to make this independent from what is defined in superclasses, |
|
165 |
get the superclass menu and add my functions." |
|
131 | 166 |
|
97 | 167 |
|m sub idx| |
38 | 168 |
|
97 | 169 |
m := super editMenu. |
0 | 170 |
|
131 | 171 |
self sensor ctrlDown ifTrue:[ |
172 |
m addLabels:(resources array:#('-' 'commentIt' 'uncommentIt')) |
|
173 |
selectors:#(nil commentSelection uncommentSelection) |
|
174 |
after:(m labels size). |
|
175 |
self hasSelection ifFalse:[ |
|
176 |
m disableAll:#(commentSelection uncommentSelection) |
|
177 |
]. |
|
178 |
] ifFalse:[ |
|
38 | 179 |
|
131 | 180 |
" |
181 |
codeViews do support #accept |
|
182 |
... add it after #inspectIt |
|
183 |
" |
|
184 |
idx := m indexOf:#inspectIt. |
|
185 |
idx ~~ 0 ifTrue:[ |
|
186 |
m addLabels:(resources array:#('-' 'accept')) |
|
187 |
selectors:#(nil accept) |
|
188 |
after:idx. |
|
189 |
]. |
|
190 |
||
191 |
" |
|
192 |
and add #explain after $gotoLine in the extra menu |
|
193 |
" |
|
194 |
sub := m subMenuAt:#others. |
|
195 |
sub notNil ifTrue:[ |
|
196 |
idx := sub indexOf:#gotoLine. |
|
197 |
sub addLabels:(resources array:#('-' 'explain')) |
|
198 |
selectors:#(nil explain) |
|
199 |
after:idx. |
|
200 |
self hasSelection ifFalse:[ |
|
201 |
sub disable:#explain |
|
202 |
]. |
|
97 | 203 |
]. |
59 | 204 |
]. |
131 | 205 |
^ m. |
136 | 206 |
! |
207 |
||
201 | 208 |
explain |
209 |
"explain action; |
|
210 |
evaluate the explainBlock passing whole contents and |
|
211 |
selection as arguments." |
|
212 |
||
213 |
|text| |
|
214 |
||
215 |
explainAction notNil ifTrue:[ |
|
216 |
text := self selection. |
|
217 |
text notNil ifTrue:[ |
|
218 |
explainAction value:(self contents) value:(text asString) |
|
219 |
] |
|
220 |
] |
|
221 |
! |
|
222 |
||
136 | 223 |
uncommentSelection |
224 |
"convenient function to comment out a block. |
|
225 |
All lines from line1 to line2 get an end-of-line comment |
|
226 |
in the first col." |
|
227 |
||
228 |
|e| |
|
229 |
||
230 |
(selectionStartCol == 1 and:[selectionEndCol == 0]) ifTrue:[ |
|
231 |
self uncommentFrom:selectionStartLine to:selectionEndLine-1 |
|
232 |
] ifFalse:[ |
|
233 |
((self characterAtLine:selectionStartLine col:selectionStartCol) == $" |
|
234 |
and:[(self characterAtLine:selectionEndLine col:selectionEndCol) == $"]) ifTrue:[ |
|
235 |
self deleteCharAtLine:selectionEndLine col:selectionEndCol. |
|
236 |
self deleteCharAtLine:selectionStartLine col:selectionStartCol. |
|
237 |
e := selectionEndCol - 1. |
|
238 |
selectionStartLine == selectionEndLine ifTrue:[e := e - 1]. |
|
239 |
self selectFromLine:selectionStartLine col:selectionStartCol |
|
240 |
toLine:selectionEndLine col:e. |
|
241 |
] |
|
242 |
] |
|
0 | 243 |
! ! |
244 |
||
206 | 245 |
!CodeView class methodsFor:'documentation'! |
246 |
||
247 |
version |
|
419 | 248 |
^ '$Header: /cvs/stx/stx/libwidg/CodeView.st,v 1.26 1996-02-27 14:35:33 cg Exp $' |
206 | 249 |
! ! |