368 at:aPointOrNil |
368 at:aPointOrNil |
369 |
369 |
370 ! |
370 ! |
371 |
371 |
372 pasteSpecifications:aSpecificationOrList keepLayout:keepLayout keepPosition:keepPosition at:aPointOrNil |
372 pasteSpecifications:aSpecificationOrList keepLayout:keepLayout keepPosition:keepPosition at:aPointOrNil |
373 "add the specs to the object view; returns list of pasted components |
373 "add the specs to the object view; returns list of pasted components" |
374 " |
374 |
375 |paste pasteOrigin pasteOffset builder newSel bounds containerToPasteInto| |
375 |paste pasteOrigin pasteOffset builder newSel bounds containerToPasteInto| |
376 |
376 |
377 treeView askForSelectionChangeAllowed ifFalse:[^ nil]. |
377 treeView askForSelectionChangeAllowed ifFalse:[^ nil]. |
378 |
378 |
379 containerToPasteInto := self singleSelection. |
379 containerToPasteInto := self singleSelection. |
380 containerToPasteInto isNil ifTrue:[ |
380 containerToPasteInto isNil ifTrue:[ |
381 self selection size > 0 ifTrue:[ |
381 self selection size > 0 ifTrue:[ |
382 containerToPasteInto := self commonContainerOf:self selection |
382 containerToPasteInto := self commonContainerOf:self selection |
383 ] ifFalse:[ |
383 ] ifFalse:[ |
384 containerToPasteInto := self |
384 containerToPasteInto := self |
385 ]. |
385 ]. |
386 self selection:containerToPasteInto. |
386 self selection:containerToPasteInto. |
387 ]. |
387 ]. |
388 |
388 |
389 (self canPasteInto:containerToPasteInto) ifFalse:[ |
389 (self canPasteInto:containerToPasteInto) ifFalse:[ |
390 containerToPasteInto notNil ifTrue:[ |
390 containerToPasteInto notNil ifTrue:[ |
391 "/ search up parent list for something we can paste into |
391 "/ search up parent list for something we can paste into |
392 [containerToPasteInto notNil and:[(self canPasteInto:containerToPasteInto) not]] whileTrue:[ |
392 [containerToPasteInto notNil and:[(self canPasteInto:containerToPasteInto) not]] whileTrue:[ |
393 containerToPasteInto := containerToPasteInto container. |
393 containerToPasteInto := containerToPasteInto container. |
394 ]. |
394 ]. |
395 self selection:containerToPasteInto. |
395 self selection:containerToPasteInto. |
396 ]. |
396 ]. |
397 ]. |
397 ]. |
398 containerToPasteInto isNil ifTrue:[ |
398 containerToPasteInto isNil ifTrue:[ |
399 containerToPasteInto := self |
399 containerToPasteInto := self |
400 ]. |
400 ]. |
401 |
401 |
402 (self canPaste:aSpecificationOrList) ifFalse:[ |
402 (self canPaste:aSpecificationOrList) ifFalse:[ |
403 Dialog warn:'Cannot paste into selected component (not a container ?)'. |
403 Dialog warn:'Cannot paste into selected component (not a container ?)'. |
404 ^ nil |
404 ^ nil |
405 ]. |
405 ]. |
406 |
406 |
407 aSpecificationOrList isCollection ifTrue:[ |
407 aSpecificationOrList isCollection ifTrue:[ |
408 paste := aSpecificationOrList |
408 paste := aSpecificationOrList |
409 ] ifFalse:[ |
409 ] ifFalse:[ |
410 paste := Array with:aSpecificationOrList |
410 paste := Array with:aSpecificationOrList |
411 ]. |
411 ]. |
412 self setSelection:nil. |
412 self setClipboardObject:nil. |
413 |
413 |
414 newSel := OrderedCollection new. |
414 newSel := OrderedCollection new. |
415 builder := UIBuilder new isEditing:true. |
415 builder := UIBuilder new isEditing:true. |
416 |
416 |
417 className notNil ifTrue:[ |
417 className notNil ifTrue:[ |
418 builder applicationClass:(self resolveName:className) |
418 builder applicationClass:(self resolveName:className) |
419 ]. |
419 ]. |
420 |
420 |
421 (keepLayout not or:[keepPosition]) ifTrue:[ |
421 (keepLayout not or:[keepPosition]) ifTrue:[ |
422 pasteOffset := 0@0. |
422 pasteOffset := 0@0. |
423 |
423 |
424 keepPosition ifTrue:[ |
424 keepPosition ifTrue:[ |
425 pasteOrigin := device translatePoint:0@0 |
425 pasteOrigin := device translatePoint:0@0 |
426 fromView:self |
426 fromView:self |
427 toView:containerToPasteInto. |
427 toView:containerToPasteInto. |
428 ] ifFalse:[ |
428 ] ifFalse:[ |
429 aPointOrNil isNil ifTrue:[ |
429 aPointOrNil isNil ifTrue:[ |
430 pasteOrigin := self sensor mousePoint. |
430 pasteOrigin := self sensor mousePoint. |
431 pasteOrigin := device translatePoint:pasteOrigin |
431 pasteOrigin := device translatePoint:pasteOrigin |
432 fromView:nil |
432 fromView:nil |
433 toView:containerToPasteInto. |
433 toView:containerToPasteInto. |
434 ] ifFalse:[ |
434 ] ifFalse:[ |
435 pasteOrigin := device translatePoint:aPointOrNil |
435 pasteOrigin := device translatePoint:aPointOrNil |
436 fromView:self |
436 fromView:self |
437 toView:containerToPasteInto. |
437 toView:containerToPasteInto. |
438 ] |
438 ] |
439 ]. |
439 ]. |
440 |
440 |
441 bounds := Rectangle origin:0@0 extent:(containerToPasteInto bounds extent) |
441 bounds := Rectangle origin:0@0 extent:(containerToPasteInto bounds extent) |
442 ]. |
442 ]. |
443 |
443 |
444 paste do:[:aSpec| |
444 paste do:[:aSpec| |
445 |view newOrigin| |
445 |view newOrigin| |
446 |
446 |
447 view := self addSpec:aSpec builder:builder in:containerToPasteInto. |
447 view := self addSpec:aSpec builder:builder in:containerToPasteInto. |
448 |
448 |
449 keepPosition ifTrue:[ |
449 keepPosition ifTrue:[ |
450 self moveObject:view to:(view origin + pasteOrigin). |
450 self moveObject:view to:(view origin + pasteOrigin). |
451 ] ifFalse:[ |
451 ] ifFalse:[ |
452 keepLayout ifFalse:[ |
452 keepLayout ifFalse:[ |
453 (bounds containsPoint:pasteOrigin) ifFalse:[ |
453 (bounds containsPoint:pasteOrigin) ifFalse:[ |
454 newOrigin := pasteOffset. |
454 newOrigin := pasteOffset. |
455 ] ifTrue:[ |
455 ] ifTrue:[ |
456 newOrigin := pasteOrigin + pasteOffset. |
456 newOrigin := pasteOrigin + pasteOffset. |
457 ]. |
457 ]. |
458 self moveObject:view to:newOrigin. |
458 self moveObject:view to:newOrigin. |
459 pasteOffset := pasteOffset + 4 |
459 pasteOffset := pasteOffset + 4 |
460 ]. |
460 ]. |
461 ]. |
461 ]. |
462 view realize. |
462 view realize. |
463 newSel add:view. |
463 newSel add:view. |
464 ]. |
464 ]. |
465 |
465 |
466 self withinTransaction:#paste objects:newSel do:[ |
466 self withinTransaction:#paste objects:newSel do:[ |
467 undoHistory addUndoSelector:#undoCreate: |
467 undoHistory addUndoSelector:#undoCreate: |
468 withArgs:(newSel collect:[:v|(self propertyOfView:v) identifier]) |
468 withArgs:(newSel collect:[:v|(self propertyOfView:v) identifier]) |
469 ]. |
469 ]. |
470 |
470 |
471 self realizeAllSubViews. |
471 self realizeAllSubViews. |
472 newSel do:[:v| v raise]. |
472 newSel do:[:v| v raise]. |
473 self elementChangedSize:containerToPasteInto. |
473 self elementChangedSize:containerToPasteInto. |