author | Claus Gittinger <cg@exept.de> |
Mon, 22 Aug 2011 16:33:28 +0200 | |
changeset 10651 | 7ab02ade36e2 |
parent 10631 | 7639ba8f13da |
child 10653 | 0f30edd43161 |
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 |
||
10651 | 107 |
!CodeNavigationService methodsFor:'change & update'! |
108 |
||
109 |
update: aspect with: param from: sender |
|
110 |
sender == textView modifiedChannel ifTrue:[self halt.]. |
|
111 |
||
112 |
"Created: / 22-08-2011 / 16:22:19 / cg" |
|
113 |
! ! |
|
114 |
||
9979 | 115 |
!CodeNavigationService methodsFor:'code services'! |
116 |
||
10631 | 117 |
browseClass:class |
118 |
self browser isNil ifTrue:[ ^ NewSystemBrowser browseClass:class ]. |
|
9979 | 119 |
(UserPreferences current alwaysOpenNewTabWhenCtrlClick |
10631 | 120 |
or:[ self browser navigationState modified ]) |
121 |
ifTrue:[ |
|
122 |
self browser |
|
123 |
spawnFullBrowserInClass:class |
|
124 |
selector:nil |
|
125 |
in:#newBuffer |
|
126 |
] |
|
127 |
ifFalse:[ self browser switchToClass:class ] |
|
9979 | 128 |
|
129 |
"Created: / 15-02-2010 / 09:36:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
130 |
"Modified: / 25-07-2010 / 11:00:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10631 | 131 |
"Modified: / 21-08-2011 / 10:07:30 / cg" |
9979 | 132 |
! |
133 |
||
134 |
browser |
|
135 |
||
136 |
^codeView browserHolder value |
|
137 |
||
138 |
"Created: / 06-03-2010 / 21:14:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
139 |
! ! |
|
140 |
||
141 |
!CodeNavigationService methodsFor:'event handling'! |
|
142 |
||
143 |
button1Press |
|
144 |
||
145 |
codeView syntaxElementSelection ifNil:[^self]. |
|
146 |
||
147 |
codeView syntaxElementSelection type == #selector ifTrue:[^self button1PressForSelector: codeView syntaxElementSelection value]. |
|
148 |
codeView syntaxElementSelection type == #class ifTrue:[^self browseClass:codeView syntaxElementSelection value]. |
|
149 |
||
150 |
"Created: / 14-02-2010 / 18:43:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
151 |
"Modified: / 06-03-2010 / 21:11:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
152 |
! |
|
153 |
||
154 |
button1PressForSelector: selector |
|
155 |
||
156 |
| impls menu | |
|
10254 | 157 |
impls := codeView implementorsOf: selector. |
10631 | 158 |
"/ impls size = 1 ifTrue:[^codeView browseMethod: impls anyOne]. |
10254 | 159 |
menu := codeView implementorsMenu: impls selector: selector. |
9979 | 160 |
self highlightClear. |
161 |
menu showAtPointer. |
|
162 |
||
163 |
"Created: / 14-02-2010 / 18:50:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10254 | 164 |
"Modified: / 30-06-2011 / 19:34:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10271 | 165 |
"Modified: / 07-07-2011 / 17:16:23 / jv" |
10631 | 166 |
"Modified: / 21-08-2011 / 11:06:08 / cg" |
9979 | 167 |
! |
168 |
||
169 |
button2Press |
|
170 |
||
171 |
| sel | |
|
172 |
sel := codeView syntaxElementSelection. |
|
173 |
(sel notNil and:[sel type == #selector]) ifTrue:[^self button2PressForSelector: sel value]. |
|
174 |
||
175 |
"Created: / 14-02-2010 / 18:43:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
176 |
"Modified: / 17-06-2011 / 08:58:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
177 |
! |
|
178 |
||
179 |
button2PressForSelector: selector |
|
180 |
||
181 |
| senders menu | |
|
10631 | 182 |
senders := codeView sendersOf: selector. |
183 |
"/ senders size = 1 ifTrue:[ codeView browseMethod: senders anyOne. ^ self]. |
|
10254 | 184 |
menu := codeView sendersMenu: senders selector: selector. |
9979 | 185 |
self highlightClear. |
186 |
menu showAtPointer. |
|
187 |
||
188 |
"Created: / 14-02-2010 / 18:50:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10254 | 189 |
"Modified: / 30-06-2011 / 19:34:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10631 | 190 |
"Modified: / 21-08-2011 / 11:34:49 / cg" |
9979 | 191 |
! |
192 |
||
10631 | 193 |
buttonMotion:button x:x y:y in:view |
9979 | 194 |
"Handles an event in given view (a subview of codeView). |
195 |
If the method returns true, the event will not be processed |
|
196 |
by the view." |
|
10631 | 197 |
|
198 |
(view == textView and:[ textView sensor ctrlDown ]) ifTrue:[ |
|
199 |
self highlightElementAtX:x y:y. |
|
200 |
^ true |
|
201 |
]. |
|
202 |
^ false |
|
9979 | 203 |
|
204 |
"Created: / 06-03-2010 / 20:40:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10631 | 205 |
"Modified (format): / 21-08-2011 / 10:07:15 / cg" |
9979 | 206 |
! |
207 |
||
208 |
buttonPress: button x:x y:y in: view |
|
209 |
||
210 |
"Handles an event in given view (a subview of codeView). |
|
211 |
If the method returns true, the event will not be processed |
|
212 |
by the view." |
|
213 |
||
10631 | 214 |
(view == textView) ifTrue:[ |
215 |
codeView sensor ctrlDown ifTrue:[ |
|
216 |
button == 1 ifTrue: [self button1Press.^true]. |
|
9979 | 217 |
button == #paste ifTrue: [self button2Press.^true]. |
10631 | 218 |
button == 2 ifTrue: [self button2Press.^true] |
219 |
]. |
|
9979 | 220 |
button == 1 ifTrue:[ |
221 |
self highlightVariableAtX:x y:y. |
|
222 |
] |
|
10631 | 223 |
]. |
9979 | 224 |
^false |
225 |
||
226 |
"Created: / 06-03-2010 / 21:12:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
227 |
"Modified: / 25-06-2010 / 14:53:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10631 | 228 |
"Modified (format): / 21-08-2011 / 10:06:54 / cg" |
9979 | 229 |
! |
230 |
||
231 |
keyPress:key x:x y:y in:view |
|
232 |
"Handles an event in given view (a subview of codeView). |
|
10588 | 233 |
If the method returns true, it has eaten the event and it will not be processed |
9979 | 234 |
by the view." |
10588 | 235 |
|
10631 | 236 |
|ev p| |
237 |
||
9979 | 238 |
(view == textView) ifTrue:[ |
239 |
(key == #'Control_L' or:[ key == #Ctrl ]) ifTrue:[ |
|
10631 | 240 |
"/ because it is delegated, the position is not correct |
241 |
ev := WindowGroup lastEventQuerySignal query. |
|
242 |
p := view device translatePoint:(ev x @ ev y) fromView:ev view toView:view. |
|
243 |
view sensor pushUserEvent:#highlightElementAtX:y: for:self withArguments:{p x. p y.}. |
|
10588 | 244 |
^ true. |
9979 | 245 |
]. |
10651 | 246 |
textView modified ifTrue:[ |
247 |
self highlightClear. |
|
248 |
codeView syntaxElements: nil. |
|
249 |
^ false |
|
250 |
]. |
|
10588 | 251 |
view sensor pushUserEvent:#highlightVariableAtCursor for:self . |
9979 | 252 |
]. |
253 |
^ false |
|
254 |
||
255 |
"Created: / 06-03-2010 / 20:50:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10361 | 256 |
"Modified: / 20-07-2011 / 18:49:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10651 | 257 |
"Modified: / 22-08-2011 / 16:30:29 / cg" |
9979 | 258 |
! |
259 |
||
260 |
keyRelease: key x:x y:y in: view |
|
261 |
"Handles an event in given view (a subview of codeView). |
|
10588 | 262 |
If the method returns true, it has eaten the event and it will not be processed |
9979 | 263 |
by the view." |
264 |
||
10631 | 265 |
|ev p| |
266 |
||
10588 | 267 |
(view == textView and:[key == #'Control_L' or:[key == #Ctrl]]) ifTrue:[ |
10631 | 268 |
"/ because it is delegated, the position is not correct |
269 |
ev := WindowGroup lastEventQuerySignal query. |
|
270 |
p := view device translatePoint:(ev x @ ev y) fromView:ev view toView:view. |
|
271 |
self highlightClear. |
|
272 |
"/ view sensor pushUserEvent:#highlightClear for:self. |
|
10588 | 273 |
^ true |
274 |
]. |
|
275 |
^ false |
|
9979 | 276 |
|
277 |
"Created: / 06-03-2010 / 21:03:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10631 | 278 |
"Modified: / 21-08-2011 / 11:32:40 / cg" |
9979 | 279 |
! ! |
280 |
||
281 |
!CodeNavigationService methodsFor:'initialization'! |
|
282 |
||
283 |
initialize |
|
284 |
||
285 |
super initialize. |
|
286 |
selectorEmphasis := self class defaultSelectorEmphasis. |
|
287 |
variableEmphasis := self class defaultVariableEmphasis. |
|
10361 | 288 |
linesToRedraw := OrderedCollection new. |
9979 | 289 |
|
290 |
"Created: / 25-06-2010 / 14:05:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
291 |
! ! |
|
292 |
||
293 |
!CodeNavigationService methodsFor:'private'! |
|
294 |
||
295 |
elementAtCursor |
|
296 |
^self elementAtLine: textView cursorLine col: textView cursorCol - 1 |
|
297 |
||
298 |
"Created: / 25-06-2010 / 14:39:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
299 |
! |
|
300 |
||
10631 | 301 |
elementAtLine:line col:colArg |
302 |
|characterPosition index element col| |
|
303 |
||
304 |
"/ if beyond end of line, do not advance into next line |
|
305 |
col := colArg min:(textView listAt:line) size. |
|
9979 | 306 |
|
307 |
characterPosition := textView characterPositionOfLine:line col:col. |
|
308 |
index := SortedCollection binarySearch: (codeView syntaxElements) forIndexOf: characterPosition. |
|
309 |
index > (codeView syntaxElements) size ifTrue:[^nil]. |
|
10631 | 310 |
element := (codeView syntaxElements) at:index ifAbsent:nil. |
311 |
element notNil ifTrue:[ |
|
312 |
(characterPosition between: element start and: element stop) ifTrue:[^element]. |
|
313 |
]. |
|
314 |
^nil |
|
9979 | 315 |
|
316 |
"Created: / 25-06-2010 / 14:40:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10631 | 317 |
"Modified: / 21-08-2011 / 11:03:29 / cg" |
9979 | 318 |
! |
319 |
||
320 |
elementAtX:x y:y |
|
321 |
|visibleLine line col| |
|
322 |
||
10631 | 323 |
codeView syntaxElements isNil ifTrue:[^nil]. |
324 |
||
9979 | 325 |
visibleLine := textView visibleLineOfY:y. |
326 |
col := textView colOfX:x inVisibleLine:visibleLine. |
|
327 |
line := textView visibleLineToAbsoluteLine:visibleLine. |
|
328 |
^self elementAtLine:line col:col |
|
329 |
||
330 |
"Created: / 25-06-2010 / 14:52:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
331 |
"Modified: / 01-08-2010 / 08:50:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10631 | 332 |
"Modified: / 21-08-2011 / 10:26:08 / cg" |
333 |
! |
|
334 |
||
335 |
foo |
|
336 |
|characterPosition index element | |
|
337 |
||
338 |
characterPosition := 1 |
|
339 |
||
340 |
"Created: / 21-08-2011 / 10:48:05 / cg" |
|
9979 | 341 |
! |
342 |
||
343 |
highlighEmphasisFor: element |
|
344 |
||
345 |
element ifNil:[^nil]. |
|
346 |
||
10631 | 347 |
element isSelector ifTrue:[^selectorEmphasis]. |
348 |
element isVariable ifTrue:[^variableEmphasis]. |
|
349 |
element isSelf ifTrue:[^variableEmphasis]. |
|
9979 | 350 |
|
351 |
^nil |
|
352 |
||
353 |
"Created: / 25-06-2010 / 13:54:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10631 | 354 |
"Modified: / 21-08-2011 / 09:42:37 / cg" |
9979 | 355 |
! |
356 |
||
357 |
highlightClear |
|
358 |
||
10361 | 359 |
^self highlightClear: true. |
9979 | 360 |
|
361 |
"Modified: / 26-12-2007 / 12:28:05 / janfrog" |
|
362 |
"Created: / 25-06-2010 / 14:15:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10276 | 363 |
"Modified: / 08-07-2011 / 08:50:45 / cg" |
10361 | 364 |
"Modified: / 20-07-2011 / 18:52:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
9979 | 365 |
! |
366 |
||
10361 | 367 |
highlightClear: redraw |
368 |
||
369 |
codeView syntaxElementSelection == nil ifTrue:[ ^ self ]. |
|
370 |
textView list ifNil:[ ^ self ]. |
|
371 |
textView list withIndexDo:[:line :lineNo | |
|
372 |
line isText ifTrue:[ |
|
373 |
(line hasEmphasis: currentEmphasis) ifTrue:[ |
|
374 |
line emphasisAllRemove:currentEmphasis. |
|
375 |
linesToRedraw add: lineNo. |
|
376 |
] |
|
377 |
] |
|
378 |
]. |
|
379 |
codeView syntaxElementSelection:nil. |
|
380 |
||
381 |
redraw ifTrue:[self redrawLines]. |
|
9979 | 382 |
|
10361 | 383 |
"Modified: / 26-12-2007 / 12:28:05 / janfrog" |
384 |
"Created: / 20-07-2011 / 18:52:19 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10631 | 385 |
"Modified: / 21-08-2011 / 10:15:15 / cg" |
10361 | 386 |
! |
387 |
||
388 |
highlightElement:element |
|
10631 | 389 |
|e| |
390 |
||
391 |
codeView syntaxElementSelection == element ifTrue:[ ^ self ]. "/ no change |
|
392 |
codeView syntaxElementSelection notNil ifTrue:[ |
|
393 |
self highlightClear: false. |
|
394 |
]. |
|
10361 | 395 |
|
10631 | 396 |
currentEmphasis := self highlighEmphasisFor:element. |
397 |
element notNil ifTrue:[ |
|
398 |
codeView syntaxElementSelection:element. |
|
399 |
e := element firstElementInChain. |
|
400 |
[ e notNil ] whileTrue:[ |
|
401 |
self highlightWithoutClearFrom:e start to:e stop. |
|
402 |
e := e nextElement |
|
403 |
]. |
|
404 |
]. |
|
10361 | 405 |
self redrawLines. |
9979 | 406 |
|
407 |
"Created: / 14-02-2010 / 16:18:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10361 | 408 |
"Modified: / 20-07-2011 / 18:52:46 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10631 | 409 |
"Modified: / 21-08-2011 / 10:22:58 / cg" |
9979 | 410 |
! |
411 |
||
412 |
highlightElementAtCursor |
|
413 |
self highlightElementAtLine: textView cursorLine col: textView cursorCol |
|
414 |
||
415 |
"Created: / 14-02-2010 / 16:17:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
416 |
"Modified: / 06-03-2010 / 19:59:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
417 |
! |
|
418 |
||
419 |
highlightElementAtLine:line col:col |
|
420 |
|characterPosition index element | |
|
421 |
||
422 |
||
423 |
characterPosition := textView characterPositionOfLine:line col:col. |
|
424 |
index := SortedCollection binarySearch: (codeView syntaxElements) forIndexOf: characterPosition. |
|
425 |
index > (codeView syntaxElements) size ifTrue:[^self highlightElement: nil]. |
|
426 |
element := (codeView syntaxElements) at: index. |
|
427 |
(characterPosition between: element start and: element stop) ifFalse:[^self highlightElement: nil]. |
|
428 |
self highlightElement:element |
|
429 |
||
430 |
"Created: / 14-02-2010 / 16:17:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
431 |
"Modified: / 01-08-2010 / 08:50:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
432 |
! |
|
433 |
||
434 |
highlightElementAtX:x y:y |
|
435 |
|visibleLine line col| |
|
436 |
||
10631 | 437 |
codeView syntaxElements isNil ifTrue:[^self]. |
9979 | 438 |
visibleLine := textView visibleLineOfY:y. |
439 |
col := textView colOfX:x inVisibleLine:visibleLine. |
|
440 |
line := textView visibleLineToAbsoluteLine:visibleLine. |
|
441 |
self highlightElementAtLine:line col:col |
|
442 |
||
443 |
"Created: / 14-02-2010 / 16:12:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
444 |
"Modified: / 06-03-2010 / 20:06:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10631 | 445 |
"Modified: / 21-08-2011 / 10:22:10 / cg" |
446 |
! |
|
447 |
||
448 |
highlightElementOrNil:e |
|
449 |
e notNil ifTrue:[ |
|
450 |
"/ cg: only if selected !! |
|
451 |
"/ self halt. |
|
452 |
self highlightElement:e. |
|
453 |
] ifFalse:[ |
|
454 |
self highlightClear |
|
455 |
]. |
|
456 |
||
457 |
"Created: / 25-06-2010 / 14:52:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
458 |
"Created: / 21-08-2011 / 09:56:39 / cg" |
|
9979 | 459 |
! |
460 |
||
461 |
highlightLine:lineNo fromLine:startLine col:endLine toLine:startCol col:endCol |
|
462 |
|line start end| |
|
463 |
||
464 |
(lineNo between:startLine and:endLine) ifFalse:[ |
|
465 |
^ self |
|
466 |
]. |
|
467 |
line := textView listAt:lineNo. |
|
10291
af5825474e18
changed: #highlightLine:fromLine:col:toLine:col:
Claus Gittinger <cg@exept.de>
parents:
10276
diff
changeset
|
468 |
line isEmpty ifTrue:[^self]. |
9979 | 469 |
start := lineNo = startLine ifTrue:[ |
470 |
startCol |
|
471 |
] ifFalse:[ |
|
472 |
line indexOfNonSeparator |
|
473 |
]. |
|
474 |
end := lineNo = endLine ifTrue:[ |
|
475 |
endCol |
|
476 |
] ifFalse:[ line size ]. |
|
477 |
line |
|
10291
af5825474e18
changed: #highlightLine:fromLine:col:toLine:col:
Claus Gittinger <cg@exept.de>
parents:
10276
diff
changeset
|
478 |
emphasisFrom:(start max: 1) |
af5825474e18
changed: #highlightLine:fromLine:col:toLine:col:
Claus Gittinger <cg@exept.de>
parents:
10276
diff
changeset
|
479 |
to:(end min: line size) |
10361 | 480 |
add: currentEmphasis. |
481 |
linesToRedraw add: lineNo. |
|
9979 | 482 |
|
483 |
"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
|
484 |
"Modified: / 08-07-2011 / 13:02:51 / cg" |
10361 | 485 |
"Modified: / 20-07-2011 / 18:43:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
9979 | 486 |
! |
487 |
||
488 |
highlightVariable:e |
|
10631 | 489 |
(e notNil and:[ e isVariableOrSelf ]) ifTrue:[ |
9979 | 490 |
self highlightElement:e. |
491 |
] ifFalse:[ |
|
492 |
self highlightClear. |
|
10361 | 493 |
]. |
494 |
||
495 |
"Modified: / 20-07-2011 / 18:54:44 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10631 | 496 |
"Modified: / 21-08-2011 / 09:39:42 / cg" |
9979 | 497 |
! |
498 |
||
499 |
highlightVariableAtCursor |
|
10631 | 500 |
self highlightElementOrNil:(self elementAtCursor) |
9979 | 501 |
|
502 |
"Modified: / 25-06-2010 / 14:53:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10631 | 503 |
"Modified: / 21-08-2011 / 09:56:56 / cg" |
9979 | 504 |
! |
505 |
||
506 |
highlightVariableAtX:x y:y |
|
10631 | 507 |
self highlightElementOrNil:(self elementAtX:x y:y). |
9979 | 508 |
|
509 |
"Created: / 25-06-2010 / 14:52:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10631 | 510 |
"Modified: / 21-08-2011 / 10:24:50 / cg" |
9979 | 511 |
! |
512 |
||
513 |
highlightWithoutClearFrom: start to: end |
|
514 |
"Remove underlined emphasis" |
|
515 |
||
516 |
|startLine startCol endLine endCol| |
|
517 |
||
518 |
startLine := textView lineOfCharacterPosition:start. |
|
519 |
startCol := start - (textView characterPositionOfLine:startLine col:1) + 1. |
|
520 |
endLine := textView lineOfCharacterPosition:end. |
|
521 |
endCol := end - (textView characterPositionOfLine:endLine col:1) + 1. |
|
522 |
self highlightWithoutClearFromLine: startLine col: startCol toLine: endLine col: endCol |
|
523 |
||
524 |
"Created: / 25-06-2010 / 14:15:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
525 |
! |
|
526 |
||
527 |
highlightWithoutClearFromLine: startLine col: startCol toLine: endLine col: endCol |
|
528 |
||
529 |
textView list keysAndValuesDo: |
|
530 |
[:lineNo :line| |
|
531 |
|start end| |
|
532 |
line isText ifTrue: |
|
533 |
[self highlightLine: lineNo fromLine: startLine col: endLine toLine: startCol col: endCol]]. |
|
534 |
||
535 |
"Created: / 25-06-2010 / 14:15:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
536 |
! ! |
|
537 |
||
10361 | 538 |
!CodeNavigationService methodsFor:'redrawing'! |
539 |
||
540 |
redrawLines |
|
541 |
linesToRedraw do:[:lineNo| |
|
10588 | 542 |
textView invalidateLine: lineNo. |
10361 | 543 |
]. |
544 |
linesToRedraw := OrderedCollection new: 1 |
|
545 |
||
546 |
"Created: / 20-07-2011 / 18:45:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10588 | 547 |
"Modified (format): / 18-08-2011 / 16:01:34 / cg" |
10361 | 548 |
! ! |
549 |
||
9979 | 550 |
!CodeNavigationService class methodsFor:'documentation'! |
551 |
||
552 |
version_CVS |
|
10651 | 553 |
^ '$Header: /cvs/stx/stx/libtool/Tools__CodeNavigationService.st,v 1.11 2011-08-22 14:33:28 cg Exp $' |
9979 | 554 |
! |
555 |
||
556 |
version_SVN |
|
557 |
^ '§Id: Tools__CodeNavigationService.st 7788 2011-06-17 07:57:48Z vranyj1 §' |
|
558 |
! ! |