# HG changeset patch # User Claus Gittinger # Date 1065116546 -7200 # Node ID c59a91953b6472353b986125b188c1a347331be7 # Parent 700bf3fda9fa5d9ddeb0bacb670c45dfe5af135f paste with no container selected: search for a good one diff -r 700bf3fda9fa -r c59a91953b64 UIPainterView.st --- a/UIPainterView.st Fri Sep 26 09:56:09 2003 +0200 +++ b/UIPainterView.st Thu Oct 02 19:42:26 2003 +0200 @@ -208,6 +208,19 @@ !UIPainterView methodsFor:'copy & cut & paste'! +commonContainerOf:someComponents + |container| + + container := someComponents first container. + [container notNil + and:[ (someComponents conform:[:eachComponent | eachComponent isComponentOf:container]) not]] + whileTrue:[ + container := container container. + ]. +self halt. + ^ container +! + copySelection "copy the selection into the cut&paste-buffer " @@ -353,17 +366,27 @@ pasteSpecifications:aSpecificationOrList keepLayout:keepLayout keepPosition:keepPosition at:aPointOrNil "add the specs to the object view; returns list of pasted components " - |paste frame pasteOrigin pasteOffset builder newSel bounds container| + |paste pasteOrigin pasteOffset builder newSel bounds containerToPasteInto| treeView askForSelectionChangeAllowed ifFalse:[^ nil]. - (self canPasteInto:(self singleSelection)) ifFalse:[ - (container := self singleSelection) notNil ifTrue:[ + containerToPasteInto := self singleSelection. + containerToPasteInto isNil ifTrue:[ + self selection size > 0 ifTrue:[ + containerToPasteInto := self commonContainerOf:self selection + ] ifFalse:[ + containerToPasteInto := self + ]. + self selection:containerToPasteInto. + ]. + + (self canPasteInto:containerToPasteInto) ifFalse:[ + containerToPasteInto notNil ifTrue:[ "/ search up parent list for something we can paste into - [container notNil and:[(self canPasteInto:container) not]] whileTrue:[ - container := container container. + [containerToPasteInto notNil and:[(self canPasteInto:containerToPasteInto) not]] whileTrue:[ + containerToPasteInto := containerToPasteInto container. ]. - self selection:container. + self selection:containerToPasteInto. ]. ]. @@ -377,9 +400,6 @@ ] ifFalse:[ paste := Array with:aSpecificationOrList ]. - (frame := self singleSelection) isNil ifTrue:[ - frame := self - ]. self setSelection:nil. newSel := OrderedCollection new. @@ -395,27 +415,27 @@ keepPosition ifTrue:[ pasteOrigin := device translatePoint:0@0 fromView:self - toView:frame. + toView:containerToPasteInto. ] ifFalse:[ aPointOrNil isNil ifTrue:[ pasteOrigin := self sensor mousePoint. pasteOrigin := device translatePoint:pasteOrigin fromView:nil - toView:frame. + toView:containerToPasteInto. ] ifFalse:[ pasteOrigin := device translatePoint:aPointOrNil fromView:self - toView:frame. + toView:containerToPasteInto. ] ]. - bounds := Rectangle origin:0@0 extent:(frame bounds extent) + bounds := Rectangle origin:0@0 extent:(containerToPasteInto bounds extent) ]. paste do:[:aSpec| |view newOrigin| - view := self addSpec:aSpec builder:builder in:frame. + view := self addSpec:aSpec builder:builder in:containerToPasteInto. keepPosition ifTrue:[ self moveObject:view to:(view origin + pasteOrigin). @@ -441,7 +461,7 @@ self realizeAllSubViews. newSel do:[:v| v raise]. - self elementChangedSize:frame. + self elementChangedSize:containerToPasteInto. newSel size == 1 ifTrue:[newSel := newSel at:1]. ^ newSel @@ -1930,14 +1950,10 @@ " |prop spec| - (prop := self propertyOfView:anObject) notNil ifTrue:[ - spec := prop spec copy. - spec layoutFromView:anObject - ]. + (prop := self propertyOfView:anObject) isNil ifTrue:[^ nil]. + spec := prop spec copy. + spec layoutFromView:anObject. ^ spec - - - ! specForSelection