diff -r 2bd9e855e6ac -r badd429a2a2a UIPainterView.st --- a/UIPainterView.st Fri Jan 25 19:32:34 2008 +0100 +++ b/UIPainterView.st Fri Jan 25 19:32:48 2008 +0100 @@ -254,7 +254,7 @@ sel := treeView selection. - coll := self minSetOfSuperViews:(self selection). + coll := self minClosedViewSetFor:(self selection). coll notNil ifTrue:[ "/ self select:nil. @@ -271,17 +271,15 @@ ! deleteSelectionBuffered: buffered - "cut the selection into the cut&paste-buffer - and open a transaction" - - |specs coll index oldSelection newSelection treeModel children size nd| + "cut the selection. If buffered is true, place it into the cut&paste-buffer" + + |specs specsToRemove index oldSelection newSelection treeModel children size node| treeView askForSelectionChangeAllowed ifFalse:[^ self]. - coll := self minSetOfSuperViews:(self selection). - - coll notNil ifTrue:[ - treeView cvsEventsDisabledDo:[ + specsToRemove := self minClosedViewSetFor:(self selection). + specsToRemove notEmptyOrNil ifTrue:[ + treeView canvasEventsDisabledDo:[ treeModel := treeView model. oldSelection := treeModel selectedNodes at:1 ifAbsent: nil. @@ -303,10 +301,10 @@ self hideSelection. selection := nil. - specs := coll collect:[:aView| self fullSpecFor:aView ]. - - self withinTransaction:#cut objects:coll do:[ - coll reverseDo:[:aView| + specs := specsToRemove collect:[:aView| self fullSpecFor:aView ]. + + self withinTransaction:#cut objects:specsToRemove do:[ + specsToRemove reverseDo:[:aView| self createUndoRemove:aView. self remove:aView. ] @@ -314,8 +312,8 @@ buffered ifTrue: [self setClipboardObject:specs]. treeView selection:nil. treeView selection:(Array with: newSelection). - (nd := treeView selectedNode) notNil ifTrue:[ - self setSelection:nd contents view withRedraw:true. + (node := treeView selectedNode) notNil ifTrue:[ + self setSelection:node contents view withRedraw:true. ] ] ] @@ -335,7 +333,7 @@ sel := treeView selection. - coll := self minSetOfSuperViews:(self selection). + coll := self minClosedViewSetFor:(self selection). coll isNil ifTrue:[^ nil]. @@ -369,7 +367,7 @@ ! pasteSpecifications:aSpecificationOrList keepLayout:keepLayout - "add the specs to the object view; returns list of pasted components" + "add the specs to the object view; returns list of pasted widgets" ^ self pasteSpecifications:aSpecificationOrList @@ -380,7 +378,7 @@ ! pasteSpecifications:aSpecificationOrList keepLayout:keepLayout at:aPointOrNil - "add the specs to the object view; returns list of pasted components" + "add the specs to the object view; returns list of pasted widgets" ^ self pasteSpecifications:aSpecificationOrList @@ -390,9 +388,9 @@ ! pasteSpecifications:aSpecificationOrList keepLayout:keepLayout keepPosition:keepPosition at:aPointOrNil - "add the specs to the object view; returns list of pasted components" - - |paste pasteOrigin pasteOffset builder newSel bounds containerToPasteInto| + "add the specs to the object view; returns list of pasted widgets" + + |specsToPaste pasteOrigin pasteOffset builder newSel bounds containerToPasteInto| treeView askForSelectionChangeAllowed ifFalse:[^ nil]. @@ -431,9 +429,9 @@ ]. aSpecificationOrList isCollection ifTrue:[ - paste := aSpecificationOrList + specsToPaste := aSpecificationOrList ] ifFalse:[ - paste := Array with:aSpecificationOrList + specsToPaste := Array with:aSpecificationOrList ]. "/ self setClipboardObject:nil. @@ -453,8 +451,7 @@ toView:containerToPasteInto. ] ifFalse:[ aPointOrNil isNil ifTrue:[ - pasteOrigin := self sensor mousePoint. - pasteOrigin := device translatePoint:pasteOrigin + pasteOrigin := device translatePoint:(self sensor mousePoint) fromView:nil toView:containerToPasteInto. ] ifFalse:[ @@ -467,10 +464,10 @@ bounds := Rectangle origin:0@0 extent:(containerToPasteInto bounds extent) ]. - paste do:[:aSpec| + specsToPaste do:[:eachSpec| |view newOrigin| - view := self addSpec:aSpec builder:builder in:containerToPasteInto. + view := self addSpec:eachSpec builder:builder in:containerToPasteInto. keepPosition ifTrue:[ self moveObject:view to:(view origin + pasteOrigin). @@ -513,6 +510,71 @@ sel := self pasteSpecifications:(self getClipboardObject) keepLayout:true. self changeSelectionAfterPasteOf:sel. +! + +replaceSelectionBy:aNewSpec + "replace the selected widget by another one." + + |specs coll index oldSelection newSelection treeModel children size node + container widgets builder newView property| + + treeView askForSelectionChangeAllowed ifFalse:[^ self]. + self assert:(self selection size == 1). + + treeModel := treeView model. + oldSelection := treeModel selectedNodes at:1 ifAbsent: nil. + property := oldSelection contents. + property spec:aNewSpec. +self halt. + self rebuildView:(property view) fromSpec:aNewSpec withBuilder:nil forceNewView:true. + +"/ p := self propertyOfView:aView) +"/ +"/ builder := UIBuilder new isEditing:true. +"/ newView := aNewSpec buildViewWithLayoutFor:builder in:(container contents view). +self halt. +^self. + self deleteSelectionBuffered:false. + widgets := self pasteSpecifications:(Array with:aNewSpec) keepLayout:false. + self select:widgets. + ^ widgets. + + treeView canvasEventsDisabledDo:[ + treeModel := treeView model. + oldSelection := treeModel selectedNodes at:1 ifAbsent: nil. + + oldSelection notNil ifTrue:[ + children := oldSelection parent children. + (size := children size) > 1 ifTrue:[ + index := children identityIndexOf:oldSelection. + size == index ifTrue:[ + index := index - 1 + ]. + newSelection := children at:index ifAbsent:1. + ] ifFalse:[ + newSelection := oldSelection parent + ]. + newSelection := treeModel indexOf:newSelection. + ] ifFalse:[ + newSelection := 1 + ]. + + self hideSelection. + selection := nil. + specs := coll collect:[:aView| self fullSpecFor:aView ]. + + self withinTransaction:#cut objects:coll do:[ + coll reverseDo:[:aView| + self createUndoRemove:aView. + self remove:aView. + ] + ]. + treeView selection:nil. + treeView selection:(Array with: newSelection). + (node := treeView selectedNode) notNil ifTrue:[ + self setSelection:node contents view withRedraw:true. + ] + ] ! ! !UIPainterView methodsFor:'drag & drop'! @@ -2062,23 +2124,23 @@ "add an object to the selection " (self enabled and:[(self isSelected:anObject) not]) ifTrue:[ - selection isCollection ifFalse:[ - selection isNil ifTrue:[ - selection := anObject - ] ifFalse:[ - selection := OrderedCollection with:selection with:anObject - ] - ] ifTrue:[ - "/ to enforce the change-message (value is identical to oldValue) - selection isList ifTrue:[ - selection add:anObject - ] ifFalse:[ - selection := selection asOrderedCollection. - selection := selection copyWith:anObject - ] - ]. - self showSelected:anObject. - treeView cvsSelectionAdd:anObject. + selection isCollection ifFalse:[ + selection isNil ifTrue:[ + selection := anObject + ] ifFalse:[ + selection := OrderedCollection with:selection with:anObject + ] + ] ifTrue:[ + "/ to enforce the change-message (value is identical to oldValue) + selection isList ifTrue:[ + selection add:anObject + ] ifFalse:[ + selection := selection asOrderedCollection. + selection := selection copyWith:anObject + ] + ]. + self showSelected:anObject. + treeView canvasSelectionAdd:anObject. ] "Modified: / 11.2.2000 / 01:39:05 / cg" @@ -2088,21 +2150,21 @@ "remove an object from the selection " (self isSelected:anObject) ifTrue:[ - self showUnselected:anObject. - - selection size > 1 ifTrue:[ - selection isList ifTrue:[ - selection remove:anObject ifAbsent:nil - ] ifFalse:[ - "/ to enforce the change-message (value is identical to oldValue) - selection := selection asOrderedCollection. - selection := selection copyWithout:anObject - ]. - self showSelection. - ] ifFalse:[ - selection := nil - ]. - treeView cvsSelectionRemove:anObject. + self showUnselected:anObject. + + selection size > 1 ifTrue:[ + selection isList ifTrue:[ + selection remove:anObject ifAbsent:nil + ] ifFalse:[ + "/ to enforce the change-message (value is identical to oldValue) + selection := selection asOrderedCollection. + selection := selection copyWithout:anObject + ]. + self showSelection. + ] ifFalse:[ + selection := nil + ]. + treeView canvasSelectionRemove:anObject. ] "Modified: / 11.2.2000 / 01:41:11 / cg" @@ -2112,12 +2174,11 @@ "change selection to something " (self enabled and:[something ~= self selection]) ifTrue:[ - something isNil - ifTrue: [treeView selection: (Array with: 1)] - ifFalse:[treeView cvsSelection:something]. - self setSelection:something withRedraw:true + something isNil + ifTrue: [treeView selection: (Array with: 1)] + ifFalse:[treeView canvasSelection:something]. + self setSelection:something withRedraw:true ] - ! selectNextUpInHierarchy @@ -2125,11 +2186,11 @@ (sel := self selection) isNil ifTrue:[^self]. sel isCollection ifTrue:[ - sel := self selection first. + sel := self selection first. ]. sel := sel superView. sel isNil ifTrue:[^self]. - treeView cvsSelection: sel. + treeView canvasSelection: sel. self selection: sel. ! @@ -2229,50 +2290,54 @@ ! rebuildView:aView fromSpec:aSpec withBuilder:aBuilderOrNil + self + rebuildView:aView fromSpec:aSpec withBuilder:aBuilderOrNil forceNewView:false +! + +rebuildView:aView fromSpec:aSpec withBuilder:aBuilderOrNil forceNewView:forceNewView |v builder| (builder := aBuilderOrNil) isNil ifTrue:[ - "/ create a dummy builder - builder := UIBuilder new isEditing:true. - className notNil ifTrue:[ - builder applicationClass:(self resolveName:className). - ]. + "/ create a dummy builder + builder := UIBuilder new isEditing:true. + className notNil ifTrue:[ + builder applicationClass:(self resolveName:className). + ]. ]. aSpec class isLayoutContainer ifTrue:[ - "/ TODO: - "/ go through subviews and let them resize to their default/preferred - "/ needed if we change a containers layout from fit to non-fit. - - (aView subViews ? #()) do:[:aSubView | - |fix spec prop| - - (prop := self propertyOfView:aSubView) notNil ifTrue:[ - spec := prop spec. - - spec useDefaultExtent ifTrue:[ - fix := aSubView sizeFixed:false. - aSubView extent:aSubView preferredExtent. - aSubView sizeFixed:fix - ] - ] - ]. + "/ TODO: + "/ go through subviews and let them resize to their default/preferred + "/ needed if we change a containers layout from fit to non-fit. + + (aView subViews ? #()) do:[:aSubView | + |fix spec prop| + + (prop := self propertyOfView:aSubView) notNil ifTrue:[ + spec := prop spec. + + spec useDefaultExtent ifTrue:[ + fix := aSubView sizeFixed:false. + aSubView extent:aSubView preferredExtent. + aSubView sizeFixed:fix + ] + ] + ]. ]. - aSpec needsRebuildForAttributes ifTrue:[ - "/ needs a full rebuild (in case view class depends upon spec-attribute) - v := aSpec buildViewWithLayoutFor:builder in:(self findContainerOfView:aView). - v realize. - aView destroy. - device sync. - device flush. - aView becomeSameAs:v. - "/ inputView raise. + (forceNewView or:[aSpec needsRebuildForAttributes]) ifTrue:[ + "/ needs a full rebuild (in case view class depends upon spec-attribute) + v := aSpec buildViewWithLayoutFor:builder in:(self findContainerOfView:aView). + v realize. + aView destroy. + device sync. + device flush. + aView becomeSameAs:v. + "/ inputView raise. ] ifFalse:[ - aSpec setAttributesIn:aView with:builder. - self elementChangedSize:aView. + aSpec setAttributesIn:aView with:builder. + self elementChangedSize:aView. ]. - ! specFor:anObject