29struct UndoManager::ActionSet
31 ActionSet (
const String& transactionName) : name (transactionName)
36 for (
auto* a : actions)
45 for (
int i = actions.size(); --i >= 0;)
46 if (! actions.getUnchecked (i)->undo())
52 int getTotalSize()
const
56 for (
auto* a : actions)
57 total += a->getSizeInUnits();
62 OwnedArray<UndoableAction> actions;
88 return totalUnitsStored;
93 maxNumUnitsToKeep = jmax (1,
maxUnits);
128 if (
actionSet !=
nullptr && ! newTransaction)
135 totalUnitsStored -=
lastAction->getSizeInUnits();
142 actionSet =
new ActionSet (newTransactionName);
147 totalUnitsStored +=
action->getSizeInUnits();
149 newTransaction =
false;
151 moveFutureTransactionsToStash();
152 dropOldTransactionsIfTooLarge();
161void UndoManager::moveFutureTransactionsToStash()
163 if (nextIndex < transactions.
size())
165 stashedFutureTransactions.
clear();
167 while (nextIndex < transactions.
size())
171 totalUnitsStored -=
removed->getTotalSize();
176void UndoManager::restoreStashedFutureTransactions()
178 while (nextIndex < transactions.
size())
180 totalUnitsStored -= transactions.
getUnchecked (nextIndex)->getTotalSize();
181 transactions.
remove (nextIndex);
184 for (
auto* stashed : stashedFutureTransactions)
186 transactions.
add (stashed);
187 totalUnitsStored += stashed->getTotalSize();
193void UndoManager::dropOldTransactionsIfTooLarge()
196 && totalUnitsStored > maxNumUnitsToKeep
197 && transactions.
size() > minimumTransactionsToKeep)
199 totalUnitsStored -= transactions.
getFirst()->getTotalSize();
205 jassert (totalUnitsStored >= 0);
216 newTransaction =
true;
223 newTransactionName = newName;
224 else if (
auto*
action = getCurrentSet())
230 if (
auto*
action = getCurrentSet())
233 return newTransactionName;
237UndoManager::ActionSet* UndoManager::getCurrentSet()
const {
return transactions[nextIndex - 1]; }
238UndoManager::ActionSet* UndoManager::getNextSet()
const {
return transactions[nextIndex]; }
247 if (
auto* s = getCurrentSet())
266 if (
auto* s = getNextSet())
285 if (
auto* s = getCurrentSet())
293 if (
auto* s = getNextSet())
303 for (
int i = nextIndex;;)
305 if (
auto*
t = transactions[--i])
316 for (
int i = nextIndex;;)
318 if (
auto*
t = transactions[i++])
327 if (
auto* s = getCurrentSet())
335 if (
auto* s = getNextSet())
343 if ((! newTransaction) &&
undo())
345 restoreStashedFutureTransactions();
354 if (! newTransaction)
355 if (
auto* s = getCurrentSet())
356 for (
auto* a : s->actions)
362 if (! newTransaction)
363 if (
auto* s = getCurrentSet())
364 return s->actions.size();
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)