0
|
1 |
"
|
4
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
3 |
All Rights Reserved
|
|
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
|
|
14 |
instanceVariableNames:'acceptAction explainAction'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Interface-Workspace'
|
|
18 |
!
|
|
19 |
|
|
20 |
CodeView comment:'
|
|
21 |
|
4
|
22 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
23 |
All Rights Reserved
|
|
24 |
|
|
25 |
a view for code which can recompile its contents. It adds accept and explain
|
|
26 |
to the menu, and defines two actions: acceptAction to be performed for accept
|
|
27 |
and explainAction to be performed for explain.
|
|
28 |
|
27
|
29 |
$Header: /cvs/stx/stx/libwidg/CodeView.st,v 1.7 1994-01-17 09:30:00 claus Exp $
|
0
|
30 |
written winter-89 by claus
|
|
31 |
'!
|
|
32 |
|
|
33 |
!CodeView methodsFor:'initialization'!
|
|
34 |
|
6
|
35 |
initialize
|
|
36 |
super initialize.
|
|
37 |
showMatchingParenthesis := true
|
|
38 |
!
|
|
39 |
|
0
|
40 |
initializeMiddleButtonMenu
|
|
41 |
|labels|
|
|
42 |
|
6
|
43 |
labels := resources array:#(
|
|
44 |
"
|
0
|
45 |
'undo'
|
6
|
46 |
"
|
|
47 |
'again'
|
0
|
48 |
'-'
|
|
49 |
'copy'
|
|
50 |
'cut'
|
|
51 |
'paste'
|
|
52 |
'-'
|
|
53 |
'doIt'
|
|
54 |
'printIt'
|
|
55 |
'inspectIt'
|
|
56 |
'-'
|
10
|
57 |
'accept'
|
0
|
58 |
'-'
|
18
|
59 |
'others'
|
10
|
60 |
).
|
0
|
61 |
|
10
|
62 |
self middleButtonMenu:(PopUpMenu
|
0
|
63 |
labels:labels
|
6
|
64 |
selectors:#(
|
|
65 |
"
|
|
66 |
undo
|
|
67 |
"
|
|
68 |
again
|
|
69 |
nil
|
|
70 |
copySelection
|
10
|
71 |
cut
|
|
72 |
paste
|
|
73 |
nil
|
|
74 |
doIt
|
|
75 |
printIt
|
|
76 |
inspectIt
|
|
77 |
nil
|
|
78 |
accept
|
|
79 |
nil
|
|
80 |
others
|
|
81 |
)
|
0
|
82 |
receiver:self
|
|
83 |
for:self).
|
|
84 |
|
10
|
85 |
middleButtonMenu subMenuAt:#others put:(PopUpMenu
|
18
|
86 |
labels:(resources array:#(
|
10
|
87 |
'search'
|
|
88 |
'goto'
|
|
89 |
'-'
|
|
90 |
'explain'
|
|
91 |
'-'
|
|
92 |
'font'
|
|
93 |
'-'
|
|
94 |
'indent'
|
|
95 |
'-'
|
18
|
96 |
'save as ...'
|
10
|
97 |
'print'
|
18
|
98 |
))
|
10
|
99 |
selectors:#(
|
|
100 |
search
|
|
101 |
gotoLine
|
|
102 |
nil
|
|
103 |
explain
|
|
104 |
nil
|
|
105 |
changeFont
|
|
106 |
nil
|
|
107 |
indent
|
|
108 |
nil
|
|
109 |
save
|
|
110 |
print
|
|
111 |
)
|
|
112 |
receiver:self
|
|
113 |
for:self).
|
0
|
114 |
! !
|
|
115 |
|
|
116 |
!CodeView methodsFor:'accessing'!
|
|
117 |
|
|
118 |
acceptAction:aBlock
|
|
119 |
"set the action to be performed on accept"
|
|
120 |
|
|
121 |
acceptAction := aBlock
|
|
122 |
!
|
|
123 |
|
27
|
124 |
acceptAction
|
|
125 |
"return the action to be performed on accept (or nil)"
|
|
126 |
|
|
127 |
^ acceptAction
|
|
128 |
!
|
|
129 |
|
0
|
130 |
explainAction:aBlock
|
|
131 |
"set the action to be performed on explain"
|
|
132 |
|
|
133 |
explainAction := aBlock
|
|
134 |
! !
|
|
135 |
|
|
136 |
!CodeView methodsFor:'selections'!
|
|
137 |
|
|
138 |
disableSelectionMenuEntries
|
|
139 |
"disable relevant menu entries for a selection"
|
|
140 |
|
|
141 |
super disableSelectionMenuEntries.
|
|
142 |
middleButtonMenu disable:#explain
|
|
143 |
!
|
|
144 |
|
|
145 |
enableSelectionMenuEntries
|
|
146 |
"enable relevant menu entries for a selection"
|
|
147 |
|
|
148 |
super enableSelectionMenuEntries.
|
|
149 |
middleButtonMenu enable:#explain
|
|
150 |
! !
|
|
151 |
|
|
152 |
!CodeView methodsFor:'user actions'!
|
|
153 |
|
|
154 |
accept
|
|
155 |
"accept action;
|
|
156 |
save cursor and selection; then execute the accept-action
|
|
157 |
and finally restore cursor and selection"
|
|
158 |
|
|
159 |
acceptAction notNil ifTrue:[
|
|
160 |
codeStartPosition := 1.
|
27
|
161 |
|
0
|
162 |
abortBlock := [
|
|
163 |
self cursor:Cursor normal.
|
|
164 |
"redraw selection in normal color"
|
|
165 |
self selectFromLine:selectionStartLine col:selectionStartCol
|
|
166 |
toLine:selectionEndLine col:selectionEndCol.
|
|
167 |
abortBlock := nil.
|
|
168 |
^ nil
|
|
169 |
].
|
|
170 |
[
|
27
|
171 |
Object abortSignal catch:[
|
|
172 |
acceptAction value:(self contents)
|
|
173 |
]
|
0
|
174 |
] valueNowOrOnUnwindDo:[
|
|
175 |
self unselect.
|
|
176 |
abortBlock := nil
|
|
177 |
]
|
|
178 |
]
|
|
179 |
!
|
|
180 |
|
|
181 |
explain
|
|
182 |
"explain action;
|
|
183 |
evaluate the explainBlock passing whole contents and
|
|
184 |
selection as arguments."
|
|
185 |
|
|
186 |
|text|
|
|
187 |
|
|
188 |
explainAction notNil ifTrue:[
|
|
189 |
text := self selection.
|
|
190 |
text notNil ifTrue:[
|
|
191 |
explainAction value:(self contents)
|
|
192 |
value:(text asString)
|
|
193 |
]
|
|
194 |
]
|
|
195 |
! !
|
|
196 |
|
|
197 |
!CodeView methodsFor:'events'!
|
|
198 |
|
|
199 |
keyPress:key x:x y:y
|
|
200 |
"catch keyboard shortcut: control-a for accept"
|
|
201 |
|
10
|
202 |
(key == #Accept) ifTrue:[^ self accept].
|
|
203 |
(key == #Explain) ifTrue:[^ self explain].
|
0
|
204 |
(key == #Help) ifTrue:[^ self explain].
|
|
205 |
super keyPress:key x:x y:y
|
|
206 |
! !
|