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 |
|
|
103 |
<resource: #keyboard (#Accept #Explain #Help
|
|
104 |
#CommentSelection #UncommentSelection)>
|
|
105 |
|
|
106 |
(key == #Accept) ifTrue:[^ self accept].
|
|
107 |
(key == #Explain) ifTrue:[^ self explain].
|
|
108 |
(key == #Help) ifTrue:[^ self explain].
|
|
109 |
(key == #CommentSelection) ifTrue:[^ self commentSelection].
|
|
110 |
(key == #UncommentSelection) ifTrue:[^ self uncommentSelection].
|
|
111 |
|
|
112 |
super keyPress:key x:x y:y
|
32
|
113 |
! !
|
|
114 |
|
0
|
115 |
!CodeView methodsFor:'initialization'!
|
|
116 |
|
97
|
117 |
editMenu
|
121
|
118 |
"return the popUpMenu;
|
|
119 |
to make this independent from what is defined in superclasses,
|
|
120 |
get the superclass menu and add my functions."
|
131
|
121 |
|
97
|
122 |
|m sub idx|
|
38
|
123 |
|
97
|
124 |
m := super editMenu.
|
0
|
125 |
|
131
|
126 |
self sensor ctrlDown ifTrue:[
|
|
127 |
m addLabels:(resources array:#('-' 'commentIt' 'uncommentIt'))
|
|
128 |
selectors:#(nil commentSelection uncommentSelection)
|
|
129 |
after:(m labels size).
|
|
130 |
self hasSelection ifFalse:[
|
|
131 |
m disableAll:#(commentSelection uncommentSelection)
|
|
132 |
].
|
|
133 |
] ifFalse:[
|
38
|
134 |
|
131
|
135 |
"
|
|
136 |
codeViews do support #accept
|
|
137 |
... add it after #inspectIt
|
|
138 |
"
|
|
139 |
idx := m indexOf:#inspectIt.
|
|
140 |
idx ~~ 0 ifTrue:[
|
|
141 |
m addLabels:(resources array:#('-' 'accept'))
|
|
142 |
selectors:#(nil accept)
|
|
143 |
after:idx.
|
|
144 |
].
|
|
145 |
|
|
146 |
"
|
|
147 |
and add #explain after $gotoLine in the extra menu
|
|
148 |
"
|
|
149 |
sub := m subMenuAt:#others.
|
|
150 |
sub notNil ifTrue:[
|
|
151 |
idx := sub indexOf:#gotoLine.
|
|
152 |
sub addLabels:(resources array:#('-' 'explain'))
|
|
153 |
selectors:#(nil explain)
|
|
154 |
after:idx.
|
|
155 |
self hasSelection ifFalse:[
|
|
156 |
sub disable:#explain
|
|
157 |
].
|
97
|
158 |
].
|
59
|
159 |
].
|
131
|
160 |
^ m.
|
|
161 |
! !
|
97
|
162 |
|
0
|
163 |
!CodeView methodsFor:'user actions'!
|
|
164 |
|
|
165 |
accept
|
125
|
166 |
"redefined accept action;
|
|
167 |
save cursor and selection to allow restore in case of an error
|
|
168 |
(we are typically compiling here ... and the compiler may show
|
|
169 |
errors by highlighting them)"
|
95
|
170 |
|
|
171 |
codeStartPosition := 1.
|
|
172 |
[
|
|
173 |
Object abortSignal handle:[:ex |
|
|
174 |
self cursor:Cursor normal.
|
|
175 |
"redraw selection in normal color"
|
|
176 |
self selectFromLine:selectionStartLine col:selectionStartCol
|
|
177 |
toLine:selectionEndLine col:selectionEndCol.
|
|
178 |
ex return
|
|
179 |
] do:[
|
125
|
180 |
super accept.
|
70
|
181 |
]
|
95
|
182 |
] valueNowOrOnUnwindDo:[
|
|
183 |
self unselect.
|
0
|
184 |
]
|
|
185 |
!
|
|
186 |
|
136
|
187 |
commentSelection
|
|
188 |
"convenient function to comment out a block.
|
|
189 |
All lines from line1 to line2 get an end-of-line comment
|
|
190 |
in the first col."
|
|
191 |
|
|
192 |
|e|
|
|
193 |
|
|
194 |
(selectionStartCol == 1 and:[selectionEndCol == 0]) ifTrue:[
|
|
195 |
self commentFrom:selectionStartLine to:selectionEndLine-1
|
|
196 |
] ifFalse:[
|
|
197 |
self insert:$" atLine:selectionStartLine col:selectionStartCol.
|
|
198 |
e := selectionEndCol + 1.
|
|
199 |
selectionStartLine == selectionEndLine ifTrue:[e := e + 1].
|
|
200 |
self insert:$" atLine:selectionEndLine col:e.
|
|
201 |
self selectFromLine:selectionStartLine col:selectionStartCol
|
|
202 |
toLine:selectionEndLine col:e.
|
|
203 |
]
|
|
204 |
!
|
|
205 |
|
201
|
206 |
explain
|
|
207 |
"explain action;
|
|
208 |
evaluate the explainBlock passing whole contents and
|
|
209 |
selection as arguments."
|
|
210 |
|
|
211 |
|text|
|
|
212 |
|
|
213 |
explainAction notNil ifTrue:[
|
|
214 |
text := self selection.
|
|
215 |
text notNil ifTrue:[
|
|
216 |
explainAction value:(self contents) value:(text asString)
|
|
217 |
]
|
|
218 |
]
|
|
219 |
!
|
|
220 |
|
136
|
221 |
uncommentSelection
|
|
222 |
"convenient function to comment out a block.
|
|
223 |
All lines from line1 to line2 get an end-of-line comment
|
|
224 |
in the first col."
|
|
225 |
|
|
226 |
|e|
|
|
227 |
|
|
228 |
(selectionStartCol == 1 and:[selectionEndCol == 0]) ifTrue:[
|
|
229 |
self uncommentFrom:selectionStartLine to:selectionEndLine-1
|
|
230 |
] ifFalse:[
|
|
231 |
((self characterAtLine:selectionStartLine col:selectionStartCol) == $"
|
|
232 |
and:[(self characterAtLine:selectionEndLine col:selectionEndCol) == $"]) ifTrue:[
|
|
233 |
self deleteCharAtLine:selectionEndLine col:selectionEndCol.
|
|
234 |
self deleteCharAtLine:selectionStartLine col:selectionStartCol.
|
|
235 |
e := selectionEndCol - 1.
|
|
236 |
selectionStartLine == selectionEndLine ifTrue:[e := e - 1].
|
|
237 |
self selectFromLine:selectionStartLine col:selectionStartCol
|
|
238 |
toLine:selectionEndLine col:e.
|
|
239 |
]
|
|
240 |
]
|
0
|
241 |
! !
|
|
242 |
|
206
|
243 |
!CodeView class methodsFor:'documentation'!
|
|
244 |
|
|
245 |
version
|
|
246 |
^ '$Header: /cvs/stx/stx/libwidg/CodeView.st,v 1.23 1995-11-24 09:13:18 cg Exp $'
|
|
247 |
! !
|