From f752a3331eac464814f42b77c975a24b741e1758 Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 3 Apr 2018 12:32:08 +0100 Subject: [PATCH] Added methods UndoManager::getUndoDescriptions() and UndoManager::getRedoDescriptions() --- .../undomanager/juce_UndoManager.cpp | 32 ++++++++++- .../undomanager/juce_UndoManager.h | 55 ++++++++++++------- 2 files changed, 64 insertions(+), 23 deletions(-) diff --git a/modules/juce_data_structures/undomanager/juce_UndoManager.cpp b/modules/juce_data_structures/undomanager/juce_UndoManager.cpp index b850912973..dfdaed0a05 100644 --- a/modules/juce_data_structures/undomanager/juce_UndoManager.cpp +++ b/modules/juce_data_structures/undomanager/juce_UndoManager.cpp @@ -98,7 +98,7 @@ void UndoManager::setMaxNumberOfStoredUnits (int maxUnits, int minTransactions) } //============================================================================== -bool UndoManager::perform (UndoableAction* const newAction, const String& actionName) +bool UndoManager::perform (UndoableAction* newAction, const String& actionName) { if (perform (newAction)) { @@ -237,8 +237,8 @@ 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 noexcept { return transactions[nextIndex - 1]; } +UndoManager::ActionSet* UndoManager::getNextSet() const noexcept { return transactions[nextIndex]; } bool UndoManager::canUndo() const noexcept { return getCurrentSet() != nullptr; } bool UndoManager::canRedo() const noexcept { return getNextSet() != nullptr; } @@ -297,6 +297,32 @@ String UndoManager::getRedoDescription() const return {}; } +StringArray UndoManager::getUndoDescriptions() const +{ + StringArray descriptions; + + for (int i = nextIndex;;) + { + if (auto* t = transactions[--i]) + descriptions.add (t->name); + else + return descriptions; + } +} + +StringArray UndoManager::getRedoDescriptions() const +{ + StringArray descriptions; + + for (int i = nextIndex;;) + { + if (auto* t = transactions[i++]) + descriptions.add (t->name); + else + return descriptions; + } +} + Time UndoManager::getTimeOfUndoTransaction() const { if (auto* s = getCurrentSet()) diff --git a/modules/juce_data_structures/undomanager/juce_UndoManager.h b/modules/juce_data_structures/undomanager/juce_UndoManager.h index 2edc581872..3eac83abf6 100644 --- a/modules/juce_data_structures/undomanager/juce_UndoManager.h +++ b/modules/juce_data_structures/undomanager/juce_UndoManager.h @@ -158,14 +158,10 @@ public: */ bool canUndo() const noexcept; - /** Returns the name of the transaction that will be rolled-back when undo() is called. - @see undo - */ - String getUndoDescription() const; - /** Tries to roll-back the last transaction. @returns true if the transaction can be undone, and false if it fails, or if there aren't any transactions to undo + @see undoCurrentTransactionOnly */ bool undo(); @@ -184,6 +180,23 @@ public: */ bool undoCurrentTransactionOnly(); + /** Returns the name of the transaction that will be rolled-back when undo() is called. + @see undo, canUndo, getUndoDescriptions + */ + String getUndoDescription() const; + + /** Returns the names of the sequence of transactions that will be performed if undo() + is repeatedly called. Note that for transactions where no name was provided, the + corresponding string will be empty. + @see undo, canUndo, getUndoDescription + */ + StringArray getUndoDescriptions() const; + + /** Returns the time to which the state would be restored if undo() was to be called. + If an undo isn't currently possible, it'll return Time(). + */ + Time getTimeOfUndoTransaction() const; + /** Returns a list of the UndoableAction objects that have been performed during the transaction that is currently open. @@ -200,33 +213,35 @@ public: */ int getNumActionsInCurrentTransaction() const; - /** Returns the time to which the state would be restored if undo() was to be called. - If an undo isn't currently possible, it'll return Time(). - */ - Time getTimeOfUndoTransaction() const; - - /** Returns the time to which the state would be restored if redo() was to be called. - If a redo isn't currently possible, it'll return Time::getCurrentTime(). - */ - Time getTimeOfRedoTransaction() const; - //============================================================================== /** Returns true if there's at least one action in the list to redo. @see getRedoDescription, redo, canUndo */ bool canRedo() const noexcept; - /** Returns the name of the transaction that will be redone when redo() is called. - @see redo - */ - String getRedoDescription() const; - /** Tries to redo the last transaction that was undone. @returns true if the transaction can be redone, and false if it fails, or if there aren't any transactions to redo */ bool redo(); + /** Returns the name of the transaction that will be redone when redo() is called. + @see redo, canRedo, getRedoDescriptions + */ + String getRedoDescription() const; + + /** Returns the names of the sequence of transactions that will be performed if redo() + is repeatedly called. Note that for transactions where no name was provided, the + corresponding string will be empty. + @see redo, canRedo, getRedoDescription + */ + StringArray getRedoDescriptions() const; + + /** Returns the time to which the state would be restored if redo() was to be called. + If a redo isn't currently possible, it'll return Time::getCurrentTime(). + @see redo, canRedo + */ + Time getTimeOfRedoTransaction() const; private: //==============================================================================