0
|
1 |
"
|
4
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
70
|
3 |
All Rights Reserved
|
0
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
Workspace subclass:#CodeView
|
125
|
14 |
instanceVariableNames:'explainAction'
|
0
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Interface-Workspace'
|
|
18 |
!
|
|
19 |
|
|
20 |
CodeView comment:'
|
4
|
21 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
70
|
22 |
All Rights Reserved
|
0
|
23 |
|
125
|
24 |
$Header: /cvs/stx/stx/libwidg/CodeView.st,v 1.17 1995-05-09 01:55:04 claus Exp $
|
0
|
25 |
'!
|
|
26 |
|
32
|
27 |
!CodeView class methodsFor:'documentation'!
|
|
28 |
|
38
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
70
|
32 |
All Rights Reserved
|
38
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
125
|
45 |
$Header: /cvs/stx/stx/libwidg/CodeView.st,v 1.17 1995-05-09 01:55:04 claus Exp $
|
38
|
46 |
"
|
|
47 |
!
|
|
48 |
|
32
|
49 |
documentation
|
|
50 |
"
|
125
|
51 |
a view for text which is known to be smalltalk code.
|
|
52 |
It adds explain to the menu, and defines another action:
|
|
53 |
explainAction to be performed for explain.
|
32
|
54 |
|
125
|
55 |
This action is to be defined by the user of this view
|
38
|
56 |
(i.e. ususally the owning browser)
|
121
|
57 |
|
125
|
58 |
If used with a model, accept sends the changeMsg to it (as defined in EditTextView).
|
121
|
59 |
(however, it is possible to define moth changeMsg and acceptAction)
|
123
|
60 |
|
|
61 |
|
|
62 |
Caveat:
|
|
63 |
in this version, CodeView does not yet support MVC setups for doIt
|
|
64 |
and explain.
|
|
65 |
If required, simulate this by setting the doItAction and
|
|
66 |
explainAction, to notify the model manually about whats going on.
|
32
|
67 |
"
|
|
68 |
! !
|
|
69 |
|
0
|
70 |
!CodeView methodsFor:'initialization'!
|
|
71 |
|
97
|
72 |
editMenu
|
121
|
73 |
"return the popUpMenu;
|
|
74 |
to make this independent from what is defined in superclasses,
|
|
75 |
get the superclass menu and add my functions."
|
|
76 |
|
97
|
77 |
|m sub idx|
|
38
|
78 |
|
97
|
79 |
m := super editMenu.
|
0
|
80 |
|
38
|
81 |
"
|
|
82 |
codeViews do support #accept
|
121
|
83 |
... add it after #inspectIt
|
38
|
84 |
"
|
97
|
85 |
idx := m indexOf:#inspectIt.
|
38
|
86 |
idx ~~ 0 ifTrue:[
|
118
|
87 |
m addLabels:(resources array:#('-' 'accept'))
|
|
88 |
selectors:#(nil accept)
|
|
89 |
after:idx.
|
38
|
90 |
].
|
|
91 |
|
59
|
92 |
"
|
121
|
93 |
and add #explain after $gotoLine in the extra menu
|
59
|
94 |
"
|
97
|
95 |
sub := m subMenuAt:#others.
|
59
|
96 |
sub notNil ifTrue:[
|
70
|
97 |
idx := sub indexOf:#gotoLine.
|
118
|
98 |
sub addLabels:(resources array:#('-' 'explain'))
|
|
99 |
selectors:#(nil explain)
|
|
100 |
after:idx.
|
97
|
101 |
self hasSelection ifFalse:[
|
|
102 |
sub disable:#explain
|
|
103 |
].
|
59
|
104 |
].
|
97
|
105 |
|
|
106 |
^ m.
|
0
|
107 |
! !
|
|
108 |
|
|
109 |
!CodeView methodsFor:'accessing'!
|
|
110 |
|
|
111 |
explainAction:aBlock
|
|
112 |
"set the action to be performed on explain"
|
|
113 |
|
|
114 |
explainAction := aBlock
|
|
115 |
! !
|
|
116 |
|
|
117 |
!CodeView methodsFor:'user actions'!
|
|
118 |
|
|
119 |
accept
|
125
|
120 |
"redefined accept action;
|
|
121 |
save cursor and selection to allow restore in case of an error
|
|
122 |
(we are typically compiling here ... and the compiler may show
|
|
123 |
errors by highlighting them)"
|
95
|
124 |
|
|
125 |
codeStartPosition := 1.
|
|
126 |
[
|
|
127 |
Object abortSignal handle:[:ex |
|
|
128 |
self cursor:Cursor normal.
|
|
129 |
"redraw selection in normal color"
|
|
130 |
self selectFromLine:selectionStartLine col:selectionStartCol
|
|
131 |
toLine:selectionEndLine col:selectionEndCol.
|
|
132 |
ex return
|
|
133 |
] do:[
|
125
|
134 |
super accept.
|
70
|
135 |
]
|
95
|
136 |
] valueNowOrOnUnwindDo:[
|
|
137 |
self unselect.
|
0
|
138 |
]
|
|
139 |
!
|
|
140 |
|
|
141 |
explain
|
|
142 |
"explain action;
|
|
143 |
evaluate the explainBlock passing whole contents and
|
|
144 |
selection as arguments."
|
|
145 |
|
|
146 |
|text|
|
|
147 |
|
|
148 |
explainAction notNil ifTrue:[
|
70
|
149 |
text := self selection.
|
|
150 |
text notNil ifTrue:[
|
121
|
151 |
explainAction value:(self contents) value:(text asString)
|
70
|
152 |
]
|
0
|
153 |
]
|
|
154 |
! !
|
|
155 |
|
70
|
156 |
!CodeView methodsFor:'event handling'!
|
0
|
157 |
|
|
158 |
keyPress:key x:x y:y
|
32
|
159 |
"catch keyboard shortcuts"
|
0
|
160 |
|
32
|
161 |
(key == #Accept) ifTrue:[^ self accept].
|
10
|
162 |
(key == #Explain) ifTrue:[^ self explain].
|
32
|
163 |
(key == #Help) ifTrue:[^ self explain].
|
121
|
164 |
|
0
|
165 |
super keyPress:key x:x y:y
|
|
166 |
! !
|