author | vrany |
Wed, 28 Sep 2011 01:28:42 +0200 | |
changeset 10729 | f4109bfaad31 |
parent 10721 | 6813188d742b |
child 10954 | ba2dc0bd7290 |
permissions | -rw-r--r-- |
9980 | 1 |
" |
10077 | 2 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague |
10440
ad79e93dc9b7
no need to access BackgroundJob via Smalltalk - the bug
Claus Gittinger <cg@exept.de>
parents:
10439
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 |
||
30 |
CodeViewService subclass:#CodeHighlightingService |
|
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
31 |
instanceVariableNames:'job done modified' |
10439
6a41520db1be
variable renamed in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10438
diff
changeset
|
32 |
classVariableNames:'' |
6a41520db1be
variable renamed in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10438
diff
changeset
|
33 |
poolDictionaries:'' |
6a41520db1be
variable renamed in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10438
diff
changeset
|
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 |
10440
ad79e93dc9b7
no need to access BackgroundJob via Smalltalk - the bug
Claus Gittinger <cg@exept.de>
parents:
10439
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 |
||
67 |
!CodeHighlightingService class methodsFor:'accessing'! |
|
68 |
||
69 |
label |
|
70 |
||
71 |
"Answers short label - for UI" |
|
72 |
||
73 |
^'Syntax Highlighting' |
|
74 |
||
75 |
"Created: / 07-03-2010 / 14:00:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
76 |
! ! |
|
77 |
||
10486 | 78 |
!CodeHighlightingService methodsFor:'accessing'! |
79 |
||
80 |
syntaxHighlighter |
|
10721
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
81 |
| app lang highlighter | |
10486 | 82 |
|
83 |
"First, ask application..." |
|
84 |
app := codeView application. |
|
85 |
app notNil ifTrue:[ |
|
10721
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
86 |
| mthd class | |
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
87 |
|
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
88 |
mthd := codeView methodHolder value. |
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
89 |
class := codeView classHolder value. |
10486 | 90 |
(mthd notNil and:[app respondsTo: #syntaxHighlighterForMethod:]) ifTrue:[ |
91 |
highlighter := app syntaxHighlighterForMethod:mthd. |
|
92 |
] ifFalse:[ |
|
93 |
(class notNil and:[app respondsTo: #syntaxHighlighterForClass:]) ifTrue:[ |
|
94 |
highlighter := app syntaxHighlighterForClass: class. |
|
10721
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
95 |
] ifFalse:[ |
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
96 |
(class notNil and:[app respondsTo: #syntaxHighlighter]) ifTrue:[ |
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
97 |
highlighter := app syntaxHighlighterClass. |
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
98 |
]. |
10486 | 99 |
]. |
100 |
] |
|
101 |
]. |
|
102 |
"App did not provide any highlighter..." |
|
103 |
highlighter isNil ifTrue:[ |
|
10729 | 104 |
highlighter := (lang := codeView language) |
10486 | 105 |
ifNil:[nil] |
106 |
ifNotNil:[lang syntaxHighlighterClass]. |
|
107 |
]. |
|
108 |
"HACK!!!!!!" |
|
109 |
highlighter == SyntaxHighlighter ifTrue:[ |
|
110 |
highlighter := SyntaxHighlighter2 |
|
111 |
]. |
|
112 |
^ highlighter |
|
113 |
||
114 |
"Created: / 05-08-2011 / 10:48:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10721
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
115 |
"Modified: / 26-09-2011 / 15:50:10 / cg" |
10729 | 116 |
"Modified: / 28-09-2011 / 00:23:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10486 | 117 |
! |
118 |
||
119 |
syntaxHighlighters |
|
120 |
||
121 |
| highlighters | |
|
122 |
||
123 |
highlighters := OrderedCollection new: 4. |
|
124 |
||
125 |
codeView services do:[:service| |
|
126 |
| highlighter | |
|
127 |
highlighter := service syntaxHighlighter. |
|
128 |
highlighter notNil ifTrue:[ |
|
129 |
"HACK, since AbstractSyntaxHighlighter overwrite |
|
130 |
emphasis instead of adding it..." |
|
131 |
(highlighter isKindOf: AbstractSyntaxHighlighter class) ifTrue:[ |
|
132 |
highlighters addFirst: highlighter |
|
133 |
] ifFalse:[ |
|
134 |
highlighters add: highlighter |
|
135 |
]. |
|
136 |
] |
|
137 |
]. |
|
138 |
||
139 |
^highlighters |
|
140 |
||
141 |
"Created: / 05-08-2011 / 10:49:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
142 |
! ! |
|
143 |
||
9980 | 144 |
!CodeHighlightingService methodsFor:'change & update'! |
145 |
||
146 |
update: aspect with: param from: sender |
|
10701
741e06a3136f
changed: #update:with:from:
Claus Gittinger <cg@exept.de>
parents:
10660
diff
changeset
|
147 |
textView notNil ifTrue:[ |
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
148 |
"/sender == textView modifiedChannel ifTrue:[^self codeChanged: false]. |
10701
741e06a3136f
changed: #update:with:from:
Claus Gittinger <cg@exept.de>
parents:
10660
diff
changeset
|
149 |
sender == textView model ifTrue:[^self codeChanged: true]. |
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
150 |
(sender == textView and:[aspect == #sizeOfContents]) ifTrue:[^self codeChanged: true]. |
10701
741e06a3136f
changed: #update:with:from:
Claus Gittinger <cg@exept.de>
parents:
10660
diff
changeset
|
151 |
]. |
741e06a3136f
changed: #update:with:from:
Claus Gittinger <cg@exept.de>
parents:
10660
diff
changeset
|
152 |
codeView notNil ifTrue:[ |
741e06a3136f
changed: #update:with:from:
Claus Gittinger <cg@exept.de>
parents:
10660
diff
changeset
|
153 |
sender == codeView languageHolder ifTrue:[^self codeChanged: true]. |
741e06a3136f
changed: #update:with:from:
Claus Gittinger <cg@exept.de>
parents:
10660
diff
changeset
|
154 |
sender == codeView classHolder ifTrue:[^self codeChanged: true]. |
741e06a3136f
changed: #update:with:from:
Claus Gittinger <cg@exept.de>
parents:
10660
diff
changeset
|
155 |
]. |
9980 | 156 |
super update: aspect with: param from: sender |
157 |
||
158 |
"Created: / 06-03-2010 / 19:38:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10701
741e06a3136f
changed: #update:with:from:
Claus Gittinger <cg@exept.de>
parents:
10660
diff
changeset
|
159 |
"Modified: / 13-09-2011 / 12:00:29 / cg" |
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
160 |
"Modified: / 16-09-2011 / 17:30:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
161 |
! ! |
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
162 |
|
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
163 |
!CodeHighlightingService methodsFor:'event handling'! |
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
164 |
|
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
165 |
linesDeletedFrom: start to: end |
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
166 |
|
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
167 |
self codeChanged: true |
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
168 |
|
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
169 |
"Created: / 06-07-2011 / 17:14:36 / jv" |
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
170 |
"Created: / 16-09-2011 / 15:18:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
171 |
! |
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
172 |
|
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
173 |
linesInsertedFrom: start to: end |
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
174 |
|
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
175 |
self codeChanged: true |
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
176 |
|
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
177 |
"Created: / 06-07-2011 / 17:14:36 / jv" |
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
178 |
"Created: / 16-09-2011 / 15:18:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
179 |
! |
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
180 |
|
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
181 |
linesModifiedFrom: start to: end |
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
182 |
|
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
183 |
self codeChanged: true |
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
184 |
|
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
185 |
"Created: / 06-07-2011 / 17:14:36 / jv" |
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
186 |
"Created: / 16-09-2011 / 15:15:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
9980 | 187 |
! ! |
188 |
||
10420 | 189 |
!CodeHighlightingService methodsFor:'initialization'! |
190 |
||
191 |
initialize |
|
192 |
||
10486 | 193 |
job := (Smalltalk at:#BackgroundJob) |
10721
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
194 |
named: 'Syntax Highlighting Job' |
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
195 |
on:[self syntaxHighlight: true]. |
10420 | 196 |
|
197 |
"Created: / 29-07-2011 / 10:31:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10439
6a41520db1be
variable renamed in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10438
diff
changeset
|
198 |
"Modified: / 03-08-2011 / 16:47:53 / cg" |
10721
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
199 |
"Modified (format): / 26-09-2011 / 15:39:56 / cg" |
10420 | 200 |
! ! |
201 |
||
9980 | 202 |
!CodeHighlightingService methodsFor:'private'! |
203 |
||
204 |
codeChanged: force |
|
10660
4b97f38f9a0f
comment/format in: #codeChanged:
Claus Gittinger <cg@exept.de>
parents:
10650
diff
changeset
|
205 |
(force or:[codeView textView modified]) ifTrue:[ |
4b97f38f9a0f
comment/format in: #codeChanged:
Claus Gittinger <cg@exept.de>
parents:
10650
diff
changeset
|
206 |
self syntaxHighlight |
4b97f38f9a0f
comment/format in: #codeChanged:
Claus Gittinger <cg@exept.de>
parents:
10650
diff
changeset
|
207 |
]. |
9980 | 208 |
|
10420 | 209 |
"Modified: / 29-07-2011 / 11:07:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10650
fccac41fd387
comment/format in: #syntaxHighlight:
Claus Gittinger <cg@exept.de>
parents:
10644
diff
changeset
|
210 |
"Modified: / 22-08-2011 / 13:51:53 / cg" |
10660
4b97f38f9a0f
comment/format in: #codeChanged:
Claus Gittinger <cg@exept.de>
parents:
10650
diff
changeset
|
211 |
"Modified (format): / 05-09-2011 / 05:06:40 / cg" |
9980 | 212 |
! |
213 |
||
214 |
setHighlightedCode:newCode elements: elements |
|
215 |
"the background synhighlighter has generated new colored text, |
|
216 |
with highlighted syntax. |
|
217 |
If there have been no modifications in the meantime, install it." |
|
218 |
||
10420 | 219 |
|firstShown lastShown cursorWasOn anyChange newLines l replaceAction list| |
9980 | 220 |
|
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
221 |
"textView" modified ifTrue:[ |
10634
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
222 |
"/ new input arrived in the meantime |
10420 | 223 |
|
10634
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
224 |
^ self |
9980 | 225 |
]. |
10420 | 226 |
done ifFalse:[ |
10634
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
227 |
"/ another coloring process has already been started. |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
228 |
"/ ignore this (leftover) code. |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
229 |
^ self |
9980 | 230 |
]. |
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
231 |
|
9980 | 232 |
firstShown := textView firstLineShown. |
233 |
lastShown := textView lastLineShown. |
|
10634
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
234 |
|
9980 | 235 |
replaceAction := [:lNr :line | |
10634
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
236 |
|oldLine| |
9980 | 237 |
|
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
238 |
oldLine := list at:lNr ifAbsent:nil. |
10634
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
239 |
oldLine notNil ifTrue:[ |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
240 |
line notNil ifTrue:[ |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
241 |
"/ this check is needed - there is a race |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
242 |
"/ when the text is converted. This detects the |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
243 |
"/ resulting error. |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
244 |
"/ Certainly a kludge. |
9980 | 245 |
|
10634
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
246 |
oldLine string = line string ifTrue:[ |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
247 |
oldLine emphasis ~= line emphasis ifTrue:[ |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
248 |
textView modifiedChannel removeDependent:self. |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
249 |
list at:lNr put:line. |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
250 |
textView modifiedChannel addDependent:self. |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
251 |
(lNr between:firstShown and:lastShown) ifTrue:[ |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
252 |
anyChange ifFalse:[ |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
253 |
anyChange := true. |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
254 |
cursorWasOn := textView hideCursor |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
255 |
]. |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
256 |
textView redrawLine:lNr |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
257 |
] |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
258 |
] |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
259 |
] |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
260 |
] |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
261 |
] |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
262 |
]. |
10234
7cdbded1e728
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10151
diff
changeset
|
263 |
|
9980 | 264 |
anyChange := false. |
265 |
newLines := newCode asStringCollection. |
|
266 |
list := textView list. |
|
267 |
list isNil ifTrue:[ |
|
10634
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
268 |
textView list:newLines. |
9980 | 269 |
] ifFalse:[ |
10634
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
270 |
"/ the cursor line first - that's where your eyes are ... |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
271 |
(l := textView cursorLine) notNil ifTrue:[ |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
272 |
l <= newLines size ifTrue:[ |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
273 |
replaceAction value:l value:(newLines at:l) |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
274 |
] |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
275 |
]. |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
276 |
newLines keysAndValuesDo:replaceAction. |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
277 |
anyChange ifTrue:[ |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
278 |
cursorWasOn ifTrue:[ |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
279 |
textView showCursor |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
280 |
] |
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
281 |
] |
9980 | 282 |
]. |
283 |
codeView syntaxElements: elements |
|
284 |
||
285 |
"Modified: / 09-10-2006 / 11:50:17 / cg" |
|
286 |
"Created: / 14-02-2010 / 16:10:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10634
9db32390ac37
comment/format in: #setHighlightedCode:elements:
Claus Gittinger <cg@exept.de>
parents:
10497
diff
changeset
|
287 |
"Modified (format): / 21-08-2011 / 09:38:22 / cg" |
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
288 |
"Modified: / 16-09-2011 / 17:33:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
9980 | 289 |
! |
290 |
||
291 |
showInfo: aString |
|
292 |
||
293 |
codeView showInfo: aString |
|
294 |
||
295 |
"Created: / 06-03-2010 / 19:34:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
296 |
! |
|
297 |
||
10420 | 298 |
syntaxHighlight |
9980 | 299 |
|
10486 | 300 |
|highlighters prio | |
9980 | 301 |
|
10721
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
302 |
(highlighters := self syntaxHighlighters) isEmptyOrNil ifTrue:[ |
10486 | 303 |
"No higlighter, nothing to do" |
304 |
^self |
|
10420 | 305 |
]. |
9980 | 306 |
|
307 |
"/ this clobbers the codeViews modified state; therefore, we have to remember |
|
308 |
"/ this info somewhere ... |
|
10244 | 309 |
codeView browser ifNotNil:[ |
10486 | 310 |
textView modified ifTrue:[ |
311 |
codeView browser navigationState realModifiedState: true |
|
312 |
]. |
|
313 |
textView modifiedChannel setValue:false. |
|
9980 | 314 |
]. |
315 |
||
10420 | 316 |
job scheduled ifTrue:[ |
10486 | 317 |
job running ifFalse:[ |
318 |
"/ process already created, but did not get a change to start yet; |
|
319 |
^ self |
|
320 |
] ifTrue:[ |
|
321 |
job stop. |
|
322 |
] |
|
9980 | 323 |
]. |
324 |
prio := Processor userBackgroundPriority - 1. |
|
325 |
textView shown ifFalse:[ |
|
10486 | 326 |
prio := prio - 1 max:1 |
9980 | 327 |
]. |
10149 | 328 |
|
10420 | 329 |
job startWithPriority: prio. |
330 |
||
331 |
"Modified: / 07-07-2011 / 12:26:12 / Jan Vrany <jan.vrant@fit.cvut,cz>" |
|
332 |
"Created: / 29-07-2011 / 11:07:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10721
6813188d742b
comment/format in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10710
diff
changeset
|
333 |
"Modified: / 26-09-2011 / 15:40:23 / cg" |
10420 | 334 |
! |
335 |
||
336 |
syntaxHighlight: delayed |
|
337 |
||
10486 | 338 |
|oldCode oldCodeList newCode elements cls mthd highlighterClasses| |
10420 | 339 |
|
340 |
done := false. |
|
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
341 |
modified := false. |
10420 | 342 |
codeView syntaxElements: nil. |
343 |
codeView syntaxElementSelection: nil. |
|
344 |
||
10486 | 345 |
highlighterClasses := self syntaxHighlighters. |
10149 | 346 |
|
10420 | 347 |
cls := codeView klass. |
348 |
(cls notNil and:[cls isObsolete]) ifTrue:[ |
|
10486 | 349 |
cls isMeta ifTrue:[ |
350 |
cls := (Smalltalk at:cls theNonMetaclass name) class |
|
351 |
] ifFalse:[ |
|
352 |
cls := Smalltalk at:cls name |
|
353 |
]. |
|
10420 | 354 |
]. |
355 |
mthd := codeView methodHolder value. |
|
10149 | 356 |
|
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
357 |
"textView" modified ifFalse:[ |
10486 | 358 |
oldCodeList := textView list copy. |
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
359 |
"textView" modified ifFalse:[ |
10486 | 360 |
oldCodeList isNil ifFalse:[ |
361 |
oldCode := oldCodeList asStringWithoutEmphasis. |
|
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
362 |
"textView" modified ifFalse:[ |
10486 | 363 |
Screen currentScreenQuerySignal answer:codeView device |
364 |
do:[ |
|
365 |
Parser::ParseError handle:[:ex | |
|
366 |
|errMsg| |
|
9980 | 367 |
|
10486 | 368 |
errMsg := ex description asStringCollection first asString. |
9980 | 369 |
|
10486 | 370 |
"/ Transcript topView raiseDeiconified. |
371 |
"/ Transcript showCR:'ParseError: ', ex description. |
|
9980 | 372 |
"/ self halt. |
10486 | 373 |
"/ self showInfo:(errMsg colorizeAllWith:Color red). |
374 |
newCode := nil. |
|
375 |
] do:[ |
|
376 |
elements := SortedCollection new. |
|
377 |
newCode := oldCode asText. |
|
378 |
codeView codeAspect == #method ifTrue:[ |
|
379 |
highlighterClasses do:[:e|newCode := e formatMethod:mthd source:newCode in:cls using: nil elementsInto: elements]. |
|
380 |
] ifFalse:[ |
|
381 |
codeView codeAspect == #expression ifTrue:[ |
|
382 |
highlighterClasses do:[:e|newCode := e formatExpression:newCode in:cls elementsInto: elements]. |
|
383 |
] ifFalse:[ |
|
384 |
codeView codeAspect == #classDefinition ifTrue:[ |
|
385 |
highlighterClasses do:[:e|newCode := e formatClassDefinition:newCode in:cls elementsInto: elements]. |
|
386 |
] |
|
387 |
]. |
|
388 |
]. |
|
389 |
] |
|
390 |
]. |
|
391 |
newCode notNil ifTrue:[ |
|
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
392 |
"textView" modified ifFalse:[ |
10486 | 393 |
newCode ~= oldCodeList ifTrue:[ |
394 |
newCode := newCode asStringCollection. |
|
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
395 |
"textView" modified ifFalse:[ |
10486 | 396 |
done := true. |
397 |
textView notNil ifTrue:[ |
|
398 |
"/ must add this event - and not been interrupted |
|
399 |
"/ by any arriving key-event. |
|
400 |
"/ self showInfo:nil. |
|
401 |
delayed ifTrue:[ |
|
402 |
codeView sensor |
|
403 |
pushUserEvent:#setHighlightedCode:elements: |
|
404 |
for:self |
|
405 |
withArguments:(Array with:newCode with: elements). |
|
406 |
"/self delayedUpdateBufferLabelWithCheckIfModified |
|
407 |
] ifFalse:[ |
|
408 |
textView contents: newCode. |
|
409 |
] |
|
410 |
] |
|
411 |
] |
|
412 |
]. |
|
413 |
] |
|
414 |
] |
|
415 |
] |
|
416 |
] |
|
417 |
] |
|
10420 | 418 |
] |
9980 | 419 |
|
10420 | 420 |
"Created: / 29-07-2011 / 11:01:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10650
fccac41fd387
comment/format in: #syntaxHighlight:
Claus Gittinger <cg@exept.de>
parents:
10644
diff
changeset
|
421 |
"Modified: / 22-08-2011 / 14:17:47 / cg" |
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
422 |
"Modified: / 16-09-2011 / 17:01:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
9980 | 423 |
! ! |
424 |
||
10410 | 425 |
!CodeHighlightingService methodsFor:'registering'! |
426 |
||
427 |
registerIn: aCodeView |
|
428 |
||
429 |
super registerIn: aCodeView. |
|
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
430 |
textView addDependent: self. |
10410 | 431 |
|
432 |
"Created: / 27-07-2011 / 13:25:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
433 |
! ! |
|
434 |
||
9980 | 435 |
!CodeHighlightingService class methodsFor:'documentation'! |
436 |
||
10497 | 437 |
version |
10729 | 438 |
^ '$Header: /cvs/stx/stx/libtool/Tools__CodeHighlightingService.st,v 1.25 2011-09-27 23:28:42 vrany Exp $' |
10497 | 439 |
! |
440 |
||
9980 | 441 |
version_CVS |
10729 | 442 |
^ '$Header: /cvs/stx/stx/libtool/Tools__CodeHighlightingService.st,v 1.25 2011-09-27 23:28:42 vrany Exp $' |
9980 | 443 |
! |
444 |
||
445 |
version_SVN |
|
446 |
^ '§Id: Tools__CodeHighlightingService.st 7715 2011-04-10 16:32:58Z vranyj1 §' |
|
447 |
! ! |