| 447 | } |
| 448 | |
| 449 | bool WorldEditor::pasteSelection( bool dropSel ) |
| 450 | { |
| 451 | clearSelection(); |
| 452 | |
| 453 | // Grab the world editor undo manager. |
| 454 | UndoManager *undoMan = NULL; |
| 455 | if ( !Sim::findObject( "EUndoManager", undoMan ) ) |
| 456 | { |
| 457 | Con::errorf( "WorldEditor::pasteSelection() - EUndoManager not found!" ); |
| 458 | return false; |
| 459 | } |
| 460 | |
| 461 | SimGroup *targetGroup = NULL; |
| 462 | if( isMethod( "getNewObjectGroup" ) ) |
| 463 | { |
| 464 | ConsoleValue cValue = Con::executef( this, "getNewObjectGroup" ); |
| 465 | const char* targetGroupName = cValue.getString(); |
| 466 | |
| 467 | if( targetGroupName && targetGroupName[ 0 ] && !Sim::findObject( targetGroupName, targetGroup) ) |
| 468 | Con::errorf( "WorldEditor::pasteSelection() - no SimGroup called '%s'", targetGroupName ); |
| 469 | } |
| 470 | |
| 471 | if( !targetGroup) |
| 472 | { |
| 473 | targetGroup = Scene::getRootScene(); |
| 474 | if( !targetGroup) |
| 475 | { |
| 476 | Con::errorf( "WorldEditor::pasteSelection() - Scene not found" ); |
| 477 | return false; |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | // Setup the action. |
| 482 | MECreateUndoAction *action = new MECreateUndoAction( "Paste" ); |
| 483 | |
| 484 | for( U32 i = 0; i < mCopyBuffer.size(); i++ ) |
| 485 | { |
| 486 | SimObject* obj = mCopyBuffer[i].restore(); |
| 487 | if ( !obj ) |
| 488 | continue; |
| 489 | |
| 490 | if (targetGroup) |
| 491 | targetGroup->addObject( obj ); |
| 492 | |
| 493 | action->addObject( obj ); |
| 494 | |
| 495 | if ( !mSelectionLocked ) |
| 496 | { |
| 497 | mSelected->addObject( obj ); |
| 498 | Con::executef( this, "onSelect", obj->getIdString() ); |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | // Its safe to submit the action before the selection |
| 503 | // is dropped below because the state of the objects |
| 504 | // are not stored until they are first undone. |
| 505 | undoMan->addAction( action ); |
| 506 |
no test coverage detected