37 for (
auto*
a : actions)
46 for (
int i = actions.
size(); --i >= 0;)
53 int getTotalSize()
const
57 for (
auto*
a : actions)
58 total +=
a->getSizeInUnits();
89 return totalUnitsStored;
94 maxNumUnitsToKeep = jmax (1,
maxUnits);
129 if (
actionSet !=
nullptr && ! newTransaction)
136 totalUnitsStored -=
lastAction->getSizeInUnits();
148 totalUnitsStored +=
action->getSizeInUnits();
150 newTransaction =
false;
152 moveFutureTransactionsToStash();
153 dropOldTransactionsIfTooLarge();
162void UndoManager::moveFutureTransactionsToStash()
164 if (nextIndex < transactions.
size())
166 stashedFutureTransactions.
clear();
168 while (nextIndex < transactions.
size())
172 totalUnitsStored -=
removed->getTotalSize();
177void UndoManager::restoreStashedFutureTransactions()
179 while (nextIndex < transactions.
size())
181 totalUnitsStored -= transactions.
getUnchecked (nextIndex)->getTotalSize();
182 transactions.
remove (nextIndex);
185 for (
auto* stashed : stashedFutureTransactions)
187 transactions.
add (stashed);
188 totalUnitsStored += stashed->getTotalSize();
194void UndoManager::dropOldTransactionsIfTooLarge()
197 && totalUnitsStored > maxNumUnitsToKeep
198 && transactions.
size() > minimumTransactionsToKeep)
200 totalUnitsStored -= transactions.
getFirst()->getTotalSize();
206 jassert (totalUnitsStored >= 0);
217 newTransaction =
true;
224 newTransactionName = newName;
225 else if (
auto*
action = getCurrentSet())
231 if (
auto*
action = getCurrentSet())
234 return newTransactionName;
239UndoManager::ActionSet* UndoManager::getNextSet()
const {
return transactions[nextIndex]; }
248 if (
auto*
s = getCurrentSet())
267 if (
auto*
s = getNextSet())
286 if (
auto*
s = getCurrentSet())
294 if (
auto*
s = getNextSet())
304 for (
int i = nextIndex;;)
306 if (
auto*
t = transactions[--i])
317 for (
int i = nextIndex;;)
319 if (
auto*
t = transactions[i++])
328 if (
auto*
s = getCurrentSet())
336 if (
auto*
s = getNextSet())
344 if ((! newTransaction) &&
undo())
346 restoreStashedFutureTransactions();
355 if (! newTransaction)
356 if (
auto*
s = getCurrentSet())
357 for (
auto*
a :
s->actions)
363 if (! newTransaction)
364 if (
auto*
s = getCurrentSet())
365 return s->actions.
size();
Holds a resizable array of primitive or copy-by-value objects.
ElementType getUnchecked(int index) const
Returns one of the elements in the array, without checking the index passed in.
void removeLast(int howManyToRemove=1)
Removes the last n elements from the array.
void clearQuick()
Removes all elements from the array without freeing the array's allocated storage.
int size() const noexcept
Returns the current number of elements in the array.
void remove(int indexToRemove)
Removes an element from the array.
void insert(int indexToInsertAt, ParameterType newElement)
Inserts a new element into the array at a given position.
ElementType getFirst() const noexcept
Returns the first element in the array, or a default value if the array is empty.
void add(const ElementType &newElement)
Appends a new element at the end of the array.
ElementType removeAndReturn(int indexToRemove)
Removes an element from the array.
void clear()
Removes all elements from the array.
ElementType getLast() const noexcept
Returns the last element in the array, or a default value if the array is empty.
void sendChangeMessage()
Causes an asynchronous change message to be sent to all the registered listeners.
A special array for holding a list of strings.
Holds an absolute date and time.
static Time JUCE_CALLTYPE getCurrentTime() noexcept
Returns a Time object that is set to the current system time.
void beginNewTransaction()
Starts a new group of actions that together will be treated as a single transaction.
Time getTimeOfUndoTransaction() const
Returns the time to which the state would be restored if undo() was to be called.
String getCurrentTransactionName() const
Returns the name of the current transaction.
void setMaxNumberOfStoredUnits(int maxNumberOfUnitsToKeep, int minimumTransactionsToKeep)
Sets the amount of space that can be used for storing UndoableAction objects.
bool redo()
Tries to redo the last transaction that was undone.
String getRedoDescription() const
Returns the name of the transaction that will be redone when redo() is called.
StringArray getRedoDescriptions() const
Returns the names of the sequence of transactions that will be performed if redo() is repeatedly call...
bool undo()
Tries to roll-back the last transaction.
~UndoManager() override
Destructor.
bool isPerformingUndoRedo() const
Returns true if the caller code is in the middle of an undo or redo action.
void clearUndoHistory()
Deletes all stored actions in the list.
bool canUndo() const
Returns true if there's at least one action in the list to undo.
bool undoCurrentTransactionOnly()
Tries to roll-back any actions that were added to the current transaction.
int getNumberOfUnitsTakenUpByStoredCommands() const
Returns the current amount of space to use for storing UndoableAction objects.
bool perform(UndoableAction *action)
Performs an action and adds it to the undo history list.
Time getTimeOfRedoTransaction() const
Returns the time to which the state would be restored if redo() was to be called.
bool canRedo() const
Returns true if there's at least one action in the list to redo.
StringArray getUndoDescriptions() const
Returns the names of the sequence of transactions that will be performed if undo() is repeatedly call...
String getUndoDescription() const
Returns the name of the transaction that will be rolled-back when undo() is called.
UndoManager(int maxNumberOfUnitsToKeep=30000, int minimumTransactionsToKeep=30)
Creates an UndoManager.
void getActionsInCurrentTransaction(Array< const UndoableAction * > &actionsFound) const
Returns a list of the UndoableAction objects that have been performed during the transaction that is ...
int getNumActionsInCurrentTransaction() const
Returns the number of UndoableAction objects that have been performed during the transaction that is ...
void setCurrentTransactionName(const String &newName)
Changes the name stored for the current transaction.
Used by the UndoManager class to store an action which can be done and undone.