Sync - Reloads can be undone

This commit is contained in:
Emmanuel BENOîT 2017-11-22 15:43:06 +01:00
parent 7ef4bedfa6
commit cc8d2b824e
4 changed files with 54 additions and 17 deletions

View file

@ -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

59
sync.cc
View file

@ -1,6 +1,8 @@
#include "externals.hh"
#include "sync.hh"
#include "globals.hh"
#include "sync.hh"
#include "syncedit.hh"
#include "undo.hh"
#include <imgui_internal.h>
#include <ebcl/Files.hh>
@ -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( )

View file

@ -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;
// ---------------------------------------------------------------------

View file

@ -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 ) ... ) ) );
}