Tools__CodeHighlightingService.st
branchjv
changeset 12125 0c49a3b13e43
parent 12123 4bde08cebd48
child 12128 a7ff7d66ee85
--- a/Tools__CodeHighlightingService.st	Sun Jan 29 12:56:58 2012 +0000
+++ b/Tools__CodeHighlightingService.st	Sun Jan 29 15:33:37 2012 +0000
@@ -27,8 +27,8 @@
 
 "{ NameSpace: Tools }"
 
-CodeViewService subclass:#CodeHighlightingService
-	instanceVariableNames:'job done'
+BackgroundSourceProcessingService subclass:#CodeHighlightingService
+	instanceVariableNames:''
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Interface-CodeView'
@@ -78,24 +78,30 @@
 !CodeHighlightingService methodsFor:'accessing'!
 
 syntaxHighlighter
-    | app lang highlighter mthd class |
+    | app lang highlighter |
 
     "First, ask application..."
     app := codeView application.
-    mthd := codeView methodHolder value.
-    class := codeView classHolder value.
     app notNil ifTrue:[
+        | mthd class |
+
+        mthd := codeView methodHolder value.
+        class := codeView classHolder value.
         (mthd notNil and:[app respondsTo: #syntaxHighlighterForMethod:]) ifTrue:[
             highlighter := app syntaxHighlighterForMethod:mthd.
         ] ifFalse:[
             (class notNil and:[app respondsTo: #syntaxHighlighterForClass:]) ifTrue:[                        
                 highlighter := app syntaxHighlighterForClass: class.
+            ] ifFalse:[
+                (class notNil and:[app respondsTo: #syntaxHighlighter]) ifTrue:[                        
+                    highlighter := app syntaxHighlighterClass.
+                ].
             ].
         ]
     ].
     "App did not provide any highlighter..."
     highlighter isNil ifTrue:[        
-        highlighter := (lang := codeView languageHolder value)
+        highlighter := (lang := codeView language)
                 ifNil:[nil]
                 ifNotNil:[lang syntaxHighlighterClass].
     ].
@@ -105,8 +111,9 @@
     ].
     ^ highlighter
 
-    "Modified: / 05-07-2011 / 11:10:11 / cg"
     "Created: / 05-08-2011 / 10:48:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 26-09-2011 / 15:50:10 / cg"
+    "Modified: / 28-09-2011 / 00:23:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 syntaxHighlighters
@@ -134,171 +141,41 @@
     "Created: / 05-08-2011 / 10:49:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
-!CodeHighlightingService methodsFor:'change & update'!
-
-update: aspect with: param from: sender
+!CodeHighlightingService methodsFor:'acessing-defaults'!
 
-    sender == textView modifiedChannel ifTrue:[^self codeChanged: false].
-    sender == textView model ifTrue:[^self codeChanged: true].
-    sender == codeView languageHolder ifTrue:[^self codeChanged: true].
-    sender == codeView classHolder ifTrue:[^self codeChanged: true].
-
-    super update: aspect with: param from: sender
+defaultJobName
 
-    "Created: / 06-03-2010 / 19:38:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 05-07-2011 / 10:18:08 / cg"
-! !
-
-!CodeHighlightingService methodsFor:'initialization'!
+    ^'CodeView2''s syntax highlighting job'
 
-initialize
-
-    job := (Smalltalk at:#BackgroundJob)
-	    named: 'Syntax Highlighting Job'
-	    on:[self syntaxHighlight: true].
-
-    "Created: / 29-07-2011 / 10:31:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 03-08-2011 / 16:47:53 / cg"
+    "Created: / 24-01-2012 / 12:06:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !CodeHighlightingService methodsFor:'private'!
 
-codeChanged: force
-
-    (force or:[codeView textView modified]) ifTrue:
-	[self syntaxHighlight].
-
-    "Modified: / 29-07-2011 / 11:07:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-setHighlightedCode:newCode elements: elements
-    "the background synhighlighter has generated new colored text,
-     with highlighted syntax.
-     If there have been no modifications in the meantime, install it."
-
-    |firstShown lastShown cursorWasOn anyChange newLines l replaceAction list|
-
-
-    textView modified ifTrue:[
-	"/ new input arrived in the meantime
-
-	^ self
-    ].
-    done  ifFalse:[
-	"/ another coloring process has already been started.
-	"/ ignore this (leftover) code.
-	^ self
-    ].
-    firstShown := textView firstLineShown.
-    lastShown := textView lastLineShown.
-    replaceAction := [:lNr :line |
-	    |oldLine|
-
-	    oldLine := list at:lNr ifAbsent:nil.
-	    oldLine notNil ifTrue:[
-		line notNil ifTrue:[
-		    "/ this check is needed - there is a race
-		    "/ when the text is converted. This detects the
-		    "/ resulting error.
-		    "/ Certainly a kludge.
+process
+    "(Re)starts the processing job. Should be called whenever a source 
+     must be (re)processed."
 
-		    oldLine string = line string ifTrue:[
-			oldLine emphasis ~= line emphasis ifTrue:[
-			    textView modifiedChannel removeDependent:self.
-			    list at:lNr put:line.
-			    textView modifiedChannel addDependent:self.
-			    (lNr between:firstShown and:lastShown) ifTrue:[
-				anyChange ifFalse:[
-				    anyChange := true.
-				    cursorWasOn := textView hideCursor
-				].
-				textView redrawLine:lNr
-			    ]
-			]
-		    ]
-		]
-	    ]
-	].
+    | highlighters |
 
-    anyChange := false.
-    newLines := newCode asStringCollection.
-    list := textView list.
-    list isNil ifTrue:[
-	textView list:newLines.
-    ] ifFalse:[
-	"/ the cursor line first - that's where your eyes are ...
-	(l := textView cursorLine) notNil ifTrue:[
-	    l <= newLines size ifTrue:[
-		replaceAction value:l value:(newLines at:l)
-	    ]
-	].
-	newLines keysAndValuesDo:replaceAction.
-	anyChange ifTrue:[
-	    cursorWasOn ifTrue:[
-		textView showCursor
-	    ]
-	]
-    ].
-    codeView syntaxElements: elements
-
-    "Modified: / 09-10-2006 / 11:50:17 / cg"
-    "Created: / 14-02-2010 / 16:10:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified (format): / 06-07-2011 / 18:21:12 / cg"
-    "Modified: / 29-07-2011 / 11:10:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-showInfo: aString
-
-    codeView showInfo: aString
-
-    "Created: / 06-03-2010 / 19:34:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-syntaxHighlight
-
-    |highlighters prio |
-
-    highlighters := self syntaxHighlighters.
-
-    highlighters isEmptyOrNil ifTrue:[
+    (highlighters := self syntaxHighlighters) 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.
-    ].
-
-    job scheduled ifTrue:[
-        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
-    ].
-
-    job startWithPriority: prio.
+    super process.
 
     "Modified: / 07-07-2011 / 12:26:12 / Jan Vrany <jan.vrant@fit.cvut,cz>"
-    "Modified: / 20-07-2011 / 15:14:14 / cg"
-    "Created: / 29-07-2011 / 11:07:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 26-09-2011 / 15:40:23 / cg"
+    "Created: / 24-01-2012 / 12:11:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-syntaxHighlight: delayed
+process: delayed
 
     |oldCode oldCodeList newCode elements cls mthd highlighterClasses|
 
     done := false.
+    modified := false.
     codeView syntaxElements: nil.
     codeView syntaxElementSelection: nil.
 
@@ -314,12 +191,12 @@
     ].
     mthd := codeView methodHolder value.
 
-    textView modified ifFalse:[
+    "textView" modified ifFalse:[
         oldCodeList := textView list copy.
-        textView modified ifFalse:[
+        "textView" modified ifFalse:[
             oldCodeList isNil ifFalse:[
                 oldCode := oldCodeList asStringWithoutEmphasis.
-                textView modified ifFalse:[
+                "textView" modified ifFalse:[
                     Screen currentScreenQuerySignal answer:codeView device
                     do:[
                         Parser::ParseError handle:[:ex |
@@ -349,10 +226,10 @@
                         ]
                     ].
                     newCode notNil ifTrue:[
-                        textView modified ifFalse:[
+                        "textView" modified ifFalse:[
                             newCode ~= oldCodeList ifTrue:[
                                 newCode := newCode asStringCollection.
-                                textView modified ifFalse:[
+                                "textView" modified ifFalse:[
                                     done := true.
                                     textView notNil ifTrue:[
                                         "/ must add this event - and not been interrupted
@@ -377,29 +254,98 @@
         ]
     ]
 
-    "Created: / 29-07-2011 / 11:01:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
+    "Modified: / 22-08-2011 / 14:17:47 / cg"
+    "Modified: / 16-09-2011 / 17:01:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 24-01-2012 / 12:21:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+setHighlightedCode:newCode elements: elements
+    "the background synhighlighter has generated new colored text,
+     with highlighted syntax.
+     If there have been no modifications in the meantime, install it."
+
+    |firstShown lastShown cursorWasOn anyChange newLines l replaceAction list|
+
+    "textView" modified ifTrue:[
+        "/ new input arrived in the meantime
 
-!CodeHighlightingService methodsFor:'registering'!
+        ^ self
+    ].
+    done  ifFalse:[
+        "/ another coloring process has already been started.
+        "/ ignore this (leftover) code.
+        ^ self
+    ].
+
+    firstShown := textView firstLineShown.
+    lastShown := textView lastLineShown.
+
+    replaceAction := [:lNr :line |
+            |oldLine|
+
+            oldLine :=  list at:lNr ifAbsent:nil.
+            oldLine notNil ifTrue:[
+                line notNil ifTrue:[
+                    "/ this check is needed - there is a race
+                    "/ when the text is converted. This detects the
+                    "/ resulting error.
+                    "/ Certainly a kludge.
 
-registerIn: aCodeView
+                    oldLine string = line string ifTrue:[
+                        oldLine emphasis ~= line emphasis ifTrue:[
+                            textView modifiedChannel removeDependent:self.
+                            list at:lNr put:line.
+                            textView modifiedChannel addDependent:self.
+                            (lNr between:firstShown and:lastShown) ifTrue:[
+                                anyChange ifFalse:[
+                                    anyChange := true.
+                                    cursorWasOn := textView hideCursor
+                                ].
+                                textView redrawLine:lNr
+                            ]
+                        ]
+                    ]
+                ]
+            ]
+        ].
 
-    super registerIn: aCodeView.
-    self syntaxHighlight.
+    anyChange := false.
+    newLines := newCode asStringCollection.
+    list := textView list.
+    list isNil ifTrue:[
+        textView list:newLines.
+    ] ifFalse:[
+        "/ the cursor line first - that's where your eyes are ...
+        (l := textView cursorLine) notNil ifTrue:[
+            l <= newLines size ifTrue:[
+                replaceAction value:l value:(newLines at:l)
+            ]
+        ].
+        newLines keysAndValuesDo:replaceAction.
+        anyChange ifTrue:[
+            cursorWasOn ifTrue:[
+                textView showCursor
+            ]
+        ]
+    ].
+    codeView syntaxElements: elements
 
-    "Created: / 27-07-2011 / 13:25:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 09-10-2006 / 11:50:17 / cg"
+    "Created: / 14-02-2010 / 16:10:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (format): / 21-08-2011 / 09:38:22 / cg"
+    "Modified: / 16-09-2011 / 17:33:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !CodeHighlightingService class methodsFor:'documentation'!
 
 version
-    ^ '$Id: /cvs/stx/stx/libtool/Tools__CodeHighlightingService.st,v 1.17 2011/08/05 12:31:54 vrany Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/Tools__CodeHighlightingService.st,v 1.30 2012/01/24 12:56:13 vrany Exp $'
 !
 
 version_CVS
-    ^ '§Header: /cvs/stx/stx/libtool/Tools__CodeHighlightingService.st,v 1.17 2011/08/05 12:31:54 vrany Exp §'
+    ^ '§Header: /cvs/stx/stx/libtool/Tools__CodeHighlightingService.st,v 1.30 2012/01/24 12:56:13 vrany Exp §'
 !
 
 version_SVN
     ^ '$Id: Tools__CodeHighlightingService.st 7715 2011-04-10 16:32:58Z vranyj1 $'
-! !
\ No newline at end of file
+! !