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