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