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