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