author | Claus Gittinger <cg@exept.de> |
Thu, 07 May 1998 19:44:37 +0200 | |
changeset 1516 | 677fbbd9b32f |
parent 1396 | 4e019d312d6f |
child 1625 | 2203f9f0d3f3 |
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 |
|
1396
4e019d312d6f
moved comment stuff from here to workSpace.
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
14 |
instanceVariableNames:'explainAction' |
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 |
|
83 |
! ! |
|
84 |
||
85 |
!CodeView methodsFor:'event handling'! |
|
86 |
||
87 |
keyPress:key x:x y:y |
|
88 |
"catch keyboard shortcuts" |
|
89 |
||
274
6df4bb990f04
handle accept where acceptAction is define (this was a historic leftover)
Claus Gittinger <cg@exept.de>
parents:
206
diff
changeset
|
90 |
<resource: #keyboard (#Explain #Help |
922 | 91 |
#CommentSelection #UncommentSelection)> |
201 | 92 |
|
93 |
(key == #Explain) ifTrue:[^ self explain]. |
|
94 |
(key == #Help) ifTrue:[^ self explain]. |
|
95 |
(key == #CommentSelection) ifTrue:[^ self commentSelection]. |
|
96 |
(key == #UncommentSelection) ifTrue:[^ self uncommentSelection]. |
|
97 |
||
98 |
super keyPress:key x:x y:y |
|
922 | 99 |
|
100 |
"Modified: 9.1.1997 / 12:14:00 / cg" |
|
32 | 101 |
! ! |
102 |
||
419 | 103 |
!CodeView methodsFor:'menu & menu actions'! |
104 |
||
105 |
accept |
|
106 |
"redefined accept action; |
|
107 |
save cursor and selection to allow restore in case of an error |
|
108 |
(we are typically compiling here ... and the compiler may show |
|
109 |
errors by highlighting them)" |
|
110 |
||
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
111 |
acceptEnabled == false ifTrue:[ |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
112 |
device beep. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
113 |
^ self |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
114 |
]. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
115 |
|
419 | 116 |
codeStartPosition := 1. |
117 |
[ |
|
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
118 |
AbortSignal handle:[:ex | |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
119 |
self cursor:Cursor normal. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
120 |
"redraw selection in normal color" |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
121 |
self selectFromLine:selectionStartLine col:selectionStartCol |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
122 |
toLine:selectionEndLine col:selectionEndCol. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
123 |
ex return |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
124 |
] do:[ |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
125 |
super accept. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
126 |
] |
419 | 127 |
] valueNowOrOnUnwindDo:[ |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
128 |
self unselect. |
419 | 129 |
] |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
130 |
|
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
131 |
"Modified: 7.3.1997 / 11:06:13 / cg" |
419 | 132 |
! |
133 |
||
97 | 134 |
editMenu |
121 | 135 |
"return the popUpMenu; |
136 |
to make this independent from what is defined in superclasses, |
|
137 |
get the superclass menu and add my functions." |
|
131 | 138 |
|
489 | 139 |
<resource: #keyboard (#CommentSelection #UncommentSelection |
140 |
#Accept #Explain)> |
|
1261
bdb18f73205c
resource flag: #menu -> #programMenu
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
141 |
<resource: #programMenu> |
489 | 142 |
|
1516 | 143 |
|m sub sensor| |
38 | 144 |
|
97 | 145 |
m := super editMenu. |
0 | 146 |
|
1516 | 147 |
((sensor := self sensor) notNil and:[sensor ctrlDown]) ifFalse:[ |
430 | 148 |
" |
149 |
codeViews do support #accept |
|
150 |
... add it after #inspectIt |
|
151 |
" |
|
464 | 152 |
m addLabels:(resources array:#('-' 'accept')) |
153 |
selectors:#(nil accept) |
|
154 |
accelerators:#(nil #Accept) |
|
155 |
after:#inspectIt. |
|
131 | 156 |
|
1293
c0806b73dc48
disable accept menuItem, if there is no acceptAction
Claus Gittinger <cg@exept.de>
parents:
1261
diff
changeset
|
157 |
(acceptEnabled == false |
c0806b73dc48
disable accept menuItem, if there is no acceptAction
Claus Gittinger <cg@exept.de>
parents:
1261
diff
changeset
|
158 |
or:[acceptAction isNil]) ifTrue:[ |
1106
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
159 |
m disable:#accept |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
160 |
]. |
7afde7c75396
added #disableAccept interface
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
161 |
|
430 | 162 |
" |
163 |
and add #explain after $gotoLine in the extra menu |
|
164 |
" |
|
165 |
sub := m subMenuAt:#others. |
|
166 |
sub notNil ifTrue:[ |
|
167 |
sub addLabels:(resources array:#('-' 'explain')) |
|
168 |
selectors:#(nil explain) |
|
169 |
accelerators:#(nil Explain) |
|
464 | 170 |
after:#gotoLine. |
430 | 171 |
|
172 |
self hasSelection ifFalse:[ |
|
173 |
sub disable:#explain |
|
174 |
]. |
|
175 |
]. |
|
59 | 176 |
]. |
131 | 177 |
^ m. |
430 | 178 |
|
1516 | 179 |
"Modified: / 7.5.1998 / 02:48:01 / cg" |
136 | 180 |
! |
181 |
||
201 | 182 |
explain |
183 |
"explain action; |
|
184 |
evaluate the explainBlock passing whole contents and |
|
185 |
selection as arguments." |
|
186 |
||
187 |
|text| |
|
188 |
||
189 |
explainAction notNil ifTrue:[ |
|
190 |
text := self selection. |
|
191 |
text notNil ifTrue:[ |
|
192 |
explainAction value:(self contents) value:(text asString) |
|
193 |
] |
|
194 |
] |
|
0 | 195 |
! ! |
196 |
||
206 | 197 |
!CodeView class methodsFor:'documentation'! |
198 |
||
199 |
version |
|
1516 | 200 |
^ '$Header: /cvs/stx/stx/libwidg/CodeView.st,v 1.39 1998-05-07 17:44:37 cg Exp $' |
206 | 201 |
! ! |