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