diff --git a/Makefile b/Makefile index 775afdb..db98015 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,7 @@ COMMON = \ undo.cc \ \ sync.cc \ + syncedit.cc \ syncoverrides.cc \ \ ops.cc \ @@ -44,7 +45,6 @@ COMMON = \ DEMO = \ demo.cc \ main.cc \ - syncedit.cc \ syncview.cc \ # END DEMO diff --git a/sync.cc b/sync.cc index 5164c40..7828f1c 100644 --- a/sync.cc +++ b/sync.cc @@ -1,6 +1,8 @@ #include "externals.hh" -#include "sync.hh" #include "globals.hh" +#include "sync.hh" +#include "syncedit.hh" +#include "undo.hh" #include #include @@ -546,7 +548,7 @@ T_SyncManager::T_SyncManager( ) soRoot_( "*root*" ) { watcher_.watch( "curves.srd" ); - loadCurves( ); + loadCurves( false ); } /*----------------------------------------------------------------------------*/ @@ -622,9 +624,11 @@ void T_SyncManager::curvesChanged_( ) } } -bool T_SyncManager::loadCurves( ) +bool T_SyncManager::loadCurves( + const bool undoable ) { printf( "Loading curves data\n" ); + T_SharedPtr< T_ParserOutput_ > p; try { using namespace ebcl; const T_SRDParserConfig cfg( MakeCurvesParser_( ) ); @@ -636,15 +640,7 @@ bool T_SyncManager::loadCurves( ) T_SRDTextReader reader( parser ); reader.read( "curves.srd" , fis ); - auto p( parser.getData< T_SharedPtr< T_ParserOutput_ > >( ) ); - curves_ = std::move( p->curves ); - if ( p->time ) { - time_.iDuration = p->time->iDuration; - time_.uDuration = p->time->uDuration; - } else { - time_.iDuration = 3600; - time_.uDuration = 1.f / 60.f; - } + p = parser.getData< T_SharedPtr< T_ParserOutput_ > >( ); } catch ( ebcl::X_StreamError const& e ) { printf( "... ERR %s\n" , e.what( ) ); return false; @@ -662,11 +658,50 @@ bool T_SyncManager::loadCurves( ) } printf( "... success\n" ); + assert( p ); + if ( undoable ) { + addReloadUndoData_( (void*)(T_ParserOutput_*) p ); + } + curves_ = std::move( p->curves ); + if ( p->time ) { + time_.iDuration = p->time->iDuration; + time_.uDuration = p->time->uDuration; + } else { + time_.iDuration = 3600; + time_.uDuration = 1.f / 60.f; + } + updateCurveCaches( ); modified_ = fileChanged_ = false; return true; } +void T_SyncManager::addReloadUndoData_( + void* const data ) const noexcept +{ + T_ParserOutput_& p{ *(T_ParserOutput_*)data }; + auto& undo{ Globals::Undo( ).add< T_UndoDurationChanges >( + p.time ? p.time->iDuration : 3600 , + time_.iDuration , + p.time ? p.time->uDuration : ( 1.f / 60.f ) , + time_.uDuration ) }; + + auto& nCurves{ p.curves.curves }; + for ( auto const& curve : curves_.curves.values( ) ) { + auto const* const nc{ nCurves.get( curve.name ) }; + if ( nc ) { + undo.curveReplacement( curve , *nc ); + } else { + undo.curveDeletion( curve ); + } + } + for ( auto const& nc : nCurves.values( ) ) { + if ( !curves_.curves.contains( nc.name ) ) { + undo.curveCreation( nc ); + } + } +} + /*----------------------------------------------------------------------------*/ void T_SyncManager::updateCurveCaches( ) diff --git a/sync.hh b/sync.hh index b2a5505..e6a5d7c 100644 --- a/sync.hh +++ b/sync.hh @@ -355,10 +355,11 @@ struct T_SyncManager : public virtual A_MouseCtrl bool curvesFileChanged( ) const noexcept { return fileChanged_; } - bool loadCurves( ); + bool loadCurves( bool undoable = true ); private: void curvesChanged_( ); + void addReloadUndoData_( void* data ) const noexcept; // --------------------------------------------------------------------- diff --git a/undo.hh b/undo.hh index abca968..8ecf72f 100644 --- a/undo.hh +++ b/undo.hh @@ -49,15 +49,16 @@ class T_UndoManager template< typename T , typename... Args - > A_UndoAction& add( Args&&... args ) noexcept; + > T& add( Args&&... args ) noexcept; }; template< typename T , typename... Args -> inline A_UndoAction& T_UndoManager::add( +> inline T& T_UndoManager::add( Args&&... args ) noexcept { - return addAction( NewOwned< T >( std::forward< Args >( args ) ... ) ); + return reinterpret_cast< T& >( addAction( + NewOwned< T >( std::forward< Args >( args ) ... ) ) ); }