74 " |
74 " |
75 ! ! |
75 ! ! |
76 |
76 |
77 !CodeView methodsFor:'accessing'! |
77 !CodeView methodsFor:'accessing'! |
78 |
78 |
79 commentStrings:anArrayOfCommentStrings |
|
80 "define the comment strings" |
|
81 |
|
82 commentStrings := anArrayOfCommentStrings |
|
83 |
|
84 "Created: 7.1.1997 / 20:25:06 / cg" |
|
85 ! |
|
86 |
|
87 explainAction:aBlock |
79 explainAction:aBlock |
88 "set the action to be performed on explain" |
80 "set the action to be performed on explain" |
89 |
81 |
90 explainAction := aBlock |
82 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 |
|
100 |eolComment opening closing| |
|
101 |
|
102 eolComment := commentStrings at:1. |
|
103 eolComment isNil ifTrue:[ |
|
104 opening := (commentStrings at:2) at:1. |
|
105 closing := (commentStrings at:2) at:2. |
|
106 (opening isNil or:[closing isNil]) ifTrue:[^ self]. |
|
107 ]. |
|
108 |
|
109 line1 to:line2 do:[:lineNr | |
|
110 |l| |
|
111 |
|
112 l := self listAt:lineNr. |
|
113 l isNil ifTrue:[l := '']. |
|
114 eolComment notNil ifTrue:[ |
|
115 l := eolComment , l |
|
116 ] ifFalse:[ |
|
117 l := opening , l , closing |
|
118 ]. |
|
119 self at:lineNr put:l |
|
120 ]. |
|
121 self textChanged. |
|
122 |
|
123 "Modified: 7.1.1997 / 20:15:06 / cg" |
|
124 ! |
|
125 |
|
126 commentSelection |
|
127 "convenient function to comment out a block. |
|
128 All lines from line1 to line2 get an end-of-line comment |
|
129 in the first col." |
|
130 |
|
131 |e commentPair opening closing| |
|
132 |
|
133 selectionStartLine notNil ifTrue:[ |
|
134 (selectionStartCol == 1 and:[selectionEndCol == 0]) ifTrue:[ |
|
135 self commentFrom:selectionStartLine to:selectionEndLine-1 |
|
136 ] ifFalse:[ |
|
137 commentPair := commentStrings at:2. |
|
138 opening := commentPair at:1. |
|
139 closing := commentPair at:2. |
|
140 (opening isNil or:[closing isNil]) ifTrue:[^ self]. |
|
141 |
|
142 e := selectionEndCol. |
|
143 |
|
144 self insertString:closing atLine:selectionEndLine col:e+1. |
|
145 self insertString:opening atLine:selectionStartLine col:selectionStartCol. |
|
146 |
|
147 selectionStartLine == selectionEndLine ifTrue:[e := e + opening size]. |
|
148 self selectFromLine:selectionStartLine col:selectionStartCol |
|
149 toLine:selectionEndLine col:e+closing size. |
|
150 ] |
|
151 ] |
|
152 |
|
153 "Modified: 7.1.1997 / 20:13:25 / cg" |
|
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 |
|
161 |eolComment opening closing rest| |
|
162 |
|
163 eolComment := commentStrings at:1. |
|
164 eolComment isNil ifTrue:[ |
|
165 opening := (commentStrings at:2) at:1. |
|
166 closing := (commentStrings at:2) at:2. |
|
167 (opening isNil or:[closing isNil]) ifTrue:[^ self]. |
|
168 ] ifFalse:[ |
|
169 rest := eolComment size + 1. |
|
170 ]. |
|
171 |
|
172 line1 to:line2 do:[:lineNr | |
|
173 |l| |
|
174 |
|
175 l := self listAt:lineNr. |
|
176 l notNil ifTrue:[ |
|
177 eolComment notNil ifTrue:[ |
|
178 (l startsWith:eolComment) ifTrue:[ |
|
179 l := l copyFrom:rest |
|
180 ] |
|
181 ] ifFalse:[ |
|
182 ((l startsWith:opening) |
|
183 and:[l endsWith:closing]) ifTrue:[ |
|
184 l := l copyFrom:opening size + 1. |
|
185 l := l copyWithoutLast:closing size. |
|
186 ] |
|
187 ]. |
|
188 self at:lineNr put:l |
|
189 ] |
|
190 ]. |
|
191 self textChanged. |
|
192 |
|
193 "Modified: 7.1.1997 / 20:17:44 / cg" |
|
194 ! |
|
195 |
|
196 uncommentSelection |
|
197 "convenient function to comment out a block. |
|
198 All lines from line1 to line2 get an end-of-line comment |
|
199 in the first col." |
|
200 |
|
201 |e commentPair opening closing sz1 sz2| |
|
202 |
|
203 selectionStartLine notNil ifTrue:[ |
|
204 (selectionStartCol == 1 and:[selectionEndCol == 0]) ifTrue:[ |
|
205 self uncommentFrom:selectionStartLine to:selectionEndLine-1 |
|
206 ] ifFalse:[ |
|
207 commentPair := commentStrings at:2. |
|
208 opening := commentPair at:1. |
|
209 closing := commentPair at:2. |
|
210 (opening isNil or:[closing isNil]) ifTrue:[^ self]. |
|
211 |
|
212 sz1 := opening size. |
|
213 sz2 := closing size. |
|
214 |
|
215 ((self |
|
216 stringAtLine:selectionStartLine |
|
217 from:selectionStartCol |
|
218 to:selectionStartCol+sz1 - 1) = opening |
|
219 and:[(self |
|
220 stringAtLine:selectionEndLine |
|
221 from:selectionEndCol - sz2 + 1 |
|
222 to:selectionEndCol) = closing ]) ifTrue:[ |
|
223 |
|
224 self deleteCharsAtLine:selectionEndLine fromCol:selectionEndCol-sz2+1 toCol:selectionEndCol. |
|
225 self deleteCharsAtLine:selectionStartLine fromCol:selectionStartCol toCol:selectionStartCol+sz1-1. |
|
226 |
|
227 e := selectionEndCol - sz2. |
|
228 selectionStartLine == selectionEndLine ifTrue:[e := e - sz1]. |
|
229 self selectFromLine:selectionStartLine col:selectionStartCol |
|
230 toLine:selectionEndLine col:e. |
|
231 ] |
|
232 ] |
|
233 ] |
|
234 |
|
235 "Modified: 7.1.1997 / 20:13:32 / cg" |
|
236 ! ! |
83 ! ! |
237 |
84 |
238 !CodeView methodsFor:'event handling'! |
85 !CodeView methodsFor:'event handling'! |
239 |
86 |
240 keyPress:key x:x y:y |
87 keyPress:key x:x y:y |