UIPainterView.st
changeset 3360 b7f7e48455dd
parent 3348 1028e3c18509
child 3387 462d9e0dea1f
equal deleted inserted replaced
3359:258a64461215 3360:b7f7e48455dd
   638 !
   638 !
   639 
   639 
   640 replaceSelectionBy:aNewSpec
   640 replaceSelectionBy:aNewSpec
   641     "replace the selected widget by another one."
   641     "replace the selected widget by another one."
   642 
   642 
   643     |oldSelection treeModel newView oldView container specs|
   643     |oldSelection treeModel newView oldView container specs index|
   644 
   644 
   645     (self singleSelection notNil and:[treeView askForSelectionChangeAllowed]) ifFalse:[
   645     (self singleSelection notNil and:[treeView askForSelectionChangeAllowed]) ifFalse:[
   646         ^ self
   646         ^ self
   647     ].
   647     ].
       
   648     
   648     treeModel    := treeView model.
   649     treeModel    := treeView model.
   649     oldSelection := treeModel selectedNodes at:1 ifAbsent: nil.
   650     oldSelection := treeModel selectedNodes at:1 ifAbsent: nil.
   650     oldSelection isNil ifTrue:[^ self].
   651     oldSelection isNil ifTrue:[^ self].
   651 
   652 
   652     oldView := oldSelection contents view.
   653     oldView := oldSelection contents view.
   653 
   654 
   654     (oldSelection hasChildren and:[aNewSpec class supportsSubComponents]) ifTrue:[
   655     (oldSelection hasChildren and:[aNewSpec class supportsSubComponents]) ifTrue:[
   655         specs := oldSelection children collect:[:each|
   656         specs := 
   656             self fullSpecWithAbsolutePositionFor:(each contents view)
   657             oldSelection children collect:[:each|
   657         ].
   658                 self fullSpecWithAbsolutePositionFor:(each contents view)
       
   659             ].
   658     ].
   660     ].
   659 
   661 
   660     aNewSpec
   662     aNewSpec
   661         otherAttributeAt:#uiPainterAttributes 
   663         otherAttributeAt:#uiPainterAttributes 
   662         put:(Dictionary new
   664         put:(Dictionary new
   663                 at:#origin put:oldView origin;
   665                 at:#origin put:oldView origin;
   664                 at:#extent put:oldView extent;
   666                 at:#extent put:oldView extent;
   665                 at:#absOrigin put:(oldView originRelativeTo:self);
   667                 at:#absOrigin put:(oldView originRelativeTo:self);
   666                 yourself).
   668                 yourself).
   667 
   669 
       
   670     index := oldSelection parent children identityIndexOf:oldSelection.
   668     container := self singleSelection container.
   671     container := self singleSelection container.
   669 
   672     
   670     self withinTransaction:#replaceBy objects:(Array with:oldView) do:[
   673     self withinTransaction:#replaceBy objects:(Array with:oldView) do:[
   671         self withSelectionHiddenDo:[
   674         self withSelectionHiddenDo:[
   672             newView := self 
   675             newView := self 
   673                     pasteSpecifications:(Array with:aNewSpec)
   676                     pasteSpecifications:(Array with:aNewSpec)
   674                     into:container
   677                     into:container
   675                     beforeIndex:1
   678                     beforeIndex:index
   676                     keepLayout:true
   679                     keepLayout:true
   677                     keepPosition:true
   680                     keepPosition:true
   678                     at:#keep.
   681                     at:#keep.
   679 
   682 
   680             self deleteSelectionBuffered:false.
   683             self deleteSelectionBuffered:false.
   682             specs size > 0 ifTrue:[
   685             specs size > 0 ifTrue:[
   683                 self pasteSpecifications:specs 
   686                 self pasteSpecifications:specs 
   684                             into:newView
   687                             into:newView
   685                             keepLayout:(aNewSpec class canResizeSubComponents)
   688                             keepLayout:(aNewSpec class canResizeSubComponents)
   686                             keepPosition:(aNewSpec class isLayoutContainer not)
   689                             keepPosition:(aNewSpec class isLayoutContainer not)
   687                             at:nil.
   690                             at:index.
   688             ].
   691             ].
   689             self select:newView.
   692             self select:newView.
   690        ].
   693        ].
   691     ].
   694     ].
   692     ^ newView.
   695     ^ newView.