mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Changed UndoManager so that if a transaction is aborted with undoCurrentTransactionOnly(), then any previously-saved future redo states are restored.
This commit is contained in:
parent
aa150395f4
commit
bc17cb90a8
2 changed files with 39 additions and 8 deletions
|
|
@ -153,7 +153,8 @@ bool UndoManager::perform (UndoableAction* const newAction)
|
|||
actionSet->actions.add (action.release());
|
||||
newTransaction = false;
|
||||
|
||||
clearFutureTransactions();
|
||||
moveFutureTransactionsToStash();
|
||||
dropOldTransactionsIfTooLarge();
|
||||
sendChangeMessage();
|
||||
return true;
|
||||
}
|
||||
|
|
@ -162,14 +163,36 @@ bool UndoManager::perform (UndoableAction* const newAction)
|
|||
return false;
|
||||
}
|
||||
|
||||
void UndoManager::clearFutureTransactions()
|
||||
void UndoManager::moveFutureTransactionsToStash()
|
||||
{
|
||||
while (nextIndex < transactions.size())
|
||||
if (nextIndex < transactions.size())
|
||||
{
|
||||
totalUnitsStored -= transactions.getLast()->getTotalSize();
|
||||
transactions.removeLast();
|
||||
stashedFutureTransactions.clear();
|
||||
|
||||
while (nextIndex < transactions.size())
|
||||
{
|
||||
totalUnitsStored -= transactions.getLast()->getTotalSize();
|
||||
stashedFutureTransactions.add (transactions.removeAndReturn (nextIndex));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UndoManager::restoreStashedFutureTransactions()
|
||||
{
|
||||
jassert (nextIndex == transactions.size());
|
||||
|
||||
for (int i = 0; i < stashedFutureTransactions.size(); ++i)
|
||||
{
|
||||
ActionSet* action = stashedFutureTransactions.removeAndReturn (i);
|
||||
totalUnitsStored += action->getTotalSize();
|
||||
transactions.add (action);
|
||||
}
|
||||
|
||||
stashedFutureTransactions.clearQuick (false);
|
||||
}
|
||||
|
||||
void UndoManager::dropOldTransactionsIfTooLarge()
|
||||
{
|
||||
while (nextIndex > 0
|
||||
&& totalUnitsStored > maxNumUnitsToKeep
|
||||
&& transactions.size() > minimumTransactionsToKeep)
|
||||
|
|
@ -290,7 +313,13 @@ Time UndoManager::getTimeOfRedoTransaction() const
|
|||
|
||||
bool UndoManager::undoCurrentTransactionOnly()
|
||||
{
|
||||
return newTransaction ? false : undo();
|
||||
if ((! newTransaction) && undo())
|
||||
{
|
||||
restoreStashedFutureTransactions();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void UndoManager::getActionsInCurrentTransaction (Array<const UndoableAction*>& actionsFound) const
|
||||
|
|
|
|||
|
|
@ -229,13 +229,15 @@ private:
|
|||
//==============================================================================
|
||||
struct ActionSet;
|
||||
friend struct ContainerDeletePolicy<ActionSet>;
|
||||
OwnedArray<ActionSet> transactions;
|
||||
OwnedArray<ActionSet> transactions, stashedFutureTransactions;
|
||||
String newTransactionName;
|
||||
int totalUnitsStored, maxNumUnitsToKeep, minimumTransactionsToKeep, nextIndex;
|
||||
bool newTransaction, reentrancyCheck;
|
||||
ActionSet* getCurrentSet() const noexcept;
|
||||
ActionSet* getNextSet() const noexcept;
|
||||
void clearFutureTransactions();
|
||||
void moveFutureTransactionsToStash();
|
||||
void restoreStashedFutureTransactions();
|
||||
void dropOldTransactionsIfTooLarge();
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (UndoManager)
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue