30struct UndoManager::ActionSet
32 ActionSet (
const String& transactionName) : name (transactionName)
37 for (
auto* a : actions)
46 for (
int i = actions.size(); --i >= 0;)
47 if (! actions.getUnchecked(i)->undo())
53 int getTotalSize()
const
57 for (
auto* a : actions)
58 total += a->getSizeInUnits();
63 OwnedArray<UndoableAction> actions;
89 return totalUnitsStored;
94 maxNumUnitsToKeep = jmax (1,
maxUnits);
129 if (
actionSet !=
nullptr && ! newTransaction)
136 totalUnitsStored -=
lastAction->getSizeInUnits();
143 actionSet =
new ActionSet (newTransactionName);
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;
238UndoManager::ActionSet* UndoManager::getCurrentSet()
const {
return transactions[nextIndex - 1]; }
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();
void removeLast(int howManyToRemove=1)
int size() const noexcept
void add(const ElementType &newElement)
ElementType getLast() const noexcept
int size() const noexcept
ObjectClass * getUnchecked(int index) const noexcept
ObjectClass * removeAndReturn(int indexToRemove)
void remove(int indexToRemove, bool deleteObject=true)
ObjectClass * getFirst() const noexcept
void clear(bool deleteObjects=true)
ObjectClass * add(ObjectClass *newObject)
void clearQuick(bool deleteObjects)
ObjectClass * insert(int indexToInsertAt, ObjectClass *newObject)
static Time JUCE_CALLTYPE getCurrentTime() noexcept
void beginNewTransaction()
Time getTimeOfUndoTransaction() const
String getCurrentTransactionName() const
void setMaxNumberOfStoredUnits(int maxNumberOfUnitsToKeep, int minimumTransactionsToKeep)
String getRedoDescription() const
StringArray getRedoDescriptions() const
bool isPerformingUndoRedo() const
bool undoCurrentTransactionOnly()
int getNumberOfUnitsTakenUpByStoredCommands() const
bool perform(UndoableAction *action)
Time getTimeOfRedoTransaction() const
StringArray getUndoDescriptions() const
String getUndoDescription() const
UndoManager(int maxNumberOfUnitsToKeep=30000, int minimumTransactionsToKeep=30)
void getActionsInCurrentTransaction(Array< const UndoableAction * > &actionsFound) const
int getNumActionsInCurrentTransaction() const
void setCurrentTransactionName(const String &newName)