author | Claus Gittinger <cg@exept.de> |
Wed, 12 Jun 1996 14:57:41 +0200 | |
changeset 762 | 832730063164 |
parent 693 | 8369529a2ac4 |
child 857 | 4990383442cc |
permissions | -rw-r--r-- |
0 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
59 | 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 |
TextCollector subclass:#Workspace |
|
257 | 14 |
instanceVariableNames:'doItAction codeStartPosition errorFgColor errorBgColor' |
15 |
classVariableNames:'DefaultErrorForegroundColor DefaultErrorBackgroundColor' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Interface-Workspace' |
|
0 | 18 |
! |
19 |
||
32 | 20 |
!Workspace class methodsFor:'documentation'! |
21 |
||
38 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
59 | 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 |
" |
|
38 |
a view for editable text which can evaluate expressions. |
|
38 | 39 |
I.e. its basically a view for editable text, with added |
40 |
'doIt', 'printIt' and 'inspectIt' functions on the popup-menu. |
|
125 | 41 |
|
38 | 42 |
The action to be performed on doIt is defined by a block, |
58 | 43 |
which can be defined by the owner of this view. |
60 | 44 |
(thus you can put a workspace into more complex widgets, and |
45 |
control what should happen on 'doIt'). |
|
58 | 46 |
|
578 | 47 |
A useful default action is automatically defined, which simply |
48 |
evaluates the selection as a smalltalk expression. |
|
49 |
(but, a lisp or prolog workspace would define its own action, |
|
50 |
to call for another compiler/interpreter ...) |
|
32 | 51 |
|
123 | 52 |
|
53 |
Caveat: |
|
418 | 54 |
in this version, Workspace does not yet support doIt in MVC setups. |
55 |
For now, simulate this by setting the doItAction, to notify the |
|
56 |
model manually about the doIt. |
|
123 | 57 |
|
58 |
||
578 | 59 |
[instance variables:] |
32 | 60 |
|
121 | 61 |
doItAction <Block> block to evaluate for doIt |
123 | 62 |
|
121 | 63 |
errorFgColor <Color> fg-Color to be used when highlighting errors |
64 |
||
65 |
errorBgColor <Color> bg-Color to be used when highlighting errors |
|
58 | 66 |
|
578 | 67 |
codeStartPosition private temporary |
121 | 68 |
|
578 | 69 |
|
70 |
[styleSheet values:] |
|
121 | 71 |
|
72 |
codeErrorSelectionForegroundColor fg color to highlight errors |
|
418 | 73 |
(default: selection fg) |
74 |
||
121 | 75 |
codeErrorSelectionBackgroundColor bg color to highlight errors |
418 | 76 |
(default: selection bg) |
578 | 77 |
|
78 |
[see also:] |
|
79 |
Workspace EditTextView |
|
80 |
Parser ByteCodeCompiler |
|
583 | 81 |
|
82 |
[author:] |
|
83 |
Claus Gittinger |
|
32 | 84 |
" |
201 | 85 |
! ! |
86 |
||
87 |
!Workspace class methodsFor:'defaults'! |
|
88 |
||
89 |
updateStyleCache |
|
444
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
430
diff
changeset
|
90 |
"extract values from the styleSheet and cache them in class variables" |
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
430
diff
changeset
|
91 |
|
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
430
diff
changeset
|
92 |
<resource: #style (#codeErrorSelectionForegroundColor |
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
430
diff
changeset
|
93 |
#codeErrorSelectionBackgroundColor)> |
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
430
diff
changeset
|
94 |
|
201 | 95 |
DefaultErrorForegroundColor := StyleSheet colorAt:'codeErrorSelectionForegroundColor'. |
96 |
DefaultErrorBackgroundColor := StyleSheet colorAt:'codeErrorSelectionBackgroundColor'. |
|
444
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
430
diff
changeset
|
97 |
|
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
430
diff
changeset
|
98 |
"Modified: 1.3.1996 / 13:52:04 / cg" |
32 | 99 |
! ! |
100 |
||
0 | 101 |
!Workspace class methodsFor:'getting a System Workspace'! |
102 |
||
32 | 103 |
open |
0 | 104 |
"launch a new workspace" |
105 |
||
418 | 106 |
|scr topView workspace f| |
0 | 107 |
|
418 | 108 |
topView := StandardSystemView |
421 | 109 |
label:(self classResources string:'Workspace') |
418 | 110 |
minExtent:(100 @ 100). |
23 | 111 |
|
418 | 112 |
scr := HVScrollableView for:self in:topView. |
113 |
scr origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
114 |
workspace := scr scrolledView. |
|
0 | 115 |
|
418 | 116 |
"/ adjust topViews extent according to my font |
117 |
||
0 | 118 |
f := workspace font. |
119 |
topView extent:((f widthOf:'x') * 40) @ (f height * 10). |
|
7 | 120 |
topView open. |
131 | 121 |
^ workspace |
0 | 122 |
|
58 | 123 |
" |
124 |
Workspace open |
|
125 |
" |
|
418 | 126 |
|
421 | 127 |
"Modified: 27.2.1996 / 17:41:08 / cg" |
0 | 128 |
! ! |
129 |
||
201 | 130 |
!Workspace methodsFor:'accessing'! |
0 | 131 |
|
201 | 132 |
doItAction |
133 |
"return the action to be performed when 'doIt' is selected" |
|
32 | 134 |
|
201 | 135 |
^ doItAction |
0 | 136 |
! |
137 |
||
418 | 138 |
doItAction:aOneArgBlock |
139 |
"define the action to be performed when 'doIt' is selected. |
|
140 |
The block will be evaluated, passing the selection as a String argument. |
|
141 |
A default doItAction is set for you in the initialize method." |
|
0 | 142 |
|
418 | 143 |
doItAction := aOneArgBlock |
144 |
||
145 |
"Modified: 27.2.1996 / 15:31:37 / cg" |
|
201 | 146 |
! ! |
147 |
||
148 |
!Workspace methodsFor:'compiler interface'! |
|
149 |
||
150 |
currentSourceCode |
|
151 |
"special interface to compiler - called by parser |
|
152 |
to get the updated source code after a corrected error" |
|
153 |
||
154 |
^ self contents |
|
0 | 155 |
! |
156 |
||
201 | 157 |
wantChangeLog |
158 |
"sent by the compiler to ask if a changeLog entry should |
|
159 |
be written. Return true here." |
|
0 | 160 |
|
201 | 161 |
^ true |
0 | 162 |
! ! |
163 |
||
418 | 164 |
!Workspace methodsFor:'compiler interface - error handling'! |
0 | 165 |
|
201 | 166 |
correctableError:aString position:relPos to:relEndPos from:aCompiler |
167 |
"compiler notifies us of a correctable error; |
|
168 |
hilight the error (relPos to relEndPos) and show a Box asking for continue/correct/abort; |
|
169 |
this method should return true to the compiler if user wants the error |
|
170 |
to be corrected; false otherwise" |
|
171 |
||
172 |
|action| |
|
173 |
||
174 |
self highlightingErrorPosition:relPos to:relEndPos do:[ |
|
368 | 175 |
action := OptionBox |
176 |
request:aString |
|
177 |
label:'Error' |
|
178 |
form:(WarningBox iconBitmap) |
|
179 |
buttonLabels:#('cancel' 'correct' 'continue') |
|
180 |
values:#(#abort #correct #continue) |
|
181 |
default:#continue. |
|
201 | 182 |
]. |
183 |
||
184 |
action == #abort ifTrue:[ |
|
368 | 185 |
Object abortSignal raise. |
186 |
^ false |
|
201 | 187 |
]. |
368 | 188 |
^ action == #correct |
189 |
||
190 |
"Modified: 20.2.1996 / 20:48:52 / cg" |
|
201 | 191 |
! |
192 |
||
193 |
error:aString position:relPos to:relEndPos asWarning:asWarning |
|
194 |
"compiler notifies us of an error; hilight the error (relPos to relEndPos) |
|
195 |
and show a Box asking for continue/abort." |
|
196 |
||
197 |
|answer| |
|
198 |
||
199 |
self highlightingErrorPosition:relPos to:relEndPos do:[ |
|
213
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
200 |
|box lbl| |
201 | 201 |
|
213
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
202 |
WarningSignal isHandled ifTrue:[ |
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
203 |
WarningSignal raiseErrorString:aString. |
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
204 |
^ false |
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
205 |
]. |
201 | 206 |
|
213
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
207 |
" |
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
208 |
ask if we should abort or continue |
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
209 |
" |
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
210 |
box := YesNoBox title:aString |
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
211 |
yesText:(resources string:'continue') |
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
212 |
noText:(resources string:'abort'). |
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
213 |
|
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
214 |
asWarning ifTrue:[ |
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
215 |
lbl := 'Compiler warning' |
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
216 |
] ifFalse:[ |
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
217 |
lbl := 'Compiler error'. |
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
218 |
]. |
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
219 |
box label:lbl. |
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
220 |
box form:(WarningBox iconBitmap). |
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
221 |
answer := box confirm. |
201 | 222 |
]. |
223 |
||
224 |
" |
|
225 |
do the abort if we have to |
|
226 |
" |
|
227 |
answer ifFalse:[ |
|
213
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
228 |
Object abortSignal raise. |
201 | 229 |
]. |
230 |
^ false |
|
213
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
231 |
|
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
232 |
"Created: 24.11.1995 / 22:56:34 / cg" |
201 | 233 |
! |
234 |
||
235 |
error:aString position:relPos to:relEndPos from:aCompiler |
|
236 |
"compiler notifies us of an error; hilight the error (relPos to relEndPos) |
|
237 |
and show a Box asking for continue/abort." |
|
238 |
||
239 |
^ self error:aString position:relPos to:relEndPos asWarning:false |
|
240 |
! |
|
241 |
||
59 | 242 |
highlightingErrorPosition:relPos to:relEndPos do:aBlock |
243 |
"evaluate aBlock while some selection is shown highlighted with error colors." |
|
58 | 244 |
|
59 | 245 |
|absPosition fg bg| |
0 | 246 |
|
58 | 247 |
" |
248 |
change color of selection & hide cursor |
|
249 |
" |
|
0 | 250 |
fg := selectionFgColor. |
251 |
bg := selectionBgColor. |
|
252 |
selectionBgColor := errorBgColor. |
|
253 |
selectionFgColor := errorFgColor. |
|
58 | 254 |
self hideCursor. |
0 | 255 |
|
58 | 256 |
" |
257 |
select the text - relEndPos may be nil in which case the whole line is selected |
|
258 |
we have to adjust the positions given by the compiler, since they |
|
259 |
are relative to the texts start (the compiler did stream-read the code). |
|
260 |
" |
|
0 | 261 |
codeStartPosition isNil ifTrue:[codeStartPosition := 1]. |
262 |
absPosition := codeStartPosition + relPos - 1. |
|
263 |
relEndPos isNil ifTrue:[ |
|
59 | 264 |
self selectLineWhereCharacterPosition:absPosition |
0 | 265 |
] ifFalse:[ |
59 | 266 |
self selectFromCharacterPosition:absPosition to:(codeStartPosition + relEndPos - 1) |
0 | 267 |
]. |
268 |
self makeSelectionVisible. |
|
269 |
||
155 | 270 |
device flush. |
58 | 271 |
|
59 | 272 |
aBlock valueNowOrOnUnwindDo:[ |
273 |
" |
|
274 |
undo selection color change and show cursor again |
|
275 |
" |
|
276 |
selectionFgColor := fg. |
|
277 |
selectionBgColor := bg. |
|
278 |
self showCursor. |
|
0 | 279 |
]. |
280 |
! |
|
281 |
||
116 | 282 |
warning:aString position:relPos to:relEndPos from:aCompiler |
32 | 283 |
"compiler notifies us of a warning - same behavior as error" |
0 | 284 |
|
95 | 285 |
self error:aString position:relPos to:relEndPos asWarning:true |
0 | 286 |
! ! |
287 |
||
288 |
!Workspace methodsFor:'events'! |
|
289 |
||
290 |
keyPress:key x:x y:y |
|
132 | 291 |
|
292 |
<resource: #keyboard (#DoIt #InspectIt #PrintIt)> |
|
293 |
||
131 | 294 |
|cmd commands fKey| |
60 | 295 |
|
32 | 296 |
(key == #DoIt) ifTrue:[^ self doIt]. |
23 | 297 |
(key == #InspectIt) ifTrue:[^ self inspectIt]. |
418 | 298 |
(key == #PrintIt) ifTrue:[^ self printIt]. |
38 | 299 |
|
300 |
" |
|
131 | 301 |
Ctrl-Fn or Cmd-Fn evaluates a key-sequence (n = 0..99) |
60 | 302 |
(I added Ctrl-Fn, because some windowmanagers already use cmd-fn) |
38 | 303 |
see TextView>>keyPress:x:y: |
304 |
" |
|
131 | 305 |
key isSymbol ifTrue:[ |
418 | 306 |
(key startsWith:'CmdF') ifTrue:[ |
307 |
fKey := key copyFrom:4 |
|
308 |
] ifFalse:[ |
|
309 |
(key startsWith:'CtrlF') ifTrue:[ |
|
310 |
fKey := key copyFrom:5 |
|
311 |
] |
|
312 |
]. |
|
131 | 313 |
]. |
314 |
fKey notNil ifTrue:[ |
|
418 | 315 |
fKey := fKey asSymbol. |
316 |
commands := Smalltalk at:#FunctionKeySequences ifAbsent:[nil]. |
|
317 |
commands notNil ifTrue:[ |
|
318 |
cmd := commands at:fKey ifAbsent:[nil]. |
|
319 |
cmd notNil ifTrue:[ |
|
320 |
AbortSignal "ErrorSignal" handle:[:ex | |
|
321 |
self warn:'error occurred in keyboard macro'. |
|
322 |
ex return. |
|
323 |
] do:[ |
|
324 |
Parser evaluate:cmd asString |
|
325 |
receiver:self |
|
326 |
notifying:nil |
|
327 |
compile:false. |
|
328 |
]. |
|
329 |
^ self |
|
330 |
] |
|
331 |
] |
|
38 | 332 |
]. |
333 |
||
0 | 334 |
super keyPress:key x:x y:y |
38 | 335 |
|
336 |
" |
|
418 | 337 |
example uses of function keys: |
38 | 338 |
|
339 |
to set tab-distance to 4-cols, |
|
340 |
select the following: |
|
341 |
||
342 |
self setTab4 |
|
343 |
||
344 |
then, press shift-F2 to define the sequence; |
|
95 | 345 |
press cmd-F2 to execute it |
38 | 346 |
voila: you have set 4-tabs. |
95 | 347 |
(some window managers (MWM, 4DWM have cmd-Fn redefined; use Ctrl-Fn then). |
38 | 348 |
|
349 |
to switch back, perform the same procedure with: |
|
350 |
||
418 | 351 |
self setTab8 |
38 | 352 |
|
60 | 353 |
Within the expression, 'self' is bound to the view. Thus, you can do |
354 |
all kinds of fancy things. |
|
355 |
For example: |
|
95 | 356 |
if you like a browser to come up on the selection when pressing Cmd-F3: |
60 | 357 |
select: |
38 | 358 |
|
418 | 359 |
|sel| |
360 |
sel := self selection asString withoutSeparators. |
|
361 |
(Smalltalk includesKey:sel asSymbol) ifTrue:[ |
|
362 |
(Smalltalk at:sel asSymbol) isClass ifTrue:[ |
|
363 |
SystemBrowser browseClass:(Smalltalk at:sel asSymbol) |
|
364 |
] |
|
365 |
] |
|
38 | 366 |
|
367 |
then, press shift-F3 to define the command. |
|
368 |
press cmd-F3 to execute it (select some classname before). |
|
60 | 369 |
(notice: on the Indy, Cmd-F3 is already used by the window manager) |
38 | 370 |
|
95 | 371 |
if you like a file-include command on Cmd-F4: |
38 | 372 |
select: |
373 |
||
418 | 374 |
|sel| |
375 |
sel := self selection. |
|
376 |
sel notNil ifTrue:[ |
|
377 |
sel := sel asString withoutSeparators. |
|
378 |
s := FileStream readonlyFileNamed:sel. |
|
379 |
s notNil ifTrue:[ |
|
380 |
self paste:(s contents asString). |
|
381 |
s close |
|
382 |
] |
|
383 |
] |
|
38 | 384 |
|
385 |
this will paste the contents of the file at the current cusor position. |
|
60 | 386 |
(select above expression, press Shift-F4, |
387 |
then select any filename and press Cmd-F4) |
|
418 | 388 |
try it here: /etc/passwd |
38 | 389 |
" |
418 | 390 |
|
391 |
"Modified: 27.2.1996 / 15:11:09 / cg" |
|
0 | 392 |
! ! |
201 | 393 |
|
394 |
!Workspace methodsFor:'execution'! |
|
395 |
||
396 |
doItWithValueDo:aBlock |
|
418 | 397 |
"helper for doIt, printIt and inspectIt. |
398 |
Evaluate the selection and, if all went well, evaluate the argument, |
|
399 |
aBlock with the value. |
|
400 |
Most work is in preparing for proper cleanup in case of abort |
|
401 |
or other exception while the evaluation is performed. |
|
402 |
(restore cursor, selectionColors etc.)" |
|
201 | 403 |
|
404 |
|code value selLine selCol endLine endCol cLine cCol cleanUp| |
|
405 |
||
406 |
code := self selection. |
|
407 |
code notNil ifTrue:[ |
|
257 | 408 |
codeStartPosition := self characterPositionOfSelection. |
201 | 409 |
|
257 | 410 |
" |
411 |
remember selection for later - if there is an error, |
|
412 |
the notification method will highlight it. |
|
413 |
thus destroying the current selection |
|
414 |
" |
|
415 |
selLine := selectionStartLine. |
|
416 |
selCol := selectionStartCol. |
|
417 |
endLine := selectionEndLine. |
|
418 |
endCol := selectionEndCol. |
|
419 |
cCol := cursorCol. |
|
420 |
cLine := cursorLine. |
|
201 | 421 |
|
257 | 422 |
" |
423 |
cleanup: restore previous selection and cursor positions |
|
424 |
" |
|
425 |
cleanUp := [ |
|
426 |
self selectFromLine:selLine col:selCol toLine:endLine col:endCol. |
|
427 |
cLine notNil ifTrue:[ |
|
428 |
self cursorLine:cLine col:cCol |
|
429 |
]. |
|
430 |
]. |
|
201 | 431 |
|
257 | 432 |
" |
433 |
perform the action. |
|
434 |
Be careful to release the reference to the value; |
|
435 |
otherwise, we could keep lots of garbage from being freed |
|
436 |
until the view gets closed |
|
437 |
" |
|
438 |
self topView withExecuteCursorDo:[ |
|
439 |
[ |
|
440 |
AbortSignal handle:[:ex | |
|
441 |
ex return |
|
442 |
] do:[ |
|
443 |
doItAction notNil ifTrue:[ |
|
444 |
value := doItAction value:code asString. |
|
445 |
cleanUp value. cleanUp := nil. |
|
446 |
aBlock value:value. |
|
447 |
] |
|
448 |
] |
|
449 |
] valueNowOrOnUnwindDo:[ |
|
450 |
cleanUp notNil ifTrue:[cleanUp value. cleanUp := nil]. |
|
451 |
value := nil |
|
452 |
] |
|
453 |
]. |
|
201 | 454 |
] |
257 | 455 |
|
418 | 456 |
"Modified: 27.2.1996 / 15:30:58 / cg" |
201 | 457 |
! ! |
458 |
||
459 |
!Workspace methodsFor:'initialize / release'! |
|
460 |
||
461 |
initStyle |
|
462 |
super initStyle. |
|
463 |
||
464 |
errorFgColor := DefaultErrorForegroundColor. |
|
465 |
errorFgColor isNil ifTrue:[errorFgColor := selectionFgColor]. |
|
466 |
errorBgColor := DefaultErrorBackgroundColor. |
|
467 |
errorBgColor isNil ifTrue:[ |
|
468 |
device hasColors ifTrue:[ |
|
469 |
errorBgColor := Color red |
|
470 |
] ifFalse:[ |
|
471 |
errorBgColor := selectionBgColor |
|
472 |
] |
|
473 |
]. |
|
474 |
! |
|
475 |
||
476 |
initialize |
|
477 |
super initialize. |
|
478 |
||
479 |
showMatchingParenthesis := true. |
|
480 |
||
481 |
self initializeDoITAction. |
|
482 |
! |
|
483 |
||
484 |
initializeDoITAction |
|
485 |
"set up the block to be evaluated for doIts. |
|
486 |
This is done here in a separate method to allow easier |
|
487 |
redefinition in subclasses" |
|
488 |
||
489 |
doItAction := [:theCode | |
|
490 |
Compiler |
|
491 |
evaluate:theCode |
|
492 |
in:nil |
|
493 |
receiver:nil |
|
494 |
notifying:self |
|
495 |
logged:true |
|
496 |
ifFail:nil |
|
497 |
]. |
|
498 |
! ! |
|
499 |
||
418 | 500 |
!Workspace methodsFor:'menu & menu actions'! |
501 |
||
502 |
doIt |
|
503 |
"user selected 'doIt' from menu; show a wait-cursor, evaluate the code |
|
504 |
and finally restore cursor; return result of evaluation" |
|
505 |
||
506 |
self doItWithValueDo:[:result | ] |
|
507 |
! |
|
508 |
||
509 |
editMenu |
|
489 | 510 |
<resource: #keyboard (#DoIt #PrintIt #InspectIt)> |
511 |
||
418 | 512 |
|m idx| |
513 |
||
514 |
m := super editMenu. |
|
515 |
||
516 |
" |
|
517 |
workspaces support #doIt, #printIt and #inspectIt |
|
518 |
add them after paste. |
|
519 |
" |
|
520 |
idx := m indexOf:#paste. |
|
521 |
idx == 0 ifTrue:[idx := m indexOf:#pasteOrReplace]. |
|
522 |
idx ~~ 0 ifTrue:[ |
|
430 | 523 |
m addLabels:(resources array:#('-' 'doIt' 'printIt' 'inspectIt')) |
524 |
selectors:#(nil doIt printIt inspectIt) |
|
525 |
accelerators:#(nil DoIt PrintIt InspectIt) |
|
526 |
after:idx |
|
418 | 527 |
]. |
528 |
||
529 |
self hasSelection ifFalse:[ |
|
430 | 530 |
m disableAll:#(printIt doIt inspectIt) |
418 | 531 |
]. |
532 |
||
533 |
^ m. |
|
430 | 534 |
|
489 | 535 |
"Modified: 7.3.1996 / 13:14:15 / cg" |
418 | 536 |
! |
537 |
||
538 |
inspectIt |
|
539 |
"user selected 'inspectIt' from menu; use doIt to evaluate the code |
|
540 |
and start an inspector on the result" |
|
541 |
||
542 |
self doItWithValueDo:[:result | result inspect] |
|
543 |
! |
|
544 |
||
545 |
printIt |
|
546 |
"user selected 'printIt' from menu; use doIt to evaluate the code |
|
547 |
and insert result of evaluation into my text. |
|
548 |
If the text is readOnly, do nothing." |
|
549 |
||
550 |
readOnly ifTrue:[ |
|
693 | 551 |
self beep |
418 | 552 |
] ifFalse:[ |
553 |
self doItWithValueDo:[:result | |
|
554 |
self cursorLine:selectionEndLine col:(selectionEndCol + 1). |
|
555 |
self insertSelectedStringAtCursor:(result displayString "printString") |
|
556 |
] |
|
557 |
] |
|
558 |
||
693 | 559 |
"Modified: 28.5.1996 / 16:59:04 / cg" |
418 | 560 |
! ! |
561 |
||
206 | 562 |
!Workspace class methodsFor:'documentation'! |
563 |
||
564 |
version |
|
693 | 565 |
^ '$Header: /cvs/stx/stx/libwidg/Workspace.st,v 1.46 1996-05-28 14:59:29 cg Exp $'! ! |