Tools__BackgroundSourceProcessingService.st
author Claus Gittinger <cg@exept.de>
Sun, 01 Sep 2013 14:03:10 +0200
changeset 13456 ff46ea29cb9a
parent 11618 29842c419b87
child 12401 4714b9640528
child 13881 ceebd29ba8f6
permissions -rw-r--r--
class: Tools::CodeView2

"{ Package: 'stx:libtool' }"

"{ NameSpace: Tools }"

CodeViewService subclass:#BackgroundSourceProcessingService
	instanceVariableNames:'job done modified'
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-CodeView'
!

!BackgroundSourceProcessingService class methodsFor:'documentation'!

documentation
"
    An abstract base class for all services that process current
    (displayed) source code. All processing is done in background
    job, that is restarted whenever a text in the editor is changed.

    [author:]
        Jan Vrany <jan.vrany@fit.cvut.cz>

    [instance variables:]
        job         <BackgroundJob> A background job.

    [class variables:]

    [see also:]

"
! !

!BackgroundSourceProcessingService class methodsFor:'testing'!

isAbstract

    ^self == Tools::BackgroundSourceProcessingService

    "Created: / 24-01-2012 / 12:27:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!BackgroundSourceProcessingService methodsFor:'acessing-defaults'!

defaultJobName
    "Returns a human-readable job name, to ease identification in process browser"

    ^ 'CodeView2''s source processing job'

    "Created: / 24-01-2012 / 12:05:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!BackgroundSourceProcessingService methodsFor:'change & update'!

sourceChanged:force
    "Called when codeview's text changes"

    (force or:[codeView textView modified]) ifTrue:[
        self process
    ].

    "Modified: / 22-08-2011 / 13:51:53 / cg"
    "Modified (format): / 05-09-2011 / 05:06:40 / cg"
    "Modified: / 24-01-2012 / 12:25:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

update:aspect with:param from:sender 
    textView notNil ifTrue:[
        "/sender == textView modifiedChannel ifTrue:[^self codeChanged: false].
        sender == textView model ifTrue:[
            ^ self sourceChanged:true
        ].
        (sender == textView and:[aspect == #sizeOfContents]) ifTrue:[
            ^ self sourceChanged:true
        ].
    ].
    codeView notNil ifTrue:[
        sender == codeView languageHolder ifTrue:[
            ^ self sourceChanged:true
        ].
        sender == codeView classHolder ifTrue:[
            ^ self sourceChanged:true
        ].
    ].
    super 
        update:aspect
        with:param
        from:sender

    "Created: / 06-03-2010 / 19:38:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 13-09-2011 / 12:00:29 / cg"
    "Modified: / 16-09-2011 / 17:30:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!BackgroundSourceProcessingService methodsFor:'event handling'!

linesDeletedFrom:start to:end 
    self sourceChanged:true

    "Created: / 06-07-2011 / 17:14:36 / jv"
    "Created: / 16-09-2011 / 15:18:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

linesInsertedFrom:start to:end 
    self sourceChanged:true

    "Created: / 06-07-2011 / 17:14:36 / jv"
    "Created: / 16-09-2011 / 15:18:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

linesModifiedFrom:start to:end 
    self sourceChanged:true

    "Created: / 06-07-2011 / 17:14:36 / jv"
    "Created: / 16-09-2011 / 15:15:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!BackgroundSourceProcessingService methodsFor:'initialization'!

initialize
    job := (Smalltalk at:#BackgroundJob) 
                named:self defaultJobName
                on:[
                    Error handle:[:ex |
                        (Dialog confirm:('Error while processing source:\\',ex description,'\\Debug ?') withCRs)
                        ifTrue:[
                            ex reject.
                        ]
                    ] do:[
                        self process:true
                    ]
                ].

    "Created: / 29-07-2011 / 10:31:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 24-01-2012 / 12:26:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 19-07-2012 / 16:17:21 / cg"
! !

!BackgroundSourceProcessingService methodsFor:'processing'!

process
    "(Re)starts the processing job. Should be called whenever a source 
     must be (re)processed."

    | prio browser |

    "/ this clobbers the codeViews modified state; therefore, we have to remember
    "/ this info somewhere ...
    (browser := codeView browser) notNil ifTrue:[
        textView modified ifTrue:[
            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
        ].
        job stop.
    ].
    prio := Processor userBackgroundPriority.
    job startWithPriority: prio.

    "Modified: / 07-07-2011 / 12:26:12 / Jan Vrany <jan.vrant@fit.cvut,cz>"
    "Created: / 24-01-2012 / 12:15:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 05-06-2012 / 23:58:20 / cg"
!

process: delayed
    "Do the real source processing. If delayed is true, actuall data update must
     be done within the event queue using #pushUserEvent:...
     "

    self subclassResponsibility

    "Created: / 24-01-2012 / 12:25:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!BackgroundSourceProcessingService methodsFor:'registering'!

registerIn: aCodeView

    super registerIn: aCodeView.
    textView addDependent: self.

    "Created: / 27-07-2011 / 13:25:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!BackgroundSourceProcessingService class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libtool/Tools__BackgroundSourceProcessingService.st,v 1.3 2012-07-19 15:19:59 cg Exp $'
!

version_CVS
    ^ '$Header: /cvs/stx/stx/libtool/Tools__BackgroundSourceProcessingService.st,v 1.3 2012-07-19 15:19:59 cg Exp $'
! !