UIPainter.st
changeset 3051 ebb32d3a997e
parent 3032 41f4128c029c
child 3053 db8d30e7a621
equal deleted inserted replaced
3050:238571e2a33b 3051:ebb32d3a997e
  5007         code readStream fileIn.
  5007         code readStream fileIn.
  5008     ].
  5008     ].
  5009     UserPreferences current systemBrowserClass openInClass:cls selector:aspect
  5009     UserPreferences current systemBrowserClass openInClass:cls selector:aspect
  5010 !
  5010 !
  5011 
  5011 
       
  5012 doBrowseAspectClass:aspectSelector
       
  5013     "browse the class as entered in the field (can be called by buttons in a subspec)"
       
  5014 
       
  5015     self doBrowseAspectClassAndSelector:{ aspectSelector . nil }
       
  5016 !
       
  5017 
       
  5018 doBrowseAspectClassAndSelector:classAndSelectorPair
       
  5019     "browse the class as entered in the field (can be called by buttons in a subspec)"
       
  5020 
       
  5021     |spec classAspect selectorAspect className selector class |
       
  5022 
       
  5023     classAspect := classAndSelectorPair first.
       
  5024     selectorAspect := classAndSelectorPair second.
       
  5025 
       
  5026     "/ wrong: the code below uses the spec's aspect values;
       
  5027     "/ but the spec is only valid after accepting.
       
  5028 
       
  5029     "/    spec := painter specForSelection.
       
  5030     "/    spec isNil ifTrue:[^ self].
       
  5031     "/    className := spec perform:classAspect.
       
  5032     "/    
       
  5033     "/    selectorAspect notNil ifTrue:[
       
  5034     "/        selector := spec perform:selectorAspect.
       
  5035     "/    ].
       
  5036 
       
  5037     "/ we have to take the current value from the widget's value,
       
  5038     "/ which is in the listOfAspects!!
       
  5039     className := (specTool aspectFor:classAspect) value.
       
  5040     selector := (specTool aspectFor:selectorAspect) value.
       
  5041 
       
  5042     (className isEmptyOrNil or:[(selectorAspect notNil and:[selector isEmptyOrNil])]) ifTrue:[
       
  5043         Dialog information:(resources 
       
  5044                                 string:'Class and/or selector missing (for "%1 / %2")'
       
  5045                                 with:classAspect with:selectorAspect).
       
  5046         ^ self
       
  5047     ].
       
  5048     class := Smalltalk classNamed:className.
       
  5049     class isBehavior ifFalse:[
       
  5050         Dialog information:(resources 
       
  5051                                 string:'"%1" does not refer to a valid class (in "%2")'
       
  5052                                 with:className with:classAspect).
       
  5053         ^ self
       
  5054     ].
       
  5055     UserPreferences current systemBrowserClass openInClass:class selector:selector
       
  5056 !
       
  5057 
  5012 doBrowseAspectMethod:aspectSelector
  5058 doBrowseAspectMethod:aspectSelector
  5013     "browse or create the aspect method as entered in the field (button beside input fieled pressed)"
  5059     "browse or create the aspect method as entered in the field (button beside input fieled pressed)"
  5014 
  5060 
  5015     self isModified ifTrue:[ self accept ].
  5061     self isModified ifTrue:[ self accept ].
  5016     "/ self acceptOrIgnoreSectionModification.
  5062     "/ self acceptOrIgnoreSectionModification.
  5904     "Created: / 16-01-2008 / 17:49:20 / cg"
  5950     "Created: / 16-01-2008 / 17:49:20 / cg"
  5905 ! !
  5951 ! !
  5906 
  5952 
  5907 !UIPainter::TreeView class methodsFor:'documentation'!
  5953 !UIPainter::TreeView class methodsFor:'documentation'!
  5908 
  5954 
  5909 documentation
  5955 erarchy"
  5910 "
  5956 
  5911     selection in tree view; only used by the UIPainter
  5957     treeView doStepOver:-1
  5912 
  5958 ! !
  5913     [see also:]
  5959 
  5914         SelectionInTreeView
  5960 !UIPainter::TreeView methodsFor:'accessing'!
  5915         SelectionInTree
  5961 
  5916         TreeItem
  5962 ditToolbar
       
  5963     self editToolBarVisibleHolder value:false
       
  5964 !
       
  5965 
       
  5966 BarVisibleHolder value:false
       
  5967 !
       
  5968 
       
  5969 Spec newSpec|
       
  5970 
       
  5971     (aSpecOrWidgetClass isSubclassOf:UISpecification) ifTrue:[
       
  5972         newSpecClass := aSpecOrWidgetClass.
       
  5973     ] ifFalse:[
       
  5974         (aSpecOrWidgetClass isSubclassOf:View) ifTrue:[
       
  5975             newSpecClass := aSpecOrWidgetClass basicNew specClass.
       
  5976         ] ifFalse:[
       
  5977             newSpecClass := nil
       
  5978         ].
       
  5979     ].
       
  5980     newSpecClass isNil ifTrue:[
       
  5981         Dialog warn:'Invalid Spec- or View-Class: ' , aSpecOrWidgetClass name.
       
  5982         ^ self.
       
  5983     ].
       
  5984 
       
  5985     treeView isCanvasSelected ifTrue:[
       
  5986         ^ self
       
  5987     ].
       
  5988     oldSpec := self selectedSpec.
       
  5989     newSpec := newSpecClass cloneFrom:oldSpec.
       
  5990 
       
  5991     self painter replaceSelectionBy:newSpec.
       
  5992 
       
  5993     "Modified: / 05-09-2012 / 19:24:40 / cg"
       
  5994 !
       
  5995 
       
  5996 og warn:'Invalid Spec- or View-Class: ' , aSpecOrWidgetClass name.
       
  5997         ^ self.
       
  5998     ].
       
  5999 
       
  6000     treeView isCanvasSelected ifTrue:[
       
  6001         ^ self
       
  6002     ].
       
  6003     oldSpec := self selectedSpec.
       
  6004     newSpec := newSpecClass cloneFrom:oldSpec.
       
  6005 
       
  6006     self painter replaceSelectionBy:newSpec.
       
  6007 
       
  6008     "Modified: / 05-09-2012 / 19:24:40 / cg"
       
  6009 !
       
  6010 
       
  6011 TreeItem
  5917         UIPainter
  6012         UIPainter
  5918 
  6013 
  5919     [author:]
  6014     [author:]
  5920         Claus Atzkern
  6015         Claus Atzkern
  5921 "
  6016 "
  5922 
  6017 
  5923 
  6018 
  5924 ! !
  6019 !
  5925 
  6020 
  5926 !UIPainter::TreeView methodsFor:'accessing'!
  6021 ew)"
  5927 
       
  5928 canvas
       
  5929     "returns the canvas (UIPainterView)"
       
  5930 
       
  5931     ^ model root contents view
       
  5932 
       
  5933 
       
  5934 !
       
  5935 
       
  5936 canvas:aCanvas
       
  5937     "install canvas (UIPainterView)"
       
  5938 
  6022 
  5939     self canvas:aCanvas specName:nil
  6023     self canvas:aCanvas specName:nil
  5940 !
  6024 !
  5941 
  6025 
  5942 canvas:aCanvas specName:nameOfSpec
  6026 props := UIPainterView::ViewProperty new.
  5943     "install canvas (UIPainterView)"
       
  5944 
       
  5945     |props|
       
  5946 
       
  5947     props := UIPainterView::ViewProperty new.
       
  5948     props view:aCanvas.
  6027     props view:aCanvas.
  5949 
  6028 
  5950     model root:(TreeItem 
  6029     model root:(TreeItem 
  5951                     name:(nameOfSpec ? painter defaultNameOfCanvas) asBoldText 
  6030                     name:(nameOfSpec ? painter defaultNameOfCanvas) asBoldText 
  5952                     contents:props).
  6031                     contents:props).
  5953 
  6032 
  5954     model root expand.
  6033     model root expand.
  5955     self enableChannel:(aCanvas enableChannel).
  6034     self enableChannel:(aCanvas enableChannel).
  5956 !
  6035 !
  5957 
  6036 
  5958 canvasSpec
  6037 model root expand.
       
  6038     self enableChannel:(aCanvas enableChannel).
       
  6039 !
       
  6040 
       
  6041 pec
  5959     "returns spec assigned to canvas"
  6042     "returns spec assigned to canvas"
  5960 
  6043 
  5961     |spec list cls canvas|
  6044     |spec list cls canvas|
  5962 
  6045 
  5963     spec := self windowSpecClass new.
  6046     spec := self windowSpecClass new.
  5994                 thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:#action].
  6077                 thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:#action].
  5995     ].
  6078     ].
  5996   ^ spec
  6079   ^ spec
  5997 !
  6080 !
  5998 
  6081 
  5999 canvasSpec:aSpec
  6082 igned to canvas"
  6000     "update canvas from spec"
  6083 
  6001 
  6084     |spec list cls canvas|
  6002     |spec|
  6085 
  6003 
  6086     spec := self windowSpecClass new.
  6004     self setAttributesFromWindowSpec:aSpec.
  6087     canvas := self canvas.
  6005     spec := aSpec copy.
  6088 
  6006     spec  menu:nil.
  6089     spec fromView:(canvas topView) callBack:nil.
  6007     spec flags:nil.
  6090 
  6008 
  6091     windowSpec notNil ifTrue:[
  6009     spec setAttributesIn:(self canvas "topView") with:(UIBuilder new isEditing:true).
  6092         spec copyValuesFromSpec:windowSpec.
  6010 !
  6093     ].
  6011 
  6094 
  6012 exportedAspects
  6095     spec exportedAspects isNil ifTrue:[
  6013     "returns spec assigned to canvas"
  6096         (     (cls  := canvas className) notNil
  6014 
  6097          and:[(cls  := canvas resolveName:cls) notNil]
  6015     windowSpec isNil ifTrue:[^ #()].
  6098         ) ifTrue:[
  6016     ^ windowSpec exportedAspects ? #()
  6099             list := cls perform:#aspectSelectors ifNotUnderstood:nil.
  6017 
  6100         ].
  6018 !
  6101         spec setExportedAspectsFrom:list.
  6019 
  6102         windowSpec notNil ifTrue:[
  6020 itemOfView:aView
  6103             windowSpec exportedAspects:(spec exportedAspects).
  6021     "returns item assigned to view or nil"
  6104         ]
  6022 
  6105     ].
  6023     aView notNil ifTrue:[
  6106 
       
  6107     self propertiesDo:[:aProp| 
       
  6108         |propsSpec|
       
  6109 
       
  6110         spec exportedAspectsAddKey:(aProp model) type:nil.
       
  6111         propsSpec := aProp spec.
       
  6112         propsSpec aspectSelectors 
       
  6113                 select:[:a | a isString or:[a isSymbol]] 
       
  6114                 thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:nil].
       
  6115         propsSpec actionSelectors 
       
  6116                 select:[:a | a isString or:[a isSymbol]] 
       
  6117                 thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:#action].
       
  6118     ].
       
  6119   ^ spec
       
  6120 !
       
  6121 
       
  6122 spec := self windowSpecClass new.
       
  6123     canvas := self canvas.
       
  6124 
       
  6125     spec fromView:(canvas topView) callBack:nil.
       
  6126 
       
  6127     windowSpec notNil ifTrue:[
       
  6128         spec copyValuesFromSpec:windowSpec.
       
  6129     ].
       
  6130 
       
  6131     spec exportedAspects isNil ifTrue:[
       
  6132         (     (cls  := canvas className) notNil
       
  6133          and:[(cls  := canvas resolveName:cls) notNil]
       
  6134         ) ifTrue:[
       
  6135             list := cls perform:#aspectSelectors ifNotUnderstood:nil.
       
  6136         ].
       
  6137         spec setExportedAspectsFrom:list.
       
  6138         windowSpec notNil ifTrue:[
       
  6139             windowSpec exportedAspects:(spec exportedAspects).
       
  6140         ]
       
  6141     ].
       
  6142 
       
  6143     self propertiesDo:[:aProp| 
       
  6144         |propsSpec|
       
  6145 
       
  6146         spec exportedAspectsAddKey:(aProp model) type:nil.
       
  6147         propsSpec := aProp spec.
       
  6148         propsSpec aspectSelectors 
       
  6149                 select:[:a | a isString or:[a isSymbol]] 
       
  6150                 thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:nil].
       
  6151         propsSpec actionSelectors 
       
  6152                 select:[:a | a isString or:[a isSymbol]] 
       
  6153                 thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:#action].
       
  6154     ].
       
  6155   ^ spec
       
  6156 !
       
  6157 
       
  6158 l.
       
  6159 
       
  6160     windowSpec notNil ifTrue:[
       
  6161         spec copyValuesFromSpec:windowSpec.
       
  6162     ].
       
  6163 
       
  6164     spec exportedAspects isNil ifTrue:[
       
  6165         (     (cls  := canvas className) notNil
       
  6166          and:[(cls  := canvas resolveName:cls) notNil]
       
  6167         ) ifTrue:[
       
  6168             list := cls perform:#aspectSelectors ifNotUnderstood:nil.
       
  6169         ].
       
  6170         spec setExportedAspectsFrom:list.
       
  6171         windowSpec notNil ifTrue:[
       
  6172             windowSpec exportedAspects:(spec exportedAspects).
       
  6173         ]
       
  6174     ].
       
  6175 
       
  6176     self propertiesDo:[:aProp| 
       
  6177         |propsSpec|
       
  6178 
       
  6179         spec exportedAspectsAddKey:(aProp model) type:nil.
       
  6180         propsSpec := aProp spec.
       
  6181         propsSpec aspectSelectors 
       
  6182                 select:[:a | a isString or:[a isSymbol]] 
       
  6183                 thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:nil].
       
  6184         propsSpec actionSelectors 
       
  6185                 select:[:a | a isString or:[a isSymbol]] 
       
  6186                 thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:#action].
       
  6187     ].
       
  6188   ^ spec
       
  6189 ! !
       
  6190 
       
  6191 !UIPainter::TreeView methodsFor:'accessing-property'!
       
  6192 
       
  6193 as className) notNil
       
  6194          and:[(cls  := canvas resolveName:cls) notNil]
       
  6195         ) ifTrue:[
       
  6196             list := cls perform:#aspectSelectors ifNotUnderstood:nil.
       
  6197         ].
       
  6198         spec setExportedAspectsFrom:list.
       
  6199         windowSpec notNil ifTrue:[
       
  6200             windowSpec exportedAspects:(spec exportedAspects).
       
  6201         ]
       
  6202     ].
       
  6203 
       
  6204     self propertiesDo:[:aProp| 
       
  6205         |propsSpec|
       
  6206 
       
  6207         spec exportedAspectsAddKey:(aProp model) type:nil.
       
  6208         propsSpec := aProp spec.
       
  6209         propsSpec aspectSelectors 
       
  6210                 select:[:a | a isString or:[a isSymbol]] 
       
  6211                 thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:nil].
       
  6212         propsSpec actionSelectors 
       
  6213                 select:[:a | a isString or:[a isSymbol]] 
       
  6214                 thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:#action].
       
  6215     ].
       
  6216   ^ spec
       
  6217 !
       
  6218 
       
  6219 stood:nil.
       
  6220         ].
       
  6221         spec setExportedAspectsFrom:list.
       
  6222         windowSpec notNil ifTrue:[
       
  6223             windowSpec exportedAspects:(spec exportedAspects).
       
  6224         ]
       
  6225     ].
       
  6226 
       
  6227     self propertiesDo:[:aProp| 
       
  6228         |propsSpec|
       
  6229 
       
  6230         spec exportedAspectsAddKey:(aProp model) type:nil.
       
  6231         propsSpec := aProp spec.
       
  6232         propsSpec aspectSelectors 
       
  6233                 select:[:a | a isString or:[a isSymbol]] 
       
  6234                 thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:nil].
       
  6235         propsSpec actionSelectors 
       
  6236                 select:[:a | a isString or:[a isSymbol]] 
       
  6237                 thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:#action].
       
  6238     ].
       
  6239   ^ spec
       
  6240 !
       
  6241 
       
  6242 esDo:[:aProp| 
       
  6243         |propsSpec|
       
  6244 
       
  6245         spec exportedAspectsAddKey:(aProp model) type:nil.
       
  6246         propsSpec := aProp spec.
       
  6247         propsSpec aspectSelectors 
       
  6248                 select:[:a | a isString or:[a isSymbol]] 
       
  6249                 thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:nil].
       
  6250         propsSpec actionSelectors 
       
  6251                 select:[:a | a isString or:[a isSymbol]] 
       
  6252                 thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:#action].
       
  6253     ].
       
  6254   ^ spec
       
  6255 ! !
       
  6256 
       
  6257 !UIPainter::TreeView methodsFor:'adding & removing'!
       
  6258 
       
  6259 sSymbol]] 
       
  6260                 thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:#action].
       
  6261     ].
       
  6262   ^ spec
       
  6263 !
       
  6264 
       
  6265 spec
       
  6266 !
       
  6267 
       
  6268 aView notNil ifTrue:[
  6024         self allItemsDo:[:anItem|
  6269         self allItemsDo:[:anItem|
  6025             (anItem contents view == aView) ifTrue:[^ anItem]
  6270             (anItem contents view == aView) ifTrue:[^ anItem]
  6026         ]
  6271         ]
  6027     ].
  6272     ].
  6028     ^ nil
  6273     ^ nil
  6029 
  6274 
  6030 
  6275 
  6031 !
  6276 !
  6032 
  6277 
  6033 lastDrawnMaster
  6278 ass
  6034     "returns the lastDrawnMaster"
       
  6035 
       
  6036     ^ lastDrawnMaster
       
  6037 
       
  6038 
       
  6039 !
       
  6040 
       
  6041 painter
       
  6042     ^ painter
       
  6043 !
       
  6044 
       
  6045 painter:something
       
  6046     painter := something.
       
  6047 !
       
  6048 
       
  6049 windowSpecClass
       
  6050     "returns the default  windowSpecClass (WindowSpec)"
       
  6051 
       
  6052     ^ windowSpecClass ? WindowSpec
       
  6053 !
       
  6054 
       
  6055 windowSpecClass:aClass
       
  6056     "set the default windowSpecClass"
  6279     "set the default windowSpecClass"
  6057 
  6280 
  6058     ^ windowSpecClass := aClass
  6281     ^ windowSpecClass := aClass
  6059 ! !
  6282 ! !
  6060 
  6283 
  6061 !UIPainter::TreeView methodsFor:'accessing-property'!
  6284 !UIPainter::TreeView methodsFor:'building'!
  6062 
  6285 
  6063 propertiesDo:aOneArgBlock
  6286 yDetect:aOneArgBlock
  6064     "evaluates the argument a block on each property"
       
  6065 
       
  6066     self allItemsDo:[:anItem| aOneArgBlock value:(anItem contents)]
       
  6067 
       
  6068 
       
  6069 !
       
  6070 
       
  6071 propertyDetect:aOneArgBlock
       
  6072     "evaluates the block on each property"
  6287     "evaluates the block on each property"
  6073 
  6288 
  6074     self allItemsDo:[:anItem|
  6289     self allItemsDo:[:anItem|
  6075         (aOneArgBlock value:(anItem contents)) ifTrue:[^ anItem contents]
  6290         (aOneArgBlock value:(anItem contents)) ifTrue:[^ anItem contents]
  6076     ].
  6291     ].
  6077     ^ nil
  6292     ^ nil
  6078 
  6293 
  6079 !
  6294 !
  6080 
  6295 
  6081 propertySelected
  6296 y beforeIndex:anIndex
  6082     "returns current selected property or nil in case of multi selection
       
  6083      or empty selection "
       
  6084 
       
  6085     |idx|
       
  6086 
       
  6087     selection size == 1 ifTrue:[
       
  6088         (idx := selection first) ~~ 1 ifTrue:[          "canvas: not yet supported"
       
  6089             ^ (listOfNodes at:idx) contents
       
  6090         ]
       
  6091     ].
       
  6092     ^ nil
       
  6093 
       
  6094 ! !
       
  6095 
       
  6096 !UIPainter::TreeView methodsFor:'adding & removing'!
       
  6097 
       
  6098 addProperty:aProperty
       
  6099     "adds a new item"
       
  6100 
       
  6101     ^ self addProperty:aProperty beforeIndex:nil.
       
  6102 !
       
  6103 
       
  6104 addProperty:aProperty beforeIndex:anIndex
       
  6105     "adds a new item"
  6297     "adds a new item"
  6106 
  6298 
  6107     |parent treeItem index| 
  6299     |parent treeItem index| 
  6108 
  6300 
  6109     parent := self detectItemCorespondingToView:(aProperty view superView).
  6301     parent := self detectItemCorespondingToView:(aProperty view superView).
  6115     (anIndex notNil and:[anIndex > 0]) ifTrue:[
  6307     (anIndex notNil and:[anIndex > 0]) ifTrue:[
  6116         index := anIndex min:index.
  6308         index := anIndex min:index.
  6117     ].
  6309     ].
  6118     model add:treeItem beforeIndex:index below:parent.
  6310     model add:treeItem beforeIndex:index below:parent.
  6119     ^ treeItem
  6311     ^ treeItem
  6120 !
  6312 ! !
  6121 
  6313 
  6122 removeAll
  6314 !UIPainter::TreeView methodsFor:'canvas selection'!
  6123     "removes all items other than canvas"
  6315 
  6124 
  6316 copy do:[:aView|
  6125     lastDrawnMaster := nil.
       
  6126     windowSpec := nil.
       
  6127 
       
  6128     self canvas components copy do:[:aView|
       
  6129         aView destroy
  6317         aView destroy
  6130     ].
  6318     ].
  6131     self canvas subViews copy do:[:aView|
  6319     self canvas subViews copy do:[:aView|
  6132         "/ care to not destroy the transparent input view
  6320         "/ care to not destroy the transparent input view
  6133         (aView isInputOnly) ifFalse:[aView destroy]
  6321         (aView isInputOnly) ifFalse:[aView destroy]
  6134     ].
  6322     ].
  6135     model root name: painter defaultNameOfCanvas asBoldText.
  6323     model root name: painter defaultNameOfCanvas asBoldText.
  6136     model removeAllOtherThanRoot.
  6324     model removeAllOtherThanRoot.
  6137 !
  6325 !
  6138 
  6326 
  6139 removeView:aView
  6327 orComponents:aSpecArray named:specNameSymbol
  6140     "removes a view"
       
  6141 
       
  6142     |item prnt|
       
  6143 
       
  6144     ((item := self itemOfView:aView) notNil and:[(prnt := item parent) notNil]) ifTrue:[
       
  6145         aView destroy.
       
  6146         prnt contents view sizeChanged:nil.
       
  6147         model remove:item
       
  6148     ]
       
  6149 
       
  6150 
       
  6151 ! !
       
  6152 
       
  6153 !UIPainter::TreeView methodsFor:'building'!
       
  6154 
       
  6155 generateFullSpecForComponents:aSpecArray named:specNameSymbol
       
  6156     "generates a full spec from aSpecArray"
  6328     "generates a full spec from aSpecArray"
  6157 
  6329 
  6158     |fullSpec winSpec|
  6330     |fullSpec winSpec|
  6159 
  6331 
  6160     fullSpec := FullSpec new.
  6332     fullSpec := FullSpec new.
  6174     ].    
  6346     ].    
  6175     winSpec name: winSpec label.
  6347     winSpec name: winSpec label.
  6176     ^ fullSpec.
  6348     ^ fullSpec.
  6177 !
  6349 !
  6178 
  6350 
  6179 setAttributesFromWindowSpec:aWindowSpec
  6351 wSpec (which should not)
  6180     "sets a window spec from aWindowSpec and applies some attributes
  6352         self canvas gridShown ifTrue:[
  6181      to the canvas."
  6353             fullSpec window backgroundColor:nil.    
  6182 
  6354         ].
  6183     |name canvasView builder|
  6355     ] ifFalse:[
       
  6356         winSpec copyValuesFromSpec:windowSpec.
       
  6357     ].    
       
  6358     winSpec name: winSpec label.
       
  6359     ^ fullSpec.
       
  6360 !
       
  6361 
       
  6362 |name canvasView builder|
  6184 
  6363 
  6185     windowSpec := (self windowSpecClass) new copyValuesFromSpec:aWindowSpec.
  6364     windowSpec := (self windowSpecClass) new copyValuesFromSpec:aWindowSpec.
  6186     canvasView := self canvas.
  6365     canvasView := self canvas.
  6187 
  6366 
  6188     builder := UIBuilder new isEditing:true.
  6367     builder := UIBuilder new isEditing:true.
  6192     canvasView topView name:name.
  6371     canvasView topView name:name.
  6193     self canvasNameChanged:name.
  6372     self canvasNameChanged:name.
  6194     self application treeSelectionChanged.
  6373     self application treeSelectionChanged.
  6195 ! !
  6374 ! !
  6196 
  6375 
  6197 !UIPainter::TreeView methodsFor:'canvas selection'!
  6376 !UIPainter::TreeView methodsFor:'change & update'!
  6198 
  6377 
  6199 canvasSelection:aSelection
  6378 := aWindowSpec label.
  6200     "canvas changed its selection
  6379     canvasView topView name:name.
  6201     "
  6380     self canvasNameChanged:name.
  6202     |sel list size|
  6381     self application treeSelectionChanged.
  6203 
  6382 !
  6204     ((sel := aSelection) isNil or:[sel isCollection]) ifFalse:[
  6383 
  6205         sel := Array with:sel
  6384 True:[
  6206     ].
       
  6207 
       
  6208     (size := sel size) ~~ 0 ifTrue:[
       
  6209         list := OrderedCollection new:size.
  6385         list := OrderedCollection new:size.
  6210 
  6386 
  6211         sel do:[:aView|
  6387         sel do:[:aView|
  6212             |item|
  6388             |item|
  6213 
  6389 
  6219         sel := list collect:[:anItem| self indexOfNode:anItem ].
  6395         sel := list collect:[:anItem| self indexOfNode:anItem ].
  6220     ].
  6396     ].
  6221     self canvasEventsDisabledDo:[ self selection:sel ].            
  6397     self canvasEventsDisabledDo:[ self selection:sel ].            
  6222 !
  6398 !
  6223 
  6399 
  6224 canvasSelectionAdd:aView
  6400 ]
  6225     "canvas adds a view to current selection
  6401         ].
  6226     "
  6402         sel := list collect:[:anItem| self indexOfNode:anItem ].
  6227     |item index oldSel|
  6403     ].
  6228 
  6404     self canvasEventsDisabledDo:[ self selection:sel ].            
  6229     item := self itemOfView:aView.
  6405 ! !
  6230 
  6406 
  6231     item notNil ifTrue:[
  6407 !UIPainter::TreeView methodsFor:'drag & drop'!
  6232         model doMakeVisible:item.
  6408 
  6233 
  6409 election 
  6234         (index := self indexOfNode:item) ~~ 0 ifTrue:[
       
  6235             oldSel := selection copy.
       
  6236             self addToSelection:index.
       
  6237             self selectionChangedFrom:oldSel
       
  6238         ]        
       
  6239     ]            
       
  6240 !
       
  6241 
       
  6242 canvasSelectionRemove:aView
       
  6243     "canvas removes a view from current selection
       
  6244     "
       
  6245     |item index oldSel|
       
  6246 
       
  6247     (     (item := self itemOfView:aView) notNil
       
  6248      and:[(index := self indexOfNode:item) ~~ 0
       
  6249      and:[self isInSelection:index]]
       
  6250     ) ifTrue:[
       
  6251         oldSel := selection copy.
       
  6252         self removeFromSelection:index.
       
  6253         self selectionChangedFrom:oldSel.
       
  6254     ].
       
  6255 !
       
  6256 
       
  6257 selectedViews
       
  6258     ^ self selection 
       
  6259         collect:[:index |
  6410         collect:[:index |
  6260             |node view|
  6411             |node view|
  6261 
  6412 
  6262             node := listOfNodes at:index.
  6413             node := listOfNodes at:index.
  6263             view := node contents view.
  6414             view := node contents view.
  6264             view
  6415             view
  6265         ]
  6416         ]
  6266 ! !
  6417 !
  6267 
  6418 
  6268 !UIPainter::TreeView methodsFor:'change & update'!
  6419 view
  6269 
  6420         ]
  6270 canvasNameChanged:aName
  6421 !
  6271     "called if identification name assigned to window (canvas) changed
  6422 
  6272     "
  6423 fNodes at:1.
  6273     |name node|
       
  6274 
       
  6275     node := listOfNodes at:1.
       
  6276 
  6424 
  6277     (    aName size ~~ 0
  6425     (    aName size ~~ 0
  6278      and:[(name := aName string withoutSeparators) size ~~ 0
  6426      and:[(name := aName string withoutSeparators) size ~~ 0
  6279      and:[(self propertyDetect:[:p| p name = name]) isNil
  6427      and:[(self propertyDetect:[:p| p name = name]) isNil
  6280      and:[node name ~= name]]]
  6428      and:[node name ~= name]]]
  6282         node name: name asBoldText.
  6430         node name: name asBoldText.
  6283         node changed.   
  6431         node changed.   
  6284     ].
  6432     ].
  6285 !
  6433 !
  6286 
  6434 
  6287 layoutChanged
  6435 ]]
  6288     "layout of any component changed; in case of single selection, the
  6436     ) ifTrue:[
  6289      application will be informed to update its layout
  6437         node name: name asBoldText.
       
  6438         node changed.   
       
  6439     ].
       
  6440 !
       
  6441 
       
  6442 d to update its layout
  6290     "
  6443     "
  6291     selection size == 1 ifTrue:[
  6444     selection size == 1 ifTrue:[
  6292         self application layoutChanged
  6445         self application layoutChanged
  6293     ]
  6446     ]
  6294 
  6447 
  6295 
  6448 
  6296 !
  6449 !
  6297 
  6450 
  6298 propertyChanged:aProperty
  6451 perty changed
  6299     "property of view derived from argument a property changed
       
  6300     "
  6452     "
  6301     |item idx end|
  6453     |item idx end|
  6302 
  6454 
  6303     item := self itemOfView:(aProperty view).
  6455     item := self itemOfView:(aProperty view).
  6304 
  6456 
  6327             self application propertyChanged
  6479             self application propertyChanged
  6328         ]
  6480         ]
  6329     ].
  6481     ].
  6330 
  6482 
  6331 
  6483 
       
  6484 !
       
  6485 
       
  6486 ame = aProperty name ifFalse:[
       
  6487             idx := self firstLineShown.
       
  6488 
       
  6489             (end := self lastLineShown) > listOfNodes size ifTrue:[
       
  6490                 end := listOfNodes size
       
  6491             ].                          
       
  6492             item changed.   
       
  6493 
       
  6494             [idx <= end] whileTrue:[
       
  6495                 (listOfNodes at:idx) == item ifTrue:[
       
  6496                     self redrawLine:idx.                "/ is visible; redraw line
       
  6497                     end := 0
       
  6498                 ] ifFalse:[
       
  6499                     idx := idx + 1
       
  6500                 ]
       
  6501             ]
       
  6502         ].
       
  6503 
       
  6504         self selectedNode == item ifTrue:[              "/ inform application
       
  6505             self application propertyChanged
       
  6506         ]
       
  6507     ].
       
  6508 
       
  6509 
       
  6510 !
       
  6511 
       
  6512 ].                          
       
  6513             item changed.   
       
  6514 
       
  6515             [idx <= end] whileTrue:[
       
  6516                 (listOfNodes at:idx) == item ifTrue:[
       
  6517                     self redrawLine:idx.                "/ is visible; redraw line
       
  6518                     end := 0
       
  6519                 ] ifFalse:[
       
  6520                     idx := idx + 1
       
  6521                 ]
       
  6522             ]
       
  6523         ].
       
  6524 
       
  6525         self selectedNode == item ifTrue:[              "/ inform application
       
  6526             self application propertyChanged
       
  6527         ]
       
  6528     ].
       
  6529 
       
  6530 
  6332 ! !
  6531 ! !
  6333 
  6532 
  6334 !UIPainter::TreeView methodsFor:'drag & drop'!
  6533 !UIPainter::TreeView methodsFor:'enumerating'!
  6335 
  6534 
  6336 canDrop:aDropContext
  6535 end := 0
  6337     "can drop ? -> delegate to canvas"
  6536                 ] ifFalse:[
  6338 
  6537                     idx := idx + 1
  6339     ^ self canvas canDrop:aDropContext
  6538                 ]
  6340 
  6539             ]
  6341     "Modified: / 13-10-2006 / 16:08:43 / cg"
  6540         ].
  6342 !
  6541 
  6343 
  6542         self selectedNode == item ifTrue:[              "/ inform application
  6344 canDrop:aDropContext at:aPoint
  6543             self application propertyChanged
       
  6544         ]
       
  6545     ].
       
  6546 
       
  6547 
       
  6548 ! !
       
  6549 
       
  6550 !UIPainter::TreeView methodsFor:'event handling'!
       
  6551 
       
  6552 rm application
       
  6553             self application propertyChanged
       
  6554         ]
       
  6555     ].
       
  6556 
       
  6557 
       
  6558 !
       
  6559 
       
  6560 ntext at:aPoint
  6345     "can drop ? -> delegate to canvas"
  6561     "can drop ? -> delegate to canvas"
  6346 
  6562 
  6347     ^ self canvas canDrop:aDropContext at:aPoint
  6563     ^ self canvas canDrop:aDropContext at:aPoint
  6348 
  6564 
  6349     "Created: / 13-10-2006 / 12:35:53 / cg"
  6565     "Created: / 13-10-2006 / 12:35:53 / cg"
  6350     "Modified: / 13-10-2006 / 16:08:46 / cg"
  6566     "Modified: / 13-10-2006 / 16:08:46 / cg"
  6351 !
  6567 !
  6352 
  6568 
  6353 canDropObjects:aCollectionOfDropObjects
  6569 / cg"
  6354     "can drop ? -> delegate to canvas"
  6570     "Modified: / 13-10-2006 / 16:08:46 / cg"
  6355 
  6571 ! !
  6356     ^ self canvas canDropObjects:aCollectionOfDropObjects
  6572 
  6357 
  6573 !UIPainter::TreeView methodsFor:'initialization'!
  6358     "Created: / 13-10-2006 / 16:08:31 / cg"
  6574 
  6359 !
  6575 cg"
  6360 
       
  6361 canDropObjects:aCollectionOfDropObjects at:aPoint
       
  6362     "can drop ? -> delegate to canvas"
       
  6363 
       
  6364     ^ self canvas canDropObjects:aCollectionOfDropObjects at:aPoint
       
  6365 
       
  6366     "Created: / 13-10-2006 / 16:08:35 / cg"
       
  6367 !
       
  6368 
       
  6369 drop:aDropContext
       
  6370     "drop objects -> delegate to canvas"
       
  6371 
       
  6372     self canvas drop:aDropContext
       
  6373 
       
  6374     "Created: / 13-10-2006 / 12:35:59 / cg"
       
  6375     "Modified: / 13-10-2006 / 16:09:04 / cg"
  6576     "Modified: / 13-10-2006 / 16:09:04 / cg"
  6376 !
  6577 !
  6377 
  6578 
  6378 drop:aDropContext at:aPoint
  6579 "Modified: / 13-10-2006 / 16:09:07 / cg"
  6379     "drop objects -> delegate to canvas"
  6580 !
  6380 
  6581 
  6381     self canvas drop:aDropContext at:nil
  6582 : / 13-10-2006 / 16:08:56 / cg"
  6382 
       
  6383     "Modified: / 13-10-2006 / 16:09:07 / cg"
       
  6384 !
       
  6385 
       
  6386 dropObjects:aCollectionOfDropObjects
       
  6387     "drop objects -> delegate to canvas"
       
  6388 
       
  6389     self canvas dropObjects:aCollectionOfDropObjects
       
  6390 
       
  6391     "Created: / 13-10-2006 / 16:08:51 / cg"
       
  6392 !
       
  6393 
       
  6394 dropObjects:aCollectionOfDropObjects at:aPoint
       
  6395     "drop objects -> delegate to canvas"
       
  6396 
       
  6397     self canvas dropObjects:aCollectionOfDropObjects at:nil
       
  6398 
       
  6399     "Created: / 13-10-2006 / 16:08:56 / cg"
       
  6400 ! !
  6583 ! !
  6401 
  6584 
  6402 !UIPainter::TreeView methodsFor:'enumerating'!
  6585 !UIPainter::TreeView methodsFor:'private'!
  6403 
  6586 
  6404 allItemsDo:aOneArgBlock
  6587 ock
  6405     "evaluates the argument a block on each item other than the canvas"
  6588 
  6406 
  6589 
  6407     model root allChildrenDo:aOneArgBlock
  6590 !
       
  6591 
       
  6592 Clicked
       
  6593     ]
  6408 
  6594 
  6409 
  6595 
  6410 ! !
  6596 ! !
  6411 
  6597 
  6412 !UIPainter::TreeView methodsFor:'event handling'!
  6598 !UIPainter::TreeView methodsFor:'queries'!
  6413 
  6599 
  6414 canvasEventsDisabledDo:aBlock
  6600 [
  6415     "evaluates the block without raising selection changed notifications to canvas"
       
  6416 
       
  6417     |restoreCanvasEvents|
       
  6418 
       
  6419     restoreCanvasEvents  := canvasEventsDisabled.
       
  6420     canvasEventsDisabled := true.
       
  6421     aBlock value.
       
  6422     canvasEventsDisabled := restoreCanvasEvents.
       
  6423 !
       
  6424 
       
  6425 doubleClicked
       
  6426     "disables collapsing of the root item"
       
  6427 
       
  6428     self selectedNode == model root ifFalse:[
       
  6429         super doubleClicked
       
  6430     ]
       
  6431 
       
  6432 
       
  6433 !
       
  6434 
       
  6435 redrawLabelAt:x y:yTop index:anIndex
       
  6436     "draws a tiny rectangle for indicating the master node (first selected node)"
       
  6437 
       
  6438     |dX|
       
  6439 
       
  6440     super redrawLabelAt:x y:yTop index:anIndex.
       
  6441 
       
  6442     ((selection size > 1) and: [selection first == anIndex]) ifTrue:[
       
  6443         dX := textInset - 1.
       
  6444         self paint:(Color red). "/ self application painter handleMasterColor.
       
  6445         self fillRectangleX:(x - dX - 2)
       
  6446                           y:yTop + ((fontHeight - dX) // 2)
       
  6447                       width:dX
       
  6448                      height:dX
       
  6449     ]
       
  6450 ! !
       
  6451 
       
  6452 !UIPainter::TreeView methodsFor:'initialization'!
       
  6453 
       
  6454 iconForNode:aNode
       
  6455     |spec|       
       
  6456 
       
  6457     spec := aNode contents spec.
       
  6458     spec isNil ifTrue: [
       
  6459         ^ WindowSpec icon
       
  6460     ] ifFalse:[
       
  6461         ^ spec icon
       
  6462     ]
       
  6463 !
       
  6464 
       
  6465 initialize
       
  6466     "initialize the tree view; multiple select and tree item actions"
       
  6467 
       
  6468     super initialize.
       
  6469 
       
  6470     self multipleSelectOk:true.
       
  6471     canvasEventsDisabled := false.
       
  6472     self showDirectoryIndicator: true.
       
  6473     self showDirectoryIndicatorForRoot: false.
       
  6474 
       
  6475     self model 
       
  6476         iconAction:[:aNode| self iconForNode:aNode];
       
  6477         labelAction: [:aNode | self labelForNode:aNode].
       
  6478 !
       
  6479 
       
  6480 labelForNode:aNode
       
  6481     |spec|
       
  6482 
       
  6483     spec := aNode contents spec.
       
  6484     spec notNil ifTrue: [
       
  6485         ^ self nameForSpecInList:spec
       
  6486     ] ifFalse:[
       
  6487         ^ aNode name
  6601         ^ aNode name
  6488     ]
  6602     ]
  6489 ! !
  6603 !
  6490 
  6604 
  6491 !UIPainter::TreeView methodsFor:'private'!
  6605 aspect := aSpec nameOfMainAspect.
  6492 
       
  6493 nameForSpecInList:aSpec
       
  6494     "returns the tree item label for aSpec"
       
  6495 
       
  6496     |aspect aspectPrefix nameString viewClassString|
       
  6497 
       
  6498     nameString := aSpec name ? ''.
       
  6499     viewClassString := '[',aSpec viewClass name,']' .
       
  6500 
       
  6501     aspect := aSpec nameOfMainAspect.
       
  6502     aspect notNil ifTrue:[
  6606     aspect notNil ifTrue:[
  6503         aspectPrefix := '(',aspect allBold ,') '
  6607         aspectPrefix := '(',aspect allBold ,') '
  6504     ] ifFalse:[
  6608     ] ifFalse:[
  6505         aspectPrefix := ''.
  6609         aspectPrefix := ''.
  6506     ].
  6610     ].
  6508     ^ aspectPrefix, nameString, ': ', viewClassString
  6612     ^ aspectPrefix, nameString, ': ', viewClassString
  6509 
  6613 
  6510     "Modified: / 17-08-2011 / 09:10:31 / cg"
  6614     "Modified: / 17-08-2011 / 09:10:31 / cg"
  6511 !
  6615 !
  6512 
  6616 
  6513 selectionChangedFrom:oldSelection
  6617 m:oldSelection
  6514     "selection has changed. update master selection and raise notification
  6618     "selection has changed. update master selection and raise notification
  6515      to canvas in case of enabled cvs events
  6619      to canvas in case of enabled cvs events
  6516     "
  6620     "
  6517     |sel size|
  6621     |sel size|
  6518 
  6622 
  6545         ]
  6649         ]
  6546     ]         
  6650     ]         
  6547     ifFalse: [
  6651     ifFalse: [
  6548         lastDrawnMaster := nil
  6652         lastDrawnMaster := nil
  6549     ] 
  6653     ] 
  6550 ! !
  6654 !
  6551 
  6655 
  6552 !UIPainter::TreeView methodsFor:'queries'!
  6656 ].             
  6553 
  6657     size = 1 ifTrue:[
  6554 canChangeOrderInContainer
  6658         oldSelection size > 1 ifTrue: [
  6555     "returns true if any selection exists and all widgets in the selection
  6659             (listOfNodes at:lastDrawnMaster) retrieveLabel.
  6556      can change their layout through to a move or align operation"
  6660             self redrawLine: lastDrawnMaster. 
       
  6661             lastDrawnMaster := selection first
       
  6662         ]
       
  6663     ].
       
  6664     size > 1 ifTrue:[
       
  6665         selection first ~~ lastDrawnMaster ifTrue: [
       
  6666             (listOfNodes at:selection first) retrieveLabel.
       
  6667             lastDrawnMaster notNil ifTrue: [(listOfNodes at:lastDrawnMaster) retrieveLabel].
       
  6668             self redrawLine: lastDrawnMaster. 
       
  6669             self redrawLine: (lastDrawnMaster := selection first)
       
  6670         ]
       
  6671     ]         
       
  6672     ifFalse: [
       
  6673         lastDrawnMaster := nil
       
  6674     ] 
       
  6675 !
       
  6676 
       
  6677 er := selection first)
       
  6678         ]
       
  6679     ]         
       
  6680     ifFalse: [
       
  6681         lastDrawnMaster := nil
       
  6682     ] 
       
  6683 !
       
  6684 
       
  6685 on"
  6557 
  6686 
  6558     ^(selection size == 1)  and: 
  6687     ^(selection size == 1)  and: 
  6559     [(selection at: 1) ~~ 1 and:   
  6688     [(selection at: 1) ~~ 1 and:   
  6560     [self selectedNode parent children size > 1]] 
  6689     [self selectedNode parent children size > 1]] 
  6561 
  6690 
  6562 
  6691 
  6563 !
  6692 !
  6564 
  6693 
  6565 canExchangeSelectionLayouts 
  6694 AlignSelection
  6566     "returns true if the selections size is exactly 2
       
  6567      and all widgets in the selection
       
  6568      can change their layout through to a move or align operation"
       
  6569 
       
  6570     selection size == 2 ifFalse:[
       
  6571         ^ false
       
  6572     ].
       
  6573     ^ self canMoveOrAlignSelection
       
  6574 !
       
  6575 
       
  6576 canMoveOrAlignSelection
       
  6577     "returns true if any selection exists and all widgets in the selection
  6695     "returns true if any selection exists and all widgets in the selection
  6578      can change their layout through to a move or align operation"
  6696      can change their layout through to a move or align operation"
  6579 
  6697 
  6580     selection isEmptyOrNil ifTrue:[
  6698     selection isEmptyOrNil ifTrue:[
  6581         ^ false
  6699         ^ false
  6595         ]
  6713         ]
  6596     ].
  6714     ].
  6597     ^ true
  6715     ^ true
  6598 !
  6716 !
  6599 
  6717 
  6600 canMoveSelectionIntoContainer
  6718 tyOrNil ifTrue:[
       
  6719         ^ false
       
  6720     ].
       
  6721 
       
  6722     selection do:[:i|
       
  6723         |node view|
       
  6724 
       
  6725         i == 1 ifTrue:[
       
  6726             "/ the tree node for the canvas itself.
       
  6727             ^ false
       
  6728         ].
       
  6729         node := listOfNodes at:i.
       
  6730         view := node contents view.
       
  6731         (self canvas canChangeLayoutOfView:view) ifFalse:[
       
  6732             ^ false
       
  6733         ]
       
  6734     ].
       
  6735     ^ true
       
  6736 !
       
  6737 
       
  6738 ^ false
       
  6739         ].
       
  6740         node := listOfNodes at:i.
       
  6741         view := node contents view.
       
  6742         (self canvas canChangeLayoutOfView:view) ifFalse:[
       
  6743             ^ false
       
  6744         ]
       
  6745     ].
       
  6746     ^ true
       
  6747 ! !
       
  6748 
       
  6749 !UIPainter::TreeView methodsFor:'searching'!
       
  6750 
       
  6751 ectionIntoContainer
  6601     "returns true in case that one widget is selected and can change its container
  6752     "returns true in case that one widget is selected and can change its container
  6602      widget to an element below"
  6753      widget to an element below"
  6603 
  6754 
  6604     |item oldParentItem newParentItem idx|
  6755     |item oldParentItem newParentItem idx|
  6605 
  6756 
  6611         ] startingAt:idx ifNone:nil.
  6762         ] startingAt:idx ifNone:nil.
  6612         ^ newParentItem notNil.
  6763         ^ newParentItem notNil.
  6613     ].
  6764     ].
  6614 
  6765 
  6615     ^ false
  6766     ^ false
  6616 !
  6767 ! !
  6617 
  6768 
  6618 canMoveSelectionOutOfContainer
  6769 !UIPainter::TreeView methodsFor:'user interaction'!
  6619     "returns true in case that one widget is selected which is contained within
  6770 
       
  6771 ] startingAt:idx ifNone:nil.
       
  6772         ^ newParentItem notNil.
       
  6773     ].
       
  6774 
       
  6775     ^ false
       
  6776 !
       
  6777 
       
  6778 rue in case that one widget is selected which is contained within
  6620      another widget"
  6779      another widget"
  6621 
  6780 
  6622     |item prnt|
  6781     |item prnt|
  6623 
  6782 
  6624     (     (item := self selectedNode) isNil
  6783     (     (item := self selectedNode) isNil
  6628         ^ false
  6787         ^ false
  6629     ].
  6788     ].
  6630     ^ true
  6789     ^ true
  6631 !
  6790 !
  6632 
  6791 
  6633 canResizeSelectedWidget
  6792 within a widget which allows to resize sub components"
  6634     "returns true in case of one widget selected and is contained
       
  6635      within a widget which allows to resize sub components"
       
  6636 
  6793 
  6637     |selectedNode|
  6794     |selectedNode|
  6638 
  6795 
  6639     (selectedNode := self selectedNode) notNil ifTrue:[
  6796     (selectedNode := self selectedNode) notNil ifTrue:[
  6640         (selectedNode := selectedNode parent) notNil ifTrue:[
  6797         (selectedNode := selectedNode parent) notNil ifTrue:[
  6642         ]
  6799         ]
  6643     ].
  6800     ].
  6644     ^ false
  6801     ^ false
  6645 !
  6802 !
  6646 
  6803 
  6647 canResizeSelection
  6804 ctionChangeAllowed 
  6648     "returns true if all selected widgets can be resized"
       
  6649 
       
  6650     selection isEmptyOrNil ifTrue:[ ^ false ].
       
  6651     ^ self canvas canResize:(self selectedViews)
       
  6652 !
       
  6653 
       
  6654 hasOneSelectionOtherThanCanvas
       
  6655     "returns true in case that one selection exists other than the canvas"
       
  6656 
       
  6657     ^ selection size == 1 and:[selection first ~~ 1]
       
  6658 !
       
  6659 
       
  6660 isCanvasSelected
       
  6661     "returns true in case of a single selection and the
       
  6662      selection is the canvas (index 1)"
       
  6663 
       
  6664     ^ selection size == 1 and:[self isInSelection:1]
       
  6665 ! !
       
  6666 
       
  6667 !UIPainter::TreeView methodsFor:'searching'!
       
  6668 
       
  6669 detectItemCorespondingToView:aView
       
  6670     "detects the item coresponding to the view. The item of the view or the first
       
  6671      subview providing the item is returned. If no property is detected nil is
       
  6672      returned"
       
  6673 
       
  6674     |view item|
       
  6675 
       
  6676     (view := aView) isNil ifTrue:[ ^ nil ].
       
  6677 
       
  6678     [(item := self itemOfView:view) isNil] whileTrue:[
       
  6679         (view := view superView) isNil ifTrue:[^ listOfNodes at:1]
       
  6680     ].
       
  6681     ^ item
       
  6682 ! !
       
  6683 
       
  6684 !UIPainter::TreeView methodsFor:'user interaction'!
       
  6685 
       
  6686 askForSelectionChangeAllowed 
       
  6687     selectConditionBlock notNil ifTrue:[
  6805     selectConditionBlock notNil ifTrue:[
  6688         ^ selectConditionBlock value:nil 
  6806         ^ selectConditionBlock value:nil 
  6689     ].
  6807     ].
  6690     ^ true
  6808     ^ true
  6691 !
  6809 !
  6692 
  6810 
  6693 doChangeParentOfSelectedItemTo:newParentItem
  6811 kForSelectionChangeAllowed ifFalse:[^ self].
  6694 
       
  6695     |canvas|
       
  6696 
       
  6697     newParentItem isNil ifTrue:[
       
  6698         ^ self
       
  6699     ].
       
  6700     self askForSelectionChangeAllowed ifFalse:[^ self].    
       
  6701     self setSelection:nil.
       
  6702 
       
  6703     canvas := self canvas.
       
  6704     canvas deleteSelection.
       
  6705     canvas setSelection:(newParentItem contents view) withRedraw:false.
       
  6706     canvas pasteWithLayout.
       
  6707 !
       
  6708 
       
  6709 doSortItems
       
  6710     "sort items by their top-left position"
       
  6711 
       
  6712     |selectedItems parent sortedItems newChildren itemList parentView|
       
  6713 
       
  6714     self askForSelectionChangeAllowed ifFalse:[^ self].
       
  6715 
  6812 
  6716     selectedItems := self selectedNodes.
  6813     selectedItems := self selectedNodes.
  6717     selectedItems size <= 1 ifTrue:[^ self].
  6814     selectedItems size <= 1 ifTrue:[^ self].
  6718     parent := selectedItems first parent.
  6815     parent := selectedItems first parent.
  6719     (parent isNil or:[(selectedItems conform:[:e| e parent == parent]) not]) ifTrue:[^ self].
  6816     (parent isNil or:[(selectedItems conform:[:e| e parent == parent]) not]) ifTrue:[^ self].
  6747     self canvas showSelection.
  6844     self canvas showSelection.
  6748 
  6845 
  6749     self selectNodes:itemList asOrderedCollection.
  6846     self selectNodes:itemList asOrderedCollection.
  6750 !
  6847 !
  6751 
  6848 
  6752 doStepIn
  6849 sNil or:[(selectedItems conform:[:e| e parent == parent]) not]) ifTrue:[^ self].
  6753     "move the currently selected widget into the next available container below"
  6850 
  6754     
  6851     sortedItems := selectedItems sort:[:a :b| 
  6755     |item oldParentItem newParentItem idx|
  6852                             a contents view origin isLeftOrAbove:(b contents view origin)].
  6756 
  6853     itemList := selectedItems asIdentitySet.
  6757     item := self selectedNode.
  6854 
  6758     (item notNil and:[(oldParentItem := item parent) notNil]) ifTrue:[
  6855     newChildren := parent children collect:[:eachChild|
  6759         idx := (oldParentItem indexOfChild:item) + 1.
  6856         (itemList includes:eachChild) ifTrue:[
  6760         newParentItem := oldParentItem children 
  6857             sortedItems removeFirst.
  6761                     detect:[:eachChild | eachChild contents spec class supportsSubComponents]
  6858         ] ifFalse:[
  6762                     startingAt:idx
  6859             eachChild.
  6763                     ifNone:nil.
       
  6764         newParentItem notNil ifTrue:[
       
  6765             self doChangeParentOfSelectedItemTo:newParentItem
       
  6766         ].
  6860         ].
  6767     ]
  6861     ].
  6768 !
       
  6769 
       
  6770 doStepOut
       
  6771     |item|
       
  6772 
       
  6773     item := self selectedNode.    
       
  6774     (item notNil and:[(item := item parent) notNil]) ifTrue:[
       
  6775         self doChangeParentOfSelectedItemTo:(item parent)
       
  6776     ].
       
  6777 !
       
  6778 
       
  6779 doStepOver:anIndex
       
  6780     "moves child 'anIndex' forward or backward in list of children"
       
  6781 
       
  6782     |item idx size parentItem parentItemsView itemsView canvas|
       
  6783 
       
  6784     self askForSelectionChangeAllowed ifFalse:[^ self].
       
  6785 
       
  6786     (    (item := self selectedNode) isNil
       
  6787      or:[(parentItem := item parent) isNil
       
  6788      or:[(size := parentItem children size) < 2
       
  6789      or:[(idx  := parentItem indexOfChild:item) == 0]]]
       
  6790     ) ifTrue:[
       
  6791         ^ self
       
  6792     ].
       
  6793 
       
  6794     idx := idx + anIndex.
       
  6795 
       
  6796     idx < 1 ifTrue:[idx := size]
       
  6797            ifFalse:[idx > size ifTrue:[idx := 1]].
       
  6798 
  6862 
  6799     self setSelection:nil.
  6863     self setSelection:nil.
  6800     model remove:item.
  6864     model remove:parent children.
  6801     model add:item beforeIndex:idx below:parentItem.
  6865     model add:newChildren beforeIndex:1 below:parent.
  6802 
  6866 
  6803     idx := parentItem indexOfChild:item.
  6867     parentView := parent contents view.
  6804     itemsView := item contents view.
  6868 
  6805     parentItemsView := parentItem contents view.
  6869     self canvas hideSelection.
  6806 
  6870     newChildren keysAndValuesDo:[:idx :eachItem|
  6807     canvas := self canvas.
  6871         parentView changeSequenceOrderFor:eachItem contents view to:idx.
  6808     canvas hideSelection.
  6872     ].
  6809 
  6873     parentView specClass isLayoutContainer ifFalse:[
  6810     itemsView isView ifFalse:[
  6874         parentView components notEmptyOrNil ifTrue:[ self halt ].
  6811         "/ a component - has its own collection (and therefore indexing) - sigh
  6875         parentView subViews do:[:v| v raise ].
  6812         idx := idx - ((1 to:idx-1) count:[:i | (parentItem children at:i) contents view isView]).
  6876     ].
  6813         parentItemsView changeSequenceOrderFor:itemsView to:idx.
  6877     self canvas showSelection.
  6814     ] ifTrue:[
  6878 
  6815         "/ a view - has its own collection (and therefore indexing) - sigh
  6879     self selectNodes:itemList asOrderedCollection.
  6816         idx := idx - ((1 to:idx-1) count:[:i | (parentItem children at:i) contents view isView not]).
       
  6817         parentItemsView changeSequenceOrderFor:itemsView to:idx.
       
  6818     ].
       
  6819 
       
  6820     parentItemsView specClass isLayoutContainer ifFalse:[
       
  6821         "/ spVw components notEmptyOrNil ifTrue:[ self halt ].
       
  6822         parentItemsView subViews do:[:v| v raise ].
       
  6823     ].
       
  6824     canvas showSelection.
       
  6825     self selectNode:item.
       
  6826 ! !
  6880 ! !
  6827 
  6881 
  6828 !UIPainter class methodsFor:'documentation'!
  6882 !UIPainter class methodsFor:'documentation'!
  6829 
  6883 
  6830 version
  6884 version