CodeView.st
author claus
Sun, 07 Aug 1994 15:23:42 +0200
changeset 38 4b9b70b2cc87
parent 32 b6c23dfd5663
child 59 450ce95a72a4
permissions -rw-r--r--
2.10.3 pre-final version

"
 COPYRIGHT (c) 1989 by Claus Gittinger
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

Workspace subclass:#CodeView
       instanceVariableNames:'acceptAction explainAction'
       classVariableNames:''
       poolDictionaries:''
       category:'Interface-Workspace'
!

CodeView comment:'
COPYRIGHT (c) 1989 by Claus Gittinger
            All Rights Reserved

$Header: /cvs/stx/stx/libwidg/CodeView.st,v 1.9 1994-08-07 13:21:14 claus Exp $
'!

!CodeView class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1989 by Claus Gittinger
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

version
"
$Header: /cvs/stx/stx/libwidg/CodeView.st,v 1.9 1994-08-07 13:21:14 claus Exp $
"
!

documentation
"
    a view for code which can recompile its contents. It adds accept and explain
    to the menu, and defines two actions: acceptAction to be performed for accept
    and explainAction to be performed for explain.

    These actions are to be defined by the user of this view 
    (i.e. ususally the owning browser)
"
! !

!CodeView methodsFor:'initialization'!

initializeMiddleButtonMenu
    |sub idx|

    super initializeMiddleButtonMenu.

    "
     codeViews do support #accept
    "
    idx := middleButtonMenu indexOf:#inspectIt.
    idx ~~ 0 ifTrue:[
        middleButtonMenu addLabel:'-'
                         selector:nil
                            after:idx.
        middleButtonMenu addLabel:(resources string:'accept')
                         selector:#accept 
                            after:idx + 1.
    ].

    sub := middleButtonMenu subMenuAt:#others.
    idx := sub indexOf:#gotoLine.
    sub addLabel:'-'
        selector:nil
           after:idx.
    sub addLabel:(resources string:'explain')
        selector:#explain
           after:idx + 1.

    self enableOrDisableSelectionMenuEntries
! !

!CodeView methodsFor:'accessing'!

acceptAction:aBlock
    "set the action to be performed on accept"

    acceptAction := aBlock
!

acceptAction
    "return the action to be performed on accept (or nil)"

    ^ acceptAction
!

explainAction:aBlock
    "set the action to be performed on explain"

    explainAction := aBlock
! !

!CodeView methodsFor:'selections'!

disableSelectionMenuEntries
    "disable relevant menu entries for a selection"

    middleButtonMenu notNil ifTrue:[
        super disableSelectionMenuEntries.
        middleButtonMenu disable:#explain
    ]
!

enableSelectionMenuEntries
    "enable relevant menu entries for a selection"

    middleButtonMenu notNil ifTrue:[
        super enableSelectionMenuEntries.
        middleButtonMenu enable:#explain
    ]
! !

!CodeView methodsFor:'user actions'!

accept
    "accept action;
     save cursor and selection; then execute the accept-action
     and finally restore cursor and selection"

    acceptAction notNil ifTrue:[
        codeStartPosition := 1.

        abortBlock := [
            self cursor:Cursor normal.
            "redraw selection in normal color"
            self selectFromLine:selectionStartLine col:selectionStartCol 
                         toLine:selectionEndLine col:selectionEndCol.
            abortBlock := nil.
            ^ nil
        ].
        [
            Object abortSignal catch:[
                acceptAction value:(self list "contents")
            ]
        ] valueNowOrOnUnwindDo:[
            self unselect.
            abortBlock := nil
        ]
    ]
!

explain
    "explain action;
     evaluate the explainBlock passing whole contents and 
     selection as arguments."

    |text|

    explainAction notNil ifTrue:[
        text := self selection.
        text notNil ifTrue:[
            explainAction value:(self contents)
                          value:(text asString)
        ]
    ]
! !

!CodeView methodsFor:'events'!

keyPress:key x:x y:y
    "catch keyboard shortcuts"

    (key == #Accept)  ifTrue:[^ self accept].
    (key == #Explain) ifTrue:[^ self explain].
    (key == #Help)    ifTrue:[^ self explain].
    super keyPress:key x:x y:y
! !