author | Claus Gittinger <cg@exept.de> |
Mon, 27 Jan 1997 16:00:15 +0100 | |
changeset 976 | ed2b99f9695a |
parent 966 | 824e0ecc0e6f |
child 1107 | 25753e7f960f |
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" |
857 | 128 |
! |
129 |
||
130 |
openForRemote:hostName |
|
131 |
"launch a new workspace to evaluate expression on some remote machine. |
|
132 |
This requires the RemoteObjects package to be loaded." |
|
133 |
||
134 |
|server remoteCompiler workspace| |
|
135 |
||
136 |
RemoteObjectServer isNil ifTrue:[^ nil]. |
|
137 |
||
138 |
server := RemoteObjectServer on:hostName. |
|
139 |
remoteCompiler := server get:#Compiler. |
|
140 |
||
141 |
workspace := self open. |
|
858 | 142 |
workspace topView label:'Remote Workspace [' , hostName , ']'. |
857 | 143 |
workspace doItAction: |
144 |
[:theCode | |
|
145 |
remoteCompiler |
|
146 |
evaluate:theCode |
|
147 |
in:nil |
|
148 |
receiver:nil |
|
149 |
notifying:workspace |
|
150 |
logged:true |
|
151 |
ifFail:nil |
|
152 |
] |
|
153 |
" |
|
154 |
Workspace openForRemote:'andi' |
|
155 |
" |
|
156 |
||
858 | 157 |
"Modified: 28.10.1996 / 17:51:44 / cg" |
0 | 158 |
! ! |
159 |
||
201 | 160 |
!Workspace methodsFor:'accessing'! |
0 | 161 |
|
201 | 162 |
doItAction |
163 |
"return the action to be performed when 'doIt' is selected" |
|
32 | 164 |
|
201 | 165 |
^ doItAction |
0 | 166 |
! |
167 |
||
418 | 168 |
doItAction:aOneArgBlock |
169 |
"define the action to be performed when 'doIt' is selected. |
|
170 |
The block will be evaluated, passing the selection as a String argument. |
|
171 |
A default doItAction is set for you in the initialize method." |
|
0 | 172 |
|
418 | 173 |
doItAction := aOneArgBlock |
174 |
||
175 |
"Modified: 27.2.1996 / 15:31:37 / cg" |
|
201 | 176 |
! ! |
177 |
||
178 |
!Workspace methodsFor:'compiler interface'! |
|
179 |
||
180 |
currentSourceCode |
|
181 |
"special interface to compiler - called by parser |
|
182 |
to get the updated source code after a corrected error" |
|
183 |
||
184 |
^ self contents |
|
0 | 185 |
! |
186 |
||
201 | 187 |
wantChangeLog |
188 |
"sent by the compiler to ask if a changeLog entry should |
|
189 |
be written. Return true here." |
|
0 | 190 |
|
201 | 191 |
^ true |
0 | 192 |
! ! |
193 |
||
418 | 194 |
!Workspace methodsFor:'compiler interface - error handling'! |
0 | 195 |
|
201 | 196 |
correctableError:aString position:relPos to:relEndPos from:aCompiler |
197 |
"compiler notifies us of a correctable error; |
|
198 |
hilight the error (relPos to relEndPos) and show a Box asking for continue/correct/abort; |
|
199 |
this method should return true to the compiler if user wants the error |
|
200 |
to be corrected; false otherwise" |
|
201 |
||
202 |
|action| |
|
203 |
||
204 |
self highlightingErrorPosition:relPos to:relEndPos do:[ |
|
368 | 205 |
action := OptionBox |
206 |
request:aString |
|
207 |
label:'Error' |
|
208 |
form:(WarningBox iconBitmap) |
|
209 |
buttonLabels:#('cancel' 'correct' 'continue') |
|
210 |
values:#(#abort #correct #continue) |
|
211 |
default:#continue. |
|
201 | 212 |
]. |
213 |
||
214 |
action == #abort ifTrue:[ |
|
368 | 215 |
Object abortSignal raise. |
216 |
^ false |
|
201 | 217 |
]. |
368 | 218 |
^ action == #correct |
219 |
||
220 |
"Modified: 20.2.1996 / 20:48:52 / cg" |
|
201 | 221 |
! |
222 |
||
223 |
error:aString position:relPos to:relEndPos asWarning:asWarning |
|
224 |
"compiler notifies us of an error; hilight the error (relPos to relEndPos) |
|
225 |
and show a Box asking for continue/abort." |
|
226 |
||
227 |
|answer| |
|
228 |
||
229 |
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
|
230 |
|box lbl| |
201 | 231 |
|
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 |
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
|
233 |
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
|
234 |
^ false |
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
235 |
]. |
201 | 236 |
|
213
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
237 |
" |
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
238 |
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
|
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 |
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
|
241 |
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
|
242 |
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
|
243 |
|
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
244 |
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
|
245 |
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
|
246 |
] ifFalse:[ |
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 error'. |
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
248 |
]. |
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
249 |
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
|
250 |
box form:(WarningBox iconBitmap). |
921 | 251 |
answer := box confirm. |
252 |
box destroy. |
|
201 | 253 |
]. |
254 |
||
255 |
" |
|
256 |
do the abort if we have to |
|
257 |
" |
|
258 |
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
|
259 |
Object abortSignal raise. |
201 | 260 |
]. |
261 |
^ 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
|
262 |
|
6286d3f36c14
raise warningSignal if handled (allows warnBoxes from compiler to be suppressed in debugger)
Claus Gittinger <cg@exept.de>
parents:
208
diff
changeset
|
263 |
"Created: 24.11.1995 / 22:56:34 / cg" |
921 | 264 |
"Modified: 7.1.1997 / 23:00:45 / cg" |
201 | 265 |
! |
266 |
||
267 |
error:aString position:relPos to:relEndPos from:aCompiler |
|
268 |
"compiler notifies us of an error; hilight the error (relPos to relEndPos) |
|
269 |
and show a Box asking for continue/abort." |
|
270 |
||
271 |
^ self error:aString position:relPos to:relEndPos asWarning:false |
|
272 |
! |
|
273 |
||
59 | 274 |
highlightingErrorPosition:relPos to:relEndPos do:aBlock |
275 |
"evaluate aBlock while some selection is shown highlighted with error colors." |
|
58 | 276 |
|
59 | 277 |
|absPosition fg bg| |
0 | 278 |
|
58 | 279 |
" |
280 |
change color of selection & hide cursor |
|
281 |
" |
|
0 | 282 |
fg := selectionFgColor. |
283 |
bg := selectionBgColor. |
|
284 |
selectionBgColor := errorBgColor. |
|
285 |
selectionFgColor := errorFgColor. |
|
58 | 286 |
self hideCursor. |
0 | 287 |
|
58 | 288 |
" |
289 |
select the text - relEndPos may be nil in which case the whole line is selected |
|
290 |
we have to adjust the positions given by the compiler, since they |
|
291 |
are relative to the texts start (the compiler did stream-read the code). |
|
292 |
" |
|
0 | 293 |
codeStartPosition isNil ifTrue:[codeStartPosition := 1]. |
294 |
absPosition := codeStartPosition + relPos - 1. |
|
295 |
relEndPos isNil ifTrue:[ |
|
59 | 296 |
self selectLineWhereCharacterPosition:absPosition |
0 | 297 |
] ifFalse:[ |
59 | 298 |
self selectFromCharacterPosition:absPosition to:(codeStartPosition + relEndPos - 1) |
0 | 299 |
]. |
300 |
self makeSelectionVisible. |
|
301 |
||
155 | 302 |
device flush. |
58 | 303 |
|
59 | 304 |
aBlock valueNowOrOnUnwindDo:[ |
305 |
" |
|
306 |
undo selection color change and show cursor again |
|
307 |
" |
|
308 |
selectionFgColor := fg. |
|
309 |
selectionBgColor := bg. |
|
310 |
self showCursor. |
|
0 | 311 |
]. |
312 |
! |
|
313 |
||
116 | 314 |
warning:aString position:relPos to:relEndPos from:aCompiler |
32 | 315 |
"compiler notifies us of a warning - same behavior as error" |
0 | 316 |
|
95 | 317 |
self error:aString position:relPos to:relEndPos asWarning:true |
0 | 318 |
! ! |
319 |
||
320 |
!Workspace methodsFor:'events'! |
|
321 |
||
322 |
keyPress:key x:x y:y |
|
132 | 323 |
|
922 | 324 |
<resource: #keyboard (#DoIt #InspectIt #PrintIt #'CmdF*' #'CtrlF*')> |
132 | 325 |
|
131 | 326 |
|cmd commands fKey| |
60 | 327 |
|
32 | 328 |
(key == #DoIt) ifTrue:[^ self doIt]. |
23 | 329 |
(key == #InspectIt) ifTrue:[^ self inspectIt]. |
418 | 330 |
(key == #PrintIt) ifTrue:[^ self printIt]. |
38 | 331 |
|
332 |
" |
|
131 | 333 |
Ctrl-Fn or Cmd-Fn evaluates a key-sequence (n = 0..99) |
60 | 334 |
(I added Ctrl-Fn, because some windowmanagers already use cmd-fn) |
38 | 335 |
see TextView>>keyPress:x:y: |
336 |
" |
|
131 | 337 |
key isSymbol ifTrue:[ |
418 | 338 |
(key startsWith:'CmdF') ifTrue:[ |
339 |
fKey := key copyFrom:4 |
|
340 |
] ifFalse:[ |
|
341 |
(key startsWith:'CtrlF') ifTrue:[ |
|
342 |
fKey := key copyFrom:5 |
|
343 |
] |
|
344 |
]. |
|
131 | 345 |
]. |
346 |
fKey notNil ifTrue:[ |
|
418 | 347 |
fKey := fKey asSymbol. |
348 |
commands := Smalltalk at:#FunctionKeySequences ifAbsent:[nil]. |
|
349 |
commands notNil ifTrue:[ |
|
350 |
cmd := commands at:fKey ifAbsent:[nil]. |
|
351 |
cmd notNil ifTrue:[ |
|
352 |
AbortSignal "ErrorSignal" handle:[:ex | |
|
353 |
self warn:'error occurred in keyboard macro'. |
|
354 |
ex return. |
|
355 |
] do:[ |
|
356 |
Parser evaluate:cmd asString |
|
357 |
receiver:self |
|
358 |
notifying:nil |
|
359 |
compile:false. |
|
360 |
]. |
|
361 |
^ self |
|
362 |
] |
|
363 |
] |
|
38 | 364 |
]. |
365 |
||
0 | 366 |
super keyPress:key x:x y:y |
38 | 367 |
|
368 |
" |
|
418 | 369 |
example uses of function keys: |
38 | 370 |
|
371 |
to set tab-distance to 4-cols, |
|
372 |
select the following: |
|
373 |
||
374 |
self setTab4 |
|
375 |
||
376 |
then, press shift-F2 to define the sequence; |
|
95 | 377 |
press cmd-F2 to execute it |
38 | 378 |
voila: you have set 4-tabs. |
95 | 379 |
(some window managers (MWM, 4DWM have cmd-Fn redefined; use Ctrl-Fn then). |
38 | 380 |
|
381 |
to switch back, perform the same procedure with: |
|
382 |
||
418 | 383 |
self setTab8 |
38 | 384 |
|
60 | 385 |
Within the expression, 'self' is bound to the view. Thus, you can do |
386 |
all kinds of fancy things. |
|
387 |
For example: |
|
95 | 388 |
if you like a browser to come up on the selection when pressing Cmd-F3: |
60 | 389 |
select: |
38 | 390 |
|
418 | 391 |
|sel| |
392 |
sel := self selection asString withoutSeparators. |
|
393 |
(Smalltalk includesKey:sel asSymbol) ifTrue:[ |
|
394 |
(Smalltalk at:sel asSymbol) isClass ifTrue:[ |
|
395 |
SystemBrowser browseClass:(Smalltalk at:sel asSymbol) |
|
396 |
] |
|
397 |
] |
|
38 | 398 |
|
399 |
then, press shift-F3 to define the command. |
|
400 |
press cmd-F3 to execute it (select some classname before). |
|
60 | 401 |
(notice: on the Indy, Cmd-F3 is already used by the window manager) |
38 | 402 |
|
95 | 403 |
if you like a file-include command on Cmd-F4: |
38 | 404 |
select: |
405 |
||
418 | 406 |
|sel| |
407 |
sel := self selection. |
|
408 |
sel notNil ifTrue:[ |
|
409 |
sel := sel asString withoutSeparators. |
|
410 |
s := FileStream readonlyFileNamed:sel. |
|
411 |
s notNil ifTrue:[ |
|
412 |
self paste:(s contents asString). |
|
413 |
s close |
|
414 |
] |
|
415 |
] |
|
38 | 416 |
|
417 |
this will paste the contents of the file at the current cusor position. |
|
60 | 418 |
(select above expression, press Shift-F4, |
419 |
then select any filename and press Cmd-F4) |
|
418 | 420 |
try it here: /etc/passwd |
38 | 421 |
" |
418 | 422 |
|
922 | 423 |
"Modified: 9.1.1997 / 12:18:30 / cg" |
0 | 424 |
! ! |
201 | 425 |
|
426 |
!Workspace methodsFor:'execution'! |
|
427 |
||
428 |
doItWithValueDo:aBlock |
|
418 | 429 |
"helper for doIt, printIt and inspectIt. |
430 |
Evaluate the selection and, if all went well, evaluate the argument, |
|
431 |
aBlock with the value. |
|
432 |
Most work is in preparing for proper cleanup in case of abort |
|
433 |
or other exception while the evaluation is performed. |
|
434 |
(restore cursor, selectionColors etc.)" |
|
201 | 435 |
|
929 | 436 |
|code selLine selCol endLine endCol cLine cCol cleanUp| |
201 | 437 |
|
438 |
code := self selection. |
|
439 |
code notNil ifTrue:[ |
|
257 | 440 |
codeStartPosition := self characterPositionOfSelection. |
201 | 441 |
|
257 | 442 |
" |
443 |
remember selection for later - if there is an error, |
|
444 |
the notification method will highlight it. |
|
445 |
thus destroying the current selection |
|
446 |
" |
|
447 |
selLine := selectionStartLine. |
|
448 |
selCol := selectionStartCol. |
|
449 |
endLine := selectionEndLine. |
|
450 |
endCol := selectionEndCol. |
|
451 |
cCol := cursorCol. |
|
452 |
cLine := cursorLine. |
|
201 | 453 |
|
257 | 454 |
" |
455 |
cleanup: restore previous selection and cursor positions |
|
456 |
" |
|
457 |
cleanUp := [ |
|
458 |
self selectFromLine:selLine col:selCol toLine:endLine col:endCol. |
|
459 |
cLine notNil ifTrue:[ |
|
460 |
self cursorLine:cLine col:cCol |
|
461 |
]. |
|
462 |
]. |
|
201 | 463 |
|
257 | 464 |
" |
465 |
perform the action. |
|
466 |
Be careful to release the reference to the value; |
|
467 |
otherwise, we could keep lots of garbage from being freed |
|
468 |
until the view gets closed |
|
469 |
" |
|
470 |
self topView withExecuteCursorDo:[ |
|
471 |
[ |
|
472 |
AbortSignal handle:[:ex | |
|
473 |
ex return |
|
474 |
] do:[ |
|
929 | 475 |
|value| |
476 |
||
257 | 477 |
doItAction notNil ifTrue:[ |
929 | 478 |
value := doItAction value:(code asString). |
257 | 479 |
cleanUp value. cleanUp := nil. |
480 |
aBlock value:value. |
|
481 |
] |
|
482 |
] |
|
483 |
] valueNowOrOnUnwindDo:[ |
|
929 | 484 |
cleanUp notNil ifTrue:[ |
485 |
cleanUp value. cleanUp := nil |
|
486 |
]. |
|
257 | 487 |
] |
488 |
]. |
|
201 | 489 |
] |
257 | 490 |
|
929 | 491 |
"Modified: 11.1.1997 / 20:56:30 / cg" |
201 | 492 |
! ! |
493 |
||
494 |
!Workspace methodsFor:'initialize / release'! |
|
495 |
||
496 |
initStyle |
|
966 | 497 |
"setup viewStyle specifics" |
498 |
||
201 | 499 |
super initStyle. |
500 |
||
501 |
errorFgColor := DefaultErrorForegroundColor. |
|
502 |
errorFgColor isNil ifTrue:[errorFgColor := selectionFgColor]. |
|
503 |
errorBgColor := DefaultErrorBackgroundColor. |
|
504 |
errorBgColor isNil ifTrue:[ |
|
966 | 505 |
device hasColors ifTrue:[ |
506 |
errorBgColor := Color red |
|
507 |
] ifFalse:[ |
|
508 |
errorBgColor := selectionBgColor |
|
509 |
] |
|
201 | 510 |
]. |
966 | 511 |
|
512 |
"Modified: 22.1.1997 / 11:58:00 / cg" |
|
201 | 513 |
! |
514 |
||
515 |
initialize |
|
516 |
super initialize. |
|
517 |
||
518 |
showMatchingParenthesis := true. |
|
519 |
||
520 |
self initializeDoITAction. |
|
521 |
! |
|
522 |
||
523 |
initializeDoITAction |
|
524 |
"set up the block to be evaluated for doIts. |
|
525 |
This is done here in a separate method to allow easier |
|
526 |
redefinition in subclasses" |
|
527 |
||
528 |
doItAction := [:theCode | |
|
529 |
Compiler |
|
530 |
evaluate:theCode |
|
531 |
in:nil |
|
532 |
receiver:nil |
|
533 |
notifying:self |
|
534 |
logged:true |
|
535 |
ifFail:nil |
|
536 |
]. |
|
537 |
! ! |
|
538 |
||
418 | 539 |
!Workspace methodsFor:'menu & menu actions'! |
540 |
||
541 |
doIt |
|
542 |
"user selected 'doIt' from menu; show a wait-cursor, evaluate the code |
|
543 |
and finally restore cursor; return result of evaluation" |
|
544 |
||
545 |
self doItWithValueDo:[:result | ] |
|
546 |
! |
|
547 |
||
548 |
editMenu |
|
489 | 549 |
<resource: #keyboard (#DoIt #PrintIt #InspectIt)> |
550 |
||
418 | 551 |
|m idx| |
552 |
||
553 |
m := super editMenu. |
|
554 |
||
555 |
" |
|
556 |
workspaces support #doIt, #printIt and #inspectIt |
|
557 |
add them after paste. |
|
558 |
" |
|
559 |
idx := m indexOf:#paste. |
|
560 |
idx == 0 ifTrue:[idx := m indexOf:#pasteOrReplace]. |
|
561 |
idx ~~ 0 ifTrue:[ |
|
430 | 562 |
m addLabels:(resources array:#('-' 'doIt' 'printIt' 'inspectIt')) |
563 |
selectors:#(nil doIt printIt inspectIt) |
|
922 | 564 |
accelerators:#(nil #DoIt #PrintIt #InspectIt) |
430 | 565 |
after:idx |
418 | 566 |
]. |
567 |
||
568 |
self hasSelection ifFalse:[ |
|
430 | 569 |
m disableAll:#(printIt doIt inspectIt) |
418 | 570 |
]. |
571 |
||
572 |
^ m. |
|
430 | 573 |
|
922 | 574 |
"Modified: 9.1.1997 / 12:17:01 / cg" |
418 | 575 |
! |
576 |
||
577 |
inspectIt |
|
578 |
"user selected 'inspectIt' from menu; use doIt to evaluate the code |
|
579 |
and start an inspector on the result" |
|
580 |
||
581 |
self doItWithValueDo:[:result | result inspect] |
|
582 |
! |
|
583 |
||
584 |
printIt |
|
585 |
"user selected 'printIt' from menu; use doIt to evaluate the code |
|
586 |
and insert result of evaluation into my text. |
|
587 |
If the text is readOnly, do nothing." |
|
588 |
||
589 |
readOnly ifTrue:[ |
|
693 | 590 |
self beep |
418 | 591 |
] ifFalse:[ |
592 |
self doItWithValueDo:[:result | |
|
593 |
self cursorLine:selectionEndLine col:(selectionEndCol + 1). |
|
594 |
self insertSelectedStringAtCursor:(result displayString "printString") |
|
595 |
] |
|
596 |
] |
|
597 |
||
693 | 598 |
"Modified: 28.5.1996 / 16:59:04 / cg" |
418 | 599 |
! ! |
600 |
||
206 | 601 |
!Workspace class methodsFor:'documentation'! |
602 |
||
603 |
version |
|
966 | 604 |
^ '$Header: /cvs/stx/stx/libwidg/Workspace.st,v 1.52 1997-01-22 11:02:10 cg Exp $' |
858 | 605 |
! ! |