.
"
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:'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.17 1995-05-09 01:55:04 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.17 1995-05-09 01:55:04 claus Exp $
"
!
documentation
"
a view for text which is known to be smalltalk code.
It adds explain to the menu, and defines another action:
explainAction to be performed for explain.
This action is to be defined by the user of this view
(i.e. ususally the owning browser)
If used with a model, accept sends the changeMsg to it (as defined in EditTextView).
(however, it is possible to define moth changeMsg and acceptAction)
Caveat:
in this version, CodeView does not yet support MVC setups for doIt
and explain.
If required, simulate this by setting the doItAction and
explainAction, to notify the model manually about whats going on.
"
! !
!CodeView methodsFor:'initialization'!
editMenu
"return the popUpMenu;
to make this independent from what is defined in superclasses,
get the superclass menu and add my functions."
|m sub idx|
m := super editMenu.
"
codeViews do support #accept
... add it after #inspectIt
"
idx := m indexOf:#inspectIt.
idx ~~ 0 ifTrue:[
m addLabels:(resources array:#('-' 'accept'))
selectors:#(nil accept)
after:idx.
].
"
and add #explain after $gotoLine in the extra menu
"
sub := m subMenuAt:#others.
sub notNil ifTrue:[
idx := sub indexOf:#gotoLine.
sub addLabels:(resources array:#('-' 'explain'))
selectors:#(nil explain)
after:idx.
self hasSelection ifFalse:[
sub disable:#explain
].
].
^ m.
! !
!CodeView methodsFor:'accessing'!
explainAction:aBlock
"set the action to be performed on explain"
explainAction := aBlock
! !
!CodeView methodsFor:'user actions'!
accept
"redefined accept action;
save cursor and selection to allow restore in case of an error
(we are typically compiling here ... and the compiler may show
errors by highlighting them)"
codeStartPosition := 1.
[
Object abortSignal handle:[:ex |
self cursor:Cursor normal.
"redraw selection in normal color"
self selectFromLine:selectionStartLine col:selectionStartCol
toLine:selectionEndLine col:selectionEndCol.
ex return
] do:[
super accept.
]
] valueNowOrOnUnwindDo:[
self unselect.
]
!
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:'event handling'!
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
! !