mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-25 16:48:44 +02:00
Some inversion of control flow when popping Undo state
This commit is contained in:
parent
2741d58880
commit
4f7d308ca3
@ -4673,6 +4673,8 @@ void AudacityProject::ModifyState(bool bWantsAutoSave)
|
||||
// Need to keep it and its tracks "t" available for Undo/Redo/SetStateTo.
|
||||
void AudacityProject::PopState(const UndoState &state)
|
||||
{
|
||||
mViewInfo.selectedRegion = state.selectedRegion;
|
||||
|
||||
// Restore tags
|
||||
mTags = state.tags;
|
||||
|
||||
@ -4725,9 +4727,8 @@ void AudacityProject::PopState(const UndoState &state)
|
||||
|
||||
void AudacityProject::SetStateTo(unsigned int n)
|
||||
{
|
||||
const UndoState &state =
|
||||
GetUndoManager()->SetStateTo(n, &mViewInfo.selectedRegion);
|
||||
PopState(state);
|
||||
GetUndoManager()->SetStateTo(n,
|
||||
[this]( const UndoState &state ){ PopState(state); } );
|
||||
|
||||
HandleResize();
|
||||
mTrackPanel->SetFocusedTrack(NULL);
|
||||
|
@ -300,8 +300,7 @@ void UndoManager::PushState(const TrackList * l,
|
||||
lastAction = longDescription;
|
||||
}
|
||||
|
||||
const UndoState &UndoManager::SetStateTo
|
||||
(unsigned int n, SelectedRegion *selectedRegion)
|
||||
void UndoManager::SetStateTo(unsigned int n, const Consumer &consumer)
|
||||
{
|
||||
n -= 1;
|
||||
|
||||
@ -309,36 +308,30 @@ const UndoState &UndoManager::SetStateTo
|
||||
|
||||
current = n;
|
||||
|
||||
*selectedRegion = stack[current]->state.selectedRegion;
|
||||
|
||||
lastAction = wxT("");
|
||||
mayConsolidate = false;
|
||||
|
||||
return stack[current]->state;
|
||||
consumer( stack[current]->state );
|
||||
}
|
||||
|
||||
const UndoState &UndoManager::Undo(SelectedRegion *selectedRegion)
|
||||
void UndoManager::Undo(const Consumer &consumer)
|
||||
{
|
||||
wxASSERT(UndoAvailable());
|
||||
|
||||
current--;
|
||||
|
||||
*selectedRegion = stack[current]->state.selectedRegion;
|
||||
|
||||
lastAction = wxT("");
|
||||
mayConsolidate = false;
|
||||
|
||||
return stack[current]->state;
|
||||
consumer( stack[current]->state );
|
||||
}
|
||||
|
||||
const UndoState &UndoManager::Redo(SelectedRegion *selectedRegion)
|
||||
void UndoManager::Redo(const Consumer &consumer)
|
||||
{
|
||||
wxASSERT(RedoAvailable());
|
||||
|
||||
current++;
|
||||
|
||||
*selectedRegion = stack[current]->state.selectedRegion;
|
||||
|
||||
/*
|
||||
if (!RedoAvailable()) {
|
||||
*sel0 = stack[current]->sel0;
|
||||
@ -355,7 +348,7 @@ const UndoState &UndoManager::Redo(SelectedRegion *selectedRegion)
|
||||
lastAction = wxT("");
|
||||
mayConsolidate = false;
|
||||
|
||||
return stack[current]->state;
|
||||
consumer( stack[current]->state );
|
||||
}
|
||||
|
||||
bool UndoManager::UnsavedChanges()
|
||||
|
@ -118,9 +118,11 @@ class AUDACITY_DLL_API UndoManager {
|
||||
wxLongLong_t GetLongDescription(unsigned int n, wxString *desc, wxString *size);
|
||||
void SetLongDescription(unsigned int n, const wxString &desc);
|
||||
|
||||
const UndoState &SetStateTo(unsigned int n, SelectedRegion *selectedRegion);
|
||||
const UndoState &Undo(SelectedRegion *selectedRegion);
|
||||
const UndoState &Redo(SelectedRegion *selectedRegion);
|
||||
// These functions accept a callback that uses the state
|
||||
using Consumer = std::function< void( const UndoState & ) >;
|
||||
void SetStateTo(unsigned int n, const Consumer &consumer);
|
||||
void Undo(const Consumer &consumer);
|
||||
void Redo(const Consumer &consumer);
|
||||
|
||||
bool UndoAvailable();
|
||||
bool RedoAvailable();
|
||||
|
@ -219,7 +219,6 @@ void DoUndo(AudacityProject &project)
|
||||
{
|
||||
auto trackPanel = project.GetTrackPanel();
|
||||
auto &undoManager = *project.GetUndoManager();
|
||||
auto &selectedRegion = project.GetViewInfo().selectedRegion;
|
||||
auto mixerBoard = project.GetMixerBoard();
|
||||
auto historyWindow = project.GetHistoryWindow();
|
||||
|
||||
@ -233,8 +232,8 @@ void DoUndo(AudacityProject &project)
|
||||
return;
|
||||
}
|
||||
|
||||
const UndoState &state = undoManager.Undo(&selectedRegion);
|
||||
project.PopState(state);
|
||||
undoManager.Undo(
|
||||
[&]( const UndoState &state ){ project.PopState( state ); } );
|
||||
|
||||
trackPanel->EnsureVisible(trackPanel->GetFirstSelectedTrack());
|
||||
|
||||
@ -264,7 +263,6 @@ void OnRedo(const CommandContext &context)
|
||||
auto &project = context.project;
|
||||
auto trackPanel = project.GetTrackPanel();
|
||||
auto &undoManager = *project.GetUndoManager();
|
||||
auto &selectedRegion = project.GetViewInfo().selectedRegion;
|
||||
auto mixerBoard = project.GetMixerBoard();
|
||||
auto historyWindow = project.GetHistoryWindow();
|
||||
|
||||
@ -277,8 +275,8 @@ void OnRedo(const CommandContext &context)
|
||||
return;
|
||||
}
|
||||
|
||||
const UndoState &state = undoManager.Redo(&selectedRegion);
|
||||
project.PopState(state);
|
||||
undoManager.Redo(
|
||||
[&]( const UndoState &state ){ project.PopState( state ); } );
|
||||
|
||||
trackPanel->EnsureVisible(trackPanel->GetFirstSelectedTrack());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user