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