mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-04 17:49:45 +02:00
UndoManager emits events when state changes
This commit is contained in:
parent
4f7d308ca3
commit
cee0d35da2
@ -38,6 +38,10 @@ UndoManager
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
wxDEFINE_EVENT(EVT_UNDO_PUSHED, wxCommandEvent);
|
||||
wxDEFINE_EVENT(EVT_UNDO_MODIFIED, wxCommandEvent);
|
||||
wxDEFINE_EVENT(EVT_UNDO_RESET, wxCommandEvent);
|
||||
|
||||
using ConstBlockFilePtr = const BlockFile*;
|
||||
using Set = std::unordered_set<ConstBlockFilePtr>;
|
||||
|
||||
@ -245,6 +249,9 @@ void UndoManager::ModifyState(const TrackList * l,
|
||||
|
||||
stack[current]->state.selectedRegion = selectedRegion;
|
||||
SonifyEndModifyState();
|
||||
|
||||
// wxWidgets will own the event object
|
||||
QueueEvent( safenew wxCommandEvent{ EVT_UNDO_MODIFIED } );
|
||||
}
|
||||
|
||||
void UndoManager::PushState(const TrackList * l,
|
||||
@ -298,6 +305,9 @@ void UndoManager::PushState(const TrackList * l,
|
||||
}
|
||||
|
||||
lastAction = longDescription;
|
||||
|
||||
// wxWidgets will own the event object
|
||||
QueueEvent( safenew wxCommandEvent{ EVT_UNDO_PUSHED } );
|
||||
}
|
||||
|
||||
void UndoManager::SetStateTo(unsigned int n, const Consumer &consumer)
|
||||
@ -312,6 +322,9 @@ void UndoManager::SetStateTo(unsigned int n, const Consumer &consumer)
|
||||
mayConsolidate = false;
|
||||
|
||||
consumer( stack[current]->state );
|
||||
|
||||
// wxWidgets will own the event object
|
||||
QueueEvent( safenew wxCommandEvent{ EVT_UNDO_RESET } );
|
||||
}
|
||||
|
||||
void UndoManager::Undo(const Consumer &consumer)
|
||||
@ -324,6 +337,9 @@ void UndoManager::Undo(const Consumer &consumer)
|
||||
mayConsolidate = false;
|
||||
|
||||
consumer( stack[current]->state );
|
||||
|
||||
// wxWidgets will own the event object
|
||||
QueueEvent( safenew wxCommandEvent{ EVT_UNDO_RESET } );
|
||||
}
|
||||
|
||||
void UndoManager::Redo(const Consumer &consumer)
|
||||
@ -349,6 +365,9 @@ void UndoManager::Redo(const Consumer &consumer)
|
||||
mayConsolidate = false;
|
||||
|
||||
consumer( stack[current]->state );
|
||||
|
||||
// wxWidgets will own the event object
|
||||
QueueEvent( safenew wxCommandEvent{ EVT_UNDO_RESET } );
|
||||
}
|
||||
|
||||
bool UndoManager::UnsavedChanges()
|
||||
|
@ -51,10 +51,24 @@
|
||||
|
||||
#include "MemoryX.h"
|
||||
#include <vector>
|
||||
#include <wx/event.h>
|
||||
#include <wx/string.h>
|
||||
#include "ondemand/ODTaskThread.h"
|
||||
#include "SelectedRegion.h"
|
||||
|
||||
// Events emitted by UndoManager 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
|
||||
wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API, EVT_UNDO_PUSHED, wxCommandEvent);
|
||||
|
||||
// Project state did not change, but current state was modified in Undo history
|
||||
wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API, EVT_UNDO_MODIFIED, wxCommandEvent);
|
||||
|
||||
// Project state changed because of undo or redo or rollback; undo manager
|
||||
// contents did not change other than the pointer to current state
|
||||
wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API, EVT_UNDO_RESET, wxCommandEvent);
|
||||
|
||||
class Tags;
|
||||
class Track;
|
||||
class TrackList;
|
||||
@ -90,7 +104,7 @@ inline UndoPush operator | (UndoPush a, UndoPush b)
|
||||
inline UndoPush operator & (UndoPush a, UndoPush 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:
|
||||
UndoManager();
|
||||
~UndoManager();
|
||||
@ -118,7 +132,8 @@ class AUDACITY_DLL_API UndoManager {
|
||||
wxLongLong_t GetLongDescription(unsigned int n, wxString *desc, wxString *size);
|
||||
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.
|
||||
using Consumer = std::function< void( const UndoState & ) >;
|
||||
void SetStateTo(unsigned int n, const Consumer &consumer);
|
||||
void Undo(const Consumer &consumer);
|
||||
|
Loading…
x
Reference in New Issue
Block a user