author | Claus Gittinger <cg@exept.de> |
Wed, 17 Jan 1996 12:18:40 +0100 | |
changeset 291 | 71f4a66b3281 |
parent 274 | 6df4bb990f04 |
child 365 | cb7a40a691f3 |
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 |
|
201 | 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. |
39 |
It adds explain to the menu, and defines another action: |
|
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 |
|
125 | 45 |
If used with a model, accept sends the changeMsg to it (as defined in EditTextView). |
121 | 46 |
(however, it is possible to define moth changeMsg and acceptAction) |
123 | 47 |
|
48 |
||
49 |
Caveat: |
|
50 |
in this version, CodeView does not yet support MVC setups for doIt |
|
51 |
and explain. |
|
52 |
If required, simulate this by setting the doItAction and |
|
53 |
explainAction, to notify the model manually about whats going on. |
|
32 | 54 |
" |
201 | 55 |
! ! |
56 |
||
57 |
!CodeView methodsFor:'accessing'! |
|
58 |
||
59 |
explainAction:aBlock |
|
60 |
"set the action to be performed on explain" |
|
61 |
||
62 |
explainAction := aBlock |
|
63 |
! ! |
|
64 |
||
65 |
!CodeView methodsFor:'editing'! |
|
66 |
||
67 |
commentFrom:line1 to:line2 |
|
68 |
"convenient function to comment out a block. |
|
69 |
All lines from line1 to line2 get an end-of-line comment |
|
70 |
in the first col." |
|
71 |
||
72 |
line1 to:line2 do:[:lineNr | |
|
73 |
|l| |
|
74 |
||
75 |
l := self listAt:lineNr. |
|
76 |
l isNil ifTrue:[l := '']. |
|
77 |
self at:lineNr put:(('"' , '/') , l) |
|
78 |
]. |
|
79 |
self textChanged. |
|
80 |
! |
|
81 |
||
82 |
uncommentFrom:line1 to:line2 |
|
83 |
"convenient function to comment out a block. |
|
84 |
All lines from line1 to line2 get an end-of-line comment |
|
85 |
in the first col." |
|
86 |
||
87 |
line1 to:line2 do:[:lineNr | |
|
88 |
|l| |
|
89 |
||
90 |
l := self listAt:lineNr. |
|
91 |
(l notNil and:[l startsWith:('"' ,'/')]) ifTrue:[ |
|
92 |
self at:lineNr put:(l copyFrom:3) |
|
93 |
] |
|
94 |
]. |
|
95 |
self textChanged. |
|
96 |
! ! |
|
97 |
||
98 |
!CodeView methodsFor:'event handling'! |
|
99 |
||
100 |
keyPress:key x:x y:y |
|
101 |
"catch keyboard shortcuts" |
|
102 |
||
274
6df4bb990f04
handle accept where acceptAction is define (this was a historic leftover)
Claus Gittinger <cg@exept.de>
parents:
206
diff
changeset
|
103 |
<resource: #keyboard (#Explain #Help |
201 | 104 |
#CommentSelection #UncommentSelection)> |
105 |
||
106 |
(key == #Explain) ifTrue:[^ self explain]. |
|
107 |
(key == #Help) ifTrue:[^ self explain]. |
|
108 |
(key == #CommentSelection) ifTrue:[^ self commentSelection]. |
|
109 |
(key == #UncommentSelection) ifTrue:[^ self uncommentSelection]. |
|
110 |
||
111 |
super keyPress:key x:x y:y |
|
32 | 112 |
! ! |
113 |
||
0 | 114 |
!CodeView methodsFor:'initialization'! |
115 |
||
97 | 116 |
editMenu |
121 | 117 |
"return the popUpMenu; |
118 |
to make this independent from what is defined in superclasses, |
|
119 |
get the superclass menu and add my functions." |
|
131 | 120 |
|
97 | 121 |
|m sub idx| |
38 | 122 |
|
97 | 123 |
m := super editMenu. |
0 | 124 |
|
131 | 125 |
self sensor ctrlDown ifTrue:[ |
126 |
m addLabels:(resources array:#('-' 'commentIt' 'uncommentIt')) |
|
127 |
selectors:#(nil commentSelection uncommentSelection) |
|
128 |
after:(m labels size). |
|
129 |
self hasSelection ifFalse:[ |
|
130 |
m disableAll:#(commentSelection uncommentSelection) |
|
131 |
]. |
|
132 |
] ifFalse:[ |
|
38 | 133 |
|
131 | 134 |
" |
135 |
codeViews do support #accept |
|
136 |
... add it after #inspectIt |
|
137 |
" |
|
138 |
idx := m indexOf:#inspectIt. |
|
139 |
idx ~~ 0 ifTrue:[ |
|
140 |
m addLabels:(resources array:#('-' 'accept')) |
|
141 |
selectors:#(nil accept) |
|
142 |
after:idx. |
|
143 |
]. |
|
144 |
||
145 |
" |
|
146 |
and add #explain after $gotoLine in the extra menu |
|
147 |
" |
|
148 |
sub := m subMenuAt:#others. |
|
149 |
sub notNil ifTrue:[ |
|
150 |
idx := sub indexOf:#gotoLine. |
|
151 |
sub addLabels:(resources array:#('-' 'explain')) |
|
152 |
selectors:#(nil explain) |
|
153 |
after:idx. |
|
154 |
self hasSelection ifFalse:[ |
|
155 |
sub disable:#explain |
|
156 |
]. |
|
97 | 157 |
]. |
59 | 158 |
]. |
131 | 159 |
^ m. |
160 |
! ! |
|
97 | 161 |
|
0 | 162 |
!CodeView methodsFor:'user actions'! |
163 |
||
164 |
accept |
|
125 | 165 |
"redefined accept action; |
166 |
save cursor and selection to allow restore in case of an error |
|
167 |
(we are typically compiling here ... and the compiler may show |
|
168 |
errors by highlighting them)" |
|
95 | 169 |
|
170 |
codeStartPosition := 1. |
|
171 |
[ |
|
172 |
Object abortSignal handle:[:ex | |
|
173 |
self cursor:Cursor normal. |
|
174 |
"redraw selection in normal color" |
|
175 |
self selectFromLine:selectionStartLine col:selectionStartCol |
|
176 |
toLine:selectionEndLine col:selectionEndCol. |
|
177 |
ex return |
|
178 |
] do:[ |
|
125 | 179 |
super accept. |
70 | 180 |
] |
95 | 181 |
] valueNowOrOnUnwindDo:[ |
182 |
self unselect. |
|
0 | 183 |
] |
184 |
! |
|
185 |
||
136 | 186 |
commentSelection |
187 |
"convenient function to comment out a block. |
|
188 |
All lines from line1 to line2 get an end-of-line comment |
|
189 |
in the first col." |
|
190 |
||
191 |
|e| |
|
192 |
||
193 |
(selectionStartCol == 1 and:[selectionEndCol == 0]) ifTrue:[ |
|
194 |
self commentFrom:selectionStartLine to:selectionEndLine-1 |
|
195 |
] ifFalse:[ |
|
196 |
self insert:$" atLine:selectionStartLine col:selectionStartCol. |
|
197 |
e := selectionEndCol + 1. |
|
198 |
selectionStartLine == selectionEndLine ifTrue:[e := e + 1]. |
|
199 |
self insert:$" atLine:selectionEndLine col:e. |
|
200 |
self selectFromLine:selectionStartLine col:selectionStartCol |
|
201 |
toLine:selectionEndLine col:e. |
|
202 |
] |
|
203 |
! |
|
204 |
||
201 | 205 |
explain |
206 |
"explain action; |
|
207 |
evaluate the explainBlock passing whole contents and |
|
208 |
selection as arguments." |
|
209 |
||
210 |
|text| |
|
211 |
||
212 |
explainAction notNil ifTrue:[ |
|
213 |
text := self selection. |
|
214 |
text notNil ifTrue:[ |
|
215 |
explainAction value:(self contents) value:(text asString) |
|
216 |
] |
|
217 |
] |
|
218 |
! |
|
219 |
||
136 | 220 |
uncommentSelection |
221 |
"convenient function to comment out a block. |
|
222 |
All lines from line1 to line2 get an end-of-line comment |
|
223 |
in the first col." |
|
224 |
||
225 |
|e| |
|
226 |
||
227 |
(selectionStartCol == 1 and:[selectionEndCol == 0]) ifTrue:[ |
|
228 |
self uncommentFrom:selectionStartLine to:selectionEndLine-1 |
|
229 |
] ifFalse:[ |
|
230 |
((self characterAtLine:selectionStartLine col:selectionStartCol) == $" |
|
231 |
and:[(self characterAtLine:selectionEndLine col:selectionEndCol) == $"]) ifTrue:[ |
|
232 |
self deleteCharAtLine:selectionEndLine col:selectionEndCol. |
|
233 |
self deleteCharAtLine:selectionStartLine col:selectionStartCol. |
|
234 |
e := selectionEndCol - 1. |
|
235 |
selectionStartLine == selectionEndLine ifTrue:[e := e - 1]. |
|
236 |
self selectFromLine:selectionStartLine col:selectionStartCol |
|
237 |
toLine:selectionEndLine col:e. |
|
238 |
] |
|
239 |
] |
|
0 | 240 |
! ! |
241 |
||
206 | 242 |
!CodeView class methodsFor:'documentation'! |
243 |
||
244 |
version |
|
274
6df4bb990f04
handle accept where acceptAction is define (this was a historic leftover)
Claus Gittinger <cg@exept.de>
parents:
206
diff
changeset
|
245 |
^ '$Header: /cvs/stx/stx/libwidg/CodeView.st,v 1.24 1996-01-09 17:29:25 cg Exp $' |
206 | 246 |
! ! |