Tools__CodeViewService.st
author Claus Gittinger <cg@exept.de>
Thu, 06 Jun 2013 14:03:57 +0200
changeset 12861 3106975dc3e1
parent 11182 90f2879a3926
child 12900 5a645e7b5961
child 13170 c9b815af5777
permissions -rw-r--r--
class: Tools::CodeViewService added: #buttonRelease:x:y:in: comment/format in: #buttonMotion:x:y:in: #buttonPress:x:y:in: #keyPress:x:y:in: #keyRelease:x:y:in:

"
 COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
              All Rights Reserved

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the 'Software'), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"
"{ Package: 'stx:libtool' }"

"{ NameSpace: Tools }"

Object subclass:#CodeViewService
	instanceVariableNames:'enabled codeView textView gutterView'
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-CodeView'
!

!CodeViewService class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
              All Rights Reserved

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the 'Software'), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"
!

documentation
"
    A base class for CodeView2 services. A 'service' is an extension
    mechanism for CodeView2. Once plugged in, service gets informed 
    about changes in the text and it also may intercept events.

    See concrete subclasses how to use and implement code services.

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

    [instance variables:]

    [class variables:]

    [see also:]

"
! !

!CodeViewService class methodsFor:'instance creation'!

new
    "return an initialized instance"

    ^ self basicNew initialize.
! !

!CodeViewService class methodsFor:'accessing'!

availableServices

    ^self allSubclasses select:
        [:cls|cls isAbstract not and:[cls allRequiredServicesAvailable and:[cls isAvailable]]].

    "
        Tools::CodeViewService availableServices
    "

    "Created: / 07-03-2010 / 13:42:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 27-07-2011 / 11:49:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

label

    "Answers short label - for UI"

    ^self class name

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

requiredServices

    "Returns a list of services required for myself to work
     correctly. A list should contain class names of the services
     (as not all services may be loaded in)"

    ^#()

    "Created: / 27-07-2011 / 11:39:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CodeViewService class methodsFor:'queries'!

allRequiredServicesAvailable

    | cls |

    ^self requiredServices allSatisfy:[:clsName|
        cls := Smalltalk at: clsName.
        cls notNil and:[cls allRequiredServicesAvailable and:[cls isAvailable]]                        
    ].

    "Created: / 27-07-2011 / 11:49:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CodeViewService class methodsFor:'registering'!

registerIn: aCodeView

    ^self new 
        registerIn: aCodeView;
        yourself.

    "Created: / 07-03-2010 / 13:50:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CodeViewService class methodsFor:'testing'!

isAbstract

    ^self == Tools::CodeViewService

    "Created: / 07-03-2010 / 13:41:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

isAvailable

    ^true

    "Created: / 03-04-2011 / 23:07:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

isAvailableFor: applicationClass

    "Returns true if given service may be used in
     given application class."

    ^true

    "Created: / 27-07-2011 / 11:45:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CodeViewService methodsFor:'accessing'!

application

    ^codeView application

    "Created: / 27-07-2011 / 12:11:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

enabled
    ^ enabled
!

enabled:aBoolean
    enabled := aBoolean.
!

label

    ^self class label

    "Created: / 07-03-2010 / 14:03:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

service: serviceClassName

    ^codeView services detect:[:service|service class name == serviceClassName] ifNone:[nil]

    "Created: / 05-08-2011 / 11:48:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

syntaxHighlighter

    "Returns a syntax highligter class or nil. The highlighting
     process gather all syntaxHighlighterClasses from all services
     and then use them one by one to highlight the text. Individual
     services may override this method to provide additional 
     highliging of the source code"

    ^nil

    "Created: / 05-08-2011 / 10:49:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CodeViewService methodsFor:'change & update'!

update: aspect with: param from: sender

    "Get updated whenever something changes in the code view.
     Subclasses may override this"

    "Intentionally left blank here"

    "Created: / 06-03-2010 / 19:23:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CodeViewService methodsFor:'event handling'!

buttonMotion: button x:x y:y in: view
    "Handles an event in given view (a subview of codeView).
     If the method returns true, it has eaten the event and it will not be processed
     by the view."

    ^false

    "Created: / 06-03-2010 / 20:17:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 17-06-2011 / 13:05:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (comment): / 18-08-2011 / 15:57:40 / cg"
!

buttonPress: button x:x y:y in: view
    "Handles an event in given view (a subview of codeView).
     If the method returns true, it has eaten the event and it will not be processed
     by the view."

    ^false

    "Created: / 06-03-2010 / 20:36:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 17-06-2011 / 13:06:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (comment): / 18-08-2011 / 15:57:36 / cg"
!

buttonRelease: button x:x y:y in: view
    "Handles an event in given view (a subview of codeView).
     If the method returns true, it has eaten the event and it will not be processed
     by the view."

    ^false
!

keyPress:key x:x y:y in: view
    "Handles an event in given view (a subview of codeView).
     If the method returns true, it has eaten the event and it will not be processed
     by the view."

    ^false

    "Created: / 06-03-2010 / 20:34:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 17-06-2011 / 13:06:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (comment): / 18-08-2011 / 15:57:28 / cg"
!

keyRelease: key x: x y: y in: view
    "Handles an event in given view (a subview of codeView).
     If the method returns true, it has eaten the event and it will not be processed
     by the view."

    ^false

    "Created: / 06-03-2010 / 20:35:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 17-06-2011 / 13:06:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (comment): / 18-08-2011 / 15:57:33 / cg"
!

linesDeletedFrom: start to: end

    "Created: / 06-07-2011 / 17:14:23 / jv"
!

linesInsertedFrom: start to: end

    "Created: / 06-07-2011 / 17:14:31 / jv"
!

linesModifiedFrom: start to: end

    "Created: / 06-07-2011 / 17:14:36 / jv"
!

viewRealized
    "Sent when a code view has been realized. May be overriden
     by subclasses"

    "Created: / 23-01-2012 / 10:38:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CodeViewService methodsFor:'initialization'!

initialize
    "Invoked when a new instance is created."


    "/ please change as required (and remove this comment)
    "/ enabled := nil.
    "/ codeView := nil.
    "/ textView := nil.

    super initialize.

    "Modified: / 03-09-2010 / 22:29:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CodeViewService methodsFor:'misc'!

showInfo: aString

    codeView showInfo: aString

    "Created: / 06-03-2010 / 19:34:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Created: / 21-01-2012 / 12:44:22 / cg"
! !

!CodeViewService methodsFor:'redrawing'!

drawLine:lineNo in: view atX:x y:y width: w height:h from:startCol to:endColOrNil with:fg and:bg

    "Called by both gutterView and textView (well, not yet) to
     allow services to draw custom things on text view.
     Ask JV what the args means if unsure (I'm lazy to document
     them, now it is just an experiment...)"

    "Intentionally left blank, to be overriden by subclasses"

    "Created: / 17-06-2011 / 13:49:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CodeViewService methodsFor:'registering'!

registerIn: aCodeView

    "Installs myself in aCodeView"

    codeView := aCodeView.
    codeView addDependent: self.
    textView := aCodeView textView. 
    gutterView := aCodeView gutterView.
    enabled := true.

    "Created: / 06-03-2010 / 19:21:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 17-06-2011 / 13:07:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

unregister

    "Uninstall myself from my codeView"

    codeView removeDependent: self.
    codeView := nil.
    textView := nil.

    "Created: / 06-03-2010 / 19:21:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 17-06-2011 / 12:57:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CodeViewService methodsFor:'testing'!

isEnabled

    ^enabled == true

    "Created: / 07-03-2010 / 13:47:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CodeViewService class methodsFor:'documentation'!

version_CVS
    ^ '$Header: /cvs/stx/stx/libtool/Tools__CodeViewService.st,v 1.9 2013-06-06 12:03:57 cg Exp $'
!

version_SVN
    ^ '$Id: Tools__CodeViewService.st,v 1.9 2013-06-06 12:03:57 cg Exp $'
! !