26#include <wx/hashset.h>
42 using Savers = std::vector<UndoRedoExtensionRegistry::Saver>;
54 result.emplace_back(saver(
project));
68 {
return std::make_unique<UndoManager>(
project ); }
90 wxASSERT(
stack.empty() );
95 wxASSERT(n <
stack.size());
105 wxASSERT(n <
stack.size());
117 auto iter =
stack.begin() + n;
118 auto state = std::move(*iter);
125 if (
auto pThis = wThis.lock())
126 pThis->Publish(message);
139 for (
size_t ii =
begin; ii <
end; ++ii) {
184 if (index < 0 || index >= (
int)
stack.size())
186 auto &extensions =
stack[index]->state.extensions;
187 return std::all_of(extensions.begin(), extensions.end(), [&](
auto &ext){
188 return !ext || ext->CanUndoOrRedo(mProject);
213 if (state >= 0 && state <
stack.size() ) {
214 auto &theState = *
stack[state];
215 theState.description = longDescription;
216 theState.shortDescription = shortDescription;
244 std::make_unique<UndoStackElem>
265 wxASSERT(n <
stack.size());
320 auto fn = [&](
decltype(
stack[0]) &ptr ){ consumer( *ptr ); };
333 for (
auto ii =
begin; ii <
end; ++ii)
334 consumer(*
stack[ii]);
340 for (
auto ii =
begin; ii >
end; --ii)
341 consumer(*
stack[ii]);
Toolkit-neutral facade for basic user interface services.
static const AudacityProject::AttachedObjects::RegisteredFactory key
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
CallbackReturn Publish(const UndoRedoMessage &message)
Send a message to connected callbacks.
RAII for a database transaction, possibly nested.
Holds a msgid for the translation catalog; may also bind format arguments.
wxString Translation() const
Maintain a non-persistent list of states of the project, to support undo and redo commands.
void VisitStates(const Consumer &consumer, bool newestFirst)
Give read-only access to all states.
void RenameState(int state, const TranslatableString &longDescription, const TranslatableString &shortDescription)
int GetSavedState() const
unsigned int GetNumStates()
void RemoveStateAt(int n)
UndoManager(AudacityProject &project)
void GetShortDescription(unsigned int n, TranslatableString *desc)
void SetStateTo(unsigned int n, const Consumer &consumer)
void Undo(const Consumer &consumer)
AudacityProject & mProject
void EnqueueMessage(UndoRedoMessage message)
void Redo(const Consumer &consumer)
TranslatableString lastAction
void RemoveStates(size_t begin, size_t end)
void SetLongDescription(unsigned int n, const TranslatableString &desc)
void PushState(const TranslatableString &longDescription, const TranslatableString &shortDescription, UndoPush flags=UndoPush::NONE)
bool CheckAvailable(int index)
static UndoManager & Get(AudacityProject &project)
std::function< void(const UndoStackElem &) > Consumer
unsigned int GetCurrentState()
bool UnsavedChanges() const
std::function< std::shared_ptr< UndoStateExtension >(AudacityProject &)> Saver
Type of function that produces an UndoStateExtension object when saving state of a project.
virtual bool CanUndoOrRedo(const AudacityProject &project)
Whether undo or redo is now permitted; default returns true.
virtual ~UndoStateExtension()
void CallAfter(Action action)
Schedule an action to be done later, and in the main thread.
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
const TranslatableString desc
static Savers & GetSavers()
std::vector< UndoRedoExtensionRegistry::Saver > Savers
UndoState::Extensions GetExtensions(AudacityProject &project)
const char * end(const char *str) noexcept
const char * begin(const char *str) noexcept
Entry(const Saver &saver)
Type of message published by UndoManager.
@ EndPurge
End elimination of old undo states.
@ Purge
Undo or redo states eliminated.
@ BeginPurge
Begin elimination of old undo states.
std::vector< std::shared_ptr< UndoStateExtension > > Extensions