Audacity 3.2.0
|
Maintain a non-persistent list of states of the project, to support undo and redo commands. More...
#include <UndoManager.h>
Public Types | |
using | Consumer = std::function< void(const UndoStackElem &) > |
Public Types inherited from Observer::Publisher< UndoRedoMessage > | |
using | message_type = UndoRedoMessage |
using | CallbackReturn = std::conditional_t< true, void, bool > |
using | Callback = std::function< CallbackReturn(const UndoRedoMessage &) > |
Type of functions that can be connected to the Publisher. More... | |
Public Member Functions | |
UndoManager (AudacityProject &project) | |
~UndoManager () | |
UndoManager (const UndoManager &)=delete | |
UndoManager & | operator= (const UndoManager &)=delete |
void | PushState (const TranslatableString &longDescription, const TranslatableString &shortDescription, UndoPush flags=UndoPush::NONE) |
void | ModifyState () |
void | RenameState (int state, const TranslatableString &longDescription, const TranslatableString &shortDescription) |
void | AbandonRedo () |
void | ClearStates () |
void | RemoveStates (size_t begin, size_t end) |
unsigned int | GetNumStates () |
unsigned int | GetCurrentState () |
void | StopConsolidating () |
void | GetShortDescription (unsigned int n, TranslatableString *desc) |
void | SetLongDescription (unsigned int n, const TranslatableString &desc) |
void | SetStateTo (unsigned int n, const Consumer &consumer) |
void | Undo (const Consumer &consumer) |
void | Redo (const Consumer &consumer) |
void | VisitStates (const Consumer &consumer, bool newestFirst) |
Give read-only access to all states. More... | |
void | VisitStates (const Consumer &consumer, size_t begin, size_t end) |
Visit a specified range of states. More... | |
bool | UndoAvailable () |
bool | RedoAvailable () |
void | MarkUnsaved () |
bool | UnsavedChanges () const |
int | GetSavedState () const |
void | StateSaved () |
Public Member Functions inherited from ClientData::Base | |
virtual | ~Base () |
Public Member Functions inherited from Observer::Publisher< UndoRedoMessage > | |
Publisher (ExceptionPolicy *pPolicy=nullptr, Alloc a={}) | |
Constructor supporting type-erased custom allocation/deletion. More... | |
Publisher (Publisher &&)=default | |
Publisher & | operator= (Publisher &&)=default |
Subscription | Subscribe (Callback callback) |
Connect a callback to the Publisher; later-connected are called earlier. More... | |
Subscription | Subscribe (Object &obj, Return(Object::*callback)(Args...)) |
Overload of Subscribe takes an object and pointer-to-member-function. More... | |
Static Public Member Functions | |
static UndoManager & | Get (AudacityProject &project) |
static const UndoManager & | Get (const AudacityProject &project) |
Private Member Functions | |
bool | CheckAvailable (int index) |
void | EnqueueMessage (UndoRedoMessage message) |
void | RemoveStateAt (int n) |
Private Attributes | |
AudacityProject & | mProject |
int | current |
int | saved |
UndoStack | stack |
TranslatableString | lastAction |
bool | mayConsolidate { false } |
Additional Inherited Members | |
Static Public Attributes inherited from Observer::Publisher< UndoRedoMessage > | |
static constexpr bool | notifies_all |
Protected Member Functions inherited from Observer::Publisher< UndoRedoMessage > | |
CallbackReturn | Publish (const UndoRedoMessage &message) |
Send a message to connected callbacks. More... | |
Maintain a non-persistent list of states of the project, to support undo and redo commands.
Works with HistoryDialog to provide the Undo functionality.
The history should be cleared before destruction
Definition at line 151 of file UndoManager.h.
using UndoManager::Consumer = std::function< void( const UndoStackElem & ) > |
Definition at line 191 of file UndoManager.h.
|
explicit |
Definition at line 81 of file UndoManager.cpp.
UndoManager::~UndoManager | ( | ) |
Definition at line 88 of file UndoManager.cpp.
References stack.
|
delete |
void UndoManager::AbandonRedo | ( | ) |
Definition at line 255 of file UndoManager.cpp.
References current, RemoveStates(), saved, and stack.
Referenced by PushState().
|
private |
Definition at line 182 of file UndoManager.cpp.
References stack.
Referenced by RedoAvailable(), and UndoAvailable().
void UndoManager::ClearStates | ( | ) |
Definition at line 155 of file UndoManager.cpp.
References current, RemoveStates(), saved, and stack.
|
private |
Definition at line 122 of file UndoManager.cpp.
References BasicUI::CallAfter().
Referenced by ModifyState(), PushState(), Redo(), RemoveStates(), RenameState(), SetStateTo(), and Undo().
|
static |
Definition at line 71 of file UndoManager.cpp.
Referenced by MacroCommands::ApplyMacro(), ProjectFileManager::Compact(), ProjectFileManager::CompactProjectOnClose(), anonymous_namespace{RealtimeEffectPanel.cpp}::RealtimeEffectControl::Create(), anonymous_namespace{ClipMenus.cpp}::DoClipLeftOrRight(), ProjectFileManager::DoSave(), EstimateRemovedBlocks(), HistoryDialog::HistoryDialog(), ProjectHistory::InitialState(), RealtimeEffectPanel::MakeMasterEffectPane(), RealtimeEffectPanel::MakeTrackEffectPane(), ProjectHistory::ModifyState(), CommandManager::ModifyUndoMenuItems(), anonymous_namespace{BatchProcessDialog.cpp}::OnApplyMacroDirectlyByName(), ProjectManager::OnCloseWindow(), EffectUIHost::OnEnable(), anonymous_namespace{EditMenus.cpp}::OnRedo(), anonymous_namespace{TrackMenus.cpp}::OnResample(), anonymous_namespace{TimerRecordDialog.cpp}::OnTimerRecord(), anonymous_namespace{EditMenus.cpp}::OnUndo(), ProjectManager::OpenProject(), ProjectHistory::PushState(), RealtimeEffectPanel::RealtimeEffectPanel(), ProjectHistory::RedoAvailable(), ProjectHistory::RollbackState(), ProjectHistory::SetStateTo(), RealtimeEffectStateUI::Show(), SqliteSampleBlockFactory::SqliteSampleBlockFactory(), TrackPanel::TrackPanel(), and ProjectHistory::UndoAvailable().
|
static |
Definition at line 76 of file UndoManager.cpp.
References BasicUI::Get(), and project.
unsigned int UndoManager::GetCurrentState | ( | ) |
Definition at line 167 of file UndoManager.cpp.
References current.
Referenced by HistoryDialog::DoUpdate(), and HistoryDialog::Populate().
unsigned int UndoManager::GetNumStates | ( | ) |
Definition at line 162 of file UndoManager.cpp.
References stack.
int UndoManager::GetSavedState | ( | ) | const |
void UndoManager::GetShortDescription | ( | unsigned int | n, |
TranslatableString * | desc | ||
) |
Definition at line 93 of file UndoManager.cpp.
References anonymous_namespace{ExportPCM.cpp}::desc, and stack.
void UndoManager::MarkUnsaved | ( | ) |
Definition at line 345 of file UndoManager.cpp.
References saved.
Referenced by anonymous_namespace{RealtimeEffectPanel.cpp}::RealtimeEffectControl::Create(), RealtimeEffectPanel::MakeMasterEffectPane(), RealtimeEffectPanel::MakeTrackEffectPane(), EffectUIHost::OnEnable(), and RealtimeEffectStateUI::Show().
void UndoManager::ModifyState | ( | ) |
Definition at line 192 of file UndoManager.cpp.
References current, EnqueueMessage(), anonymous_namespace{UndoManager.cpp}::GetExtensions(), UndoRedoMessage::Modified, mProject, and stack.
Referenced by PushState().
|
delete |
void UndoManager::PushState | ( | const TranslatableString & | longDescription, |
const TranslatableString & | shortDescription, | ||
UndoPush | flags = UndoPush::NONE |
||
) |
Definition at line 222 of file UndoManager.cpp.
References AbandonRedo(), CONSOLIDATE, current, EnqueueMessage(), anonymous_namespace{UndoManager.cpp}::GetExtensions(), lastAction, mayConsolidate, ModifyState(), mProject, NONE, UndoRedoMessage::Pushed, saved, stack, and TranslatableString::Translation().
void UndoManager::Redo | ( | const Consumer & | consumer | ) |
Definition at line 291 of file UndoManager.cpp.
References current, EnqueueMessage(), lastAction, mayConsolidate, RedoAvailable(), stack, and UndoRedoMessage::UndoOrRedo.
bool UndoManager::RedoAvailable | ( | ) |
Definition at line 177 of file UndoManager.cpp.
References CheckAvailable(), and current.
Referenced by Redo().
|
private |
Definition at line 110 of file UndoManager.cpp.
References stack.
Referenced by RemoveStates().
void UndoManager::RemoveStates | ( | size_t | begin, |
size_t | end | ||
) |
begin | inclusive start of range |
end | exclusive end of range |
Definition at line 130 of file UndoManager.cpp.
References details::begin(), UndoRedoMessage::BeginPurge, current, details::end(), UndoRedoMessage::EndPurge, EnqueueMessage(), mProject, Observer::Publisher< UndoRedoMessage >::Publish(), UndoRedoMessage::Purge, RemoveStateAt(), and saved.
Referenced by AbandonRedo(), ClearStates(), and HistoryDialog::OnDiscard().
void UndoManager::RenameState | ( | int | state, |
const TranslatableString & | longDescription, | ||
const TranslatableString & | shortDescription | ||
) |
Definition at line 209 of file UndoManager.cpp.
References EnqueueMessage(), UndoRedoMessage::Renamed, and stack.
void UndoManager::SetLongDescription | ( | unsigned int | n, |
const TranslatableString & | desc | ||
) |
Definition at line 100 of file UndoManager.cpp.
References anonymous_namespace{ExportPCM.cpp}::desc, and stack.
void UndoManager::SetStateTo | ( | unsigned int | n, |
const Consumer & | consumer | ||
) |
Definition at line 263 of file UndoManager.cpp.
References current, EnqueueMessage(), lastAction, mayConsolidate, UndoRedoMessage::Reset, and stack.
void UndoManager::StateSaved | ( | ) |
Definition at line 355 of file UndoManager.cpp.
References current, and saved.
Referenced by ProjectFileManager::DoSave().
|
inline |
Definition at line 183 of file UndoManager.h.
void UndoManager::Undo | ( | const Consumer & | consumer | ) |
Definition at line 277 of file UndoManager.cpp.
References current, EnqueueMessage(), lastAction, mayConsolidate, stack, UndoAvailable(), and UndoRedoMessage::UndoOrRedo.
bool UndoManager::UndoAvailable | ( | ) |
Definition at line 172 of file UndoManager.cpp.
References CheckAvailable(), and current.
Referenced by Undo().
bool UndoManager::UnsavedChanges | ( | ) | const |
Definition at line 350 of file UndoManager.cpp.
References current, and saved.
Referenced by ProjectFileManager::CompactProjectOnClose().
void UndoManager::VisitStates | ( | const Consumer & | consumer, |
bool | newestFirst | ||
) |
Give read-only access to all states.
Definition at line 318 of file UndoManager.cpp.
Referenced by HistoryDialog::DoUpdate().
void UndoManager::VisitStates | ( | const Consumer & | consumer, |
size_t | begin, | ||
size_t | end | ||
) |
Visit a specified range of states.
end is exclusive; visit newer states first if end < begin
Definition at line 327 of file UndoManager.cpp.
References details::begin(), details::end(), min(), size, and stack.
|
private |
Definition at line 221 of file UndoManager.h.
Referenced by AbandonRedo(), ClearStates(), GetCurrentState(), ModifyState(), PushState(), Redo(), RedoAvailable(), RemoveStates(), SetStateTo(), StateSaved(), Undo(), UndoAvailable(), UndoManager(), and UnsavedChanges().
|
private |
Definition at line 226 of file UndoManager.h.
Referenced by PushState(), Redo(), SetStateTo(), and Undo().
|
private |
Definition at line 227 of file UndoManager.h.
Referenced by PushState(), Redo(), SetStateTo(), and Undo().
|
private |
Definition at line 219 of file UndoManager.h.
Referenced by ModifyState(), PushState(), and RemoveStates().
|
private |
Definition at line 222 of file UndoManager.h.
Referenced by AbandonRedo(), ClearStates(), GetSavedState(), MarkUnsaved(), PushState(), RemoveStates(), StateSaved(), UndoManager(), and UnsavedChanges().
|
private |
Definition at line 224 of file UndoManager.h.
Referenced by AbandonRedo(), CheckAvailable(), ClearStates(), GetNumStates(), GetShortDescription(), ModifyState(), PushState(), Redo(), RemoveStateAt(), RenameState(), SetLongDescription(), SetStateTo(), Undo(), VisitStates(), and ~UndoManager().