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
|
|
31 |
instanceVariableNames:'selectorEmphasis variableEmphasis currentEmphasis'
|
|
32 |
classVariableNames:''
|
|
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>"
|
|
76 |
! !
|
|
77 |
|
|
78 |
!CodeNavigationService class methodsFor:'accessing - defaults'!
|
|
79 |
|
|
80 |
defaultSelectorEmphasis
|
|
81 |
^ Array with:#backgroundColor
|
|
82 |
-> (Color white blendWith:(Color
|
|
83 |
redByte:100
|
|
84 |
greenByte:180
|
|
85 |
blueByte:255))
|
|
86 |
!
|
|
87 |
|
|
88 |
defaultVariableEmphasis
|
|
89 |
^ Array with:#backgroundColor
|
|
90 |
-> (Color gray: 90)
|
|
91 |
|
|
92 |
"Created: / 25-06-2010 / 13:56:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
93 |
! !
|
|
94 |
|
|
95 |
!CodeNavigationService methodsFor:'code services'!
|
|
96 |
|
|
97 |
browseClass: class
|
|
98 |
|
|
99 |
self browser ifNil: [^NewSystemBrowser browseClass:class].
|
|
100 |
(UserPreferences current alwaysOpenNewTabWhenCtrlClick
|
|
101 |
or:[self browser navigationState modified])
|
|
102 |
ifTrue:
|
|
103 |
[self browser
|
|
104 |
spawnFullBrowserInClass: class selector:nil in:#newBuffer]
|
|
105 |
ifFalse:
|
|
106 |
[self browser
|
|
107 |
switchToClass: class]
|
|
108 |
|
|
109 |
"Created: / 15-02-2010 / 09:36:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
110 |
"Modified: / 25-07-2010 / 11:00:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
111 |
!
|
|
112 |
|
|
113 |
browseMethod: method
|
|
114 |
|
|
115 |
self browseMethod: method label: nil.
|
|
116 |
|
|
117 |
"Created: / 14-02-2010 / 19:41:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
118 |
!
|
|
119 |
|
|
120 |
browseMethod: method label: label
|
|
121 |
|
|
122 |
self browser ifNil: [^NewSystemBrowser openInMethod:method].
|
|
123 |
(UserPreferences current alwaysOpenNewTabWhenCtrlClick
|
|
124 |
or:[self browser navigationState modified])
|
|
125 |
ifTrue:
|
|
126 |
[self browser
|
|
127 |
spawnFullBrowserInClass: method mclass
|
|
128 |
selector:method selector
|
|
129 |
in:#newBuffer]
|
|
130 |
ifFalse:
|
|
131 |
[self browser
|
|
132 |
switchToClass: method containingClass
|
|
133 |
selector: method selector].
|
|
134 |
|
|
135 |
"Modified: / 19-02-2008 / 10:15:17 / janfrog"
|
|
136 |
"Created: / 19-10-2008 / 08:16:17 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
137 |
"Modified: / 25-07-2010 / 13:34:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
138 |
!
|
|
139 |
|
|
140 |
browseMethods: methods label: label
|
|
141 |
|
|
142 |
methods size = 1 ifTrue:
|
|
143 |
[^self browseMethod: methods anyOne label: label].
|
|
144 |
|
|
145 |
self browser
|
|
146 |
ifNil: [NewSystemBrowser browseMethods: methods title: label]
|
|
147 |
ifNotNil:[self browser spawnMethodBrowserFor:methods in:#newBuffer label:label]
|
|
148 |
|
|
149 |
"Created: / 26-12-2007 / 11:32:04 / janfrog"
|
|
150 |
"Modified: / 19-10-2008 / 08:17:28 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
151 |
!
|
|
152 |
|
|
153 |
browser
|
|
154 |
|
|
155 |
^codeView browserHolder value
|
|
156 |
|
|
157 |
"Created: / 06-03-2010 / 21:14:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
158 |
!
|
|
159 |
|
|
160 |
implementorsOf: selector
|
|
161 |
|
|
162 |
selector ifNil:[^#()].
|
|
163 |
^SystemBrowser
|
|
164 |
findImplementorsOf: selector
|
|
165 |
in: Smalltalk allClasses
|
|
166 |
ignoreCase: false
|
|
167 |
|
|
168 |
"Created: / 26-12-2007 / 11:37:11 / janfrog"
|
|
169 |
!
|
|
170 |
|
|
171 |
sendersOf: selector
|
|
172 |
|
|
173 |
^SystemBrowser
|
|
174 |
findSendersOf: selector
|
|
175 |
in: Smalltalk allClasses
|
|
176 |
ignoreCase: false
|
|
177 |
|
|
178 |
"Created: / 26-12-2007 / 11:37:22 / janfrog"
|
|
179 |
! !
|
|
180 |
|
|
181 |
!CodeNavigationService methodsFor:'event handling'!
|
|
182 |
|
|
183 |
button1Press
|
|
184 |
|
|
185 |
codeView syntaxElementSelection ifNil:[^self].
|
|
186 |
|
|
187 |
codeView syntaxElementSelection type == #selector ifTrue:[^self button1PressForSelector: codeView syntaxElementSelection value].
|
|
188 |
codeView syntaxElementSelection type == #class ifTrue:[^self browseClass:codeView syntaxElementSelection value].
|
|
189 |
|
|
190 |
"Created: / 14-02-2010 / 18:43:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
191 |
"Modified: / 06-03-2010 / 21:11:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
192 |
!
|
|
193 |
|
|
194 |
button1PressForSelector: selector
|
|
195 |
|
|
196 |
| impls menu |
|
|
197 |
impls := self implementorsOf: selector.
|
|
198 |
impls size = 1 ifTrue:[^self browseMethod: impls anyOne].
|
|
199 |
menu := self implementorsMenu: impls selector: selector.
|
|
200 |
self highlightClear.
|
|
201 |
menu showAtPointer.
|
|
202 |
|
|
203 |
"Created: / 14-02-2010 / 18:50:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
204 |
!
|
|
205 |
|
|
206 |
button2Press
|
|
207 |
|
|
208 |
| sel |
|
|
209 |
sel := codeView syntaxElementSelection.
|
|
210 |
(sel notNil and:[sel type == #selector]) ifTrue:[^self button2PressForSelector: sel value].
|
|
211 |
|
|
212 |
"Created: / 14-02-2010 / 18:43:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
213 |
"Modified: / 17-06-2011 / 08:58:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
214 |
!
|
|
215 |
|
|
216 |
button2PressForSelector: selector
|
|
217 |
|
|
218 |
| senders menu |
|
|
219 |
senders := self implementorsOf: selector.
|
|
220 |
senders size = 1 ifTrue:[^self browseMethod: senders anyOne].
|
|
221 |
menu := self sendersMenu: senders selector: selector.
|
|
222 |
self highlightClear.
|
|
223 |
menu showAtPointer.
|
|
224 |
|
|
225 |
"Created: / 14-02-2010 / 18:50:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
226 |
!
|
|
227 |
|
|
228 |
buttonMotion: button x:x y:y in: view
|
|
229 |
|
|
230 |
"Handles an event in given view (a subview of codeView).
|
|
231 |
If the method returns true, the event will not be processed
|
|
232 |
by the view."
|
|
233 |
|
|
234 |
(view == textView and:[textView sensor ctrlDown]) ifTrue:
|
|
235 |
[self highlightElementAtX:x y:y. ^true].
|
|
236 |
^false
|
|
237 |
|
|
238 |
"Created: / 06-03-2010 / 20:40:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
239 |
!
|
|
240 |
|
|
241 |
buttonPress: button x:x y:y in: view
|
|
242 |
|
|
243 |
"Handles an event in given view (a subview of codeView).
|
|
244 |
If the method returns true, the event will not be processed
|
|
245 |
by the view."
|
|
246 |
|
|
247 |
(view == textView) ifTrue:
|
|
248 |
[codeView sensor ctrlDown ifTrue:
|
|
249 |
[button == 1 ifTrue: [self button1Press.^true].
|
|
250 |
button == #paste ifTrue: [self button2Press.^true].
|
|
251 |
button == 2 ifTrue: [self button2Press.^true]].
|
|
252 |
button == 1 ifTrue:[
|
|
253 |
self highlightVariableAtX:x y:y.
|
|
254 |
]
|
|
255 |
].
|
|
256 |
^false
|
|
257 |
|
|
258 |
"Created: / 06-03-2010 / 21:12:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
259 |
"Modified: / 25-06-2010 / 14:53:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
260 |
!
|
|
261 |
|
|
262 |
keyPress:key x:x y:y in:view
|
|
263 |
"Handles an event in given view (a subview of codeView).
|
|
264 |
If the method returns true, the event will not be processed
|
|
265 |
by the view."
|
|
266 |
|
|
267 |
(view == textView) ifTrue:[
|
|
268 |
(key == #'Control_L' or:[ key == #Ctrl ]) ifTrue:[
|
|
269 |
self highlightElementAtX:x y:y.
|
|
270 |
^ true
|
|
271 |
].
|
|
272 |
self highlightVariableAtCursor.
|
|
273 |
^ false
|
|
274 |
].
|
|
275 |
^ false
|
|
276 |
|
|
277 |
"Created: / 06-03-2010 / 20:50:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
278 |
"Modified: / 25-06-2010 / 14:46:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
279 |
!
|
|
280 |
|
|
281 |
keyRelease: key x:x y:y in: view
|
|
282 |
|
|
283 |
"Handles an event in given view (a subview of codeView).
|
|
284 |
If the method returns true, the event will not be processed
|
|
285 |
by the view."
|
|
286 |
|
|
287 |
(view == textView and:[key == #'Control_L' or:[key == #Ctrl]]) ifTrue:
|
|
288 |
[self highlightClear. textView redraw. ^true].
|
|
289 |
^false
|
|
290 |
|
|
291 |
"Created: / 06-03-2010 / 21:03:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
292 |
! !
|
|
293 |
|
|
294 |
!CodeNavigationService methodsFor:'initialization'!
|
|
295 |
|
|
296 |
initialize
|
|
297 |
|
|
298 |
super initialize.
|
|
299 |
selectorEmphasis := self class defaultSelectorEmphasis.
|
|
300 |
variableEmphasis := self class defaultVariableEmphasis.
|
|
301 |
|
|
302 |
"Created: / 25-06-2010 / 14:05:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
303 |
! !
|
|
304 |
|
|
305 |
!CodeNavigationService methodsFor:'menus-dynamic'!
|
|
306 |
|
|
307 |
implementorsMenu: implementors selector: selector
|
|
308 |
| menu|
|
|
309 |
|
|
310 |
menu := Menu new.
|
|
311 |
implementors isNilOrEmptyCollection ifTrue:[
|
|
312 |
menu addItem:(MenuItem label:'No implementors found') disable
|
|
313 |
] ifFalse:[
|
|
314 |
menu addItem:(MenuItem
|
|
315 |
label:(selector storeString , (' (all implementors) ') asText allItalic)
|
|
316 |
value:[
|
|
317 |
self browseMethods:implementors
|
|
318 |
label:'Implementors of ' , selector storeString
|
|
319 |
]).
|
|
320 |
menu addSeparator.
|
|
321 |
implementors do:[:mth |
|
|
322 |
menu
|
|
323 |
addItem:(MenuItem label:(selector storeString
|
|
324 |
, (' in ' , mth containingClass name asText allBold))
|
|
325 |
value:[ self browseMethod:mth label: 'Implementor of ' , selector storeString ])
|
|
326 |
]
|
|
327 |
].
|
|
328 |
^ menu
|
|
329 |
|
|
330 |
"Modified: / 19-10-2008 / 08:16:50 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
331 |
"Created: / 14-02-2010 / 19:39:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
332 |
!
|
|
333 |
|
|
334 |
sendersMenu: senders selector: selector
|
|
335 |
| menu|
|
|
336 |
|
|
337 |
menu := Menu new.
|
|
338 |
senders isNilOrEmptyCollection ifTrue:[
|
|
339 |
menu addItem:(MenuItem label:'No senders found') disable
|
|
340 |
] ifFalse:[
|
|
341 |
menu addItem:(MenuItem
|
|
342 |
label:(selector storeString , (' (all senders)') asText allItalic)
|
|
343 |
value:[
|
|
344 |
self browseMethods:senders
|
|
345 |
label:'Senders of ' , selector storeString
|
|
346 |
]).
|
|
347 |
menu addSeparator.
|
|
348 |
senders do:[:mth |
|
|
349 |
menu
|
|
350 |
addItem:(MenuItem label:(mth selector storeString
|
|
351 |
, (' in ' , mth containingClass name asText allBold))
|
|
352 |
value:[ self browseMethod:mth label: 'Sender of ' , selector storeString ])
|
|
353 |
]
|
|
354 |
].
|
|
355 |
^ menu
|
|
356 |
|
|
357 |
"Modified: / 19-10-2008 / 08:17:00 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
358 |
"Created: / 14-02-2010 / 19:40:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
359 |
"Modified: / 01-08-2010 / 11:09:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
360 |
! !
|
|
361 |
|
|
362 |
!CodeNavigationService methodsFor:'private'!
|
|
363 |
|
|
364 |
elementAtCursor
|
|
365 |
^self elementAtLine: textView cursorLine col: textView cursorCol - 1
|
|
366 |
|
|
367 |
"Created: / 25-06-2010 / 14:39:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
368 |
!
|
|
369 |
|
|
370 |
elementAtLine:line col:col
|
|
371 |
|characterPosition index element |
|
|
372 |
|
|
373 |
characterPosition := textView characterPositionOfLine:line col:col.
|
|
374 |
index := SortedCollection binarySearch: (codeView syntaxElements) forIndexOf: characterPosition.
|
|
375 |
index > (codeView syntaxElements) size ifTrue:[^nil].
|
|
376 |
element := (codeView syntaxElements) at: index.
|
|
377 |
(characterPosition between: element start and: element stop) ifFalse:[^nil].
|
|
378 |
^element
|
|
379 |
|
|
380 |
"Created: / 25-06-2010 / 14:40:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
381 |
!
|
|
382 |
|
|
383 |
elementAtX:x y:y
|
|
384 |
|visibleLine line col|
|
|
385 |
|
|
386 |
codeView syntaxElements ifNil:[^nil].
|
|
387 |
visibleLine := textView visibleLineOfY:y.
|
|
388 |
col := textView colOfX:x inVisibleLine:visibleLine.
|
|
389 |
line := textView visibleLineToAbsoluteLine:visibleLine.
|
|
390 |
^self elementAtLine:line col:col
|
|
391 |
|
|
392 |
"Created: / 25-06-2010 / 14:52:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
393 |
"Modified: / 01-08-2010 / 08:50:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
394 |
!
|
|
395 |
|
|
396 |
highlighEmphasisFor: element
|
|
397 |
|
|
398 |
element ifNil:[^nil].
|
|
399 |
|
|
400 |
element type == #selector ifTrue:[^selectorEmphasis].
|
|
401 |
element type == #variable ifTrue:[^variableEmphasis].
|
|
402 |
|
|
403 |
^nil
|
|
404 |
|
|
405 |
"Created: / 25-06-2010 / 13:54:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
406 |
!
|
|
407 |
|
|
408 |
highlightClear
|
|
409 |
|textView|
|
|
410 |
|
|
411 |
codeView syntaxElementSelection == nil ifTrue:[^ self].
|
|
412 |
|
|
413 |
textView := codeView textView.
|
|
414 |
textView list ifNil:[ ^ self ].
|
|
415 |
textView list do:[:line |
|
|
416 |
line isText ifTrue:[
|
|
417 |
line emphasisAllRemove: currentEmphasis
|
|
418 |
]
|
|
419 |
].
|
|
420 |
textView redraw.
|
|
421 |
codeView syntaxElementSelection:nil.
|
|
422 |
|
|
423 |
"Modified: / 26-12-2007 / 12:28:05 / janfrog"
|
|
424 |
"Created: / 25-06-2010 / 14:15:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
425 |
"Modified: / 30-06-2011 / 11:07:05 / cg"
|
|
426 |
!
|
|
427 |
|
|
428 |
highlightElement: element
|
|
429 |
codeView syntaxElementSelection == element ifTrue:[^ self].
|
|
430 |
|
|
431 |
self highlightClear.
|
|
432 |
currentEmphasis := self highlighEmphasisFor: element.
|
|
433 |
element
|
|
434 |
ifNotNil:
|
|
435 |
[|e|
|
|
436 |
codeView syntaxElementSelection: element.
|
|
437 |
e := element.
|
|
438 |
[e isNil] whileFalse:
|
|
439 |
[self highlightWithoutClearFrom: e start to: e stop.
|
|
440 |
e := e next].
|
|
441 |
e := element prev.
|
|
442 |
[e isNil] whileFalse:
|
|
443 |
[self highlightWithoutClearFrom: e start to: e stop.
|
|
444 |
e := e prev]].
|
|
445 |
textView invalidate
|
|
446 |
|
|
447 |
"Created: / 14-02-2010 / 16:18:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
448 |
"Modified: / 25-06-2010 / 14:18:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
449 |
"Modified: / 30-06-2011 / 11:06:42 / cg"
|
|
450 |
!
|
|
451 |
|
|
452 |
highlightElementAtCursor
|
|
453 |
self highlightElementAtLine: textView cursorLine col: textView cursorCol
|
|
454 |
|
|
455 |
"Created: / 14-02-2010 / 16:17:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
456 |
"Modified: / 06-03-2010 / 19:59:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
457 |
!
|
|
458 |
|
|
459 |
highlightElementAtLine:line col:col
|
|
460 |
|characterPosition index element |
|
|
461 |
|
|
462 |
|
|
463 |
characterPosition := textView characterPositionOfLine:line col:col.
|
|
464 |
index := SortedCollection binarySearch: (codeView syntaxElements) forIndexOf: characterPosition.
|
|
465 |
index > (codeView syntaxElements) size ifTrue:[^self highlightElement: nil].
|
|
466 |
element := (codeView syntaxElements) at: index.
|
|
467 |
(characterPosition between: element start and: element stop) ifFalse:[^self highlightElement: nil].
|
|
468 |
self highlightElement:element
|
|
469 |
|
|
470 |
"Created: / 14-02-2010 / 16:17:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
471 |
"Modified: / 01-08-2010 / 08:50:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
472 |
!
|
|
473 |
|
|
474 |
highlightElementAtX:x y:y
|
|
475 |
|visibleLine line col|
|
|
476 |
|
|
477 |
codeView syntaxElements ifNil:[^self].
|
|
478 |
visibleLine := textView visibleLineOfY:y.
|
|
479 |
col := textView colOfX:x inVisibleLine:visibleLine.
|
|
480 |
line := textView visibleLineToAbsoluteLine:visibleLine.
|
|
481 |
self highlightElementAtLine:line col:col
|
|
482 |
|
|
483 |
"Created: / 14-02-2010 / 16:12:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
484 |
"Modified: / 06-03-2010 / 20:06:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
485 |
!
|
|
486 |
|
|
487 |
highlightLine:lineNo fromLine:startLine col:endLine toLine:startCol col:endCol
|
|
488 |
|line start end|
|
|
489 |
|
|
490 |
(lineNo between:startLine and:endLine) ifFalse:[
|
|
491 |
^ self
|
|
492 |
].
|
|
493 |
line := textView listAt:lineNo.
|
|
494 |
start := lineNo = startLine ifTrue:[
|
|
495 |
startCol
|
|
496 |
] ifFalse:[
|
|
497 |
line indexOfNonSeparator
|
|
498 |
].
|
|
499 |
end := lineNo = endLine ifTrue:[
|
|
500 |
endCol
|
|
501 |
] ifFalse:[ line size ].
|
|
502 |
line
|
|
503 |
emphasisFrom:start
|
|
504 |
to:end
|
|
505 |
add: currentEmphasis
|
|
506 |
|
|
507 |
"Created: / 25-06-2010 / 14:15:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
508 |
"Modified: / 03-09-2010 / 22:39:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
509 |
!
|
|
510 |
|
|
511 |
highlightVariable:e
|
|
512 |
(e notNil and:[ e type == #variable ]) ifTrue:[
|
|
513 |
self highlightElement:e.
|
|
514 |
] ifFalse:[
|
|
515 |
self highlightClear.
|
|
516 |
]
|
|
517 |
!
|
|
518 |
|
|
519 |
highlightVariableAtCursor
|
|
520 |
|e|
|
|
521 |
|
|
522 |
e := self elementAtCursor.
|
|
523 |
self highlightVariable: e
|
|
524 |
|
|
525 |
"Modified: / 25-06-2010 / 14:53:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
526 |
!
|
|
527 |
|
|
528 |
highlightVariableAtX:x y:y
|
|
529 |
|e|
|
|
530 |
|
|
531 |
e := self elementAtX:x y:y.
|
|
532 |
self highlightVariable:e.
|
|
533 |
|
|
534 |
"Created: / 25-06-2010 / 14:52:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
535 |
!
|
|
536 |
|
|
537 |
highlightWithoutClearFrom: start to: end
|
|
538 |
"Remove underlined emphasis"
|
|
539 |
|
|
540 |
|startLine startCol endLine endCol|
|
|
541 |
|
|
542 |
startLine := textView lineOfCharacterPosition:start.
|
|
543 |
startCol := start - (textView characterPositionOfLine:startLine col:1) + 1.
|
|
544 |
endLine := textView lineOfCharacterPosition:end.
|
|
545 |
endCol := end - (textView characterPositionOfLine:endLine col:1) + 1.
|
|
546 |
self highlightWithoutClearFromLine: startLine col: startCol toLine: endLine col: endCol
|
|
547 |
|
|
548 |
"Created: / 25-06-2010 / 14:15:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
549 |
!
|
|
550 |
|
|
551 |
highlightWithoutClearFromLine: startLine col: startCol toLine: endLine col: endCol
|
|
552 |
|
|
553 |
textView list keysAndValuesDo:
|
|
554 |
[:lineNo :line|
|
|
555 |
|start end|
|
|
556 |
line isText ifTrue:
|
|
557 |
[self highlightLine: lineNo fromLine: startLine col: endLine toLine: startCol col: endCol]].
|
|
558 |
|
|
559 |
"Created: / 25-06-2010 / 14:15:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
560 |
! !
|
|
561 |
|
|
562 |
!CodeNavigationService class methodsFor:'documentation'!
|
|
563 |
|
|
564 |
version_CVS
|
10076
|
565 |
^ '$Header: /cvs/stx/stx/libtool/Tools__CodeNavigationService.st,v 1.2 2011-07-03 17:50:19 cg Exp $'
|
9979
|
566 |
!
|
|
567 |
|
|
568 |
version_SVN
|
|
569 |
^ '§Id: Tools__CodeNavigationService.st 7788 2011-06-17 07:57:48Z vranyj1 §'
|
|
570 |
! !
|