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
|
|
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
|
70
|
22 |
All Rights Reserved
|
0
|
23 |
|
97
|
24 |
$Header: /cvs/stx/stx/libwidg/CodeView.st,v 1.13 1995-03-06 19:28:05 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 |
"
|
97
|
45 |
$Header: /cvs/stx/stx/libwidg/CodeView.st,v 1.13 1995-03-06 19:28:05 claus Exp $
|
38
|
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 |
|
97
|
62 |
editMenu
|
|
63 |
|m sub idx|
|
38
|
64 |
|
97
|
65 |
m := super editMenu.
|
0
|
66 |
|
38
|
67 |
"
|
|
68 |
codeViews do support #accept
|
|
69 |
"
|
97
|
70 |
idx := m indexOf:#inspectIt.
|
38
|
71 |
idx ~~ 0 ifTrue:[
|
97
|
72 |
m addLabel:'-' selector:nil after:idx.
|
|
73 |
m addLabel:(resources string:'accept') selector:#accept after:idx + 1.
|
38
|
74 |
].
|
|
75 |
|
59
|
76 |
"
|
|
77 |
and explain in the extra menu
|
|
78 |
"
|
97
|
79 |
sub := m subMenuAt:#others.
|
59
|
80 |
sub notNil ifTrue:[
|
70
|
81 |
idx := sub indexOf:#gotoLine.
|
|
82 |
sub addLabel:'-' selector:nil after:idx.
|
|
83 |
sub addLabel:(resources string:'explain') selector:#explain after:idx + 1.
|
97
|
84 |
self hasSelection ifFalse:[
|
|
85 |
sub disable:#explain
|
|
86 |
].
|
59
|
87 |
].
|
97
|
88 |
|
|
89 |
^ m.
|
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:'user actions'!
|
|
113 |
|
|
114 |
accept
|
|
115 |
"accept action;
|
95
|
116 |
save cursor and selection; then execute the accept-action and/or
|
|
117 |
accept change. Finally restore cursor and selection."
|
|
118 |
|
|
119 |
codeStartPosition := 1.
|
|
120 |
[
|
|
121 |
Object abortSignal handle:[:ex |
|
|
122 |
self cursor:Cursor normal.
|
|
123 |
"redraw selection in normal color"
|
|
124 |
self selectFromLine:selectionStartLine col:selectionStartCol
|
|
125 |
toLine:selectionEndLine col:selectionEndCol.
|
|
126 |
ex return
|
|
127 |
] do:[
|
|
128 |
|n|
|
0
|
129 |
|
95
|
130 |
"/
|
|
131 |
"/ ST/X way of doing things
|
|
132 |
"/
|
|
133 |
acceptAction notNil ifTrue:[
|
70
|
134 |
acceptAction value:(self list "contents")
|
95
|
135 |
].
|
|
136 |
"/
|
|
137 |
"/ MVC way of doing it
|
|
138 |
"/
|
|
139 |
self sendChangeMessageWith:self contents
|
70
|
140 |
]
|
95
|
141 |
] valueNowOrOnUnwindDo:[
|
|
142 |
self unselect.
|
0
|
143 |
]
|
|
144 |
!
|
|
145 |
|
|
146 |
explain
|
|
147 |
"explain action;
|
|
148 |
evaluate the explainBlock passing whole contents and
|
|
149 |
selection as arguments."
|
|
150 |
|
|
151 |
|text|
|
|
152 |
|
|
153 |
explainAction notNil ifTrue:[
|
70
|
154 |
text := self selection.
|
|
155 |
text notNil ifTrue:[
|
|
156 |
explainAction value:(self contents)
|
|
157 |
value:(text asString)
|
|
158 |
]
|
0
|
159 |
]
|
|
160 |
! !
|
|
161 |
|
70
|
162 |
!CodeView methodsFor:'event handling'!
|
0
|
163 |
|
|
164 |
keyPress:key x:x y:y
|
32
|
165 |
"catch keyboard shortcuts"
|
0
|
166 |
|
32
|
167 |
(key == #Accept) ifTrue:[^ self accept].
|
10
|
168 |
(key == #Explain) ifTrue:[^ self explain].
|
32
|
169 |
(key == #Help) ifTrue:[^ self explain].
|
0
|
170 |
super keyPress:key x:x y:y
|
|
171 |
! !
|