Sync - Reloads can be undone
This commit is contained in:
parent
7ef4bedfa6
commit
cc8d2b824e
4 changed files with 54 additions and 17 deletions
2
Makefile
2
Makefile
|
@ -32,6 +32,7 @@ COMMON = \
|
||||||
undo.cc \
|
undo.cc \
|
||||||
\
|
\
|
||||||
sync.cc \
|
sync.cc \
|
||||||
|
syncedit.cc \
|
||||||
syncoverrides.cc \
|
syncoverrides.cc \
|
||||||
\
|
\
|
||||||
ops.cc \
|
ops.cc \
|
||||||
|
@ -44,7 +45,6 @@ COMMON = \
|
||||||
DEMO = \
|
DEMO = \
|
||||||
demo.cc \
|
demo.cc \
|
||||||
main.cc \
|
main.cc \
|
||||||
syncedit.cc \
|
|
||||||
syncview.cc \
|
syncview.cc \
|
||||||
# END DEMO
|
# END DEMO
|
||||||
|
|
||||||
|
|
59
sync.cc
59
sync.cc
|
@ -1,6 +1,8 @@
|
||||||
#include "externals.hh"
|
#include "externals.hh"
|
||||||
#include "sync.hh"
|
|
||||||
#include "globals.hh"
|
#include "globals.hh"
|
||||||
|
#include "sync.hh"
|
||||||
|
#include "syncedit.hh"
|
||||||
|
#include "undo.hh"
|
||||||
|
|
||||||
#include <imgui_internal.h>
|
#include <imgui_internal.h>
|
||||||
#include <ebcl/Files.hh>
|
#include <ebcl/Files.hh>
|
||||||
|
@ -546,7 +548,7 @@ T_SyncManager::T_SyncManager( )
|
||||||
soRoot_( "*root*" )
|
soRoot_( "*root*" )
|
||||||
{
|
{
|
||||||
watcher_.watch( "curves.srd" );
|
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" );
|
printf( "Loading curves data\n" );
|
||||||
|
T_SharedPtr< T_ParserOutput_ > p;
|
||||||
try {
|
try {
|
||||||
using namespace ebcl;
|
using namespace ebcl;
|
||||||
const T_SRDParserConfig cfg( MakeCurvesParser_( ) );
|
const T_SRDParserConfig cfg( MakeCurvesParser_( ) );
|
||||||
|
@ -636,15 +640,7 @@ bool T_SyncManager::loadCurves( )
|
||||||
T_SRDTextReader reader( parser );
|
T_SRDTextReader reader( parser );
|
||||||
reader.read( "curves.srd" , fis );
|
reader.read( "curves.srd" , fis );
|
||||||
|
|
||||||
auto p( parser.getData< T_SharedPtr< T_ParserOutput_ > >( ) );
|
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;
|
|
||||||
}
|
|
||||||
} catch ( ebcl::X_StreamError const& e ) {
|
} catch ( ebcl::X_StreamError const& e ) {
|
||||||
printf( "... ERR %s\n" , e.what( ) );
|
printf( "... ERR %s\n" , e.what( ) );
|
||||||
return false;
|
return false;
|
||||||
|
@ -662,11 +658,50 @@ bool T_SyncManager::loadCurves( )
|
||||||
}
|
}
|
||||||
printf( "... success\n" );
|
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( );
|
updateCurveCaches( );
|
||||||
modified_ = fileChanged_ = false;
|
modified_ = fileChanged_ = false;
|
||||||
return true;
|
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( )
|
void T_SyncManager::updateCurveCaches( )
|
||||||
|
|
3
sync.hh
3
sync.hh
|
@ -355,10 +355,11 @@ struct T_SyncManager : public virtual A_MouseCtrl
|
||||||
bool curvesFileChanged( ) const noexcept
|
bool curvesFileChanged( ) const noexcept
|
||||||
{ return fileChanged_; }
|
{ return fileChanged_; }
|
||||||
|
|
||||||
bool loadCurves( );
|
bool loadCurves( bool undoable = true );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void curvesChanged_( );
|
void curvesChanged_( );
|
||||||
|
void addReloadUndoData_( void* data ) const noexcept;
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
7
undo.hh
7
undo.hh
|
@ -49,15 +49,16 @@ class T_UndoManager
|
||||||
template<
|
template<
|
||||||
typename T ,
|
typename T ,
|
||||||
typename... Args
|
typename... Args
|
||||||
> A_UndoAction& add( Args&&... args ) noexcept;
|
> T& add( Args&&... args ) noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template<
|
template<
|
||||||
typename T ,
|
typename T ,
|
||||||
typename... Args
|
typename... Args
|
||||||
> inline A_UndoAction& T_UndoManager::add(
|
> inline T& T_UndoManager::add(
|
||||||
Args&&... args ) noexcept
|
Args&&... args ) noexcept
|
||||||
{
|
{
|
||||||
return addAction( NewOwned< T >( std::forward< Args >( args ) ... ) );
|
return reinterpret_cast< T& >( addAction(
|
||||||
|
NewOwned< T >( std::forward< Args >( args ) ... ) ) );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue