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 |
|
6
|
29 |
$Header: /cvs/stx/stx/libwidg/CodeView.st,v 1.4 1993-12-11 01:41:07 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 |
'replace'
|
|
53 |
'-'
|
|
54 |
'font'
|
|
55 |
'-'
|
|
56 |
'search'
|
|
57 |
'goto'
|
|
58 |
'-'
|
|
59 |
'indent'
|
|
60 |
'-'
|
|
61 |
'save'
|
|
62 |
'print'
|
|
63 |
" 'filein' "
|
|
64 |
'-'
|
|
65 |
'doIt'
|
|
66 |
'printIt'
|
|
67 |
'inspectIt'
|
|
68 |
'-'
|
|
69 |
'explain'
|
|
70 |
'-'
|
|
71 |
'accept').
|
|
72 |
|
|
73 |
self middleButtonMenu:(PopUpMenu
|
|
74 |
labels:labels
|
6
|
75 |
selectors:#(
|
|
76 |
"
|
|
77 |
undo
|
|
78 |
"
|
|
79 |
again
|
|
80 |
nil
|
|
81 |
copySelection
|
0
|
82 |
cut
|
|
83 |
paste
|
|
84 |
replace
|
|
85 |
nil
|
|
86 |
changeFont
|
|
87 |
nil
|
|
88 |
search
|
|
89 |
gotoLine
|
|
90 |
nil
|
|
91 |
indent
|
|
92 |
nil
|
|
93 |
save
|
|
94 |
print
|
|
95 |
" fileItIn "
|
|
96 |
nil
|
|
97 |
doIt
|
|
98 |
printIt
|
|
99 |
inspectIt
|
|
100 |
nil
|
|
101 |
explain
|
|
102 |
nil
|
|
103 |
accept)
|
|
104 |
receiver:self
|
|
105 |
for:self).
|
|
106 |
|
|
107 |
! !
|
|
108 |
|
|
109 |
!CodeView methodsFor:'accessing'!
|
|
110 |
|
|
111 |
acceptAction:aBlock
|
|
112 |
"set the action to be performed on accept"
|
|
113 |
|
|
114 |
acceptAction := aBlock
|
|
115 |
!
|
|
116 |
|
|
117 |
explainAction:aBlock
|
|
118 |
"set the action to be performed on explain"
|
|
119 |
|
|
120 |
explainAction := aBlock
|
|
121 |
! !
|
|
122 |
|
|
123 |
!CodeView methodsFor:'selections'!
|
|
124 |
|
|
125 |
disableSelectionMenuEntries
|
|
126 |
"disable relevant menu entries for a selection"
|
|
127 |
|
|
128 |
super disableSelectionMenuEntries.
|
|
129 |
middleButtonMenu disable:#explain
|
|
130 |
!
|
|
131 |
|
|
132 |
enableSelectionMenuEntries
|
|
133 |
"enable relevant menu entries for a selection"
|
|
134 |
|
|
135 |
super enableSelectionMenuEntries.
|
|
136 |
middleButtonMenu enable:#explain
|
|
137 |
! !
|
|
138 |
|
|
139 |
!CodeView methodsFor:'user actions'!
|
|
140 |
|
|
141 |
accept
|
|
142 |
"accept action;
|
|
143 |
save cursor and selection; then execute the accept-action
|
|
144 |
and finally restore cursor and selection"
|
|
145 |
|
|
146 |
acceptAction notNil ifTrue:[
|
|
147 |
codeStartPosition := 1.
|
|
148 |
"
|
|
149 |
self cursor:Cursor wait.
|
|
150 |
"
|
|
151 |
abortBlock := [
|
|
152 |
self cursor:Cursor normal.
|
|
153 |
"redraw selection in normal color"
|
|
154 |
self selectFromLine:selectionStartLine col:selectionStartCol
|
|
155 |
toLine:selectionEndLine col:selectionEndCol.
|
|
156 |
abortBlock := nil.
|
|
157 |
^ nil
|
|
158 |
].
|
|
159 |
[
|
|
160 |
acceptAction value:(self contents)
|
|
161 |
] valueNowOrOnUnwindDo:[
|
|
162 |
"
|
|
163 |
self cursor:Cursor normal.
|
|
164 |
"
|
|
165 |
self unselect.
|
|
166 |
abortBlock := nil
|
|
167 |
]
|
|
168 |
]
|
|
169 |
!
|
|
170 |
|
|
171 |
explain
|
|
172 |
"explain action;
|
|
173 |
evaluate the explainBlock passing whole contents and
|
|
174 |
selection as arguments."
|
|
175 |
|
|
176 |
|text|
|
|
177 |
|
|
178 |
explainAction notNil ifTrue:[
|
|
179 |
text := self selection.
|
|
180 |
text notNil ifTrue:[
|
|
181 |
explainAction value:(self contents)
|
|
182 |
value:(text asString)
|
|
183 |
]
|
|
184 |
]
|
|
185 |
! !
|
|
186 |
|
|
187 |
!CodeView methodsFor:'events'!
|
|
188 |
|
|
189 |
keyPress:key x:x y:y
|
|
190 |
"catch keyboard shortcut: control-a for accept"
|
|
191 |
|
|
192 |
(key == #Cmda) ifTrue:[^ self accept].
|
|
193 |
(key == #Cmde) ifTrue:[^ self explain].
|
|
194 |
(key == #Help) ifTrue:[^ self explain].
|
|
195 |
super keyPress:key x:x y:y
|
|
196 |
! !
|