| 1365 | //----------------------------------------------------------------------------- |
| 1366 | |
| 1367 | void GuiEditCtrl::saveSelection( const char* filename ) |
| 1368 | { |
| 1369 | // If there are no selected objects, then don't save. |
| 1370 | |
| 1371 | if( mSelectedControls.size() == 0 ) |
| 1372 | return; |
| 1373 | |
| 1374 | // Open the stream. |
| 1375 | |
| 1376 | Stream* stream; |
| 1377 | if( filename ) |
| 1378 | { |
| 1379 | stream = FileStream::createAndOpen( filename, Torque::FS::File::Write ); |
| 1380 | if( !stream ) |
| 1381 | { |
| 1382 | Con::errorf( "GuiEditCtrl::saveSelection - could not open '%s' for writing", filename ); |
| 1383 | return; |
| 1384 | } |
| 1385 | } |
| 1386 | else |
| 1387 | stream = new MemStream( 4096 ); |
| 1388 | |
| 1389 | // Create a temporary SimSet. |
| 1390 | |
| 1391 | SimSet* clipboardSet = new SimSet; |
| 1392 | clipboardSet->registerObject(); |
| 1393 | Sim::getRootGroup()->addObject( clipboardSet, "guiClipboard" ); |
| 1394 | |
| 1395 | // Add the selected controls to the set. |
| 1396 | |
| 1397 | for( Vector< GuiControl* >::iterator i = mSelectedControls.begin(); |
| 1398 | i != mSelectedControls.end(); ++ i ) |
| 1399 | { |
| 1400 | GuiControl* ctrl = *i; |
| 1401 | if( !selectionContainsParentOf( ctrl ) ) |
| 1402 | clipboardSet->addObject( ctrl ); |
| 1403 | } |
| 1404 | |
| 1405 | // Write the SimSet. Use the IgnoreCanSave to ensure the controls |
| 1406 | // get actually written out (also disables the default parent inheritance |
| 1407 | // behavior for the flag). |
| 1408 | |
| 1409 | clipboardSet->write( *stream, 0, IgnoreCanSave ); |
| 1410 | clipboardSet->deleteObject(); |
| 1411 | |
| 1412 | // If we were writing to a memory stream, copy to clipboard |
| 1413 | // now. |
| 1414 | |
| 1415 | if( !filename ) |
| 1416 | { |
| 1417 | MemStream* memStream = static_cast< MemStream* >( stream ); |
| 1418 | memStream->write( U8( 0 ) ); |
| 1419 | Platform::setClipboard( ( const char* ) memStream->getBuffer() ); |
| 1420 | } |
| 1421 | |
| 1422 | delete stream; |
| 1423 | } |
| 1424 |
no test coverage detected