CodeView.st
author claus
Thu, 16 Dec 1993 12:00:50 +0100
changeset 10 a288b33897a5
parent 6 fd1b68b48422
child 18 66bf62e27141
permissions -rw-r--r--
*** empty log message ***

"
 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

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.

$Header: /cvs/stx/stx/libwidg/CodeView.st,v 1.5 1993-12-16 11:00:30 claus Exp $
written winter-89 by claus
'!

!CodeView methodsFor:'initialization'!

initialize
    super initialize.
    showMatchingParenthesis := true
!

initializeMiddleButtonMenu
    |labels|

    labels := resources array:#(
"
                               'undo'
"
                               'again'
                               '-'
                               'copy'
                               'cut'
                               'paste'
                               '-'
                               'doIt'
                               'printIt'
                               'inspectIt'
                               '-'
                               'accept'
                               '-'
                               'others ...'
                               ).

    self middleButtonMenu:(PopUpMenu
                                labels:labels
                             selectors:#(
"
                                         undo
"
                                         again
                                         nil
                                         copySelection
                                         cut
                                         paste
                                         nil
                                         doIt
                                         printIt
                                         inspectIt
                                         nil
                                         accept
                                         nil
                                         others
                                        )
                                receiver:self
                                     for:self).

    middleButtonMenu subMenuAt:#others put:(PopUpMenu
                                labels:#(
                                         'search'
                                         'goto'
                                         '-'
                                         'explain'
                                         '-'
                                         'font'
                                         '-'
                                         'indent'
                                         '-'
                                         'save as ..'
                                         'print'
                                        )
                              selectors:#(
                                          search
                                          gotoLine
                                          nil
                                          explain
                                          nil
                                          changeFont
                                          nil
                                          indent
                                          nil
                                          save
                                          print
                                         )
                                receiver:self
                                     for:self).
! !

!CodeView methodsFor:'accessing'!

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

    acceptAction := aBlock
!

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

    explainAction := aBlock
! !

!CodeView methodsFor:'selections'!

disableSelectionMenuEntries
    "disable relevant menu entries for a selection"

    super disableSelectionMenuEntries.
    middleButtonMenu disable:#explain
!

enableSelectionMenuEntries
    "enable relevant menu entries for a selection"

    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.
"
        self cursor:Cursor wait.
"
        abortBlock := [
            self cursor:Cursor normal.
            "redraw selection in normal color"
            self selectFromLine:selectionStartLine col:selectionStartCol 
                         toLine:selectionEndLine col:selectionEndCol.
            abortBlock := nil.
            ^ nil
        ].
        [
            acceptAction value:(self contents)
        ] valueNowOrOnUnwindDo:[
"
            self cursor:Cursor normal.
"
            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 shortcut: control-a for accept"

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