![]() |
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 &) > |
![]() | |
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 TrackList &l, const SelectedRegion &selectedRegion, const TranslatableString &longDescription, const TranslatableString &shortDescription, UndoPush flags=UndoPush::NONE) |
void | ModifyState (const TrackList &l, const SelectedRegion &selectedRegion) |
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 () |
bool | UnsavedChanges () const |
int | GetSavedState () const |
void | StateSaved () |
![]() | |
virtual | ~Base () |
![]() | |
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 | |
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 constexpr bool | notifies_all |
![]() | |
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 163 of file UndoManager.h.
using UndoManager::Consumer = std::function< void( const UndoStackElem & ) > |
Definition at line 206 of file UndoManager.h.
|
explicit |
Definition at line 77 of file UndoManager.cpp.
UndoManager::~UndoManager | ( | ) |
Definition at line 84 of file UndoManager.cpp.
References stack.
|
delete |
void UndoManager::AbandonRedo | ( | ) |
Definition at line 265 of file UndoManager.cpp.
References current, RemoveStates(), saved, and stack.
Referenced by PushState().
void UndoManager::ClearStates | ( | ) |
Definition at line 151 of file UndoManager.cpp.
References current, RemoveStates(), saved, and stack.
Referenced by ProjectManager::OnCloseWindow().
|
private |
Definition at line 118 of file UndoManager.cpp.
References BasicUI::CallAfter().
Referenced by ModifyState(), PushState(), Redo(), RemoveStates(), RenameState(), SetStateTo(), and Undo().
|
static |
Definition at line 67 of file UndoManager.cpp.
References key.
Referenced by MacroCommands::ApplyMacro(), ProjectFileManager::Compact(), ProjectFileManager::CompactProjectOnClose(), anonymous_namespace{ClipMenus.cpp}::DoClipLeftOrRight(), ProjectFileManager::DoSave(), EstimateRemovedBlocks(), ViewActions::Handler::Handler(), HistoryDialog::HistoryDialog(), ProjectHistory::InitialState(), LyricsPanel::LyricsPanel(), MenuManager::MenuManager(), ProjectHistory::ModifyState(), MenuManager::ModifyUndoMenuItems(), PluginActions::Handler::OnApplyMacroDirectlyByName(), ProjectManager::OnCloseWindow(), EditActions::Handler::OnRedo(), TrackActions::Handler::OnResample(), TransportActions::Handler::OnTimerRecord(), EditActions::Handler::OnUndo(), ProjectManager::OpenProject(), ProjectWindow::ProjectWindow(), ProjectHistory::PushState(), ProjectHistory::RedoAvailable(), ProjectHistory::RollbackState(), ProjectHistory::SetStateTo(), SqliteSampleBlockFactory::SqliteSampleBlockFactory(), TrackPanel::TrackPanel(), ProjectHistory::UndoAvailable(), and UnsavedChangesFlag().
|
static |
Definition at line 72 of file UndoManager.cpp.
References BasicUI::Get().
unsigned int UndoManager::GetCurrentState | ( | ) |
Definition at line 163 of file UndoManager.cpp.
References current.
Referenced by HistoryDialog::DoUpdate(), and HistoryDialog::Populate().
unsigned int UndoManager::GetNumStates | ( | ) |
Definition at line 158 of file UndoManager.cpp.
References stack.
int UndoManager::GetSavedState | ( | ) | const |
void UndoManager::GetShortDescription | ( | unsigned int | n, |
TranslatableString * | desc | ||
) |
Definition at line 89 of file UndoManager.cpp.
void UndoManager::ModifyState | ( | const TrackList & | l, |
const SelectedRegion & | selectedRegion | ||
) |
Definition at line 178 of file UndoManager.cpp.
References TrackList::Create(), current, EnqueueMessage(), anonymous_namespace{UndoManager.cpp}::GetExtensions(), UndoRedoMessage::Modified, mProject, and stack.
Referenced by PushState().
|
delete |
void UndoManager::PushState | ( | const TrackList & | l, |
const SelectedRegion & | selectedRegion, | ||
const TranslatableString & | longDescription, | ||
const TranslatableString & | shortDescription, | ||
UndoPush | flags = UndoPush::NONE |
||
) |
Definition at line 221 of file UndoManager.cpp.
References AbandonRedo(), CONSOLIDATE, TrackList::Create(), 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 301 of file UndoManager.cpp.
References current, EnqueueMessage(), lastAction, mayConsolidate, RedoAvailable(), stack, and UndoRedoMessage::UndoOrRedo.
bool UndoManager::RedoAvailable | ( | ) |
|
private |
Definition at line 106 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 126 of file UndoManager.cpp.
References PackedArray::begin(), UndoRedoMessage::BeginPurge, current, PackedArray::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 208 of file UndoManager.cpp.
References EnqueueMessage(), UndoRedoMessage::Renamed, and stack.
void UndoManager::SetLongDescription | ( | unsigned int | n, |
const TranslatableString & | desc | ||
) |
void UndoManager::SetStateTo | ( | unsigned int | n, |
const Consumer & | consumer | ||
) |
Definition at line 273 of file UndoManager.cpp.
References current, EnqueueMessage(), lastAction, mayConsolidate, UndoRedoMessage::Reset, and stack.
void UndoManager::StateSaved | ( | ) |
Definition at line 360 of file UndoManager.cpp.
References current, and saved.
Referenced by ProjectFileManager::DoSave().
|
inline |
Definition at line 198 of file UndoManager.h.
void UndoManager::Undo | ( | const Consumer & | consumer | ) |
Definition at line 287 of file UndoManager.cpp.
References current, EnqueueMessage(), lastAction, mayConsolidate, stack, UndoAvailable(), and UndoRedoMessage::UndoOrRedo.
bool UndoManager::UndoAvailable | ( | ) |
Definition at line 168 of file UndoManager.cpp.
References current.
Referenced by Undo().
bool UndoManager::UnsavedChanges | ( | ) | const |
Definition at line 355 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 328 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 337 of file UndoManager.cpp.
References PackedArray::begin(), PackedArray::end(), min(), size, and stack.
|
private |
Definition at line 233 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 239 of file UndoManager.h.
Referenced by PushState(), Redo(), SetStateTo(), and Undo().
|
private |
Definition at line 240 of file UndoManager.h.
Referenced by PushState(), Redo(), SetStateTo(), and Undo().
|
private |
Definition at line 231 of file UndoManager.h.
Referenced by ModifyState(), PushState(), and RemoveStates().
|
private |
Definition at line 234 of file UndoManager.h.
Referenced by AbandonRedo(), ClearStates(), GetSavedState(), PushState(), RemoveStates(), StateSaved(), UndoManager(), and UnsavedChanges().
|
private |
Definition at line 237 of file UndoManager.h.
Referenced by AbandonRedo(), ClearStates(), GetNumStates(), GetShortDescription(), ModifyState(), PushState(), Redo(), RedoAvailable(), RemoveStateAt(), RenameState(), SetLongDescription(), SetStateTo(), Undo(), VisitStates(), and ~UndoManager().