UIPainterView.st
changeset 2221 8ac60d4545ad
parent 2212 7224d23c4a37
child 2226 5917585724c6
equal deleted inserted replaced
2220:ff2b5cb004c2 2221:8ac60d4545ad
   213     ]
   213     ]
   214 ! !
   214 ! !
   215 
   215 
   216 !UIPainterView methodsFor:'copy & cut & paste'!
   216 !UIPainterView methodsFor:'copy & cut & paste'!
   217 
   217 
       
   218 changeSelectionAfterPasteOf:sel
       
   219     sel notNil ifTrue:[
       
   220         self select:sel.
       
   221     ].
       
   222 !
       
   223 
   218 commonContainerOf:someComponents
   224 commonContainerOf:someComponents
   219     |container|
   225     |container|
   220 
   226 
   221     container := someComponents first container.
   227     container := someComponents first container.
   222     [container notNil
   228     [container notNil
   327     "add the objects in the paste-buffer to the object view"
   333     "add the objects in the paste-buffer to the object view"
   328 
   334 
   329     |sel|
   335     |sel|
   330 
   336 
   331     sel := self pasteSpecifications:(self getClipboardObject) keepLayout:false.
   337     sel := self pasteSpecifications:(self getClipboardObject) keepLayout:false.
   332 
   338     self changeSelectionAfterPasteOf:sel.
   333     sel notNil ifTrue:[
       
   334         self select:sel.
       
   335     ].
       
   336 !
   339 !
   337 
   340 
   338 pasteKeepingPosition
   341 pasteKeepingPosition
   339     "add the objects in the paste-buffer to the object view;
   342     "add the objects in the paste-buffer to the object view;
   340      translate the layout as appropriate, to position the component
   343      translate the layout as appropriate, to position the component
   346         pasteSpecifications:(self getClipboardObject)
   349         pasteSpecifications:(self getClipboardObject)
   347         keepLayout:true
   350         keepLayout:true
   348         keepPosition:true
   351         keepPosition:true
   349         at:nil.
   352         at:nil.
   350 
   353 
   351     sel notNil ifTrue:[
   354     self changeSelectionAfterPasteOf:sel.
   352         self select:sel.
       
   353     ].
       
   354 !
   355 !
   355 
   356 
   356 pasteSpecifications:aSpecificationOrList keepLayout:keepLayout
   357 pasteSpecifications:aSpecificationOrList keepLayout:keepLayout
   357     "add the specs to the object view; returns list of pasted components"
   358     "add the specs to the object view; returns list of pasted components"
   358 
   359 
   386         self selection size > 0 ifTrue:[
   387         self selection size > 0 ifTrue:[
   387             containerToPasteInto := self commonContainerOf:self selection
   388             containerToPasteInto := self commonContainerOf:self selection
   388         ] ifFalse:[
   389         ] ifFalse:[
   389             containerToPasteInto := self
   390             containerToPasteInto := self
   390         ].
   391         ].
   391         self selection:containerToPasteInto.
   392 "/        self selection:containerToPasteInto.
   392     ].
   393     ].
   393 
   394 
   394     (self canPasteInto:containerToPasteInto) ifFalse:[
   395     (self canPasteInto:containerToPasteInto) ifFalse:[
   395         containerToPasteInto notNil ifTrue:[
   396         containerToPasteInto notNil ifTrue:[
   396             "/ search up parent list for something we can paste into
   397             "/ search up parent list for something we can paste into
   399                     containerToPasteInto := nil
   400                     containerToPasteInto := nil
   400                 ] ifFalse:[
   401                 ] ifFalse:[
   401                     containerToPasteInto := containerToPasteInto container.
   402                     containerToPasteInto := containerToPasteInto container.
   402                 ].
   403                 ].
   403             ].
   404             ].
   404             self selection:containerToPasteInto.
   405 "/            self selection:containerToPasteInto.
   405         ].
   406         ].
   406     ].
   407     ].
   407     containerToPasteInto isNil ifTrue:[
   408     containerToPasteInto isNil ifTrue:[
   408         containerToPasteInto := self
   409         containerToPasteInto := self
   409     ].
   410     ].
   410 
   411 
   411     (self canPaste:aSpecificationOrList) ifFalse:[
   412     (self canPaste:aSpecificationOrList into:containerToPasteInto)
       
   413     "(self canPaste:aSpecificationOrList)" 
       
   414     ifFalse:[
   412         Dialog warn:'Cannot paste into selected component (not a container ?)'.
   415         Dialog warn:'Cannot paste into selected component (not a container ?)'.
   413         ^ nil
   416         ^ nil
   414     ].
   417     ].
   415 
   418 
   416     aSpecificationOrList isCollection ifTrue:[
   419     aSpecificationOrList isCollection ifTrue:[
   417         paste := aSpecificationOrList
   420         paste := aSpecificationOrList
   418     ] ifFalse:[
   421     ] ifFalse:[
   419         paste := Array with:aSpecificationOrList
   422         paste := Array with:aSpecificationOrList
   420     ].
   423     ].
   421     self setClipboardObject:nil.
   424 "/    self setClipboardObject:nil.
   422 
   425 
   423     newSel  := OrderedCollection new.
   426     newSel  := OrderedCollection new.
   424     builder := UIBuilder new isEditing:true.
   427     builder := UIBuilder new isEditing:true.
   425 
   428 
   426     className notNil ifTrue:[
   429     className notNil ifTrue:[
   493      don't change the layout"
   496      don't change the layout"
   494 
   497 
   495     |sel|
   498     |sel|
   496 
   499 
   497     sel := self pasteSpecifications:(self getClipboardObject) keepLayout:true.
   500     sel := self pasteSpecifications:(self getClipboardObject) keepLayout:true.
   498 
   501     self changeSelectionAfterPasteOf:sel.
   499     sel notNil ifTrue:[
       
   500         self select:sel.
       
   501     ].
       
   502 ! !
   502 ! !
   503 
   503 
   504 !UIPainterView methodsFor:'drag & drop'!
   504 !UIPainterView methodsFor:'drag & drop'!
   505 
   505 
   506 canDrop:aDropContext
   506 canDrop:aDropContext
   527 !
   527 !
   528 
   528 
   529 canPaste:something
   529 canPaste:something
   530     "returns true if something could be pasted"
   530     "returns true if something could be pasted"
   531 
   531 
       
   532     ^ self canPaste:something into:(self singleSelection)
       
   533 !
       
   534 
       
   535 canPaste:something into:containerToPasteInto
       
   536     "returns true if something could be pasted"
       
   537 
   532     |el size|
   538     |el size|
   533 
   539 
   534     ((size := self numberOfSelections) <= 1 and:[self enabled]) ifFalse:[
   540     ((size := self numberOfSelections) <= 1 and:[self enabled]) ifFalse:[
   535         ^ false
   541         ^ false
   536     ].
   542     ].
   541     (el isKindOf:UISpecification) ifFalse:[
   547     (el isKindOf:UISpecification) ifFalse:[
   542         ^ false
   548         ^ false
   543     ].
   549     ].
   544 
   550 
   545     size == 1 ifTrue:[
   551     size == 1 ifTrue:[
   546         ^ self canPasteInto:(self singleSelection)
   552         ^ self canPasteInto:containerToPasteInto
   547     ].
   553     ].
   548     ^ true
   554     ^ true
   549 !
   555 !
   550 
   556 
   551 canPasteInto:aView
   557 canPasteInto:aView