UIPainterView.st
changeset 352 088174fc1e71
parent 335 9f048ededd7d
child 361 6624bb5d9a1a
equal deleted inserted replaced
351:7cb9f9c9a872 352:088174fc1e71
   385                 ifFalse:[self select:oldSel]
   385                 ifFalse:[self select:oldSel]
   386 ! !
   386 ! !
   387 
   387 
   388 !UIPainterView methodsFor:'generating output'!
   388 !UIPainterView methodsFor:'generating output'!
   389 
   389 
       
   390 aspectMethods
       
   391     "extract a list of aspect methods - for browsing"
       
   392 
       
   393     |cls methods skip selector protoSpec|
       
   394 
       
   395     className isNil ifTrue:[
       
   396         self warn:'set the class first'.
       
   397         ^ #()
       
   398     ].
       
   399 
       
   400     cls := self resolveName:className.
       
   401     methods := IdentitySet new.
       
   402 
       
   403     treeView propertiesDo:[:aProp|
       
   404         |selector|
       
   405 
       
   406         (selector := aProp model) notNil ifTrue:[
       
   407             selector isArray ifFalse:[
       
   408                 selector := selector asSymbol.
       
   409                 (cls implements:selector) ifTrue:[
       
   410                     skip := false.
       
   411                     (cls isSubclassOf:SimpleDialog) ifTrue:[
       
   412                         skip := SimpleDialog implements:selector asSymbol
       
   413                     ].
       
   414                     skip ifFalse:[
       
   415                         methods add:(cls compiledMethodAt:selector)
       
   416                     ].
       
   417                 ].
       
   418             ].
       
   419         ].
       
   420 
       
   421         (selector := aProp menu) notNil ifTrue:[
       
   422             selector isArray ifFalse:[
       
   423                 selector := selector asSymbol.
       
   424                 (cls implements:selector) ifTrue:[
       
   425                     methods add:(cls compiledMethodAt:selector)
       
   426                 ]
       
   427             ].
       
   428         ].
       
   429 
       
   430         (aProp spec aspectSelectors) do:[:aSel |
       
   431             |selector|
       
   432 
       
   433             aSel isArray ifFalse:[
       
   434                 selector := aSel asSymbol.
       
   435                 (cls implements:selector) ifTrue:[
       
   436                     methods add:(cls compiledMethodAt:selector)
       
   437                 ]
       
   438             ].
       
   439         ].
       
   440         aProp spec actionSelectors do:[:aSel|
       
   441             |selector|
       
   442 
       
   443             aSel isArray ifFalse:[
       
   444                 selector := aSel asSymbol.
       
   445                 (cls implements:selector) ifTrue:[
       
   446                     methods add:(cls compiledMethodAt:selector)
       
   447                 ]
       
   448             ].
       
   449         ].
       
   450         aProp spec valueSelectors do:[:aSel|
       
   451             |selector|
       
   452 
       
   453             aSel isArray ifFalse:[
       
   454                 selector := aSel asSymbol.
       
   455                 (cls implements:selector) ifTrue:[
       
   456                     methods add:(cls compiledMethodAt:selector)
       
   457                 ]
       
   458             ].
       
   459         ]
       
   460     ].
       
   461 
       
   462     protoSpec := treeView canvasSpec.
       
   463 
       
   464     (selector := protoSpec menu) notNil ifTrue:[
       
   465         selector isArray ifFalse:[
       
   466             selector := selector asSymbol.
       
   467             (cls implements:selector) ifTrue:[
       
   468                 methods add:(cls compiledMethodAt:selector)
       
   469             ]
       
   470         ].
       
   471     ].
       
   472 
       
   473     ^ methods
       
   474 
       
   475     "Created: / 25.10.1997 / 18:58:25 / cg"
       
   476     "Modified: / 26.10.1997 / 15:06:18 / cg"
       
   477 !
       
   478 
   390 generateActionMethodFor:aspect spec:protoSpec inClass:targetClass
   479 generateActionMethodFor:aspect spec:protoSpec inClass:targetClass
   391     |selector args showIt code alreadyInSuperclass|
   480     |selector args showIt code alreadyInSuperclass|
   392 
   481 
   393     selector := aspect asSymbol.
   482     selector := aspect asSymbol.
   394 
   483 
   402         showIt := ''' , anArgument printString , '' ...''.\'.
   491         showIt := ''' , anArgument printString , '' ...''.\'.
   403     ].
   492     ].
   404 
   493 
   405     code := '!!' , targetClass name , ' methodsFor:''actions''!!\\' ,
   494     code := '!!' , targetClass name , ' methodsFor:''actions''!!\\' ,
   406                 aspect , args , '\' ,
   495                 aspect , args , '\' ,
   407                 '    "automatically generated by UIPainter ..."\' ,
   496                 '    "automatically generated by UIPainter ..."\\' ,
       
   497                 '    "*** the code below performs no action"\' ,
       
   498                 '    "*** (except for some feedback on the Transcript)"\' ,
       
   499                 '    "*** Please change as required and accept in the browser."\' ,
   408                 '\' .
   500                 '\' .
   409 
   501 
   410     alreadyInSuperclass ifTrue:[
   502     alreadyInSuperclass ifTrue:[
   411         code := code ,
   503         code := code ,
   412                     '    "action for ' , aspect , ' is already provided in a superclass."\' ,
   504                     '    "action for ' , aspect , ' is already provided in a superclass."\' ,
   430 
   522 
   431     code := code ,
   523     code := code ,
   432                 '!! !!\\'.
   524                 '!! !!\\'.
   433     ^ code withCRs
   525     ^ code withCRs
   434 
   526 
   435     "Modified: 19.8.1997 / 12:03:20 / cg"
   527     "Modified: / 25.10.1997 / 19:18:50 / cg"
   436 !
   528 !
   437 
   529 
   438 generateAspectMethodFor:aspect spec:protoSpec inClass:targetClass
   530 generateAspectMethodFor:aspect spec:protoSpec inClass:targetClass
   439     |modelClass|
   531     |modelClass modelValue modelGen|
   440 
   532 
   441     modelClass := protoSpec defaultModelClassFor:aspect.
   533     modelClass := protoSpec defaultModelClassFor:aspect.
       
   534     modelValue := protoSpec defaultModelValueFor:aspect.
       
   535 
       
   536     modelValue isNil ifTrue:[
       
   537         modelGen := modelClass name , ' new'
       
   538     ] ifFalse:[
       
   539         modelGen := modelValue storeString , ' asValue'
       
   540     ].
   442 
   541 
   443     ^ ('!!' , targetClass name , ' methodsFor:''aspects''!!\\' ,
   542     ^ ('!!' , targetClass name , ' methodsFor:''aspects''!!\\' ,
   444       aspect , '\' ,
   543       aspect , '\' ,
   445       '    "automatically generated by UIPainter ..."\' ,
   544       '    "automatically generated by UIPainter ..."\\' ,
       
   545       '    "*** the code below creates a default model when invoked."\' ,
       
   546       '    "*** (which may not be the one you wanted)"\' ,
       
   547       '    "*** Please change as required and accept in the browser."\' ,
   446       '\' ,
   548       '\' ,
   447       '    |holder|\' ,
   549       '    |holder|\' ,
   448       '\' ,
   550       '\' ,
   449       '    (holder := builder bindingAt:#' , aspect , ') isNil ifTrue:[\' ,
   551       '    (holder := builder bindingAt:#' , aspect , ') isNil ifTrue:[\' ,
   450       '        builder aspectAt:#' , aspect , ' put:(holder := ' , ' ' , modelClass name , ' new' , ').\' ,
   552       '        builder aspectAt:#' , aspect , ' put:(holder := ' , ' ' , modelGen , ').\' ,
   451       '    ].\' ,
   553       '    ].\' ,
   452       '    ^ holder\' ,
   554       '    ^ holder\' ,
   453       '!! !!\\') withCRs
   555       '!! !!\\') withCRs
       
   556 
       
   557     "Modified: / 26.10.1997 / 19:01:15 / cg"
   454 !
   558 !
   455 
   559 
   456 generateAspectMethods
   560 generateAspectMethods
   457     |cls code skip modelSelector menuSelector protoSpec thisCode|
   561     "generate aspect, action & menu methods
       
   562      - but do not overwrite existing ones.
       
   563      Return a string ready to compile into the application class."
       
   564 
       
   565     |cls code skip menuSelector protoSpec thisCode|
   458 
   566 
   459     code := ''.
   567     code := ''.
   460 
   568 
   461     className isNil ifTrue:[
   569     className isNil ifTrue:[
   462         self warn:'set the class first'.
   570         self warn:'set the class first'.
   463         ^ code
   571         ^ code
   464     ].
   572     ].
   465     cls := self resolveName:className.
   573     cls := self resolveName:className.
   466 
   574 
   467     treeView propertiesDo:[:aProp|
   575     treeView propertiesDo:[:aProp|
       
   576         |modelSelector menuSelector|
       
   577 
   468         protoSpec := aProp spec.
   578         protoSpec := aProp spec.
   469 
   579 
   470         (modelSelector := aProp model) notNil ifTrue:[
   580         (modelSelector := aProp model) notNil ifTrue:[
   471             (cls implements:modelSelector asSymbol) ifFalse:[
   581             (modelSelector isArray not) ifTrue:[
   472                 skip := false.
   582                 (cls implements:modelSelector asSymbol) ifFalse:[
   473                 (cls isSubclassOf:SimpleDialog) ifTrue:[
   583                     skip := false.
   474                     skip := SimpleDialog implements:modelSelector asSymbol
   584                     (cls isSubclassOf:SimpleDialog) ifTrue:[
   475                 ].
   585                         skip := SimpleDialog implements:modelSelector asSymbol
   476                 skip ifFalse:[
       
   477                     "/ kludge ..
       
   478                     (protoSpec isMemberOf:ActionButtonSpec) ifTrue:[
       
   479                         thisCode := (self generateActionMethodFor:modelSelector spec:protoSpec inClass:cls).
       
   480                     ] ifFalse:[
       
   481                         thisCode := (self generateAspectMethodFor:modelSelector spec:protoSpec inClass:cls).
       
   482                     ].
   586                     ].
   483                     code := code , thisCode
   587                     skip ifFalse:[
       
   588                         "/ kludge ..
       
   589                         (protoSpec isMemberOf:ActionButtonSpec) ifTrue:[
       
   590                             thisCode := (self generateActionMethodFor:modelSelector spec:protoSpec inClass:cls).
       
   591                         ] ifFalse:[
       
   592                             thisCode := (self generateAspectMethodFor:modelSelector spec:protoSpec inClass:cls).
       
   593                         ].
       
   594                         code := code , thisCode
       
   595                     ].
   484                 ].
   596                 ].
   485             ].
   597             ].
   486         ].
   598         ].
   487 
   599 
   488         (menuSelector := aProp menu) notNil ifTrue:[
   600         (menuSelector := aProp menu) notNil ifTrue:[
       
   601             (menuSelector isArray not) ifTrue:[
       
   602                 thisCode := self generateMenuMethodFor:menuSelector spec:protoSpec inClass:cls.
       
   603                 thisCode size ~~ 0 ifTrue:[
       
   604                     code := code , thisCode
       
   605                 ]
       
   606             ]
       
   607         ].
       
   608 
       
   609         aProp spec aspectSelectors do:[:aSel|
       
   610             (aSel isArray not) ifTrue:[
       
   611                 (cls implements:aSel asSymbol) ifFalse:[
       
   612                     thisCode := (self generateAspectMethodFor:aSel spec:protoSpec inClass:cls).
       
   613                     code := code , thisCode
       
   614                 ]
       
   615             ]
       
   616         ].
       
   617         aProp spec actionSelectors do:[:aSel|
       
   618             (aSel isArray not) ifTrue:[
       
   619                 (cls implements:aSel asSymbol) ifFalse:[
       
   620                     thisCode := (self generateActionMethodFor:aSel spec:protoSpec inClass:cls).
       
   621                     code := code , thisCode
       
   622                 ]
       
   623             ]
       
   624         ].
       
   625         aProp spec valueSelectors do:[:aSel|
       
   626             (aSel isArray not) ifTrue:[
       
   627                 (cls implements:aSel asSymbol) ifFalse:[
       
   628                     thisCode := (self generateValueMethodFor:aSel spec:protoSpec inClass:cls).
       
   629                     code := code , thisCode
       
   630                 ]
       
   631             ]
       
   632         ]
       
   633     ].
       
   634 
       
   635     protoSpec := treeView canvasSpec.
       
   636 
       
   637     (menuSelector := protoSpec menu) notNil ifTrue:[
       
   638         (menuSelector isArray not) ifTrue:[
   489             thisCode := self generateMenuMethodFor:menuSelector spec:protoSpec inClass:cls.
   639             thisCode := self generateMenuMethodFor:menuSelector spec:protoSpec inClass:cls.
   490             thisCode size ~~ 0 ifTrue:[
   640             thisCode size ~~ 0 ifTrue:[
   491                 code := code , thisCode
   641                 code := code , thisCode
   492             ]
   642             ]
   493         ].
       
   494 
       
   495         aProp spec aspectSelectors do:[:aSel|
       
   496             (cls implements:aSel asSymbol) ifFalse:[
       
   497                 thisCode := (self generateAspectMethodFor:aSel spec:protoSpec inClass:cls).
       
   498                 code := code , thisCode
       
   499             ]
       
   500         ].
       
   501         aProp spec actionSelectors do:[:aSel|
       
   502             (cls implements:aSel asSymbol) ifFalse:[
       
   503                 thisCode := (self generateActionMethodFor:aSel spec:protoSpec inClass:cls).
       
   504                 code := code , thisCode
       
   505             ]
       
   506         ].
       
   507         aProp spec valueSelectors do:[:aSel|
       
   508             (cls implements:aSel asSymbol) ifFalse:[
       
   509                 thisCode := (self generateValueMethodFor:aSel spec:protoSpec inClass:cls).
       
   510                 code := code , thisCode
       
   511             ]
       
   512         ]
   643         ]
   513     ].
   644     ].
   514 
   645 
   515     protoSpec := treeView canvasSpec.
       
   516 
       
   517     (menuSelector := protoSpec menu) notNil ifTrue:[
       
   518         thisCode := self generateMenuMethodFor:menuSelector spec:protoSpec inClass:cls.
       
   519         thisCode size ~~ 0 ifTrue:[
       
   520             code := code , thisCode
       
   521         ]
       
   522     ].
       
   523 
       
   524 
       
   525     ^ code
   646     ^ code
       
   647 
       
   648     "Modified: / 26.10.1997 / 14:43:55 / cg"
   526 !
   649 !
   527 
   650 
   528 generateMenuMethodFor:aspect spec:protoSpec inClass:aClass
   651 generateMenuMethodFor:aspect spec:protoSpec inClass:aClass
   529     |code cperf performer category|
   652     |code cperf performer category|
   530 
   653 
   545 
   668 
   546             cperf  := Character excla asString 
   669             cperf  := Character excla asString 
   547                     , aClass name , ' methodsFor:' , category storeString
   670                     , aClass name , ' methodsFor:' , category storeString
   548                     , Character excla asString , '\\'
   671                     , Character excla asString , '\\'
   549                     , performer , '\'
   672                     , performer , '\'
   550                     , '    "this window spec was automatically generated by the UI Builder"\\'
   673                     , '    "this menu spec was automatically generated by the UI MenuBuilder"\\'
   551                     , '    ^ self\\'
   674                     , '    ^ self\\'
   552                     , '\'
   675                     , '\'
   553                     , Character excla asString
   676                     , Character excla asString
   554                     , ' '
   677                     , ' '
   555                     , Character excla asString
   678                     , Character excla asString
   561 
   684 
   562     code size == 0 ifTrue:[
   685     code size == 0 ifTrue:[
   563         ^ nil
   686         ^ nil
   564     ].
   687     ].
   565   ^ code withCRs
   688   ^ code withCRs
       
   689 
       
   690     "Modified: / 26.10.1997 / 14:44:20 / cg"
   566 !
   691 !
   567 
   692 
   568 generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
   693 generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
   569     ^ ('!!' , targetClass name , ' methodsFor:''values''!!\\' ,
   694     ^ ('!!' , targetClass name , ' methodsFor:''values''!!\\' ,
   570       aspect , '\' ,
   695       aspect , '\' ,
   571       '    "automatically generated by UIPainter ..."\' ,
   696       '    "automatically generated by UIPainter ..."\\' ,
       
   697       '    "*** the code below returns a default value when invoked."\' ,
       
   698       '    "*** (which may not be the one you wanted)"\' ,
       
   699       '    "*** Please change as required and accept in the browser."\' ,
   572       '\' ,
   700       '\' ,
   573       '    "value to be added below ..."\' ,
   701       '    "value to be added below ..."\' ,
   574       '    Transcript showCR:self class name , '': no value yet for ' , aspect , ' ...''.\' ,
   702       '    Transcript showCR:self class name , '': no value yet for ' , aspect , ' ...''.\' ,
   575       '\' ,
   703       '\' ,
   576       '^ nil.' ,
   704       '^ nil.' ,
   577       '!! !!\\') withCRs
   705       '!! !!\\') withCRs
   578 
   706 
   579 
   707     "Modified: / 25.10.1997 / 19:22:17 / cg"
   580 
       
   581 
       
   582 !
   708 !
   583 
   709 
   584 generateWindowSpecMethodSource
   710 generateWindowSpecMethodSource
   585     |spec str code category cls mthd|
   711     |spec str code category cls mthd|
   586 
   712