author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Thu, 09 Feb 2017 09:56:47 +0000 | |
branch | jv |
changeset 17459 | 9f54cb54204c |
parent 17214 | c192b970f250 |
child 18226 | 346376844040 |
permissions | -rw-r--r-- |
17166 | 1 |
"{ Encoding: utf8 }" |
2 |
||
9980 | 3 |
" |
10077 | 4 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague |
13073
ff2d1aceaffd
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13064
diff
changeset
|
5 |
All Rights Reserved |
9980 | 6 |
|
10077 | 7 |
Permission is hereby granted, free of charge, to any person |
8 |
obtaining a copy of this software and associated documentation |
|
9 |
files (the 'Software'), to deal in the Software without |
|
10 |
restriction, including without limitation the rights to use, |
|
11 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
12 |
copies of the Software, and to permit persons to whom the |
|
13 |
Software is furnished to do so, subject to the following |
|
14 |
conditions: |
|
15 |
||
16 |
The above copyright notice and this permission notice shall be |
|
17 |
included in all copies or substantial portions of the Software. |
|
18 |
||
19 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
20 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
21 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
22 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
23 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
24 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
25 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
26 |
OTHER DEALINGS IN THE SOFTWARE. |
|
9980 | 27 |
" |
28 |
"{ Package: 'stx:libtool' }" |
|
29 |
||
30 |
"{ NameSpace: Tools }" |
|
31 |
||
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
32 |
BackgroundSourceProcessingService subclass:#CodeHighlightingService |
13107 | 33 |
instanceVariableNames:'syntaxPreferences' |
13102 | 34 |
classVariableNames:'' |
35 |
poolDictionaries:'' |
|
36 |
category:'Interface-CodeView' |
|
9980 | 37 |
! |
38 |
||
39 |
!CodeHighlightingService class methodsFor:'documentation'! |
|
40 |
||
41 |
copyright |
|
42 |
" |
|
10077 | 43 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague |
13073
ff2d1aceaffd
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13064
diff
changeset
|
44 |
All Rights Reserved |
10077 | 45 |
|
46 |
Permission is hereby granted, free of charge, to any person |
|
47 |
obtaining a copy of this software and associated documentation |
|
48 |
files (the 'Software'), to deal in the Software without |
|
49 |
restriction, including without limitation the rights to use, |
|
50 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
51 |
copies of the Software, and to permit persons to whom the |
|
52 |
Software is furnished to do so, subject to the following |
|
53 |
conditions: |
|
9980 | 54 |
|
10077 | 55 |
The above copyright notice and this permission notice shall be |
56 |
included in all copies or substantial portions of the Software. |
|
57 |
||
58 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
59 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
60 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
61 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
62 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
63 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
64 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
65 |
OTHER DEALINGS IN THE SOFTWARE. |
|
9980 | 66 |
" |
67 |
! ! |
|
68 |
||
69 |
!CodeHighlightingService class methodsFor:'accessing'! |
|
70 |
||
71 |
label |
|
13102 | 72 |
"Answers a short label - for UI" |
9980 | 73 |
|
74 |
^'Syntax Highlighting' |
|
75 |
||
76 |
"Created: / 07-03-2010 / 14:00:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
77 |
! ! |
|
78 |
||
13207 | 79 |
!CodeHighlightingService class methodsFor:'testing'! |
80 |
||
81 |
isUsefulFor:aCodeView |
|
82 |
"this filters useful services. |
|
83 |
Redefined to return true for myself - not for subclasses" |
|
84 |
||
85 |
^ self == Tools::CodeHighlightingService |
|
86 |
||
87 |
"Created: / 22-07-2013 / 14:00:54 / cg" |
|
88 |
! ! |
|
89 |
||
10486 | 90 |
!CodeHighlightingService methodsFor:'accessing'! |
91 |
||
13107 | 92 |
preferences:preferences |
93 |
"must be able to set those - otherwise, it uses a different coloring scheme in |
|
94 |
expecco" |
|
95 |
||
96 |
syntaxPreferences := preferences. |
|
97 |
! |
|
98 |
||
10486 | 99 |
syntaxHighlighter |
10721
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
100 |
| app lang highlighter | |
10486 | 101 |
|
102 |
"First, ask application..." |
|
103 |
app := codeView application. |
|
104 |
app notNil ifTrue:[ |
|
10721
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
105 |
| mthd class | |
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
106 |
|
13200
74d83643473b
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13107
diff
changeset
|
107 |
mthd := codeView method. |
10486 | 108 |
(mthd notNil and:[app respondsTo: #syntaxHighlighterForMethod:]) ifTrue:[ |
109 |
highlighter := app syntaxHighlighterForMethod:mthd. |
|
110 |
] ifFalse:[ |
|
11617 | 111 |
class := codeView classHolder value. |
10486 | 112 |
(class notNil and:[app respondsTo: #syntaxHighlighterForClass:]) ifTrue:[ |
113 |
highlighter := app syntaxHighlighterForClass: class. |
|
10721
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
114 |
] ifFalse:[ |
14487
ec94f1fcdf94
class: Tools::CodeHighlightingService
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14486
diff
changeset
|
115 |
(app respondsTo: #syntaxHighlighter) ifTrue:[ |
14486
c8b1e2d7dc46
class: Tools::CodeHighlightingService
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13867
diff
changeset
|
116 |
highlighter := app syntaxHighlighter. |
10721
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
117 |
]. |
10486 | 118 |
]. |
119 |
] |
|
120 |
]. |
|
121 |
"App did not provide any highlighter..." |
|
122 |
highlighter isNil ifTrue:[ |
|
11544
e82e2d8be007
changed: #syntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
11384
diff
changeset
|
123 |
highlighter := (lang := codeView language) isNil |
e82e2d8be007
changed: #syntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
11384
diff
changeset
|
124 |
ifTrue:[nil] |
e82e2d8be007
changed: #syntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
11384
diff
changeset
|
125 |
ifFalse:[lang syntaxHighlighterClass]. |
10486 | 126 |
]. |
127 |
"HACK!!!!!!" |
|
128 |
highlighter == SyntaxHighlighter ifTrue:[ |
|
129 |
highlighter := SyntaxHighlighter2 |
|
130 |
]. |
|
131 |
^ highlighter |
|
132 |
||
133 |
"Created: / 05-08-2011 / 10:48:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
13200
74d83643473b
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13107
diff
changeset
|
134 |
"Modified: / 22-07-2013 / 13:33:46 / cg" |
14487
ec94f1fcdf94
class: Tools::CodeHighlightingService
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14486
diff
changeset
|
135 |
"Modified: / 10-06-2014 / 17:58:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10486 | 136 |
! |
137 |
||
138 |
syntaxHighlighters |
|
13867 | 139 |
|
140 |
| highlighters highlighter | |
|
10486 | 141 |
|
13867 | 142 |
highlighters := OrderedCollection new: 4. |
143 |
highlighter := self syntaxHighlighter. |
|
144 |
highlighter notNil ifTrue:[ |
|
15827
e1a8c9093e23
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15805
diff
changeset
|
145 |
"/ cg: who sets this highlighter when adding a subclass to one of the expecco codeDescriptions? |
e1a8c9093e23
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15805
diff
changeset
|
146 |
"/ highlighter class == Workflow::ExecutionEditorShellScript::NaiveShellScriptSyntaxHighlighter ifTrue:[self halt]. |
e1a8c9093e23
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15805
diff
changeset
|
147 |
"/ highlighter == Workflow::ExecutionEditorShellScript::NaiveShellScriptSyntaxHighlighter ifTrue:[self halt]. |
13867 | 148 |
highlighters add: highlighter |
149 |
]. |
|
10486 | 150 |
|
14928
3c11ff12d0bc
Fixes for enabling / disabling individual CodeView2 services.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14784
diff
changeset
|
151 |
codeView servicesDo:[:service| |
13867 | 152 |
service ~~ self ifTrue:[ |
153 |
highlighter := service syntaxHighlighter. |
|
154 |
highlighter notNil ifTrue:[ |
|
15827
e1a8c9093e23
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15805
diff
changeset
|
155 |
"/ cg: who sets this highlighter when adding a subclass to one of the expecco codeDescriptions? |
e1a8c9093e23
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15805
diff
changeset
|
156 |
"/ highlighter class == Workflow::ExecutionEditorShellScript::NaiveShellScriptSyntaxHighlighter ifTrue:[self halt]. |
e1a8c9093e23
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15805
diff
changeset
|
157 |
"/ highlighter == Workflow::ExecutionEditorShellScript::NaiveShellScriptSyntaxHighlighter ifTrue:[self halt]. |
10486 | 158 |
highlighters add: highlighter |
159 |
]. |
|
160 |
] |
|
161 |
]. |
|
162 |
^highlighters |
|
163 |
||
164 |
"Created: / 05-08-2011 / 10:49:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
13867 | 165 |
"Modified: / 19-07-2012 / 12:58:48 / cg" |
14928
3c11ff12d0bc
Fixes for enabling / disabling individual CodeView2 services.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14784
diff
changeset
|
166 |
"Modified: / 27-11-2014 / 15:42:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10486 | 167 |
! ! |
168 |
||
16762 | 169 |
!CodeHighlightingService methodsFor:'accessing-defaults'! |
9980 | 170 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
171 |
defaultJobName |
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
172 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
173 |
^'CodeView2''s syntax highlighting job' |
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
174 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
175 |
"Created: / 24-01-2012 / 12:06:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10420 | 176 |
! ! |
177 |
||
9980 | 178 |
!CodeHighlightingService methodsFor:'private'! |
179 |
||
16621 | 180 |
clearScrollbarBackground |
181 |
"/ immediate change the scroller back to showing nothing; |
|
182 |
"/ will get new info, when the highlighter is finished. |
|
183 |
||
184 |
|scroller| |
|
185 |
||
186 |
codeView notNil ifTrue:[ |
|
187 |
scroller := textView superView verticalScrollBar thumb. |
|
188 |
scroller shown ifTrue:[ |
|
189 |
scroller |
|
190 |
initStyle ; |
|
191 |
invalidateRepairNow:true. |
|
192 |
] |
|
193 |
]. |
|
194 |
! |
|
195 |
||
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
196 |
process |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
197 |
"(Re)starts the processing job. Should be called whenever a source |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
198 |
must be (re)processed." |
9980 | 199 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
200 |
| highlighters | |
9980 | 201 |
|
10721
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
202 |
(highlighters := self syntaxHighlighters) isEmptyOrNil ifTrue:[ |
10486 | 203 |
"No higlighter, nothing to do" |
10968
5e738ee1cd2a
No highlighting by default (either method or language must be set)
vrany
parents:
10961
diff
changeset
|
204 |
^self |
10420 | 205 |
]. |
9980 | 206 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
207 |
super process. |
10420 | 208 |
|
209 |
"Modified: / 07-07-2011 / 12:26:12 / Jan Vrany <jan.vrant@fit.cvut,cz>" |
|
10968
5e738ee1cd2a
No highlighting by default (either method or language must be set)
vrany
parents:
10961
diff
changeset
|
210 |
"Modified: / 26-09-2011 / 15:40:23 / cg" |
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
211 |
"Created: / 24-01-2012 / 12:11:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10420 | 212 |
! |
213 |
||
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
214 |
process: delayed |
13867 | 215 |
|
10486 | 216 |
|oldCode oldCodeList newCode elements cls mthd highlighterClasses| |
13588
0701806de907
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13554
diff
changeset
|
217 |
"/ codeView topView class == DebugView ifTrue:[^ self]. |
11617 | 218 |
|
10420 | 219 |
done := false. |
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
220 |
modified := false. |
10420 | 221 |
codeView syntaxElements: nil. |
222 |
codeView syntaxElementSelection: nil. |
|
223 |
||
10486 | 224 |
highlighterClasses := self syntaxHighlighters. |
10149 | 225 |
|
10420 | 226 |
cls := codeView klass. |
227 |
(cls notNil and:[cls isObsolete]) ifTrue:[ |
|
10486 | 228 |
cls isMeta ifTrue:[ |
229 |
cls := (Smalltalk at:cls theNonMetaclass name) class |
|
230 |
] ifFalse:[ |
|
231 |
cls := Smalltalk at:cls name |
|
232 |
]. |
|
10420 | 233 |
]. |
13200
74d83643473b
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13107
diff
changeset
|
234 |
mthd := codeView method. |
10149 | 235 |
|
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
236 |
"textView" modified ifFalse:[ |
13554
0c5bc183802b
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13263
diff
changeset
|
237 |
"/ bad bad bad: textView's list may change, while we copy!!!!!!!!!! |
0c5bc183802b
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13263
diff
changeset
|
238 |
[ |
0c5bc183802b
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13263
diff
changeset
|
239 |
oldCodeList := textView list copy. |
0c5bc183802b
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13263
diff
changeset
|
240 |
] valueUninterruptably. |
0c5bc183802b
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13263
diff
changeset
|
241 |
|
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
242 |
"textView" modified ifFalse:[ |
10486 | 243 |
oldCodeList isNil ifFalse:[ |
15805
aa12f05014e6
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15789
diff
changeset
|
244 |
oldCode := oldCodeList asStringCollection asStringWithoutEmphasis. |
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
245 |
"textView" modified ifFalse:[ |
10486 | 246 |
Screen currentScreenQuerySignal answer:codeView device |
247 |
do:[ |
|
17166 | 248 |
"/ cg: not a good idea to handle it here; |
15447
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
249 |
"/ Syntaxhighlighter does it also, and will generate a better colorized string |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
250 |
"/ Parser parseErrorSignal handle:[:ex | |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
251 |
"/ |errMsg| |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
252 |
"/ |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
253 |
"/ errMsg := ex description asStringCollection first asString. |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
254 |
"/ |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
255 |
"/ "/ Transcript topView raiseDeiconified. |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
256 |
"/ Transcript showCR:'Error caught: ', ex description. |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
257 |
"/ "/ self halt. |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
258 |
"/ "/ self showInfo:(errMsg colorizeAllWith:Color red). |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
259 |
"/ newCode := nil. |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
260 |
"/ ] do:[ |
13867 | 261 |
| codeAspect | |
262 |
||
263 |
elements := ParseTreeIndex new. |
|
10486 | 264 |
newCode := oldCode asText. |
11705 | 265 |
codeAspect := codeView codeAspect. |
266 |
codeAspect == SyntaxHighlighter codeAspectMethod ifTrue:[ |
|
13107 | 267 |
highlighterClasses do:[:e|newCode := e formatMethod:mthd source:newCode in:cls using:syntaxPreferences elementsInto: elements]. |
10486 | 268 |
] ifFalse:[ |
11705 | 269 |
codeAspect == (SyntaxHighlighter codeAspectExpression) ifTrue:[ |
13867 | 270 |
highlighterClasses do:[:e|newCode := e formatExpression:newCode in:cls elementsInto: elements]. |
10486 | 271 |
] ifFalse:[ |
11705 | 272 |
codeAspect == (SyntaxHighlighter codeAspectClassDefinition) ifTrue:[ |
11384 | 273 |
highlighterClasses do:[:e|newCode := e formatClassDefinition:newCode string in:cls elementsInto: elements]. |
16128
e7b59cfeb8f3
Added support for highlighting of a statement list
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15828
diff
changeset
|
274 |
] ifFalse:[ |
e7b59cfeb8f3
Added support for highlighting of a statement list
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15828
diff
changeset
|
275 |
codeAspect == (SyntaxHighlighter codeAspectStatements) ifTrue:[ |
e7b59cfeb8f3
Added support for highlighting of a statement list
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15828
diff
changeset
|
276 |
highlighterClasses do:[:e|newCode := e formatStatements:newCode string in:cls elementsInto: elements]. |
e7b59cfeb8f3
Added support for highlighting of a statement list
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15828
diff
changeset
|
277 |
] |
e7b59cfeb8f3
Added support for highlighting of a statement list
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15828
diff
changeset
|
278 |
]. |
10486 | 279 |
]. |
280 |
]. |
|
15447
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
281 |
"/ ] |
10486 | 282 |
]. |
283 |
newCode notNil ifTrue:[ |
|
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
284 |
"textView" modified ifFalse:[ |
10486 | 285 |
newCode ~= oldCodeList ifTrue:[ |
286 |
newCode := newCode asStringCollection. |
|
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
287 |
"textView" modified ifFalse:[ |
10486 | 288 |
done := true. |
289 |
textView notNil ifTrue:[ |
|
290 |
"/ must add this event - and not been interrupted |
|
291 |
"/ by any arriving key-event. |
|
292 |
"/ self showInfo:nil. |
|
293 |
delayed ifTrue:[ |
|
294 |
codeView sensor |
|
295 |
pushUserEvent:#setHighlightedCode:elements: |
|
296 |
for:self |
|
297 |
withArguments:(Array with:newCode with: elements). |
|
298 |
"/self delayedUpdateBufferLabelWithCheckIfModified |
|
299 |
] ifFalse:[ |
|
300 |
textView contents: newCode. |
|
13867 | 301 |
codeView syntaxElements: elements. |
302 |
gutterView invalidate. |
|
16621 | 303 |
codeView updateScrollersViewBackground. |
10486 | 304 |
] |
305 |
] |
|
306 |
] |
|
307 |
]. |
|
308 |
] |
|
309 |
] |
|
310 |
] |
|
311 |
] |
|
312 |
] |
|
10420 | 313 |
] |
9980 | 314 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
315 |
"Created: / 24-01-2012 / 12:21:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
13200
74d83643473b
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13107
diff
changeset
|
316 |
"Modified: / 22-07-2013 / 13:33:40 / cg" |
16128
e7b59cfeb8f3
Added support for highlighting of a statement list
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15828
diff
changeset
|
317 |
"Modified: / 22-02-2016 / 21:00:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
318 |
! |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
319 |
|
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
320 |
setHighlightedCode:newCode elements: elements |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
321 |
"the background synhighlighter has generated new colored text, |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
322 |
with highlighted syntax. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
323 |
If there have been no modifications in the meantime, install it." |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
324 |
|
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
325 |
|firstShown lastShown cursorWasOn anyChange newLines l replaceAction list| |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
326 |
|
14784
0e0fc09a7a62
BrowserEnvironment is now polymorphic with ParseTreeEnvironment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14487
diff
changeset
|
327 |
"/ It may happen that service is unregistered while |
0e0fc09a7a62
BrowserEnvironment is now polymorphic with ParseTreeEnvironment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14487
diff
changeset
|
328 |
"/ an user event for #setHighlightedCode:elements: is already in |
0e0fc09a7a62
BrowserEnvironment is now polymorphic with ParseTreeEnvironment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14487
diff
changeset
|
329 |
"/ an event queue but not yet processed. To handle this situation. |
0e0fc09a7a62
BrowserEnvironment is now polymorphic with ParseTreeEnvironment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14487
diff
changeset
|
330 |
"/ check if textView is nil (which is in case the service is unregistered) |
0e0fc09a7a62
BrowserEnvironment is now polymorphic with ParseTreeEnvironment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14487
diff
changeset
|
331 |
textView isNil ifTrue:[ ^ self ]. |
9980 | 332 |
|
14784
0e0fc09a7a62
BrowserEnvironment is now polymorphic with ParseTreeEnvironment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14487
diff
changeset
|
333 |
|
0e0fc09a7a62
BrowserEnvironment is now polymorphic with ParseTreeEnvironment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14487
diff
changeset
|
334 |
modified ifTrue:[ |
0e0fc09a7a62
BrowserEnvironment is now polymorphic with ParseTreeEnvironment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14487
diff
changeset
|
335 |
"/ a new input arrived in the meantime |
0e0fc09a7a62
BrowserEnvironment is now polymorphic with ParseTreeEnvironment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14487
diff
changeset
|
336 |
^ self |
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
337 |
]. |
14784
0e0fc09a7a62
BrowserEnvironment is now polymorphic with ParseTreeEnvironment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14487
diff
changeset
|
338 |
|
11611 | 339 |
done ifFalse:[ |
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
340 |
"/ another coloring process has already been started. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
341 |
"/ ignore this (leftover) code. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
342 |
^ self |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
343 |
]. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
344 |
|
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
345 |
firstShown := textView firstLineShown. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
346 |
lastShown := textView lastLineShown. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
347 |
|
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
348 |
replaceAction := [:lNr :line | |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
349 |
|oldLine| |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
350 |
|
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
351 |
oldLine := list at:lNr ifAbsent:nil. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
352 |
oldLine notNil ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
353 |
line notNil ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
354 |
"/ this check is needed - there is a race |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
355 |
"/ when the text is converted. This detects the |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
356 |
"/ resulting error. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
357 |
"/ Certainly a kludge. |
10410 | 358 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
359 |
oldLine string = line string ifTrue:[ |
13867 | 360 |
| i | |
361 |
||
362 |
"JV@2012-02-01: Remove any emphasis on leading whitespace" |
|
363 |
"(presumably created by LintHighlighter)" |
|
364 |
i := line string indexOfNonSeparator. |
|
365 |
i > 1 ifTrue:[ |
|
366 |
| e | |
|
367 |
||
368 |
(e := (line emphasisAt: i - 1)) notNil ifTrue:[ |
|
369 |
line emphasisFrom: 1 to: i - 1 remove: e. |
|
370 |
] |
|
371 |
]. |
|
372 |
||
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
373 |
oldLine emphasis ~= line emphasis ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
374 |
textView modifiedChannel removeDependent:self. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
375 |
list at:lNr put:line. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
376 |
textView modifiedChannel addDependent:self. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
377 |
(lNr between:firstShown and:lastShown) ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
378 |
anyChange ifFalse:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
379 |
anyChange := true. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
380 |
cursorWasOn := textView hideCursor |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
381 |
]. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
382 |
textView redrawLine:lNr |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
383 |
] |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
384 |
] |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
385 |
] |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
386 |
] |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
387 |
] |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
388 |
]. |
10410 | 389 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
390 |
anyChange := false. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
391 |
newLines := newCode asStringCollection. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
392 |
list := textView list. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
393 |
list isNil ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
394 |
textView list:newLines. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
395 |
] ifFalse:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
396 |
"/ the cursor line first - that's where your eyes are ... |
15094
7e80c05b797b
Fix in Tools::CodeHighlightingService>>#setHighlightedCode:elements:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14928
diff
changeset
|
397 |
((l := textView cursorLine) notNil and:[l between: 1 and: newLines size]) ifTrue:[ |
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
398 |
l <= newLines size ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
399 |
replaceAction value:l value:(newLines at:l) |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
400 |
] |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
401 |
]. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
402 |
newLines keysAndValuesDo:replaceAction. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
403 |
anyChange ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
404 |
cursorWasOn ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
405 |
textView showCursor |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
406 |
] |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
407 |
] |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
408 |
]. |
13867 | 409 |
codeView syntaxElements: elements. |
410 |
gutterView invalidate. |
|
16621 | 411 |
codeView updateScrollersViewBackground. |
412 |
||
13867 | 413 |
"/ Transcript showCR:'--> rehighlighted ', self identityHash printString. |
10410 | 414 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
415 |
"Modified: / 09-10-2006 / 11:50:17 / cg" |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
416 |
"Created: / 14-02-2010 / 16:10:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
13867 | 417 |
"Modified (format): / 21-08-2011 / 09:38:22 / cg" |
418 |
"Modified: / 01-02-2012 / 19:18:00 / jv" |
|
15094
7e80c05b797b
Fix in Tools::CodeHighlightingService>>#setHighlightedCode:elements:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14928
diff
changeset
|
419 |
"Modified: / 20-01-2015 / 15:17:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10410 | 420 |
! ! |
421 |
||
9980 | 422 |
!CodeHighlightingService class methodsFor:'documentation'! |
423 |
||
10497 | 424 |
version |
15789
3c5227646c1f
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15447
diff
changeset
|
425 |
^ '$Header$' |
10497 | 426 |
! |
427 |
||
9980 | 428 |
version_CVS |
15789
3c5227646c1f
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15447
diff
changeset
|
429 |
^ '$Header$' |
9980 | 430 |
! |
431 |
||
16128
e7b59cfeb8f3
Added support for highlighting of a statement list
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15828
diff
changeset
|
432 |
version_HG |
e7b59cfeb8f3
Added support for highlighting of a statement list
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15828
diff
changeset
|
433 |
|
e7b59cfeb8f3
Added support for highlighting of a statement list
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15828
diff
changeset
|
434 |
^ '$Changeset: <not expanded> $' |
e7b59cfeb8f3
Added support for highlighting of a statement list
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15828
diff
changeset
|
435 |
! |
e7b59cfeb8f3
Added support for highlighting of a statement list
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15828
diff
changeset
|
436 |
|
9980 | 437 |
version_SVN |
15789
3c5227646c1f
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15447
diff
changeset
|
438 |
^ '$Id$' |
9980 | 439 |
! ! |
12099
d3315fdc1c92
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
11705
diff
changeset
|
440 |