author | Claus Gittinger <cg@exept.de> |
Thu, 18 Jan 2018 17:18:35 +0100 | |
changeset 17943 | b2efb0175eab |
parent 17716 | 406658241c77 |
child 18040 | 8f6de437a2df |
permissions | -rw-r--r-- |
9980 | 1 |
" |
10077 | 2 |
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
|
3 |
All Rights Reserved |
9980 | 4 |
|
10077 | 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. |
|
9980 | 25 |
" |
26 |
"{ Package: 'stx:libtool' }" |
|
27 |
||
28 |
"{ NameSpace: Tools }" |
|
29 |
||
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
30 |
BackgroundSourceProcessingService subclass:#CodeHighlightingService |
13107 | 31 |
instanceVariableNames:'syntaxPreferences' |
13102 | 32 |
classVariableNames:'' |
33 |
poolDictionaries:'' |
|
34 |
category:'Interface-CodeView' |
|
9980 | 35 |
! |
36 |
||
37 |
!CodeHighlightingService class methodsFor:'documentation'! |
|
38 |
||
39 |
copyright |
|
40 |
" |
|
10077 | 41 |
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
|
42 |
All Rights Reserved |
10077 | 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: |
|
9980 | 52 |
|
10077 | 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. |
|
9980 | 64 |
" |
65 |
! ! |
|
66 |
||
17716 | 67 |
|
9980 | 68 |
!CodeHighlightingService class methodsFor:'accessing'! |
69 |
||
70 |
label |
|
13102 | 71 |
"Answers a short label - for UI" |
9980 | 72 |
|
73 |
^'Syntax Highlighting' |
|
74 |
||
75 |
"Created: / 07-03-2010 / 14:00:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
76 |
! ! |
|
77 |
||
13207 | 78 |
!CodeHighlightingService class methodsFor:'testing'! |
79 |
||
80 |
isUsefulFor:aCodeView |
|
81 |
"this filters useful services. |
|
82 |
Redefined to return true for myself - not for subclasses" |
|
83 |
||
84 |
^ self == Tools::CodeHighlightingService |
|
85 |
||
86 |
"Created: / 22-07-2013 / 14:00:54 / cg" |
|
87 |
! ! |
|
88 |
||
10486 | 89 |
!CodeHighlightingService methodsFor:'accessing'! |
90 |
||
13107 | 91 |
preferences:preferences |
92 |
"must be able to set those - otherwise, it uses a different coloring scheme in |
|
93 |
expecco" |
|
94 |
||
95 |
syntaxPreferences := preferences. |
|
96 |
! |
|
97 |
||
10486 | 98 |
syntaxHighlighter |
10721
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
99 |
| app lang highlighter | |
10486 | 100 |
|
101 |
"First, ask application..." |
|
102 |
app := codeView application. |
|
103 |
app notNil ifTrue:[ |
|
10721
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
104 |
| mthd class | |
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
105 |
|
13200
74d83643473b
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13107
diff
changeset
|
106 |
mthd := codeView method. |
10486 | 107 |
(mthd notNil and:[app respondsTo: #syntaxHighlighterForMethod:]) ifTrue:[ |
108 |
highlighter := app syntaxHighlighterForMethod:mthd. |
|
109 |
] ifFalse:[ |
|
11617 | 110 |
class := codeView classHolder value. |
10486 | 111 |
(class notNil and:[app respondsTo: #syntaxHighlighterForClass:]) ifTrue:[ |
112 |
highlighter := app syntaxHighlighterForClass: class. |
|
10721
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
113 |
] ifFalse:[ |
14487
ec94f1fcdf94
class: Tools::CodeHighlightingService
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14486
diff
changeset
|
114 |
(app respondsTo: #syntaxHighlighter) ifTrue:[ |
14486
c8b1e2d7dc46
class: Tools::CodeHighlightingService
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13867
diff
changeset
|
115 |
highlighter := app syntaxHighlighter. |
10721
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
116 |
]. |
10486 | 117 |
]. |
118 |
] |
|
119 |
]. |
|
120 |
"App did not provide any highlighter..." |
|
121 |
highlighter isNil ifTrue:[ |
|
11544
e82e2d8be007
changed: #syntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
11384
diff
changeset
|
122 |
highlighter := (lang := codeView language) isNil |
e82e2d8be007
changed: #syntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
11384
diff
changeset
|
123 |
ifTrue:[nil] |
e82e2d8be007
changed: #syntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
11384
diff
changeset
|
124 |
ifFalse:[lang syntaxHighlighterClass]. |
10486 | 125 |
]. |
126 |
"HACK!!!!!!" |
|
127 |
highlighter == SyntaxHighlighter ifTrue:[ |
|
128 |
highlighter := SyntaxHighlighter2 |
|
129 |
]. |
|
130 |
^ highlighter |
|
131 |
||
132 |
"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
|
133 |
"Modified: / 22-07-2013 / 13:33:46 / cg" |
14487
ec94f1fcdf94
class: Tools::CodeHighlightingService
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14486
diff
changeset
|
134 |
"Modified: / 10-06-2014 / 17:58:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10486 | 135 |
! |
136 |
||
137 |
syntaxHighlighters |
|
13867 | 138 |
|
139 |
| highlighters highlighter | |
|
10486 | 140 |
|
17716 | 141 |
highlighters := OrderedCollection new. |
13867 | 142 |
highlighter := self syntaxHighlighter. |
143 |
highlighter notNil ifTrue:[ |
|
15827
e1a8c9093e23
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15805
diff
changeset
|
144 |
"/ 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
|
145 |
"/ highlighter class == Workflow::ExecutionEditorShellScript::NaiveShellScriptSyntaxHighlighter ifTrue:[self halt]. |
e1a8c9093e23
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15805
diff
changeset
|
146 |
"/ highlighter == Workflow::ExecutionEditorShellScript::NaiveShellScriptSyntaxHighlighter ifTrue:[self halt]. |
13867 | 147 |
highlighters add: highlighter |
148 |
]. |
|
10486 | 149 |
|
14928
3c11ff12d0bc
Fixes for enabling / disabling individual CodeView2 services.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14784
diff
changeset
|
150 |
codeView servicesDo:[:service| |
13867 | 151 |
service ~~ self ifTrue:[ |
152 |
highlighter := service syntaxHighlighter. |
|
153 |
highlighter notNil ifTrue:[ |
|
15827
e1a8c9093e23
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15805
diff
changeset
|
154 |
"/ 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
|
155 |
"/ highlighter class == Workflow::ExecutionEditorShellScript::NaiveShellScriptSyntaxHighlighter ifTrue:[self halt]. |
e1a8c9093e23
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15805
diff
changeset
|
156 |
"/ highlighter == Workflow::ExecutionEditorShellScript::NaiveShellScriptSyntaxHighlighter ifTrue:[self halt]. |
10486 | 157 |
highlighters add: highlighter |
158 |
]. |
|
159 |
] |
|
160 |
]. |
|
161 |
^highlighters |
|
162 |
||
163 |
"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
|
164 |
"Modified: / 27-11-2014 / 15:42:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
17716 | 165 |
"Modified: / 21-10-2017 / 12:58:40 / cg" |
10486 | 166 |
! ! |
167 |
||
16762 | 168 |
!CodeHighlightingService methodsFor:'accessing-defaults'! |
9980 | 169 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
170 |
defaultJobName |
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
171 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
172 |
^'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
|
173 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
174 |
"Created: / 24-01-2012 / 12:06:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10420 | 175 |
! ! |
176 |
||
9980 | 177 |
!CodeHighlightingService methodsFor:'private'! |
178 |
||
16621 | 179 |
clearScrollbarBackground |
180 |
"/ immediate change the scroller back to showing nothing; |
|
181 |
"/ will get new info, when the highlighter is finished. |
|
182 |
||
183 |
|scroller| |
|
184 |
||
185 |
codeView notNil ifTrue:[ |
|
186 |
scroller := textView superView verticalScrollBar thumb. |
|
187 |
scroller shown ifTrue:[ |
|
188 |
scroller |
|
189 |
initStyle ; |
|
190 |
invalidateRepairNow:true. |
|
191 |
] |
|
192 |
]. |
|
193 |
! |
|
194 |
||
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
195 |
process |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
196 |
"(Re)starts the processing job. Should be called whenever a source |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
197 |
must be (re)processed." |
9980 | 198 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
199 |
| highlighters | |
9980 | 200 |
|
10721
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
201 |
(highlighters := self syntaxHighlighters) isEmptyOrNil ifTrue:[ |
10486 | 202 |
"No higlighter, nothing to do" |
10968
5e738ee1cd2a
No highlighting by default (either method or language must be set)
vrany
parents:
10961
diff
changeset
|
203 |
^self |
10420 | 204 |
]. |
9980 | 205 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
206 |
super process. |
10420 | 207 |
|
208 |
"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
|
209 |
"Modified: / 26-09-2011 / 15:40:23 / cg" |
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
210 |
"Created: / 24-01-2012 / 12:11:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10420 | 211 |
! |
212 |
||
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
213 |
process: delayed |
17716 | 214 |
|oldCode oldCodeList newCode elements cls mthd highlighterClasses| |
13867 | 215 |
|
17716 | 216 |
"/ codeView topView class == DebugView ifTrue:[^ self]. |
11617 | 217 |
|
10420 | 218 |
done := false. |
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
219 |
modified := false. |
10420 | 220 |
codeView syntaxElements: nil. |
221 |
codeView syntaxElementSelection: nil. |
|
222 |
||
10486 | 223 |
highlighterClasses := self syntaxHighlighters. |
17716 | 224 |
highlighterClasses isEmptyOrNil ifTrue:[^ self]. |
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]. |
17166 | 268 |
] ifFalse:[codeAspect == SyntaxHighlighter codeAspectExpression ifTrue:[ |
269 |
highlighterClasses do:[:e|newCode := e formatExpression:newCode in:cls elementsInto: elements]. |
|
270 |
] ifFalse:[codeAspect == SyntaxHighlighter codeAspectClassDefinition ifTrue:[ |
|
271 |
highlighterClasses do:[:e|newCode := e formatClassDefinition:newCode string in:cls elementsInto: elements]. |
|
17716 | 272 |
] ifFalse:[codeAspect == SyntaxHighlighter codeAspectFile ifTrue:[ |
273 |
highlighterClasses do:[:e|newCode := e formatFileContents:newCode string elementsInto: elements]. |
|
274 |
] ifFalse:[codeAspect isNil ifTrue:[ |
|
275 |
highlighterClasses do:[:e|newCode := e formatFileContents:newCode string elementsInto: elements]. |
|
276 |
]]]]]. |
|
15447
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
277 |
"/ ] |
10486 | 278 |
]. |
279 |
newCode notNil ifTrue:[ |
|
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
280 |
"textView" modified ifFalse:[ |
10486 | 281 |
newCode ~= oldCodeList ifTrue:[ |
282 |
newCode := newCode asStringCollection. |
|
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
283 |
"textView" modified ifFalse:[ |
10486 | 284 |
done := true. |
285 |
textView notNil ifTrue:[ |
|
286 |
"/ must add this event - and not been interrupted |
|
287 |
"/ by any arriving key-event. |
|
288 |
"/ self showInfo:nil. |
|
289 |
delayed ifTrue:[ |
|
290 |
codeView sensor |
|
291 |
pushUserEvent:#setHighlightedCode:elements: |
|
292 |
for:self |
|
293 |
withArguments:(Array with:newCode with: elements). |
|
294 |
"/self delayedUpdateBufferLabelWithCheckIfModified |
|
295 |
] ifFalse:[ |
|
296 |
textView contents: newCode. |
|
13867 | 297 |
codeView syntaxElements: elements. |
298 |
gutterView invalidate. |
|
16621 | 299 |
codeView updateScrollersViewBackground. |
10486 | 300 |
] |
301 |
] |
|
302 |
] |
|
303 |
]. |
|
304 |
] |
|
305 |
] |
|
306 |
] |
|
307 |
] |
|
308 |
] |
|
10420 | 309 |
] |
9980 | 310 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
311 |
"Created: / 24-01-2012 / 12:21:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
17716 | 312 |
"Modified: / 21-10-2017 / 13:29:53 / cg" |
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
313 |
! |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
314 |
|
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
315 |
setHighlightedCode:newCode elements: elements |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
316 |
"the background synhighlighter has generated new colored text, |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
317 |
with highlighted syntax. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
318 |
If there have been no modifications in the meantime, install it." |
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 |
|firstShown lastShown cursorWasOn anyChange newLines l replaceAction list| |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
321 |
|
14784
0e0fc09a7a62
BrowserEnvironment is now polymorphic with ParseTreeEnvironment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14487
diff
changeset
|
322 |
"/ 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
|
323 |
"/ 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
|
324 |
"/ 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
|
325 |
"/ 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
|
326 |
textView isNil ifTrue:[ ^ self ]. |
9980 | 327 |
|
14784
0e0fc09a7a62
BrowserEnvironment is now polymorphic with ParseTreeEnvironment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14487
diff
changeset
|
328 |
|
0e0fc09a7a62
BrowserEnvironment is now polymorphic with ParseTreeEnvironment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14487
diff
changeset
|
329 |
modified ifTrue:[ |
0e0fc09a7a62
BrowserEnvironment is now polymorphic with ParseTreeEnvironment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14487
diff
changeset
|
330 |
"/ 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
|
331 |
^ self |
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
332 |
]. |
14784
0e0fc09a7a62
BrowserEnvironment is now polymorphic with ParseTreeEnvironment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14487
diff
changeset
|
333 |
|
11611 | 334 |
done ifFalse:[ |
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
335 |
"/ another coloring process has already been started. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
336 |
"/ ignore this (leftover) code. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
337 |
^ self |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
338 |
]. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
339 |
|
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
340 |
firstShown := textView firstLineShown. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
341 |
lastShown := textView lastLineShown. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
342 |
|
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
343 |
replaceAction := [:lNr :line | |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
344 |
|oldLine| |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
345 |
|
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
346 |
oldLine := list at:lNr ifAbsent:nil. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
347 |
oldLine notNil ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
348 |
line notNil ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
349 |
"/ this check is needed - there is a race |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
350 |
"/ when the text is converted. This detects the |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
351 |
"/ resulting error. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
352 |
"/ Certainly a kludge. |
10410 | 353 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
354 |
oldLine string = line string ifTrue:[ |
13867 | 355 |
| i | |
356 |
||
357 |
"JV@2012-02-01: Remove any emphasis on leading whitespace" |
|
358 |
"(presumably created by LintHighlighter)" |
|
359 |
i := line string indexOfNonSeparator. |
|
360 |
i > 1 ifTrue:[ |
|
361 |
| e | |
|
362 |
||
363 |
(e := (line emphasisAt: i - 1)) notNil ifTrue:[ |
|
364 |
line emphasisFrom: 1 to: i - 1 remove: e. |
|
365 |
] |
|
366 |
]. |
|
367 |
||
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
368 |
oldLine emphasis ~= line emphasis ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
369 |
textView modifiedChannel removeDependent:self. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
370 |
list at:lNr put:line. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
371 |
textView modifiedChannel addDependent:self. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
372 |
(lNr between:firstShown and:lastShown) ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
373 |
anyChange ifFalse:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
374 |
anyChange := true. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
375 |
cursorWasOn := textView hideCursor |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
376 |
]. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
377 |
textView redrawLine:lNr |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
378 |
] |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
379 |
] |
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 |
] |
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 |
]. |
10410 | 384 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
385 |
anyChange := false. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
386 |
newLines := newCode asStringCollection. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
387 |
list := textView list. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
388 |
list isNil ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
389 |
textView list:newLines. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
390 |
] ifFalse:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
391 |
"/ 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
|
392 |
((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
|
393 |
l <= newLines size ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
394 |
replaceAction value:l value:(newLines at:l) |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
395 |
] |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
396 |
]. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
397 |
newLines keysAndValuesDo:replaceAction. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
398 |
anyChange ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
399 |
cursorWasOn ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
400 |
textView showCursor |
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 |
] |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
403 |
]. |
13867 | 404 |
codeView syntaxElements: elements. |
405 |
gutterView invalidate. |
|
16621 | 406 |
codeView updateScrollersViewBackground. |
407 |
||
13867 | 408 |
"/ Transcript showCR:'--> rehighlighted ', self identityHash printString. |
10410 | 409 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
410 |
"Modified: / 09-10-2006 / 11:50:17 / cg" |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
411 |
"Created: / 14-02-2010 / 16:10:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
13867 | 412 |
"Modified (format): / 21-08-2011 / 09:38:22 / cg" |
413 |
"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
|
414 |
"Modified: / 20-01-2015 / 15:17:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10410 | 415 |
! ! |
416 |
||
9980 | 417 |
!CodeHighlightingService class methodsFor:'documentation'! |
418 |
||
10497 | 419 |
version |
15789
3c5227646c1f
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15447
diff
changeset
|
420 |
^ '$Header$' |
10497 | 421 |
! |
422 |
||
9980 | 423 |
version_CVS |
15789
3c5227646c1f
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15447
diff
changeset
|
424 |
^ '$Header$' |
9980 | 425 |
! |
426 |
||
427 |
version_SVN |
|
15789
3c5227646c1f
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15447
diff
changeset
|
428 |
^ '$Id$' |
9980 | 429 |
! ! |
12099
d3315fdc1c92
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
11705
diff
changeset
|
430 |