|
|
|
@@ -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<UndoableAction> actions;
|
|
|
|
String name;
|
|
|
|
Time time;
|
|
|
|
Time time { Time::getCurrentTime() };
|
|
|
|
};
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
@@ -117,9 +115,9 @@ bool UndoManager::perform (UndoableAction* newAction) |
|
|
|
{
|
|
|
|
std::unique_ptr<UndoableAction> 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<bool> setter (reentrancyCheck, true);
|
|
|
|
const ScopedValueSetter<bool> setter (isInsideUndoRedoCall, true);
|
|
|
|
|
|
|
|
if (s->undo())
|
|
|
|
--nextIndex;
|
|
|
|
@@ -266,7 +266,7 @@ bool UndoManager::redo() |
|
|
|
{
|
|
|
|
if (auto* s = getNextSet())
|
|
|
|
{
|
|
|
|
const ScopedValueSetter<bool> setter (reentrancyCheck, true);
|
|
|
|
const ScopedValueSetter<bool> setter (isInsideUndoRedoCall, true);
|
|
|
|
|
|
|
|
if (s->perform())
|
|
|
|
++nextIndex;
|
|
|
|
|