0
|
1 |
"
|
4
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
3 |
All Rights Reserved
|
|
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
|
|
14 |
instanceVariableNames:'acceptAction explainAction'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Interface-Workspace'
|
|
18 |
!
|
|
19 |
|
|
20 |
CodeView comment:'
|
4
|
21 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
22 |
All Rights Reserved
|
|
23 |
|
38
|
24 |
$Header: /cvs/stx/stx/libwidg/CodeView.st,v 1.9 1994-08-07 13:21:14 claus Exp $
|
0
|
25 |
'!
|
|
26 |
|
32
|
27 |
!CodeView class methodsFor:'documentation'!
|
|
28 |
|
38
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
|
32 |
All Rights Reserved
|
|
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 |
"
|
|
45 |
$Header: /cvs/stx/stx/libwidg/CodeView.st,v 1.9 1994-08-07 13:21:14 claus Exp $
|
|
46 |
"
|
|
47 |
!
|
|
48 |
|
32
|
49 |
documentation
|
|
50 |
"
|
|
51 |
a view for code which can recompile its contents. It adds accept and explain
|
|
52 |
to the menu, and defines two actions: acceptAction to be performed for accept
|
|
53 |
and explainAction to be performed for explain.
|
|
54 |
|
38
|
55 |
These actions are to be defined by the user of this view
|
|
56 |
(i.e. ususally the owning browser)
|
32
|
57 |
"
|
|
58 |
! !
|
|
59 |
|
0
|
60 |
!CodeView methodsFor:'initialization'!
|
|
61 |
|
|
62 |
initializeMiddleButtonMenu
|
38
|
63 |
|sub idx|
|
|
64 |
|
|
65 |
super initializeMiddleButtonMenu.
|
0
|
66 |
|
38
|
67 |
"
|
|
68 |
codeViews do support #accept
|
|
69 |
"
|
|
70 |
idx := middleButtonMenu indexOf:#inspectIt.
|
|
71 |
idx ~~ 0 ifTrue:[
|
|
72 |
middleButtonMenu addLabel:'-'
|
|
73 |
selector:nil
|
|
74 |
after:idx.
|
|
75 |
middleButtonMenu addLabel:(resources string:'accept')
|
|
76 |
selector:#accept
|
|
77 |
after:idx + 1.
|
|
78 |
].
|
|
79 |
|
|
80 |
sub := middleButtonMenu subMenuAt:#others.
|
|
81 |
idx := sub indexOf:#gotoLine.
|
|
82 |
sub addLabel:'-'
|
|
83 |
selector:nil
|
|
84 |
after:idx.
|
|
85 |
sub addLabel:(resources string:'explain')
|
|
86 |
selector:#explain
|
|
87 |
after:idx + 1.
|
32
|
88 |
|
|
89 |
self enableOrDisableSelectionMenuEntries
|
0
|
90 |
! !
|
|
91 |
|
|
92 |
!CodeView methodsFor:'accessing'!
|
|
93 |
|
|
94 |
acceptAction:aBlock
|
|
95 |
"set the action to be performed on accept"
|
|
96 |
|
|
97 |
acceptAction := aBlock
|
|
98 |
!
|
|
99 |
|
27
|
100 |
acceptAction
|
|
101 |
"return the action to be performed on accept (or nil)"
|
|
102 |
|
|
103 |
^ acceptAction
|
|
104 |
!
|
|
105 |
|
0
|
106 |
explainAction:aBlock
|
|
107 |
"set the action to be performed on explain"
|
|
108 |
|
|
109 |
explainAction := aBlock
|
|
110 |
! !
|
|
111 |
|
|
112 |
!CodeView methodsFor:'selections'!
|
|
113 |
|
|
114 |
disableSelectionMenuEntries
|
|
115 |
"disable relevant menu entries for a selection"
|
|
116 |
|
38
|
117 |
middleButtonMenu notNil ifTrue:[
|
|
118 |
super disableSelectionMenuEntries.
|
|
119 |
middleButtonMenu disable:#explain
|
|
120 |
]
|
0
|
121 |
!
|
|
122 |
|
|
123 |
enableSelectionMenuEntries
|
|
124 |
"enable relevant menu entries for a selection"
|
|
125 |
|
38
|
126 |
middleButtonMenu notNil ifTrue:[
|
|
127 |
super enableSelectionMenuEntries.
|
|
128 |
middleButtonMenu enable:#explain
|
|
129 |
]
|
0
|
130 |
! !
|
|
131 |
|
|
132 |
!CodeView methodsFor:'user actions'!
|
|
133 |
|
|
134 |
accept
|
|
135 |
"accept action;
|
|
136 |
save cursor and selection; then execute the accept-action
|
|
137 |
and finally restore cursor and selection"
|
|
138 |
|
|
139 |
acceptAction notNil ifTrue:[
|
|
140 |
codeStartPosition := 1.
|
27
|
141 |
|
0
|
142 |
abortBlock := [
|
|
143 |
self cursor:Cursor normal.
|
|
144 |
"redraw selection in normal color"
|
|
145 |
self selectFromLine:selectionStartLine col:selectionStartCol
|
|
146 |
toLine:selectionEndLine col:selectionEndCol.
|
|
147 |
abortBlock := nil.
|
|
148 |
^ nil
|
|
149 |
].
|
|
150 |
[
|
27
|
151 |
Object abortSignal catch:[
|
32
|
152 |
acceptAction value:(self list "contents")
|
27
|
153 |
]
|
0
|
154 |
] valueNowOrOnUnwindDo:[
|
|
155 |
self unselect.
|
|
156 |
abortBlock := nil
|
|
157 |
]
|
|
158 |
]
|
|
159 |
!
|
|
160 |
|
|
161 |
explain
|
|
162 |
"explain action;
|
|
163 |
evaluate the explainBlock passing whole contents and
|
|
164 |
selection as arguments."
|
|
165 |
|
|
166 |
|text|
|
|
167 |
|
|
168 |
explainAction notNil ifTrue:[
|
|
169 |
text := self selection.
|
|
170 |
text notNil ifTrue:[
|
|
171 |
explainAction value:(self contents)
|
|
172 |
value:(text asString)
|
|
173 |
]
|
|
174 |
]
|
|
175 |
! !
|
|
176 |
|
|
177 |
!CodeView methodsFor:'events'!
|
|
178 |
|
|
179 |
keyPress:key x:x y:y
|
32
|
180 |
"catch keyboard shortcuts"
|
0
|
181 |
|
32
|
182 |
(key == #Accept) ifTrue:[^ self accept].
|
10
|
183 |
(key == #Explain) ifTrue:[^ self explain].
|
32
|
184 |
(key == #Help) ifTrue:[^ self explain].
|
0
|
185 |
super keyPress:key x:x y:y
|
|
186 |
! !
|