author | fm |
Mon, 26 Oct 2009 13:54:28 +0100 | |
changeset 9081 | d59a59877121 |
parent 9054 | 5ee0f83a1944 |
child 9099 | 2729600bb93c |
permissions | -rw-r--r-- |
5141 | 1 |
" |
2 |
COPYRIGHT (c) 2002 by eXept Software AG |
|
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 |
" |
|
3712 | 12 |
"{ Package: 'stx:libtool' }" |
13 |
||
14 |
Object subclass:#CodeGeneratorTool |
|
8572 | 15 |
instanceVariableNames:'compositeChangeCollector compositeChangeNesting userPreferences |
16 |
generateComments' |
|
8258 | 17 |
classVariableNames:'GenerateCommentsForGetters GenerateCommentsForSetters |
18 |
CopyrightTemplate' |
|
3712 | 19 |
poolDictionaries:'' |
20 |
category:'Interface-Browsers' |
|
21 |
! |
|
22 |
||
3719 | 23 |
!CodeGeneratorTool class methodsFor:'documentation'! |
24 |
||
5141 | 25 |
copyright |
26 |
" |
|
27 |
COPYRIGHT (c) 2002 by eXept Software AG |
|
28 |
All Rights Reserved |
|
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
3719 | 39 |
documentation |
40 |
" |
|
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
41 |
This utility class contains various code generation facilites; |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
42 |
these were extracted from the old and newBrowser. |
6791
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
43 |
There is probably more to come... |
3719 | 44 |
|
45 |
[author:] |
|
46 |
Claus Gittiner |
|
47 |
" |
|
48 |
! ! |
|
3712 | 49 |
|
8572 | 50 |
!CodeGeneratorTool class methodsFor:'instance creation'! |
51 |
||
52 |
new |
|
53 |
^ self basicNew initialize. |
|
54 |
! ! |
|
55 |
||
3712 | 56 |
!CodeGeneratorTool class methodsFor:'code generation'! |
57 |
||
58 |
createAccessMethodsFor:aCollectionOfVarNames in:aClass withChange:withChange asValueHolder:asValueHolder readersOnly:readersOnly writersOnly:writersOnly |
|
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
59 |
"create accessors in aClass" |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
60 |
|
5758 | 61 |
^ self new |
6313 | 62 |
createAccessMethodsFor:aCollectionOfVarNames |
63 |
in:aClass |
|
64 |
withChange:withChange |
|
65 |
asValueHolder:asValueHolder |
|
66 |
readersOnly:readersOnly |
|
67 |
writersOnly:writersOnly |
|
4444
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
68 |
! |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
69 |
|
3712 | 70 |
createApplicationCodeFor:aClass |
71 |
"create an empty application framework" |
|
72 |
||
5758 | 73 |
^ self new createApplicationCodeFor:aClass |
3712 | 74 |
! |
75 |
||
3804 | 76 |
createClassResponsibleProtocolFor:aClass |
77 |
"create stubs for the required protocol" |
|
78 |
||
5758 | 79 |
^ self new createClassResponsibleProtocolFor:aClass |
3804 | 80 |
! |
81 |
||
5124 | 82 |
createClassTypeTestMethodsIn:aClass forClasses:subClasses |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
83 |
"create a #isXXX test methods (I'm tired of typing)" |
4351 | 84 |
|
5758 | 85 |
^ self new createClassTypeTestMethodsIn:aClass forClasses:subClasses |
4351 | 86 |
! |
87 |
||
3712 | 88 |
createDocumentationMethodsFor:aClass |
89 |
"create empty documentation methods" |
|
90 |
||
5758 | 91 |
^ self new createDocumentationMethodsFor:aClass |
3712 | 92 |
! |
93 |
||
6313 | 94 |
createEnumTypeCodeFor:aClass |
95 |
^ self new createEnumTypeCodeFor:aClass |
|
96 |
! |
|
97 |
||
6718 | 98 |
createInitializedInstanceCreationMethodsIn:aClass |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
99 |
"create a #new and #initialize methods (I'm tired of typing)" |
3712 | 100 |
|
6718 | 101 |
^ self new createInitializedInstanceCreationMethodsIn:aClass |
102 |
! |
|
103 |
||
104 |
createParametrizedInstanceCreationMethodsNamed:selector in:aClass |
|
105 |
"create a #selector instance creation method (I'm tired of typing)" |
|
106 |
||
107 |
^ self new createParametrizedInstanceCreationMethodsNamed:selector in:aClass |
|
3712 | 108 |
! |
109 |
||
8344
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
110 |
createRedefinedInstanceCreationMethodsIn:aClass |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
111 |
"create a redefined #new method" |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
112 |
|
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
113 |
^ self new createRedefinedInstanceCreationMethodsIn:aClass |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
114 |
! |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
115 |
|
9081 | 116 |
createStartupCodeFor:aClass forStartOf:anApplicationClassOrNil |
9049
9a2003a4fef3
added: #createStartupCodeFor:forStartOf:
Claus Gittinger <cg@exept.de>
parents:
9044
diff
changeset
|
117 |
"create standAloneStartup code" |
9a2003a4fef3
added: #createStartupCodeFor:forStartOf:
Claus Gittinger <cg@exept.de>
parents:
9044
diff
changeset
|
118 |
|
9081 | 119 |
^ self new createStartupCodeFor:aClass forStartOf:anApplicationClassOrNil |
9049
9a2003a4fef3
added: #createStartupCodeFor:forStartOf:
Claus Gittinger <cg@exept.de>
parents:
9044
diff
changeset
|
120 |
! |
9a2003a4fef3
added: #createStartupCodeFor:forStartOf:
Claus Gittinger <cg@exept.de>
parents:
9044
diff
changeset
|
121 |
|
3712 | 122 |
createTestCaseSampleCodeFor:aClass |
4590 | 123 |
"create an (almost) empty testCase class" |
3712 | 124 |
|
5758 | 125 |
^ self new createTestCaseSampleCodeFor:aClass |
3712 | 126 |
! |
127 |
||
128 |
createVisitorMethodsIn:visitedClass andVisitorClass:visitorClass |
|
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
129 |
"create acceptVisitor: in visitedClass and acceptXXX in visitorClass. (I'm tired of typing)" |
3712 | 130 |
|
5758 | 131 |
^ self new createVisitorMethodsIn:visitedClass andVisitorClass:visitorClass |
3712 | 132 |
! |
133 |
||
6050 | 134 |
createWebApplicationCodeFor:aClass |
135 |
"create an empty webApplication framework" |
|
136 |
||
137 |
^ self new createWebApplicationCodeFor:aClass |
|
138 |
! |
|
139 |
||
7973 | 140 |
createWebServiceCodeFor:aClass |
141 |
"create an empty webService framework" |
|
142 |
||
143 |
^ self new createWebServiceCodeFor:aClass |
|
144 |
! |
|
145 |
||
8572 | 146 |
createWidgetCodeFor:aClass |
147 |
"create usually required widget code (redraw, model update, event handling)" |
|
148 |
||
149 |
^ self new createWidgetCodeFor:aClass |
|
150 |
! |
|
151 |
||
3712 | 152 |
initialMenuSpecMethodSourceForApplications |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
153 |
"return a menuSpec with typical stuff in it" |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
154 |
|
3712 | 155 |
^ |
156 |
'mainMenu |
|
157 |
"This resource specification was automatically generated by the CodeGeneratorTool." |
|
158 |
||
159 |
"Do not manually edit this!! If it is corrupted, |
|
160 |
the MenuEditor may not be able to read the specification." |
|
161 |
||
162 |
" |
|
163 |
MenuEditor new openOnClass:%1 andSelector:#mainMenu |
|
164 |
" |
|
165 |
||
166 |
<resource: #menu> |
|
167 |
||
168 |
^ #(#Menu |
|
169 |
#( |
|
170 |
#(#MenuItem |
|
171 |
#label: ''File'' |
|
172 |
#translateLabel: true |
|
173 |
#submenu: |
|
174 |
#(#Menu |
|
175 |
#( |
|
176 |
#(#MenuItem |
|
177 |
#label: ''New'' |
|
178 |
#translateLabel: true |
|
179 |
#value: #menuNew |
|
180 |
) |
|
181 |
#(#MenuItem |
|
182 |
#label: ''-'' |
|
183 |
) |
|
184 |
#(#MenuItem |
|
185 |
#label: ''Open...'' |
|
186 |
#translateLabel: true |
|
187 |
#value: #menuOpen |
|
188 |
) |
|
189 |
#(#MenuItem |
|
190 |
#label: ''-'' |
|
191 |
) |
|
192 |
#(#MenuItem |
|
193 |
#label: ''Save'' |
|
194 |
#translateLabel: true |
|
195 |
#value: #menuSave |
|
196 |
) |
|
197 |
#(#MenuItem |
|
198 |
#label: ''Save As...'' |
|
199 |
#translateLabel: true |
|
200 |
#value: #menuSaveAs |
|
201 |
) |
|
202 |
#(#MenuItem |
|
203 |
#label: ''-'' |
|
204 |
) |
|
205 |
#(#MenuItem |
|
206 |
#label: ''Exit'' |
|
207 |
#translateLabel: true |
|
208 |
#value: #closeRequest |
|
209 |
) |
|
210 |
) nil |
|
211 |
nil |
|
212 |
) |
|
213 |
) |
|
214 |
#(#MenuItem |
|
215 |
#label: ''Help'' |
|
216 |
#translateLabel: true |
|
217 |
#startGroup: #right |
|
218 |
#submenu: |
|
219 |
#(#Menu |
|
220 |
#( |
|
221 |
#(#MenuItem |
|
222 |
#label: ''Documentation'' |
|
223 |
#translateLabel: true |
|
224 |
#value: #openDocumentation |
|
225 |
) |
|
226 |
#(#MenuItem |
|
227 |
#label: ''-'' |
|
228 |
) |
|
229 |
#(#MenuItem |
|
6643 | 230 |
#label: ''About this Application...'' |
3712 | 231 |
#translateLabel: true |
232 |
#value: #openAboutThisApplication |
|
233 |
) |
|
234 |
) nil |
|
235 |
nil |
|
236 |
) |
|
237 |
) |
|
238 |
) nil |
|
239 |
nil |
|
240 |
) |
|
241 |
'. |
|
242 |
! |
|
243 |
||
7973 | 244 |
initialPageMenuSpec |
245 |
"return a menuSpec with typical stuff in it" |
|
246 |
||
247 |
"This resource specification was automatically generated by the CodeGeneratorTool." |
|
248 |
||
249 |
"Do not manually edit this!! If it is corrupted, |
|
250 |
the MenuEditor may not be able to read the specification." |
|
251 |
||
252 |
" |
|
253 |
MenuEditor new openOnClass:%1 andSelector:#mainMenu |
|
254 |
" |
|
255 |
||
256 |
<resource: #menu> |
|
257 |
||
258 |
^ #(#Menu |
|
259 |
#( |
|
260 |
#(#MenuItem |
|
261 |
#label: 'AAA' |
|
262 |
#translateLabel: true |
|
263 |
#submenu: |
|
264 |
#(#Menu |
|
265 |
#( |
|
266 |
#(#MenuItem |
|
267 |
#label: 'New' |
|
268 |
#translateLabel: true |
|
269 |
#value: #menuNew |
|
270 |
) |
|
271 |
#(#MenuItem |
|
272 |
#label: '-' |
|
273 |
) |
|
274 |
#(#MenuItem |
|
275 |
#label: 'Open...' |
|
276 |
#translateLabel: true |
|
277 |
#value: #menuOpen |
|
278 |
) |
|
279 |
#(#MenuItem |
|
280 |
#label: '-' |
|
281 |
) |
|
282 |
#(#MenuItem |
|
283 |
#label: 'Save' |
|
284 |
#translateLabel: true |
|
285 |
#value: #menuSave |
|
286 |
) |
|
287 |
#(#MenuItem |
|
288 |
#label: 'Save As...' |
|
289 |
#translateLabel: true |
|
290 |
#value: #menuSaveAs |
|
291 |
) |
|
292 |
#(#MenuItem |
|
293 |
#label: '-' |
|
294 |
) |
|
295 |
#(#MenuItem |
|
296 |
#label: 'Exit' |
|
297 |
#translateLabel: true |
|
298 |
#value: #closeRequest |
|
299 |
) |
|
300 |
) nil |
|
301 |
nil |
|
302 |
) |
|
303 |
) |
|
304 |
#(#MenuItem |
|
305 |
#label: 'Help' |
|
306 |
#translateLabel: true |
|
307 |
#startGroup: #right |
|
308 |
#submenu: |
|
309 |
#(#Menu |
|
310 |
#( |
|
311 |
#(#MenuItem |
|
312 |
#label: 'Documentation' |
|
313 |
#translateLabel: true |
|
314 |
#value: #openDocumentation |
|
315 |
) |
|
316 |
#(#MenuItem |
|
317 |
#label: '-' |
|
318 |
) |
|
319 |
#(#MenuItem |
|
320 |
#label: 'About this Application...' |
|
321 |
#translateLabel: true |
|
322 |
#value: #openAboutThisApplication |
|
323 |
) |
|
324 |
) nil |
|
325 |
nil |
|
326 |
) |
|
327 |
) |
|
328 |
) nil |
|
329 |
nil |
|
330 |
) |
|
331 |
! |
|
332 |
||
333 |
initialPageMenuSpecMethodSourceForWebApplications |
|
334 |
"return a menuSpec with typical stuff in it" |
|
335 |
||
336 |
^ |
|
337 |
'mainMenu |
|
338 |
"This resource specification was automatically generated by the CodeGeneratorTool." |
|
339 |
||
340 |
"Do not manually edit this!! If it is corrupted, |
|
341 |
the MenuEditor may not be able to read the specification." |
|
342 |
||
343 |
" |
|
344 |
MenuEditor new openOnClass:%1 andSelector:#mainMenu |
|
345 |
" |
|
346 |
||
347 |
<resource: #menu> |
|
348 |
||
349 |
^ ',(self initialPageMenuSpec decodeAsLiteralArray literalArrayEncoding storeString),' |
|
350 |
'. |
|
351 |
||
352 |
" |
|
353 |
self initialPageMenuSpecMethodSourceForWebApplications |
|
354 |
" |
|
355 |
! |
|
356 |
||
357 |
initialPageSpecMethodSourceForWebApplications |
|
358 |
"return an empty pageSpec" |
|
359 |
||
360 |
^ |
|
361 |
'pageSpec |
|
362 |
"This resource specification was automatically generated by the CodeGeneratorTool." |
|
363 |
||
364 |
"Do not manually edit this!! If it is corrupted, |
|
365 |
the UIPainter may not be able to read the specification." |
|
366 |
||
367 |
" |
|
368 |
UIPainter new openOnClass:%1 andSelector:#windowSpec |
|
369 |
" |
|
370 |
||
371 |
<resource: #canvas> |
|
372 |
||
373 |
^ #(#FullSpec |
|
374 |
#window: |
|
375 |
#(#WindowSpec |
|
376 |
#name: ''%1'' |
|
377 |
#layout: #(#LayoutFrame 204 0 162 0 503 0 461 0) |
|
378 |
#label: ''%1'' |
|
379 |
#min: #(#Point 10 10) |
|
380 |
#max: #(#Point 1024 768) |
|
381 |
#bounds: #(#Rectangle 204 162 504 462) |
|
382 |
#menu: #pageMenu |
|
383 |
#usePreferredExtent: false |
|
384 |
) |
|
385 |
#component: |
|
386 |
#(#SpecCollection |
|
387 |
#collection: #() |
|
388 |
) |
|
389 |
) |
|
390 |
'. |
|
391 |
! |
|
392 |
||
9054 | 393 |
initialWindowSpecForApplications |
394 |
"This resource specification was automatically generated |
|
395 |
by the UIPainter of ST/X." |
|
396 |
||
397 |
"Do not manually edit this!! If it is corrupted, |
|
398 |
the UIPainter may not be able to read the specification." |
|
399 |
||
400 |
" |
|
401 |
UIPainter new openOnClass:CodeGeneratorTool andSelector:#initialWindowSpecForApplications |
|
402 |
" |
|
403 |
||
404 |
<resource: #canvas> |
|
405 |
||
406 |
^ |
|
407 |
#(FullSpec |
|
408 |
name: initialWindowSpecForApplications |
|
409 |
window: |
|
410 |
(WindowSpec |
|
411 |
label: '%1' |
|
412 |
name: '%1' |
|
413 |
min: (Point 10 10) |
|
414 |
max: (Point 1024 768) |
|
415 |
bounds: (Rectangle 0 0 300 300) |
|
416 |
menu: mainMenu |
|
417 |
) |
|
418 |
component: |
|
419 |
(SpecCollection |
|
420 |
collection: ( |
|
421 |
(LabelSpec |
|
422 |
label: 'Hello World' |
|
423 |
name: 'Label1' |
|
424 |
layout: (LayoutFrame 0 0.0 60 0 0 1.0 219 0) |
|
425 |
translateLabel: true |
|
426 |
) |
|
427 |
) |
|
428 |
||
429 |
) |
|
430 |
) |
|
431 |
! |
|
432 |
||
433 |
initialWindowSpecForDialogs |
|
434 |
<resource: #canvas> |
|
435 |
||
436 |
"return an initial windowSpec for dialogs" |
|
437 |
||
438 |
^ #(#FullSpec |
|
439 |
#window: |
|
440 |
#(#WindowSpec |
|
441 |
#name: '%1' |
|
442 |
#layout: #(#LayoutFrame 221 0 118 0 520 0 417 0) |
|
443 |
#level: 0 |
|
444 |
#label: '%1' |
|
445 |
#min: #(#Point 10 10) |
|
446 |
#max: #(#Point 1024 768) |
|
447 |
#bounds: #(#Rectangle 221 118 521 418) |
|
448 |
#usePreferredExtent: false |
|
449 |
) |
|
450 |
#component: |
|
451 |
#(#SpecCollection |
|
452 |
#collection: |
|
453 |
#( |
|
454 |
#(#HorizontalPanelViewSpec |
|
455 |
#name: 'buttonPanel' |
|
456 |
#layout: #(#LayoutFrame 0 0.0 -45 1 0 1.0 0 1.0) |
|
457 |
#component: |
|
458 |
#(#SpecCollection |
|
459 |
#collection: |
|
460 |
#( |
|
461 |
#(#ActionButtonSpec |
|
462 |
#name: 'cancelButton' |
|
463 |
#label: 'Cancel' |
|
464 |
#tabable: true |
|
465 |
#translateLabel: true |
|
466 |
#model: #cancel |
|
467 |
#extent: #(#Point 125 22) |
|
468 |
) |
|
469 |
#(#ActionButtonSpec |
|
470 |
#name: 'okButton' |
|
471 |
#label: 'OK' |
|
472 |
#tabable: true |
|
473 |
#translateLabel: true |
|
474 |
#isDefault: true |
|
475 |
#model: #accept |
|
476 |
#extent: #(#Point 125 22) |
|
477 |
) |
|
478 |
) |
|
479 |
) |
|
480 |
#reverseOrderIfOKAtLeft: true |
|
481 |
#horizontalLayout: #spreadSpaceMax |
|
482 |
#verticalLayout: #center |
|
483 |
#horizontalSpace: 3 |
|
484 |
#verticalSpace: 3 |
|
485 |
) |
|
486 |
) |
|
487 |
) |
|
488 |
) |
|
489 |
! |
|
490 |
||
3712 | 491 |
initialWindowSpecMethodSourceForApplications |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
492 |
"return an empty windowSpec with an initial menubar in it" |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
493 |
|
3712 | 494 |
^ |
495 |
'windowSpec |
|
496 |
"This resource specification was automatically generated by the CodeGeneratorTool." |
|
497 |
||
498 |
"Do not manually edit this!! If it is corrupted, |
|
499 |
the UIPainter may not be able to read the specification." |
|
500 |
||
501 |
" |
|
502 |
UIPainter new openOnClass:%1 andSelector:#windowSpec |
|
503 |
" |
|
504 |
||
505 |
<resource: #canvas> |
|
506 |
||
9054 | 507 |
^ ', |
508 |
self initialWindowSpecForApplications decodeAsLiteralArray prettyPrintString |
|
509 |
. |
|
510 |
||
511 |
" |
|
512 |
self initialWindowSpecMethodSourceForApplications |
|
513 |
" |
|
3712 | 514 |
! |
515 |
||
516 |
initialWindowSpecMethodSourceForDialogs |
|
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
517 |
"return an empty windowSpec for dialogs" |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
518 |
|
3712 | 519 |
^ |
520 |
'windowSpec |
|
521 |
"This resource specification was automatically generated by the CodeGeneratorTool." |
|
522 |
||
523 |
"Do not manually edit this!! If it is corrupted, |
|
524 |
the UIPainter may not be able to read the specification." |
|
525 |
||
526 |
" |
|
527 |
UIPainter new openOnClass:%1 andSelector:#windowSpec |
|
528 |
" |
|
529 |
||
530 |
<resource: #canvas> |
|
531 |
||
9054 | 532 |
^ ', |
533 |
self initialWindowSpecForDialogs decodeAsLiteralArray prettyPrintString |
|
3712 | 534 |
! ! |
535 |
||
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
536 |
!CodeGeneratorTool class methodsFor:'code generation-basic'! |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
537 |
|
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
538 |
createAccessMethodsFor:aCollectionOfVarNames in:aClass withChange:withChange asValueHolder:asValueHolder readersOnly:readersOnly writersOnly:writersOnly lazyInitialization:lazyInitialization |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
539 |
"workhorse for creating access methods for instvars." |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
540 |
|
5758 | 541 |
^ self new |
542 |
createAccessMethodsFor:aCollectionOfVarNames in:aClass withChange:withChange asValueHolder:asValueHolder readersOnly:readersOnly writersOnly:writersOnly lazyInitialization:lazyInitialization |
|
543 |
! ! |
|
544 |
||
545 |
!CodeGeneratorTool class methodsFor:'code generation-individual methods'! |
|
546 |
||
547 |
createAcceptVisitorMethod:selector in:aClass |
|
548 |
"create an acceptVisitor: method |
|
549 |
(I'm tired of typing)" |
|
550 |
||
551 |
^ self new createAcceptVisitorMethod:selector in:aClass |
|
552 |
! |
|
553 |
||
554 |
createAcceptVisitorMethodIn:aClass |
|
555 |
"create an acceptVisitor: method |
|
556 |
(I'm tired of typing)" |
|
557 |
||
558 |
^ self new createAcceptVisitorMethodIn:aClass |
|
559 |
! |
|
560 |
||
561 |
createCopyrightMethodFor:aClass |
|
562 |
"add copyright method containing your/your companies |
|
563 |
copyright template but only if not already present. |
|
564 |
this is only added, if specified in the |
|
565 |
COPYRIGHT_TEMPLATE_FILE resources." |
|
566 |
||
567 |
^ self new createCopyrightMethodFor:aClass |
|
568 |
! |
|
569 |
||
570 |
createDocumentationMethodFor:aClass |
|
571 |
"add documentation method containing doc template |
|
572 |
but only if not already present." |
|
573 |
||
574 |
^ self new createDocumentationMethodFor:aClass |
|
575 |
! |
|
576 |
||
577 |
createExamplesMethodFor:aClass |
|
578 |
"add examples method containing examples template |
|
579 |
but only if not already present." |
|
580 |
||
581 |
^ self new createExamplesMethodFor:aClass |
|
582 |
! |
|
583 |
||
584 |
createImageSpecMethodFor:anImage comment:comment in:aClass selector:sel |
|
585 |
^ self new createImageSpecMethodFor:anImage comment:comment in:aClass selector:sel |
|
586 |
! |
|
587 |
||
588 |
createInitialHistoryMethodFor:aClass |
|
589 |
"add history method containing created-entry |
|
590 |
but only if not already present." |
|
591 |
||
592 |
^ self new createInitialHistoryMethodFor:aClass |
|
593 |
! |
|
594 |
||
595 |
createInstanceCreationMethodWithSetupFor:selector category:category in:aMetaClass |
|
596 |
"add an inst-creation method" |
|
597 |
||
598 |
^ self new createInstanceCreationMethodWithSetupFor:selector category:category in:aMetaClass |
|
599 |
! |
|
600 |
||
601 |
createMultiSetterMethodFor:aCollectionOfVarNames in:aClass |
|
602 |
"create a multi-setter method for instvars." |
|
603 |
||
604 |
^ self new createMultiSetterMethodFor:aCollectionOfVarNames in:aClass |
|
605 |
! |
|
606 |
||
607 |
createSubclassResponsibilityMethodFor:aSelector category:cat in:aClass |
|
608 |
"add a subclassResponsibility method; |
|
609 |
but only if not already present." |
|
610 |
||
611 |
^ self new createSubclassResponsibilityMethodFor:aSelector category:cat in:aClass |
|
612 |
! |
|
613 |
||
614 |
createUpdateMethodIn:aClass |
|
615 |
"create an update:with:from:-method |
|
616 |
(I'm tired of typing)" |
|
617 |
||
618 |
^ self new createUpdateMethodIn:aClass |
|
619 |
! |
|
620 |
||
621 |
createVersionMethodFor:aClass |
|
622 |
"add version method containing RCS template |
|
623 |
but only if not already present and its not a private class." |
|
624 |
||
625 |
^ self new createVersionMethodFor:aClass |
|
626 |
! ! |
|
627 |
||
7973 | 628 |
!CodeGeneratorTool class methodsFor:'code generation-menus'! |
629 |
||
630 |
createActionMethodFor:aSelector in:aClass category:aCategory redefine:redefine |
|
631 |
|alreadyInSuperclass method code| |
|
632 |
||
633 |
(aClass includesSelector:aSelector) ifTrue:[ |
|
634 |
^ nil |
|
635 |
]. |
|
636 |
||
637 |
alreadyInSuperclass := aClass superclass canUnderstand:aSelector. |
|
638 |
(alreadyInSuperclass and:[redefine not]) ifTrue:[ |
|
639 |
^ nil |
|
640 |
]. |
|
641 |
||
642 |
method := self methodNameTemplateFor:aSelector. |
|
643 |
||
644 |
code := '%1 |
|
645 |
"automatically generated by UIEditor ..." |
|
646 |
||
647 |
"*** the code below performs no action" |
|
648 |
"*** (except for some feedback on the Transcript)" |
|
649 |
"*** Please change as required and accept in the browser." |
|
650 |
"*** (and replace this comment by something more useful ;-)" |
|
651 |
||
652 |
"action to be added ..." |
|
653 |
||
654 |
Transcript showCR:self class name, '': action for #%2 ...''. |
|
655 |
' bindWith:method with:aSelector. |
|
656 |
||
657 |
alreadyInSuperclass ifTrue:[ |
|
658 |
code := code, (('\ super %1\' bindWith:method) withCRs). |
|
659 |
]. |
|
660 |
self compile:code forClass:aClass inCategory:(aCategory ? 'actions'). |
|
661 |
^ code |
|
662 |
! |
|
663 |
||
664 |
createAspectMethodFor:aSelector in:aClass category:aCategory redefine:redefine |
|
665 |
|alreadyInSuperclass method code text| |
|
666 |
||
667 |
(aClass includesSelector:aSelector) ifTrue:[ |
|
668 |
^ nil |
|
669 |
]. |
|
670 |
||
671 |
alreadyInSuperclass := aClass superclass canUnderstand:aSelector. |
|
672 |
(alreadyInSuperclass and:[redefine not]) ifTrue:[ |
|
673 |
^ nil |
|
674 |
]. |
|
675 |
||
676 |
method := self methodNameTemplateFor:aSelector. |
|
677 |
||
678 |
code := '%1 |
|
679 |
"automatically generated by UIEditor ..." |
|
680 |
||
681 |
"*** the code below creates a default model when invoked" |
|
682 |
"*** (which may not be the one you wanted)" |
|
683 |
"*** Please change as required and accept in the browser." |
|
684 |
"*** (and replace this comment by something more useful ;-)" |
|
685 |
||
686 |
"aspect to be added ..." |
|
687 |
||
688 |
Transcript showCR:self class name, '': aspect for #%2 ...''. |
|
689 |
||
690 |
' bindWith:method with:aSelector. |
|
691 |
||
692 |
alreadyInSuperclass ifTrue:[ |
|
693 |
text := ' ^ super %1\' bindWith:method. |
|
694 |
] ifFalse:[ |
|
695 |
text := ' ^ builder valueAspectFor:#''%1'' initialValue:true\' bindWith:aSelector. |
|
696 |
]. |
|
697 |
code := code, (text withCRs). |
|
698 |
self compile:code forClass:aClass inCategory:(aCategory ? 'actions'). |
|
699 |
^ code |
|
700 |
! ! |
|
701 |
||
5758 | 702 |
!CodeGeneratorTool class methodsFor:'compilation'! |
703 |
||
704 |
compile:theCode forClass:aClass inCategory:cat |
|
705 |
"install some code for a class. |
|
706 |
If refactory browser stuff is avaliable the refactory tools are used to support undo" |
|
707 |
||
708 |
^ self new compile:theCode forClass:aClass inCategory:cat |
|
709 |
! ! |
|
710 |
||
8258 | 711 |
!CodeGeneratorTool class methodsFor:'defaults'! |
712 |
||
713 |
copyrightTemplate |
|
714 |
"return the contents of COPYRIGHT_TEMPLATE_FILE resources |
|
715 |
or a standard template" |
|
716 |
||
717 |
|fn| |
|
718 |
||
719 |
CopyrightTemplate notNil ifTrue:[^ CopyrightTemplate]. |
|
720 |
||
721 |
fn := SystemBrowser classResources at:#'COPYRIGHT_TEMPLATE_FILE' default:nil. |
|
722 |
fn notNil ifTrue:[ |
|
723 |
fn := fn asFilename. |
|
724 |
fn exists ifTrue:[ |
|
8488 | 725 |
^ fn contentsAsString. |
8258 | 726 |
]. |
727 |
]. |
|
728 |
^ ' COPYRIGHT (c) %1 by >>yourCompany<< |
|
729 |
All Rights Reserved |
|
730 |
||
731 |
This software is furnished under a license and may be used |
|
732 |
only in accordance with the terms of that license and with the |
|
733 |
inclusion of the above copyright notice. This software may not |
|
734 |
be provided or otherwise made available to, or used by, any |
|
735 |
other person. No title to or ownership of the software is |
|
736 |
hereby transferred. |
|
737 |
'. |
|
738 |
! |
|
739 |
||
740 |
copyrightTemplate:aString |
|
8488 | 741 |
"set the COPYRIGHT_TEMPLATE_FILE" |
742 |
||
8258 | 743 |
CopyrightTemplate := aString. |
744 |
! ! |
|
745 |
||
5758 | 746 |
!CodeGeneratorTool class methodsFor:'private'! |
747 |
||
748 |
canUseRefactoringSupport |
|
749 |
"check if refactory browser stuff is avaliable" |
|
750 |
||
751 |
^ RefactoryChangeManager notNil |
|
752 |
and:[RefactoryChangeManager isLoaded |
|
753 |
and:[UserPreferences current useRefactoringSupport]] |
|
7973 | 754 |
! |
755 |
||
756 |
methodNameTemplateFor:aSelector |
|
757 |
|numArgs method| |
|
758 |
||
759 |
numArgs := aSelector numArgs. |
|
760 |
numArgs == 1 ifTrue:[ |
|
761 |
method := aSelector, 'anArgument'. |
|
762 |
] ifFalse:[ |
|
763 |
numArgs == 0 ifTrue:[ |
|
764 |
method := aSelector |
|
765 |
] ifFalse:[ |
|
766 |
method := ''. |
|
767 |
aSelector keywords keysAndValuesDo:[:i :key| |
|
768 |
method := method, key, 'arg', i printString, ' '. |
|
769 |
]. |
|
770 |
] |
|
771 |
]. |
|
772 |
^ method |
|
5758 | 773 |
! ! |
774 |
||
9022
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
775 |
!CodeGeneratorTool class methodsFor:'utilities'! |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
776 |
|
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
777 |
missingRequiredProtocolFor:aClass |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
778 |
"return the missing required protocol; |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
779 |
that is the set of selectors which send #subclassResponsibility in a superclass and |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
780 |
have no implementation in aClass or in any class between aClass and that superclass" |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
781 |
|
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
782 |
|requiredSelectors implementedSelectors| |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
783 |
|
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
784 |
requiredSelectors := IdentitySet new. |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
785 |
implementedSelectors := IdentitySet withAll:(aClass methodDictionary keys). |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
786 |
|
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
787 |
aClass allSuperclassesDo:[:eachSuperClass | |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
788 |
eachSuperClass methodDictionary keysAndValuesDo:[:eachSelector :eachMethod | |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
789 |
((eachMethod sends:#subclassResponsibility) or:[eachMethod sends:#subclassResponsibility:]) ifTrue:[ |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
790 |
(implementedSelectors includes:eachSelector) ifFalse:[ |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
791 |
requiredSelectors add:eachSelector. |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
792 |
] |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
793 |
] ifFalse:[ |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
794 |
(requiredSelectors includes:eachSelector) ifFalse:[ |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
795 |
implementedSelectors add:eachSelector. |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
796 |
]. |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
797 |
]. |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
798 |
] |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
799 |
]. |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
800 |
^ requiredSelectors |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
801 |
! ! |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
802 |
|
5759 | 803 |
!CodeGeneratorTool methodsFor:'buld changes'! |
804 |
||
5763 | 805 |
addChange:aChange |
806 |
compositeChangeCollector addChange:aChange |
|
807 |
! |
|
808 |
||
5759 | 809 |
executeCollectedChangesNamed:name |
810 |
compositeChangeCollector notNil ifTrue:[ |
|
811 |
compositeChangeNesting := compositeChangeNesting - 1. |
|
812 |
compositeChangeNesting == 0 ifTrue:[ |
|
813 |
compositeChangeCollector name:name. |
|
814 |
compositeChangeCollector changesSize == 0 ifTrue:[ |
|
815 |
self information:'Nothing generated.'. |
|
816 |
] ifFalse:[ |
|
7037 | 817 |
RefactoryChangeManager performChange:compositeChangeCollector. |
5759 | 818 |
]. |
819 |
compositeChangeCollector := nil. |
|
820 |
] |
|
821 |
] |
|
822 |
! |
|
823 |
||
824 |
startCollectChanges |
|
825 |
(self canUseRefactoringSupport) ifTrue:[ |
|
826 |
compositeChangeCollector isNil ifTrue:[ |
|
827 |
compositeChangeCollector := CompositeRefactoryChange new. |
|
828 |
compositeChangeNesting := 0. |
|
829 |
]. |
|
830 |
compositeChangeNesting := compositeChangeNesting + 1. |
|
831 |
] |
|
832 |
! ! |
|
833 |
||
5758 | 834 |
!CodeGeneratorTool methodsFor:'code generation'! |
835 |
||
836 |
createAccessMethodsFor:aCollectionOfVarNames in:aClass withChange:withChange asValueHolder:asValueHolder readersOnly:readersOnly writersOnly:writersOnly |
|
837 |
"create accessors in aClass" |
|
838 |
||
839 |
self |
|
840 |
createAccessMethodsFor:aCollectionOfVarNames |
|
841 |
in:aClass |
|
842 |
withChange:withChange |
|
843 |
asValueHolder:asValueHolder |
|
844 |
readersOnly:readersOnly |
|
845 |
writersOnly:writersOnly |
|
846 |
lazyInitialization:false |
|
847 |
! |
|
848 |
||
849 |
createApplicationCodeFor:aClass |
|
850 |
"create an empty application framework" |
|
851 |
||
7480
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
852 |
|nonMetaClass metaClass className txt isDialog |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
853 |
categoryForMenuActionsMethods compileMenuAction compileTemplateAction| |
5758 | 854 |
|
855 |
self startCollectChanges. |
|
856 |
||
8572 | 857 |
categoryForMenuActionsMethods := userPreferences categoryForMenuActionsMethods. |
5758 | 858 |
|
859 |
nonMetaClass := aClass theNonMetaclass. |
|
860 |
metaClass := aClass theMetaclass. |
|
861 |
className := nonMetaClass name. |
|
862 |
||
863 |
isDialog := (nonMetaClass isSubclassOf:SimpleDialog). |
|
864 |
||
865 |
"/ add a windowSpec method for an empty applicationWindow, |
|
866 |
"/ with a menuPanel. |
|
867 |
||
868 |
(metaClass includesSelector:#windowSpec) ifFalse:[ |
|
869 |
isDialog ifTrue:[ |
|
870 |
txt := self class initialWindowSpecMethodSourceForDialogs. |
|
871 |
] ifFalse:[ |
|
872 |
txt := self class initialWindowSpecMethodSourceForApplications. |
|
873 |
]. |
|
874 |
self |
|
875 |
compile:(txt bindWith:className) |
|
876 |
forClass:metaClass |
|
877 |
inCategory:'interface specs'. |
|
878 |
]. |
|
879 |
||
7480
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
880 |
compileTemplateAction := |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
881 |
[:selector :category | |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
882 |
(nonMetaClass includesSelector:selector) ifFalse:[ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
883 |
|codeTemplateSelector| |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
884 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
885 |
codeTemplateSelector := ('codeFor_',(selector upTo:$:)) asSymbol. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
886 |
txt := self perform:codeTemplateSelector. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
887 |
self |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
888 |
compile:txt |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
889 |
forClass:nonMetaClass |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
890 |
inCategory:(category = '*' ifTrue:categoryForMenuActionsMethods ifFalse:category). |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
891 |
] |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
892 |
]. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
893 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
894 |
#( |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
895 |
#'postBuildWith:' 'initialization & release' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
896 |
#'postOpenWith:' 'initialization & release' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
897 |
) pairWiseDo:compileTemplateAction. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
898 |
|
5758 | 899 |
isDialog ifFalse:[ |
900 |
"/ add a topMenu method |
|
901 |
||
902 |
(metaClass includesSelector:#mainMenu) ifFalse:[ |
|
903 |
txt := self class initialMenuSpecMethodSourceForApplications. |
|
904 |
self |
|
905 |
compile:(txt bindWith:className) |
|
906 |
forClass:metaClass |
|
907 |
inCategory:'menu specs'. |
|
908 |
]. |
|
909 |
||
7480
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
910 |
#( |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
911 |
#'hasUnsavedChanges' 'private queries' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
912 |
#'closeRequest' 'initialization & release' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
913 |
#'closeDownViews' 'initialization & release' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
914 |
#'menuSaveAs' '*' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
915 |
#'menuNew' '*' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
916 |
#'menuOpen' '*' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
917 |
#'menuSave' '*' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
918 |
#'doSaveAs' '*' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
919 |
#'openDocumentation' '*' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
920 |
#'openAboutThisApplication' '*' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
921 |
) pairWiseDo:compileTemplateAction. |
5758 | 922 |
]. |
923 |
||
924 |
isDialog ifTrue:[ |
|
7480
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
925 |
#( |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
926 |
#'closeAccept' 'user actions' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
927 |
) pairWiseDo:compileTemplateAction. |
5758 | 928 |
]. |
929 |
||
6050 | 930 |
self executeCollectedChangesNamed:('Add Application Code for ' , className). |
5758 | 931 |
|
7480
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
932 |
"Modified: / 27-10-2006 / 10:21:58 / cg" |
5758 | 933 |
! |
934 |
||
8987 | 935 |
createClassInitializeMethodIn:aClass |
936 |
"create a #initialize method on the class side (I'm tired of typing)" |
|
937 |
||
938 |
|nonMetaClass metaClass className code initializer bindings| |
|
939 |
||
940 |
nonMetaClass := aClass theNonMetaclass. |
|
941 |
metaClass := aClass theMetaclass. |
|
942 |
className := nonMetaClass name. |
|
943 |
||
944 |
self startCollectChanges. |
|
945 |
||
946 |
(metaClass includesSelector:#'initialize') ifFalse:[ |
|
947 |
'initialize |
|
948 |
"Invoked at system start or when the class is dynamically loaded." |
|
949 |
||
950 |
"/ please change as required (and remove this comment) |
|
951 |
'. |
|
952 |
bindings := Dictionary new. |
|
953 |
bindings at:'INIT_CLASSINSTVARS' put:( |
|
954 |
String streamContents:[:s | |
|
955 |
metaClass instVarNames do:[:eachClassInstVar | |
|
956 |
initializer := 'nil'. "/ need more intelligence here (try to guess class from messages sent to it) ... |
|
957 |
s nextPutLine:(' "/ %1 := %2.' bindWith:eachClassInstVar with:initializer). |
|
958 |
] |
|
959 |
]). |
|
960 |
||
961 |
bindings at:'INIT_CLASSVARS' put:( |
|
962 |
String streamContents:[:s | |
|
963 |
nonMetaClass classVarNames do:[:eachClassVar | |
|
964 |
initializer := 'nil'. "/ need more intelligence here (try to guess class from messages sent to it) ... |
|
965 |
s nextPutLine:(' "/ %1 := %2.' bindWith:eachClassVar with:initializer). |
|
966 |
] |
|
967 |
]). |
|
968 |
||
969 |
code := (self codeFor_classInitialize) expandPlaceholdersWith:bindings. |
|
970 |
||
971 |
self |
|
972 |
compile:code |
|
973 |
forClass:metaClass |
|
974 |
inCategory:'initialization'. |
|
975 |
]. |
|
976 |
||
977 |
self executeCollectedChangesNamed:('Add Class Initializer to ' , className). |
|
978 |
! |
|
979 |
||
5758 | 980 |
createClassResponsibleProtocolFor:aClass |
981 |
"create stubs for the required protocol" |
|
982 |
||
6050 | 983 |
|nonMetaClass metaClass className| |
984 |
||
985 |
nonMetaClass := aClass theNonMetaclass. |
|
986 |
metaClass := aClass theMetaclass. |
|
987 |
className := nonMetaClass name. |
|
988 |
||
5758 | 989 |
self startCollectChanges. |
990 |
||
6050 | 991 |
self privCreateClassResponsibleProtocolFor:nonMetaClass. |
992 |
self privCreateClassResponsibleProtocolFor:metaClass. |
|
5758 | 993 |
|
6050 | 994 |
self executeCollectedChangesNamed:('Add Required Protocol to ' , className). |
5758 | 995 |
! |
996 |
||
997 |
createClassTypeTestMethodsIn:aClass forClasses:subClasses |
|
998 |
"create a #isXXX test methods (I'm tired of typing)" |
|
999 |
||
1000 |
| code| |
|
1001 |
||
1002 |
self startCollectChanges. |
|
1003 |
||
1004 |
subClasses do:[:eachSubClass | |
|
1005 |
|nm selector| |
|
1006 |
||
1007 |
nm := eachSubClass nameWithoutPrefix. |
|
1008 |
selector := 'is' , nm. |
|
1009 |
(aClass includesSelector:selector) ifFalse:[ |
|
1010 |
code := (selector , '\ ^ false') withCRs. |
|
1011 |
self |
|
1012 |
compile:code |
|
1013 |
forClass:aClass |
|
1014 |
inCategory:'testing'. |
|
1015 |
]. |
|
1016 |
(eachSubClass includesSelector:selector) ifFalse:[ |
|
1017 |
code := (selector , '\ ^ true') withCRs. |
|
1018 |
self |
|
1019 |
compile:code |
|
1020 |
forClass:eachSubClass |
|
1021 |
inCategory:'testing'. |
|
1022 |
]. |
|
1023 |
]. |
|
1024 |
||
5759 | 1025 |
self executeCollectedChangesNamed:'Add ClassType Tests' |
5758 | 1026 |
! |
1027 |
||
1028 |
createDocumentationMethodsFor:aClass |
|
1029 |
"create empty documentation methods" |
|
1030 |
||
6050 | 1031 |
|nonMetaClass metaClass className| |
5758 | 1032 |
|
6050 | 1033 |
nonMetaClass := aClass theNonMetaclass. |
1034 |
metaClass := aClass theMetaclass. |
|
1035 |
className := nonMetaClass name. |
|
5758 | 1036 |
|
1037 |
self startCollectChanges. |
|
1038 |
||
8890 | 1039 |
"/ self createVersionMethodFor:metaClass. |
6050 | 1040 |
self createCopyrightMethodFor:metaClass. |
1041 |
self createDocumentationMethodFor:metaClass. |
|
8572 | 1042 |
self createExamplesMethodFor:metaClass. |
1043 |
"/ self createInitialHistoryMethodFor:metaClass. |
|
5758 | 1044 |
|
6050 | 1045 |
self executeCollectedChangesNamed:('Add Documentation to ' , className). |
5758 | 1046 |
! |
1047 |
||
6313 | 1048 |
createEnumTypeCodeFor:aClass |
1049 |
|nonMetaClass metaClass className enumValues code initCode runValue maxValue| |
|
1050 |
||
1051 |
self startCollectChanges. |
|
1052 |
||
1053 |
nonMetaClass := aClass theNonMetaclass. |
|
1054 |
metaClass := aClass theMetaclass. |
|
1055 |
className := nonMetaClass name. |
|
1056 |
||
1057 |
enumValues := nonMetaClass classVarNames. |
|
1058 |
enumValues do:[:eachVariableName | |
|
1059 |
self |
|
1060 |
createAccessMethodsFor:(Array with:eachVariableName) |
|
1061 |
in:metaClass |
|
1062 |
withChange:false |
|
1063 |
asValueHolder:false |
|
1064 |
readersOnly:true |
|
1065 |
writersOnly:false |
|
1066 |
]. |
|
1067 |
||
8572 | 1068 |
maxValue := enumValues |
1069 |
inject:0 |
|
1070 |
into:[:maxSoFar :eachVariableName | |
|
1071 |
|oldVal val| |
|
1072 |
oldVal := nonMetaClass classVarAt:eachVariableName. |
|
1073 |
oldVal notNil ifTrue:[ val := oldVal numericValue ]. |
|
1074 |
(val ? maxSoFar) max:maxSoFar |
|
1075 |
]. |
|
6313 | 1076 |
|
1077 |
initCode := WriteStream on: String new. |
|
1078 |
initCode nextPutLine:'initialize'. |
|
1079 |
runValue := maxValue + 1. |
|
1080 |
enumValues keysAndValuesDo:[:idx :eachVariableName | |
|
1081 |
|oldValue thisValue| |
|
1082 |
||
1083 |
oldValue := nonMetaClass classVarAt:eachVariableName. |
|
1084 |
oldValue notNil ifTrue:[ |
|
1085 |
thisValue := oldValue numericValue. |
|
1086 |
] ifFalse:[ |
|
1087 |
thisValue := runValue. |
|
1088 |
runValue := runValue + 1. |
|
1089 |
]. |
|
1090 |
initCode |
|
1091 |
nextPutAll:' '; |
|
1092 |
nextPutAll:eachVariableName; |
|
1093 |
nextPutAll:' := self basicNew'. |
|
1094 |
(aClass canUnderstand:#'setNumericValue:') ifTrue:[ |
|
1095 |
initCode nextPutAll:' setNumericValue: ',thisValue printString. |
|
1096 |
]. |
|
1097 |
(aClass canUnderstand:#'setCssClassString:') ifTrue:[ |
|
1098 |
initCode nextPutAll:('; setCssClassString: ''' , nonMetaClass nameWithoutPrefix asLowercaseFirst , eachVariableName , ''''). |
|
1099 |
]. |
|
1100 |
(aClass canUnderstand:#'setName:') ifTrue:[ |
|
1101 |
initCode nextPutAll:('; setName: ''' , eachVariableName asLowercaseFirst , ''''). |
|
1102 |
]. |
|
1103 |
initCode nextPutLine:'.'. |
|
1104 |
]. |
|
1105 |
initCode cr. |
|
1106 |
initCode nextPutLine:' "'. |
|
1107 |
initCode nextPutLine:' ',className, ' initialize'. |
|
1108 |
initCode nextPutLine:' "'. |
|
1109 |
||
1110 |
self |
|
1111 |
compile:(initCode contents) |
|
1112 |
forClass:metaClass |
|
1113 |
inCategory:'class initialization'. |
|
1114 |
||
1115 |
||
1116 |
code := 'allStateNames\ ^ #( ' , |
|
6341 | 1117 |
((enumValues collect:[:each | '#''',each asLowercaseFirst,'''']) asStringWith:' ') , ')', |
6313 | 1118 |
'\\ "\' , |
1119 |
' ',className, ' allStateNames\' , |
|
1120 |
' "\'. |
|
1121 |
self |
|
1122 |
compile:code withCRs |
|
1123 |
forClass:metaClass |
|
1124 |
inCategory:'queries'. |
|
1125 |
||
1126 |
self executeCollectedChangesNamed:('Generate EnumType Code for ' , className). |
|
1127 |
||
1128 |
aClass initialize. |
|
1129 |
||
1130 |
"Modified: / 1.2.1998 / 16:10:03 / cg" |
|
1131 |
! |
|
1132 |
||
8572 | 1133 |
createExamplesMethodForViewClass:aClass |
1134 |
"create an examples method" |
|
1135 |
||
1136 |
|nonMetaClass metaClass className code| |
|
1137 |
||
1138 |
nonMetaClass := aClass theNonMetaclass. |
|
1139 |
metaClass := aClass theMetaclass. |
|
1140 |
className := nonMetaClass name. |
|
1141 |
||
1142 |
self startCollectChanges. |
|
1143 |
||
1144 |
(metaClass includesSelector:#examples) ifFalse:[ |
|
1145 |
code := |
|
1146 |
'examples |
|
1147 |
" |
|
1148 |
Notice that everything between [exBegin] and [exEnd] is extracted by the html-doc generator |
|
1149 |
to create nicely formatted and clickable executable examples in the generated html-doc. |
|
1150 |
(see the browsers class-documentation menu items for more) |
|
1151 |
||
1152 |
trying the widget as standAlone view: |
|
1153 |
[exBegin] |
|
1154 |
%1 new open |
|
1155 |
[exEnd] |
|
1156 |
||
1157 |
embedded in another view: |
|
1158 |
[exBegin] |
|
1159 |
|top v| |
|
1160 |
||
1161 |
top := StandardSystemView new. |
|
1162 |
top extent:300@300. |
|
1163 |
v := %1 new. |
|
1164 |
v origin:10@10 corner:150@150. |
|
1165 |
top add:v. |
|
1166 |
top open |
|
1167 |
[exEnd] |
|
1168 |
" |
|
1169 |
' bindWith:className. |
|
1170 |
||
1171 |
self |
|
1172 |
compile:code |
|
1173 |
forClass:metaClass |
|
1174 |
inCategory:'documentation'. |
|
1175 |
]. |
|
1176 |
||
1177 |
self executeCollectedChangesNamed:('Add Example to ' , className). |
|
1178 |
! |
|
1179 |
||
6718 | 1180 |
createInitializedInstanceCreationMethodsIn:aClass |
5758 | 1181 |
"create a #new and #initialize methods (I'm tired of typing)" |
1182 |
||
6050 | 1183 |
|nonMetaClass metaClass className code initializer m| |
1184 |
||
1185 |
nonMetaClass := aClass theNonMetaclass. |
|
1186 |
metaClass := aClass theMetaclass. |
|
1187 |
className := nonMetaClass name. |
|
5758 | 1188 |
|
1189 |
self startCollectChanges. |
|
1190 |
||
6050 | 1191 |
(nonMetaClass includesSelector:#'initialize') ifFalse:[ |
5758 | 1192 |
code := |
1193 |
'initialize |
|
1194 |
"Invoked when a new instance is created." |
|
1195 |
||
1196 |
"/ please change as required (and remove this comment) |
|
1197 |
'. |
|
1198 |
||
6718 | 1199 |
nonMetaClass instVarNames do:[:eachInstVar | |
1200 |
initializer := 'nil'. "/ need more intelligence here (try to guess class from messages sent to it) ... |
|
1201 |
code := code , (' "/ ' , eachInstVar , ' := ' , initializer , '.' , Character cr). |
|
1202 |
]. |
|
5758 | 1203 |
|
6718 | 1204 |
m := nonMetaClass responseTo:#initialize. |
1205 |
(m notNil and:[m messagesSent size == 0]) ifTrue:[ |
|
1206 |
"/ inherits an empty initialize. |
|
5758 | 1207 |
|
6718 | 1208 |
code := code , ' |
5758 | 1209 |
"/ super initialize. -- commented since inherited method does nothing |
1210 |
'. |
|
6718 | 1211 |
] ifFalse:[ |
1212 |
code := code , ' |
|
1213 |
super initialize. |
|
1214 |
'. |
|
5758 | 1215 |
]. |
1216 |
||
1217 |
self |
|
1218 |
compile:code |
|
6050 | 1219 |
forClass:nonMetaClass |
5758 | 1220 |
inCategory:'initialization'. |
1221 |
]. |
|
1222 |
||
6050 | 1223 |
(metaClass includesSelector:#'new') ifFalse:[ |
1224 |
m := metaClass responseTo:#new. |
|
6718 | 1225 |
(m isNil |
1226 |
or:[ (m sends:#initialize) not |
|
1227 |
or:[ |answer| |
|
1228 |
(Dialog |
|
1229 |
confirmWithCancel:'The inherited #new method already seems to invoke #initialize. Redefine ?' |
|
1230 |
onCancel:[^ self]) ]]) ifTrue:[ |
|
1231 |
code := |
|
5758 | 1232 |
'new |
1233 |
^ self basicNew initialize. |
|
1234 |
'. |
|
6718 | 1235 |
self |
1236 |
compile:code |
|
1237 |
forClass:metaClass |
|
1238 |
inCategory:'instance creation'. |
|
1239 |
]. |
|
1240 |
]. |
|
1241 |
||
1242 |
self executeCollectedChangesNamed:('Add Initialized Instance Creation to ' , className). |
|
1243 |
||
1244 |
"Created: / 11.10.2001 / 22:18:55 / cg" |
|
1245 |
! |
|
1246 |
||
1247 |
createParametrizedInstanceCreationMethodsNamed:selector in:aClass |
|
1248 |
"create a #selector instance creation method (I'm tired of typing)" |
|
1249 |
||
1250 |
|nonMetaClass metaClass className code initializer m dfn| |
|
1251 |
||
1252 |
dfn := Method methodDefinitionTemplateForSelector:selector. |
|
1253 |
||
1254 |
nonMetaClass := aClass theNonMetaclass. |
|
1255 |
metaClass := aClass theMetaclass. |
|
1256 |
className := nonMetaClass name. |
|
1257 |
||
1258 |
self startCollectChanges. |
|
1259 |
||
1260 |
(nonMetaClass includesSelector:selector asSymbol) ifFalse:[ |
|
1261 |
code := |
|
1262 |
'initialize',dfn asUppercaseFirst,' |
|
1263 |
"Invoked when a new instance is created for arg." |
|
1264 |
||
1265 |
"/ please change as required (and remove these comments) |
|
1266 |
"/ do something with arg here (instVar-foo := arg) |
|
1267 |
'. |
|
1268 |
nonMetaClass instVarNames do:[:eachInstVar | |
|
1269 |
initializer := 'nil'. "/ need more intelligence here (try to guess class from messages sent to it) ... |
|
1270 |
code := code , (' "/ ' , eachInstVar , ' := ' , initializer , '.' , Character cr). |
|
1271 |
]. |
|
1272 |
||
1273 |
m := nonMetaClass responseTo:#initialize. |
|
1274 |
(m notNil and:[ m messagesSent size == 0 ]) ifTrue:[ |
|
1275 |
"/ inherits an empty initialize. |
|
1276 |
||
1277 |
code := code , ' |
|
1278 |
"/ super initialize. -- commented since inherited method does nothing |
|
1279 |
'. |
|
1280 |
] ifFalse:[ |
|
1281 |
code := code , ' |
|
1282 |
super initialize. |
|
1283 |
'. |
|
1284 |
]. |
|
1285 |
||
5758 | 1286 |
self |
1287 |
compile:code |
|
6718 | 1288 |
forClass:nonMetaClass |
1289 |
inCategory:'initialization'. |
|
5758 | 1290 |
]. |
1291 |
||
6718 | 1292 |
(metaClass includesSelector:selector) ifFalse:[ |
1293 |
m := metaClass responseTo:selector. |
|
1294 |
(m isNil |
|
1295 |
or:[ (Dialog confirmWithCancel:'The ',selector,'- method is already inherited. Redefine ?' onCancel:[^ self]) ]) |
|
1296 |
ifTrue:[ |
|
1297 |
code := |
|
1298 |
dfn,' |
|
1299 |
"Create & return a new instance for arg." |
|
5758 | 1300 |
|
6718 | 1301 |
^ self basicNew initialize',dfn asUppercaseFirst,' |
1302 |
'. |
|
1303 |
self |
|
1304 |
compile:code |
|
1305 |
forClass:metaClass |
|
1306 |
inCategory:'instance creation'. |
|
1307 |
]. |
|
1308 |
]. |
|
1309 |
||
1310 |
self executeCollectedChangesNamed:('Add Parametrized Instance Creation to ' , className). |
|
5758 | 1311 |
! |
1312 |
||
7470 | 1313 |
createPoolInitializationCodeFor:aClass |
1314 |
|nonMetaClass metaClass className poolVars code initCode runValue maxValue| |
|
1315 |
||
1316 |
self startCollectChanges. |
|
1317 |
||
1318 |
nonMetaClass := aClass theNonMetaclass. |
|
1319 |
metaClass := aClass theMetaclass. |
|
1320 |
className := nonMetaClass name. |
|
1321 |
||
1322 |
poolVars := nonMetaClass classVarNames. |
|
1323 |
||
1324 |
initCode := WriteStream on: String new. |
|
1325 |
initCode nextPutLine:'initialize'. |
|
1326 |
||
1327 |
poolVars do:[:eachVariableName | |
|
1328 |
|oldValue thisValue| |
|
1329 |
||
1330 |
oldValue := nonMetaClass classVarAt:eachVariableName. |
|
1331 |
oldValue notNil ifTrue:[ |
|
1332 |
thisValue := oldValue. |
|
1333 |
] ifFalse:[ |
|
1334 |
thisValue := nil. |
|
1335 |
]. |
|
1336 |
initCode |
|
1337 |
nextPutAll:' '; |
|
1338 |
nextPutAll:eachVariableName; |
|
1339 |
nextPutAll:' := '; |
|
1340 |
nextPutAll:thisValue storeString; |
|
1341 |
nextPutLine:'.'. |
|
1342 |
]. |
|
1343 |
initCode cr. |
|
1344 |
initCode nextPutLine:' "'. |
|
1345 |
initCode nextPutLine:' ',className, ' initialize'. |
|
1346 |
initCode nextPutLine:' "'. |
|
1347 |
||
1348 |
self |
|
1349 |
compile:(initCode contents) |
|
1350 |
forClass:metaClass |
|
1351 |
inCategory:'class initialization'. |
|
1352 |
||
1353 |
self executeCollectedChangesNamed:('Generate Pool Initialization Code for ' , className). |
|
1354 |
||
1355 |
aClass initialize. |
|
1356 |
||
1357 |
"Created: / 25-10-2006 / 09:28:40 / cg" |
|
1358 |
! |
|
1359 |
||
8344
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1360 |
createRedefinedInstanceCreationMethodsIn:aClass |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1361 |
"create a redefined #new methods" |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1362 |
|
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1363 |
|nonMetaClass metaClass className code| |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1364 |
|
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1365 |
nonMetaClass := aClass theNonMetaclass. |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1366 |
metaClass := aClass theMetaclass. |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1367 |
className := nonMetaClass name. |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1368 |
|
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1369 |
self startCollectChanges. |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1370 |
|
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1371 |
(metaClass includesSelector:#'new') ifFalse:[ |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1372 |
code := |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1373 |
'new |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1374 |
^ super new. |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1375 |
'. |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1376 |
self |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1377 |
compile:code |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1378 |
forClass:metaClass |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1379 |
inCategory:'redefined instance creation'. |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1380 |
]. |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1381 |
(metaClass includesSelector:#'new:') ifFalse:[ |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1382 |
code := |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1383 |
'new:n |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1384 |
^ super new:n. |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1385 |
'. |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1386 |
self |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1387 |
compile:code |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1388 |
forClass:metaClass |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1389 |
inCategory:'redefined instance creation'. |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1390 |
]. |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1391 |
|
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1392 |
self executeCollectedChangesNamed:('Redefined Instance Creation to ' , className). |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1393 |
! |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1394 |
|
5953 | 1395 |
createStandardPrintOnMethodIn:aClass |
1396 |
"create a #printOn: method (I'm tired of typing)" |
|
1397 |
||
6050 | 1398 |
|code nonMetaClass| |
1399 |
||
1400 |
nonMetaClass := aClass theNonMetaclass. |
|
5953 | 1401 |
|
1402 |
self startCollectChanges. |
|
1403 |
||
6050 | 1404 |
(nonMetaClass includesSelector:#'printOn:') ifFalse:[ |
5953 | 1405 |
code := |
1406 |
'printOn:aStream |
|
1407 |
"append a printed representation if the receiver to the argument, aStream" |
|
1408 |
||
1409 |
super printOn:aStream. |
|
1410 |
'. |
|
6050 | 1411 |
nonMetaClass instVarNames do:[:eachInstVarName | |
5953 | 1412 |
code := code , ' '. |
1413 |
code := code , 'aStream nextPutAll:'''. |
|
1414 |
code := code , eachInstVarName. |
|
1415 |
code := code , ': ''.' , Character cr. |
|
1416 |
code := code , ' '. |
|
1417 |
code := code , eachInstVarName. |
|
1418 |
code := code , ' printOn:aStream.' , Character cr. |
|
1419 |
||
1420 |
]. |
|
1421 |
||
1422 |
self |
|
1423 |
compile:code |
|
6050 | 1424 |
forClass:nonMetaClass |
5953 | 1425 |
inCategory:'printing & storing'. |
1426 |
]. |
|
1427 |
||
1428 |
||
6050 | 1429 |
self executeCollectedChangesNamed:('Add #printOn: to ' , nonMetaClass name). |
5953 | 1430 |
|
1431 |
"Created: / 11.10.2001 / 22:18:55 / cg" |
|
1432 |
! |
|
1433 |
||
9081 | 1434 |
createStartupCodeFor:aClass forStartOf:anApplicationClassOrNil |
9049
9a2003a4fef3
added: #createStartupCodeFor:forStartOf:
Claus Gittinger <cg@exept.de>
parents:
9044
diff
changeset
|
1435 |
"create startup code (main)" |
9a2003a4fef3
added: #createStartupCodeFor:forStartOf:
Claus Gittinger <cg@exept.de>
parents:
9044
diff
changeset
|
1436 |
|
9081 | 1437 |
|nonMetaClass metaClass className source |
1438 |
hasAplicationClass anApplicationClassNameOrStartupClassName| |
|
9049
9a2003a4fef3
added: #createStartupCodeFor:forStartOf:
Claus Gittinger <cg@exept.de>
parents:
9044
diff
changeset
|
1439 |
|
9a2003a4fef3
added: #createStartupCodeFor:forStartOf:
Claus Gittinger <cg@exept.de>
parents:
9044
diff
changeset
|
1440 |
self startCollectChanges. |
9a2003a4fef3
added: #createStartupCodeFor:forStartOf:
Claus Gittinger <cg@exept.de>
parents:
9044
diff
changeset
|
1441 |
|
9081 | 1442 |
hasAplicationClass := anApplicationClassOrNil notNil. |
9049
9a2003a4fef3
added: #createStartupCodeFor:forStartOf:
Claus Gittinger <cg@exept.de>
parents:
9044
diff
changeset
|
1443 |
nonMetaClass := aClass theNonMetaclass. |
9a2003a4fef3
added: #createStartupCodeFor:forStartOf:
Claus Gittinger <cg@exept.de>
parents:
9044
diff
changeset
|
1444 |
metaClass := aClass theMetaclass. |
9a2003a4fef3
added: #createStartupCodeFor:forStartOf:
Claus Gittinger <cg@exept.de>
parents:
9044
diff
changeset
|
1445 |
className := nonMetaClass name. |
9a2003a4fef3
added: #createStartupCodeFor:forStartOf:
Claus Gittinger <cg@exept.de>
parents:
9044
diff
changeset
|
1446 |
|
9a2003a4fef3
added: #createStartupCodeFor:forStartOf:
Claus Gittinger <cg@exept.de>
parents:
9044
diff
changeset
|
1447 |
(metaClass includesSelector:#main:) ifFalse:[ |
9081 | 1448 |
|
1449 |
source := String streamContents:[:stream | |
|
1450 |
stream nextPutAll: |
|
9049
9a2003a4fef3
added: #createStartupCodeFor:forStartOf:
Claus Gittinger <cg@exept.de>
parents:
9044
diff
changeset
|
1451 |
'main:argv |
9a2003a4fef3
added: #createStartupCodeFor:forStartOf:
Claus Gittinger <cg@exept.de>
parents:
9044
diff
changeset
|
1452 |
self verboseInfo:''starting %1''. |
9a2003a4fef3
added: #createStartupCodeFor:forStartOf:
Claus Gittinger <cg@exept.de>
parents:
9044
diff
changeset
|
1453 |
|
9081 | 1454 |
'. |
1455 |
hasAplicationClass ifTrue: [ |
|
1456 |
stream nextPutAll: |
|
1457 |
' %1 open. |
|
9049
9a2003a4fef3
added: #createStartupCodeFor:forStartOf:
Claus Gittinger <cg@exept.de>
parents:
9044
diff
changeset
|
1458 |
'. |
9081 | 1459 |
]. |
1460 |
]. |
|
1461 |
||
1462 |
anApplicationClassNameOrStartupClassName := hasAplicationClass |
|
1463 |
ifTrue: [anApplicationClassOrNil name] |
|
1464 |
ifFalse: [className.]. |
|
9049
9a2003a4fef3
added: #createStartupCodeFor:forStartOf:
Claus Gittinger <cg@exept.de>
parents:
9044
diff
changeset
|
1465 |
self |
9081 | 1466 |
compile:(source bindWith:anApplicationClassNameOrStartupClassName) |
9049
9a2003a4fef3
added: #createStartupCodeFor:forStartOf:
Claus Gittinger <cg@exept.de>
parents:
9044
diff
changeset
|
1467 |
forClass:metaClass |
9a2003a4fef3
added: #createStartupCodeFor:forStartOf:
Claus Gittinger <cg@exept.de>
parents:
9044
diff
changeset
|
1468 |
inCategory:'startup'. |
9a2003a4fef3
added: #createStartupCodeFor:forStartOf:
Claus Gittinger <cg@exept.de>
parents:
9044
diff
changeset
|
1469 |
]. |
9a2003a4fef3
added: #createStartupCodeFor:forStartOf:
Claus Gittinger <cg@exept.de>
parents:
9044
diff
changeset
|
1470 |
self executeCollectedChangesNamed:('Add Startup Code to ' , className). |
9a2003a4fef3
added: #createStartupCodeFor:forStartOf:
Claus Gittinger <cg@exept.de>
parents:
9044
diff
changeset
|
1471 |
! |
9a2003a4fef3
added: #createStartupCodeFor:forStartOf:
Claus Gittinger <cg@exept.de>
parents:
9044
diff
changeset
|
1472 |
|
5758 | 1473 |
createTestCaseSampleCodeFor:aClass |
1474 |
"create an (almost) empty testCase class" |
|
1475 |
||
1476 |
|nonMetaClass metaClass| |
|
1477 |
||
1478 |
nonMetaClass := aClass theNonMetaclass. |
|
1479 |
metaClass := aClass theMetaclass. |
|
1480 |
"/ className := nonMetaClass name. |
|
1481 |
||
1482 |
( nonMetaClass includesSelector:#test1 ) ifFalse:[ |
|
1483 |
self |
|
1484 |
compile: |
|
1485 |
'test1 |
|
1486 |
"This is a demonstration testCase - it is meant to be removed eventually. |
|
1487 |
This testCase will PASS. |
|
1488 |
Double click on the TestCase class or open a TestRunner to see me checking... |
|
1489 |
- please add more methods like this..." |
|
1490 |
||
1491 |
|o| |
|
1492 |
||
1493 |
o := Array new:2. |
|
1494 |
self assert: ( o size == 2 ). |
|
1495 |
self should: [ o at:0 ] raise:Error. |
|
1496 |
self shouldnt: [ o at:1 ] raise:Error. |
|
1497 |
||
1498 |
" |
|
1499 |
self run:#test1 |
|
1500 |
self new test1 |
|
1501 |
" |
|
1502 |
' |
|
1503 |
forClass:nonMetaClass |
|
1504 |
inCategory:'tests'. |
|
1505 |
]. |
|
1506 |
||
1507 |
( nonMetaClass includesSelector:#test2 ) ifFalse:[ |
|
1508 |
self |
|
1509 |
compile: |
|
1510 |
'test2 |
|
1511 |
"This is a demonstration testCase - it is meant to be removed eventually.. |
|
1512 |
This testCase WILL FAIL. |
|
1513 |
Double click on the TestCase class or open a TestRunner to see me checking... |
|
1514 |
- please add more methods like this..." |
|
1515 |
||
1516 |
|o| |
|
1517 |
||
1518 |
o := Array new:2. |
|
1519 |
self assert: ( o size == 3 ). |
|
1520 |
||
1521 |
" |
|
1522 |
self run:#test2 |
|
1523 |
self new test2 |
|
1524 |
" |
|
1525 |
' |
|
1526 |
forClass:nonMetaClass |
|
1527 |
inCategory:'tests'. |
|
1528 |
]. |
|
1529 |
||
1530 |
( nonMetaClass includesSelector:#test3 ) ifFalse:[ |
|
1531 |
self |
|
1532 |
compile: |
|
1533 |
'test3 |
|
1534 |
"This is a demonstration testCase - it is meant to be removed eventually.. |
|
1535 |
This testCase WILL generate an ERROR. |
|
1536 |
Double click on the TestCase class or open a TestRunner to see me checking... |
|
1537 |
- please add more methods like this..." |
|
1538 |
||
1539 |
|o| |
|
1540 |
||
1541 |
o := Array new:2. |
|
1542 |
self assert: ( o foo ). |
|
1543 |
||
1544 |
" |
|
1545 |
self run:#test3 |
|
1546 |
self new test3 |
|
1547 |
" |
|
1548 |
' |
|
1549 |
forClass:nonMetaClass |
|
1550 |
inCategory:'tests'. |
|
1551 |
]. |
|
1552 |
||
1553 |
( nonMetaClass includesSelector:#setUp ) ifFalse:[ |
|
1554 |
self |
|
1555 |
compile: |
|
1556 |
'setUp |
|
1557 |
"common setup - invoked before testing." |
|
1558 |
||
1559 |
super setUp |
|
1560 |
' |
|
1561 |
forClass:nonMetaClass |
|
1562 |
inCategory:'initialize / release'. |
|
1563 |
]. |
|
1564 |
||
1565 |
( nonMetaClass includesSelector:#tearDown ) ifFalse:[ |
|
1566 |
self |
|
1567 |
compile: |
|
1568 |
'tearDown |
|
1569 |
"common cleanup - invoked after testing." |
|
1570 |
||
1571 |
super tearDown |
|
1572 |
' |
|
1573 |
forClass:nonMetaClass |
|
1574 |
inCategory:'initialize / release'. |
|
1575 |
] |
|
1576 |
! |
|
1577 |
||
1578 |
createVisitorMethodsIn:visitedClass andVisitorClass:visitorClass |
|
1579 |
"create acceptVisitor: in visitedClass and acceptXXX in visitorClass. (I'm tired of typing)" |
|
1580 |
||
1581 |
|sel| |
|
1582 |
||
6921 | 1583 |
self assert:( visitedClass isMeta not ). |
1584 |
self assert:( visitorClass isMeta not ). |
|
5758 | 1585 |
|
1586 |
self startCollectChanges. |
|
1587 |
||
1588 |
sel := ('visit' , visitedClass nameWithoutPrefix , ':'). |
|
1589 |
self createAcceptVisitorMethod:sel in:visitedClass. |
|
1590 |
||
1591 |
(visitorClass includesSelector:sel) ifFalse:[ |
|
1592 |
self |
|
1593 |
compile: |
|
1594 |
(('%1anObject |
|
1595 |
"dispatched back from the visited %2-object (visitor pattern)" |
|
1596 |
||
1597 |
"fall back to general object-case - please change as required" |
|
1598 |
||
1599 |
^ self visitObject:anObject |
|
1600 |
') bindWith:sel with:visitedClass nameWithoutPrefix asLowercaseFirst) |
|
1601 |
forClass:visitorClass |
|
1602 |
inCategory:'visiting'. |
|
1603 |
]. |
|
1604 |
||
1605 |
(visitorClass includesSelector:#'visitObject:') ifFalse:[ |
|
1606 |
self |
|
1607 |
compile: |
|
1608 |
('visitObject:anObject |
|
1609 |
"dispatched back from the visited objects (visitor pattern)" |
|
1610 |
||
1611 |
"general fallBack - please change as required" |
|
1612 |
||
1613 |
self halt:''not yet implemented'' |
|
1614 |
') |
|
1615 |
forClass:visitorClass |
|
1616 |
inCategory:'visiting'. |
|
1617 |
]. |
|
1618 |
||
1619 |
(visitorClass includesSelector:#'visit:') ifFalse:[ |
|
1620 |
self |
|
1621 |
compile: |
|
1622 |
('visit:anObject |
|
1623 |
"visit anObject (visitor pattern). |
|
1624 |
The object should call back one of my visitXXXX methods." |
|
1625 |
||
1626 |
^ anObject acceptVisitor:self |
|
1627 |
') |
|
1628 |
forClass:visitorClass |
|
1629 |
inCategory:'visiting'. |
|
1630 |
]. |
|
1631 |
||
1632 |
self executeCollectedChangesNamed:('Add Visitor Pattern'). |
|
6050 | 1633 |
! |
1634 |
||
1635 |
createWebApplicationCodeFor:aClass |
|
1636 |
"create an empty webApplication framework" |
|
1637 |
||
1638 |
|nonMetaClass metaClass className txt| |
|
1639 |
||
1640 |
self startCollectChanges. |
|
1641 |
||
1642 |
nonMetaClass := aClass theNonMetaclass. |
|
1643 |
metaClass := aClass theMetaclass. |
|
1644 |
className := nonMetaClass name. |
|
1645 |
||
7973 | 1646 |
(metaClass includesSelector:#pageSpec) ifFalse:[ |
1647 |
txt := self class initialPageSpecMethodSourceForWebApplications. |
|
1648 |
self |
|
1649 |
compile:(txt bindWith:className) |
|
1650 |
forClass:metaClass |
|
1651 |
inCategory:'page specs'. |
|
1652 |
]. |
|
1653 |
||
1654 |
self executeCollectedChangesNamed:('Add WebApplication Code for ' , className). |
|
1655 |
||
1656 |
"Modified: / 1.2.1998 / 16:10:03 / cg" |
|
1657 |
! |
|
1658 |
||
1659 |
createWebServiceCodeFor:aClass |
|
1660 |
"create an empty webService framework" |
|
1661 |
||
1662 |
|nonMetaClass metaClass className txt| |
|
1663 |
||
1664 |
self startCollectChanges. |
|
1665 |
||
1666 |
nonMetaClass := aClass theNonMetaclass. |
|
1667 |
metaClass := aClass theMetaclass. |
|
1668 |
className := nonMetaClass name. |
|
1669 |
||
6050 | 1670 |
(nonMetaClass includesSelector:#process:) ifFalse:[ |
1671 |
txt := |
|
1672 |
'process:aRequest |
|
7973 | 1673 |
"This is the web services main processing method. |
6050 | 1674 |
It will be invoked for every incoming webBrowser-request. |
1675 |
The argument, aRequest contains the parameters (url, fields, parameters etc.)." |
|
1676 |
||
1677 |
|response| |
|
1678 |
||
1679 |
response := aRequest response. |
|
1680 |
response nextPutLine:''<HTML>''. |
|
1681 |
response nextPutLine:'' <HEAD>''. |
|
1682 |
response nextPutLine:'' <TITLE>Hello</TITLE>''. |
|
1683 |
response nextPutLine:'' </HEAD>''. |
|
1684 |
response nextPutLine:'' <BODY>''. |
|
1685 |
response nextPutLine:'' <H1>Hello World !!</H1>''. |
|
1686 |
response nextPutLine:'' </BODY>''. |
|
1687 |
response nextPutLine:''</HTML>''. |
|
1688 |
'. |
|
1689 |
self |
|
1690 |
compile:txt |
|
1691 |
forClass:nonMetaClass |
|
1692 |
inCategory:'response generation'. |
|
1693 |
]. |
|
1694 |
||
1695 |
(metaClass includesSelector:#linkName) ifFalse:[ |
|
1696 |
txt := |
|
1697 |
'linkName |
|
1698 |
"return the default linkName path (with slash)." |
|
1699 |
||
1700 |
^ ''/NewService'' |
|
1701 |
'. |
|
1702 |
self |
|
1703 |
compile:txt |
|
1704 |
forClass:metaClass |
|
1705 |
inCategory:'defaults'. |
|
1706 |
]. |
|
1707 |
||
1708 |
(metaClass includesSelector:#settingsApplicationClass) ifFalse:[ |
|
1709 |
txt := |
|
1710 |
'settingsApplicationClass |
|
1711 |
"a SettingsApplication class - or nil (used in the settings dialog if non-nil)." |
|
1712 |
||
1713 |
^ nil |
|
1714 |
'. |
|
1715 |
self |
|
1716 |
compile:txt |
|
1717 |
forClass:metaClass |
|
1718 |
inCategory:'defaults'. |
|
1719 |
]. |
|
1720 |
||
1721 |
||
7973 | 1722 |
self executeCollectedChangesNamed:('Add WebService Code for ' , className). |
6050 | 1723 |
|
1724 |
"Modified: / 1.2.1998 / 16:10:03 / cg" |
|
8572 | 1725 |
! |
1726 |
||
1727 |
createWidgetCodeFor:aClass |
|
1728 |
"create usually required widget code (redraw, model update, event handling)" |
|
1729 |
||
1730 |
|nonMetaClass metaClass className compileTemplateAction| |
|
1731 |
||
1732 |
self startCollectChanges. |
|
1733 |
||
1734 |
nonMetaClass := aClass theNonMetaclass. |
|
1735 |
metaClass := aClass theMetaclass. |
|
1736 |
className := nonMetaClass name. |
|
1737 |
||
1738 |
compileTemplateAction := |
|
1739 |
[:selector :templateSelector :category | |
|
1740 |
(nonMetaClass includesSelector:selector) ifFalse:[ |
|
1741 |
|txt| |
|
1742 |
||
1743 |
txt := self perform:templateSelector. |
|
1744 |
self |
|
1745 |
compile:txt |
|
1746 |
forClass:nonMetaClass |
|
1747 |
inCategory:category. |
|
1748 |
] |
|
1749 |
]. |
|
1750 |
||
1751 |
#( |
|
1752 |
#'initialize' #code_forWidget_initialize 'initialization & release' |
|
1753 |
#'update:with:from:' #code_forWidget_update 'change & update' |
|
1754 |
#'redrawX:y:width:height:' #code_forWidget_redraw 'drawing' |
|
1755 |
#'buttonPress:x:y:' #code_forWidget_buttonPress 'event handling' |
|
1756 |
#'keyPress:x:y:' #code_forWidget_keyPress 'event handling' |
|
1757 |
#'sizeChanged:' #code_forWidget_sizeChanged 'event handling' |
|
1758 |
) inGroupsOf:3 do:compileTemplateAction. |
|
1759 |
||
1760 |
self executeCollectedChangesNamed:('Add Widget Code for ' , className). |
|
5758 | 1761 |
! ! |
1762 |
||
1763 |
!CodeGeneratorTool methodsFor:'code generation-basic'! |
|
1764 |
||
1765 |
createAccessMethodsFor:aCollectionOfVarNames in:aClass withChange:withChange asValueHolder:asValueHolder readersOnly:readersOnly writersOnly:writersOnly lazyInitialization:lazyInitialization |
|
1766 |
"workhorse for creating access methods for instvars." |
|
1767 |
||
8572 | 1768 |
|classesClassVars generateCommentsForSetters generateCommentsForGetters| |
5758 | 1769 |
|
1770 |
self startCollectChanges. |
|
1771 |
||
8572 | 1772 |
generateCommentsForSetters := userPreferences generateCommentsForSetters. |
1773 |
generateCommentsForGetters := userPreferences generateCommentsForGetters. |
|
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1774 |
|
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1775 |
classesClassVars := aClass theNonMetaclass allClassVarNames. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1776 |
|
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1777 |
aCollectionOfVarNames do:[:name | |
8773
a722c4bb21a7
changed: #createAccessMethodsFor:in:withChange:asValueHolder:readersOnly:writersOnly:lazyInitialization:
Claus Gittinger <cg@exept.de>
parents:
8574
diff
changeset
|
1778 |
|source varType methodName defaultMethodName argName| |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1779 |
|
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1780 |
varType := (classesClassVars includes:name) |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1781 |
ifTrue:['static'] |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1782 |
ifFalse:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1783 |
(aClass isMeta ifTrue:['classInstVar'] ifFalse:['instance'])]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1784 |
|
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1785 |
methodName := name. |
6643 | 1786 |
name isUppercaseFirst ifTrue:[ |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1787 |
methodName := methodName asLowercaseFirst. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1788 |
]. |
8773
a722c4bb21a7
changed: #createAccessMethodsFor:in:withChange:asValueHolder:readersOnly:writersOnly:lazyInitialization:
Claus Gittinger <cg@exept.de>
parents:
8574
diff
changeset
|
1789 |
argName := 'something'. |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1790 |
|
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1791 |
"/ the GETTER |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1792 |
writersOnly ifFalse:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1793 |
lazyInitialization ifTrue:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1794 |
defaultMethodName := 'default' , name asUppercaseFirst. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1795 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1796 |
|
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1797 |
"check, if method is not already present" |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1798 |
(aClass includesSelector:(methodName asSymbol)) ifFalse:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1799 |
asValueHolder ifTrue:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1800 |
source := methodName , '\'. |
5758 | 1801 |
generateComments ifTrue:[ |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1802 |
source := source , ' "return/create the ''%2'' value holder (automatically generated)"\\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1803 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1804 |
source := source , ' %2 isNil ifTrue:[\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1805 |
lazyInitialization ifTrue:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1806 |
source := source |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1807 |
, ' %2 := self class %3 asValue.\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1808 |
] ifFalse:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1809 |
source := source |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1810 |
, ' %2 := ValueHolder new.\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1811 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1812 |
|
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1813 |
withChange ifTrue:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1814 |
source := source |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1815 |
, ' %2 addDependent:self.\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1816 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1817 |
source := source |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1818 |
, ' ].\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1819 |
, ' ^ %2'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1820 |
] ifFalse:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1821 |
source := methodName , '\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1822 |
lazyInitialization ifTrue:[ |
5758 | 1823 |
generateCommentsForGetters ifTrue:[ |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1824 |
source := source , ' "return the %1 instance variable ''%2'' with lazy instance creation (automatically generated)"\\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1825 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1826 |
source := source |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1827 |
, ' %2 isNil ifTrue:[\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1828 |
, ' %2 := self class %3.\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1829 |
, ' ].\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1830 |
, ' ^ %2'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1831 |
] ifFalse:[ |
5758 | 1832 |
generateCommentsForGetters ifTrue:[ |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1833 |
source := source , ' "return the %1 instance variable ''%2'' (automatically generated)"\\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1834 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1835 |
source := source |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1836 |
, ' ^ %2'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1837 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1838 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1839 |
source := (source bindWith:varType with:name with:defaultMethodName) withCRs. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1840 |
self compile:source forClass:aClass inCategory:(asValueHolder ifTrue:['aspects'] ifFalse:['accessing']). |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1841 |
] ifTrue:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1842 |
Transcript showCR:'method ''', methodName , ''' already present' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1843 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1844 |
|
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1845 |
"/ default for lazy on class side |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1846 |
lazyInitialization ifTrue:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1847 |
(aClass class includesSelector:(defaultMethodName asSymbol)) ifFalse:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1848 |
source := defaultMethodName , '\'. |
5758 | 1849 |
generateComments ifTrue:[ |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1850 |
source := source , ' "default value for the ''%2'' instance variable (automatically generated)"\\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1851 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1852 |
source := source |
6839
c25218305e50
Send #shouldImplement instead of #halt:.
Stefan Vogel <sv@exept.de>
parents:
6791
diff
changeset
|
1853 |
, ' self shouldImplement.\' |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1854 |
, ' ^ nil.'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1855 |
source := (source bindWith:varType with:name) withCRs. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1856 |
self compile:source forClass:aClass class inCategory:'defaults'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1857 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1858 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1859 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1860 |
|
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1861 |
"/ the SETTER |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1862 |
readersOnly ifFalse:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1863 |
(aClass includesSelector:((methodName , ':') asSymbol)) ifFalse:[ |
8773
a722c4bb21a7
changed: #createAccessMethodsFor:in:withChange:asValueHolder:readersOnly:writersOnly:lazyInitialization:
Claus Gittinger <cg@exept.de>
parents:
8574
diff
changeset
|
1864 |
((methodName size > 2) and:[ (methodName startsWith:'is') and:[ (methodName at:3) isUppercase ]]) |
a722c4bb21a7
changed: #createAccessMethodsFor:in:withChange:asValueHolder:readersOnly:writersOnly:lazyInitialization:
Claus Gittinger <cg@exept.de>
parents:
8574
diff
changeset
|
1865 |
ifTrue:[ |
a722c4bb21a7
changed: #createAccessMethodsFor:in:withChange:asValueHolder:readersOnly:writersOnly:lazyInitialization:
Claus Gittinger <cg@exept.de>
parents:
8574
diff
changeset
|
1866 |
argName := 'aBoolean' |
a722c4bb21a7
changed: #createAccessMethodsFor:in:withChange:asValueHolder:readersOnly:writersOnly:lazyInitialization:
Claus Gittinger <cg@exept.de>
parents:
8574
diff
changeset
|
1867 |
]. |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1868 |
asValueHolder ifTrue:[ |
8773
a722c4bb21a7
changed: #createAccessMethodsFor:in:withChange:asValueHolder:readersOnly:writersOnly:lazyInitialization:
Claus Gittinger <cg@exept.de>
parents:
8574
diff
changeset
|
1869 |
source := methodName , ':%3\'. "/ argName |
5758 | 1870 |
generateComments ifTrue:[ |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1871 |
source := source , ' "set the ''%2'' value holder' , ' (automatically generated)"\\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1872 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1873 |
withChange ifTrue:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1874 |
source := source |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1875 |
, ' |oldValue newValue|\\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1876 |
, ' %2 notNil ifTrue:[\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1877 |
, ' oldValue := %2 value.\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1878 |
, ' %2 removeDependent:self.\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1879 |
, ' ].\' |
8773
a722c4bb21a7
changed: #createAccessMethodsFor:in:withChange:asValueHolder:readersOnly:writersOnly:lazyInitialization:
Claus Gittinger <cg@exept.de>
parents:
8574
diff
changeset
|
1880 |
, ' %2 := %3.\' "/ argName |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1881 |
, ' %2 notNil ifTrue:[\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1882 |
, ' %2 addDependent:self.\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1883 |
, ' ].\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1884 |
, ' newValue := %2 value.\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1885 |
, ' oldValue ~~ newValue ifTrue:[\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1886 |
, ' self update:#value with:newValue from:%2.\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1887 |
, ' ].\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1888 |
] ifFalse:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1889 |
source := source |
8773
a722c4bb21a7
changed: #createAccessMethodsFor:in:withChange:asValueHolder:readersOnly:writersOnly:lazyInitialization:
Claus Gittinger <cg@exept.de>
parents:
8574
diff
changeset
|
1890 |
, ' %2 := %3.'. "/ argName |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1891 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1892 |
] ifFalse:[ |
8773
a722c4bb21a7
changed: #createAccessMethodsFor:in:withChange:asValueHolder:readersOnly:writersOnly:lazyInitialization:
Claus Gittinger <cg@exept.de>
parents:
8574
diff
changeset
|
1893 |
source := methodName , ':%3\'. "/ argName |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1894 |
withChange ifTrue:[ |
5758 | 1895 |
generateComments ifTrue:[ |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1896 |
source := source , ' "set the value of the %1 variable ''%2'''. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1897 |
source := source , ' and send a change notification (automatically generated)"\\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1898 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1899 |
source := source |
8773
a722c4bb21a7
changed: #createAccessMethodsFor:in:withChange:asValueHolder:readersOnly:writersOnly:lazyInitialization:
Claus Gittinger <cg@exept.de>
parents:
8574
diff
changeset
|
1900 |
, ' (%2 ~~ %3) ifTrue:[\' |
a722c4bb21a7
changed: #createAccessMethodsFor:in:withChange:asValueHolder:readersOnly:writersOnly:lazyInitialization:
Claus Gittinger <cg@exept.de>
parents:
8574
diff
changeset
|
1901 |
, ' %2 := %3.\' "/ argName |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1902 |
, ' self changed:#%2.\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1903 |
, ' ].\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1904 |
] ifFalse:[ |
5758 | 1905 |
generateCommentsForSetters ifTrue:[ |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1906 |
source := source , ' "set the value of the %1 variable ''%2'''. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1907 |
source := source , ' (automatically generated)"\\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1908 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1909 |
source := source |
8773
a722c4bb21a7
changed: #createAccessMethodsFor:in:withChange:asValueHolder:readersOnly:writersOnly:lazyInitialization:
Claus Gittinger <cg@exept.de>
parents:
8574
diff
changeset
|
1910 |
, ' %2 := %3.'. "/ argName |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1911 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1912 |
]. |
8773
a722c4bb21a7
changed: #createAccessMethodsFor:in:withChange:asValueHolder:readersOnly:writersOnly:lazyInitialization:
Claus Gittinger <cg@exept.de>
parents:
8574
diff
changeset
|
1913 |
source := (source bindWith:varType with:name with:argName) withCRs. |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1914 |
self |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1915 |
compile:source |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1916 |
forClass:aClass |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1917 |
inCategory:(asValueHolder ifTrue:['aspects'] ifFalse:['accessing']). |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1918 |
] ifTrue:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1919 |
Transcript showCR:'method ''', methodName , ':'' already present' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1920 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1921 |
]. |
5758 | 1922 |
]. |
1923 |
||
1924 |
self executeCollectedChangesNamed:('Add Accessors'). |
|
5763 | 1925 |
! |
1926 |
||
7615 | 1927 |
createCollectionAccessMethodsFor:aCollectionOfVarNames in:aClass withChange:withChange |
8572 | 1928 |
|classesClassVars| |
7615 | 1929 |
|
1930 |
self startCollectChanges. |
|
1931 |
||
1932 |
classesClassVars := aClass theNonMetaclass allClassVarNames. |
|
1933 |
||
1934 |
aCollectionOfVarNames do:[:name | |
|
1935 |
|source varType methodNameBase methodName defaultMethodName| |
|
1936 |
||
1937 |
varType := (classesClassVars includes:name) |
|
1938 |
ifTrue:['static'] |
|
1939 |
ifFalse:[ |
|
1940 |
(aClass isMeta ifTrue:['classInstVar'] ifFalse:['instance'])]. |
|
1941 |
||
1942 |
methodNameBase := name asUppercaseFirst. |
|
1943 |
(methodNameBase endsWith:'s') ifTrue:[ |
|
1944 |
methodNameBase := methodNameBase copyWithoutLast:1. |
|
1945 |
]. |
|
1946 |
methodName := 'add' , methodNameBase, ':'. |
|
1947 |
||
1948 |
"check, if method is not already present" |
|
1949 |
(aClass includesSelector:(methodName asSymbol)) ifFalse:[ |
|
1950 |
source := methodName , 'a%1\'. |
|
1951 |
generateComments ifTrue:[ |
|
1952 |
source := source , ' "add a ',methodNameBase,'"\\'. |
|
1953 |
]. |
|
1954 |
source := source , ' %2 isNil ifTrue:[\'. |
|
1955 |
source := source |
|
1956 |
, ' %2 := OrderedCollection new.\'. |
|
1957 |
source := source |
|
1958 |
, ' ].\' |
|
1959 |
, ' %2 add: a%1'. |
|
1960 |
source := (source bindWith:methodNameBase with:name) withCRs. |
|
1961 |
self compile:source forClass:aClass inCategory:'accessing'. |
|
1962 |
] ifTrue:[ |
|
1963 |
Transcript showCR:'method ''', methodName , ''' already present' |
|
1964 |
]. |
|
1965 |
||
1966 |
methodName := 'remove' , methodNameBase, ':'. |
|
1967 |
||
1968 |
"check, if method is not already present" |
|
1969 |
(aClass includesSelector:(methodName asSymbol)) ifFalse:[ |
|
1970 |
source := methodName , 'a%1\'. |
|
1971 |
generateComments ifTrue:[ |
|
1972 |
source := source , ' "remove a ',methodNameBase,'"\\'. |
|
1973 |
]. |
|
1974 |
source := source |
|
1975 |
, ' %2 remove: a%1'. |
|
1976 |
source := (source bindWith:methodNameBase with:name) withCRs. |
|
1977 |
self compile:source forClass:aClass inCategory:'accessing'. |
|
1978 |
] ifTrue:[ |
|
1979 |
Transcript showCR:'method ''', methodName , ''' already present' |
|
1980 |
]. |
|
1981 |
]. |
|
1982 |
||
1983 |
self |
|
1984 |
createAccessMethodsFor:aCollectionOfVarNames |
|
1985 |
in:aClass |
|
1986 |
withChange:withChange |
|
1987 |
asValueHolder:false |
|
1988 |
readersOnly:true |
|
1989 |
writersOnly:false |
|
1990 |
lazyInitialization:false. |
|
1991 |
||
1992 |
self executeCollectedChangesNamed:('Add Collection Access'). |
|
1993 |
||
1994 |
"Created: / 04-02-2007 / 15:52:31 / cg" |
|
1995 |
! |
|
1996 |
||
5763 | 1997 |
createValueHoldersFor:aCollectionOfVarNames in:aClass lazyInitialization:lazyInitialization |
1998 |
"workhorse for creating access methods for instvars." |
|
1999 |
||
8572 | 2000 |
|nonMetaClass metaClass classesClassVars generateCommentsForSetters generateCommentsForGetters| |
6050 | 2001 |
|
2002 |
nonMetaClass := aClass theNonMetaclass. |
|
2003 |
metaClass := aClass theMetaclass. |
|
5763 | 2004 |
|
2005 |
self startCollectChanges. |
|
2006 |
||
8572 | 2007 |
generateCommentsForSetters := userPreferences generateCommentsForSetters. |
2008 |
generateCommentsForGetters := userPreferences generateCommentsForGetters. |
|
5763 | 2009 |
|
6050 | 2010 |
classesClassVars := nonMetaClass allClassVarNames. |
5763 | 2011 |
|
2012 |
aCollectionOfVarNames do:[:name | |
|
2013 |
|source varType methodName holderMethodName defaultMethodName| |
|
2014 |
||
2015 |
holderMethodName := name. |
|
6643 | 2016 |
name isUppercaseFirst ifTrue:[ |
5763 | 2017 |
holderMethodName := holderMethodName asLowercaseFirst. |
2018 |
]. |
|
2019 |
(holderMethodName endsWith:'Holder') ifTrue:[ |
|
2020 |
methodName := holderMethodName copyWithoutLast:6. |
|
2021 |
] ifFalse:[ |
|
2022 |
methodName := holderMethodName. |
|
2023 |
holderMethodName := methodName , 'Holder'. |
|
2024 |
]. |
|
2025 |
||
2026 |
methodName notNil ifTrue:[ |
|
6050 | 2027 |
(metaClass includesSelector:(methodName asSymbol)) ifFalse:[ |
5763 | 2028 |
source := '%1\'. |
2029 |
generateComments ifTrue:[ |
|
2030 |
source := source , ' "return the value in ''%2''"\\'. |
|
2031 |
]. |
|
2032 |
source := source , ' ^ self %2 value'. |
|
2033 |
source := (source bindWith:methodName with:holderMethodName) withCRs. |
|
6050 | 2034 |
self compile:source forClass:nonMetaClass inCategory:('accessing'). |
5763 | 2035 |
] ifTrue:[ |
2036 |
Transcript showCR:'method ''', methodName , ''' already present' |
|
2037 |
]. |
|
2038 |
||
6050 | 2039 |
(metaClass includesSelector:((methodName , ':') asSymbol)) ifFalse:[ |
5763 | 2040 |
source := '%1: newValue\'. |
2041 |
generateComments ifTrue:[ |
|
2042 |
source := source , ' "set the value in ''%2''"\\'. |
|
2043 |
]. |
|
2044 |
source := source , ' self %2 value: newValue'. |
|
2045 |
source := (source bindWith:methodName with:holderMethodName) withCRs. |
|
6050 | 2046 |
self compile:source forClass:nonMetaClass inCategory:('accessing'). |
5763 | 2047 |
] ifTrue:[ |
2048 |
Transcript showCR:'method ''', methodName , ':'' already present' |
|
2049 |
]. |
|
2050 |
]. |
|
6050 | 2051 |
(metaClass includesSelector:(holderMethodName asSymbol)) ifFalse:[ |
5763 | 2052 |
source := '%1\'. |
2053 |
generateComments ifTrue:[ |
|
2054 |
source := source , ' "return/create the valueHolder ''%1''"\\'. |
|
2055 |
]. |
|
2056 |
source := source , ' %1 isNil ifTrue:[\'. |
|
2057 |
source := source , ' %1 := ValueHolder with:nil "defaultValue here".\'. |
|
2058 |
source := source , ' ].\'. |
|
2059 |
source := source , ' ^ %1\'. |
|
2060 |
source := (source bindWith:holderMethodName) withCRs. |
|
6050 | 2061 |
self compile:source forClass:nonMetaClass inCategory:('accessing'). |
5763 | 2062 |
] ifTrue:[ |
2063 |
Transcript showCR:'method ''', methodName , ''' already present' |
|
2064 |
]. |
|
2065 |
]. |
|
2066 |
||
2067 |
self executeCollectedChangesNamed:('Add ValueHolder'). |
|
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
2068 |
! ! |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
2069 |
|
5758 | 2070 |
!CodeGeneratorTool methodsFor:'code generation-individual methods'! |
3712 | 2071 |
|
2072 |
createAcceptVisitorMethod:selector in:aClass |
|
2073 |
"create an acceptVisitor: method |
|
2074 |
(I'm tired of typing)" |
|
2075 |
||
6921 | 2076 |
self assert:( aClass isMeta not ). |
3712 | 2077 |
|
2078 |
(aClass includesSelector:#'acceptVisitor:') ifFalse:[ |
|
2079 |
self |
|
2080 |
compile: |
|
2081 |
(('acceptVisitor:aVisitor |
|
2082 |
"Double dispatch back to the visitor, passing my type encoded in |
|
2083 |
the selector (visitor pattern)" |
|
2084 |
||
2085 |
"stub code automatically generated - please change if required" |
|
2086 |
||
2087 |
^ aVisitor %1self |
|
2088 |
') bindWith:selector) |
|
2089 |
forClass:aClass |
|
2090 |
inCategory:'visiting'. |
|
2091 |
] |
|
2092 |
! |
|
2093 |
||
2094 |
createAcceptVisitorMethodIn:aClass |
|
2095 |
"create an acceptVisitor: method |
|
2096 |
(I'm tired of typing)" |
|
2097 |
||
2098 |
self |
|
2099 |
createAcceptVisitorMethod:('visit' , aClass nameWithoutPrefix , ':') asSymbol |
|
2100 |
in:aClass |
|
2101 |
! |
|
2102 |
||
2103 |
createCopyrightMethodFor:aClass |
|
2104 |
"add copyright method containing your/your companies |
|
2105 |
copyright template but only if not already present. |
|
2106 |
this is only added, if specified in the |
|
2107 |
COPYRIGHT_TEMPLATE_FILE resources." |
|
2108 |
||
8258 | 2109 |
|fn copyRightText| |
3712 | 2110 |
|
2111 |
(aClass includesSelector:#copyright) ifFalse:[ |
|
2112 |
fn := SystemBrowser classResources at:#'COPYRIGHT_TEMPLATE_FILE' default:nil. |
|
2113 |
fn notNil ifTrue:[ |
|
2114 |
fn := fn asFilename. |
|
2115 |
fn exists ifTrue:[ |
|
8488 | 2116 |
copyRightText := fn contentsAsString. |
8258 | 2117 |
self createCopyrightMethodFor:copyRightText for:aClass |
3712 | 2118 |
] |
2119 |
]. |
|
8258 | 2120 |
]. |
2121 |
! |
|
2122 |
||
2123 |
createCopyrightMethodFor:copyRightText for:aClass |
|
2124 |
"add copyright method containing text, |
|
2125 |
but only if not already present." |
|
2126 |
||
2127 |
|txt| |
|
2128 |
||
2129 |
(aClass includesSelector:#copyright) ifFalse:[ |
|
2130 |
copyRightText notNil ifTrue:[ |
|
2131 |
txt := copyRightText bindWith:(Date today year). |
|
3712 | 2132 |
self compile: |
2133 |
'copyright |
|
2134 |
" |
|
2135 |
' , txt , ' |
|
2136 |
" |
|
2137 |
' forClass:aClass |
|
2138 |
inCategory:'documentation'. |
|
2139 |
] |
|
2140 |
]. |
|
2141 |
! |
|
2142 |
||
2143 |
createDocumentationMethodFor:aClass |
|
2144 |
"add documentation method containing doc template |
|
2145 |
but only if not already present." |
|
2146 |
||
6050 | 2147 |
|metaClass nonMetaClass userName loginName hostName emailAddress code existingComment| |
2148 |
||
2149 |
metaClass := aClass theMetaclass. |
|
2150 |
nonMetaClass := aClass theNonMetaclass. |
|
3712 | 2151 |
|
6050 | 2152 |
(metaClass includesSelector:#documentation) ifFalse:[ |
2153 |
existingComment := nonMetaClass comment. |
|
2154 |
existingComment isEmptyOrNil ifTrue:[ |
|
2155 |
(nonMetaClass isSubclassOf:HTTPService) ifTrue:[ |
|
6159 | 2156 |
existingComment := ' [start Server with:] |
7545
df2fc5dbee78
changed #createDocumentationMethodFor:
Claus Gittinger <cg@exept.de>
parents:
7480
diff
changeset
|
2157 |
HTTPServer startServerOnPort:8080 |
6159 | 2158 |
|
2159 |
[start with:] |
|
6050 | 2160 |
(self new) |
7545
df2fc5dbee78
changed #createDocumentationMethodFor:
Claus Gittinger <cg@exept.de>
parents:
7480
diff
changeset
|
2161 |
registerServiceOn:(HTTPServer runningServerOnPort:8080)'. |
6050 | 2162 |
]. |
2163 |
]. |
|
2164 |
||
3712 | 2165 |
userName := OperatingSystem getFullUserName. |
2166 |
loginName := OperatingSystem getLoginName. |
|
2167 |
hostName := OperatingSystem getHostName. |
|
2168 |
emailAddress := loginName , '@' , hostName. |
|
2169 |
||
5756 | 2170 |
"/ ugly; should ask the class for that |
6350 | 2171 |
metaClass isJavaScriptMetaclass ifTrue:[ |
5756 | 2172 |
code := |
2173 |
'function documentation() { |
|
2174 |
/* |
|
6050 | 2175 |
' , (existingComment ? ' documentation to be added.') , ' |
5756 | 2176 |
|
2177 |
[author:] |
|
2178 |
' , userName |
|
2179 |
, ' (' , emailAddress , ')' , ' |
|
2180 |
||
2181 |
[instance variables:] |
|
2182 |
||
2183 |
[class variables:] |
|
2184 |
||
2185 |
[see also:] |
|
2186 |
||
2187 |
*/ |
|
2188 |
} |
|
2189 |
' |
|
2190 |
] ifFalse:[ |
|
2191 |
code:= |
|
3712 | 2192 |
'documentation |
2193 |
" |
|
6050 | 2194 |
' , (existingComment ? ' documentation to be added.') , ' |
3712 | 2195 |
|
2196 |
[author:] |
|
2197 |
' , userName |
|
2198 |
, ' (' , emailAddress , ')' , ' |
|
2199 |
||
2200 |
[instance variables:] |
|
2201 |
||
2202 |
[class variables:] |
|
2203 |
||
2204 |
[see also:] |
|
2205 |
||
2206 |
" |
|
5756 | 2207 |
' |
2208 |
]. |
|
2209 |
||
2210 |
self |
|
2211 |
compile:code |
|
6050 | 2212 |
forClass:metaClass |
5756 | 2213 |
inCategory:'documentation'. |
3712 | 2214 |
]. |
7545
df2fc5dbee78
changed #createDocumentationMethodFor:
Claus Gittinger <cg@exept.de>
parents:
7480
diff
changeset
|
2215 |
|
df2fc5dbee78
changed #createDocumentationMethodFor:
Claus Gittinger <cg@exept.de>
parents:
7480
diff
changeset
|
2216 |
"Modified: / 24-11-2006 / 15:54:27 / cg" |
3712 | 2217 |
! |
2218 |
||
2219 |
createExamplesMethodFor:aClass |
|
2220 |
"add examples method containing examples template |
|
2221 |
but only if not already present." |
|
2222 |
||
6050 | 2223 |
|nonMetaclass fragment| |
2224 |
||
2225 |
nonMetaclass := aClass theNonMetaclass. |
|
8572 | 2226 |
|
2227 |
(nonMetaclass isSubclassOf:View) ifTrue:[ |
|
2228 |
self createExamplesMethodForViewClass:aClass. |
|
2229 |
^ self |
|
2230 |
]. |
|
2231 |
||
6050 | 2232 |
(nonMetaclass isSubclassOf:ApplicationModel) ifFalse:[ |
2233 |
^ self |
|
2234 |
]. |
|
3712 | 2235 |
|
2236 |
(aClass includesSelector:#examples) ifFalse:[ |
|
6050 | 2237 |
(nonMetaclass isSubclassOf:ApplicationModel) ifTrue:[ |
3712 | 2238 |
fragment := ' Starting the application: |
2239 |
[exBegin] |
|
6050 | 2240 |
' , nonMetaclass name , ' open |
3712 | 2241 |
|
2242 |
[exEnd] |
|
2243 |
' |
|
2244 |
] ifFalse:[ |
|
2245 |
fragment := '' |
|
2246 |
]. |
|
2247 |
||
2248 |
self |
|
2249 |
compile: |
|
2250 |
'examples |
|
2251 |
" |
|
2252 |
' , fragment , ' |
|
2253 |
more examples to be added: |
|
2254 |
[exBegin] |
|
2255 |
... add code fragment for |
|
2256 |
... executable example here ... |
|
2257 |
[exEnd] |
|
2258 |
" |
|
2259 |
' |
|
2260 |
forClass:aClass |
|
2261 |
inCategory:'documentation'. |
|
2262 |
]. |
|
2263 |
! |
|
2264 |
||
3822
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2265 |
createImageSpecMethodFor:anImage comment:comment in:aClass selector:sel |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2266 |
|imageStoreStream mthd imageKey category| |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2267 |
|
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2268 |
anImage storeOn: (imageStoreStream := WriteStream on: ''). |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2269 |
|
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2270 |
"/ if that method already exists, do not overwrite the category |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2271 |
category := 'image specs'. |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2272 |
(mthd := aClass compiledMethodAt:sel) notNil ifTrue:[ |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2273 |
category := mthd category. |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2274 |
]. |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2275 |
|
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2276 |
imageKey := (aClass name, ' ', sel) asSymbol. |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2277 |
Icon constantNamed: imageKey put:nil. |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2278 |
aClass |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2279 |
compile: ((sel, |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2280 |
'\', comment, |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2281 |
'\\' , |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2282 |
' "\', |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2283 |
' self ' , sel , ' inspect\', |
3823 | 2284 |
' ImageEditor openOnClass:self andSelector:#', sel, '\', |
3822
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2285 |
' Icon flushCachedIcons', |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2286 |
'\ "', |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2287 |
'\\', |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2288 |
' <resource: #image>', |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2289 |
'\\', |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2290 |
' ^Icon\') withCRs, |
7967
2560906ca552
use string-key in constantNamed:-icon caching
Claus Gittinger <cg@exept.de>
parents:
7615
diff
changeset
|
2291 |
' constantNamed:''', imageKey, '''\' withCRs, |
3822
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2292 |
' ifAbsentPut:[', imageStoreStream contents, ']') |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2293 |
classified: category. |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2294 |
! |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2295 |
|
3712 | 2296 |
createInitialHistoryMethodFor:aClass |
2297 |
"add history method containing created-entry |
|
2298 |
but only if not already present." |
|
2299 |
||
5758 | 2300 |
|code| |
2301 |
||
3712 | 2302 |
(aClass includesSelector:#history) ifFalse:[ |
2303 |
HistoryManager notNil ifTrue:[ |
|
5758 | 2304 |
code := HistoryManager codeForInitialHistoryMethodIn:aClass. |
2305 |
self |
|
2306 |
compile:code |
|
2307 |
forClass:aClass |
|
2308 |
inCategory:'documentation'. |
|
3712 | 2309 |
]. |
2310 |
]. |
|
2311 |
! |
|
2312 |
||
4512 | 2313 |
createInstanceCreationMethodWithSetupFor:selector category:category in:aMetaClass |
2314 |
"add an inst-creation method" |
|
2315 |
||
2316 |
|template| |
|
2317 |
||
2318 |
(aMetaClass includesSelector:selector) ifFalse:[ |
|
2319 |
template := Parser methodSpecificationForSelector:selector. |
|
2320 |
self |
|
2321 |
compile: |
|
2322 |
template , ' |
|
2323 |
^ self new ' , template , ' |
|
2324 |
' |
|
2325 |
forClass:aMetaClass |
|
2326 |
inCategory:category. |
|
2327 |
]. |
|
2328 |
! |
|
2329 |
||
3712 | 2330 |
createMultiSetterMethodFor:aCollectionOfVarNames in:aClass |
2331 |
"create a multi-setter method for instvars." |
|
2332 |
||
2333 |
|source| |
|
2334 |
||
2335 |
source := ''. |
|
2336 |
aCollectionOfVarNames do:[:eachVar | |
|
2337 |
source := source , (eachVar , ':' , eachVar , 'Arg '). |
|
2338 |
]. |
|
2339 |
source := source , Character cr. |
|
8572 | 2340 |
(userPreferences generateCommentsForSetters) ifTrue:[ |
6993 | 2341 |
source := source , (' "set instance variables"' , Character cr , Character cr). |
6992 | 2342 |
]. |
3712 | 2343 |
aCollectionOfVarNames do:[:eachVar | |
2344 |
source := source , (' ' , eachVar , ' := ' , eachVar , 'Arg.' , Character cr). |
|
2345 |
]. |
|
2346 |
self compile:source forClass:aClass inCategory:'accessing'. |
|
2347 |
! |
|
2348 |
||
3800
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2349 |
createSubclassResponsibilityMethodFor:aSelector category:cat in:aClass |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2350 |
"add a subclassResponsibility method; |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2351 |
but only if not already present." |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2352 |
|
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2353 |
(aClass includesSelector:aSelector) ifFalse:[ |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2354 |
|
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2355 |
self compile: |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2356 |
(Method methodDefinitionTemplateForSelector:aSelector) , |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2357 |
' |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2358 |
"raise an error: must be redefined in concrete subclass(es)" |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2359 |
|
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2360 |
^ self subclassResponsibility |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2361 |
' |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2362 |
forClass:aClass |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2363 |
inCategory:cat. |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2364 |
]. |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2365 |
! |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2366 |
|
3712 | 2367 |
createUpdateMethodIn:aClass |
2368 |
"create an update:with:from:-method |
|
2369 |
(I'm tired of typing)" |
|
2370 |
||
8572 | 2371 |
|code| |
2372 |
||
3712 | 2373 |
(aClass includesSelector:#'update:with:from:') ifFalse:[ |
8572 | 2374 |
generateComments ifFalse:[ |
2375 |
code := |
|
2376 |
'update:something with:aParameter from:changedObject |
|
2377 |
super update:something with:aParameter from:changedObject |
|
2378 |
' |
|
2379 |
] ifTrue:[ |
|
2380 |
code := |
|
3712 | 2381 |
'update:something with:aParameter from:changedObject |
2382 |
"Invoked when an object that I depend upon sends a change notification." |
|
2383 |
||
2384 |
"stub code automatically generated - please change as required" |
|
2385 |
||
2386 |
"/ changedObject == someOfMyValueHolders ifTrue:[ |
|
4926 | 2387 |
"/ self doSomethingApropriate. |
2388 |
"/ ^ self. |
|
3712 | 2389 |
"/ ]. |
2390 |
super update:something with:aParameter from:changedObject |
|
2391 |
' |
|
8572 | 2392 |
]. |
2393 |
||
2394 |
self |
|
2395 |
compile:code |
|
3712 | 2396 |
forClass:aClass |
2397 |
inCategory:'change & update'. |
|
2398 |
] |
|
2399 |
! |
|
2400 |
||
2401 |
createVersionMethodFor:aClass |
|
8890 | 2402 |
<resource: #obsolete> |
3712 | 2403 |
"add version method containing RCS template |
2404 |
but only if not already present and its not a private class." |
|
2405 |
||
5756 | 2406 |
|code| |
2407 |
||
8890 | 2408 |
self obsoleteMethodWarning. |
2409 |
||
3712 | 2410 |
aClass isPrivate ifFalse:[ |
2411 |
(aClass includesSelector:#version) ifFalse:[ |
|
5756 | 2412 |
"/ ugly; should ask the class for that |
2413 |
aClass isJavaScriptClass ifTrue:[ |
|
2414 |
code:= ('function version() {\ return ("$' , 'Header$");\}') withCRs |
|
2415 |
] ifFalse:[ |
|
2416 |
code:= ('version\ ^ ''$' , 'Header$''') withCRs |
|
2417 |
]. |
|
2418 |
self |
|
2419 |
compile:code |
|
2420 |
forClass:aClass |
|
2421 |
inCategory:'documentation'. |
|
3712 | 2422 |
] |
2423 |
]. |
|
2424 |
! ! |
|
2425 |
||
7480
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2426 |
!CodeGeneratorTool methodsFor:'code templates'! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2427 |
|
8987 | 2428 |
codeFor_classInitialize |
2429 |
generateComments ifFalse:[ |
|
2430 |
^ |
|
2431 |
'initialize |
|
2432 |
%(INIT_CLASSINSTVARS) |
|
2433 |
%(INIT_CLASSVARS) |
|
2434 |
'. |
|
2435 |
]. |
|
2436 |
||
2437 |
^ |
|
2438 |
'initialize |
|
2439 |
"Invoked at system start or when the class is dynamically loaded." |
|
2440 |
||
2441 |
"/ please change as required (and remove this comment) |
|
2442 |
%(INIT_CLASSINSTVARS) |
|
2443 |
%(INIT_CLASSVARS) |
|
2444 |
'. |
|
2445 |
! |
|
2446 |
||
7480
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2447 |
codeFor_closeAccept |
8572 | 2448 |
generateComments ifFalse:[ |
2449 |
^ |
|
2450 |
'closeAccept |
|
2451 |
^ super closeAccept |
|
2452 |
'. |
|
2453 |
]. |
|
2454 |
||
7480
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2455 |
^ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2456 |
'closeAccept |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2457 |
"This is a hook method generated by the Browser. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2458 |
It will be invoked when your dialog-window is closed with OK." |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2459 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2460 |
"/ add any actions as required here ... |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2461 |
Transcript showCR:''dialog accepted''. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2462 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2463 |
"/ do not remove the one below (otherwise, the dialog will not close itself)... |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2464 |
^ super closeAccept |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2465 |
'. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2466 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2467 |
"Created: / 27-10-2006 / 10:03:31 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2468 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2469 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2470 |
codeFor_closeDownViews |
8572 | 2471 |
generateComments ifFalse:[ |
2472 |
^ |
|
2473 |
'closeDownViews |
|
2474 |
^ super closeDownViews |
|
2475 |
'. |
|
2476 |
]. |
|
2477 |
||
7480
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2478 |
^ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2479 |
'closeDownViews |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2480 |
"This is a hook method generated by the Browser. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2481 |
It will be invoked when your app/dialog-window is really closed. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2482 |
See also #closeDownViews, which is invoked before and may suppress the close |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2483 |
or ask the user for confirmation." |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2484 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2485 |
"/ change the code below as required ... |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2486 |
"/ This should cleanup any leftover resources |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2487 |
"/ (for example, temporary files) |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2488 |
"/ super closeRequest will initiate the closeDown |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2489 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2490 |
"/ add your code here |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2491 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2492 |
"/ do not remove the one below ... |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2493 |
^ super closeDownViews |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2494 |
'. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2495 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2496 |
"Created: / 27-10-2006 / 10:01:32 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2497 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2498 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2499 |
codeFor_closeRequest |
8572 | 2500 |
generateComments ifFalse:[ |
2501 |
^ |
|
2502 |
'closeRequest |
|
2503 |
self hasUnsavedChanges ifTrue:[ |
|
2504 |
(self confirm:(resources string:''Close without saving ?'')) ifFalse:[ |
|
2505 |
^ self |
|
2506 |
] |
|
2507 |
]. |
|
2508 |
^ super closeRequest |
|
2509 |
'. |
|
2510 |
]. |
|
2511 |
||
7480
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2512 |
^ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2513 |
'closeRequest |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2514 |
"This is a hook method generated by the Browser. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2515 |
It will be invoked when your app/dialog-window is about to be |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2516 |
closed (this method has a chance to suppress the close). |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2517 |
See also #closeDownViews, which is invoked when the close is really done." |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2518 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2519 |
"/ change the code below as required ... |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2520 |
"/ Closing can be suppressed, by simply returning. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2521 |
"/ The ''super closeRequest'' at the end will initiate the real closeDown |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2522 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2523 |
self hasUnsavedChanges ifTrue:[ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2524 |
(self confirm:(resources string:''Close without saving ?'')) ifFalse:[ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2525 |
^ self |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2526 |
] |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2527 |
]. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2528 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2529 |
^ super closeRequest |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2530 |
'. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2531 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2532 |
"Created: / 27-10-2006 / 10:01:06 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2533 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2534 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2535 |
codeFor_doSaveAs |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2536 |
^ self codeFor_emptyMenuActionCodeFor:#doSaveAs menuItem:'save/saveAs' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2537 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2538 |
"Created: / 27-10-2006 / 10:22:06 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2539 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2540 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2541 |
codeFor_emptyMenuActionCodeFor:selector menuItem:item |
8572 | 2542 |
generateComments ifFalse:[ |
2543 |
^ |
|
2544 |
selector,' |
|
2545 |
self warn:''no action for ''''',item,''''' defined.''. |
|
2546 |
'. |
|
2547 |
]. |
|
2548 |
||
7480
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2549 |
^ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2550 |
selector,' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2551 |
"This method was generated by the Browser. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2552 |
It will be invoked when the menu-item ''',item,''' is selected." |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2553 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2554 |
"/ change below and add any actions as required here ... |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2555 |
self warn:''no action for ''''',item,''''' defined.''. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2556 |
'. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2557 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2558 |
"Created: / 27-10-2006 / 10:16:43 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2559 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2560 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2561 |
codeFor_hasUnsavedChanges |
8572 | 2562 |
generateComments ifFalse:[ |
2563 |
^ |
|
2564 |
'hasUnsavedChanges |
|
2565 |
^ false. |
|
2566 |
'. |
|
2567 |
]. |
|
2568 |
||
7480
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2569 |
^ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2570 |
'hasUnsavedChanges |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2571 |
"Return true, if any unsaved changes are present |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2572 |
(i.e. the contents needs to be saved or else will be lost)" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2573 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2574 |
"/ add real code as required (or remove the halt and always return false)... |
9053
9e09bbdb81a3
changed: #codeFor_hasUnsavedChanges
Claus Gittinger <cg@exept.de>
parents:
9049
diff
changeset
|
2575 |
"/ self halt:''check this code''. |
7480
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2576 |
^ false. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2577 |
'. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2578 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2579 |
"Created: / 27-10-2006 / 10:00:36 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2580 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2581 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2582 |
codeFor_menuNew |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2583 |
^ self codeFor_emptyMenuActionCodeFor:#menuNew menuItem:'new' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2584 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2585 |
"Created: / 27-10-2006 / 10:17:08 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2586 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2587 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2588 |
codeFor_menuOpen |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2589 |
^ self codeFor_emptyMenuActionCodeFor:#menuOpen menuItem:'open' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2590 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2591 |
"Created: / 27-10-2006 / 10:17:18 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2592 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2593 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2594 |
codeFor_menuSave |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2595 |
^ self codeFor_emptyMenuActionCodeFor:#menuSave menuItem:'save' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2596 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2597 |
"Created: / 27-10-2006 / 10:17:25 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2598 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2599 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2600 |
codeFor_menuSaveAs |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2601 |
^ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2602 |
'menuSaveAs |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2603 |
"This method was generated by the Browser. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2604 |
It will be invoked when the menu-item ''saveAs'' is selected." |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2605 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2606 |
"/ change below as required... (see examples in Dialog class for more options) |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2607 |
Dialog |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2608 |
requestSaveFileName:(resources string:''Save'') |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2609 |
default:''foo.txt'' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2610 |
fromDirectory:nil |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2611 |
action:[:fileName | self doSaveAs:fileName] |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2612 |
appendAction:nil. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2613 |
'. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2614 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2615 |
"Created: / 27-10-2006 / 10:01:57 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2616 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2617 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2618 |
codeFor_openAboutThisApplication |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2619 |
^ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2620 |
'openAboutThisApplication |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2621 |
"This method was generated by the Browser. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2622 |
It will be invoked when the menu-item ''help-about'' is selected." |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2623 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2624 |
"/ could open a customized aboutBox here ... |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2625 |
super openAboutThisApplication |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2626 |
'. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2627 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2628 |
"Created: / 27-10-2006 / 10:03:13 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2629 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2630 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2631 |
codeFor_openDocumentation |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2632 |
^ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2633 |
'openDocumentation |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2634 |
"This method was generated by the Browser. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2635 |
It will be invoked when the menu-item ''help-documentation'' is selected." |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2636 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2637 |
"/ change below as required ... |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2638 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2639 |
"/ to open an HTML viewer on some document (under ''doc/online/<language>/'' ): |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2640 |
HTMLDocumentView openFullOnDocumentationFile:''TOP.html''. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2641 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2642 |
"/ add application-specific help files under the ''doc/online/<language>/help/appName'' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2643 |
"/ directory, and open a viewer with: |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2644 |
"/ HTMLDocumentView openFullOnDocumentationFile:''help/<MyApplication>/TOP.html''. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2645 |
'. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2646 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2647 |
"Created: / 27-10-2006 / 10:02:55 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2648 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2649 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2650 |
codeFor_postBuildWith |
8572 | 2651 |
generateComments ifFalse:[ |
2652 |
^ |
|
2653 |
'postBuildWith:aBuilder |
|
2654 |
^ super postBuildWith:aBuilder |
|
2655 |
'. |
|
2656 |
]. |
|
2657 |
||
7480
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2658 |
^ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2659 |
'postBuildWith:aBuilder |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2660 |
"This is a hook method generated by the Browser. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2661 |
It will be invoked during the initialization of your app/dialog, |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2662 |
after all of the visual components have been built, |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2663 |
but BEFORE the top window is made visible. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2664 |
Add any app-specific actions here (reading files, setting up values etc.) |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2665 |
See also #postOpenWith:, which is invoked after opening." |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2666 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2667 |
"/ add any code here ... |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2668 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2669 |
^ super postBuildWith:aBuilder |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2670 |
'. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2671 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2672 |
"Created: / 27-10-2006 / 09:59:33 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2673 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2674 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2675 |
codeFor_postOpenWith |
8572 | 2676 |
generateComments ifFalse:[ |
2677 |
^ |
|
2678 |
'postOpenWith:aBuilder |
|
2679 |
^ super postOpenWith:aBuilder |
|
2680 |
'. |
|
2681 |
]. |
|
2682 |
||
7480
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2683 |
^ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2684 |
'postOpenWith:aBuilder |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2685 |
"This is a hook method generated by the Browser. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2686 |
It will be invoked right after the applications window has been opened. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2687 |
Add any app-specific actions here (starting background processes etc.). |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2688 |
See also #postBuildWith:, which is invoked before opening." |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2689 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2690 |
"/ add any code here ... |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2691 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2692 |
^ super postOpenWith:aBuilder |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2693 |
'. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2694 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2695 |
"Created: / 27-10-2006 / 09:59:56 / cg" |
8572 | 2696 |
! |
2697 |
||
2698 |
code_forWidget_buttonPress |
|
2699 |
generateComments ifFalse:[ |
|
2700 |
^ |
|
2701 |
'buttonPress:button x:x y:y |
|
8574 | 2702 |
Transcript show:''button: ''; showCR:button. |
8572 | 2703 |
super buttonPress:button x:x y:y |
2704 |
' |
|
2705 |
]. |
|
2706 |
||
2707 |
^ |
|
2708 |
'buttonPress:button x:x y:y |
|
2709 |
"called when a mouse-button is pressed. button is the button-nr (1 for left-button). |
|
2710 |
x/y are the mouse position at the time of the click. |
|
2711 |
There are also corresponding buttonRelease and buttonMotion methods which could be |
|
2712 |
redefined...." |
|
2713 |
||
8574 | 2714 |
Transcript show:''button: ''; showCR:button. |
8572 | 2715 |
"/ super-code handles middleButtonMenu, if it was assigned (with middleButtonmenu:) |
2716 |
super buttonPress:button x:x y:y |
|
2717 |
' |
|
2718 |
! |
|
2719 |
||
2720 |
code_forWidget_initialize |
|
2721 |
^ |
|
2722 |
'initialize |
|
2723 |
super initialize "/ to initialize inherited state |
|
2724 |
||
2725 |
"/ add code to initialize private variables, |
|
2726 |
"/ and sub-components as required. |
|
2727 |
' |
|
2728 |
! |
|
2729 |
||
2730 |
code_forWidget_keyPress |
|
2731 |
generateComments ifFalse:[ |
|
2732 |
^ |
|
2733 |
'keyPress:key x:x y:y |
|
2734 |
"/ key == #Copy ifTrue:[ |
|
2735 |
"/ ]. |
|
2736 |
"/ key == #Cut ifTrue:[ |
|
2737 |
"/ ]. |
|
8574 | 2738 |
Transcript show:''key: ''; showCR:key. |
8572 | 2739 |
super keyPress:key x:x y:y |
2740 |
' |
|
2741 |
]. |
|
2742 |
^ |
|
2743 |
'keyPress:key x:x y:y |
|
2744 |
"called when a keyboard-key was pressed. key is either a character (for ordinary keys) |
|
2745 |
or a symbol, such as #Copy, #Cut or #Paste. |
|
2746 |
x/y are the mouse position at the time of the key-press. |
|
2747 |
There is also a corresponding keyRelease method which could be redefined...." |
|
2748 |
||
8574 | 2749 |
Transcript show:''key: ''; showCR:key. |
8572 | 2750 |
super keyPress:key x:x y:y |
2751 |
' |
|
2752 |
! |
|
2753 |
||
2754 |
code_forWidget_redraw |
|
8573 | 2755 |
|sel comment code| |
2756 |
||
2757 |
sel := 'redrawX:x y:y width:w height:h'. |
|
8572 | 2758 |
generateComments ifFalse:[ |
8573 | 2759 |
comment := ''. |
2760 |
] ifTrue:[ |
|
2761 |
comment := ' |
|
8572 | 2762 |
"called to redraw a part of the widgets area. x/y define the origin, w/h the size of |
2763 |
that area. The clipping region has already been set by the caller, so even if the code |
|
2764 |
below draws outside the redraw-area, it will not affect what is on the screen. |
|
2765 |
Therefore, the example below can fill the rectangle in the redraw area, but still draw |
|
2766 |
the cross in the outside regions." |
|
2767 |
||
8573 | 2768 |
'. |
2769 |
]. |
|
2770 |
||
2771 |
code := ' |
|
8572 | 2772 |
self paint:Color red. |
8573 | 2773 |
self fillRectangleX:x y:y width:w height:h. |
8572 | 2774 |
|
2775 |
self paint:Color yellow. |
|
8573 | 2776 |
self displayLineFrom:0@0 to:(width@height). |
2777 |
self displayLineFrom:width@0 to:(0@height). |
|
2778 |
'. |
|
2779 |
||
2780 |
^ sel,comment,code |
|
8572 | 2781 |
! |
2782 |
||
2783 |
code_forWidget_sizeChanged |
|
2784 |
generateComments ifFalse:[ |
|
2785 |
^ |
|
2786 |
'sizeChanged:how |
|
2787 |
self invalidate. |
|
2788 |
super sizeChanged:how. |
|
2789 |
' |
|
2790 |
]. |
|
2791 |
||
2792 |
^ |
|
2793 |
'sizeChanged:how |
|
2794 |
"Invoked whenever the size of the view changes. |
|
2795 |
Here, we force a full redraw, which might not be needed all the time" |
|
2796 |
||
2797 |
self invalidate. |
|
2798 |
super sizeChanged:how. |
|
2799 |
' |
|
2800 |
! |
|
2801 |
||
2802 |
code_forWidget_update |
|
2803 |
generateComments ifFalse:[ |
|
2804 |
^ |
|
2805 |
'update:something with:aParameter from:changedObject |
|
2806 |
changedObject == model ifTrue:[ |
|
2807 |
self invalidate. |
|
2808 |
^ self |
|
2809 |
]. |
|
2810 |
super update:something with:aParameter from:changedObject |
|
2811 |
' |
|
2812 |
]. |
|
2813 |
||
2814 |
^ |
|
2815 |
'update:something with:aParameter from:changedObject |
|
2816 |
"Invoked when an object that I depend upon sends a change notification." |
|
2817 |
||
2818 |
"stub code automatically generated - please change as required" |
|
2819 |
||
2820 |
changedObject == model ifTrue:[ |
|
2821 |
self invalidate. |
|
2822 |
^ self |
|
2823 |
]. |
|
2824 |
super update:something with:aParameter from:changedObject |
|
2825 |
' |
|
7480
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2826 |
! ! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2827 |
|
6938 | 2828 |
!CodeGeneratorTool methodsFor:'compilation'! |
2829 |
||
2830 |
compile:theCode forClass:aClass inCategory:cat |
|
2831 |
"install some code for a class. |
|
2832 |
If refactory browser stuff is avaliable the refactory tools are used to support undo" |
|
2833 |
||
7037 | 2834 |
self |
2835 |
compile:theCode forClass:aClass inCategory:cat |
|
2836 |
skipIfSame:true |
|
2837 |
! |
|
6938 | 2838 |
|
7037 | 2839 |
compile:theCode forClass:aClass inCategory:cat skipIfSame:skipIfSame |
2840 |
"install some code for a class. |
|
2841 |
If refactory browser stuff is avaliable the refactory tools are used to support undo" |
|
2842 |
||
2843 |
|change compiler selector oldMthd isSame| |
|
6938 | 2844 |
|
7037 | 2845 |
isSame := false. |
2846 |
skipIfSame ifTrue:[ |
|
2847 |
compiler := aClass compilerClass new. |
|
2848 |
compiler parseMethod:theCode in:aClass ignoreErrors:true ignoreWarnings:true. |
|
2849 |
||
2850 |
selector := compiler selector. |
|
2851 |
selector notNil ifTrue:[ |
|
2852 |
oldMthd := aClass compiledMethodAt:selector. |
|
2853 |
isSame := (oldMthd notNil and:[oldMthd source = theCode]). |
|
2854 |
isSame ifTrue:[ ^ self ]. |
|
6938 | 2855 |
]. |
2856 |
]. |
|
2857 |
||
2858 |
self canUseRefactoringSupport ifFalse:[ |
|
2859 |
"/ compile immediately |
|
2860 |
aClass compile:theCode classified:cat. |
|
2861 |
^ self. |
|
2862 |
]. |
|
2863 |
||
2864 |
change := InteractiveAddMethodChange compile:(theCode asString) in:aClass classified:cat. |
|
2865 |
||
2866 |
"/ if collecting, add to changes (to be executed as one change at the end, |
|
2867 |
"/ in order to have only one change in the undo-list (instead of many) |
|
2868 |
compositeChangeCollector notNil ifTrue:[ |
|
2869 |
compositeChangeCollector addChange:change |
|
2870 |
] ifFalse:[ |
|
7037 | 2871 |
RefactoryChangeManager performChange:change. |
6938 | 2872 |
] |
2873 |
||
2874 |
"Modified: / 21-08-2006 / 18:39:06 / cg" |
|
2875 |
! ! |
|
3712 | 2876 |
|
8572 | 2877 |
!CodeGeneratorTool methodsFor:'initialization'! |
2878 |
||
2879 |
initialize |
|
2880 |
userPreferences := UserPreferences current. |
|
2881 |
generateComments := userPreferences generateComments. |
|
2882 |
! ! |
|
2883 |
||
5758 | 2884 |
!CodeGeneratorTool methodsFor:'private'! |
4108
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2885 |
|
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
2886 |
canUseRefactoringSupport |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
2887 |
"check if refactory browser stuff is avaliable" |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
2888 |
|
5758 | 2889 |
^ self class canUseRefactoringSupport |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
2890 |
! |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
2891 |
|
9027
f2edc1bca4de
added: #codeFor_shouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9025
diff
changeset
|
2892 |
codeFor_shouldImplementFor:selector inClass:aClass |
9044
5da7b7815f56
comment/format in: #codeFor_shouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9028
diff
changeset
|
2893 |
"used in the 'generate required protocol' to generate a shouldImplement-sending |
5da7b7815f56
comment/format in: #codeFor_shouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9028
diff
changeset
|
2894 |
method for each subclassClassresponsibility method above aClass." |
5da7b7815f56
comment/format in: #codeFor_shouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9028
diff
changeset
|
2895 |
|
9025
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2896 |
|mthd comment implClass methodBodyStream searcher errorMessageString| |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2897 |
|
9028
56eb45cb11f3
changed: #codeFor_shouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9027
diff
changeset
|
2898 |
(aClass notNil |
56eb45cb11f3
changed: #codeFor_shouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9027
diff
changeset
|
2899 |
and:[ aClass superclass notNil ]) ifTrue:[ |
56eb45cb11f3
changed: #codeFor_shouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9027
diff
changeset
|
2900 |
implClass := aClass superclass whichClassImplements:selector. |
56eb45cb11f3
changed: #codeFor_shouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9027
diff
changeset
|
2901 |
]. |
9025
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2902 |
implClass isNil ifTrue:[ |
9028
56eb45cb11f3
changed: #codeFor_shouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9027
diff
changeset
|
2903 |
^ ((Method methodDefinitionTemplateForSelector:selector),'\ ^ self shouldImplement\') withCRs |
9025
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2904 |
]. |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2905 |
|
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2906 |
mthd := implClass compiledMethodAt:selector. |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2907 |
|
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2908 |
methodBodyStream := '' writeStream. |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2909 |
methodBodyStream |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2910 |
nextPutAll:mthd methodDefinitionTemplate; cr; |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2911 |
nextPutAll:' "'. |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2912 |
|
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2913 |
"/ include the comment of the subclassResponsibility-sending method |
9044
5da7b7815f56
comment/format in: #codeFor_shouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9028
diff
changeset
|
2914 |
|
9025
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2915 |
comment := mthd methodComment. |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2916 |
comment isEmptyOrNil ifTrue:[ |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2917 |
methodBodyStream |
9028
56eb45cb11f3
changed: #codeFor_shouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9027
diff
changeset
|
2918 |
nextPutAll:('superclass <1s> says that I am responsible to implement this method' |
9025
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2919 |
expandMacrosWith:implClass name) |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2920 |
] ifFalse:[ |
9044
5da7b7815f56
comment/format in: #codeFor_shouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9028
diff
changeset
|
2921 |
comment |
5da7b7815f56
comment/format in: #codeFor_shouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9028
diff
changeset
|
2922 |
asStringCollection do:[:eachLine| |
5da7b7815f56
comment/format in: #codeFor_shouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9028
diff
changeset
|
2923 |
methodBodyStream nextPutAll:eachLine. |
5da7b7815f56
comment/format in: #codeFor_shouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9028
diff
changeset
|
2924 |
] separatedBy:[ |
5da7b7815f56
comment/format in: #codeFor_shouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9028
diff
changeset
|
2925 |
methodBodyStream cr; nextPutAll:' '. |
5da7b7815f56
comment/format in: #codeFor_shouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9028
diff
changeset
|
2926 |
]. |
9025
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2927 |
]. |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2928 |
methodBodyStream |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2929 |
nextPut:$"; cr; cr. |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2930 |
|
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2931 |
"/ include the argument of the subclassResponsibility:-sending method |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2932 |
self canUseRefactoringSupport ifTrue:[ |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2933 |
(mthd sends:#subclassResponsibility:) ifTrue:[ |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2934 |
searcher := ParseTreeSearcher new. |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2935 |
searcher |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2936 |
matches: 'self subclassResponsibility: `''.*''' |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2937 |
do:[:node :answer | |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2938 |
errorMessageString := node arguments first value. |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2939 |
true. |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2940 |
]. |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2941 |
searcher executeTree: (mthd parseTree) initialAnswer: false. |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2942 |
]. |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2943 |
]. |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2944 |
errorMessageString notEmptyOrNil ifTrue:[ |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2945 |
methodBodyStream |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2946 |
nextPutAll:' ^ self shouldImplement:'; |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2947 |
nextPutLine:(errorMessageString storeString) |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2948 |
] ifFalse:[ |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2949 |
methodBodyStream |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2950 |
nextPutLine:' ^ self shouldImplement'. |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2951 |
]. |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2952 |
|
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2953 |
^ methodBodyStream contents |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2954 |
! |
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2955 |
|
4108
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2956 |
privCreateClassResponsibleProtocolFor:aClass |
6791
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2957 |
"create stubs for the required protocol. |
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2958 |
aClass may be a a MetaClass or a non-MetaClass" |
4108
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2959 |
|
9022
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
2960 |
|requiredProtocol| |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
2961 |
|
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
2962 |
requiredProtocol := self class missingRequiredProtocolFor:aClass. |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
2963 |
requiredProtocol do:[:eachSelector | |
9025
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2964 |
|code implClass| |
9022
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
2965 |
|
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
2966 |
implClass := aClass whichClassImplements:eachSelector. |
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
2967 |
implClass == Object ifFalse:[ |
9027
f2edc1bca4de
added: #codeFor_shouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9025
diff
changeset
|
2968 |
code := self codeFor_shouldImplementFor:eachSelector inClass:aClass. |
9022
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
2969 |
|
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
2970 |
self |
9025
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2971 |
compile:code |
9022
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
2972 |
forClass:aClass |
9025
124489bab860
added: #codeForShouldImplementFor:inClass:
Claus Gittinger <cg@exept.de>
parents:
9022
diff
changeset
|
2973 |
inCategory:(implClass compiledMethodAt:eachSelector) category. |
9022
676088a17690
added: #missingRequiredProtocolFor:
Claus Gittinger <cg@exept.de>
parents:
8987
diff
changeset
|
2974 |
] |
4108
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2975 |
]. |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2976 |
! ! |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2977 |
|
3712 | 2978 |
!CodeGeneratorTool class methodsFor:'documentation'! |
2979 |
||
2980 |
version |
|
9081 | 2981 |
^ '$Header: /cvs/stx/stx/libtool/CodeGeneratorTool.st,v 1.73 2009-10-26 12:54:28 fm Exp $' |
8890 | 2982 |
! |
2983 |
||
2984 |
version_CVS |
|
9081 | 2985 |
^ '$Header: /cvs/stx/stx/libtool/CodeGeneratorTool.st,v 1.73 2009-10-26 12:54:28 fm Exp $' |
3712 | 2986 |
! ! |