1
0
mirror of https://github.com/cookiengineer/audacity synced 2026-03-11 17:05:26 +01:00

Define UndoManager::VisitStates

This commit is contained in:
Paul Licameli
2019-07-18 13:17:10 -04:00
parent d49a888b98
commit 490271f259
4 changed files with 62 additions and 29 deletions

View File

@@ -48,24 +48,6 @@ wxDEFINE_EVENT(EVT_UNDO_RESET, wxCommandEvent);
using SampleBlockID = long long;
struct UndoStackElem {
UndoStackElem(std::shared_ptr<TrackList> &&tracks_,
const TranslatableString &description_,
const TranslatableString &shortDescription_,
const SelectedRegion &selectedRegion_,
const std::shared_ptr<Tags> &tags_)
: state(std::move(tracks_), tags_, selectedRegion_)
, description(description_)
, shortDescription(shortDescription_)
{
}
UndoState state;
TranslatableString description;
TranslatableString shortDescription;
};
static const AudacityProject::AttachedObjects::RegisteredFactory key{
[](AudacityProject &project)
{ return std::make_unique<UndoManager>( project ); }
@@ -370,7 +352,7 @@ void UndoManager::SetStateTo(unsigned int n, const Consumer &consumer)
lastAction = {};
mayConsolidate = false;
consumer( stack[current]->state );
consumer( *stack[current] );
// wxWidgets will own the event object
mProject.QueueEvent( safenew wxCommandEvent{ EVT_UNDO_RESET } );
@@ -385,7 +367,7 @@ void UndoManager::Undo(const Consumer &consumer)
lastAction = {};
mayConsolidate = false;
consumer( stack[current]->state );
consumer( *stack[current] );
// wxWidgets will own the event object
mProject.QueueEvent( safenew wxCommandEvent{ EVT_UNDO_OR_REDO } );
@@ -413,12 +395,39 @@ void UndoManager::Redo(const Consumer &consumer)
lastAction = {};
mayConsolidate = false;
consumer( stack[current]->state );
consumer( *stack[current] );
// wxWidgets will own the event object
mProject.QueueEvent( safenew wxCommandEvent{ EVT_UNDO_OR_REDO } );
}
void UndoManager::VisitStates( const Consumer &consumer, bool newestFirst )
{
auto fn = [&]( decltype(stack[0]) &ptr ){ consumer( *ptr ); };
if (newestFirst)
std::for_each(stack.rbegin(), stack.rend(), fn);
else
std::for_each(stack.begin(), stack.end(), fn);
}
void UndoManager::VisitStates(
const Consumer &consumer, size_t begin, size_t end )
{
auto size = stack.size();
if (begin < end) {
end = std::min(end, size);
for (auto ii = begin; ii < end; ++ii)
consumer(*stack[ii]);
}
else {
if (size == 0)
return;
begin = std::min(begin, size - 1);
for (auto ii = begin; ii > end; --ii)
consumer(*stack[ii]);
}
}
bool UndoManager::UnsavedChanges() const
{
return (saved != current);