Loading...
Searching...
No Matches
juce_UndoManager.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 7 End-User License
Agreement and JUCE Privacy Policy.
End User License Agreement: www.juce.com/juce-7-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
class JUCE_API UndoManager : public ChangeBroadcaster
{
public:
//==============================================================================
UndoManager (int maxNumberOfUnitsToKeep = 30000,
int minimumTransactionsToKeep = 30);
~UndoManager() override;
//==============================================================================
void clearUndoHistory();
int getNumberOfUnitsTakenUpByStoredCommands() const;
void setMaxNumberOfStoredUnits (int maxNumberOfUnitsToKeep,
int minimumTransactionsToKeep);
//==============================================================================
bool perform (UndoableAction* action);
bool perform (UndoableAction* action, const String& actionName);
void beginNewTransaction();
void beginNewTransaction (const String& actionName);
void setCurrentTransactionName (const String& newName);
String getCurrentTransactionName() const;
//==============================================================================
bool canUndo() const;
bool undo();
bool undoCurrentTransactionOnly();
String getUndoDescription() const;
StringArray getUndoDescriptions() const;
Time getTimeOfUndoTransaction() const;
void getActionsInCurrentTransaction (Array<const UndoableAction*>& actionsFound) const;
int getNumActionsInCurrentTransaction() const;
//==============================================================================
bool canRedo() const;
bool redo();
String getRedoDescription() const;
StringArray getRedoDescriptions() const;
Time getTimeOfRedoTransaction() const;
bool isPerformingUndoRedo() const;
private:
//==============================================================================
struct ActionSet;
OwnedArray<ActionSet> transactions, stashedFutureTransactions;
String newTransactionName;
int totalUnitsStored = 0, maxNumUnitsToKeep = 0, minimumTransactionsToKeep = 0, nextIndex = 0;
bool newTransaction = true, isInsideUndoRedoCall = false;
ActionSet* getCurrentSet() const;
ActionSet* getNextSet() const;
void moveFutureTransactionsToStash();
void restoreStashedFutureTransactions();
void dropOldTransactionsIfTooLarge();
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (UndoManager)
};
} // namespace juce
juce::Array
Definition juce_Array.h:56
juce::ChangeBroadcaster::ChangeBroadcaster
ChangeBroadcaster() noexcept
Definition juce_ChangeBroadcaster.cpp:26
juce::OwnedArray
Definition juce_OwnedArray.h:50
juce::StringArray
Definition juce_StringArray.h:35
juce::String
Definition juce_String.h:53
juce::Time
Definition juce_Time.h:37
juce::UndoManager::beginNewTransaction
void beginNewTransaction()
Definition juce_UndoManager.cpp:209
juce::UndoManager::getTimeOfUndoTransaction
Time getTimeOfUndoTransaction() const
Definition juce_UndoManager.cpp:325
juce::UndoManager::getCurrentTransactionName
String getCurrentTransactionName() const
Definition juce_UndoManager.cpp:228
juce::UndoManager::setMaxNumberOfStoredUnits
void setMaxNumberOfStoredUnits(int maxNumberOfUnitsToKeep, int minimumTransactionsToKeep)
Definition juce_UndoManager.cpp:91
juce::UndoManager::redo
bool redo()
Definition juce_UndoManager.cpp:264
juce::UndoManager::getRedoDescription
String getRedoDescription() const
Definition juce_UndoManager.cpp:291
juce::UndoManager::getRedoDescriptions
StringArray getRedoDescriptions() const
Definition juce_UndoManager.cpp:312
juce::UndoManager::undo
bool undo()
Definition juce_UndoManager.cpp:245
juce::UndoManager::isPerformingUndoRedo
bool isPerformingUndoRedo() const
Definition juce_UndoManager.cpp:240
juce::UndoManager::clearUndoHistory
void clearUndoHistory()
Definition juce_UndoManager.cpp:78
juce::UndoManager::canUndo
bool canUndo() const
Definition juce_UndoManager.cpp:242
juce::UndoManager::undoCurrentTransactionOnly
bool undoCurrentTransactionOnly()
Definition juce_UndoManager.cpp:341
juce::UndoManager::getNumberOfUnitsTakenUpByStoredCommands
int getNumberOfUnitsTakenUpByStoredCommands() const
Definition juce_UndoManager.cpp:86
juce::UndoManager::perform
bool perform(UndoableAction *action)
Definition juce_UndoManager.cpp:111
juce::UndoManager::getTimeOfRedoTransaction
Time getTimeOfRedoTransaction() const
Definition juce_UndoManager.cpp:333
juce::UndoManager::canRedo
bool canRedo() const
Definition juce_UndoManager.cpp:243
juce::UndoManager::getUndoDescriptions
StringArray getUndoDescriptions() const
Definition juce_UndoManager.cpp:299
juce::UndoManager::getUndoDescription
String getUndoDescription() const
Definition juce_UndoManager.cpp:283
juce::UndoManager::UndoManager
UndoManager(int maxNumberOfUnitsToKeep=30000, int minimumTransactionsToKeep=30)
Definition juce_UndoManager.cpp:68
juce::UndoManager::getActionsInCurrentTransaction
void getActionsInCurrentTransaction(Array< const UndoableAction * > &actionsFound) const
Definition juce_UndoManager.cpp:352
juce::UndoManager::getNumActionsInCurrentTransaction
int getNumActionsInCurrentTransaction() const
Definition juce_UndoManager.cpp:360
juce::UndoManager::setCurrentTransactionName
void setCurrentTransactionName(const String &newName)
Definition juce_UndoManager.cpp:220
juce::UndoableAction
Definition juce_UndoableAction.h:39