author | Claus Gittinger <cg@exept.de> |
Tue, 22 Sep 1998 15:43:57 +0200 | |
changeset 1690 | 77d381b11f95 |
parent 1625 | 2203f9f0d3f3 |
child 1749 | 0d0f27322523 |
permissions | -rw-r--r-- |
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 |
|
1625 | 14 |
instanceVariableNames:'explainAction formatAction' |
419 | 15 |
classVariableNames:'' |
16 |
poolDictionaries:'' |
|
17 |
category:'Interface-Workspace' |
|
0 | 18 |
! |
19 |
||
32 | 20 |
!CodeView class methodsFor:'documentation'! |
21 |
||
38 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
70 | 25 |
All Rights Reserved |
38 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
32 | 36 |
documentation |
37 |
" |
|
125 | 38 |
a view for text which is known to be smalltalk code. |
419 | 39 |
It adds 'explain' to the menu, and defines another action: |
125 | 40 |
explainAction to be performed for explain. |
32 | 41 |
|
125 | 42 |
This action is to be defined by the user of this view |
917
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
43 |
(i.e. usually the owning browser) |
121 | 44 |
|
419 | 45 |
In addition, uncomment/comment are added to the controlMenu. |
46 |
These are smalltalk specific - if you plan to edit other language code, |
|
47 |
you need a different kind of CodeView for that. |
|
48 |
||
125 | 49 |
If used with a model, accept sends the changeMsg to it (as defined in EditTextView). |
419 | 50 |
(however, it is possible to define both changeMsg and acceptAction) |
123 | 51 |
|
419 | 52 |
See how doIt/printIt/inspectIt are handled in the superclass: Workspace. |
123 | 53 |
|
54 |
Caveat: |
|
419 | 55 |
in this version, CodeView does not yet support MVC setups for doIt |
56 |
and explain. |
|
57 |
If required, simulate this by setting the doItAction and |
|
58 |
explainAction, to notify the model manually about whats going on. |
|
583 | 59 |
|
917
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
60 |
[instance variables:] |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
61 |
commentStrings <Array> an array with 2 entries; |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
62 |
the first defining the EOL-comment string, |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
63 |
the 2nd (another array) defining opening |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
64 |
and closing comment strings. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
65 |
Default to ST/X comments, |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
66 |
can be changed in an instance for other |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
67 |
programming languages. |
7b66af482567
generalized commenting/uncommenting.
Claus Gittinger <cg@exept.de>
parents:
880
diff
changeset
|
68 |
|
583 | 69 |
[author:] |
70 |
Claus Gittinger |
|
71 |
||
72 |
[see also:] |
|
73 |
Workspace EditTextView TextView |
|
32 | 74 |
" |
201 | 75 |
! ! |
76 |
||
77 |
!CodeView methodsFor:'accessing'! |
|
78 |
||
79 |
explainAction:aBlock |
|
80 |
"set the action to be performed on explain" |
|
81 |
||
82 |
explainAction := aBlock |
|
1625 | 83 |
! |
84 |
||
85 |
formatAction:aBlock |
|
86 |
"set the action to be performed on format" |
|
87 |
||
88 |
formatAction := aBlock |
|
89 |
||
90 |
"Created: / 17.2.1998 / 17:05:13 / cg" |
|
201 | 91 |
! ! |
92 |
||
93 |
!CodeView methodsFor:'event handling'! |
|
94 |
||
95 |
keyPress:key x:x y:y |
|
96 |
"catch keyboard shortcuts" |
|
97 |
||
274
6df4bb990f04
handle accept where acceptAction is define (this was a historic leftover)
Claus Gittinger <cg@exept.de>
parents:
206
diff
changeset
|
98 |
<resource: #keyboard (#Explain #Help |
1625 | 99 |
#CommentSelection #UncommentSelection)> |
201 | 100 |
|
1625 | 101 |
(key == #Format) ifTrue:[^ self format]. |
201 | 102 |
(key == #Explain) ifTrue:[^ self explain]. |
103 |
(key == #Help) ifTrue:[^ self explain]. |
|
104 |
(key == #CommentSelection) ifTrue:[^ self commentSelection]. |
|
105 |
(key == #UncommentSelection) ifTrue:[^ self uncommentSelection]. |
|
106 |
||
107 |
super keyPress:key x:x y:y |
|
922 | 108 |
|
1625 | 109 |
"Modified: / 17.2.1998 / 17:05:23 / cg" |
32 | 110 |
! ! |
111 |
||
419 | 112 |
!CodeView methodsFor:'menu & menu actions'! |
113 |
||
114 |
accept |
|
115 |
"redefined accept action; |
|
116 |
save cursor and selection to allow restore in case of an error |
|
117 |
(we are typically compiling here ... and the compiler may show |
|
118 |
errors by highlighting them)" |
|
119 |
||
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
120 |
acceptEnabled == false ifTrue:[ |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
121 |
device beep. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
122 |
^ self |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
123 |
]. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
124 |
|
419 | 125 |
codeStartPosition := 1. |
126 |
[ |
|
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
127 |
AbortSignal handle:[:ex | |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
128 |
self cursor:Cursor normal. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
129 |
"redraw selection in normal color" |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
130 |
self selectFromLine:selectionStartLine col:selectionStartCol |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
131 |
toLine:selectionEndLine col:selectionEndCol. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
132 |
ex return |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
133 |
] do:[ |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
134 |
super accept. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
135 |
] |
419 | 136 |
] valueNowOrOnUnwindDo:[ |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
137 |
self unselect. |
419 | 138 |
] |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
139 |
|
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
140 |
"Modified: 7.3.1997 / 11:06:13 / cg" |
419 | 141 |
! |
142 |
||
97 | 143 |
editMenu |
121 | 144 |
"return the popUpMenu; |
145 |
to make this independent from what is defined in superclasses, |
|
146 |
get the superclass menu and add my functions." |
|
131 | 147 |
|
489 | 148 |
<resource: #keyboard (#CommentSelection #UncommentSelection |
149 |
#Accept #Explain)> |
|
1261
bdb18f73205c
resource flag: #menu -> #programMenu
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
150 |
<resource: #programMenu> |
489 | 151 |
|
1516 | 152 |
|m sub sensor| |
38 | 153 |
|
97 | 154 |
m := super editMenu. |
0 | 155 |
|
1516 | 156 |
((sensor := self sensor) notNil and:[sensor ctrlDown]) ifFalse:[ |
430 | 157 |
" |
158 |
codeViews do support #accept |
|
159 |
... add it after #inspectIt |
|
160 |
" |
|
464 | 161 |
m addLabels:(resources array:#('-' 'accept')) |
162 |
selectors:#(nil accept) |
|
163 |
accelerators:#(nil #Accept) |
|
164 |
after:#inspectIt. |
|
131 | 165 |
|
1293
c0806b73dc48
disable accept menuItem, if there is no acceptAction
Claus Gittinger <cg@exept.de>
parents:
1261
diff
changeset
|
166 |
(acceptEnabled == false |
c0806b73dc48
disable accept menuItem, if there is no acceptAction
Claus Gittinger <cg@exept.de>
parents:
1261
diff
changeset
|
167 |
or:[acceptAction isNil]) ifTrue:[ |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
168 |
m disable:#accept |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
169 |
]. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
170 |
|
430 | 171 |
" |
172 |
and add #explain after $gotoLine in the extra menu |
|
173 |
" |
|
174 |
sub := m subMenuAt:#others. |
|
175 |
sub notNil ifTrue:[ |
|
176 |
sub addLabels:(resources array:#('-' 'explain')) |
|
177 |
selectors:#(nil explain) |
|
178 |
accelerators:#(nil Explain) |
|
464 | 179 |
after:#gotoLine. |
430 | 180 |
|
1625 | 181 |
(self hasSelection not |
182 |
or:[explainAction isNil]) ifTrue:[ |
|
430 | 183 |
sub disable:#explain |
184 |
]. |
|
185 |
]. |
|
59 | 186 |
]. |
131 | 187 |
^ m. |
430 | 188 |
|
1625 | 189 |
"Modified: / 29.7.1998 / 16:14:52 / cg" |
136 | 190 |
! |
191 |
||
201 | 192 |
explain |
193 |
"explain action; |
|
194 |
evaluate the explainBlock passing whole contents and |
|
195 |
selection as arguments." |
|
196 |
||
197 |
|text| |
|
198 |
||
199 |
explainAction notNil ifTrue:[ |
|
200 |
text := self selection. |
|
201 |
text notNil ifTrue:[ |
|
202 |
explainAction value:(self contents) value:(text asString) |
|
203 |
] |
|
204 |
] |
|
1625 | 205 |
! |
206 |
||
207 |
format |
|
208 |
"format action; |
|
209 |
evaluate the formatBlock passing whole contents as argument." |
|
210 |
||
211 |
|text| |
|
212 |
||
213 |
formatAction notNil ifTrue:[ |
|
214 |
text := self contents. |
|
215 |
text notNil ifTrue:[ |
|
216 |
formatAction value:(text asString) |
|
217 |
] |
|
218 |
] |
|
219 |
||
220 |
"Created: / 17.2.1998 / 17:06:18 / cg" |
|
221 |
"Modified: / 17.2.1998 / 18:25:33 / cg" |
|
0 | 222 |
! ! |
223 |
||
206 | 224 |
!CodeView class methodsFor:'documentation'! |
225 |
||
226 |
version |
|
1625 | 227 |
^ '$Header: /cvs/stx/stx/libwidg/CodeView.st,v 1.40 1998-07-29 15:57:20 cg Exp $' |
206 | 228 |
! ! |