0
|
1 |
"
|
5
|
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 |
TextCollector subclass:#Workspace
|
|
14 |
instanceVariableNames:'doItAction
|
|
15 |
errorBox correctErrorBox
|
|
16 |
abortBlock codeStartPosition
|
|
17 |
errorFgColor errorBgColor'
|
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Interface-Workspace'
|
|
21 |
!
|
|
22 |
|
|
23 |
Workspace comment:'
|
|
24 |
|
5
|
25 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
26 |
All Rights Reserved
|
|
27 |
|
|
28 |
a view for editable text which can evaluate expressions.
|
|
29 |
|
|
30 |
instance variables:
|
|
31 |
|
|
32 |
doItAction <Block> block to evaluate for doIt
|
|
33 |
|
|
34 |
errorBox <Box> queryBox used in case of errors,
|
|
35 |
kept for fast pop-up
|
|
36 |
correctErrorBox <Box> same for correctable errors
|
|
37 |
abortBlock <Block> internal use: to jump out of doIt
|
|
38 |
in case of abort from box
|
|
39 |
codeStartPosition temporary
|
|
40 |
errorFgColor <Color> fg-color used when highlighting error
|
|
41 |
errorBgColor <Color> bg-Color used when highlighting error
|
|
42 |
|
23
|
43 |
$Header: /cvs/stx/stx/libwidg/Workspace.st,v 1.6 1994-01-08 17:31:31 claus Exp $
|
0
|
44 |
written winter-89 by claus
|
|
45 |
'!
|
|
46 |
|
|
47 |
!Workspace class methodsFor:'getting a System Workspace'!
|
|
48 |
|
|
49 |
start
|
|
50 |
"launch a new workspace"
|
|
51 |
|
23
|
52 |
|scrollable scr topView workspace f|
|
0
|
53 |
|
|
54 |
topView := StandardSystemView label:'Workspace' minExtent:(100 @ 100).
|
23
|
55 |
|
|
56 |
scrollable := true.
|
|
57 |
scrollable ifTrue:[
|
|
58 |
scr := ScrollableView for:self in:topView.
|
|
59 |
scr origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
|
|
60 |
workspace := scr scrolledView.
|
|
61 |
] ifFalse:[
|
|
62 |
workspace := super origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:topView.
|
|
63 |
workspace level:0.
|
|
64 |
].
|
0
|
65 |
|
|
66 |
"adjust topViews extent"
|
|
67 |
f := workspace font.
|
|
68 |
topView extent:((f widthOf:'x') * 40) @ (f height * 10).
|
7
|
69 |
topView open.
|
0
|
70 |
^ topView
|
|
71 |
|
|
72 |
"Workspace start"
|
|
73 |
! !
|
|
74 |
|
|
75 |
!Workspace methodsFor:'initialize / release'!
|
|
76 |
|
|
77 |
initialize
|
|
78 |
super initialize.
|
3
|
79 |
|
0
|
80 |
doItAction := [:theCode |
|
|
81 |
Compiler evaluate:theCode notifying:self
|
|
82 |
].
|
|
83 |
errorFgColor := selectionFgColor.
|
|
84 |
device hasColors ifTrue:[
|
|
85 |
errorBgColor := Color name:'Red'
|
|
86 |
] ifFalse:[
|
|
87 |
errorBgColor := selectionBgColor
|
|
88 |
]
|
|
89 |
!
|
|
90 |
|
|
91 |
initializeMiddleButtonMenu
|
|
92 |
|labels|
|
|
93 |
|
|
94 |
labels := resources array:#(
|
15
|
95 |
"
|
|
96 |
'undo'
|
|
97 |
"
|
|
98 |
'again'
|
|
99 |
'-'
|
|
100 |
'copy'
|
|
101 |
'cut'
|
|
102 |
'paste'
|
|
103 |
'-'
|
|
104 |
'doIt'
|
|
105 |
'printIt'
|
|
106 |
'inspectIt'
|
|
107 |
'-'
|
23
|
108 |
'others'
|
15
|
109 |
).
|
0
|
110 |
|
|
111 |
self middleButtonMenu:(PopUpMenu
|
|
112 |
labels:labels
|
15
|
113 |
selectors:#(
|
|
114 |
"
|
|
115 |
undo
|
|
116 |
"
|
|
117 |
again
|
|
118 |
nil
|
|
119 |
copySelection
|
0
|
120 |
cut
|
|
121 |
paste
|
|
122 |
nil
|
|
123 |
doIt
|
|
124 |
printIt
|
15
|
125 |
inspectIt
|
|
126 |
nil
|
|
127 |
others
|
|
128 |
)
|
0
|
129 |
receiver:self
|
|
130 |
for:self).
|
|
131 |
|
15
|
132 |
middleButtonMenu subMenuAt:#others put:(PopUpMenu
|
23
|
133 |
labels:(resources array:#(
|
15
|
134 |
'search'
|
|
135 |
'goto'
|
|
136 |
'-'
|
|
137 |
'font'
|
|
138 |
'-'
|
|
139 |
'indent'
|
|
140 |
'-'
|
23
|
141 |
'save as ...'
|
15
|
142 |
'print'
|
23
|
143 |
))
|
15
|
144 |
selectors:#(
|
|
145 |
search
|
|
146 |
gotoLine
|
|
147 |
nil
|
|
148 |
changeFont
|
|
149 |
nil
|
|
150 |
indent
|
|
151 |
nil
|
|
152 |
save
|
|
153 |
print
|
|
154 |
)
|
|
155 |
receiver:self
|
|
156 |
for:self).
|
0
|
157 |
!
|
|
158 |
|
|
159 |
destroy
|
7
|
160 |
errorBox notNil ifTrue:[errorBox destroy. errorBox := nil].
|
|
161 |
correctErrorBox notNil ifTrue:[correctErrorBox destroy. correctErrorBox := nil].
|
0
|
162 |
super destroy
|
|
163 |
! !
|
|
164 |
|
|
165 |
!Workspace methodsFor:'selections'!
|
|
166 |
|
|
167 |
disableSelectionMenuEntries
|
|
168 |
"disable relevant menu entries for a selection"
|
|
169 |
|
|
170 |
super disableSelectionMenuEntries.
|
|
171 |
middleButtonMenu disable:#doIt.
|
|
172 |
middleButtonMenu disable:#printIt.
|
|
173 |
middleButtonMenu disable:#inspectIt
|
|
174 |
!
|
|
175 |
|
|
176 |
enableSelectionMenuEntries
|
|
177 |
"enable relevant menu entries for a selection"
|
|
178 |
|
|
179 |
super enableSelectionMenuEntries.
|
|
180 |
middleButtonMenu enable:#doIt.
|
|
181 |
middleButtonMenu enable:#printIt.
|
|
182 |
middleButtonMenu enable:#inspectIt
|
|
183 |
! !
|
|
184 |
|
|
185 |
!Workspace methodsFor:'accessing'!
|
|
186 |
|
|
187 |
doItAction:aBlock
|
|
188 |
"define the action to be performed when 'doIt' is selected"
|
|
189 |
|
|
190 |
doItAction := aBlock
|
|
191 |
!
|
|
192 |
|
|
193 |
abortAction:aBlock
|
|
194 |
"define the action to be performed when an error occurs during
|
|
195 |
evaluation and user selects 'abort' in ErrorBox;
|
|
196 |
(this will usually be a block long-returning back)"
|
|
197 |
|
|
198 |
abortBlock := aBlock
|
|
199 |
! !
|
|
200 |
|
|
201 |
!Workspace methodsFor:'error handling'!
|
|
202 |
|
|
203 |
error:aString position:relPos to:relEndPos
|
|
204 |
"compiler notifys us of an error; hilight the error (relPos to relEndPos)
|
|
205 |
and show a Box asking for continue/abort"
|
|
206 |
|
|
207 |
|absPosition fg bg|
|
|
208 |
|
|
209 |
"change color of selection"
|
|
210 |
|
|
211 |
fg := selectionFgColor.
|
|
212 |
bg := selectionBgColor.
|
|
213 |
selectionBgColor := errorBgColor.
|
|
214 |
selectionFgColor := errorFgColor.
|
|
215 |
|
|
216 |
"select the text - relEndPos may be nil in which case the whole line is selected"
|
|
217 |
codeStartPosition isNil ifTrue:[codeStartPosition := 1].
|
|
218 |
absPosition := codeStartPosition + relPos - 1.
|
|
219 |
relEndPos isNil ifTrue:[
|
|
220 |
self selectLineWhereCharacterPosition:absPosition
|
|
221 |
] ifFalse:[
|
|
222 |
self selectFromCharacterPosition:absPosition to:(codeStartPosition + relEndPos - 1)
|
|
223 |
].
|
|
224 |
self makeSelectionVisible.
|
|
225 |
self hideCursor.
|
|
226 |
|
|
227 |
"start Dialog - make certain, that dialog-actions clean up correctly"
|
|
228 |
device synchronizeOutput.
|
|
229 |
errorBox isNil ifTrue:[
|
|
230 |
errorBox := OptionBox title:aString numberOfOptions:2.
|
|
231 |
errorBox buttonTitles:#('abort' 'continue')
|
|
232 |
].
|
|
233 |
errorBox actions:(Array with:[selectionFgColor := fg.
|
|
234 |
selectionBgColor := bg.
|
|
235 |
self showCursor.
|
|
236 |
abortBlock value.
|
|
237 |
^ false]
|
|
238 |
with:[selectionFgColor := fg.
|
|
239 |
selectionBgColor := bg.
|
|
240 |
self showCursor.
|
|
241 |
self unselect.
|
|
242 |
^ false]).
|
|
243 |
(errorBox title:aString) showAtPointer
|
|
244 |
!
|
|
245 |
|
|
246 |
warning:aString position:relPos to:relEndPos
|
|
247 |
"compiler notifys us of a warning - same behavior as error"
|
|
248 |
|
|
249 |
self error:aString position:relPos to:relEndPos
|
|
250 |
!
|
|
251 |
|
|
252 |
correctableError:aString position:relPos to:relEndPos
|
|
253 |
"compiler notifys us of a correctable error;
|
|
254 |
hilight the error (relPos to relEndPos) and show a Box asking for continue/correct/abort;
|
|
255 |
this method should return true to the compiler if user wants the error
|
|
256 |
to be corrected; false otherwise"
|
|
257 |
|
|
258 |
|absPosition fg bg|
|
|
259 |
|
|
260 |
"change selection color"
|
|
261 |
|
|
262 |
fg := selectionFgColor.
|
|
263 |
bg := selectionBgColor.
|
|
264 |
selectionBgColor := errorBgColor.
|
|
265 |
selectionFgColor := errorFgColor.
|
|
266 |
|
|
267 |
"select the error"
|
|
268 |
codeStartPosition isNil ifTrue:[codeStartPosition := 1].
|
|
269 |
absPosition := codeStartPosition + relPos - 1.
|
|
270 |
relEndPos isNil ifTrue:[
|
|
271 |
self selectLineWhereCharacterPosition:absPosition
|
|
272 |
] ifFalse:[
|
|
273 |
self selectFromCharacterPosition:absPosition to:(codeStartPosition + relEndPos - 1)
|
|
274 |
].
|
|
275 |
self makeSelectionVisible.
|
|
276 |
self hideCursor.
|
|
277 |
|
|
278 |
"start dialog - make certain cleanup is done"
|
|
279 |
device synchronizeOutput.
|
|
280 |
correctErrorBox isNil ifTrue:[
|
|
281 |
correctErrorBox := OptionBox title:aString numberOfOptions:3.
|
|
282 |
correctErrorBox buttonTitles:#('abort' 'correct' 'continue')
|
|
283 |
].
|
|
284 |
correctErrorBox actions:(Array with:[selectionFgColor := fg.
|
|
285 |
selectionBgColor := bg.
|
|
286 |
self showCursor.
|
|
287 |
abortBlock value.
|
|
288 |
^ false]
|
|
289 |
with:[selectionFgColor := fg.
|
|
290 |
selectionBgColor := bg.
|
|
291 |
self showCursor.
|
|
292 |
^ true]
|
|
293 |
with:[selectionFgColor := fg.
|
|
294 |
selectionBgColor := bg.
|
|
295 |
self showCursor.
|
|
296 |
self unselect.
|
|
297 |
^ false]).
|
|
298 |
(correctErrorBox title:aString) showAtPointer
|
|
299 |
! !
|
|
300 |
|
|
301 |
!Workspace methodsFor:'execution'!
|
|
302 |
|
|
303 |
doItWithValueDo:aBlock
|
|
304 |
"helper for doIt, printIt and inspectIt. Evaluate the selection and,
|
|
305 |
if all went well, evaluate the argument, aBlock with the value."
|
|
306 |
|
|
307 |
|code value selLine selCol endLine endCol|
|
|
308 |
|
|
309 |
code := self selection.
|
|
310 |
code notNil ifTrue:[
|
|
311 |
codeStartPosition := self characterPositionOfSelection.
|
|
312 |
selLine := selectionStartLine.
|
|
313 |
selCol := selectionStartCol.
|
|
314 |
endLine := selectionEndLine.
|
|
315 |
endCol := selectionEndCol.
|
|
316 |
|
|
317 |
self cursor:Cursor execute.
|
|
318 |
abortBlock := [self cursor:Cursor normal.
|
|
319 |
self selectFromLine:selLine col:selCol
|
|
320 |
toLine:endLine col:endCol.
|
|
321 |
abortBlock := nil.
|
|
322 |
^ nil].
|
|
323 |
[
|
|
324 |
value := doItAction value:(code asString)
|
|
325 |
] valueNowOrOnUnwindDo:[
|
|
326 |
self cursor:Cursor normal.
|
|
327 |
self selectFromLine:selLine col:selCol toLine:endLine col:endCol.
|
|
328 |
abortBlock := nil
|
|
329 |
].
|
|
330 |
aBlock value:value
|
|
331 |
]
|
|
332 |
!
|
|
333 |
|
|
334 |
doIt
|
|
335 |
"user selected 'doIt' from menu; show a wait-cursor, evaluate the code
|
|
336 |
and finally restore cursor; return result of evaluation"
|
|
337 |
|
|
338 |
self doItWithValueDo:[:result | ]
|
|
339 |
!
|
|
340 |
|
|
341 |
inspectIt
|
|
342 |
"user selected 'inspectIt' from menu; use doIt to evaluate the code
|
|
343 |
and start an inspector on the result"
|
|
344 |
|
|
345 |
self doItWithValueDo:[:result | result inspect]
|
|
346 |
!
|
|
347 |
|
|
348 |
printIt
|
|
349 |
"user selected 'printIt' from menu; use doIt to evaluate the code
|
|
350 |
and insert result of evaluation into my text"
|
|
351 |
|
|
352 |
self doItWithValueDo:[:result |
|
|
353 |
self cursorLine:selectionEndLine col:(selectionEndCol + 1).
|
|
354 |
self insertSelectedStringAtCursor:(result printString)
|
|
355 |
]
|
|
356 |
! !
|
|
357 |
|
|
358 |
!Workspace methodsFor:'events'!
|
|
359 |
|
|
360 |
keyPress:key x:x y:y
|
23
|
361 |
(key == #DoIt) ifTrue:[^ self doIt].
|
|
362 |
(key == #InspectIt) ifTrue:[^ self inspectIt].
|
|
363 |
(key == #PrintIt) ifTrue:[^ self printIt].
|
0
|
364 |
super keyPress:key x:x y:y
|
|
365 |
! !
|