493
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2011 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 |
"
|
|
12 |
"{ Package: 'stx:libjavascript' }"
|
|
13 |
|
|
14 |
CodeGeneratorTool subclass:#JavaScriptCodeGeneratorTool
|
|
15 |
instanceVariableNames:''
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Interface-Browsers'
|
|
19 |
!
|
|
20 |
|
|
21 |
!JavaScriptCodeGeneratorTool class methodsFor:'documentation'!
|
|
22 |
|
|
23 |
copyright
|
|
24 |
"
|
|
25 |
COPYRIGHT (c) 2011 by eXept Software AG
|
|
26 |
All Rights Reserved
|
|
27 |
|
|
28 |
This software is furnished under a license and may be used
|
|
29 |
only in accordance with the terms of that license and with the
|
|
30 |
inclusion of the above copyright notice. This software may not
|
|
31 |
be provided or otherwise made available to, or used by, any
|
|
32 |
other person. No title to or ownership of the software is
|
|
33 |
hereby transferred.
|
|
34 |
"
|
|
35 |
!
|
|
36 |
|
|
37 |
documentation
|
|
38 |
"
|
|
39 |
Code generation facilites for JavaScript
|
|
40 |
|
|
41 |
[author:]
|
|
42 |
Claus Gittiner
|
|
43 |
"
|
|
44 |
! !
|
|
45 |
|
544
|
46 |
!JavaScriptCodeGeneratorTool class methodsFor:'code generation'!
|
|
47 |
|
|
48 |
initialMenuSpecMethodSourceForApplications
|
|
49 |
"return code for a menuSpec with typical stuff in it"
|
|
50 |
|
|
51 |
^
|
|
52 |
'mainMenu
|
|
53 |
"This resource specification was automatically generated by the CodeGeneratorTool."
|
|
54 |
|
|
55 |
"Do not manually edit this!! If it is corrupted,
|
|
56 |
the MenuEditor may not be able to read the specification."
|
|
57 |
|
|
58 |
"
|
|
59 |
MenuEditor new openOnClass:%1 andSelector:#mainMenu
|
|
60 |
"
|
|
61 |
|
|
62 |
<resource: #menu>
|
|
63 |
|
|
64 |
^ ',(self initialMenuSpecForApplications decodeAsLiteralArray literalArrayEncoding storeString),'
|
|
65 |
'.
|
|
66 |
!
|
|
67 |
|
|
68 |
initialPageMenuSpecMethodSourceForWebApplications
|
|
69 |
"return code for a menuSpec with typical stuff in it"
|
|
70 |
|
|
71 |
^
|
|
72 |
'mainMenu
|
|
73 |
"This resource specification was automatically generated by the CodeGeneratorTool."
|
|
74 |
|
|
75 |
"Do not manually edit this!! If it is corrupted,
|
|
76 |
the MenuEditor may not be able to read the specification."
|
|
77 |
|
|
78 |
"
|
|
79 |
MenuEditor new openOnClass:%1 andSelector:#mainMenu
|
|
80 |
"
|
|
81 |
|
|
82 |
<resource: #menu>
|
|
83 |
|
|
84 |
^ ',(self initialPageMenuSpecForWebApplications decodeAsLiteralArray literalArrayEncoding storeString),'
|
|
85 |
'.
|
|
86 |
|
|
87 |
"
|
|
88 |
self initialPageMenuSpecMethodSourceForWebApplications
|
|
89 |
"
|
|
90 |
!
|
|
91 |
|
|
92 |
initialPageSpecMethodSourceForWebApplications
|
|
93 |
"return an empty pageSpec"
|
|
94 |
|
|
95 |
^
|
|
96 |
'pageSpec
|
|
97 |
"This resource specification was automatically generated by the CodeGeneratorTool."
|
|
98 |
|
|
99 |
"Do not manually edit this!! If it is corrupted,
|
|
100 |
the UIPainter may not be able to read the specification."
|
|
101 |
|
|
102 |
"
|
|
103 |
UIPainter new openOnClass:%1 andSelector:#pageSpec
|
|
104 |
"
|
|
105 |
|
|
106 |
<resource: #canvas>
|
|
107 |
|
|
108 |
^ ',(self initialPageSpecForWebApplications decodeAsLiteralArray literalArrayEncoding storeString),'
|
|
109 |
'.
|
|
110 |
!
|
|
111 |
|
|
112 |
initialToolbarMenuSpecMethodSource
|
|
113 |
"return a menuSpec with typical stuff in it"
|
|
114 |
|
|
115 |
^
|
|
116 |
'toolbarMenu
|
|
117 |
"This resource specification was automatically generated by the CodeGeneratorTool."
|
|
118 |
|
|
119 |
"Do not manually edit this!! If it is corrupted,
|
|
120 |
the MenuEditor may not be able to read the specification."
|
|
121 |
|
|
122 |
"
|
|
123 |
MenuEditor new openOnClass:%1 andSelector:#toolbarMenu
|
|
124 |
"
|
|
125 |
|
|
126 |
<resource: #menu>
|
|
127 |
|
|
128 |
^ ',(self initialToolbarMenuSpec decodeAsLiteralArray literalArrayEncoding storeString),'
|
|
129 |
'.
|
|
130 |
|
|
131 |
"
|
|
132 |
self initialToolbarMenuSpecMethodSource
|
|
133 |
"
|
|
134 |
!
|
|
135 |
|
|
136 |
initialWindowSpecMethodSourceForApplications
|
|
137 |
"return an empty windowSpec with an initial menubar in it"
|
|
138 |
|
|
139 |
^
|
|
140 |
'windowSpec
|
|
141 |
"This resource specification was automatically generated by the CodeGeneratorTool."
|
|
142 |
|
|
143 |
"Do not manually edit this!! If it is corrupted,
|
|
144 |
the UIPainter may not be able to read the specification."
|
|
145 |
|
|
146 |
"
|
|
147 |
UIPainter new openOnClass:%1 andSelector:#windowSpec
|
|
148 |
"
|
|
149 |
|
|
150 |
<resource: #canvas>
|
|
151 |
|
|
152 |
^ ',
|
|
153 |
self initialWindowSpecForApplications2 decodeAsLiteralArray prettyPrintString
|
|
154 |
.
|
|
155 |
|
|
156 |
"
|
|
157 |
self initialWindowSpecMethodSourceForApplications
|
|
158 |
"
|
|
159 |
!
|
|
160 |
|
|
161 |
initialWindowSpecMethodSourceForDialogs
|
|
162 |
"return an empty windowSpec for dialogs"
|
|
163 |
|
|
164 |
^
|
|
165 |
'windowSpec
|
|
166 |
"This resource specification was automatically generated by the CodeGeneratorTool."
|
|
167 |
|
|
168 |
"Do not manually edit this!! If it is corrupted,
|
|
169 |
the UIPainter may not be able to read the specification."
|
|
170 |
|
|
171 |
"
|
|
172 |
UIPainter new openOnClass:%1 andSelector:#windowSpec
|
|
173 |
"
|
|
174 |
|
|
175 |
<resource: #canvas>
|
|
176 |
|
|
177 |
^ ',
|
|
178 |
self initialWindowSpecForDialogs decodeAsLiteralArray prettyPrintString
|
|
179 |
! !
|
|
180 |
|
|
181 |
!JavaScriptCodeGeneratorTool class methodsFor:'code generation-menus'!
|
|
182 |
|
|
183 |
createActionMethodFor:aSelector in:aClass category:aCategory redefine:redefine
|
|
184 |
|alreadyInSuperclass method code|
|
|
185 |
|
|
186 |
(aClass includesSelector:aSelector) ifTrue:[
|
|
187 |
^ nil
|
|
188 |
].
|
|
189 |
|
|
190 |
alreadyInSuperclass := aClass superclass canUnderstand:aSelector.
|
|
191 |
(alreadyInSuperclass and:[redefine not]) ifTrue:[
|
|
192 |
^ nil
|
|
193 |
].
|
|
194 |
|
|
195 |
method := self methodNameTemplateFor:aSelector.
|
|
196 |
|
|
197 |
code := '%1
|
|
198 |
"automatically generated by UIEditor ..."
|
|
199 |
|
|
200 |
"*** the code below performs no action"
|
|
201 |
"*** (except for some feedback on the Transcript)"
|
|
202 |
"*** Please change as required and accept in the browser."
|
|
203 |
"*** (and replace this comment by something more useful ;-)"
|
|
204 |
|
|
205 |
"action to be added ..."
|
|
206 |
|
|
207 |
Transcript showCR:self class name, '': action for #%2 ...''.
|
|
208 |
' bindWith:method with:aSelector.
|
|
209 |
|
|
210 |
alreadyInSuperclass ifTrue:[
|
|
211 |
code := code, (('\ super %1\' bindWith:method) withCRs).
|
|
212 |
].
|
|
213 |
self compile:code forClass:aClass inCategory:(aCategory ? #actions).
|
|
214 |
^ code
|
|
215 |
!
|
|
216 |
|
|
217 |
createAspectMethodFor:aSelector in:aClass category:aCategory redefine:redefine
|
|
218 |
|alreadyInSuperclass method code text|
|
|
219 |
|
|
220 |
(aClass includesSelector:aSelector) ifTrue:[
|
|
221 |
^ nil
|
|
222 |
].
|
|
223 |
|
|
224 |
alreadyInSuperclass := aClass superclass canUnderstand:aSelector.
|
|
225 |
(alreadyInSuperclass and:[redefine not]) ifTrue:[
|
|
226 |
^ nil
|
|
227 |
].
|
|
228 |
|
|
229 |
method := self methodNameTemplateFor:aSelector.
|
|
230 |
|
|
231 |
code := '%1
|
|
232 |
"automatically generated by UIEditor ..."
|
|
233 |
|
|
234 |
"*** the code below creates a default model when invoked"
|
|
235 |
"*** (which may not be the one you wanted)"
|
|
236 |
"*** Please change as required and accept in the browser."
|
|
237 |
"*** (and replace this comment by something more useful ;-)"
|
|
238 |
|
|
239 |
"aspect to be added ..."
|
|
240 |
|
|
241 |
Transcript showCR:self class name, '': aspect for #%2 ...''.
|
|
242 |
|
|
243 |
' bindWith:method with:aSelector.
|
|
244 |
|
|
245 |
alreadyInSuperclass ifTrue:[
|
|
246 |
text := ' ^ super %1\' bindWith:method.
|
|
247 |
] ifFalse:[
|
|
248 |
text := ' ^ builder valueAspectFor:#''%1'' initialValue:true\' bindWith:aSelector.
|
|
249 |
].
|
|
250 |
code := code, (text withCRs).
|
|
251 |
self compile:code forClass:aClass inCategory:(aCategory ? #actions).
|
|
252 |
^ code
|
|
253 |
! !
|
|
254 |
|
|
255 |
!JavaScriptCodeGeneratorTool class methodsFor:'private'!
|
|
256 |
|
|
257 |
methodNameTemplateFor:aSelector
|
|
258 |
|numArgs method|
|
|
259 |
|
|
260 |
numArgs := aSelector numArgs.
|
|
261 |
numArgs == 1 ifTrue:[
|
|
262 |
method := aSelector, 'anArgument'.
|
|
263 |
] ifFalse:[
|
|
264 |
numArgs == 0 ifTrue:[
|
|
265 |
method := aSelector
|
|
266 |
] ifFalse:[
|
|
267 |
method := ''.
|
|
268 |
aSelector keywords keysAndValuesDo:[:i :key|
|
|
269 |
method := method, key, 'arg', i printString, ' '.
|
|
270 |
].
|
|
271 |
]
|
|
272 |
].
|
|
273 |
^ method
|
|
274 |
! !
|
|
275 |
|
|
276 |
!JavaScriptCodeGeneratorTool methodsFor:'code generation'!
|
|
277 |
|
|
278 |
createClassInitializeMethodIn:aClass
|
|
279 |
"create a #initialize method on the class side (I'm tired of typing)"
|
|
280 |
|
|
281 |
|nonMetaClass metaClass className code initializer bindings|
|
|
282 |
|
|
283 |
nonMetaClass := aClass theNonMetaclass.
|
|
284 |
metaClass := aClass theMetaclass.
|
|
285 |
className := nonMetaClass name.
|
|
286 |
|
|
287 |
self startCollectChanges.
|
|
288 |
|
|
289 |
(metaClass includesSelector:#'initialize') ifFalse:[
|
|
290 |
'initialize
|
|
291 |
"Invoked at system start or when the class is dynamically loaded."
|
|
292 |
|
|
293 |
"/ please change as required (and remove this comment)
|
|
294 |
'.
|
|
295 |
bindings := Dictionary new.
|
|
296 |
bindings at:'INIT_CLASSINSTVARS' put:(
|
|
297 |
String streamContents:[:s |
|
|
298 |
metaClass instVarNames do:[:eachClassInstVar |
|
|
299 |
initializer := 'nil'. "/ need more intelligence here (try to guess class from messages sent to it) ...
|
|
300 |
s nextPutLine:(' "/ %1 := %2.' bindWith:eachClassInstVar with:initializer).
|
|
301 |
]
|
|
302 |
]).
|
|
303 |
|
|
304 |
bindings at:'INIT_CLASSVARS' put:(
|
|
305 |
String streamContents:[:s |
|
|
306 |
nonMetaClass classVarNames do:[:eachClassVar |
|
|
307 |
initializer := 'nil'. "/ need more intelligence here (try to guess class from messages sent to it) ...
|
|
308 |
s nextPutLine:(' "/ %1 := %2.' bindWith:eachClassVar with:initializer).
|
|
309 |
]
|
|
310 |
]).
|
|
311 |
|
|
312 |
code := (self codeFor_classInitialize) expandPlaceholdersWith:bindings.
|
|
313 |
|
|
314 |
self
|
|
315 |
compile:code
|
|
316 |
forClass:metaClass
|
|
317 |
inCategory:#initialization.
|
|
318 |
].
|
|
319 |
|
|
320 |
self executeCollectedChangesNamed:('Add Class Initializer to ' , className).
|
|
321 |
!
|
|
322 |
|
|
323 |
createClassTypeTestMethodsIn:aClass forClasses:subClasses
|
|
324 |
"create a #isXXX test methods (I'm tired of typing)"
|
|
325 |
|
|
326 |
| code|
|
|
327 |
|
|
328 |
self startCollectChanges.
|
|
329 |
|
|
330 |
subClasses do:[:eachSubClass |
|
|
331 |
|nm selector|
|
|
332 |
|
|
333 |
nm := eachSubClass nameWithoutPrefix.
|
|
334 |
selector := 'is' , nm.
|
|
335 |
(aClass includesSelector:selector) ifFalse:[
|
|
336 |
code := (selector , '\ ^ false') withCRs.
|
|
337 |
self
|
|
338 |
compile:code
|
|
339 |
forClass:aClass
|
|
340 |
inCategory:#testing.
|
|
341 |
].
|
|
342 |
(eachSubClass includesSelector:selector) ifFalse:[
|
|
343 |
code := (selector , '\ ^ true') withCRs.
|
|
344 |
self
|
|
345 |
compile:code
|
|
346 |
forClass:eachSubClass
|
|
347 |
inCategory:#testing.
|
|
348 |
].
|
|
349 |
].
|
|
350 |
|
|
351 |
self executeCollectedChangesNamed:'Add ClassType Tests'
|
|
352 |
!
|
|
353 |
|
|
354 |
createEnumTypeCodeFor:aClass
|
|
355 |
|nonMetaClass metaClass className enumValues code initCode runValue maxValue|
|
|
356 |
|
|
357 |
self startCollectChanges.
|
|
358 |
|
|
359 |
nonMetaClass := aClass theNonMetaclass.
|
|
360 |
metaClass := aClass theMetaclass.
|
|
361 |
className := nonMetaClass name.
|
|
362 |
|
|
363 |
enumValues := nonMetaClass classVarNames.
|
|
364 |
enumValues do:[:eachVariableName |
|
|
365 |
self
|
|
366 |
createAccessMethodsFor:(Array with:eachVariableName)
|
|
367 |
in:metaClass
|
|
368 |
withChange:false
|
|
369 |
asValueHolder:false
|
|
370 |
readersOnly:true
|
|
371 |
writersOnly:false
|
|
372 |
].
|
|
373 |
|
|
374 |
maxValue := enumValues
|
|
375 |
inject:0
|
|
376 |
into:[:maxSoFar :eachVariableName |
|
|
377 |
|oldVal val|
|
|
378 |
oldVal := nonMetaClass classVarAt:eachVariableName.
|
|
379 |
oldVal notNil ifTrue:[ val := oldVal numericValue ].
|
|
380 |
(val ? maxSoFar) max:maxSoFar
|
|
381 |
].
|
|
382 |
|
|
383 |
initCode := WriteStream on: String new.
|
|
384 |
initCode nextPutLine:'initialize'.
|
|
385 |
runValue := maxValue + 1.
|
|
386 |
enumValues keysAndValuesDo:[:idx :eachVariableName |
|
|
387 |
|oldValue thisValue|
|
|
388 |
|
|
389 |
oldValue := nonMetaClass classVarAt:eachVariableName.
|
|
390 |
oldValue notNil ifTrue:[
|
|
391 |
thisValue := oldValue numericValue.
|
|
392 |
] ifFalse:[
|
|
393 |
thisValue := runValue.
|
|
394 |
runValue := runValue + 1.
|
|
395 |
].
|
|
396 |
initCode
|
|
397 |
nextPutAll:' ';
|
|
398 |
nextPutAll:eachVariableName;
|
|
399 |
nextPutAll:' := self basicNew'.
|
|
400 |
(aClass canUnderstand:#'setNumericValue:') ifTrue:[
|
|
401 |
initCode nextPutAll:' setNumericValue: ',thisValue printString.
|
|
402 |
].
|
|
403 |
(aClass canUnderstand:#'setCssClassString:') ifTrue:[
|
|
404 |
initCode nextPutAll:('; setCssClassString: ''' , nonMetaClass nameWithoutPrefix asLowercaseFirst , eachVariableName , '''').
|
|
405 |
].
|
|
406 |
(aClass canUnderstand:#'setName:') ifTrue:[
|
|
407 |
initCode nextPutAll:('; setName: ''' , eachVariableName asLowercaseFirst , '''').
|
|
408 |
].
|
|
409 |
initCode nextPutLine:'.'.
|
|
410 |
].
|
|
411 |
initCode cr.
|
|
412 |
initCode nextPutLine:' "'.
|
|
413 |
initCode nextPutLine:' ',className, ' initialize'.
|
|
414 |
initCode nextPutLine:' "'.
|
|
415 |
|
|
416 |
self
|
|
417 |
compile:(initCode contents)
|
|
418 |
forClass:metaClass
|
|
419 |
inCategory:#'class initialization'.
|
|
420 |
|
|
421 |
|
|
422 |
code := 'allStateNames\ ^ #( ' ,
|
|
423 |
((enumValues collect:[:each | '#''',each asLowercaseFirst,'''']) asStringWith:' ') , ')',
|
|
424 |
'\\ "\' ,
|
|
425 |
' ',className, ' allStateNames\' ,
|
|
426 |
' "\'.
|
|
427 |
self
|
|
428 |
compile:code withCRs
|
|
429 |
forClass:metaClass
|
|
430 |
inCategory:#queries.
|
|
431 |
|
|
432 |
self executeCollectedChangesNamed:('Generate EnumType Code for ' , className).
|
|
433 |
|
|
434 |
aClass initialize.
|
|
435 |
|
|
436 |
"Modified: / 1.2.1998 / 16:10:03 / cg"
|
|
437 |
!
|
|
438 |
|
|
439 |
createExamplesMethodForViewClass:aClass
|
|
440 |
"create an examples method"
|
|
441 |
|
|
442 |
|nonMetaClass metaClass className code|
|
|
443 |
|
|
444 |
nonMetaClass := aClass theNonMetaclass.
|
|
445 |
metaClass := aClass theMetaclass.
|
|
446 |
className := nonMetaClass name.
|
|
447 |
|
|
448 |
self startCollectChanges.
|
|
449 |
|
|
450 |
(metaClass includesSelector:#examples) ifFalse:[
|
|
451 |
code :=
|
|
452 |
'examples
|
|
453 |
"
|
|
454 |
Notice that everything between [exBegin] and [exEnd] is extracted by the html-doc generator
|
|
455 |
to create nicely formatted and clickable executable examples in the generated html-doc.
|
|
456 |
(see the browsers class-documentation menu items for more)
|
|
457 |
|
|
458 |
trying the widget as standAlone view:
|
|
459 |
[exBegin]
|
|
460 |
%1 new open
|
|
461 |
[exEnd]
|
|
462 |
|
|
463 |
embedded in another view:
|
|
464 |
[exBegin]
|
|
465 |
|top v|
|
|
466 |
|
|
467 |
top := StandardSystemView new.
|
|
468 |
top extent:300@300.
|
|
469 |
v := %1 new.
|
|
470 |
v origin:10@10 corner:150@150.
|
|
471 |
top add:v.
|
|
472 |
top open
|
|
473 |
[exEnd]
|
|
474 |
"
|
|
475 |
' bindWith:className.
|
|
476 |
|
|
477 |
self
|
|
478 |
compile:code
|
|
479 |
forClass:metaClass
|
|
480 |
inCategory:#documentation.
|
|
481 |
].
|
|
482 |
|
|
483 |
self executeCollectedChangesNamed:('Add Example to ' , className).
|
|
484 |
!
|
|
485 |
|
|
486 |
createInitializationMethodIn:aClass
|
|
487 |
"create a #initialize methods (I'm tired of typing)"
|
|
488 |
|
|
489 |
|nonMetaClass metaClass className code initializer m|
|
|
490 |
|
|
491 |
nonMetaClass := aClass theNonMetaclass.
|
|
492 |
metaClass := aClass theMetaclass.
|
|
493 |
className := nonMetaClass name.
|
|
494 |
|
|
495 |
self startCollectChanges.
|
|
496 |
|
|
497 |
(nonMetaClass includesSelector:#initialize) ifFalse:[
|
|
498 |
code :=
|
|
499 |
'initialize
|
|
500 |
"Invoked when a new instance is created."
|
|
501 |
|
|
502 |
"/ please change as required (and remove this comment)
|
|
503 |
'.
|
|
504 |
|
|
505 |
nonMetaClass instVarNames do:[:eachInstVar |
|
|
506 |
initializer := 'nil'. "/ need more intelligence here (try to guess class from messages sent to it) ...
|
|
507 |
code := code , (' "/ ' , eachInstVar , ' := ' , initializer , '.' , Character cr).
|
|
508 |
].
|
|
509 |
|
|
510 |
m := nonMetaClass responseTo:#initialize.
|
|
511 |
(m notNil and:[m messagesSent size == 0]) ifTrue:[
|
|
512 |
"/ inherits an empty initialize.
|
|
513 |
|
|
514 |
code := code , '
|
|
515 |
"/ super initialize. -- commented since inherited method does nothing
|
|
516 |
'.
|
|
517 |
] ifFalse:[
|
|
518 |
code := code , '
|
|
519 |
super initialize.
|
|
520 |
'.
|
|
521 |
].
|
|
522 |
|
|
523 |
self
|
|
524 |
compile:code
|
|
525 |
forClass:nonMetaClass
|
|
526 |
inCategory:#initialization.
|
|
527 |
].
|
|
528 |
|
|
529 |
self executeCollectedChangesNamed:('Add Initialized Instance Creation to ' , className).
|
|
530 |
!
|
|
531 |
|
|
532 |
createInitializedInstanceCreationMethodsIn:aClass
|
|
533 |
"create a #new and #initialize methods (I'm tired of typing)"
|
|
534 |
|
|
535 |
|nonMetaClass metaClass className code m|
|
|
536 |
|
|
537 |
nonMetaClass := aClass theNonMetaclass.
|
|
538 |
metaClass := aClass theMetaclass.
|
|
539 |
className := nonMetaClass name.
|
|
540 |
|
|
541 |
self startCollectChanges.
|
|
542 |
|
|
543 |
self createInitializationMethodIn:aClass.
|
|
544 |
|
|
545 |
(metaClass includesSelector:#new) ifFalse:[
|
|
546 |
m := metaClass responseTo:#new.
|
|
547 |
(m isNil
|
|
548 |
or:[ (m sends:#initialize) not
|
|
549 |
or:[
|
|
550 |
(Dialog
|
|
551 |
confirmWithCancel:('The inherited #new method already seems to invoke #initialize.\Redefine ?' withCRs)
|
|
552 |
default:false
|
|
553 |
onCancel:[^ self] )
|
|
554 |
]]) ifTrue:[
|
|
555 |
code :=
|
|
556 |
'new
|
|
557 |
"return an initialized instance"
|
|
558 |
|
|
559 |
^ self basicNew initialize.
|
|
560 |
'.
|
|
561 |
self
|
|
562 |
compile:code
|
|
563 |
forClass:metaClass
|
|
564 |
inCategory:#'instance creation'.
|
|
565 |
].
|
|
566 |
].
|
|
567 |
|
|
568 |
self executeCollectedChangesNamed:('Add Initialized Instance Creation to ' , className).
|
|
569 |
|
|
570 |
"Created: / 11-10-2001 / 22:18:55 / cg"
|
|
571 |
"Modified: / 30-01-2011 / 00:58:04 / cg"
|
|
572 |
!
|
|
573 |
|
|
574 |
createParametrizedInstanceCreationMethodsNamed:selector in:aClass
|
|
575 |
"create a #selector instance creation method (I'm tired of typing)"
|
|
576 |
|
|
577 |
|nonMetaClass metaClass className code initializer m dfn|
|
|
578 |
|
|
579 |
dfn := Method methodDefinitionTemplateForSelector:selector.
|
|
580 |
|
|
581 |
nonMetaClass := aClass theNonMetaclass.
|
|
582 |
metaClass := aClass theMetaclass.
|
|
583 |
className := nonMetaClass name.
|
|
584 |
|
|
585 |
self startCollectChanges.
|
|
586 |
|
|
587 |
(nonMetaClass includesSelector:selector asSymbol) ifFalse:[
|
|
588 |
code :=
|
|
589 |
'initialize',dfn asUppercaseFirst,'
|
|
590 |
"Invoked when a new instance is created for arg."
|
|
591 |
|
|
592 |
"/ please change as required (and remove these comments)
|
|
593 |
"/ do something with arg here (instVar-foo := arg)
|
|
594 |
'.
|
|
595 |
nonMetaClass instVarNames do:[:eachInstVar |
|
|
596 |
initializer := 'nil'. "/ need more intelligence here (try to guess class from messages sent to it) ...
|
|
597 |
code := code , (' "/ ' , eachInstVar , ' := ' , initializer , '.' , Character cr).
|
|
598 |
].
|
|
599 |
|
|
600 |
m := nonMetaClass responseTo:#initialize.
|
|
601 |
(m notNil and:[ m messagesSent size == 0 ]) ifTrue:[
|
|
602 |
"/ inherits an empty initialize.
|
|
603 |
|
|
604 |
code := code , '
|
|
605 |
"/ super initialize. -- commented since inherited method does nothing
|
|
606 |
'.
|
|
607 |
] ifFalse:[
|
|
608 |
code := code , '
|
|
609 |
super initialize.
|
|
610 |
'.
|
|
611 |
].
|
|
612 |
|
|
613 |
self
|
|
614 |
compile:code
|
|
615 |
forClass:nonMetaClass
|
|
616 |
inCategory:#initialization.
|
|
617 |
].
|
|
618 |
|
|
619 |
(metaClass includesSelector:selector) ifFalse:[
|
|
620 |
m := metaClass responseTo:selector.
|
|
621 |
(m isNil
|
|
622 |
or:[ (Dialog confirmWithCancel:'The ',selector,'- method is already inherited. Redefine ?' onCancel:[^ self]) ])
|
|
623 |
ifTrue:[
|
|
624 |
code :=
|
|
625 |
dfn,'
|
|
626 |
"Create & return a new instance for arg."
|
|
627 |
|
|
628 |
^ self basicNew initialize',dfn asUppercaseFirst,'
|
|
629 |
'.
|
|
630 |
self
|
|
631 |
compile:code
|
|
632 |
forClass:metaClass
|
|
633 |
inCategory:#'instance creation'.
|
|
634 |
].
|
|
635 |
].
|
|
636 |
|
|
637 |
self executeCollectedChangesNamed:('Add Parametrized Instance Creation to ' , className).
|
|
638 |
!
|
|
639 |
|
|
640 |
createPoolInitializationCodeFor:aClass
|
|
641 |
|nonMetaClass metaClass className poolVars initCode|
|
|
642 |
|
|
643 |
self startCollectChanges.
|
|
644 |
|
|
645 |
nonMetaClass := aClass theNonMetaclass.
|
|
646 |
metaClass := aClass theMetaclass.
|
|
647 |
className := nonMetaClass name.
|
|
648 |
|
|
649 |
poolVars := nonMetaClass classVarNames.
|
|
650 |
|
|
651 |
initCode := WriteStream on: String new.
|
|
652 |
initCode nextPutLine:'initialize'.
|
|
653 |
|
|
654 |
poolVars do:[:eachVariableName |
|
|
655 |
|oldValue thisValue|
|
|
656 |
|
|
657 |
oldValue := nonMetaClass classVarAt:eachVariableName.
|
|
658 |
oldValue notNil ifTrue:[
|
|
659 |
thisValue := oldValue.
|
|
660 |
] ifFalse:[
|
|
661 |
thisValue := nil.
|
|
662 |
].
|
|
663 |
initCode
|
|
664 |
nextPutAll:' ';
|
|
665 |
nextPutAll:eachVariableName;
|
|
666 |
nextPutAll:' := ';
|
|
667 |
nextPutAll:thisValue storeString;
|
|
668 |
nextPutLine:'.'.
|
|
669 |
].
|
|
670 |
initCode cr.
|
|
671 |
initCode nextPutLine:' "'.
|
|
672 |
initCode nextPutLine:' ',className, ' initialize'.
|
|
673 |
initCode nextPutLine:' "'.
|
|
674 |
|
|
675 |
self
|
|
676 |
compile:(initCode contents)
|
|
677 |
forClass:metaClass
|
|
678 |
inCategory:#'class initialization'.
|
|
679 |
|
|
680 |
self executeCollectedChangesNamed:('Generate Pool Initialization Code for ' , className).
|
|
681 |
|
|
682 |
aClass initialize.
|
|
683 |
|
|
684 |
"Created: / 25-10-2006 / 09:28:40 / cg"
|
|
685 |
!
|
|
686 |
|
|
687 |
createRedefinedInstanceCreationMethodsIn:aClass
|
|
688 |
"create a redefined #new methods"
|
|
689 |
|
|
690 |
|nonMetaClass metaClass className code|
|
|
691 |
|
|
692 |
nonMetaClass := aClass theNonMetaclass.
|
|
693 |
metaClass := aClass theMetaclass.
|
|
694 |
className := nonMetaClass name.
|
|
695 |
|
|
696 |
self startCollectChanges.
|
|
697 |
|
|
698 |
(metaClass includesSelector:#'new') ifFalse:[
|
|
699 |
code :=
|
|
700 |
'new
|
|
701 |
^ super new.
|
|
702 |
'.
|
|
703 |
self
|
|
704 |
compile:code
|
|
705 |
forClass:metaClass
|
|
706 |
inCategory:#'redefined instance creation'.
|
|
707 |
].
|
|
708 |
(metaClass includesSelector:#'new:') ifFalse:[
|
|
709 |
code :=
|
|
710 |
'new:n
|
|
711 |
^ super new:n.
|
|
712 |
'.
|
|
713 |
self
|
|
714 |
compile:code
|
|
715 |
forClass:metaClass
|
|
716 |
inCategory:#'redefined instance creation'.
|
|
717 |
].
|
|
718 |
|
|
719 |
self executeCollectedChangesNamed:('Redefined Instance Creation to ' , className).
|
|
720 |
!
|
|
721 |
|
|
722 |
createSingletonPatternInstanceCreationMethodsIn:aClass usingVariable:varName
|
|
723 |
"create redefined #new methods for singleton pattern.
|
|
724 |
Uses varName (typically a class-instvar) to keep the singleton instance."
|
|
725 |
|
|
726 |
|nonMetaClass metaClass className code|
|
|
727 |
|
|
728 |
nonMetaClass := aClass theNonMetaclass.
|
|
729 |
metaClass := aClass theMetaclass.
|
|
730 |
className := nonMetaClass name.
|
|
731 |
|
|
732 |
self startCollectChanges.
|
|
733 |
|
|
734 |
(metaClass includesSelector:#theOneAndOnlyInstance) ifFalse:[
|
|
735 |
code :=
|
|
736 |
'theOneAndOnlyInstance
|
|
737 |
"returns a singleton"
|
|
738 |
|
|
739 |
%1 isNil ifTrue:[
|
|
740 |
%1 := self basicNew initialize.
|
|
741 |
].
|
|
742 |
^ %1.
|
|
743 |
'.
|
|
744 |
self
|
|
745 |
compile:(code bindWith:varName)
|
|
746 |
forClass:metaClass
|
|
747 |
inCategory:#'instance creation'.
|
|
748 |
].
|
|
749 |
|
|
750 |
(metaClass includesSelector:#new) ifFalse:[
|
|
751 |
code :=
|
|
752 |
'new
|
|
753 |
"returns a singleton"
|
|
754 |
|
|
755 |
^ self theOneAndOnlyInstance.
|
|
756 |
'.
|
|
757 |
self
|
|
758 |
compile:(code bindWith:varName)
|
|
759 |
forClass:metaClass
|
|
760 |
inCategory:#'instance creation'.
|
|
761 |
].
|
|
762 |
|
|
763 |
(metaClass includesSelector:#flushSingleton) ifFalse:[
|
|
764 |
code :=
|
|
765 |
'flushSingleton
|
|
766 |
"flushes the cached singleton"
|
|
767 |
|
|
768 |
%1 := nil
|
|
769 |
|
|
770 |
"
|
|
771 |
self flushSingleton
|
|
772 |
"
|
|
773 |
'.
|
|
774 |
self
|
|
775 |
compile:(code bindWith:varName)
|
|
776 |
forClass:metaClass
|
|
777 |
inCategory:#'instance creation'.
|
|
778 |
].
|
|
779 |
|
|
780 |
self executeCollectedChangesNamed:('Singleton Pattern for ' , className).
|
|
781 |
|
|
782 |
"Created: / 10-02-2011 / 16:32:48 / cg"
|
|
783 |
!
|
|
784 |
|
|
785 |
createStandardPrintOnMethodIn:aClass
|
|
786 |
"create a #printOn: method (I'm tired of typing)"
|
|
787 |
|
|
788 |
|code nonMetaClass|
|
|
789 |
|
|
790 |
nonMetaClass := aClass theNonMetaclass.
|
|
791 |
|
|
792 |
self startCollectChanges.
|
|
793 |
|
|
794 |
(nonMetaClass includesSelector:#printOn:) ifFalse:[
|
|
795 |
code :=
|
|
796 |
'printOn:aStream
|
|
797 |
"append a printed representation if the receiver to the argument, aStream"
|
|
798 |
|
|
799 |
super printOn:aStream.
|
|
800 |
'.
|
|
801 |
nonMetaClass instVarNames do:[:eachInstVarName |
|
|
802 |
code := code , ' '.
|
|
803 |
code := code , 'aStream nextPutAll:'''.
|
|
804 |
code := code , eachInstVarName.
|
|
805 |
code := code , ': ''.' , Character cr.
|
|
806 |
code := code , ' '.
|
|
807 |
code := code , eachInstVarName.
|
|
808 |
code := code , ' printOn:aStream.' , Character cr.
|
|
809 |
|
|
810 |
].
|
|
811 |
|
|
812 |
self
|
|
813 |
compile:code
|
|
814 |
forClass:nonMetaClass
|
|
815 |
inCategory:#'printing & storing'.
|
|
816 |
].
|
|
817 |
|
|
818 |
|
|
819 |
self executeCollectedChangesNamed:('Add #printOn: to ' , nonMetaClass name).
|
|
820 |
|
|
821 |
"Created: / 11.10.2001 / 22:18:55 / cg"
|
|
822 |
!
|
|
823 |
|
|
824 |
createStartupCodeFor:aClass forStartOf:anApplicationClassOrNil
|
|
825 |
"create startup code (main)"
|
|
826 |
|
|
827 |
|nonMetaClass metaClass className source
|
|
828 |
hasAplicationClass anApplicationClassNameOrStartupClassName|
|
|
829 |
|
|
830 |
self startCollectChanges.
|
|
831 |
|
|
832 |
hasAplicationClass := anApplicationClassOrNil notNil.
|
|
833 |
nonMetaClass := aClass theNonMetaclass.
|
|
834 |
metaClass := aClass theMetaclass.
|
|
835 |
className := nonMetaClass name.
|
|
836 |
|
|
837 |
(metaClass includesSelector:#main:) ifFalse:[
|
|
838 |
|
|
839 |
source := String streamContents:[:stream |
|
|
840 |
stream nextPutAll:
|
|
841 |
'main:argv
|
|
842 |
self verboseInfo:''starting %1''.
|
|
843 |
|
|
844 |
'.
|
|
845 |
hasAplicationClass ifTrue: [
|
|
846 |
stream nextPutAll:
|
|
847 |
' Smalltalk openDisplay.
|
|
848 |
Display notNil ifTrue:[
|
|
849 |
Display exitOnLastClose:true.
|
|
850 |
].
|
|
851 |
%1 open.
|
|
852 |
'.
|
|
853 |
].
|
|
854 |
].
|
|
855 |
|
|
856 |
anApplicationClassNameOrStartupClassName := hasAplicationClass
|
|
857 |
ifTrue: [anApplicationClassOrNil name]
|
|
858 |
ifFalse: [className.].
|
|
859 |
self
|
|
860 |
compile:(source bindWith:anApplicationClassNameOrStartupClassName)
|
|
861 |
forClass:metaClass
|
|
862 |
inCategory:#startup.
|
|
863 |
].
|
|
864 |
self executeCollectedChangesNamed:('Add Startup Code to ' , className).
|
|
865 |
!
|
|
866 |
|
|
867 |
createTestCaseSampleCodeFor:aClass
|
|
868 |
"create an (almost) empty testCase class"
|
|
869 |
|
|
870 |
|nonMetaClass metaClass|
|
|
871 |
|
|
872 |
nonMetaClass := aClass theNonMetaclass.
|
|
873 |
metaClass := aClass theMetaclass.
|
|
874 |
"/ className := nonMetaClass name.
|
|
875 |
|
|
876 |
( nonMetaClass includesSelector:#test1 ) ifFalse:[
|
|
877 |
self
|
|
878 |
compile:
|
|
879 |
'test1
|
|
880 |
"This is a demonstration testCase - it is meant to be removed eventually.
|
|
881 |
This testCase will PASS.
|
|
882 |
Double click on the TestCase class or open a TestRunner to see me checking...
|
|
883 |
- please add more methods like this..."
|
|
884 |
|
|
885 |
|o|
|
|
886 |
|
|
887 |
o := Array new:2.
|
|
888 |
self assert: ( o size == 2 ).
|
|
889 |
self should: [ o at:0 ] raise:Error.
|
|
890 |
self shouldnt: [ o at:1 ] raise:Error.
|
|
891 |
|
|
892 |
"
|
|
893 |
self run:#test1
|
|
894 |
self new test1
|
|
895 |
"
|
|
896 |
'
|
|
897 |
forClass:nonMetaClass
|
|
898 |
inCategory:#tests.
|
|
899 |
].
|
|
900 |
|
|
901 |
( nonMetaClass includesSelector:#test2 ) ifFalse:[
|
|
902 |
self
|
|
903 |
compile:
|
|
904 |
'test2
|
|
905 |
"This is a demonstration testCase - it is meant to be removed eventually..
|
|
906 |
This testCase WILL FAIL.
|
|
907 |
Double click on the TestCase class or open a TestRunner to see me checking...
|
|
908 |
- please add more methods like this..."
|
|
909 |
|
|
910 |
|o|
|
|
911 |
|
|
912 |
o := Array new:2.
|
|
913 |
self assert: ( o size == 3 ).
|
|
914 |
|
|
915 |
"
|
|
916 |
self run:#test2
|
|
917 |
self new test2
|
|
918 |
"
|
|
919 |
'
|
|
920 |
forClass:nonMetaClass
|
|
921 |
inCategory:#tests.
|
|
922 |
].
|
|
923 |
|
|
924 |
( nonMetaClass includesSelector:#test3 ) ifFalse:[
|
|
925 |
self
|
|
926 |
compile:
|
|
927 |
'test3
|
|
928 |
"This is a demonstration testCase - it is meant to be removed eventually..
|
|
929 |
This testCase WILL generate an ERROR.
|
|
930 |
Double click on the TestCase class or open a TestRunner to see me checking...
|
|
931 |
- please add more methods like this..."
|
|
932 |
|
|
933 |
|o|
|
|
934 |
|
|
935 |
o := Array new:2.
|
|
936 |
self assert: ( o foo ).
|
|
937 |
|
|
938 |
"
|
|
939 |
self run:#test3
|
|
940 |
self new test3
|
|
941 |
"
|
|
942 |
'
|
|
943 |
forClass:nonMetaClass
|
|
944 |
inCategory:#tests.
|
|
945 |
].
|
|
946 |
|
|
947 |
( nonMetaClass includesSelector:#setUp ) ifFalse:[
|
|
948 |
self
|
|
949 |
compile:
|
|
950 |
'setUp
|
|
951 |
"common setup - invoked before testing."
|
|
952 |
|
|
953 |
super setUp
|
|
954 |
'
|
|
955 |
forClass:nonMetaClass
|
|
956 |
inCategory:#'initialize / release'.
|
|
957 |
].
|
|
958 |
|
|
959 |
( nonMetaClass includesSelector:#tearDown ) ifFalse:[
|
|
960 |
self
|
|
961 |
compile:
|
|
962 |
'tearDown
|
|
963 |
"common cleanup - invoked after testing."
|
|
964 |
|
|
965 |
super tearDown
|
|
966 |
'
|
|
967 |
forClass:nonMetaClass
|
|
968 |
inCategory:#'initialize / release'.
|
|
969 |
]
|
|
970 |
!
|
|
971 |
|
|
972 |
createVisitorMethodsIn:visitedClass andVisitorClass:visitorClass
|
|
973 |
"create acceptVisitor: in visitedClass and acceptXXX in visitorClass. (I'm tired of typing)"
|
|
974 |
|
|
975 |
|sel|
|
|
976 |
|
|
977 |
self assert:( visitedClass isMeta not ).
|
|
978 |
self assert:( visitorClass isMeta not ).
|
|
979 |
|
|
980 |
self startCollectChanges.
|
|
981 |
|
|
982 |
sel := ('visit' , visitedClass nameWithoutPrefix , ':').
|
|
983 |
self createAcceptVisitorMethod:sel in:visitedClass.
|
|
984 |
|
|
985 |
(visitorClass includesSelector:sel) ifFalse:[
|
|
986 |
self
|
|
987 |
compile:
|
|
988 |
(('%1anObject
|
|
989 |
"dispatched back from the visited %2-object (visitor pattern)"
|
|
990 |
|
|
991 |
"fall back to general object-case - please change as required"
|
|
992 |
|
|
993 |
^ self visitObject:anObject
|
|
994 |
') bindWith:sel with:visitedClass nameWithoutPrefix asLowercaseFirst)
|
|
995 |
forClass:visitorClass
|
|
996 |
inCategory:#visiting.
|
|
997 |
].
|
|
998 |
|
|
999 |
(visitorClass includesSelector:#visitObject:) ifFalse:[
|
|
1000 |
self
|
|
1001 |
compile:
|
|
1002 |
('visitObject:anObject
|
|
1003 |
"dispatched back from the visited objects (visitor pattern)"
|
|
1004 |
|
|
1005 |
"general fallBack - please change as required"
|
|
1006 |
|
|
1007 |
self halt:''not yet implemented''
|
|
1008 |
')
|
|
1009 |
forClass:visitorClass
|
|
1010 |
inCategory:#visiting.
|
|
1011 |
].
|
|
1012 |
|
|
1013 |
(visitorClass includesSelector:#visit:) ifFalse:[
|
|
1014 |
self
|
|
1015 |
compile:
|
|
1016 |
('visit:anObject
|
|
1017 |
"visit anObject (visitor pattern).
|
|
1018 |
The object should call back one of my visitXXXX methods."
|
|
1019 |
|
|
1020 |
^ anObject acceptVisitor:self
|
|
1021 |
')
|
|
1022 |
forClass:visitorClass
|
|
1023 |
inCategory:#visiting.
|
|
1024 |
].
|
|
1025 |
|
|
1026 |
self executeCollectedChangesNamed:('Add Visitor Pattern').
|
|
1027 |
!
|
|
1028 |
|
|
1029 |
createWebApplicationCodeFor:aClass
|
|
1030 |
"create an empty webApplication framework"
|
|
1031 |
|
|
1032 |
|nonMetaClass metaClass className txt|
|
|
1033 |
|
|
1034 |
self startCollectChanges.
|
|
1035 |
|
|
1036 |
nonMetaClass := aClass theNonMetaclass.
|
|
1037 |
metaClass := aClass theMetaclass.
|
|
1038 |
className := nonMetaClass name.
|
|
1039 |
|
|
1040 |
(metaClass includesSelector:#pageSpec) ifFalse:[
|
|
1041 |
txt := self class initialPageSpecMethodSourceForWebApplications.
|
|
1042 |
self
|
|
1043 |
compile:(txt bindWith:className)
|
|
1044 |
forClass:metaClass
|
|
1045 |
inCategory:#'page specs'.
|
|
1046 |
].
|
|
1047 |
|
|
1048 |
self executeCollectedChangesNamed:('Add WebApplication Code for ' , className).
|
|
1049 |
|
|
1050 |
"Modified: / 1.2.1998 / 16:10:03 / cg"
|
|
1051 |
!
|
|
1052 |
|
|
1053 |
createWebServiceCodeFor:aClass
|
|
1054 |
"create an empty webService framework"
|
|
1055 |
|
|
1056 |
|nonMetaClass metaClass className txt|
|
|
1057 |
|
|
1058 |
self startCollectChanges.
|
|
1059 |
|
|
1060 |
nonMetaClass := aClass theNonMetaclass.
|
|
1061 |
metaClass := aClass theMetaclass.
|
|
1062 |
className := nonMetaClass name.
|
|
1063 |
|
|
1064 |
(nonMetaClass includesSelector:#page1:) ifFalse:[
|
|
1065 |
txt :=
|
|
1066 |
'page1:aRequest
|
|
1067 |
"This is a sample page-generation method.
|
|
1068 |
This uses the simplest possible way to generate html: generating plain HTML.
|
|
1069 |
See page2 for a more structured example."
|
|
1070 |
|
|
1071 |
|response|
|
|
1072 |
|
|
1073 |
response := aRequest response.
|
|
1074 |
response nextPutLine:''<HTML>''.
|
|
1075 |
response nextPutLine:'' <HEAD>''.
|
|
1076 |
response nextPutLine:'' <TITLE>Hello</TITLE>''.
|
|
1077 |
response nextPutLine:'' </HEAD>''.
|
|
1078 |
response nextPutLine:'' <BODY>''.
|
|
1079 |
response nextPutLine:'' <H1>Hello World !!</H1>''.
|
|
1080 |
response nextPutLine:'' </BODY>''.
|
|
1081 |
response nextPutLine:''</HTML>''.
|
|
1082 |
'.
|
|
1083 |
self
|
|
1084 |
compile:txt
|
|
1085 |
forClass:nonMetaClass
|
|
1086 |
inCategory:#'response generation - pages'.
|
|
1087 |
].
|
|
1088 |
|
|
1089 |
(nonMetaClass includesSelector:#page2:) ifFalse:[
|
|
1090 |
txt :=
|
|
1091 |
'page2:aRequest
|
|
1092 |
"This is a sample page-generation method.
|
|
1093 |
This uses a slightly more convenient way to generate html: using an HTML tree builder.
|
|
1094 |
Event better examples to follow..."
|
|
1095 |
|
|
1096 |
|page|
|
|
1097 |
|
|
1098 |
page := HTML::TreeBuilder newDocument.
|
|
1099 |
page
|
|
1100 |
head;
|
|
1101 |
title:''Hello'';
|
|
1102 |
headEnd;
|
|
1103 |
body;
|
|
1104 |
h1:''Hello World'';
|
|
1105 |
div;
|
|
1106 |
nlsText:''here is some text and '';
|
|
1107 |
a; href:''page3'';
|
|
1108 |
text:''an anchor'';
|
|
1109 |
aEnd;
|
|
1110 |
text:'' and an image: '';
|
|
1111 |
img:(httpServer graphicLinkIdFor:(ToolbarIconLibrary smiley_cool) expirationTimeDelta:30 seconds);
|
|
1112 |
divEnd;
|
|
1113 |
bodyEnd.
|
|
1114 |
|
|
1115 |
aRequest reply:(page htmlString).
|
|
1116 |
'.
|
|
1117 |
self
|
|
1118 |
compile:txt
|
|
1119 |
forClass:nonMetaClass
|
|
1120 |
inCategory:#'response generation - pages'.
|
|
1121 |
].
|
|
1122 |
|
|
1123 |
(nonMetaClass includesSelector:#page3:) ifFalse:[
|
|
1124 |
txt :=
|
|
1125 |
'page3:aRequest
|
|
1126 |
"This is a sample page which generates plain text (i.e. nit html)."
|
|
1127 |
|
|
1128 |
aRequest response
|
|
1129 |
contentType:''text/plain'';
|
|
1130 |
data:''This is some plain text,
|
|
1131 |
without any html formatting.''
|
|
1132 |
'.
|
|
1133 |
self
|
|
1134 |
compile:txt
|
|
1135 |
forClass:nonMetaClass
|
|
1136 |
inCategory:#'response generation - pages'.
|
|
1137 |
].
|
|
1138 |
|
|
1139 |
(nonMetaClass includesSelector:#process:) ifFalse:[
|
|
1140 |
txt :=
|
|
1141 |
'process:aRequest
|
|
1142 |
"This is the web services main processing method.
|
|
1143 |
It will be invoked for every incoming webBrowser-request.
|
|
1144 |
The argument, aRequest contains the parameters (url, fields, parameters etc.); browse HTTPRequest for details.
|
|
1145 |
Its response object collects any returned html or other contents. Browse HTTPResponse for more info.
|
|
1146 |
|
|
1147 |
Here, a simple dipatch method is used: a hardcoded switch on the URL..."
|
|
1148 |
|
|
1149 |
|whichPage methodName method|
|
|
1150 |
|
|
1151 |
whichPage := aRequest pathRelativeToService.
|
|
1152 |
whichPage isEmpty ifTrue:[ whichPage := ''page1'' ].
|
|
1153 |
|
|
1154 |
"/ to prevent intruders from calling any method, check if it one
|
|
1155 |
"/ of my own methods, which is marked as a PAGE-method.
|
|
1156 |
|
|
1157 |
methodName := (whichPage,'':'') asSymbol.
|
|
1158 |
method := self class compiledMethodAt:methodName.
|
|
1159 |
"/ is there such a method ?
|
|
1160 |
method notNil ifTrue:[
|
|
1161 |
"/ and it is marked as being a WebPage-generator ?
|
|
1162 |
(method hasResource:#''PAGE'') ifTrue:[
|
|
1163 |
self perform:methodName with:aRequest.
|
|
1164 |
^ self
|
|
1165 |
].
|
|
1166 |
].
|
|
1167 |
aRequest reportNotFound:''No such page in this service''.
|
|
1168 |
'.
|
|
1169 |
self
|
|
1170 |
compile:txt
|
|
1171 |
forClass:nonMetaClass
|
|
1172 |
inCategory:#'response generation'.
|
|
1173 |
].
|
|
1174 |
|
|
1175 |
(metaClass includesSelector:#linkName) ifFalse:[
|
|
1176 |
txt :=
|
|
1177 |
'linkName
|
|
1178 |
"return the default linkName path (with slash)."
|
|
1179 |
|
|
1180 |
^ ''/NewService''
|
|
1181 |
'.
|
|
1182 |
self
|
|
1183 |
compile:txt
|
|
1184 |
forClass:metaClass
|
|
1185 |
inCategory:#defaults.
|
|
1186 |
].
|
|
1187 |
|
|
1188 |
(metaClass includesSelector:#settingsApplicationClass) ifFalse:[
|
|
1189 |
txt :=
|
|
1190 |
'settingsApplicationClass
|
|
1191 |
"a SettingsApplication class - or nil (used in the settings dialog if non-nil)."
|
|
1192 |
|
|
1193 |
^ nil
|
|
1194 |
'.
|
|
1195 |
self
|
|
1196 |
compile:txt
|
|
1197 |
forClass:metaClass
|
|
1198 |
inCategory:#defaults.
|
|
1199 |
].
|
|
1200 |
|
|
1201 |
|
|
1202 |
self executeCollectedChangesNamed:('Add WebService Code for ' , className).
|
|
1203 |
|
|
1204 |
"Modified: / 02-06-2011 / 12:51:15 / cg"
|
|
1205 |
!
|
|
1206 |
|
|
1207 |
createWidgetCodeFor:aClass
|
|
1208 |
"create usually required widget code (redraw, model update, event handling)"
|
|
1209 |
|
|
1210 |
|nonMetaClass metaClass className compileTemplateAction|
|
|
1211 |
|
|
1212 |
self startCollectChanges.
|
|
1213 |
|
|
1214 |
nonMetaClass := aClass theNonMetaclass.
|
|
1215 |
metaClass := aClass theMetaclass.
|
|
1216 |
className := nonMetaClass name.
|
|
1217 |
|
|
1218 |
compileTemplateAction :=
|
|
1219 |
[:selector :templateSelector :category |
|
|
1220 |
(nonMetaClass includesSelector:selector) ifFalse:[
|
|
1221 |
|txt|
|
|
1222 |
|
|
1223 |
txt := self perform:templateSelector.
|
|
1224 |
self
|
|
1225 |
compile:txt
|
|
1226 |
forClass:nonMetaClass
|
|
1227 |
inCategory:category.
|
|
1228 |
]
|
|
1229 |
].
|
|
1230 |
|
|
1231 |
#(
|
|
1232 |
initialize code_forWidget_initialize #'initialization & release'
|
|
1233 |
update:with:from: code_forWidget_update #'change & update'
|
|
1234 |
redrawX:y:width:height: code_forWidget_redraw #'drawing'
|
|
1235 |
buttonPress:x:y: code_forWidget_buttonPress #'event handling'
|
|
1236 |
keyPress:x:y: code_forWidget_keyPress #'event handling'
|
|
1237 |
sizeChanged: code_forWidget_sizeChanged #'event handling'
|
|
1238 |
) inGroupsOf:3 do:compileTemplateAction.
|
|
1239 |
|
|
1240 |
self executeCollectedChangesNamed:('Add Widget Code for ' , className).
|
|
1241 |
! !
|
|
1242 |
|
493
|
1243 |
!JavaScriptCodeGeneratorTool methodsFor:'code generation-basic'!
|
|
1244 |
|
|
1245 |
createAccessMethodsFor:aCollectionOfVarNames in:aClass withChange:withChange asValueHolder:asValueHolder readersOnly:readersOnly writersOnly:writersOnly lazyInitialization:lazyInitialization
|
|
1246 |
"workhorse for creating access methods for instvars."
|
|
1247 |
|
|
1248 |
|classesClassVars generateCommentsForSetters generateCommentsForGetters|
|
|
1249 |
|
|
1250 |
self startCollectChanges.
|
|
1251 |
|
|
1252 |
generateCommentsForSetters := userPreferences generateCommentsForSetters.
|
|
1253 |
generateCommentsForGetters := userPreferences generateCommentsForGetters.
|
|
1254 |
|
|
1255 |
classesClassVars := aClass theNonMetaclass allClassVarNames.
|
|
1256 |
|
|
1257 |
aCollectionOfVarNames do:[:name |
|
|
1258 |
|source varType methodName defaultMethodName argName|
|
|
1259 |
|
|
1260 |
varType := (classesClassVars includes:name)
|
|
1261 |
ifTrue:['static']
|
|
1262 |
ifFalse:[
|
|
1263 |
(aClass isMeta ifTrue:['classInstVar'] ifFalse:['instance'])].
|
|
1264 |
|
|
1265 |
methodName := name.
|
|
1266 |
name isUppercaseFirst ifTrue:[
|
|
1267 |
methodName := methodName asLowercaseFirst.
|
|
1268 |
].
|
|
1269 |
argName := 'something'.
|
|
1270 |
|
|
1271 |
"/ the GETTER
|
|
1272 |
writersOnly ifFalse:[
|
|
1273 |
lazyInitialization ifTrue:[
|
|
1274 |
defaultMethodName := 'default' , name asUppercaseFirst.
|
|
1275 |
].
|
|
1276 |
|
|
1277 |
"check, if method is not already present"
|
|
1278 |
(aClass includesSelector:(methodName asSymbol)) ifFalse:[
|
|
1279 |
asValueHolder ifTrue:[
|
|
1280 |
source := methodName , '() {\'.
|
|
1281 |
generateComments ifTrue:[
|
|
1282 |
source := source , ' // return/create the ''%2'' value holder (automatically generated)\\'.
|
|
1283 |
].
|
|
1284 |
source := source , ' if (%2 == null) {\'.
|
|
1285 |
lazyInitialization ifTrue:[
|
|
1286 |
source := source
|
|
1287 |
, ' %2 = this.class.%3.asValue;\'.
|
|
1288 |
] ifFalse:[
|
|
1289 |
source := source
|
|
1290 |
, ' %2 = new ValueHolder;\'.
|
|
1291 |
].
|
|
1292 |
|
|
1293 |
withChange ifTrue:[
|
|
1294 |
source := source
|
|
1295 |
, ' %2.addDependent(this);\'.
|
|
1296 |
].
|
|
1297 |
source := source
|
|
1298 |
, ' }\'
|
|
1299 |
, ' return %2;\'
|
|
1300 |
, '}'.
|
|
1301 |
] ifFalse:[
|
|
1302 |
source := methodName , '() {\'.
|
|
1303 |
lazyInitialization ifTrue:[
|
|
1304 |
generateCommentsForGetters ifTrue:[
|
|
1305 |
source := source , ' // return the %1 instance variable ''%2'' with lazy instance creation (automatically generated)\\'.
|
|
1306 |
].
|
|
1307 |
source := source
|
|
1308 |
, ' if (%2 == null) {\'
|
|
1309 |
, ' %2 = self.class.%3;\'
|
|
1310 |
, ' }\'
|
|
1311 |
, ' return %2;\'
|
|
1312 |
, '}'.
|
|
1313 |
] ifFalse:[
|
|
1314 |
generateCommentsForGetters ifTrue:[
|
|
1315 |
source := source , ' // return the %1 instance variable ''%2'' (automatically generated)\\'.
|
|
1316 |
].
|
|
1317 |
source := source
|
|
1318 |
, ' return %2;\'
|
|
1319 |
, '}'.
|
|
1320 |
].
|
|
1321 |
].
|
|
1322 |
source := (source bindWith:varType with:name with:defaultMethodName) withCRs.
|
|
1323 |
self compile:source forClass:aClass inCategory:(asValueHolder ifTrue:['aspects'] ifFalse:['accessing']).
|
|
1324 |
] ifTrue:[
|
|
1325 |
Transcript showCR:'method ''', methodName , ''' already present'
|
|
1326 |
].
|
|
1327 |
|
|
1328 |
"/ default for lazy on class side
|
|
1329 |
lazyInitialization ifTrue:[
|
|
1330 |
(aClass theMetaclass includesSelector:(defaultMethodName asSymbol)) ifFalse:[
|
|
1331 |
source := defaultMethodName , '() {\'.
|
|
1332 |
generateComments ifTrue:[
|
|
1333 |
source := source , ' // default value for the ''%2'' instance variable (automatically generated)\\'.
|
|
1334 |
].
|
|
1335 |
source := source
|
|
1336 |
, ' this.shouldImplement();\'
|
|
1337 |
, ' return null;\';
|
|
1338 |
, '}'.
|
|
1339 |
|
|
1340 |
source := (source bindWith:varType with:name) withCRs.
|
|
1341 |
self compile:source forClass:aClass theMetaclass inCategory:'defaults'.
|
|
1342 |
].
|
|
1343 |
].
|
|
1344 |
].
|
|
1345 |
|
|
1346 |
"/ the SETTER
|
|
1347 |
readersOnly ifFalse:[
|
|
1348 |
(aClass includesSelector:((methodName , ':') asSymbol)) ifFalse:[
|
|
1349 |
((methodName size > 2) and:[ (methodName startsWith:'is') and:[ (methodName at:3) isUppercase ]])
|
|
1350 |
ifTrue:[
|
|
1351 |
argName := 'aBoolean'
|
|
1352 |
].
|
|
1353 |
asValueHolder ifTrue:[
|
|
1354 |
source := methodName , '(%3) {\'. "/ argName
|
|
1355 |
generateComments ifTrue:[
|
|
1356 |
source := source , ' // set the ''%2'' value holder' , ' (automatically generated)\\'.
|
|
1357 |
].
|
|
1358 |
withChange ifTrue:[
|
|
1359 |
source := source
|
|
1360 |
, ' var oldValue, newValue;\\'
|
|
1361 |
, ' if (%2 !!= null) {\'
|
|
1362 |
, ' oldValue = %2.value;\'
|
|
1363 |
, ' %2.removeDependent(this);\'
|
|
1364 |
, ' }\'
|
|
1365 |
, ' %2 = %3;\' "/ argName
|
|
1366 |
, ' if (%2 !!= null) {\'
|
|
1367 |
, ' %2.addDependent(self);\'
|
|
1368 |
, ' }\'
|
|
1369 |
, ' newValue = %2.value;\'
|
|
1370 |
, ' if (oldValue !!== newValue) {\'
|
|
1371 |
, ' this.update_with_from("value".asSymbol(), newValue, %2);\'
|
|
1372 |
, ' }\'
|
|
1373 |
, '}'.
|
|
1374 |
] ifFalse:[
|
|
1375 |
source := source
|
|
1376 |
, ' %2 = %3;\' "/ argName
|
|
1377 |
, '}'.
|
|
1378 |
].
|
|
1379 |
] ifFalse:[
|
|
1380 |
source := methodName , '(%3) {\'. "/ argName
|
|
1381 |
withChange ifTrue:[
|
|
1382 |
generateComments ifTrue:[
|
|
1383 |
source := source , ' // set the value of the %1 variable ''%2''\'.
|
|
1384 |
source := source , ' // and send a change notification (automatically generated)\\'.
|
|
1385 |
].
|
|
1386 |
source := source
|
|
1387 |
, ' if (%2 !!== %3) {\'
|
|
1388 |
, ' %2 = %3;\' "/ argName
|
|
1389 |
, ' this.changed("%2".asSymbol);\'
|
|
1390 |
, ' };\'
|
|
1391 |
, '}'.
|
|
1392 |
] ifFalse:[
|
|
1393 |
generateCommentsForSetters ifTrue:[
|
|
1394 |
source := source , ' // set the value of the %1 variable ''%2''\'.
|
|
1395 |
source := source , ' // (automatically generated)"\\'.
|
|
1396 |
].
|
|
1397 |
source := source
|
|
1398 |
, ' %2 = %3;\' "/ argName
|
|
1399 |
, '}'.
|
|
1400 |
].
|
|
1401 |
].
|
|
1402 |
source := (source bindWith:varType with:name with:argName) withCRs.
|
|
1403 |
self
|
|
1404 |
compile:source
|
|
1405 |
forClass:aClass
|
|
1406 |
inCategory:(asValueHolder ifTrue:['aspects'] ifFalse:['accessing']).
|
|
1407 |
] ifTrue:[
|
|
1408 |
Transcript showCR:'method ''', methodName , ':'' already present'
|
|
1409 |
].
|
|
1410 |
].
|
|
1411 |
].
|
|
1412 |
|
|
1413 |
self executeCollectedChangesNamed:('Add Accessors').
|
544
|
1414 |
!
|
|
1415 |
|
|
1416 |
createCollectionAccessMethodsFor:aCollectionOfVarNames in:aClass withChange:withChange
|
|
1417 |
|classesClassVars|
|
|
1418 |
|
|
1419 |
self startCollectChanges.
|
|
1420 |
|
|
1421 |
classesClassVars := aClass theNonMetaclass allClassVarNames.
|
|
1422 |
|
|
1423 |
aCollectionOfVarNames do:[:name |
|
|
1424 |
|source varType methodNameBase methodName defaultMethodName|
|
|
1425 |
|
|
1426 |
varType := (classesClassVars includes:name)
|
|
1427 |
ifTrue:['static']
|
|
1428 |
ifFalse:[
|
|
1429 |
(aClass isMeta ifTrue:['classInstVar'] ifFalse:['instance'])].
|
|
1430 |
|
|
1431 |
methodNameBase := name asUppercaseFirst.
|
|
1432 |
(methodNameBase endsWith:'s') ifTrue:[
|
|
1433 |
methodNameBase := methodNameBase copyWithoutLast:1.
|
|
1434 |
].
|
|
1435 |
methodName := 'add' , methodNameBase, ':'.
|
|
1436 |
|
|
1437 |
"check, if method is not already present"
|
|
1438 |
(aClass includesSelector:(methodName asSymbol)) ifFalse:[
|
|
1439 |
source := methodName , 'a%1\'.
|
|
1440 |
generateComments ifTrue:[
|
|
1441 |
source := source , ' "add a ',methodNameBase,'"\\'.
|
|
1442 |
].
|
|
1443 |
source := source , ' %2 isNil ifTrue:[\'.
|
|
1444 |
source := source
|
|
1445 |
, ' %2 := OrderedCollection new.\'.
|
|
1446 |
source := source
|
|
1447 |
, ' ].\'
|
|
1448 |
, ' %2 add: a%1'.
|
|
1449 |
source := (source bindWith:methodNameBase with:name) withCRs.
|
|
1450 |
self compile:source forClass:aClass inCategory:#accessing.
|
|
1451 |
] ifTrue:[
|
|
1452 |
Transcript showCR:'method ''', methodName , ''' already present'
|
|
1453 |
].
|
|
1454 |
|
|
1455 |
methodName := 'remove' , methodNameBase, ':'.
|
|
1456 |
|
|
1457 |
"check, if method is not already present"
|
|
1458 |
(aClass includesSelector:(methodName asSymbol)) ifFalse:[
|
|
1459 |
source := methodName , 'a%1\'.
|
|
1460 |
generateComments ifTrue:[
|
|
1461 |
source := source , ' "remove a ',methodNameBase,'"\\'.
|
|
1462 |
].
|
|
1463 |
source := source
|
|
1464 |
, ' %2 remove: a%1'.
|
|
1465 |
source := (source bindWith:methodNameBase with:name) withCRs.
|
|
1466 |
self compile:source forClass:aClass inCategory:#accessing.
|
|
1467 |
] ifTrue:[
|
|
1468 |
Transcript showCR:'method ''', methodName , ''' already present'
|
|
1469 |
].
|
|
1470 |
].
|
|
1471 |
|
|
1472 |
self
|
|
1473 |
createAccessMethodsFor:aCollectionOfVarNames
|
|
1474 |
in:aClass
|
|
1475 |
withChange:withChange
|
|
1476 |
asValueHolder:false
|
|
1477 |
readersOnly:true
|
|
1478 |
writersOnly:false
|
|
1479 |
lazyInitialization:false.
|
|
1480 |
|
|
1481 |
self executeCollectedChangesNamed:('Add Collection Access').
|
|
1482 |
|
|
1483 |
"Created: / 04-02-2007 / 15:52:31 / cg"
|
|
1484 |
!
|
|
1485 |
|
|
1486 |
createValueHoldersFor:aCollectionOfVarNames in:aClass lazyInitialization:lazyInitialization
|
|
1487 |
"workhorse for creating access methods for instvars."
|
|
1488 |
|
|
1489 |
|nonMetaClass metaClass classesClassVars generateCommentsForSetters generateCommentsForGetters|
|
|
1490 |
|
|
1491 |
nonMetaClass := aClass theNonMetaclass.
|
|
1492 |
metaClass := aClass theMetaclass.
|
|
1493 |
|
|
1494 |
self startCollectChanges.
|
|
1495 |
|
|
1496 |
generateCommentsForSetters := userPreferences generateCommentsForSetters.
|
|
1497 |
generateCommentsForGetters := userPreferences generateCommentsForGetters.
|
|
1498 |
|
|
1499 |
classesClassVars := nonMetaClass allClassVarNames.
|
|
1500 |
|
|
1501 |
aCollectionOfVarNames do:[:name |
|
|
1502 |
|source varType methodName holderMethodName defaultMethodName|
|
|
1503 |
|
|
1504 |
holderMethodName := name.
|
|
1505 |
name isUppercaseFirst ifTrue:[
|
|
1506 |
holderMethodName := holderMethodName asLowercaseFirst.
|
|
1507 |
].
|
|
1508 |
(holderMethodName endsWith:'Holder') ifTrue:[
|
|
1509 |
methodName := holderMethodName copyWithoutLast:6.
|
|
1510 |
] ifFalse:[
|
|
1511 |
methodName := holderMethodName.
|
|
1512 |
holderMethodName := methodName , 'Holder'.
|
|
1513 |
].
|
|
1514 |
|
|
1515 |
methodName notNil ifTrue:[
|
|
1516 |
(metaClass includesSelector:(methodName asSymbol)) ifFalse:[
|
|
1517 |
source := '%1\'.
|
|
1518 |
generateComments ifTrue:[
|
|
1519 |
source := source , ' "return the value in ''%2''"\\'.
|
|
1520 |
].
|
|
1521 |
source := source , ' ^ self %2 value'.
|
|
1522 |
source := (source bindWith:methodName with:holderMethodName) withCRs.
|
|
1523 |
self compile:source forClass:nonMetaClass inCategory:#accessing.
|
|
1524 |
] ifTrue:[
|
|
1525 |
Transcript showCR:'method ''', methodName , ''' already present'
|
|
1526 |
].
|
|
1527 |
|
|
1528 |
(metaClass includesSelector:((methodName , ':') asSymbol)) ifFalse:[
|
|
1529 |
source := '%1: newValue\'.
|
|
1530 |
generateComments ifTrue:[
|
|
1531 |
source := source , ' "set the value in ''%2''"\\'.
|
|
1532 |
].
|
|
1533 |
source := source , ' self %2 value: newValue'.
|
|
1534 |
source := (source bindWith:methodName with:holderMethodName) withCRs.
|
|
1535 |
self compile:source forClass:nonMetaClass inCategory:#accessing.
|
|
1536 |
] ifTrue:[
|
|
1537 |
Transcript showCR:'method ''', methodName , ':'' already present'
|
|
1538 |
].
|
|
1539 |
].
|
|
1540 |
(metaClass includesSelector:(holderMethodName asSymbol)) ifFalse:[
|
|
1541 |
source := '%1\'.
|
|
1542 |
generateComments ifTrue:[
|
|
1543 |
source := source , ' "return/create the valueHolder ''%1''"\\'.
|
|
1544 |
].
|
|
1545 |
source := source , ' %1 isNil ifTrue:[\'.
|
|
1546 |
source := source , ' %1 := ValueHolder with:nil "defaultValue here".\'.
|
|
1547 |
source := source , ' ].\'.
|
|
1548 |
source := source , ' ^ %1\'.
|
|
1549 |
source := (source bindWith:holderMethodName) withCRs.
|
|
1550 |
self compile:source forClass:nonMetaClass inCategory:#accessing.
|
|
1551 |
] ifTrue:[
|
|
1552 |
Transcript showCR:'method ''', methodName , ''' already present'
|
|
1553 |
].
|
|
1554 |
].
|
|
1555 |
|
|
1556 |
self executeCollectedChangesNamed:('Add ValueHolder').
|
|
1557 |
! !
|
|
1558 |
|
|
1559 |
!JavaScriptCodeGeneratorTool methodsFor:'code generation-individual methods'!
|
|
1560 |
|
|
1561 |
createAcceptVisitorMethod:selector in:aClass
|
|
1562 |
"create an acceptVisitor: method
|
|
1563 |
(I'm tired of typing)"
|
|
1564 |
|
|
1565 |
self assert:( aClass isMeta not ).
|
|
1566 |
|
|
1567 |
(aClass includesSelector:#'acceptVisitor:') ifFalse:[
|
|
1568 |
self
|
|
1569 |
compile:
|
|
1570 |
(('acceptVisitor:aVisitor
|
|
1571 |
"Double dispatch back to the visitor, passing my type encoded in
|
|
1572 |
the selector (visitor pattern)"
|
|
1573 |
|
|
1574 |
"stub code automatically generated - please change if required"
|
|
1575 |
|
|
1576 |
^ aVisitor %1self
|
|
1577 |
') bindWith:selector)
|
|
1578 |
forClass:aClass
|
|
1579 |
inCategory:#visiting.
|
|
1580 |
]
|
|
1581 |
!
|
|
1582 |
|
|
1583 |
createAcceptVisitorMethodIn:aClass
|
|
1584 |
"create an acceptVisitor: method
|
|
1585 |
(I'm tired of typing)"
|
|
1586 |
|
|
1587 |
self
|
|
1588 |
createAcceptVisitorMethod:('visit' , aClass nameWithoutPrefix , ':') asSymbol
|
|
1589 |
in:aClass
|
|
1590 |
!
|
|
1591 |
|
|
1592 |
createCopyrightMethodFor:copyRightText for:aClass
|
|
1593 |
"add copyright method containing text,
|
|
1594 |
but only if not already present."
|
|
1595 |
|
|
1596 |
|txt|
|
|
1597 |
|
|
1598 |
(aClass includesSelector:#copyright) ifFalse:[
|
|
1599 |
copyRightText notNil ifTrue:[
|
|
1600 |
txt := copyRightText bindWith:(Date today year).
|
|
1601 |
self compile:
|
|
1602 |
'copyright
|
|
1603 |
"
|
|
1604 |
' , txt , '
|
|
1605 |
"
|
|
1606 |
' forClass:aClass
|
|
1607 |
inCategory:#documentation.
|
|
1608 |
]
|
|
1609 |
].
|
|
1610 |
!
|
|
1611 |
|
|
1612 |
createDocumentationMethodFor:aClass
|
|
1613 |
"add documentation method containing doc template
|
|
1614 |
but only if not already present."
|
|
1615 |
|
|
1616 |
|metaClass nonMetaClass userName loginName hostName emailAddress code existingComment|
|
|
1617 |
|
|
1618 |
metaClass := aClass theMetaclass.
|
|
1619 |
nonMetaClass := aClass theNonMetaclass.
|
|
1620 |
|
|
1621 |
(metaClass includesSelector:#documentation) ifFalse:[
|
|
1622 |
existingComment := nonMetaClass comment.
|
|
1623 |
existingComment isEmptyOrNil ifTrue:[
|
|
1624 |
(nonMetaClass isSubclassOf:HTTPService) ifTrue:[
|
|
1625 |
existingComment := ' [start Server with:]
|
|
1626 |
HTTPServer startServerOnPort:8080
|
|
1627 |
|
|
1628 |
[start with:]
|
|
1629 |
(self new)
|
|
1630 |
registerServiceOn:(HTTPServer runningServerOnPort:8080)'.
|
|
1631 |
].
|
|
1632 |
].
|
|
1633 |
|
|
1634 |
userName := OperatingSystem getFullUserName.
|
|
1635 |
loginName := OperatingSystem getLoginName.
|
|
1636 |
hostName := OperatingSystem getHostName.
|
|
1637 |
emailAddress := loginName , '@' , hostName.
|
|
1638 |
|
|
1639 |
|
|
1640 |
|
|
1641 |
"/ ugly; should ask the class for that
|
|
1642 |
metaClass isJavaScriptMetaclass ifTrue:[
|
|
1643 |
code :=
|
|
1644 |
'function documentation() {
|
|
1645 |
/*
|
|
1646 |
' , (existingComment ? ' documentation to be added.') , '
|
|
1647 |
|
|
1648 |
[author:]
|
|
1649 |
' ", userName
|
|
1650 |
, ' (' , emailAddress , ')' "
|
|
1651 |
, UserPreferences current historyManagerSignature , '
|
|
1652 |
|
|
1653 |
[instance variables:]
|
|
1654 |
|
|
1655 |
[class variables:]
|
|
1656 |
|
|
1657 |
[see also:]
|
|
1658 |
|
|
1659 |
*/
|
|
1660 |
}
|
|
1661 |
'
|
|
1662 |
] ifFalse:[
|
|
1663 |
code:=
|
|
1664 |
'documentation
|
|
1665 |
"
|
|
1666 |
' , (existingComment ? ' documentation to be added.') , '
|
|
1667 |
|
|
1668 |
[author:]
|
|
1669 |
' ", userName
|
|
1670 |
, ' (' , emailAddress , ')' "
|
|
1671 |
, UserPreferences current historyManagerSignature , '
|
|
1672 |
|
|
1673 |
[instance variables:]
|
|
1674 |
|
|
1675 |
[class variables:]
|
|
1676 |
|
|
1677 |
[see also:]
|
|
1678 |
|
|
1679 |
"
|
|
1680 |
'
|
|
1681 |
].
|
|
1682 |
|
|
1683 |
self
|
|
1684 |
compile:code
|
|
1685 |
forClass:metaClass
|
|
1686 |
inCategory:#documentation.
|
|
1687 |
].
|
|
1688 |
|
|
1689 |
"Modified: / 24-11-2006 / 15:54:27 / cg"
|
|
1690 |
"Modified: / 04-02-2011 / 08:24:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
1691 |
!
|
|
1692 |
|
|
1693 |
createExamplesMethodFor:aClass
|
|
1694 |
"add examples method containing examples template
|
|
1695 |
but only if not already present."
|
|
1696 |
|
|
1697 |
|nonMetaclass fragment|
|
|
1698 |
|
|
1699 |
nonMetaclass := aClass theNonMetaclass.
|
|
1700 |
|
|
1701 |
(nonMetaclass isSubclassOf:View) ifTrue:[
|
|
1702 |
self createExamplesMethodForViewClass:aClass.
|
|
1703 |
^ self
|
|
1704 |
].
|
|
1705 |
|
|
1706 |
(nonMetaclass isSubclassOf:ApplicationModel) ifFalse:[
|
|
1707 |
^ self
|
|
1708 |
].
|
|
1709 |
|
|
1710 |
(aClass includesSelector:#examples) ifFalse:[
|
|
1711 |
(nonMetaclass isSubclassOf:ApplicationModel) ifTrue:[
|
|
1712 |
fragment := ' Starting the application:
|
|
1713 |
[exBegin]
|
|
1714 |
' , nonMetaclass name , ' open
|
|
1715 |
|
|
1716 |
[exEnd]
|
|
1717 |
'
|
|
1718 |
] ifFalse:[
|
|
1719 |
fragment := ''
|
|
1720 |
].
|
|
1721 |
|
|
1722 |
self
|
|
1723 |
compile:
|
|
1724 |
'examples
|
|
1725 |
"
|
|
1726 |
' , fragment , '
|
|
1727 |
more examples to be added:
|
|
1728 |
[exBegin]
|
|
1729 |
... add code fragment for
|
|
1730 |
... executable example here ...
|
|
1731 |
[exEnd]
|
|
1732 |
"
|
|
1733 |
'
|
|
1734 |
forClass:aClass
|
|
1735 |
inCategory:#documentation.
|
|
1736 |
].
|
|
1737 |
!
|
|
1738 |
|
|
1739 |
createImageSpecMethodFor:anImage comment:comment in:aClass selector:sel
|
|
1740 |
|imageStoreStream mthd imageKey category|
|
|
1741 |
|
|
1742 |
anImage storeOn: (imageStoreStream := WriteStream on: '').
|
|
1743 |
|
|
1744 |
"/ if that method already exists, do not overwrite the category
|
|
1745 |
category := #'image specs'.
|
|
1746 |
(mthd := aClass compiledMethodAt:sel) notNil ifTrue:[
|
|
1747 |
category := mthd category.
|
|
1748 |
].
|
|
1749 |
|
|
1750 |
imageKey := aClass theNonMetaclass name, ' ', sel.
|
|
1751 |
Icon constantNamed: imageKey put:nil.
|
|
1752 |
self
|
|
1753 |
compile: ((sel,
|
|
1754 |
'\', comment,
|
|
1755 |
'\\' ,
|
|
1756 |
' "\',
|
|
1757 |
' self ' , sel , ' inspect\',
|
|
1758 |
' ImageEditor openOnClass:self andSelector:#', sel, '\',
|
|
1759 |
' Icon flushCachedIcons',
|
|
1760 |
'\ "',
|
|
1761 |
'\\',
|
|
1762 |
' <resource: #image>',
|
|
1763 |
'\\',
|
|
1764 |
' ^Icon\') withCRs,
|
|
1765 |
' constantNamed:''', imageKey, '''\' withCRs,
|
|
1766 |
' ifAbsentPut:[', imageStoreStream contents, ']')
|
|
1767 |
forClass:aClass
|
|
1768 |
inCategory: category.
|
|
1769 |
|
|
1770 |
"Modified: / 01-07-2011 / 12:31:12 / cg"
|
|
1771 |
!
|
|
1772 |
|
|
1773 |
createInitialHistoryMethodFor:aClass
|
|
1774 |
"add history method containing created-entry
|
|
1775 |
but only if not already present."
|
|
1776 |
|
|
1777 |
|code|
|
|
1778 |
|
|
1779 |
(aClass includesSelector:#history) ifFalse:[
|
|
1780 |
HistoryManager notNil ifTrue:[
|
|
1781 |
code := HistoryManager codeForInitialHistoryMethodIn:aClass.
|
|
1782 |
self
|
|
1783 |
compile:code
|
|
1784 |
forClass:aClass
|
|
1785 |
inCategory:#documentation.
|
|
1786 |
].
|
|
1787 |
].
|
|
1788 |
!
|
|
1789 |
|
|
1790 |
createInstanceCreationMethodWithSetupFor:selector category:category in:aMetaClass
|
|
1791 |
"add an inst-creation method"
|
|
1792 |
|
|
1793 |
|template instMthd argNames|
|
|
1794 |
|
|
1795 |
(aMetaClass includesSelector:selector) ifFalse:[
|
|
1796 |
instMthd := aMetaClass theNonMetaclass compiledMethodAt:selector.
|
|
1797 |
(instMthd notNil
|
|
1798 |
and:[ (argNames := instMthd methodArgNames) notEmptyOrNil ])
|
|
1799 |
ifTrue:[
|
|
1800 |
template := Parser methodSpecificationForSelector:selector argNames:argNames.
|
|
1801 |
] ifFalse:[
|
|
1802 |
template := Parser methodSpecificationForSelector:selector.
|
|
1803 |
].
|
|
1804 |
|
|
1805 |
self
|
|
1806 |
compile:
|
|
1807 |
template , '
|
|
1808 |
^ self new ' , template , '
|
|
1809 |
'
|
|
1810 |
forClass:aMetaClass
|
|
1811 |
inCategory:category.
|
|
1812 |
].
|
|
1813 |
!
|
|
1814 |
|
|
1815 |
createMultiSetterMethodFor:aCollectionOfVarNames in:aClass
|
|
1816 |
"create a multi-setter method for instvars."
|
|
1817 |
|
|
1818 |
|source|
|
|
1819 |
|
|
1820 |
source := ''.
|
|
1821 |
aCollectionOfVarNames do:[:eachVar |
|
|
1822 |
source := source , (eachVar , ':' , eachVar , 'Arg ').
|
|
1823 |
].
|
|
1824 |
source := source , Character cr.
|
|
1825 |
(userPreferences generateCommentsForSetters) ifTrue:[
|
|
1826 |
source := source , (' "set instance variables"' , Character cr , Character cr).
|
|
1827 |
].
|
|
1828 |
aCollectionOfVarNames do:[:eachVar |
|
|
1829 |
source := source , (' ' , eachVar , ' := ' , eachVar , 'Arg.' , Character cr).
|
|
1830 |
].
|
|
1831 |
self compile:source forClass:aClass inCategory:#accessing.
|
|
1832 |
!
|
|
1833 |
|
|
1834 |
createSubclassResponsibilityMethodFor:aSelector category:cat in:aClass
|
|
1835 |
"add a subclassResponsibility method;
|
|
1836 |
but only if not already present."
|
|
1837 |
|
|
1838 |
(aClass includesSelector:aSelector) ifFalse:[
|
|
1839 |
|
|
1840 |
self compile:
|
|
1841 |
(Method methodDefinitionTemplateForSelector:aSelector) ,
|
|
1842 |
'
|
|
1843 |
"raise an error: must be redefined in concrete subclass(es)"
|
|
1844 |
|
|
1845 |
^ self subclassResponsibility
|
|
1846 |
'
|
|
1847 |
forClass:aClass
|
|
1848 |
inCategory:cat.
|
|
1849 |
].
|
|
1850 |
!
|
|
1851 |
|
|
1852 |
createUpdateMethodIn:aClass
|
|
1853 |
"create an update:with:from:-method
|
|
1854 |
(I'm tired of typing)"
|
|
1855 |
|
|
1856 |
|code|
|
|
1857 |
|
|
1858 |
(aClass includesSelector:#update:with:from:) ifFalse:[
|
|
1859 |
generateComments ifFalse:[
|
|
1860 |
code :=
|
|
1861 |
'update:something with:aParameter from:changedObject
|
|
1862 |
super update:something with:aParameter from:changedObject
|
|
1863 |
'
|
|
1864 |
] ifTrue:[
|
|
1865 |
code :=
|
|
1866 |
'update:something with:aParameter from:changedObject
|
|
1867 |
"Invoked when an object that I depend upon sends a change notification."
|
|
1868 |
|
|
1869 |
"stub code automatically generated - please change as required"
|
|
1870 |
|
|
1871 |
"/ changedObject == someOfMyValueHolders ifTrue:[
|
|
1872 |
"/ self doSomethingApropriate.
|
|
1873 |
"/ ^ self.
|
|
1874 |
"/ ].
|
|
1875 |
super update:something with:aParameter from:changedObject
|
|
1876 |
'
|
|
1877 |
].
|
|
1878 |
|
|
1879 |
self
|
|
1880 |
compile:code
|
|
1881 |
forClass:aClass
|
|
1882 |
inCategory:#'change & update'.
|
|
1883 |
]
|
|
1884 |
!
|
|
1885 |
|
|
1886 |
createVersionMethodFor:aClass
|
|
1887 |
<resource: #obsolete>
|
|
1888 |
"add a version method containing RCS template
|
|
1889 |
but only if not already present and it's not a private class."
|
|
1890 |
|
|
1891 |
|code|
|
|
1892 |
|
|
1893 |
self obsoleteMethodWarning.
|
|
1894 |
|
|
1895 |
aClass isPrivate ifFalse:[
|
|
1896 |
(aClass includesSelector:#version) ifFalse:[
|
|
1897 |
code := aClass programmingLanguage versionMethodTemplateForCVS.
|
|
1898 |
self
|
|
1899 |
compile:code
|
|
1900 |
forClass:aClass
|
|
1901 |
inCategory:#documentation.
|
|
1902 |
]
|
|
1903 |
].
|
|
1904 |
|
|
1905 |
"Modified (comment): / 21-08-2012 / 11:54:57 / cg"
|
|
1906 |
! !
|
|
1907 |
|
|
1908 |
!JavaScriptCodeGeneratorTool methodsFor:'code templates'!
|
|
1909 |
|
|
1910 |
anyApplicationClassInProjectOf:aClass
|
|
1911 |
|prjDefinition|
|
|
1912 |
|
|
1913 |
prjDefinition := aClass projectDefinitionClass.
|
|
1914 |
prjDefinition isNil ifTrue:[ ^ nil ].
|
|
1915 |
^ (prjDefinition allClasses
|
|
1916 |
select:[:cls | cls isSubclassOf:ApplicationModel])
|
|
1917 |
firstIfEmpty:nil.
|
|
1918 |
|
|
1919 |
"Created: / 21-01-2012 / 13:24:12 / cg"
|
|
1920 |
!
|
|
1921 |
|
|
1922 |
codeFor_classInitialize
|
|
1923 |
generateComments ifFalse:[
|
|
1924 |
^
|
|
1925 |
'function initialize() {
|
|
1926 |
%(INIT_CLASSINSTVARS)
|
|
1927 |
%(INIT_CLASSVARS)
|
|
1928 |
}
|
|
1929 |
'.
|
|
1930 |
].
|
|
1931 |
|
|
1932 |
^
|
|
1933 |
'function initialize() {
|
|
1934 |
// Invoked at system start or when the class is dynamically loaded.
|
|
1935 |
|
|
1936 |
// please change as required (and remove this comment)
|
|
1937 |
%(INIT_CLASSINSTVARS)
|
|
1938 |
%(INIT_CLASSVARS)
|
|
1939 |
}
|
|
1940 |
'.
|
|
1941 |
!
|
|
1942 |
|
|
1943 |
codeFor_closeAccept
|
|
1944 |
generateComments ifFalse:[
|
|
1945 |
^
|
|
1946 |
'function closeAccept() {
|
|
1947 |
return super.closeAccept();
|
|
1948 |
}
|
|
1949 |
'.
|
|
1950 |
].
|
|
1951 |
|
|
1952 |
^
|
|
1953 |
'function closeAccept() {
|
|
1954 |
// This is a hook method generated by the Browser/CodeGeneratorTool.
|
|
1955 |
// It will be invoked when your dialog-window is closed with OK."
|
|
1956 |
|
|
1957 |
// add any actions as required here ...
|
|
1958 |
Transcript.showCR("dialog accepted");
|
|
1959 |
|
|
1960 |
// do not remove the one below (otherwise, the dialog will not close itself)...
|
|
1961 |
return super.closeAccept();
|
|
1962 |
}
|
|
1963 |
'.
|
|
1964 |
|
|
1965 |
"Created: / 27-10-2006 / 10:03:31 / cg"
|
|
1966 |
!
|
|
1967 |
|
|
1968 |
codeFor_closeDownViews
|
|
1969 |
generateComments ifFalse:[
|
|
1970 |
^
|
|
1971 |
'function closeDownViews() {
|
|
1972 |
^ super closeDownViews
|
|
1973 |
}
|
|
1974 |
'.
|
|
1975 |
].
|
|
1976 |
|
|
1977 |
^
|
|
1978 |
'function closeDownViews() {
|
|
1979 |
"This is a hook method generated by the Browser/CodeGeneratorTool.
|
|
1980 |
It will be invoked when your app/dialog-window is really closed.
|
|
1981 |
See also #closeDownViews, which is invoked before and may suppress the close
|
|
1982 |
or ask the user for confirmation."
|
|
1983 |
|
|
1984 |
"/ change the code below as required ...
|
|
1985 |
"/ This should cleanup any leftover resources
|
|
1986 |
"/ (for example, temporary files)
|
|
1987 |
"/ super closeRequest will initiate the closeDown
|
|
1988 |
|
|
1989 |
"/ add your code here
|
|
1990 |
|
|
1991 |
"/ do not remove the one below ...
|
|
1992 |
^ super closeDownViews
|
|
1993 |
}
|
|
1994 |
'.
|
|
1995 |
|
|
1996 |
"Created: / 27-10-2006 / 10:01:32 / cg"
|
|
1997 |
!
|
|
1998 |
|
|
1999 |
codeFor_closeRequest
|
|
2000 |
generateComments ifFalse:[
|
|
2001 |
^
|
|
2002 |
'closeRequest
|
|
2003 |
self hasUnsavedChanges ifTrue:[
|
|
2004 |
(self confirm:(resources string:''Close without saving ?'')) ifFalse:[
|
|
2005 |
^ self
|
|
2006 |
]
|
|
2007 |
].
|
|
2008 |
^ super closeRequest
|
|
2009 |
'.
|
|
2010 |
].
|
|
2011 |
|
|
2012 |
^
|
|
2013 |
'closeRequest
|
|
2014 |
"This is a hook method generated by the Browser/CodeGeneratorTool.
|
|
2015 |
It will be invoked when your app/dialog-window is about to be
|
|
2016 |
closed (this method has a chance to suppress the close).
|
|
2017 |
See also #closeDownViews, which is invoked when the close is really done."
|
|
2018 |
|
|
2019 |
"/ change the code below as required ...
|
|
2020 |
"/ Closing can be suppressed, by simply returning.
|
|
2021 |
"/ The ''super closeRequest'' at the end will initiate the real closeDown
|
|
2022 |
|
|
2023 |
self hasUnsavedChanges ifTrue:[
|
|
2024 |
(self confirm:(resources string:''Close without saving ?'')) ifFalse:[
|
|
2025 |
^ self
|
|
2026 |
]
|
|
2027 |
].
|
|
2028 |
|
|
2029 |
^ super closeRequest
|
|
2030 |
'.
|
|
2031 |
|
|
2032 |
"Created: / 27-10-2006 / 10:01:06 / cg"
|
|
2033 |
!
|
|
2034 |
|
|
2035 |
codeFor_emptyMenuActionCodeFor:selector menuItem:item
|
|
2036 |
generateComments ifFalse:[
|
|
2037 |
^
|
|
2038 |
selector,'
|
|
2039 |
self warn:''no action for ''''',item,''''' defined.''.
|
|
2040 |
'.
|
|
2041 |
].
|
|
2042 |
|
|
2043 |
^
|
|
2044 |
selector,'
|
|
2045 |
"This method was generated by the Browser/CodeGeneratorTool.
|
|
2046 |
It will be invoked when the menu-item ''',item,''' is selected."
|
|
2047 |
|
|
2048 |
"/ change below and add any actions as required here ...
|
|
2049 |
self warn:''no action for ''''',item,''''' defined.''.
|
|
2050 |
'.
|
|
2051 |
|
|
2052 |
"Created: / 27-10-2006 / 10:16:43 / cg"
|
|
2053 |
!
|
|
2054 |
|
|
2055 |
codeFor_hasUnsavedChanges
|
|
2056 |
generateComments ifFalse:[
|
|
2057 |
^
|
|
2058 |
'hasUnsavedChanges
|
|
2059 |
^ false.
|
|
2060 |
'.
|
|
2061 |
].
|
|
2062 |
|
|
2063 |
^
|
|
2064 |
'hasUnsavedChanges
|
|
2065 |
"Return true, if any unsaved changes are present
|
|
2066 |
(i.e. the contents needs to be saved or else will be lost)"
|
|
2067 |
|
|
2068 |
"/ add real code as required (or remove the halt and always return false)...
|
|
2069 |
"/ self halt:''check this code''.
|
|
2070 |
^ false.
|
|
2071 |
'.
|
|
2072 |
|
|
2073 |
"Created: / 27-10-2006 / 10:00:36 / cg"
|
|
2074 |
!
|
|
2075 |
|
|
2076 |
codeFor_menuSaveAs
|
|
2077 |
^
|
|
2078 |
'menuSaveAs
|
|
2079 |
"This method was generated by the Browser/CodeGeneratorTool.
|
|
2080 |
It will be invoked when the menu-item ''saveAs'' is selected."
|
|
2081 |
|
|
2082 |
"/ change below as required... (see examples in Dialog class for more options)
|
|
2083 |
Dialog
|
|
2084 |
requestSaveFileName:(resources string:''Save'')
|
|
2085 |
default:''foo.txt''
|
|
2086 |
fromDirectory:nil
|
|
2087 |
action:[:fileName | self doSaveAs:fileName]
|
|
2088 |
appendAction:nil.
|
|
2089 |
'.
|
|
2090 |
|
|
2091 |
"Created: / 27-10-2006 / 10:01:57 / cg"
|
|
2092 |
!
|
|
2093 |
|
|
2094 |
codeFor_openAboutThisApplication
|
|
2095 |
^
|
|
2096 |
'openAboutThisApplication
|
|
2097 |
"This method was generated by the Browser/CodeGeneratorTool.
|
|
2098 |
It will be invoked when the menu-item ''help-about'' is selected."
|
|
2099 |
|
|
2100 |
"/ could open a customized aboutBox here ...
|
|
2101 |
super openAboutThisApplication
|
|
2102 |
'.
|
|
2103 |
|
|
2104 |
"Created: / 27-10-2006 / 10:03:13 / cg"
|
|
2105 |
!
|
|
2106 |
|
|
2107 |
codeFor_openDocumentation
|
|
2108 |
^
|
|
2109 |
'openDocumentation
|
|
2110 |
"This method was generated by the Browser/CodeGeneratorTool.
|
|
2111 |
It will be invoked when the menu-item ''help-documentation'' is selected."
|
|
2112 |
|
|
2113 |
"/ change below as required ...
|
|
2114 |
|
|
2115 |
"/ to open an HTML viewer on some document (under ''doc/online/<language>/'' ):
|
|
2116 |
self openDocumentationFile:''TOP.html''.
|
|
2117 |
|
|
2118 |
"/ add application-specific help files under the ''doc/online/<language>/help/appName''
|
|
2119 |
"/ directory, and open a viewer with:
|
|
2120 |
"/ self openDocumentationFile:''help/<MyApplication>/TOP.html''.
|
|
2121 |
'.
|
|
2122 |
|
|
2123 |
"Created: / 27-10-2006 / 10:02:55 / cg"
|
|
2124 |
!
|
|
2125 |
|
|
2126 |
codeFor_postBuildWith
|
|
2127 |
generateComments ifFalse:[
|
|
2128 |
^
|
|
2129 |
'postBuildWith:aBuilder
|
|
2130 |
^ super postBuildWith:aBuilder
|
|
2131 |
'.
|
|
2132 |
].
|
|
2133 |
|
|
2134 |
^
|
|
2135 |
'postBuildWith:aBuilder
|
|
2136 |
"This is a hook method generated by the Browser/CodeGeneratorTool.
|
|
2137 |
It will be invoked during the initialization of your app/dialog,
|
|
2138 |
after all of the visual components have been built,
|
|
2139 |
but BEFORE the top window is made visible.
|
|
2140 |
Add any app-specific actions here (reading files, setting up values etc.)
|
|
2141 |
See also #postOpenWith:, which is invoked after opening."
|
|
2142 |
|
|
2143 |
"/ add any code here ...
|
|
2144 |
|
|
2145 |
^ super postBuildWith:aBuilder
|
|
2146 |
'.
|
|
2147 |
|
|
2148 |
"Created: / 27-10-2006 / 09:59:33 / cg"
|
|
2149 |
!
|
|
2150 |
|
|
2151 |
codeFor_postOpenWith
|
|
2152 |
generateComments ifFalse:[
|
|
2153 |
^
|
|
2154 |
'postOpenWith:aBuilder
|
|
2155 |
^ super postOpenWith:aBuilder
|
|
2156 |
'.
|
|
2157 |
].
|
|
2158 |
|
|
2159 |
^
|
|
2160 |
'postOpenWith:aBuilder
|
|
2161 |
"This is a hook method generated by the Browser/CodeGeneratorTool.
|
|
2162 |
It will be invoked right after the applications window has been opened.
|
|
2163 |
Add any app-specific actions here (starting background processes etc.).
|
|
2164 |
See also #postBuildWith:, which is invoked before opening."
|
|
2165 |
|
|
2166 |
"/ add any code here ...
|
|
2167 |
|
|
2168 |
^ super postOpenWith:aBuilder
|
|
2169 |
'.
|
|
2170 |
|
|
2171 |
"Created: / 27-10-2006 / 09:59:56 / cg"
|
|
2172 |
!
|
|
2173 |
|
|
2174 |
codeFor_standAloneApplicationRegistryPathFor:aClassOrNil
|
|
2175 |
|pkg appClass|
|
|
2176 |
|
|
2177 |
pkg := 'someUniqueName'.
|
|
2178 |
aClassOrNil notNil ifTrue:[
|
|
2179 |
(appClass := self anyApplicationClassInProjectOf:aClassOrNil) notNil ifTrue:[
|
|
2180 |
pkg := appClass nameWithoutPrefix.
|
|
2181 |
]
|
|
2182 |
].
|
|
2183 |
|
|
2184 |
generateComments ifFalse:[
|
|
2185 |
^
|
|
2186 |
'applicationRegistryPath
|
|
2187 |
^ #(''stx'' ''%1'')
|
|
2188 |
' bindWith:pkg.
|
|
2189 |
].
|
|
2190 |
|
|
2191 |
^
|
|
2192 |
'applicationRegistryPath
|
|
2193 |
"the key under which this application stores its process ID in the registry
|
|
2194 |
as a collection of path-components.
|
|
2195 |
i.e. if #(''foo'' ''bar'' ''baz'') is returned here, the current applications ID will be stored
|
|
2196 |
in HKEY_CURRENT_USER\Software\foo\bar\baz\CurrentID.
|
|
2197 |
(would also be used as a relative path for a temporary lock file under unix).
|
|
2198 |
Used to detect if another instance of this application is already running."
|
|
2199 |
|
|
2200 |
^ #(''stx'' ''%1'')
|
|
2201 |
' bindWith:pkg.
|
|
2202 |
|
|
2203 |
"Created: / 21-01-2012 / 11:23:40 / cg"
|
|
2204 |
!
|
|
2205 |
|
|
2206 |
codeFor_standAloneApplicationUUID
|
|
2207 |
generateComments ifFalse:[
|
|
2208 |
^
|
|
2209 |
'applicationUUID
|
|
2210 |
^ UUID fromString:''', UUID genUUID printString, '''
|
|
2211 |
'.
|
|
2212 |
].
|
|
2213 |
|
|
2214 |
^
|
|
2215 |
'applicationUUID
|
|
2216 |
"answer an application-specific unique uuid.
|
|
2217 |
This is used as the name of some exclusive OS-resource, which is used to find out,
|
|
2218 |
if another instance of this application is already running.
|
|
2219 |
Under win32, a mutex is used; under unix, an exclusive file in the tempDir could be used.
|
|
2220 |
If redefined, please return a real UUID (i.e. UUID fromString:''.....'') and not a string or
|
|
2221 |
similar possibly conflicting identifier.
|
|
2222 |
You can paste a fresh worldwide unique id via the editor''s more-misc-paste UUID menuFunction."
|
|
2223 |
|
|
2224 |
^ UUID fromString:''', UUID genUUID printString, '''
|
|
2225 |
'.
|
|
2226 |
|
|
2227 |
"Created: / 19-08-2011 / 02:13:19 / cg"
|
|
2228 |
!
|
|
2229 |
|
|
2230 |
codeFor_standAloneMain
|
|
2231 |
^
|
|
2232 |
'main:argv
|
|
2233 |
"main entry; argv is the array of command arguments (as array of words from space-separated command line).
|
|
2234 |
Parse arguments, and proceed to the real work function"
|
|
2235 |
|
|
2236 |
"you may want to put those into instvars, in order to be accessable from the doRealWork function"
|
|
2237 |
|aArgs bArgs cOption fileArgs helpOption|
|
|
2238 |
|
|
2239 |
aArgs := OrderedCollection new.
|
|
2240 |
bArgs := OrderedCollection new.
|
|
2241 |
fileArgs := OrderedCollection new.
|
|
2242 |
cOption := helpOption := false.
|
|
2243 |
|
|
2244 |
(GetOpt new)
|
|
2245 |
at:$a
|
|
2246 |
put:[:opt :arg | aArgs add:arg];
|
|
2247 |
at:$b
|
|
2248 |
put:[:opt :arg | bArgs add:arg];
|
|
2249 |
at:$b
|
|
2250 |
put:[:opt | cOption := true];
|
|
2251 |
at:$h
|
|
2252 |
put:[:opt | helpOption := true];
|
|
2253 |
at:$?
|
|
2254 |
put:[:arg | self usage. Smalltalk exit:0];
|
|
2255 |
default:[:arg | fileArgs add:arg];
|
|
2256 |
parse:argv.
|
|
2257 |
|
|
2258 |
helpOption ifTrue:[
|
|
2259 |
self usage.
|
|
2260 |
] ifFalse:[
|
|
2261 |
self realMain:argv.
|
|
2262 |
].
|
|
2263 |
"/ do not exit here; caller will go into event loop when returning
|
|
2264 |
'.
|
|
2265 |
|
|
2266 |
"Created: / 19-08-2011 / 02:18:49 / cg"
|
|
2267 |
!
|
|
2268 |
|
|
2269 |
codeFor_standAloneRealMainMethodFor:aClass
|
|
2270 |
|appClass|
|
|
2271 |
|
|
2272 |
(appClass := self anyApplicationClassInProjectOf:aClass) notNil ifTrue:[
|
|
2273 |
^
|
|
2274 |
'realMain:args
|
|
2275 |
"opens the application"
|
|
2276 |
|
|
2277 |
%1 open
|
|
2278 |
' bindWith:appClass name
|
|
2279 |
|
|
2280 |
].
|
|
2281 |
|
|
2282 |
^
|
|
2283 |
'realMain:argsToEcho
|
|
2284 |
"just a dummy example - does nothing but echo its arguments"
|
|
2285 |
|
|
2286 |
Stdout nextPutLine:''Hello World''.
|
|
2287 |
Stdout nextPutLine:(argsToEcho asStringWith:Character space)
|
|
2288 |
'.
|
|
2289 |
|
|
2290 |
"Created: / 21-01-2012 / 12:28:48 / cg"
|
|
2291 |
!
|
|
2292 |
|
|
2293 |
codeFor_standAloneUsage
|
|
2294 |
^
|
|
2295 |
'usage
|
|
2296 |
Stderr nextPutLine:''usage: '',self applicationName,'' [options...]''.
|
|
2297 |
Stderr nextPutLine:'' -h .................. output this message''.
|
|
2298 |
'.
|
|
2299 |
|
|
2300 |
"Created: / 19-08-2011 / 02:22:46 / cg"
|
|
2301 |
!
|
|
2302 |
|
|
2303 |
code_forWidget_buttonPress
|
|
2304 |
generateComments ifFalse:[
|
|
2305 |
^
|
|
2306 |
'buttonPress:button x:x y:y
|
|
2307 |
Transcript show:''button: ''; showCR:button.
|
|
2308 |
super buttonPress:button x:x y:y
|
|
2309 |
'
|
|
2310 |
].
|
|
2311 |
|
|
2312 |
^
|
|
2313 |
'buttonPress:button x:x y:y
|
|
2314 |
"called when a mouse-button is pressed. button is the button-nr (1 for left-button).
|
|
2315 |
x/y are the mouse position at the time of the click.
|
|
2316 |
There are also corresponding buttonRelease and buttonMotion methods which could be
|
|
2317 |
redefined...."
|
|
2318 |
|
|
2319 |
Transcript show:''button: ''; showCR:button.
|
|
2320 |
"/ super-code handles middleButtonMenu, if it was assigned (with middleButtonmenu:)
|
|
2321 |
super buttonPress:button x:x y:y
|
|
2322 |
'
|
|
2323 |
!
|
|
2324 |
|
|
2325 |
code_forWidget_initialize
|
|
2326 |
^
|
|
2327 |
'initialize
|
|
2328 |
super initialize "/ to initialize inherited state
|
|
2329 |
|
|
2330 |
"/ add code to initialize private variables,
|
|
2331 |
"/ and sub-components as required.
|
|
2332 |
'
|
|
2333 |
!
|
|
2334 |
|
|
2335 |
code_forWidget_keyPress
|
|
2336 |
generateComments ifFalse:[
|
|
2337 |
^
|
|
2338 |
'keyPress:key x:x y:y
|
|
2339 |
"/ key == #Copy ifTrue:[
|
|
2340 |
"/ ].
|
|
2341 |
"/ key == #Cut ifTrue:[
|
|
2342 |
"/ ].
|
|
2343 |
Transcript show:''key: ''; showCR:key.
|
|
2344 |
super keyPress:key x:x y:y
|
|
2345 |
'
|
|
2346 |
].
|
|
2347 |
^
|
|
2348 |
'keyPress:key x:x y:y
|
|
2349 |
"called when a keyboard-key was pressed. key is either a character (for ordinary keys)
|
|
2350 |
or a symbol, such as #Copy, #Cut or #Paste.
|
|
2351 |
x/y are the mouse position at the time of the key-press.
|
|
2352 |
There is also a corresponding keyRelease method which could be redefined...."
|
|
2353 |
|
|
2354 |
Transcript show:''key: ''; showCR:key.
|
|
2355 |
super keyPress:key x:x y:y
|
|
2356 |
'
|
|
2357 |
!
|
|
2358 |
|
|
2359 |
code_forWidget_redraw
|
|
2360 |
|sel comment code|
|
|
2361 |
|
|
2362 |
sel := 'redrawX:x y:y width:w height:h'.
|
|
2363 |
generateComments ifFalse:[
|
|
2364 |
comment := ''.
|
|
2365 |
] ifTrue:[
|
|
2366 |
comment := '
|
|
2367 |
"called to redraw a part of the widgets area. x/y define the origin, w/h the size of
|
|
2368 |
that area. The clipping region has already been set by the caller, so even if the code
|
|
2369 |
below draws outside the redraw-area, it will not affect what is on the screen.
|
|
2370 |
Therefore, the example below can fill the rectangle in the redraw area, but still draw
|
|
2371 |
the cross in the outside regions."
|
|
2372 |
|
|
2373 |
'.
|
|
2374 |
].
|
|
2375 |
|
|
2376 |
code := '
|
|
2377 |
self paint:Color red.
|
|
2378 |
self fillRectangleX:x y:y width:w height:h.
|
|
2379 |
|
|
2380 |
self paint:Color yellow.
|
|
2381 |
self displayLineFrom:0@0 to:(width@height).
|
|
2382 |
self displayLineFrom:width@0 to:(0@height).
|
|
2383 |
'.
|
|
2384 |
|
|
2385 |
^ sel,comment,code
|
|
2386 |
!
|
|
2387 |
|
|
2388 |
code_forWidget_sizeChanged
|
|
2389 |
generateComments ifFalse:[
|
|
2390 |
^
|
|
2391 |
'sizeChanged:how
|
|
2392 |
self invalidate.
|
|
2393 |
super sizeChanged:how.
|
|
2394 |
'
|
|
2395 |
].
|
|
2396 |
|
|
2397 |
^
|
|
2398 |
'sizeChanged:how
|
|
2399 |
"Invoked whenever the size of the view changes.
|
|
2400 |
Here, we force a full redraw, which might not be needed all the time"
|
|
2401 |
|
|
2402 |
self invalidate.
|
|
2403 |
super sizeChanged:how.
|
|
2404 |
'
|
|
2405 |
!
|
|
2406 |
|
|
2407 |
code_forWidget_update
|
|
2408 |
generateComments ifFalse:[
|
|
2409 |
^
|
|
2410 |
'update:something with:aParameter from:changedObject
|
|
2411 |
changedObject == model ifTrue:[
|
|
2412 |
self invalidate.
|
|
2413 |
^ self
|
|
2414 |
].
|
|
2415 |
super update:something with:aParameter from:changedObject
|
|
2416 |
'
|
|
2417 |
].
|
|
2418 |
|
|
2419 |
^
|
|
2420 |
'update:something with:aParameter from:changedObject
|
|
2421 |
"Invoked when an object that I depend upon sends a change notification."
|
|
2422 |
|
|
2423 |
"stub code automatically generated - please change as required"
|
|
2424 |
|
|
2425 |
changedObject == model ifTrue:[
|
|
2426 |
self invalidate.
|
|
2427 |
^ self
|
|
2428 |
].
|
|
2429 |
super update:something with:aParameter from:changedObject
|
|
2430 |
'
|
|
2431 |
! !
|
|
2432 |
|
|
2433 |
!JavaScriptCodeGeneratorTool methodsFor:'private'!
|
|
2434 |
|
|
2435 |
codeFor_shouldImplementFor:selector inClass:aClass
|
|
2436 |
"used in the 'generate required protocol' to generate a shouldImplement-sending
|
|
2437 |
method for each subclassClassresponsibility method above aClass."
|
|
2438 |
|
|
2439 |
|mthd comment implClass methodBodyStream searcher errorMessageString|
|
|
2440 |
|
|
2441 |
(aClass notNil
|
|
2442 |
and:[ aClass superclass notNil ]) ifTrue:[
|
|
2443 |
implClass := aClass superclass whichClassImplements:selector.
|
|
2444 |
].
|
|
2445 |
implClass isNil ifTrue:[
|
|
2446 |
^ ((Method methodDefinitionTemplateForSelector:selector),'\ ^ self shouldImplement\') withCRs
|
|
2447 |
].
|
|
2448 |
|
|
2449 |
mthd := implClass compiledMethodAt:selector.
|
|
2450 |
|
|
2451 |
methodBodyStream := '' writeStream.
|
|
2452 |
methodBodyStream
|
|
2453 |
nextPutAll:mthd methodDefinitionTemplate; cr;
|
|
2454 |
nextPutAll:' "'.
|
|
2455 |
|
|
2456 |
"/ include the comment of the subclassResponsibility-sending method
|
|
2457 |
|
|
2458 |
comment := mthd methodComment.
|
|
2459 |
comment isEmptyOrNil ifTrue:[
|
|
2460 |
methodBodyStream
|
|
2461 |
nextPutAll:('superclass <1s> says that I am responsible to implement this method'
|
|
2462 |
expandMacrosWith:implClass name)
|
|
2463 |
] ifFalse:[
|
|
2464 |
comment
|
|
2465 |
asStringCollection do:[:eachLine|
|
|
2466 |
methodBodyStream nextPutAll:eachLine.
|
|
2467 |
] separatedBy:[
|
|
2468 |
methodBodyStream cr; nextPutAll:' '.
|
|
2469 |
].
|
|
2470 |
].
|
|
2471 |
methodBodyStream
|
|
2472 |
nextPut:$"; cr; cr.
|
|
2473 |
|
|
2474 |
"/ include the argument of the subclassResponsibility:-sending method
|
|
2475 |
self canUseRefactoringSupport ifTrue:[
|
|
2476 |
(mthd sends:#subclassResponsibility:) ifTrue:[
|
|
2477 |
searcher := ParseTreeSearcher new.
|
|
2478 |
searcher
|
|
2479 |
matches: 'self subclassResponsibility: `''.*'''
|
|
2480 |
do:[:node :answer |
|
|
2481 |
errorMessageString := node arguments first value.
|
|
2482 |
true.
|
|
2483 |
].
|
|
2484 |
searcher executeTree: (mthd parseTree) initialAnswer: false.
|
|
2485 |
].
|
|
2486 |
].
|
|
2487 |
errorMessageString notEmptyOrNil ifTrue:[
|
|
2488 |
methodBodyStream
|
|
2489 |
nextPutAll:' ^ self shouldImplement:';
|
|
2490 |
nextPutLine:(errorMessageString storeString)
|
|
2491 |
] ifFalse:[
|
|
2492 |
methodBodyStream
|
|
2493 |
nextPutLine:' ^ self shouldImplement'.
|
|
2494 |
].
|
|
2495 |
|
|
2496 |
^ methodBodyStream contents
|
493
|
2497 |
! !
|
|
2498 |
|
|
2499 |
!JavaScriptCodeGeneratorTool class methodsFor:'documentation'!
|
|
2500 |
|
|
2501 |
version_CVS
|
|
2502 |
^ '$Header$'
|
|
2503 |
! !
|