author | Claus Gittinger <cg@exept.de> |
Wed, 09 Dec 2015 18:57:19 +0100 | |
changeset 15983 | 91d46574eaea |
parent 15827 | e1a8c9093e23 |
child 15828 | 833ae1c37126 |
child 16621 | fc007552c263 |
permissions | -rw-r--r-- |
15827
e1a8c9093e23
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15805
diff
changeset
|
1 |
"{ Encoding: utf8 }" |
e1a8c9093e23
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15805
diff
changeset
|
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 |
||
15789
3c5227646c1f
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15447
diff
changeset
|
69 |
|
9980 | 70 |
!CodeHighlightingService class methodsFor:'accessing'! |
71 |
||
72 |
label |
|
13102 | 73 |
"Answers a short label - for UI" |
9980 | 74 |
|
75 |
^'Syntax Highlighting' |
|
76 |
||
77 |
"Created: / 07-03-2010 / 14:00:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
78 |
! ! |
|
79 |
||
13207 | 80 |
!CodeHighlightingService class methodsFor:'testing'! |
81 |
||
82 |
isUsefulFor:aCodeView |
|
83 |
"this filters useful services. |
|
84 |
Redefined to return true for myself - not for subclasses" |
|
85 |
||
86 |
^ self == Tools::CodeHighlightingService |
|
87 |
||
88 |
"Created: / 22-07-2013 / 14:00:54 / cg" |
|
89 |
! ! |
|
90 |
||
10486 | 91 |
!CodeHighlightingService methodsFor:'accessing'! |
92 |
||
13107 | 93 |
preferences:preferences |
94 |
"must be able to set those - otherwise, it uses a different coloring scheme in |
|
95 |
expecco" |
|
96 |
||
97 |
syntaxPreferences := preferences. |
|
98 |
! |
|
99 |
||
10486 | 100 |
syntaxHighlighter |
10721
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
101 |
| app lang highlighter | |
10486 | 102 |
|
103 |
"First, ask application..." |
|
104 |
app := codeView application. |
|
105 |
app notNil ifTrue:[ |
|
10721
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
106 |
| mthd class | |
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
107 |
|
13200
74d83643473b
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13107
diff
changeset
|
108 |
mthd := codeView method. |
10486 | 109 |
(mthd notNil and:[app respondsTo: #syntaxHighlighterForMethod:]) ifTrue:[ |
110 |
highlighter := app syntaxHighlighterForMethod:mthd. |
|
111 |
] ifFalse:[ |
|
11617 | 112 |
class := codeView classHolder value. |
10486 | 113 |
(class notNil and:[app respondsTo: #syntaxHighlighterForClass:]) ifTrue:[ |
114 |
highlighter := app syntaxHighlighterForClass: class. |
|
10721
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
115 |
] ifFalse:[ |
14487
ec94f1fcdf94
class: Tools::CodeHighlightingService
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14486
diff
changeset
|
116 |
(app respondsTo: #syntaxHighlighter) ifTrue:[ |
14486
c8b1e2d7dc46
class: Tools::CodeHighlightingService
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
13867
diff
changeset
|
117 |
highlighter := app syntaxHighlighter. |
10721
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
118 |
]. |
10486 | 119 |
]. |
120 |
] |
|
121 |
]. |
|
122 |
"App did not provide any highlighter..." |
|
123 |
highlighter isNil ifTrue:[ |
|
11544
e82e2d8be007
changed: #syntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
11384
diff
changeset
|
124 |
highlighter := (lang := codeView language) isNil |
e82e2d8be007
changed: #syntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
11384
diff
changeset
|
125 |
ifTrue:[nil] |
e82e2d8be007
changed: #syntaxHighlighter
Claus Gittinger <cg@exept.de>
parents:
11384
diff
changeset
|
126 |
ifFalse:[lang syntaxHighlighterClass]. |
10486 | 127 |
]. |
128 |
"HACK!!!!!!" |
|
129 |
highlighter == SyntaxHighlighter ifTrue:[ |
|
130 |
highlighter := SyntaxHighlighter2 |
|
131 |
]. |
|
132 |
^ highlighter |
|
133 |
||
134 |
"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
|
135 |
"Modified: / 22-07-2013 / 13:33:46 / cg" |
14487
ec94f1fcdf94
class: Tools::CodeHighlightingService
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14486
diff
changeset
|
136 |
"Modified: / 10-06-2014 / 17:58:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10486 | 137 |
! |
138 |
||
139 |
syntaxHighlighters |
|
13867 | 140 |
|
141 |
| highlighters highlighter | |
|
10486 | 142 |
|
13867 | 143 |
highlighters := OrderedCollection new: 4. |
144 |
highlighter := self syntaxHighlighter. |
|
145 |
highlighter notNil ifTrue:[ |
|
15827
e1a8c9093e23
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15805
diff
changeset
|
146 |
"/ 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
|
147 |
"/ highlighter class == Workflow::ExecutionEditorShellScript::NaiveShellScriptSyntaxHighlighter ifTrue:[self halt]. |
e1a8c9093e23
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15805
diff
changeset
|
148 |
"/ highlighter == Workflow::ExecutionEditorShellScript::NaiveShellScriptSyntaxHighlighter ifTrue:[self halt]. |
13867 | 149 |
highlighters add: highlighter |
150 |
]. |
|
10486 | 151 |
|
14928
3c11ff12d0bc
Fixes for enabling / disabling individual CodeView2 services.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14784
diff
changeset
|
152 |
codeView servicesDo:[:service| |
13867 | 153 |
service ~~ self ifTrue:[ |
154 |
highlighter := service syntaxHighlighter. |
|
155 |
highlighter notNil ifTrue:[ |
|
15827
e1a8c9093e23
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15805
diff
changeset
|
156 |
"/ 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
|
157 |
"/ highlighter class == Workflow::ExecutionEditorShellScript::NaiveShellScriptSyntaxHighlighter ifTrue:[self halt]. |
e1a8c9093e23
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15805
diff
changeset
|
158 |
"/ highlighter == Workflow::ExecutionEditorShellScript::NaiveShellScriptSyntaxHighlighter ifTrue:[self halt]. |
10486 | 159 |
highlighters add: highlighter |
160 |
]. |
|
161 |
] |
|
162 |
]. |
|
163 |
^highlighters |
|
164 |
||
165 |
"Created: / 05-08-2011 / 10:49:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
13867 | 166 |
"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
|
167 |
"Modified: / 27-11-2014 / 15:42:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10486 | 168 |
! ! |
169 |
||
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
170 |
!CodeHighlightingService methodsFor:'acessing-defaults'! |
9980 | 171 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
172 |
defaultJobName |
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 |
^'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
|
175 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
176 |
"Created: / 24-01-2012 / 12:06:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10420 | 177 |
! ! |
178 |
||
9980 | 179 |
!CodeHighlightingService methodsFor:'private'! |
180 |
||
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
181 |
process |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
182 |
"(Re)starts the processing job. Should be called whenever a source |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
183 |
must be (re)processed." |
9980 | 184 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
185 |
| highlighters | |
9980 | 186 |
|
10721
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
187 |
(highlighters := self syntaxHighlighters) isEmptyOrNil ifTrue:[ |
10486 | 188 |
"No higlighter, nothing to do" |
10968
5e738ee1cd2a
No highlighting by default (either method or language must be set)
vrany
parents:
10961
diff
changeset
|
189 |
^self |
10420 | 190 |
]. |
9980 | 191 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
192 |
super process. |
10420 | 193 |
|
194 |
"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
|
195 |
"Modified: / 26-09-2011 / 15:40:23 / cg" |
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
196 |
"Created: / 24-01-2012 / 12:11:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10420 | 197 |
! |
198 |
||
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
199 |
process: delayed |
13867 | 200 |
|
10486 | 201 |
|oldCode oldCodeList newCode elements cls mthd highlighterClasses| |
13588
0701806de907
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13554
diff
changeset
|
202 |
"/ codeView topView class == DebugView ifTrue:[^ self]. |
11617 | 203 |
|
10420 | 204 |
done := false. |
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
205 |
modified := false. |
10420 | 206 |
codeView syntaxElements: nil. |
207 |
codeView syntaxElementSelection: nil. |
|
208 |
||
10486 | 209 |
highlighterClasses := self syntaxHighlighters. |
10149 | 210 |
|
10420 | 211 |
cls := codeView klass. |
212 |
(cls notNil and:[cls isObsolete]) ifTrue:[ |
|
10486 | 213 |
cls isMeta ifTrue:[ |
214 |
cls := (Smalltalk at:cls theNonMetaclass name) class |
|
215 |
] ifFalse:[ |
|
216 |
cls := Smalltalk at:cls name |
|
217 |
]. |
|
10420 | 218 |
]. |
13200
74d83643473b
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13107
diff
changeset
|
219 |
mthd := codeView method. |
10149 | 220 |
|
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
221 |
"textView" modified ifFalse:[ |
13554
0c5bc183802b
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13263
diff
changeset
|
222 |
"/ bad bad bad: textView's list may change, while we copy!!!!!!!!!! |
0c5bc183802b
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13263
diff
changeset
|
223 |
[ |
0c5bc183802b
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13263
diff
changeset
|
224 |
oldCodeList := textView list copy. |
0c5bc183802b
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13263
diff
changeset
|
225 |
] valueUninterruptably. |
0c5bc183802b
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
13263
diff
changeset
|
226 |
|
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
227 |
"textView" modified ifFalse:[ |
10486 | 228 |
oldCodeList isNil ifFalse:[ |
15805
aa12f05014e6
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15789
diff
changeset
|
229 |
oldCode := oldCodeList asStringCollection asStringWithoutEmphasis. |
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
230 |
"textView" modified ifFalse:[ |
10486 | 231 |
Screen currentScreenQuerySignal answer:codeView device |
232 |
do:[ |
|
15447
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
233 |
"/ cg: not a ood idea to handle it here; |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
234 |
"/ Syntaxhighlighter does it also, and will generate a better colorized string |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
235 |
"/ Parser parseErrorSignal handle:[:ex | |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
236 |
"/ |errMsg| |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
237 |
"/ |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
238 |
"/ errMsg := ex description asStringCollection first asString. |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
239 |
"/ |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
240 |
"/ "/ Transcript topView raiseDeiconified. |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
241 |
"/ Transcript showCR:'Error caught: ', ex description. |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
242 |
"/ "/ self halt. |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
243 |
"/ "/ self showInfo:(errMsg colorizeAllWith:Color red). |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
244 |
"/ newCode := nil. |
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
245 |
"/ ] do:[ |
13867 | 246 |
| codeAspect | |
247 |
||
248 |
elements := ParseTreeIndex new. |
|
10486 | 249 |
newCode := oldCode asText. |
11705 | 250 |
codeAspect := codeView codeAspect. |
251 |
codeAspect == SyntaxHighlighter codeAspectMethod ifTrue:[ |
|
13107 | 252 |
highlighterClasses do:[:e|newCode := e formatMethod:mthd source:newCode in:cls using:syntaxPreferences elementsInto: elements]. |
10486 | 253 |
] ifFalse:[ |
11705 | 254 |
codeAspect == (SyntaxHighlighter codeAspectExpression) ifTrue:[ |
13867 | 255 |
highlighterClasses do:[:e|newCode := e formatExpression:newCode in:cls elementsInto: elements]. |
10486 | 256 |
] ifFalse:[ |
11705 | 257 |
codeAspect == (SyntaxHighlighter codeAspectClassDefinition) ifTrue:[ |
11384 | 258 |
highlighterClasses do:[:e|newCode := e formatClassDefinition:newCode string in:cls elementsInto: elements]. |
10486 | 259 |
] |
260 |
]. |
|
261 |
]. |
|
15447
1bad1d4218b5
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15094
diff
changeset
|
262 |
"/ ] |
10486 | 263 |
]. |
264 |
newCode notNil ifTrue:[ |
|
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
265 |
"textView" modified ifFalse:[ |
10486 | 266 |
newCode ~= oldCodeList ifTrue:[ |
267 |
newCode := newCode asStringCollection. |
|
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
268 |
"textView" modified ifFalse:[ |
10486 | 269 |
done := true. |
270 |
textView notNil ifTrue:[ |
|
271 |
"/ must add this event - and not been interrupted |
|
272 |
"/ by any arriving key-event. |
|
273 |
"/ self showInfo:nil. |
|
274 |
delayed ifTrue:[ |
|
275 |
codeView sensor |
|
276 |
pushUserEvent:#setHighlightedCode:elements: |
|
277 |
for:self |
|
278 |
withArguments:(Array with:newCode with: elements). |
|
279 |
"/self delayedUpdateBufferLabelWithCheckIfModified |
|
280 |
] ifFalse:[ |
|
281 |
textView contents: newCode. |
|
13867 | 282 |
codeView syntaxElements: elements. |
283 |
gutterView invalidate. |
|
10486 | 284 |
] |
285 |
] |
|
286 |
] |
|
287 |
]. |
|
288 |
] |
|
289 |
] |
|
290 |
] |
|
291 |
] |
|
292 |
] |
|
10420 | 293 |
] |
9980 | 294 |
|
13867 | 295 |
"Modified: / 22-08-2011 / 14:17:47 / cg" |
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
296 |
"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
|
297 |
"Modified: / 22-07-2013 / 13:33:40 / cg" |
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
298 |
! |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
299 |
|
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
300 |
setHighlightedCode:newCode elements: elements |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
301 |
"the background synhighlighter has generated new colored text, |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
302 |
with highlighted syntax. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
303 |
If there have been no modifications in the meantime, install it." |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
304 |
|
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
305 |
|firstShown lastShown cursorWasOn anyChange newLines l replaceAction list| |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
306 |
|
14784
0e0fc09a7a62
BrowserEnvironment is now polymorphic with ParseTreeEnvironment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14487
diff
changeset
|
307 |
"/ 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
|
308 |
"/ 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
|
309 |
"/ 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
|
310 |
"/ 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
|
311 |
textView isNil ifTrue:[ ^ self ]. |
9980 | 312 |
|
14784
0e0fc09a7a62
BrowserEnvironment is now polymorphic with ParseTreeEnvironment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14487
diff
changeset
|
313 |
|
0e0fc09a7a62
BrowserEnvironment is now polymorphic with ParseTreeEnvironment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14487
diff
changeset
|
314 |
modified ifTrue:[ |
0e0fc09a7a62
BrowserEnvironment is now polymorphic with ParseTreeEnvironment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14487
diff
changeset
|
315 |
"/ 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
|
316 |
^ self |
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
317 |
]. |
14784
0e0fc09a7a62
BrowserEnvironment is now polymorphic with ParseTreeEnvironment
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14487
diff
changeset
|
318 |
|
11611 | 319 |
done ifFalse:[ |
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
320 |
"/ another coloring process has already been started. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
321 |
"/ ignore this (leftover) code. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
322 |
^ self |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
323 |
]. |
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 := textView firstLineShown. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
326 |
lastShown := textView lastLineShown. |
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 |
replaceAction := [:lNr :line | |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
329 |
|oldLine| |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
330 |
|
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
331 |
oldLine := list at:lNr ifAbsent:nil. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
332 |
oldLine notNil ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
333 |
line notNil ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
334 |
"/ this check is needed - there is a race |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
335 |
"/ when the text is converted. This detects the |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
336 |
"/ resulting error. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
337 |
"/ Certainly a kludge. |
10410 | 338 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
339 |
oldLine string = line string ifTrue:[ |
13867 | 340 |
| i | |
341 |
||
342 |
"JV@2012-02-01: Remove any emphasis on leading whitespace" |
|
343 |
"(presumably created by LintHighlighter)" |
|
344 |
i := line string indexOfNonSeparator. |
|
345 |
i > 1 ifTrue:[ |
|
346 |
| e | |
|
347 |
||
348 |
(e := (line emphasisAt: i - 1)) notNil ifTrue:[ |
|
349 |
line emphasisFrom: 1 to: i - 1 remove: e. |
|
350 |
] |
|
351 |
]. |
|
352 |
||
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
353 |
oldLine emphasis ~= line emphasis ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
354 |
textView modifiedChannel removeDependent:self. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
355 |
list at:lNr put:line. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
356 |
textView modifiedChannel addDependent:self. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
357 |
(lNr between:firstShown and:lastShown) ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
358 |
anyChange ifFalse:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
359 |
anyChange := true. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
360 |
cursorWasOn := textView hideCursor |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
361 |
]. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
362 |
textView redrawLine:lNr |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
363 |
] |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
364 |
] |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
365 |
] |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
366 |
] |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
367 |
] |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
368 |
]. |
10410 | 369 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
370 |
anyChange := false. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
371 |
newLines := newCode asStringCollection. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
372 |
list := textView list. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
373 |
list isNil ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
374 |
textView list:newLines. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
375 |
] ifFalse:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
376 |
"/ 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
|
377 |
((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
|
378 |
l <= newLines size ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
379 |
replaceAction value:l value:(newLines at:l) |
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 |
newLines keysAndValuesDo:replaceAction. |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
383 |
anyChange ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
384 |
cursorWasOn ifTrue:[ |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
385 |
textView showCursor |
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 |
]. |
13867 | 389 |
codeView syntaxElements: elements. |
390 |
gutterView invalidate. |
|
391 |
||
392 |
"/ Transcript showCR:'--> rehighlighted ', self identityHash printString. |
|
10410 | 393 |
|
11181
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
394 |
"Modified: / 09-10-2006 / 11:50:17 / cg" |
f04a38c369c9
CodeView2 service refactoring: CodeHighlightingService's background
vrany
parents:
11171
diff
changeset
|
395 |
"Created: / 14-02-2010 / 16:10:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
13867 | 396 |
"Modified (format): / 21-08-2011 / 09:38:22 / cg" |
397 |
"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
|
398 |
"Modified: / 20-01-2015 / 15:17:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10410 | 399 |
! ! |
400 |
||
9980 | 401 |
!CodeHighlightingService class methodsFor:'documentation'! |
402 |
||
10497 | 403 |
version |
15789
3c5227646c1f
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15447
diff
changeset
|
404 |
^ '$Header$' |
10497 | 405 |
! |
406 |
||
9980 | 407 |
version_CVS |
15789
3c5227646c1f
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15447
diff
changeset
|
408 |
^ '$Header$' |
9980 | 409 |
! |
410 |
||
411 |
version_SVN |
|
15789
3c5227646c1f
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
15447
diff
changeset
|
412 |
^ '$Id$' |
9980 | 413 |
! ! |
12099
d3315fdc1c92
class: Tools::CodeHighlightingService
Claus Gittinger <cg@exept.de>
parents:
11705
diff
changeset
|
414 |