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