diff --git a/modules/juce_data_structures/undomanager/juce_UndoManager.cpp b/modules/juce_data_structures/undomanager/juce_UndoManager.cpp index c736f0c62b..64b546b2d7 100644 --- a/modules/juce_data_structures/undomanager/juce_UndoManager.cpp +++ b/modules/juce_data_structures/undomanager/juce_UndoManager.cpp @@ -29,9 +29,7 @@ namespace juce struct UndoManager::ActionSet { - ActionSet (const String& transactionName) - : name (transactionName), - time (Time::getCurrentTime()) + ActionSet (const String& transactionName) : name (transactionName) {} bool perform() const @@ -64,7 +62,7 @@ struct UndoManager::ActionSet OwnedArray actions; String name; - Time time; + Time time { Time::getCurrentTime() }; }; //============================================================================== @@ -117,9 +115,9 @@ bool UndoManager::perform (UndoableAction* newAction) { std::unique_ptr action (newAction); - if (reentrancyCheck) + if (isPerformingUndoRedo()) { - jassertfalse; // don't call perform() recursively from the UndoableAction::perform() + jassertfalse; // Don't call perform() recursively from the UndoableAction::perform() // or undo() methods, or else these actions will be discarded! return false; } @@ -209,18 +207,18 @@ void UndoManager::dropOldTransactionsIfTooLarge() } } -void UndoManager::beginNewTransaction() noexcept +void UndoManager::beginNewTransaction() { beginNewTransaction ({}); } -void UndoManager::beginNewTransaction (const String& actionName) noexcept +void UndoManager::beginNewTransaction (const String& actionName) { newTransaction = true; newTransactionName = actionName; } -void UndoManager::setCurrentTransactionName (const String& newName) noexcept +void UndoManager::setCurrentTransactionName (const String& newName) { if (newTransaction) newTransactionName = newName; @@ -228,7 +226,7 @@ void UndoManager::setCurrentTransactionName (const String& newName) noexcept action->name = newName; } -String UndoManager::getCurrentTransactionName() const noexcept +String UndoManager::getCurrentTransactionName() const { if (auto* action = getCurrentSet()) return action->name; @@ -237,17 +235,19 @@ String UndoManager::getCurrentTransactionName() const noexcept } //============================================================================== -UndoManager::ActionSet* UndoManager::getCurrentSet() const noexcept { return transactions[nextIndex - 1]; } -UndoManager::ActionSet* UndoManager::getNextSet() const noexcept { return transactions[nextIndex]; } +UndoManager::ActionSet* UndoManager::getCurrentSet() const { return transactions[nextIndex - 1]; } +UndoManager::ActionSet* UndoManager::getNextSet() const { return transactions[nextIndex]; } -bool UndoManager::canUndo() const noexcept { return getCurrentSet() != nullptr; } -bool UndoManager::canRedo() const noexcept { return getNextSet() != nullptr; } +bool UndoManager::isPerformingUndoRedo() const { return isInsideUndoRedoCall; } + +bool UndoManager::canUndo() const { return getCurrentSet() != nullptr; } +bool UndoManager::canRedo() const { return getNextSet() != nullptr; } bool UndoManager::undo() { if (auto* s = getCurrentSet()) { - const ScopedValueSetter setter (reentrancyCheck, true); + const ScopedValueSetter setter (isInsideUndoRedoCall, true); if (s->undo()) --nextIndex; @@ -266,7 +266,7 @@ bool UndoManager::redo() { if (auto* s = getNextSet()) { - const ScopedValueSetter setter (reentrancyCheck, true); + const ScopedValueSetter setter (isInsideUndoRedoCall, true); if (s->perform()) ++nextIndex; diff --git a/modules/juce_data_structures/undomanager/juce_UndoManager.h b/modules/juce_data_structures/undomanager/juce_UndoManager.h index dd254ec28b..efa055eca6 100644 --- a/modules/juce_data_structures/undomanager/juce_UndoManager.h +++ b/modules/juce_data_structures/undomanager/juce_UndoManager.h @@ -126,7 +126,7 @@ public: method are grouped together and undone/redone together by a single call to undo() or redo(). */ - void beginNewTransaction() noexcept; + void beginNewTransaction(); /** Starts a new group of actions that together will be treated as a single transaction. @@ -137,7 +137,7 @@ public: @param actionName a description of the transaction that is about to be performed */ - void beginNewTransaction (const String& actionName) noexcept; + void beginNewTransaction (const String& actionName); /** Changes the name stored for the current transaction. @@ -145,18 +145,18 @@ public: called, but this can be used to change that name without starting a new transaction. */ - void setCurrentTransactionName (const String& newName) noexcept; + void setCurrentTransactionName (const String& newName); /** Returns the name of the current transaction. @see setCurrentTransactionName */ - String getCurrentTransactionName() const noexcept; + String getCurrentTransactionName() const; //============================================================================== /** Returns true if there's at least one action in the list to undo. @see getUndoDescription, undo, canRedo */ - bool canUndo() const noexcept; + bool canUndo() const; /** Tries to roll-back the last transaction. @returns true if the transaction can be undone, and false if it fails, or @@ -217,7 +217,7 @@ public: /** Returns true if there's at least one action in the list to redo. @see getRedoDescription, redo, canUndo */ - bool canRedo() const noexcept; + bool canRedo() const; /** Tries to redo the last transaction that was undone. @returns true if the transaction can be redone, and false if it fails, or @@ -243,15 +243,18 @@ public: */ Time getTimeOfRedoTransaction() const; + /** Returns true if the caller code is in the middle of an undo or redo action. */ + bool isPerformingUndoRedo() const; + private: //============================================================================== struct ActionSet; OwnedArray transactions, stashedFutureTransactions; String newTransactionName; int totalUnitsStored = 0, maxNumUnitsToKeep = 0, minimumTransactionsToKeep = 0, nextIndex = 0; - bool newTransaction = true, reentrancyCheck = false; - ActionSet* getCurrentSet() const noexcept; - ActionSet* getNextSet() const noexcept; + bool newTransaction = true, isInsideUndoRedoCall = false; + ActionSet* getCurrentSet() const; + ActionSet* getNextSet() const; void moveFutureTransactionsToStash(); void restoreStashedFutureTransactions(); void dropOldTransactionsIfTooLarge();