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