author | Claus Gittinger <cg@exept.de> |
Sun, 21 Aug 2011 12:23:54 +0200 | |
changeset 10631 | 7639ba8f13da |
parent 10588 | 6b026f496040 |
child 10651 | 7ab02ade36e2 |
permissions | -rw-r--r-- |
9979 | 1 |
" |
10076 | 2 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague |
3 |
All Rights Reserved |
|
9979 | 4 |
|
10076 | 5 |
Permission is hereby granted, free of charge, to any person |
6 |
obtaining a copy of this software and associated documentation |
|
7 |
files (the 'Software'), to deal in the Software without |
|
8 |
restriction, including without limitation the rights to use, |
|
9 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
10 |
copies of the Software, and to permit persons to whom the |
|
11 |
Software is furnished to do so, subject to the following |
|
12 |
conditions: |
|
13 |
||
14 |
The above copyright notice and this permission notice shall be |
|
15 |
included in all copies or substantial portions of the Software. |
|
16 |
||
17 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
18 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
19 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
20 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
21 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
22 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
23 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
24 |
OTHER DEALINGS IN THE SOFTWARE. |
|
9979 | 25 |
" |
26 |
"{ Package: 'stx:libtool' }" |
|
27 |
||
28 |
"{ NameSpace: Tools }" |
|
29 |
||
30 |
CodeViewService subclass:#CodeNavigationService |
|
10361 | 31 |
instanceVariableNames:'selectorEmphasis variableEmphasis currentEmphasis linesToRedraw' |
10631 | 32 |
classVariableNames:'DefaultVariableEmphasis DefaultSelectorEmphasis' |
9979 | 33 |
poolDictionaries:'' |
34 |
category:'Interface-CodeView' |
|
35 |
! |
|
36 |
||
37 |
!CodeNavigationService class methodsFor:'documentation'! |
|
38 |
||
39 |
copyright |
|
40 |
" |
|
10076 | 41 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague |
42 |
All Rights Reserved |
|
43 |
||
44 |
Permission is hereby granted, free of charge, to any person |
|
45 |
obtaining a copy of this software and associated documentation |
|
46 |
files (the 'Software'), to deal in the Software without |
|
47 |
restriction, including without limitation the rights to use, |
|
48 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
49 |
copies of the Software, and to permit persons to whom the |
|
50 |
Software is furnished to do so, subject to the following |
|
51 |
conditions: |
|
9979 | 52 |
|
10076 | 53 |
The above copyright notice and this permission notice shall be |
54 |
included in all copies or substantial portions of the Software. |
|
55 |
||
56 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
57 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
58 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
59 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
60 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
61 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
62 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
63 |
OTHER DEALINGS IN THE SOFTWARE. |
|
9979 | 64 |
" |
65 |
! ! |
|
66 |
||
67 |
!CodeNavigationService class methodsFor:'accessing'! |
|
68 |
||
69 |
label |
|
70 |
||
71 |
"Answers short label - for UI" |
|
72 |
||
73 |
^'Semi-modal Code Navigation' |
|
74 |
||
75 |
"Created: / 07-03-2010 / 14:00:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10412 | 76 |
! |
77 |
||
78 |
requiredServices |
|
79 |
||
80 |
^#(#'Tools::CodeHighlightingService') |
|
81 |
||
82 |
"Created: / 27-07-2011 / 11:40:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
9979 | 83 |
! ! |
84 |
||
85 |
!CodeNavigationService class methodsFor:'accessing - defaults'! |
|
86 |
||
87 |
defaultSelectorEmphasis |
|
10631 | 88 |
DefaultSelectorEmphasis isNil ifTrue:[ |
89 |
DefaultSelectorEmphasis := |
|
90 |
Array with:(#backgroundColor -> (Color rgbValue:16rDBEEFF)) |
|
91 |
]. |
|
92 |
^ DefaultSelectorEmphasis |
|
93 |
||
94 |
"Modified: / 21-08-2011 / 09:58:18 / cg" |
|
9979 | 95 |
! |
96 |
||
97 |
defaultVariableEmphasis |
|
10631 | 98 |
DefaultVariableEmphasis isNil ifTrue:[ |
99 |
DefaultVariableEmphasis := Array with:(#backgroundColor -> (Color gray: 90)) |
|
100 |
]. |
|
101 |
^ DefaultVariableEmphasis |
|
9979 | 102 |
|
103 |
"Created: / 25-06-2010 / 13:56:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10631 | 104 |
"Modified: / 21-08-2011 / 11:04:20 / cg" |
9979 | 105 |
! ! |
106 |
||
107 |
!CodeNavigationService methodsFor:'code services'! |
|
108 |
||
10631 | 109 |
browseClass:class |
110 |
self browser isNil ifTrue:[ ^ NewSystemBrowser browseClass:class ]. |
|
9979 | 111 |
(UserPreferences current alwaysOpenNewTabWhenCtrlClick |
10631 | 112 |
or:[ self browser navigationState modified ]) |
113 |
ifTrue:[ |
|
114 |
self browser |
|
115 |
spawnFullBrowserInClass:class |
|
116 |
selector:nil |
|
117 |
in:#newBuffer |
|
118 |
] |
|
119 |
ifFalse:[ self browser switchToClass:class ] |
|
9979 | 120 |
|
121 |
"Created: / 15-02-2010 / 09:36:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
122 |
"Modified: / 25-07-2010 / 11:00:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10631 | 123 |
"Modified: / 21-08-2011 / 10:07:30 / cg" |
9979 | 124 |
! |
125 |
||
126 |
browser |
|
127 |
||
128 |
^codeView browserHolder value |
|
129 |
||
130 |
"Created: / 06-03-2010 / 21:14:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
131 |
! ! |
|
132 |
||
133 |
!CodeNavigationService methodsFor:'event handling'! |
|
134 |
||
135 |
button1Press |
|
136 |
||
137 |
codeView syntaxElementSelection ifNil:[^self]. |
|
138 |
||
139 |
codeView syntaxElementSelection type == #selector ifTrue:[^self button1PressForSelector: codeView syntaxElementSelection value]. |
|
140 |
codeView syntaxElementSelection type == #class ifTrue:[^self browseClass:codeView syntaxElementSelection value]. |
|
141 |
||
142 |
"Created: / 14-02-2010 / 18:43:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
143 |
"Modified: / 06-03-2010 / 21:11:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
144 |
! |
|
145 |
||
146 |
button1PressForSelector: selector |
|
147 |
||
148 |
| impls menu | |
|
10254 | 149 |
impls := codeView implementorsOf: selector. |
10631 | 150 |
"/ impls size = 1 ifTrue:[^codeView browseMethod: impls anyOne]. |
10254 | 151 |
menu := codeView implementorsMenu: impls selector: selector. |
9979 | 152 |
self highlightClear. |
153 |
menu showAtPointer. |
|
154 |
||
155 |
"Created: / 14-02-2010 / 18:50:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10254 | 156 |
"Modified: / 30-06-2011 / 19:34:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10271 | 157 |
"Modified: / 07-07-2011 / 17:16:23 / jv" |
10631 | 158 |
"Modified: / 21-08-2011 / 11:06:08 / cg" |
9979 | 159 |
! |
160 |
||
161 |
button2Press |
|
162 |
||
163 |
| sel | |
|
164 |
sel := codeView syntaxElementSelection. |
|
165 |
(sel notNil and:[sel type == #selector]) ifTrue:[^self button2PressForSelector: sel value]. |
|
166 |
||
167 |
"Created: / 14-02-2010 / 18:43:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
168 |
"Modified: / 17-06-2011 / 08:58:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
169 |
! |
|
170 |
||
171 |
button2PressForSelector: selector |
|
172 |
||
173 |
| senders menu | |
|
10631 | 174 |
senders := codeView sendersOf: selector. |
175 |
"/ senders size = 1 ifTrue:[ codeView browseMethod: senders anyOne. ^ self]. |
|
10254 | 176 |
menu := codeView sendersMenu: senders selector: selector. |
9979 | 177 |
self highlightClear. |
178 |
menu showAtPointer. |
|
179 |
||
180 |
"Created: / 14-02-2010 / 18:50:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10254 | 181 |
"Modified: / 30-06-2011 / 19:34:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10631 | 182 |
"Modified: / 21-08-2011 / 11:34:49 / cg" |
9979 | 183 |
! |
184 |
||
10631 | 185 |
buttonMotion:button x:x y:y in:view |
9979 | 186 |
"Handles an event in given view (a subview of codeView). |
187 |
If the method returns true, the event will not be processed |
|
188 |
by the view." |
|
10631 | 189 |
|
190 |
(view == textView and:[ textView sensor ctrlDown ]) ifTrue:[ |
|
191 |
self highlightElementAtX:x y:y. |
|
192 |
^ true |
|
193 |
]. |
|
194 |
^ false |
|
9979 | 195 |
|
196 |
"Created: / 06-03-2010 / 20:40:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10631 | 197 |
"Modified (format): / 21-08-2011 / 10:07:15 / cg" |
9979 | 198 |
! |
199 |
||
200 |
buttonPress: button x:x y:y in: view |
|
201 |
||
202 |
"Handles an event in given view (a subview of codeView). |
|
203 |
If the method returns true, the event will not be processed |
|
204 |
by the view." |
|
205 |
||
10631 | 206 |
(view == textView) ifTrue:[ |
207 |
codeView sensor ctrlDown ifTrue:[ |
|
208 |
button == 1 ifTrue: [self button1Press.^true]. |
|
9979 | 209 |
button == #paste ifTrue: [self button2Press.^true]. |
10631 | 210 |
button == 2 ifTrue: [self button2Press.^true] |
211 |
]. |
|
9979 | 212 |
button == 1 ifTrue:[ |
213 |
self highlightVariableAtX:x y:y. |
|
214 |
] |
|
10631 | 215 |
]. |
9979 | 216 |
^false |
217 |
||
218 |
"Created: / 06-03-2010 / 21:12:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
219 |
"Modified: / 25-06-2010 / 14:53:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10631 | 220 |
"Modified (format): / 21-08-2011 / 10:06:54 / cg" |
9979 | 221 |
! |
222 |
||
223 |
keyPress:key x:x y:y in:view |
|
224 |
"Handles an event in given view (a subview of codeView). |
|
10588 | 225 |
If the method returns true, it has eaten the event and it will not be processed |
9979 | 226 |
by the view." |
10588 | 227 |
|
10631 | 228 |
|ev p| |
229 |
||
9979 | 230 |
(view == textView) ifTrue:[ |
231 |
(key == #'Control_L' or:[ key == #Ctrl ]) ifTrue:[ |
|
10631 | 232 |
"/ because it is delegated, the position is not correct |
233 |
ev := WindowGroup lastEventQuerySignal query. |
|
234 |
p := view device translatePoint:(ev x @ ev y) fromView:ev view toView:view. |
|
235 |
view sensor pushUserEvent:#highlightElementAtX:y: for:self withArguments:{p x. p y.}. |
|
10588 | 236 |
^ true. |
9979 | 237 |
]. |
10588 | 238 |
view sensor pushUserEvent:#highlightVariableAtCursor for:self . |
9979 | 239 |
]. |
240 |
^ false |
|
241 |
||
242 |
"Created: / 06-03-2010 / 20:50:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10361 | 243 |
"Modified: / 20-07-2011 / 18:49:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10631 | 244 |
"Modified: / 21-08-2011 / 11:33:16 / cg" |
9979 | 245 |
! |
246 |
||
247 |
keyRelease: key x:x y:y in: view |
|
248 |
"Handles an event in given view (a subview of codeView). |
|
10588 | 249 |
If the method returns true, it has eaten the event and it will not be processed |
9979 | 250 |
by the view." |
251 |
||
10631 | 252 |
|ev p| |
253 |
||
10588 | 254 |
(view == textView and:[key == #'Control_L' or:[key == #Ctrl]]) ifTrue:[ |
10631 | 255 |
"/ because it is delegated, the position is not correct |
256 |
ev := WindowGroup lastEventQuerySignal query. |
|
257 |
p := view device translatePoint:(ev x @ ev y) fromView:ev view toView:view. |
|
258 |
self highlightClear. |
|
259 |
"/ view sensor pushUserEvent:#highlightClear for:self. |
|
10588 | 260 |
^ true |
261 |
]. |
|
262 |
^ false |
|
9979 | 263 |
|
264 |
"Created: / 06-03-2010 / 21:03:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10631 | 265 |
"Modified: / 21-08-2011 / 11:32:40 / cg" |
9979 | 266 |
! ! |
267 |
||
268 |
!CodeNavigationService methodsFor:'initialization'! |
|
269 |
||
270 |
initialize |
|
271 |
||
272 |
super initialize. |
|
273 |
selectorEmphasis := self class defaultSelectorEmphasis. |
|
274 |
variableEmphasis := self class defaultVariableEmphasis. |
|
10361 | 275 |
linesToRedraw := OrderedCollection new. |
9979 | 276 |
|
277 |
"Created: / 25-06-2010 / 14:05:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
278 |
! ! |
|
279 |
||
280 |
!CodeNavigationService methodsFor:'private'! |
|
281 |
||
282 |
elementAtCursor |
|
283 |
^self elementAtLine: textView cursorLine col: textView cursorCol - 1 |
|
284 |
||
285 |
"Created: / 25-06-2010 / 14:39:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
286 |
! |
|
287 |
||
10631 | 288 |
elementAtLine:line col:colArg |
289 |
|characterPosition index element col| |
|
290 |
||
291 |
"/ if beyond end of line, do not advance into next line |
|
292 |
col := colArg min:(textView listAt:line) size. |
|
9979 | 293 |
|
294 |
characterPosition := textView characterPositionOfLine:line col:col. |
|
295 |
index := SortedCollection binarySearch: (codeView syntaxElements) forIndexOf: characterPosition. |
|
296 |
index > (codeView syntaxElements) size ifTrue:[^nil]. |
|
10631 | 297 |
element := (codeView syntaxElements) at:index ifAbsent:nil. |
298 |
element notNil ifTrue:[ |
|
299 |
(characterPosition between: element start and: element stop) ifTrue:[^element]. |
|
300 |
]. |
|
301 |
^nil |
|
9979 | 302 |
|
303 |
"Created: / 25-06-2010 / 14:40:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10631 | 304 |
"Modified: / 21-08-2011 / 11:03:29 / cg" |
9979 | 305 |
! |
306 |
||
307 |
elementAtX:x y:y |
|
308 |
|visibleLine line col| |
|
309 |
||
10631 | 310 |
codeView syntaxElements isNil ifTrue:[^nil]. |
311 |
||
9979 | 312 |
visibleLine := textView visibleLineOfY:y. |
313 |
col := textView colOfX:x inVisibleLine:visibleLine. |
|
314 |
line := textView visibleLineToAbsoluteLine:visibleLine. |
|
315 |
^self elementAtLine:line col:col |
|
316 |
||
317 |
"Created: / 25-06-2010 / 14:52:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
318 |
"Modified: / 01-08-2010 / 08:50:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10631 | 319 |
"Modified: / 21-08-2011 / 10:26:08 / cg" |
320 |
! |
|
321 |
||
322 |
foo |
|
323 |
|characterPosition index element | |
|
324 |
||
325 |
characterPosition := 1 |
|
326 |
||
327 |
"Created: / 21-08-2011 / 10:48:05 / cg" |
|
9979 | 328 |
! |
329 |
||
330 |
highlighEmphasisFor: element |
|
331 |
||
332 |
element ifNil:[^nil]. |
|
333 |
||
10631 | 334 |
element isSelector ifTrue:[^selectorEmphasis]. |
335 |
element isVariable ifTrue:[^variableEmphasis]. |
|
336 |
element isSelf ifTrue:[^variableEmphasis]. |
|
9979 | 337 |
|
338 |
^nil |
|
339 |
||
340 |
"Created: / 25-06-2010 / 13:54:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10631 | 341 |
"Modified: / 21-08-2011 / 09:42:37 / cg" |
9979 | 342 |
! |
343 |
||
344 |
highlightClear |
|
345 |
||
10361 | 346 |
^self highlightClear: true. |
9979 | 347 |
|
348 |
"Modified: / 26-12-2007 / 12:28:05 / janfrog" |
|
349 |
"Created: / 25-06-2010 / 14:15:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10276 | 350 |
"Modified: / 08-07-2011 / 08:50:45 / cg" |
10361 | 351 |
"Modified: / 20-07-2011 / 18:52:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
9979 | 352 |
! |
353 |
||
10361 | 354 |
highlightClear: redraw |
355 |
||
356 |
codeView syntaxElementSelection == nil ifTrue:[ ^ self ]. |
|
357 |
textView list ifNil:[ ^ self ]. |
|
358 |
textView list withIndexDo:[:line :lineNo | |
|
359 |
line isText ifTrue:[ |
|
360 |
(line hasEmphasis: currentEmphasis) ifTrue:[ |
|
361 |
line emphasisAllRemove:currentEmphasis. |
|
362 |
linesToRedraw add: lineNo. |
|
363 |
] |
|
364 |
] |
|
365 |
]. |
|
366 |
codeView syntaxElementSelection:nil. |
|
367 |
||
368 |
redraw ifTrue:[self redrawLines]. |
|
9979 | 369 |
|
10361 | 370 |
"Modified: / 26-12-2007 / 12:28:05 / janfrog" |
371 |
"Created: / 20-07-2011 / 18:52:19 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10631 | 372 |
"Modified: / 21-08-2011 / 10:15:15 / cg" |
10361 | 373 |
! |
374 |
||
375 |
highlightElement:element |
|
10631 | 376 |
|e| |
377 |
||
378 |
codeView syntaxElementSelection == element ifTrue:[ ^ self ]. "/ no change |
|
379 |
codeView syntaxElementSelection notNil ifTrue:[ |
|
380 |
self highlightClear: false. |
|
381 |
]. |
|
10361 | 382 |
|
10631 | 383 |
currentEmphasis := self highlighEmphasisFor:element. |
384 |
element notNil ifTrue:[ |
|
385 |
codeView syntaxElementSelection:element. |
|
386 |
e := element firstElementInChain. |
|
387 |
[ e notNil ] whileTrue:[ |
|
388 |
self highlightWithoutClearFrom:e start to:e stop. |
|
389 |
e := e nextElement |
|
390 |
]. |
|
391 |
]. |
|
10361 | 392 |
self redrawLines. |
9979 | 393 |
|
394 |
"Created: / 14-02-2010 / 16:18:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10361 | 395 |
"Modified: / 20-07-2011 / 18:52:46 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10631 | 396 |
"Modified: / 21-08-2011 / 10:22:58 / cg" |
9979 | 397 |
! |
398 |
||
399 |
highlightElementAtCursor |
|
400 |
self highlightElementAtLine: textView cursorLine col: textView cursorCol |
|
401 |
||
402 |
"Created: / 14-02-2010 / 16:17:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
403 |
"Modified: / 06-03-2010 / 19:59:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
404 |
! |
|
405 |
||
406 |
highlightElementAtLine:line col:col |
|
407 |
|characterPosition index element | |
|
408 |
||
409 |
||
410 |
characterPosition := textView characterPositionOfLine:line col:col. |
|
411 |
index := SortedCollection binarySearch: (codeView syntaxElements) forIndexOf: characterPosition. |
|
412 |
index > (codeView syntaxElements) size ifTrue:[^self highlightElement: nil]. |
|
413 |
element := (codeView syntaxElements) at: index. |
|
414 |
(characterPosition between: element start and: element stop) ifFalse:[^self highlightElement: nil]. |
|
415 |
self highlightElement:element |
|
416 |
||
417 |
"Created: / 14-02-2010 / 16:17:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
418 |
"Modified: / 01-08-2010 / 08:50:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
419 |
! |
|
420 |
||
421 |
highlightElementAtX:x y:y |
|
422 |
|visibleLine line col| |
|
423 |
||
10631 | 424 |
codeView syntaxElements isNil ifTrue:[^self]. |
9979 | 425 |
visibleLine := textView visibleLineOfY:y. |
426 |
col := textView colOfX:x inVisibleLine:visibleLine. |
|
427 |
line := textView visibleLineToAbsoluteLine:visibleLine. |
|
428 |
self highlightElementAtLine:line col:col |
|
429 |
||
430 |
"Created: / 14-02-2010 / 16:12:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
431 |
"Modified: / 06-03-2010 / 20:06:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10631 | 432 |
"Modified: / 21-08-2011 / 10:22:10 / cg" |
433 |
! |
|
434 |
||
435 |
highlightElementOrNil:e |
|
436 |
e notNil ifTrue:[ |
|
437 |
"/ cg: only if selected !! |
|
438 |
"/ self halt. |
|
439 |
self highlightElement:e. |
|
440 |
] ifFalse:[ |
|
441 |
self highlightClear |
|
442 |
]. |
|
443 |
||
444 |
"Created: / 25-06-2010 / 14:52:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
445 |
"Created: / 21-08-2011 / 09:56:39 / cg" |
|
9979 | 446 |
! |
447 |
||
448 |
highlightLine:lineNo fromLine:startLine col:endLine toLine:startCol col:endCol |
|
449 |
|line start end| |
|
450 |
||
451 |
(lineNo between:startLine and:endLine) ifFalse:[ |
|
452 |
^ self |
|
453 |
]. |
|
454 |
line := textView listAt:lineNo. |
|
10291
af5825474e18
changed: #highlightLine:fromLine:col:toLine:col:
Claus Gittinger <cg@exept.de>
parents:
10276
diff
changeset
|
455 |
line isEmpty ifTrue:[^self]. |
9979 | 456 |
start := lineNo = startLine ifTrue:[ |
457 |
startCol |
|
458 |
] ifFalse:[ |
|
459 |
line indexOfNonSeparator |
|
460 |
]. |
|
461 |
end := lineNo = endLine ifTrue:[ |
|
462 |
endCol |
|
463 |
] ifFalse:[ line size ]. |
|
464 |
line |
|
10291
af5825474e18
changed: #highlightLine:fromLine:col:toLine:col:
Claus Gittinger <cg@exept.de>
parents:
10276
diff
changeset
|
465 |
emphasisFrom:(start max: 1) |
af5825474e18
changed: #highlightLine:fromLine:col:toLine:col:
Claus Gittinger <cg@exept.de>
parents:
10276
diff
changeset
|
466 |
to:(end min: line size) |
10361 | 467 |
add: currentEmphasis. |
468 |
linesToRedraw add: lineNo. |
|
9979 | 469 |
|
470 |
"Created: / 25-06-2010 / 14:15:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10291
af5825474e18
changed: #highlightLine:fromLine:col:toLine:col:
Claus Gittinger <cg@exept.de>
parents:
10276
diff
changeset
|
471 |
"Modified: / 08-07-2011 / 13:02:51 / cg" |
10361 | 472 |
"Modified: / 20-07-2011 / 18:43:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
9979 | 473 |
! |
474 |
||
475 |
highlightVariable:e |
|
10631 | 476 |
(e notNil and:[ e isVariableOrSelf ]) ifTrue:[ |
9979 | 477 |
self highlightElement:e. |
478 |
] ifFalse:[ |
|
479 |
self highlightClear. |
|
10361 | 480 |
]. |
481 |
||
482 |
"Modified: / 20-07-2011 / 18:54:44 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10631 | 483 |
"Modified: / 21-08-2011 / 09:39:42 / cg" |
9979 | 484 |
! |
485 |
||
486 |
highlightVariableAtCursor |
|
10631 | 487 |
self highlightElementOrNil:(self elementAtCursor) |
9979 | 488 |
|
489 |
"Modified: / 25-06-2010 / 14:53:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10631 | 490 |
"Modified: / 21-08-2011 / 09:56:56 / cg" |
9979 | 491 |
! |
492 |
||
493 |
highlightVariableAtX:x y:y |
|
10631 | 494 |
self highlightElementOrNil:(self elementAtX:x y:y). |
9979 | 495 |
|
496 |
"Created: / 25-06-2010 / 14:52:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10631 | 497 |
"Modified: / 21-08-2011 / 10:24:50 / cg" |
9979 | 498 |
! |
499 |
||
500 |
highlightWithoutClearFrom: start to: end |
|
501 |
"Remove underlined emphasis" |
|
502 |
||
503 |
|startLine startCol endLine endCol| |
|
504 |
||
505 |
startLine := textView lineOfCharacterPosition:start. |
|
506 |
startCol := start - (textView characterPositionOfLine:startLine col:1) + 1. |
|
507 |
endLine := textView lineOfCharacterPosition:end. |
|
508 |
endCol := end - (textView characterPositionOfLine:endLine col:1) + 1. |
|
509 |
self highlightWithoutClearFromLine: startLine col: startCol toLine: endLine col: endCol |
|
510 |
||
511 |
"Created: / 25-06-2010 / 14:15:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
512 |
! |
|
513 |
||
514 |
highlightWithoutClearFromLine: startLine col: startCol toLine: endLine col: endCol |
|
515 |
||
516 |
textView list keysAndValuesDo: |
|
517 |
[:lineNo :line| |
|
518 |
|start end| |
|
519 |
line isText ifTrue: |
|
520 |
[self highlightLine: lineNo fromLine: startLine col: endLine toLine: startCol col: endCol]]. |
|
521 |
||
522 |
"Created: / 25-06-2010 / 14:15:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
523 |
! ! |
|
524 |
||
10361 | 525 |
!CodeNavigationService methodsFor:'redrawing'! |
526 |
||
527 |
redrawLines |
|
528 |
linesToRedraw do:[:lineNo| |
|
10588 | 529 |
textView invalidateLine: lineNo. |
10361 | 530 |
]. |
531 |
linesToRedraw := OrderedCollection new: 1 |
|
532 |
||
533 |
"Created: / 20-07-2011 / 18:45:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10588 | 534 |
"Modified (format): / 18-08-2011 / 16:01:34 / cg" |
10361 | 535 |
! ! |
536 |
||
9979 | 537 |
!CodeNavigationService class methodsFor:'documentation'! |
538 |
||
539 |
version_CVS |
|
10631 | 540 |
^ '$Header: /cvs/stx/stx/libtool/Tools__CodeNavigationService.st,v 1.10 2011-08-21 10:23:54 cg Exp $' |
9979 | 541 |
! |
542 |
||
543 |
version_SVN |
|
544 |
^ '§Id: Tools__CodeNavigationService.st 7788 2011-06-17 07:57:48Z vranyj1 §' |
|
545 |
! ! |