author | Claus Gittinger <cg@exept.de> |
Fri, 01 Aug 1997 21:48:27 +0200 | |
changeset 1293 | c0806b73dc48 |
parent 1261 | bdb18f73205c |
child 1396 | 4e019d312d6f |
permissions | -rw-r--r-- |
0 | 1 |
" |
4 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
70 | 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 |
Workspace subclass:#CodeView |
|
917
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
14 |
instanceVariableNames:'explainAction commentStrings' |
419 | 15 |
classVariableNames:'' |
16 |
poolDictionaries:'' |
|
17 |
category:'Interface-Workspace' |
|
0 | 18 |
! |
19 |
||
32 | 20 |
!CodeView class methodsFor:'documentation'! |
21 |
||
38 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
70 | 25 |
All Rights Reserved |
38 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
32 | 36 |
documentation |
37 |
" |
|
125 | 38 |
a view for text which is known to be smalltalk code. |
419 | 39 |
It adds 'explain' to the menu, and defines another action: |
125 | 40 |
explainAction to be performed for explain. |
32 | 41 |
|
125 | 42 |
This action is to be defined by the user of this view |
917
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
43 |
(i.e. usually the owning browser) |
121 | 44 |
|
419 | 45 |
In addition, uncomment/comment are added to the controlMenu. |
46 |
These are smalltalk specific - if you plan to edit other language code, |
|
47 |
you need a different kind of CodeView for that. |
|
48 |
||
125 | 49 |
If used with a model, accept sends the changeMsg to it (as defined in EditTextView). |
419 | 50 |
(however, it is possible to define both changeMsg and acceptAction) |
123 | 51 |
|
419 | 52 |
See how doIt/printIt/inspectIt are handled in the superclass: Workspace. |
123 | 53 |
|
54 |
Caveat: |
|
419 | 55 |
in this version, CodeView does not yet support MVC setups for doIt |
56 |
and explain. |
|
57 |
If required, simulate this by setting the doItAction and |
|
58 |
explainAction, to notify the model manually about whats going on. |
|
583 | 59 |
|
917
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
60 |
[instance variables:] |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
61 |
commentStrings <Array> an array with 2 entries; |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
62 |
the first defining the EOL-comment string, |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
63 |
the 2nd (another array) defining opening |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
64 |
and closing comment strings. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
65 |
Default to ST/X comments, |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
66 |
can be changed in an instance for other |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
67 |
programming languages. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
68 |
|
583 | 69 |
[author:] |
70 |
Claus Gittinger |
|
71 |
||
72 |
[see also:] |
|
73 |
Workspace EditTextView TextView |
|
32 | 74 |
" |
201 | 75 |
! ! |
76 |
||
77 |
!CodeView methodsFor:'accessing'! |
|
78 |
||
918 | 79 |
commentStrings:anArrayOfCommentStrings |
80 |
"define the comment strings" |
|
81 |
||
82 |
commentStrings := anArrayOfCommentStrings |
|
83 |
||
84 |
"Created: 7.1.1997 / 20:25:06 / cg" |
|
85 |
! |
|
86 |
||
201 | 87 |
explainAction:aBlock |
88 |
"set the action to be performed on explain" |
|
89 |
||
90 |
explainAction := aBlock |
|
91 |
! ! |
|
92 |
||
93 |
!CodeView methodsFor:'editing'! |
|
94 |
||
95 |
commentFrom:line1 to:line2 |
|
96 |
"convenient function to comment out a block. |
|
97 |
All lines from line1 to line2 get an end-of-line comment |
|
98 |
in the first col." |
|
99 |
||
917
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
100 |
|eolComment opening closing| |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
101 |
|
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
102 |
eolComment := commentStrings at:1. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
103 |
eolComment isNil ifTrue:[ |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
104 |
opening := (commentStrings at:2) at:1. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
105 |
closing := (commentStrings at:2) at:2. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
106 |
(opening isNil or:[closing isNil]) ifTrue:[^ self]. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
107 |
]. |
201 | 108 |
|
917
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
109 |
line1 to:line2 do:[:lineNr | |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
110 |
|l| |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
111 |
|
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
112 |
l := self listAt:lineNr. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
113 |
l isNil ifTrue:[l := '']. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
114 |
eolComment notNil ifTrue:[ |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
115 |
l := eolComment , l |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
116 |
] ifFalse:[ |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
117 |
l := opening , l , closing |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
118 |
]. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
119 |
self at:lineNr put:l |
201 | 120 |
]. |
121 |
self textChanged. |
|
917
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
122 |
|
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
123 |
"Modified: 7.1.1997 / 20:15:06 / cg" |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
124 |
! |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
125 |
|
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
126 |
commentSelection |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
127 |
"convenient function to comment out a block. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
128 |
All lines from line1 to line2 get an end-of-line comment |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
129 |
in the first col." |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
130 |
|
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
131 |
|e commentPair opening closing| |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
132 |
|
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
133 |
selectionStartLine notNil ifTrue:[ |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
134 |
(selectionStartCol == 1 and:[selectionEndCol == 0]) ifTrue:[ |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
135 |
self commentFrom:selectionStartLine to:selectionEndLine-1 |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
136 |
] ifFalse:[ |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
137 |
commentPair := commentStrings at:2. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
138 |
opening := commentPair at:1. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
139 |
closing := commentPair at:2. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
140 |
(opening isNil or:[closing isNil]) ifTrue:[^ self]. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
141 |
|
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
142 |
e := selectionEndCol. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
143 |
|
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
144 |
self insertString:closing atLine:selectionEndLine col:e+1. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
145 |
self insertString:opening atLine:selectionStartLine col:selectionStartCol. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
146 |
|
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
147 |
selectionStartLine == selectionEndLine ifTrue:[e := e + opening size]. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
148 |
self selectFromLine:selectionStartLine col:selectionStartCol |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
149 |
toLine:selectionEndLine col:e+closing size. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
150 |
] |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
151 |
] |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
152 |
|
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
153 |
"Modified: 7.1.1997 / 20:13:25 / cg" |
201 | 154 |
! |
155 |
||
156 |
uncommentFrom:line1 to:line2 |
|
157 |
"convenient function to comment out a block. |
|
158 |
All lines from line1 to line2 get an end-of-line comment |
|
159 |
in the first col." |
|
160 |
||
917
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
161 |
|eolComment opening closing rest| |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
162 |
|
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
163 |
eolComment := commentStrings at:1. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
164 |
eolComment isNil ifTrue:[ |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
165 |
opening := (commentStrings at:2) at:1. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
166 |
closing := (commentStrings at:2) at:2. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
167 |
(opening isNil or:[closing isNil]) ifTrue:[^ self]. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
168 |
] ifFalse:[ |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
169 |
rest := eolComment size + 1. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
170 |
]. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
171 |
|
201 | 172 |
line1 to:line2 do:[:lineNr | |
917
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
173 |
|l| |
201 | 174 |
|
917
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
175 |
l := self listAt:lineNr. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
176 |
l notNil ifTrue:[ |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
177 |
eolComment notNil ifTrue:[ |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
178 |
(l startsWith:eolComment) ifTrue:[ |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
179 |
l := l copyFrom:rest |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
180 |
] |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
181 |
] ifFalse:[ |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
182 |
((l startsWith:opening) |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
183 |
and:[l endsWith:closing]) ifTrue:[ |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
184 |
l := l copyFrom:opening size + 1. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
185 |
l := l copyWithoutLast:closing size. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
186 |
] |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
187 |
]. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
188 |
self at:lineNr put:l |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
189 |
] |
201 | 190 |
]. |
191 |
self textChanged. |
|
917
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
192 |
|
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
193 |
"Modified: 7.1.1997 / 20:17:44 / cg" |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
194 |
! |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
195 |
|
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
196 |
uncommentSelection |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
197 |
"convenient function to comment out a block. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
198 |
All lines from line1 to line2 get an end-of-line comment |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
199 |
in the first col." |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
200 |
|
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
201 |
|e commentPair opening closing sz1 sz2| |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
202 |
|
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
203 |
selectionStartLine notNil ifTrue:[ |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
204 |
(selectionStartCol == 1 and:[selectionEndCol == 0]) ifTrue:[ |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
205 |
self uncommentFrom:selectionStartLine to:selectionEndLine-1 |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
206 |
] ifFalse:[ |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
207 |
commentPair := commentStrings at:2. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
208 |
opening := commentPair at:1. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
209 |
closing := commentPair at:2. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
210 |
(opening isNil or:[closing isNil]) ifTrue:[^ self]. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
211 |
|
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
212 |
sz1 := opening size. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
213 |
sz2 := closing size. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
214 |
|
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
215 |
((self |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
216 |
stringAtLine:selectionStartLine |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
217 |
from:selectionStartCol |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
218 |
to:selectionStartCol+sz1 - 1) = opening |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
219 |
and:[(self |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
220 |
stringAtLine:selectionEndLine |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
221 |
from:selectionEndCol - sz2 + 1 |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
222 |
to:selectionEndCol) = closing ]) ifTrue:[ |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
223 |
|
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
224 |
self deleteCharsAtLine:selectionEndLine fromCol:selectionEndCol-sz2+1 toCol:selectionEndCol. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
225 |
self deleteCharsAtLine:selectionStartLine fromCol:selectionStartCol toCol:selectionStartCol+sz1-1. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
226 |
|
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
227 |
e := selectionEndCol - sz2. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
228 |
selectionStartLine == selectionEndLine ifTrue:[e := e - sz1]. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
229 |
self selectFromLine:selectionStartLine col:selectionStartCol |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
230 |
toLine:selectionEndLine col:e. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
231 |
] |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
232 |
] |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
233 |
] |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
234 |
|
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
235 |
"Modified: 7.1.1997 / 20:13:32 / cg" |
201 | 236 |
! ! |
237 |
||
238 |
!CodeView methodsFor:'event handling'! |
|
239 |
||
240 |
keyPress:key x:x y:y |
|
241 |
"catch keyboard shortcuts" |
|
242 |
||
274
6df4bb990f04
handle accept where acceptAction is define (this was a historic leftover)
Claus Gittinger <cg@exept.de>
parents:
206
diff
changeset
|
243 |
<resource: #keyboard (#Explain #Help |
922 | 244 |
#CommentSelection #UncommentSelection)> |
201 | 245 |
|
246 |
(key == #Explain) ifTrue:[^ self explain]. |
|
247 |
(key == #Help) ifTrue:[^ self explain]. |
|
248 |
(key == #CommentSelection) ifTrue:[^ self commentSelection]. |
|
249 |
(key == #UncommentSelection) ifTrue:[^ self uncommentSelection]. |
|
250 |
||
251 |
super keyPress:key x:x y:y |
|
922 | 252 |
|
253 |
"Modified: 9.1.1997 / 12:14:00 / cg" |
|
32 | 254 |
! ! |
255 |
||
917
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
256 |
!CodeView methodsFor:'initialization'! |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
257 |
|
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
258 |
initialize |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
259 |
super initialize. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
260 |
|
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
261 |
commentStrings := #('"/' |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
262 |
('"' '"')) |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
263 |
|
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
264 |
"Created: 7.1.1997 / 19:47:13 / cg" |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
265 |
! ! |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
266 |
|
419 | 267 |
!CodeView methodsFor:'menu & menu actions'! |
268 |
||
269 |
accept |
|
270 |
"redefined accept action; |
|
271 |
save cursor and selection to allow restore in case of an error |
|
272 |
(we are typically compiling here ... and the compiler may show |
|
273 |
errors by highlighting them)" |
|
274 |
||
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
275 |
acceptEnabled == false ifTrue:[ |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
276 |
device beep. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
277 |
^ self |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
278 |
]. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
279 |
|
419 | 280 |
codeStartPosition := 1. |
281 |
[ |
|
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
282 |
AbortSignal handle:[:ex | |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
283 |
self cursor:Cursor normal. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
284 |
"redraw selection in normal color" |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
285 |
self selectFromLine:selectionStartLine col:selectionStartCol |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
286 |
toLine:selectionEndLine col:selectionEndCol. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
287 |
ex return |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
288 |
] do:[ |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
289 |
super accept. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
290 |
] |
419 | 291 |
] valueNowOrOnUnwindDo:[ |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
292 |
self unselect. |
419 | 293 |
] |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
294 |
|
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
295 |
"Modified: 7.3.1997 / 11:06:13 / cg" |
419 | 296 |
! |
297 |
||
97 | 298 |
editMenu |
121 | 299 |
"return the popUpMenu; |
300 |
to make this independent from what is defined in superclasses, |
|
301 |
get the superclass menu and add my functions." |
|
131 | 302 |
|
489 | 303 |
<resource: #keyboard (#CommentSelection #UncommentSelection |
304 |
#Accept #Explain)> |
|
1261
bdb18f73205c
resource flag: #menu -> #programMenu
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
305 |
<resource: #programMenu> |
489 | 306 |
|
464 | 307 |
|m sub| |
38 | 308 |
|
97 | 309 |
m := super editMenu. |
0 | 310 |
|
131 | 311 |
self sensor ctrlDown ifTrue:[ |
430 | 312 |
m addLabels:(resources array:#('-' 'commentIt' 'uncommentIt')) |
313 |
selectors:#(nil commentSelection uncommentSelection) |
|
314 |
accelerators:#(nil CommentSelection UncommentSelection) |
|
464 | 315 |
after:#again. |
430 | 316 |
|
317 |
self hasSelection ifFalse:[ |
|
318 |
m disableAll:#(commentSelection uncommentSelection) |
|
319 |
]. |
|
131 | 320 |
] ifFalse:[ |
38 | 321 |
|
430 | 322 |
" |
323 |
codeViews do support #accept |
|
324 |
... add it after #inspectIt |
|
325 |
" |
|
464 | 326 |
m addLabels:(resources array:#('-' 'accept')) |
327 |
selectors:#(nil accept) |
|
328 |
accelerators:#(nil #Accept) |
|
329 |
after:#inspectIt. |
|
131 | 330 |
|
1293
c0806b73dc48
disable accept menuItem, if there is no acceptAction
Claus Gittinger <cg@exept.de>
parents:
1261
diff
changeset
|
331 |
(acceptEnabled == false |
c0806b73dc48
disable accept menuItem, if there is no acceptAction
Claus Gittinger <cg@exept.de>
parents:
1261
diff
changeset
|
332 |
or:[acceptAction isNil]) ifTrue:[ |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
333 |
m disable:#accept |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
334 |
]. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
335 |
|
430 | 336 |
" |
337 |
and add #explain after $gotoLine in the extra menu |
|
338 |
" |
|
339 |
sub := m subMenuAt:#others. |
|
340 |
sub notNil ifTrue:[ |
|
341 |
sub addLabels:(resources array:#('-' 'explain')) |
|
342 |
selectors:#(nil explain) |
|
343 |
accelerators:#(nil Explain) |
|
464 | 344 |
after:#gotoLine. |
430 | 345 |
|
346 |
self hasSelection ifFalse:[ |
|
347 |
sub disable:#explain |
|
348 |
]. |
|
349 |
]. |
|
59 | 350 |
]. |
131 | 351 |
^ m. |
430 | 352 |
|
1293
c0806b73dc48
disable accept menuItem, if there is no acceptAction
Claus Gittinger <cg@exept.de>
parents:
1261
diff
changeset
|
353 |
"Modified: 1.8.1997 / 21:47:55 / cg" |
136 | 354 |
! |
355 |
||
201 | 356 |
explain |
357 |
"explain action; |
|
358 |
evaluate the explainBlock passing whole contents and |
|
359 |
selection as arguments." |
|
360 |
||
361 |
|text| |
|
362 |
||
363 |
explainAction notNil ifTrue:[ |
|
364 |
text := self selection. |
|
365 |
text notNil ifTrue:[ |
|
366 |
explainAction value:(self contents) value:(text asString) |
|
367 |
] |
|
368 |
] |
|
0 | 369 |
! ! |
370 |
||
206 | 371 |
!CodeView class methodsFor:'documentation'! |
372 |
||
373 |
version |
|
1293
c0806b73dc48
disable accept menuItem, if there is no acceptAction
Claus Gittinger <cg@exept.de>
parents:
1261
diff
changeset
|
374 |
^ '$Header: /cvs/stx/stx/libwidg/CodeView.st,v 1.37 1997-08-01 19:48:27 cg Exp $' |
206 | 375 |
! ! |