73 ^'Syntax Highlighting' |
73 ^'Syntax Highlighting' |
74 |
74 |
75 "Created: / 07-03-2010 / 14:00:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
75 "Created: / 07-03-2010 / 14:00:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
76 ! ! |
76 ! ! |
77 |
77 |
|
78 !CodeHighlightingService methodsFor:'accessing'! |
|
79 |
|
80 syntaxHighlighter |
|
81 | app lang highlighter mthd class | |
|
82 |
|
83 "First, ask application..." |
|
84 app := codeView application. |
|
85 mthd := codeView methodHolder value. |
|
86 class := codeView classHolder value. |
|
87 app notNil ifTrue:[ |
|
88 (mthd notNil and:[app respondsTo: #syntaxHighlighterForMethod:]) ifTrue:[ |
|
89 highlighter := app syntaxHighlighterForMethod:mthd. |
|
90 ] ifFalse:[ |
|
91 (class notNil and:[app respondsTo: #syntaxHighlighterForClass:]) ifTrue:[ |
|
92 highlighter := app syntaxHighlighterForClass: class. |
|
93 ]. |
|
94 ] |
|
95 ]. |
|
96 "App did not provide any highlighter..." |
|
97 highlighter isNil ifTrue:[ |
|
98 highlighter := (lang := codeView languageHolder value) |
|
99 ifNil:[nil] |
|
100 ifNotNil:[lang syntaxHighlighterClass]. |
|
101 ]. |
|
102 "HACK!!!!!!" |
|
103 highlighter == SyntaxHighlighter ifTrue:[ |
|
104 highlighter := SyntaxHighlighter2 |
|
105 ]. |
|
106 ^ highlighter |
|
107 |
|
108 "Modified: / 05-07-2011 / 11:10:11 / cg" |
|
109 "Created: / 05-08-2011 / 10:48:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
110 ! |
|
111 |
|
112 syntaxHighlighters |
|
113 |
|
114 | highlighters | |
|
115 |
|
116 highlighters := OrderedCollection new: 4. |
|
117 |
|
118 codeView services do:[:service| |
|
119 | highlighter | |
|
120 highlighter := service syntaxHighlighter. |
|
121 highlighter notNil ifTrue:[ |
|
122 "HACK, since AbstractSyntaxHighlighter overwrite |
|
123 emphasis instead of adding it..." |
|
124 (highlighter isKindOf: AbstractSyntaxHighlighter class) ifTrue:[ |
|
125 highlighters addFirst: highlighter |
|
126 ] ifFalse:[ |
|
127 highlighters add: highlighter |
|
128 ]. |
|
129 ] |
|
130 ]. |
|
131 |
|
132 ^highlighters |
|
133 |
|
134 "Created: / 05-08-2011 / 10:49:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
135 ! ! |
|
136 |
78 !CodeHighlightingService methodsFor:'change & update'! |
137 !CodeHighlightingService methodsFor:'change & update'! |
79 |
138 |
80 update: aspect with: param from: sender |
139 update: aspect with: param from: sender |
81 |
140 |
82 sender == textView modifiedChannel ifTrue:[^self codeChanged: false]. |
141 sender == textView modifiedChannel ifTrue:[^self codeChanged: false]. |
195 "Created: / 06-03-2010 / 19:34:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
254 "Created: / 06-03-2010 / 19:34:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
196 ! |
255 ! |
197 |
256 |
198 syntaxHighlight |
257 syntaxHighlight |
199 |
258 |
200 |highlighterClass prio | |
259 |highlighters prio | |
201 |
260 |
202 highlighterClass := self syntaxHighlighterClass. |
261 highlighters := self syntaxHighlighters. |
203 |
262 |
204 highlighterClass isNil ifTrue:[ |
263 highlighters isEmptyOrNil ifTrue:[ |
205 "No higlighter, nothing to do" |
264 "No higlighter, nothing to do" |
206 ^self |
265 ^self |
207 ]. |
266 ]. |
208 |
267 |
209 "/ this clobbers the codeViews modified state; therefore, we have to remember |
268 "/ this clobbers the codeViews modified state; therefore, we have to remember |
210 "/ this info somewhere ... |
269 "/ this info somewhere ... |
211 codeView browser ifNotNil:[ |
270 codeView browser ifNotNil:[ |
212 textView modified ifTrue:[ |
271 textView modified ifTrue:[ |
213 codeView browser navigationState realModifiedState: true |
272 codeView browser navigationState realModifiedState: true |
214 ]. |
273 ]. |
215 textView modifiedChannel setValue:false. |
274 textView modifiedChannel setValue:false. |
216 ]. |
275 ]. |
217 |
276 |
218 job scheduled ifTrue:[ |
277 job scheduled ifTrue:[ |
219 job running ifFalse:[ |
278 job running ifFalse:[ |
220 "/ process already created, but did not get a change to start yet; |
279 "/ process already created, but did not get a change to start yet; |
221 ^ self |
280 ^ self |
222 ] ifTrue:[ |
281 ] ifTrue:[ |
223 job stop. |
282 job stop. |
224 ] |
283 ] |
225 ]. |
284 ]. |
226 prio := Processor userBackgroundPriority - 1. |
285 prio := Processor userBackgroundPriority - 1. |
227 textView shown ifFalse:[ |
286 textView shown ifFalse:[ |
228 prio := prio - 1 max:1 |
287 prio := prio - 1 max:1 |
229 ]. |
288 ]. |
230 |
289 |
231 job startWithPriority: prio. |
290 job startWithPriority: prio. |
232 |
291 |
233 "Modified: / 07-07-2011 / 12:26:12 / Jan Vrany <jan.vrant@fit.cvut,cz>" |
292 "Modified: / 07-07-2011 / 12:26:12 / Jan Vrany <jan.vrant@fit.cvut,cz>" |
235 "Created: / 29-07-2011 / 11:07:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
294 "Created: / 29-07-2011 / 11:07:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
236 ! |
295 ! |
237 |
296 |
238 syntaxHighlight: delayed |
297 syntaxHighlight: delayed |
239 |
298 |
240 |oldCode oldCodeList newCode elements cls mthd highlighterClass| |
299 |oldCode oldCodeList newCode elements cls mthd highlighterClasses| |
241 |
300 |
242 done := false. |
301 done := false. |
243 codeView syntaxElements: nil. |
302 codeView syntaxElements: nil. |
244 codeView syntaxElementSelection: nil. |
303 codeView syntaxElementSelection: nil. |
245 |
304 |
246 highlighterClass := self syntaxHighlighterClass. |
305 highlighterClasses := self syntaxHighlighters. |
247 |
306 |
248 cls := codeView klass. |
307 cls := codeView klass. |
249 (cls notNil and:[cls isObsolete]) ifTrue:[ |
308 (cls notNil and:[cls isObsolete]) ifTrue:[ |
250 cls isMeta ifTrue:[ |
309 cls isMeta ifTrue:[ |
251 cls := (Smalltalk at:cls theNonMetaclass name) class |
310 cls := (Smalltalk at:cls theNonMetaclass name) class |
252 ] ifFalse:[ |
311 ] ifFalse:[ |
253 cls := Smalltalk at:cls name |
312 cls := Smalltalk at:cls name |
254 ]. |
313 ]. |
255 ]. |
314 ]. |
256 mthd := codeView methodHolder value. |
315 mthd := codeView methodHolder value. |
257 |
316 |
258 textView modified ifFalse:[ |
317 textView modified ifFalse:[ |
259 oldCodeList := textView list copy. |
318 oldCodeList := textView list copy. |
260 textView modified ifFalse:[ |
319 textView modified ifFalse:[ |
261 oldCodeList isNil ifFalse:[ |
320 oldCodeList isNil ifFalse:[ |
262 oldCode := oldCodeList asStringWithoutEmphasis. |
321 oldCode := oldCodeList asStringWithoutEmphasis. |
263 textView modified ifFalse:[ |
322 textView modified ifFalse:[ |
264 Screen currentScreenQuerySignal answer:codeView device |
323 Screen currentScreenQuerySignal answer:codeView device |
265 do:[ |
324 do:[ |
266 Parser::ParseError handle:[:ex | |
325 Parser::ParseError handle:[:ex | |
267 |errMsg| |
326 |errMsg| |
268 |
327 |
269 errMsg := ex description asStringCollection first asString. |
328 errMsg := ex description asStringCollection first asString. |
270 |
329 |
271 "/ Transcript topView raiseDeiconified. |
330 "/ Transcript topView raiseDeiconified. |
272 "/ Transcript showCR:'ParseError: ', ex description. |
331 "/ Transcript showCR:'ParseError: ', ex description. |
273 "/ self halt. |
332 "/ self halt. |
274 "/ self showInfo:(errMsg colorizeAllWith:Color red). |
333 "/ self showInfo:(errMsg colorizeAllWith:Color red). |
275 newCode := nil. |
334 newCode := nil. |
276 ] do:[ |
335 ] do:[ |
277 elements := SortedCollection new. |
336 elements := SortedCollection new. |
278 codeView codeAspect == #method ifTrue:[ |
337 newCode := oldCode asText. |
279 newCode := highlighterClass formatMethod:mthd source:oldCode in:cls using: nil elementsInto: elements. |
338 codeView codeAspect == #method ifTrue:[ |
280 ] ifFalse:[ |
339 highlighterClasses do:[:e|newCode := e formatMethod:mthd source:newCode in:cls using: nil elementsInto: elements]. |
281 codeView codeAspect == #expression ifTrue:[ |
340 ] ifFalse:[ |
282 newCode := highlighterClass formatExpression:oldCode in:cls elementsInto: elements. |
341 codeView codeAspect == #expression ifTrue:[ |
283 ] ifFalse:[ |
342 highlighterClasses do:[:e|newCode := e formatExpression:newCode in:cls elementsInto: elements]. |
284 codeView codeAspect == #classDefinition ifTrue:[ |
343 ] ifFalse:[ |
285 newCode := highlighterClass formatClassDefinition:oldCode in:cls elementsInto: elements. |
344 codeView codeAspect == #classDefinition ifTrue:[ |
286 ] |
345 highlighterClasses do:[:e|newCode := e formatClassDefinition:newCode in:cls elementsInto: elements]. |
287 ]. |
346 ] |
288 ]. |
347 ]. |
289 ] |
348 ]. |
290 ]. |
349 ] |
291 newCode notNil ifTrue:[ |
350 ]. |
292 textView modified ifFalse:[ |
351 newCode notNil ifTrue:[ |
293 newCode ~= oldCodeList ifTrue:[ |
352 textView modified ifFalse:[ |
294 newCode := newCode asStringCollection. |
353 newCode ~= oldCodeList ifTrue:[ |
295 textView modified ifFalse:[ |
354 newCode := newCode asStringCollection. |
296 done := true. |
355 textView modified ifFalse:[ |
297 textView notNil ifTrue:[ |
356 done := true. |
298 "/ must add this event - and not been interrupted |
357 textView notNil ifTrue:[ |
299 "/ by any arriving key-event. |
358 "/ must add this event - and not been interrupted |
300 "/ self showInfo:nil. |
359 "/ by any arriving key-event. |
301 delayed ifTrue:[ |
360 "/ self showInfo:nil. |
302 codeView sensor |
361 delayed ifTrue:[ |
303 pushUserEvent:#setHighlightedCode:elements: |
362 codeView sensor |
304 for:self |
363 pushUserEvent:#setHighlightedCode:elements: |
305 withArguments:(Array with:newCode with: elements). |
364 for:self |
306 "/self delayedUpdateBufferLabelWithCheckIfModified |
365 withArguments:(Array with:newCode with: elements). |
307 ] ifFalse:[ |
366 "/self delayedUpdateBufferLabelWithCheckIfModified |
308 textView contents: newCode. |
367 ] ifFalse:[ |
309 ] |
368 textView contents: newCode. |
310 ] |
369 ] |
311 ] |
370 ] |
312 ]. |
371 ] |
313 ] |
372 ]. |
314 ] |
373 ] |
315 ] |
374 ] |
316 ] |
375 ] |
317 ] |
376 ] |
|
377 ] |
318 ] |
378 ] |
319 |
379 |
320 "Created: / 29-07-2011 / 11:01:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
380 "Created: / 29-07-2011 / 11:01:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
321 ! |
|
322 |
|
323 syntaxHighlighterClass |
|
324 | lang cls mthd | |
|
325 |
|
326 cls := (lang := codeView languageHolder value) |
|
327 ifNil:[nil] |
|
328 ifNotNil:[lang syntaxHighlighterClass]. |
|
329 |
|
330 "Ugly hack because I don't want to branch libcomp :-)" |
|
331 cls == SyntaxHighlighter ifTrue:[ |
|
332 "/ hack |
|
333 mthd := codeView methodHolder value. |
|
334 "/ what about method-language ? |
|
335 (mthd notNil and:[codeView browserHolder value notNil]) ifTrue:[ |
|
336 cls := codeView browserHolder value syntaxHighlighterForMethod:mthd. |
|
337 ]. |
|
338 cls == SyntaxHighlighter ifTrue:[ |
|
339 cls := SyntaxHighlighter2 |
|
340 ] |
|
341 ]. |
|
342 ^ cls |
|
343 |
|
344 "Created: / 14-02-2010 / 12:39:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
345 "Modified: / 06-03-2010 / 19:39:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
346 "Modified: / 05-07-2011 / 11:10:11 / cg" |
|
347 ! ! |
381 ! ! |
348 |
382 |
349 !CodeHighlightingService methodsFor:'registering'! |
383 !CodeHighlightingService methodsFor:'registering'! |
350 |
384 |
351 registerIn: aCodeView |
385 registerIn: aCodeView |