Tools__CodeHighlightingService.st
changeset 10486 ecf02903122f
parent 10440 ad79e93dc9b7
child 10497 aab867178a6f
--- a/Tools__CodeHighlightingService.st	Fri Aug 05 13:13:08 2011 +0200
+++ b/Tools__CodeHighlightingService.st	Fri Aug 05 13:13:42 2011 +0200
@@ -75,6 +75,65 @@
     "Created: / 07-03-2010 / 14:00:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!CodeHighlightingService methodsFor:'accessing'!
+
+syntaxHighlighter
+    | app lang highlighter mthd class |
+
+    "First, ask application..."
+    app := codeView application.
+    mthd := codeView methodHolder value.
+    class := codeView classHolder value.
+    app notNil ifTrue:[
+        (mthd notNil and:[app respondsTo: #syntaxHighlighterForMethod:]) ifTrue:[
+            highlighter := app syntaxHighlighterForMethod:mthd.
+        ] ifFalse:[
+            (class notNil and:[app respondsTo: #syntaxHighlighterForClass:]) ifTrue:[                        
+                highlighter := app syntaxHighlighterForClass: class.
+            ].
+        ]
+    ].
+    "App did not provide any highlighter..."
+    highlighter isNil ifTrue:[        
+        highlighter := (lang := codeView languageHolder value)
+                ifNil:[nil]
+                ifNotNil:[lang syntaxHighlighterClass].
+    ].
+    "HACK!!!!!!"
+    highlighter == SyntaxHighlighter ifTrue:[
+        highlighter := SyntaxHighlighter2
+    ].
+    ^ highlighter
+
+    "Modified: / 05-07-2011 / 11:10:11 / cg"
+    "Created: / 05-08-2011 / 10:48:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+syntaxHighlighters
+
+    | highlighters |
+
+    highlighters := OrderedCollection new: 4.
+
+    codeView services do:[:service|
+        | highlighter |
+        highlighter := service syntaxHighlighter.        
+        highlighter notNil ifTrue:[
+            "HACK, since AbstractSyntaxHighlighter overwrite
+             emphasis instead of adding it..."
+            (highlighter isKindOf: AbstractSyntaxHighlighter class) ifTrue:[
+                highlighters addFirst: highlighter                    
+            ] ifFalse:[
+                highlighters add: highlighter
+            ].
+        ]
+    ].
+
+    ^highlighters
+
+    "Created: / 05-08-2011 / 10:49:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !CodeHighlightingService methodsFor:'change & update'!
 
 update: aspect with: param from: sender
@@ -94,7 +153,7 @@
 
 initialize
 
-    job := BackgroundJob
+    job := (Smalltalk at:#BackgroundJob)
 	    named: 'Syntax Highlighting Job'
 	    on:[self syntaxHighlight: true].
 
@@ -197,35 +256,35 @@
 
 syntaxHighlight
 
-    |highlighterClass prio |
+    |highlighters prio |
 
-    highlighterClass := self syntaxHighlighterClass.
+    highlighters := self syntaxHighlighters.
 
-    highlighterClass isNil ifTrue:[
-	"No higlighter, nothing to do"
-	^self
+    highlighters isEmptyOrNil ifTrue:[
+        "No higlighter, nothing to do"
+        ^self
     ].
 
     "/ this clobbers the codeViews modified state; therefore, we have to remember
     "/ this info somewhere ...
     codeView browser ifNotNil:[
-	textView modified ifTrue:[
-	    codeView browser navigationState realModifiedState: true
-	].
-	textView modifiedChannel setValue:false.
+        textView modified ifTrue:[
+            codeView browser navigationState realModifiedState: true
+        ].
+        textView modifiedChannel setValue:false.
     ].
 
     job scheduled ifTrue:[
-	job running ifFalse:[
-	    "/ process already created, but did not get a change to start yet;
-	    ^ self
-	] ifTrue:[
-	    job stop.
-	]
+        job running ifFalse:[
+            "/ process already created, but did not get a change to start yet;
+            ^ self
+        ] ifTrue:[
+            job stop.
+        ]
     ].
     prio := Processor userBackgroundPriority - 1.
     textView shown ifFalse:[
-	prio := prio - 1 max:1
+        prio := prio - 1 max:1
     ].
 
     job startWithPriority: prio.
@@ -237,113 +296,88 @@
 
 syntaxHighlight: delayed
 
-    |oldCode oldCodeList newCode elements cls mthd highlighterClass|
+    |oldCode oldCodeList newCode elements cls mthd highlighterClasses|
 
     done := false.
     codeView syntaxElements: nil.
     codeView syntaxElementSelection: nil.
 
-    highlighterClass := self syntaxHighlighterClass.
+    highlighterClasses := self syntaxHighlighters.
 
     cls := codeView klass.
     (cls notNil and:[cls isObsolete]) ifTrue:[
-	cls isMeta ifTrue:[
-	    cls := (Smalltalk at:cls theNonMetaclass name) class
-	] ifFalse:[
-	    cls := Smalltalk at:cls name
-	].
+        cls isMeta ifTrue:[
+            cls := (Smalltalk at:cls theNonMetaclass name) class
+        ] ifFalse:[
+            cls := Smalltalk at:cls name
+        ].
     ].
     mthd := codeView methodHolder value.
 
     textView modified ifFalse:[
-	oldCodeList := textView list copy.
-	textView modified ifFalse:[
-	    oldCodeList isNil ifFalse:[
-		oldCode := oldCodeList asStringWithoutEmphasis.
-		textView modified ifFalse:[
-		    Screen currentScreenQuerySignal answer:codeView device
-		    do:[
-			Parser::ParseError handle:[:ex |
-			    |errMsg|
+        oldCodeList := textView list copy.
+        textView modified ifFalse:[
+            oldCodeList isNil ifFalse:[
+                oldCode := oldCodeList asStringWithoutEmphasis.
+                textView modified ifFalse:[
+                    Screen currentScreenQuerySignal answer:codeView device
+                    do:[
+                        Parser::ParseError handle:[:ex |
+                            |errMsg|
 
-			    errMsg := ex description asStringCollection first asString.
+                            errMsg := ex description asStringCollection first asString.
 
-			    "/ Transcript topView raiseDeiconified.
-			    "/ Transcript showCR:'ParseError: ', ex description.
+                            "/ Transcript topView raiseDeiconified.
+                            "/ Transcript showCR:'ParseError: ', ex description.
 "/ self halt.
-			    "/ self showInfo:(errMsg colorizeAllWith:Color red).
-			    newCode := nil.
-			] do:[
-			    elements := SortedCollection new.
-			    codeView codeAspect == #method ifTrue:[
-				newCode := highlighterClass formatMethod:mthd source:oldCode in:cls using: nil elementsInto: elements.
-			    ] ifFalse:[
-				codeView codeAspect == #expression ifTrue:[
-				    newCode := highlighterClass formatExpression:oldCode in:cls elementsInto: elements.
-				] ifFalse:[
-				    codeView codeAspect == #classDefinition ifTrue:[
-					newCode := highlighterClass formatClassDefinition:oldCode in:cls elementsInto: elements.
-				    ]
-				].
-			    ].
-			]
-		    ].
-		    newCode notNil ifTrue:[
-			textView modified ifFalse:[
-			    newCode ~= oldCodeList ifTrue:[
-				newCode := newCode asStringCollection.
-				textView modified ifFalse:[
-				    done := true.
-				    textView notNil ifTrue:[
-					"/ must add this event - and not been interrupted
-					"/ by any arriving key-event.
-					"/ self showInfo:nil.
-					delayed ifTrue:[
-					    codeView sensor
-						pushUserEvent:#setHighlightedCode:elements:
-						for:self
-						withArguments:(Array with:newCode with: elements).
-						"/self delayedUpdateBufferLabelWithCheckIfModified
-					] ifFalse:[
-					    textView contents: newCode.
-					]
-				    ]
-				]
-			    ].
-			]
-		    ]
-		]
-	    ]
-	]
+                            "/ self showInfo:(errMsg colorizeAllWith:Color red).
+                            newCode := nil.
+                        ] do:[
+                            elements := SortedCollection new.
+                            newCode := oldCode asText.
+                            codeView codeAspect == #method ifTrue:[
+                                highlighterClasses do:[:e|newCode := e formatMethod:mthd source:newCode in:cls using: nil elementsInto: elements].
+                            ] ifFalse:[
+                                codeView codeAspect == #expression ifTrue:[
+                                    highlighterClasses do:[:e|newCode := e formatExpression:newCode in:cls elementsInto: elements].
+                                ] ifFalse:[
+                                    codeView codeAspect == #classDefinition ifTrue:[
+                                        highlighterClasses do:[:e|newCode := e formatClassDefinition:newCode in:cls elementsInto: elements].
+                                    ]
+                                ].
+                            ].
+                        ]
+                    ].
+                    newCode notNil ifTrue:[
+                        textView modified ifFalse:[
+                            newCode ~= oldCodeList ifTrue:[
+                                newCode := newCode asStringCollection.
+                                textView modified ifFalse:[
+                                    done := true.
+                                    textView notNil ifTrue:[
+                                        "/ must add this event - and not been interrupted
+                                        "/ by any arriving key-event.
+                                        "/ self showInfo:nil.
+                                        delayed ifTrue:[
+                                            codeView sensor
+                                                pushUserEvent:#setHighlightedCode:elements:
+                                                for:self
+                                                withArguments:(Array with:newCode with: elements).
+                                                "/self delayedUpdateBufferLabelWithCheckIfModified
+                                        ] ifFalse:[
+                                            textView contents: newCode.
+                                        ]
+                                    ]
+                                ]
+                            ].
+                        ]
+                    ]
+                ]
+            ]
+        ]
     ]
 
     "Created: / 29-07-2011 / 11:01:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-syntaxHighlighterClass
-    | lang cls mthd |
-
-    cls := (lang := codeView languageHolder value)
-		ifNil:[nil]
-		ifNotNil:[lang syntaxHighlighterClass].
-
-    "Ugly hack because I don't want to branch libcomp :-)"
-    cls == SyntaxHighlighter ifTrue:[
-	"/ hack
-	mthd := codeView methodHolder value.
-	"/ what about method-language ?
-	(mthd notNil and:[codeView browserHolder value notNil]) ifTrue:[
-	    cls := codeView browserHolder value syntaxHighlighterForMethod:mthd.
-	].
-	cls == SyntaxHighlighter ifTrue:[
-	    cls := SyntaxHighlighter2
-	]
-    ].
-    ^ cls
-
-    "Created: / 14-02-2010 / 12:39:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 06-03-2010 / 19:39:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 05-07-2011 / 11:10:11 / cg"
 ! !
 
 !CodeHighlightingService methodsFor:'registering'!
@@ -359,7 +393,7 @@
 !CodeHighlightingService class methodsFor:'documentation'!
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libtool/Tools__CodeHighlightingService.st,v 1.15 2011-08-03 14:55:32 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/Tools__CodeHighlightingService.st,v 1.16 2011-08-05 11:13:42 vrany Exp $'
 !
 
 version_SVN