1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-19 14:17:41 +02:00

Send Undo events through the project, not the UndoManager

This commit is contained in:
Paul Licameli 2019-06-08 10:29:42 -04:00
parent ef8c100cee
commit 06c9896498
4 changed files with 21 additions and 19 deletions

View File

@ -159,9 +159,9 @@ HistoryWindow::HistoryWindow(AudacityProject *parent, UndoManager *manager):
Clipboard::Get().Bind(
EVT_CLIPBOARD_CHANGE, &HistoryWindow::UpdateDisplay, this);
manager->Bind(EVT_UNDO_PUSHED, &HistoryWindow::UpdateDisplay, this);
manager->Bind(EVT_UNDO_MODIFIED, &HistoryWindow::UpdateDisplay, this);
manager->Bind(EVT_UNDO_RESET, &HistoryWindow::UpdateDisplay, this);
parent->Bind(EVT_UNDO_PUSHED, &HistoryWindow::UpdateDisplay, this);
parent->Bind(EVT_UNDO_MODIFIED, &HistoryWindow::UpdateDisplay, this);
parent->Bind(EVT_UNDO_RESET, &HistoryWindow::UpdateDisplay, this);
}
void HistoryWindow::OnAudioIO(wxCommandEvent& evt)

View File

@ -120,10 +120,9 @@ LyricsPanel::LyricsPanel(wxWindow* parent, wxWindowID id,
parent->Bind(wxEVT_SHOW, &LyricsPanel::OnShow, this);
auto &undoManager = UndoManager::Get( *project );
undoManager.Bind(EVT_UNDO_PUSHED, &LyricsPanel::UpdateLyrics, this);
undoManager.Bind(EVT_UNDO_MODIFIED, &LyricsPanel::UpdateLyrics, this);
undoManager.Bind(EVT_UNDO_RESET, &LyricsPanel::UpdateLyrics, this);
project->Bind(EVT_UNDO_PUSHED, &LyricsPanel::UpdateLyrics, this);
project->Bind(EVT_UNDO_MODIFIED, &LyricsPanel::UpdateLyrics, this);
project->Bind(EVT_UNDO_RESET, &LyricsPanel::UpdateLyrics, this);
wxTheApp->Bind(EVT_AUDIOIO_PLAYBACK, &LyricsPanel::OnStartStop, this);
wxTheApp->Bind(EVT_AUDIOIO_CAPTURE, &LyricsPanel::OnStartStop, this);

View File

@ -65,7 +65,8 @@ struct UndoStackElem {
};
static const AudacityProject::AttachedObjects::RegisteredFactory key{
[](AudacityProject&) { return std::make_unique<UndoManager>(); }
[](AudacityProject &project)
{ return std::make_unique<UndoManager>( project ); }
};
UndoManager &UndoManager::Get( AudacityProject &project )
@ -78,7 +79,8 @@ const UndoManager &UndoManager::Get( const AudacityProject &project )
return Get( const_cast< AudacityProject & >( project ) );
}
UndoManager::UndoManager()
UndoManager::UndoManager( AudacityProject &project )
: mProject{ project }
{
current = -1;
saved = -1;
@ -266,7 +268,7 @@ void UndoManager::ModifyState(const TrackList * l,
SonifyEndModifyState();
// wxWidgets will own the event object
QueueEvent( safenew wxCommandEvent{ EVT_UNDO_MODIFIED } );
mProject.QueueEvent( safenew wxCommandEvent{ EVT_UNDO_MODIFIED } );
}
void UndoManager::PushState(const TrackList * l,
@ -322,7 +324,7 @@ void UndoManager::PushState(const TrackList * l,
lastAction = longDescription;
// wxWidgets will own the event object
QueueEvent( safenew wxCommandEvent{ EVT_UNDO_PUSHED } );
mProject.QueueEvent( safenew wxCommandEvent{ EVT_UNDO_PUSHED } );
}
void UndoManager::SetStateTo(unsigned int n, const Consumer &consumer)
@ -339,7 +341,7 @@ void UndoManager::SetStateTo(unsigned int n, const Consumer &consumer)
consumer( stack[current]->state );
// wxWidgets will own the event object
QueueEvent( safenew wxCommandEvent{ EVT_UNDO_RESET } );
mProject.QueueEvent( safenew wxCommandEvent{ EVT_UNDO_RESET } );
}
void UndoManager::Undo(const Consumer &consumer)
@ -354,7 +356,7 @@ void UndoManager::Undo(const Consumer &consumer)
consumer( stack[current]->state );
// wxWidgets will own the event object
QueueEvent( safenew wxCommandEvent{ EVT_UNDO_RESET } );
mProject.QueueEvent( safenew wxCommandEvent{ EVT_UNDO_RESET } );
}
void UndoManager::Redo(const Consumer &consumer)
@ -382,7 +384,7 @@ void UndoManager::Redo(const Consumer &consumer)
consumer( stack[current]->state );
// wxWidgets will own the event object
QueueEvent( safenew wxCommandEvent{ EVT_UNDO_RESET } );
mProject.QueueEvent( safenew wxCommandEvent{ EVT_UNDO_RESET } );
}
bool UndoManager::UnsavedChanges()

View File

@ -55,7 +55,7 @@
#include "ClientData.h"
#include "SelectedRegion.h"
// Events emitted by UndoManager for the use of listeners
// Events emitted by AudacityProject for the use of listeners
// Project state did not change, but a new state was copied into Undo history
// and any redo states were lost
@ -105,14 +105,13 @@ inline UndoPush operator & (UndoPush a, UndoPush b)
{ return static_cast<UndoPush>(static_cast<int>(a) & static_cast<int>(b)); }
class AUDACITY_DLL_API UndoManager
: public wxEvtHandler
, public ClientData::Base
: public ClientData::Base
{
public:
static UndoManager &Get( AudacityProject &project );
static const UndoManager &Get( const AudacityProject &project );
UndoManager();
UndoManager( AudacityProject &project );
~UndoManager();
UndoManager( const UndoManager& ) = delete;
@ -139,7 +138,7 @@ class AUDACITY_DLL_API UndoManager
void SetLongDescription(unsigned int n, const wxString &desc);
// These functions accept a callback that uses the state,
// and then they emit EVT_UNDO_RESET when that has finished.
// and then they send to the project EVT_UNDO_RESET when that has finished.
using Consumer = std::function< void( const UndoState & ) >;
void SetStateTo(unsigned int n, const Consumer &consumer);
void Undo(const Consumer &consumer);
@ -167,6 +166,8 @@ class AUDACITY_DLL_API UndoManager
void ResetODChangesFlag();
private:
AudacityProject &mProject;
int current;
int saved;
UndoStack stack;