OpenShot Audio Library | OpenShotAudio  0.6.0
juce_UndoManager.h
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2022 - Raw Material Software Limited
6 
7  JUCE is an open source library subject to commercial or open-source
8  licensing.
9 
10  By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11  Agreement and JUCE Privacy Policy.
12 
13  End User License Agreement: www.juce.com/juce-7-licence
14  Privacy Policy: www.juce.com/juce-privacy-policy
15 
16  Or: You may also use this code under the terms of the GPL v3 (see
17  www.gnu.org/licenses).
18 
19  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21  DISCLAIMED.
22 
23  ==============================================================================
24 */
25 
26 namespace juce
27 {
28 
29 //==============================================================================
51 class JUCE_API UndoManager : public ChangeBroadcaster
52 {
53 public:
54  //==============================================================================
68  UndoManager (int maxNumberOfUnitsToKeep = 30000,
69  int minimumTransactionsToKeep = 30);
70 
72  ~UndoManager() override;
73 
74  //==============================================================================
76  void clearUndoHistory();
77 
81  int getNumberOfUnitsTakenUpByStoredCommands() const;
82 
97  void setMaxNumberOfStoredUnits (int maxNumberOfUnitsToKeep,
98  int minimumTransactionsToKeep);
99 
100  //==============================================================================
108  bool perform (UndoableAction* action);
109 
120  bool perform (UndoableAction* action, const String& actionName);
121 
128  void beginNewTransaction();
129 
139  void beginNewTransaction (const String& actionName);
140 
147  void setCurrentTransactionName (const String& newName);
148 
152  String getCurrentTransactionName() const;
153 
154  //==============================================================================
158  bool canUndo() const;
159 
165  bool undo();
166 
180  bool undoCurrentTransactionOnly();
181 
185  String getUndoDescription() const;
186 
192  StringArray getUndoDescriptions() const;
193 
197  Time getTimeOfUndoTransaction() const;
198 
207  void getActionsInCurrentTransaction (Array<const UndoableAction*>& actionsFound) const;
208 
213  int getNumActionsInCurrentTransaction() const;
214 
215  //==============================================================================
219  bool canRedo() const;
220 
225  bool redo();
226 
230  String getRedoDescription() const;
231 
237  StringArray getRedoDescriptions() const;
238 
243  Time getTimeOfRedoTransaction() const;
244 
246  bool isPerformingUndoRedo() const;
247 
248 private:
249  //==============================================================================
250  struct ActionSet;
251  OwnedArray<ActionSet> transactions, stashedFutureTransactions;
252  String newTransactionName;
253  int totalUnitsStored = 0, maxNumUnitsToKeep = 0, minimumTransactionsToKeep = 0, nextIndex = 0;
254  bool newTransaction = true, isInsideUndoRedoCall = false;
255  ActionSet* getCurrentSet() const;
256  ActionSet* getNextSet() const;
257  void moveFutureTransactionsToStash();
258  void restoreStashedFutureTransactions();
259  void dropOldTransactionsIfTooLarge();
260 
261  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (UndoManager)
262 };
263 
264 } // namespace juce