UIPainterView.st
changeset 1361 9020214f03e6
parent 1358 c0116e25a2ac
child 1362 b710bba663cb
equal deleted inserted replaced
1360:555429506474 1361:9020214f03e6
   729       '    "*** Please change as required and accept it in the browser."\'.
   729       '    "*** Please change as required and accept it in the browser."\'.
   730 
   730 
   731     AspectsAsInstances ifTrue:[
   731     AspectsAsInstances ifTrue:[
   732         code := (code , '\' ,
   732         code := (code , '\' ,
   733           '    ' , aspect , ' isNil ifTrue:[\' ,
   733           '    ' , aspect , ' isNil ifTrue:[\' ,
   734           '        ' , aspect , ' := ' , ' ' , modelGen , '.\' ,
   734           '       ' , aspect , ' := ' , ' ' , modelGen , '.\' ,
       
   735           '"/       ' , aspect , ' addDependent:self.\' ,
   735           '    ].\' ,
   736           '    ].\' ,
   736           '    ^ ' , aspect ,'.\' ,
   737           '    ^ ' , aspect ,'.\' ,
   737           '!! !!\\') 
   738           '!! !!\\') 
   738     ] ifFalse:[
   739     ] ifFalse:[
   739         code := (code , '\' ,
   740         code := (code , '\' ,
   740           '    |holder|\' ,
   741           '    |holder|\' ,
   741           '\' ,
   742           '\' ,
   742           '    (holder := builder bindingAt:#' , aspect , ') isNil ifTrue:[\' ,
   743           '    (holder := builder bindingAt:#' , aspect , ') isNil ifTrue:[\' ,
   743           '        holder := ', modelGen, '.\',
   744           '        holder := ', modelGen, '.\',
   744           '        builder aspectAt:#' , aspect , ' put:holder.\',
   745           '        builder aspectAt:#' , aspect , ' put:holder.\',
       
   746           '"/        holder addDependent:self.\' ,
   745           '    ].\' ,
   747           '    ].\' ,
   746           '    ^ holder.\' ,
   748           '    ^ holder.\' ,
   747           '!! !!\\') 
   749           '!! !!\\') 
   748     ].
   750     ].
       
   751 
   749     ^ code withCRs
   752     ^ code withCRs
   750 
   753 
   751     "Modified: / 29.7.1998 / 11:29:16 / cg"
   754     "Modified: / 29.7.1998 / 11:29:16 / cg"
   752     "Modified: / 22.9.1999 / 12:33:47 / stefan"
   755     "Modified: / 22.9.1999 / 12:33:47 / stefan"
   753 !
   756 !
   756     "generate aspect, action & menu methods
   759     "generate aspect, action & menu methods
   757      - but do not overwrite existing ones.
   760      - but do not overwrite existing ones.
   758      Return a string ready to compile into the application class."
   761      Return a string ready to compile into the application class."
   759 
   762 
   760     |cls code skip protoSpec thisCode
   763     |cls code skip protoSpec thisCode
   761      definedMethodSelectors iVars t|
   764      definedMethodSelectors iVars t exportSels|
   762 
   765 
   763     definedMethodSelectors := IdentitySet new.
   766     definedMethodSelectors := IdentitySet new.
   764 
   767 
   765     code := ''.
   768     code := ''.
   766 
   769 
   805                         ].
   808                         ].
   806                         code := code, thisCode.
   809                         code := code, thisCode.
   807                         definedMethodSelectors add:sym.
   810                         definedMethodSelectors add:sym.
   808                     ] ifTrue:[
   811                     ] ifTrue:[
   809                         Transcript showCR:'no code generated for aspect: ' , sym , ' (method already exists)'
   812                         Transcript showCR:'no code generated for aspect: ' , sym , ' (method already exists)'
   810                     ]
   813                     ].
   811                 ]
   814                 ].
   812         ].
   815         ].
   813 
   816 
       
   817         "/ for each aspect, generate getter (if not yet implemented)
   814         self generateCodeFrom:(aProp spec aspectSelectors) in:cls
   818         self generateCodeFrom:(aProp spec aspectSelectors) in:cls
   815                 do:[:aSel|
   819                 do:[:aSel|
   816                     |sym|
   820                     |sym|
   817 
   821 
   818                     sym := aSel asSymbol.
   822                     sym := aSel asSymbol.
   819                     (definedMethodSelectors includes:sym) ifFalse:[
   823                     (definedMethodSelectors includes:sym) ifFalse:[
   820                         thisCode := (self generateAspectMethodFor:aSel spec:protoSpec inClass:cls).
   824                         thisCode := (self generateAspectMethodFor:aSel spec:protoSpec inClass:cls).
       
   825                         code := code , thisCode.
       
   826                         definedMethodSelectors add:sym.
       
   827                     ]
       
   828                 ].
       
   829 
       
   830         "/ exported aspects - need setter methods
       
   831         exportSels := (treeView exportedAspects ? #()) collect:[:entry | (entry subAspect , ':') asSymbol].
       
   832         self generateCodeFrom:exportSels in:cls
       
   833                 do:[:aSel|
       
   834                     |sym aspect|
       
   835 
       
   836                     sym := aSel asSymbol.
       
   837                     (definedMethodSelectors includes:sym) ifFalse:[
       
   838                         aspect := (aSel copyWithoutLast:1) asSymbol.
       
   839                         thisCode := (self generateAspectSetMethodFor:aspect spec:protoSpec inClass:cls).
   821                         code := code , thisCode.
   840                         code := code , thisCode.
   822                         definedMethodSelectors add:sym.
   841                         definedMethodSelectors add:sym.
   823                     ]
   842                     ]
   824                 ].
   843                 ].
   825 
   844 
   911 
   930 
   912     ^ ' , spec storeString , '\!!\'.
   931     ^ ' , spec storeString , '\!!\'.
   913     code := code withCRs.
   932     code := code withCRs.
   914     ^ code
   933     ^ code
   915 
   934 
       
   935 !
       
   936 
       
   937 generateAspectSetMethodFor:aspect spec:protoSpec inClass:targetClass
       
   938     |code|
       
   939 
       
   940     code := '!!' , targetClass name , ' methodsFor:''aspects - exported''!!\\' ,
       
   941       aspect , ':something\' ,
       
   942       '    "automatically generated by UIPainter ..."\\' ,
       
   943       '    "This method is used when I am embedded as subApplication,"\' ,
       
   944       '    "and the mainApp wants to connect its aspects to mine."\'.
       
   945 
       
   946     AspectsAsInstances ifTrue:[
       
   947         code := (code , '\' ,
       
   948           '    "/ ' , aspect , ' notNil ifTrue:[\' ,
       
   949           '    "/    ' , aspect , ' removeDependent:self.\' ,
       
   950           '    "/ ].\' ,
       
   951           '    ' , aspect ,' := something.\' ,
       
   952           '    "/ ' , aspect ,' notNil ifTrue:[\' ,
       
   953           '    "/    ' , aspect , ' addDependent:self.\' ,
       
   954           '    "/ ].\' ,
       
   955           '    ^ self.\' ,
       
   956           '!! !!\\') 
       
   957     ] ifFalse:[
       
   958         code := (code , '\' ,
       
   959           '    "/ |holder|\' ,
       
   960           '\' ,
       
   961           '    "/ (holder := builder bindingAt:#' , aspect , ') notNil ifTrue:[\' ,
       
   962           '    "/     holder removeDependent:self.\' ,
       
   963           '    "/ ].\' ,
       
   964           '    builder aspectAt:#' , aspect , ' put:something.\',
       
   965           '    "/ something notNil ifTrue:[\' ,
       
   966           '    "/     something addDependent:self.\' ,
       
   967           '    "/ ].\' ,
       
   968           '    ^ self.\' ,
       
   969           '!! !!\\') 
       
   970     ].
       
   971 
       
   972     ^ code withCRs
       
   973 
       
   974     "Modified: / 29.7.1998 / 11:29:16 / cg"
       
   975     "Modified: / 22.9.1999 / 12:33:47 / stefan"
   916 !
   976 !
   917 
   977 
   918 generateCodeFrom:aListOfSelectors in:aClass do:aBlock
   978 generateCodeFrom:aListOfSelectors in:aClass do:aBlock
   919 
   979 
   920     self class redefineAspectMethods ifTrue:[
   980     self class redefineAspectMethods ifTrue:[