UIPainter.st
changeset 1850 410f98d259b7
parent 1827 691d1471cd3e
child 1851 d036350188f5
equal deleted inserted replaced
1849:1209223c6d30 1850:410f98d259b7
  3156             ]
  3156             ]
  3157         ]
  3157         ]
  3158     ]
  3158     ]
  3159 !
  3159 !
  3160 
  3160 
  3161 openInterface:aSymbol
  3161 openInterface:aSymbol 
  3162     "opens the interface on the selector aSymbol"
  3162     "opens the interface on the selector aSymbol"
  3163 
  3163     
  3164     |cls painterView painter topView galleryWindow icon name|
  3164     |cls painterView painter topView galleryWindow icon name|
  3165 
  3165 
  3166     modified := false.
  3166     modified := false.
  3167 
       
  3168     aspects := IdentityDictionary new.
  3167     aspects := IdentityDictionary new.
  3169 
       
  3170     specClass notNil ifTrue:[
  3168     specClass notNil ifTrue:[
  3171         specClass isBehavior ifTrue:[
  3169         specClass isBehavior ifTrue:[
  3172             name := specClass nameWithoutPrefix.
  3170             name := specClass nameWithoutPrefix.
  3173         ] ifFalse:[
  3171         ] ifFalse:[
  3174             name := specClass printString string
  3172             name := specClass printString string
  3175         ]
  3173         ]
  3176     ].
  3174     ].
  3177 
  3175     aspects at:#classNameChannel
  3178     aspects at:#classNameChannel put:(
  3176         put:((specClass notNil ifTrue:[ specClass ] ifFalse:[ 'NewApplication' ]) 
  3179         (specClass notNil ifTrue:[specClass]
  3177                 asValue).
  3180                          ifFalse:['NewApplication']) asValue
       
  3181     ).
       
  3182 
       
  3183     specSuperclass isNil ifTrue:[
  3178     specSuperclass isNil ifTrue:[
  3184         specClass notNil ifTrue:[
  3179         specClass notNil ifTrue:[
  3185             (cls := self resolveName:specClass) notNil ifTrue:[
  3180             (cls := self resolveName:specClass) notNil ifTrue:[
  3186                 specSuperclass := cls superclass name.
  3181                 specSuperclass := cls superclass name.
  3187             ]
  3182             ]
  3188         ]
  3183         ]
  3189     ].
  3184     ].
  3190     aspects at:#superclassNameChannel put:(
  3185     aspects at:#superclassNameChannel
  3191         (specSuperclass notNil ifTrue:[specSuperclass]
  3186         put:((specSuperclass notNil 
  3192                          ifFalse:['ApplicationModel']) asValue
  3187                 ifTrue:[ specSuperclass ]
  3193     ).
  3188                 ifFalse:[ 'ApplicationModel' ]) asValue).
  3194     aspects at:#superclassNameDefaults put:#('ApplicationModel' 'SimpleDialog') asValue.
  3189     aspects at:#superclassNameDefaults
  3195     aspects at:#methodNameChannel put:(
  3190         put:#( 'ApplicationModel' 'SimpleDialog' ) asValue.
  3196         (specSelector notNil ifTrue:[specSelector asValue]
  3191     aspects at:#methodNameChannel
  3197                             ifFalse:[#windowSpec]) asValue
  3192         put:((specSelector notNil 
  3198     ).
  3193                 ifTrue:[ specSelector asValue ]
  3199 
  3194                 ifFalse:[ #windowSpec ]) asValue).
  3200     "/ the canvas ...
  3195     treeView := TreeView new.
  3201 
       
  3202     treeView    := TreeView new.
       
  3203     treeView windowSpecClass:(self defaultWindowSpecClass).
  3196     treeView windowSpecClass:(self defaultWindowSpecClass).
  3204     treeView selectConditionBlock:[:newSelection | self selectionChangeAllowed:newSelection].
  3197     treeView 
  3205 
  3198         selectConditionBlock:[:newSelection | self selectionChangeAllowed:newSelection ].
  3206     painterView := StandardSystemView new.
  3199     painterView := StandardSystemView new.
  3207 
       
  3208     name := name ? UIPainter defaultNameOfCanvas.
  3200     name := name ? UIPainter defaultNameOfCanvas.
  3209 
  3201     painterView name:name.
  3210     painterView name: name.
  3202     painterView label:name.
  3211     painterView label: name.
  3203     painterView extent:(treeView windowSpecClass defaultExtentInUIPainter).
  3212     painterView extent:(treeView windowSpecClass defaultExtentInUIPainter). "/ 300@300.
       
  3213 
       
  3214     painter := UIPainterView in:painterView.
  3204     painter := UIPainterView in:painterView.
  3215     painter layout:(0.0 @ 0.0 corner:1.0 @ 1.0) asLayout.
  3205     painter layout:(0.0 @ 0.0 corner:1.0 @ 1.0) asLayout.
  3216 
       
  3217     treeView := treeView canvas:painter specName:name.
  3206     treeView := treeView canvas:painter specName:name.
  3218     painter treeView:treeView.
  3207     painter treeView:treeView.
  3219     treeView model addDependent:self.
  3208     treeView model addDependent:self.
  3220 
       
  3221     super openInterface:aSymbol.
  3209     super openInterface:aSymbol.
  3222 
       
  3223     topView := self window.
  3210     topView := self window.
  3224     topView label:'GUI Painter'.
  3211     topView label:'GUI Painter'.
  3225 
       
  3226     painterView openInGroup:(topView windowGroup).
  3212     painterView openInGroup:(topView windowGroup).
  3227     painterView application:self.
  3213     painterView application:self.
  3228 
       
  3229     "/ the selectionPanel ...
       
  3230 
       
  3231     selectionPanel := self selectionPanelClass new.
  3214     selectionPanel := self selectionPanelClass new.
  3232     selectionPanel allButOpenInterface:#windowSpec.
  3215     selectionPanel allButOpenInterface:#windowSpec.
  3233     (galleryWindow := selectionPanel window) openInGroup:(topView windowGroup).
  3216     (galleryWindow := selectionPanel window) 
       
  3217         openInGroup:(topView windowGroup).
  3234     selectionPanel masterApplication:self.
  3218     selectionPanel masterApplication:self.
  3235 
       
  3236     icon := Smalltalk imageFromFileNamed:'UIPainter.xbm' forClass:self class.
  3219     icon := Smalltalk imageFromFileNamed:'UIPainter.xbm' forClass:self class.
  3237     topView iconLabel:'GUI Painter'.
  3220     topView iconLabel:'GUI Painter'.
  3238     topView icon:icon.
  3221     topView icon:icon.
  3239 
       
  3240     painterView iconLabel:'GUI Canvas'.
  3222     painterView iconLabel:'GUI Canvas'.
  3241     painterView icon:icon.
  3223     painterView icon:icon.
  3242 
  3224     
       
  3225 "/    painterView topView raise.
  3243     topView bePartner.
  3226     topView bePartner.
  3244     painterView bePartner.
  3227     painterView bePartner.
  3245     galleryWindow bePartner.
  3228     galleryWindow bePartner.
  3246 
       
  3247     galleryWindow iconLabel:'GUI Gallery'.
  3229     galleryWindow iconLabel:'GUI Gallery'.
  3248     galleryWindow icon:icon.
  3230     galleryWindow icon:icon.
  3249 
  3231 
  3250     painterView topView raise.
  3232     selectionPanel window waitUntilVisible.
       
  3233     painterView window waitUntilVisible.
       
  3234     self window waitUntilVisible.
       
  3235     [ Delay waitForSeconds:0.5. self window topView raise ] fork.
  3251 !
  3236 !
  3252 
  3237 
  3253 openOnClass:aClass
  3238 openOnClass:aClass
  3254     "opens the GUI Painter on aClass and #windowSpec"
  3239     "opens the GUI Painter on aClass and #windowSpec"
  3255 
  3240 
  3857 
  3842 
  3858 !
  3843 !
  3859 
  3844 
  3860 doSave
  3845 doSave
  3861     "saves the window spec"
  3846     "saves the window spec"
  3862 
  3847     
  3863     |code painter cls|
  3848     |code painter cls|
  3864 
  3849 
  3865     self askForSectionModification.
  3850     self askForSectionModification.
  3866 
       
  3867     self hasSpecClassAndSelector ifFalse:[
  3851     self hasSpecClassAndSelector ifFalse:[
  3868         self doDefineClassAndSelector isNil ifTrue: [^nil]
  3852         self doDefineClassAndSelector isNil ifTrue:[
  3869     ].
  3853             ^ nil
  3870 
  3854         ]
  3871     (specClass notNil and: [(cls := Smalltalk at: specClass asSymbol) isClass]) ifFalse:[   
  3855     ].
  3872         self warn:('Oops - cannot save - class not found: ' , specClass).
  3856     
  3873         ^nil
       
  3874     ].
       
  3875 
       
  3876 "/    specClass notNil ifTrue:[
  3857 "/    specClass notNil ifTrue:[
  3877 "/        (specClass includes:$:) ifFalse:[
  3858 "/        (specClass includes:$:) ifFalse:[
  3878 "/            (ns := Smalltalk defaultNameSpace) notNil ifTrue:[
  3859 "/            (ns := Smalltalk defaultNameSpace) notNil ifTrue:[
  3879 "/                cls := ns at:specClass asSymbol
  3860 "/                cls := ns at:specClass asSymbol
  3880 "/            ].
  3861 "/            ].
  3896 "/    ns ~~ Smalltalk defaultNameSpace ifTrue:[
  3877 "/    ns ~~ Smalltalk defaultNameSpace ifTrue:[
  3897 "/        specClass := ns name , '::' , cls nameWithoutNameSpacePrefix.
  3878 "/        specClass := ns name , '::' , cls nameWithoutNameSpacePrefix.
  3898 "/    ] ifFalse:[
  3879 "/    ] ifFalse:[
  3899 "/        specClass := cls name.
  3880 "/        specClass := cls name.
  3900 "/    ].
  3881 "/    ].
  3901 
  3882     (specClass notNil 
       
  3883         and:[ (cls := Smalltalk at:specClass asSymbol) isClass ]) 
       
  3884             ifFalse:[
       
  3885                 self warn:('Oops - cannot save - class not found: ' , specClass).
       
  3886                 ^ nil
       
  3887             ].
  3902     painter := self painter.
  3888     painter := self painter.
  3903     painter 
  3889     painter 
  3904         className:specClass
  3890         className:specClass
  3905         superclassName:specSuperclass
  3891         superclassName:specSuperclass
  3906         selector:specSelector.
  3892         selector:specSelector.
  3907 
  3893 self halt.
  3908     Transcript showCR:'generating windowSpec code...'.
  3894     Transcript showCR:'generating windowSpec code...'.
  3909 
       
  3910     code := painter generateWindowSpecMethodSource withCRs.
  3895     code := painter generateWindowSpecMethodSource withCRs.
  3911     (ReadStream on:code) fileIn.
  3896     (ReadStream on:code) fileIn.
  3912 
       
  3913     self doGenerateAspectSelectorsMethod.
  3897     self doGenerateAspectSelectorsMethod.
  3914     self helpTool doSave.
  3898     self helpTool doSave.
  3915     self updateInfoLabel.
  3899     self updateInfoLabel.
  3916 
       
  3917     modified := false.
  3900     modified := false.
  3918     painter resetModification.
  3901     painter resetModification.
  3919     (cls class includesSelector: specSelector) ifTrue:[
  3902     (cls class includesSelector:specSelector) ifTrue:[
  3920         self addToHistory: (specClass, ' ', specSelector) -> #loadFromMessage:.
  3903         self addToHistory:(specClass , ' ' , specSelector) -> #loadFromMessage:.
  3921     ].
  3904     ].
  3922 !
  3905 !
  3923 
  3906 
  3924 doSaveAs
  3907 doSaveAs
  3925     "opens a ResourceSelectionBrowser for saving the window spec on a class"
  3908     "opens a ResourceSelectionBrowser for saving the window spec on a class"