author | Claus Gittinger <cg@exept.de> |
Fri, 15 Jun 2018 04:00:37 +0200 | |
changeset 18220 | d1ebaddf1100 |
parent 18043 | 4d0525c5be64 |
child 18344 | 32c81ec462a9 |
permissions | -rw-r--r-- |
18040 | 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 |
|
17716 | 142 |
highlighters := OrderedCollection new. |
13867 | 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>" |
|
14928
3c11ff12d0bc
Fixes for enabling / disabling individual CodeView2 services.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14784
diff
changeset
|
165 |
"Modified: / 27-11-2014 / 15:42:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
17716 | 166 |
"Modified: / 21-10-2017 / 12:58:40 / cg" |
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 |
18040 | 215 |
|oldCode oldCodeList oldCodeWithoutEmphasis newCode elements cls mthd highlighterClasses| |
13867 | 216 |
|
17716 | 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. |
17716 | 225 |
highlighterClasses isEmptyOrNil ifTrue:[^ self]. |
226 |
||
10420 | 227 |
cls := codeView klass. |
228 |
(cls notNil and:[cls isObsolete]) ifTrue:[ |
|
10486 | 229 |
cls isMeta ifTrue:[ |
230 |
cls := (Smalltalk at:cls theNonMetaclass name) class |
|
231 |
] ifFalse:[ |
|
232 |
cls := Smalltalk at:cls name |
|
233 |
]. |
|
10420 | 234 |
]. |
13200
74d83643473b
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13107
diff
changeset
|
235 |
mthd := codeView method. |
18043 | 236 |
"/ mthd isNil ifTrue:[ |
237 |
"/ cls isNil ifTrue:[ |
|
238 |
"/ "/ self halt. |
|
239 |
"/ ^ self. |
|
240 |
"/ ] |
|
241 |
"/ ]. |
|
10149 | 242 |
|
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
243 |
"textView" modified ifFalse:[ |
13554
0c5bc183802b
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13263
diff
changeset
|
244 |
"/ bad bad bad: textView's list may change, while we copy!!!!!!!!!! |
0c5bc183802b
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13263
diff
changeset
|
245 |
[ |
0c5bc183802b
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13263
diff
changeset
|
246 |
oldCodeList := textView list copy. |
0c5bc183802b
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13263
diff
changeset
|
247 |
] valueUninterruptably. |
0c5bc183802b
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13263
diff
changeset
|
248 |
|
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
249 |
"textView" modified ifFalse:[ |
10486 | 250 |
oldCodeList isNil ifFalse:[ |
18040 | 251 |
oldCode := oldCodeList asStringCollection. |
252 |
oldCodeWithoutEmphasis := oldCode asStringWithoutEmphasis. |
|
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
253 |
"textView" modified ifFalse:[ |
10486 | 254 |
Screen currentScreenQuerySignal answer:codeView device |
255 |
do:[ |
|
17166 | 256 |
"/ cg: not a good idea to handle it here; |
15447
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
257 |
"/ Syntaxhighlighter does it also, and will generate a better colorized string |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
258 |
"/ Parser parseErrorSignal handle:[:ex | |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
259 |
"/ |errMsg| |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
260 |
"/ |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
261 |
"/ errMsg := ex description asStringCollection first asString. |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
262 |
"/ |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
263 |
"/ "/ Transcript topView raiseDeiconified. |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
264 |
"/ Transcript showCR:'Error caught: ', ex description. |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
265 |
"/ "/ self halt. |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
266 |
"/ "/ self showInfo:(errMsg colorizeAllWith:Color red). |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
267 |
"/ newCode := nil. |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
268 |
"/ ] do:[ |
13867 | 269 |
| codeAspect | |
270 |
||
271 |
elements := ParseTreeIndex new. |
|
18040 | 272 |
newCode := oldCodeWithoutEmphasis asText. |
11705 | 273 |
codeAspect := codeView codeAspect. |
274 |
codeAspect == SyntaxHighlighter codeAspectMethod ifTrue:[ |
|
13107 | 275 |
highlighterClasses do:[:e|newCode := e formatMethod:mthd source:newCode in:cls using:syntaxPreferences elementsInto: elements]. |
17166 | 276 |
] ifFalse:[codeAspect == SyntaxHighlighter codeAspectExpression ifTrue:[ |
277 |
highlighterClasses do:[:e|newCode := e formatExpression:newCode in:cls elementsInto: elements]. |
|
278 |
] ifFalse:[codeAspect == SyntaxHighlighter codeAspectClassDefinition ifTrue:[ |
|
279 |
highlighterClasses do:[:e|newCode := e formatClassDefinition:newCode string in:cls elementsInto: elements]. |
|
17716 | 280 |
] ifFalse:[codeAspect == SyntaxHighlighter codeAspectFile ifTrue:[ |
281 |
highlighterClasses do:[:e|newCode := e formatFileContents:newCode string elementsInto: elements]. |
|
282 |
] ifFalse:[codeAspect isNil ifTrue:[ |
|
283 |
highlighterClasses do:[:e|newCode := e formatFileContents:newCode string elementsInto: elements]. |
|
284 |
]]]]]. |
|
15447
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
285 |
"/ ] |
10486 | 286 |
]. |
287 |
newCode notNil ifTrue:[ |
|
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
288 |
"textView" modified ifFalse:[ |
18040 | 289 |
newCode ~= oldCode ifTrue:[ |
10486 | 290 |
newCode := newCode asStringCollection. |
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
291 |
"textView" modified ifFalse:[ |
10486 | 292 |
done := true. |
293 |
textView notNil ifTrue:[ |
|
294 |
"/ must add this event - and not been interrupted |
|
295 |
"/ by any arriving key-event. |
|
296 |
"/ self showInfo:nil. |
|
297 |
delayed ifTrue:[ |
|
298 |
codeView sensor |
|
299 |
pushUserEvent:#setHighlightedCode:elements: |
|
300 |
for:self |
|
301 |
withArguments:(Array with:newCode with: elements). |
|
302 |
"/self delayedUpdateBufferLabelWithCheckIfModified |
|
303 |
] ifFalse:[ |
|
304 |
textView contents: newCode. |
|
13867 | 305 |
codeView syntaxElements: elements. |
306 |
gutterView invalidate. |
|
16621 | 307 |
codeView updateScrollersViewBackground. |
10486 | 308 |
] |
309 |
] |
|
310 |
] |
|
311 |
]. |
|
312 |
] |
|
313 |
] |
|
314 |
] |
|
315 |
] |
|
316 |
] |
|
10420 | 317 |
] |
9980 | 318 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
319 |
"Created: / 24-01-2012 / 12:21:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
17716 | 320 |
"Modified: / 21-10-2017 / 13:29:53 / cg" |
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
321 |
! |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
322 |
|
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
323 |
setHighlightedCode:newCode elements: elements |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
324 |
"the background synhighlighter has generated new colored text, |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
325 |
with highlighted syntax. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
326 |
If there have been no modifications in the meantime, install it." |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
327 |
|
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
328 |
|firstShown lastShown cursorWasOn anyChange newLines l replaceAction list| |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
329 |
|
14784
0e0fc09a7a62
BrowserEnvironment is now polymorphic with ParseTreeEnvironment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14487
diff
changeset
|
330 |
"/ 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
|
331 |
"/ 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
|
332 |
"/ 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
|
333 |
"/ 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
|
334 |
textView isNil ifTrue:[ ^ self ]. |
9980 | 335 |
|
14784
0e0fc09a7a62
BrowserEnvironment is now polymorphic with ParseTreeEnvironment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14487
diff
changeset
|
336 |
|
0e0fc09a7a62
BrowserEnvironment is now polymorphic with ParseTreeEnvironment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14487
diff
changeset
|
337 |
modified ifTrue:[ |
0e0fc09a7a62
BrowserEnvironment is now polymorphic with ParseTreeEnvironment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14487
diff
changeset
|
338 |
"/ 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
|
339 |
^ self |
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
340 |
]. |
14784
0e0fc09a7a62
BrowserEnvironment is now polymorphic with ParseTreeEnvironment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14487
diff
changeset
|
341 |
|
11611 | 342 |
done ifFalse:[ |
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
343 |
"/ another coloring process has already been started. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
344 |
"/ ignore this (leftover) code. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
345 |
^ self |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
346 |
]. |
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 |
firstShown := textView firstLineShown. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
349 |
lastShown := textView lastLineShown. |
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 |
replaceAction := [:lNr :line | |
18040 | 352 |
|oldLine nonSepIndex charEmphasis| |
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
353 |
|
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
354 |
oldLine := list at:lNr ifAbsent:nil. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
355 |
oldLine notNil ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
356 |
line notNil ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
357 |
"/ this check is needed - there is a race |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
358 |
"/ when the text is converted. This detects the |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
359 |
"/ resulting error. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
360 |
"/ Certainly a kludge. |
10410 | 361 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
362 |
oldLine string = line string ifTrue:[ |
13867 | 363 |
"JV@2012-02-01: Remove any emphasis on leading whitespace" |
364 |
"(presumably created by LintHighlighter)" |
|
18040 | 365 |
nonSepIndex := line string indexOfNonSeparator. |
366 |
nonSepIndex > 1 ifTrue:[ |
|
367 |
(charEmphasis := (line emphasisAt:nonSepIndex - 1)) notNil ifTrue:[ |
|
368 |
line emphasisFrom:1 to:(nonSepIndex - 1) remove:charEmphasis. |
|
13867 | 369 |
] |
370 |
]. |
|
371 |
||
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
372 |
oldLine emphasis ~= line emphasis ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
373 |
textView modifiedChannel removeDependent:self. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
374 |
list at:lNr put:line. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
375 |
textView modifiedChannel addDependent:self. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
376 |
(lNr between:firstShown and:lastShown) ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
377 |
anyChange ifFalse:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
378 |
anyChange := true. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
379 |
cursorWasOn := textView hideCursor |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
380 |
]. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
381 |
textView redrawLine:lNr |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
382 |
] |
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 |
]. |
10410 | 388 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
389 |
anyChange := false. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
390 |
newLines := newCode asStringCollection. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
391 |
list := textView list. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
392 |
list isNil ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
393 |
textView list:newLines. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
394 |
] ifFalse:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
395 |
"/ 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
|
396 |
((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
|
397 |
l <= newLines size ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
398 |
replaceAction value:l value:(newLines at:l) |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
399 |
] |
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 |
newLines keysAndValuesDo:replaceAction. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
402 |
anyChange ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
403 |
cursorWasOn ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
404 |
textView showCursor |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
405 |
] |
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 |
]. |
13867 | 408 |
codeView syntaxElements: elements. |
409 |
gutterView invalidate. |
|
16621 | 410 |
codeView updateScrollersViewBackground. |
411 |
||
13867 | 412 |
"/ Transcript showCR:'--> rehighlighted ', self identityHash printString. |
10410 | 413 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
414 |
"Modified: / 09-10-2006 / 11:50:17 / cg" |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
415 |
"Created: / 14-02-2010 / 16:10:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
13867 | 416 |
"Modified (format): / 21-08-2011 / 09:38:22 / cg" |
417 |
"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
|
418 |
"Modified: / 20-01-2015 / 15:17:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10410 | 419 |
! ! |
420 |
||
9980 | 421 |
!CodeHighlightingService class methodsFor:'documentation'! |
422 |
||
10497 | 423 |
version |
15789
3c5227646c1f
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15447
diff
changeset
|
424 |
^ '$Header$' |
10497 | 425 |
! |
426 |
||
9980 | 427 |
version_CVS |
15789
3c5227646c1f
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15447
diff
changeset
|
428 |
^ '$Header$' |
9980 | 429 |
! |
430 |
||
431 |
version_SVN |
|
15789
3c5227646c1f
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15447
diff
changeset
|
432 |
^ '$Id$' |
9980 | 433 |
! ! |
12099
d3315fdc1c92
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
11705
diff
changeset
|
434 |