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:
parent
ef8c100cee
commit
06c9896498
@ -159,9 +159,9 @@ HistoryWindow::HistoryWindow(AudacityProject *parent, UndoManager *manager):
|
|||||||
|
|
||||||
Clipboard::Get().Bind(
|
Clipboard::Get().Bind(
|
||||||
EVT_CLIPBOARD_CHANGE, &HistoryWindow::UpdateDisplay, this);
|
EVT_CLIPBOARD_CHANGE, &HistoryWindow::UpdateDisplay, this);
|
||||||
manager->Bind(EVT_UNDO_PUSHED, &HistoryWindow::UpdateDisplay, this);
|
parent->Bind(EVT_UNDO_PUSHED, &HistoryWindow::UpdateDisplay, this);
|
||||||
manager->Bind(EVT_UNDO_MODIFIED, &HistoryWindow::UpdateDisplay, this);
|
parent->Bind(EVT_UNDO_MODIFIED, &HistoryWindow::UpdateDisplay, this);
|
||||||
manager->Bind(EVT_UNDO_RESET, &HistoryWindow::UpdateDisplay, this);
|
parent->Bind(EVT_UNDO_RESET, &HistoryWindow::UpdateDisplay, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryWindow::OnAudioIO(wxCommandEvent& evt)
|
void HistoryWindow::OnAudioIO(wxCommandEvent& evt)
|
||||||
|
@ -120,10 +120,9 @@ LyricsPanel::LyricsPanel(wxWindow* parent, wxWindowID id,
|
|||||||
|
|
||||||
parent->Bind(wxEVT_SHOW, &LyricsPanel::OnShow, this);
|
parent->Bind(wxEVT_SHOW, &LyricsPanel::OnShow, this);
|
||||||
|
|
||||||
auto &undoManager = UndoManager::Get( *project );
|
project->Bind(EVT_UNDO_PUSHED, &LyricsPanel::UpdateLyrics, this);
|
||||||
undoManager.Bind(EVT_UNDO_PUSHED, &LyricsPanel::UpdateLyrics, this);
|
project->Bind(EVT_UNDO_MODIFIED, &LyricsPanel::UpdateLyrics, this);
|
||||||
undoManager.Bind(EVT_UNDO_MODIFIED, &LyricsPanel::UpdateLyrics, this);
|
project->Bind(EVT_UNDO_RESET, &LyricsPanel::UpdateLyrics, this);
|
||||||
undoManager.Bind(EVT_UNDO_RESET, &LyricsPanel::UpdateLyrics, this);
|
|
||||||
|
|
||||||
wxTheApp->Bind(EVT_AUDIOIO_PLAYBACK, &LyricsPanel::OnStartStop, this);
|
wxTheApp->Bind(EVT_AUDIOIO_PLAYBACK, &LyricsPanel::OnStartStop, this);
|
||||||
wxTheApp->Bind(EVT_AUDIOIO_CAPTURE, &LyricsPanel::OnStartStop, this);
|
wxTheApp->Bind(EVT_AUDIOIO_CAPTURE, &LyricsPanel::OnStartStop, this);
|
||||||
|
@ -65,7 +65,8 @@ struct UndoStackElem {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const AudacityProject::AttachedObjects::RegisteredFactory key{
|
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 )
|
UndoManager &UndoManager::Get( AudacityProject &project )
|
||||||
@ -78,7 +79,8 @@ const UndoManager &UndoManager::Get( const AudacityProject &project )
|
|||||||
return Get( const_cast< AudacityProject & >( project ) );
|
return Get( const_cast< AudacityProject & >( project ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
UndoManager::UndoManager()
|
UndoManager::UndoManager( AudacityProject &project )
|
||||||
|
: mProject{ project }
|
||||||
{
|
{
|
||||||
current = -1;
|
current = -1;
|
||||||
saved = -1;
|
saved = -1;
|
||||||
@ -266,7 +268,7 @@ void UndoManager::ModifyState(const TrackList * l,
|
|||||||
SonifyEndModifyState();
|
SonifyEndModifyState();
|
||||||
|
|
||||||
// wxWidgets will own the event object
|
// 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,
|
void UndoManager::PushState(const TrackList * l,
|
||||||
@ -322,7 +324,7 @@ void UndoManager::PushState(const TrackList * l,
|
|||||||
lastAction = longDescription;
|
lastAction = longDescription;
|
||||||
|
|
||||||
// wxWidgets will own the event object
|
// 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)
|
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 );
|
consumer( stack[current]->state );
|
||||||
|
|
||||||
// wxWidgets will own the event object
|
// 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)
|
void UndoManager::Undo(const Consumer &consumer)
|
||||||
@ -354,7 +356,7 @@ void UndoManager::Undo(const Consumer &consumer)
|
|||||||
consumer( stack[current]->state );
|
consumer( stack[current]->state );
|
||||||
|
|
||||||
// wxWidgets will own the event object
|
// 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)
|
void UndoManager::Redo(const Consumer &consumer)
|
||||||
@ -382,7 +384,7 @@ void UndoManager::Redo(const Consumer &consumer)
|
|||||||
consumer( stack[current]->state );
|
consumer( stack[current]->state );
|
||||||
|
|
||||||
// wxWidgets will own the event object
|
// wxWidgets will own the event object
|
||||||
QueueEvent( safenew wxCommandEvent{ EVT_UNDO_RESET } );
|
mProject.QueueEvent( safenew wxCommandEvent{ EVT_UNDO_RESET } );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UndoManager::UnsavedChanges()
|
bool UndoManager::UnsavedChanges()
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
#include "ClientData.h"
|
#include "ClientData.h"
|
||||||
#include "SelectedRegion.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
|
// Project state did not change, but a new state was copied into Undo history
|
||||||
// and any redo states were lost
|
// 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)); }
|
{ return static_cast<UndoPush>(static_cast<int>(a) & static_cast<int>(b)); }
|
||||||
|
|
||||||
class AUDACITY_DLL_API UndoManager
|
class AUDACITY_DLL_API UndoManager
|
||||||
: public wxEvtHandler
|
: public ClientData::Base
|
||||||
, public ClientData::Base
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static UndoManager &Get( AudacityProject &project );
|
static UndoManager &Get( AudacityProject &project );
|
||||||
static const UndoManager &Get( const AudacityProject &project );
|
static const UndoManager &Get( const AudacityProject &project );
|
||||||
|
|
||||||
UndoManager();
|
UndoManager( AudacityProject &project );
|
||||||
~UndoManager();
|
~UndoManager();
|
||||||
|
|
||||||
UndoManager( const UndoManager& ) = delete;
|
UndoManager( const UndoManager& ) = delete;
|
||||||
@ -139,7 +138,7 @@ class AUDACITY_DLL_API UndoManager
|
|||||||
void SetLongDescription(unsigned int n, const wxString &desc);
|
void SetLongDescription(unsigned int n, const wxString &desc);
|
||||||
|
|
||||||
// These functions accept a callback that uses the state,
|
// 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 & ) >;
|
using Consumer = std::function< void( const UndoState & ) >;
|
||||||
void SetStateTo(unsigned int n, const Consumer &consumer);
|
void SetStateTo(unsigned int n, const Consumer &consumer);
|
||||||
void Undo(const Consumer &consumer);
|
void Undo(const Consumer &consumer);
|
||||||
@ -167,6 +166,8 @@ class AUDACITY_DLL_API UndoManager
|
|||||||
void ResetODChangesFlag();
|
void ResetODChangesFlag();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
AudacityProject &mProject;
|
||||||
|
|
||||||
int current;
|
int current;
|
||||||
int saved;
|
int saved;
|
||||||
UndoStack stack;
|
UndoStack stack;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user