OpenShot Audio Library | OpenShotAudio  0.3.1
juce_UndoManager.h
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2017 - ROLI Ltd.
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 5 End-User License
11  Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
12  27th April 2017).
13 
14  End User License Agreement: www.juce.com/juce-5-licence
15  Privacy Policy: www.juce.com/juce-5-privacy-policy
16 
17  Or: You may also use this code under the terms of the GPL v3 (see
18  www.gnu.org/licenses).
19 
20  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22  DISCLAIMED.
23 
24  ==============================================================================
25 */
26 
27 namespace juce
28 {
29 
30 //==============================================================================
52 class JUCE_API UndoManager : public ChangeBroadcaster
53 {
54 public:
55  //==============================================================================
69  UndoManager (int maxNumberOfUnitsToKeep = 30000,
70  int minimumTransactionsToKeep = 30);
71 
73  ~UndoManager() override;
74 
75  //==============================================================================
77  void clearUndoHistory();
78 
82  int getNumberOfUnitsTakenUpByStoredCommands() const;
83 
98  void setMaxNumberOfStoredUnits (int maxNumberOfUnitsToKeep,
99  int minimumTransactionsToKeep);
100 
101  //==============================================================================
109  bool perform (UndoableAction* action);
110 
121  bool perform (UndoableAction* action, const String& actionName);
122 
129  void beginNewTransaction();
130 
140  void beginNewTransaction (const String& actionName);
141 
148  void setCurrentTransactionName (const String& newName);
149 
153  String getCurrentTransactionName() const;
154 
155  //==============================================================================
159  bool canUndo() const;
160 
166  bool undo();
167 
181  bool undoCurrentTransactionOnly();
182 
186  String getUndoDescription() const;
187 
193  StringArray getUndoDescriptions() const;
194 
198  Time getTimeOfUndoTransaction() const;
199 
208  void getActionsInCurrentTransaction (Array<const UndoableAction*>& actionsFound) const;
209 
214  int getNumActionsInCurrentTransaction() const;
215 
216  //==============================================================================
220  bool canRedo() const;
221 
226  bool redo();
227 
231  String getRedoDescription() const;
232 
238  StringArray getRedoDescriptions() const;
239 
244  Time getTimeOfRedoTransaction() const;
245 
247  bool isPerformingUndoRedo() const;
248 
249 private:
250  //==============================================================================
251  struct ActionSet;
252  OwnedArray<ActionSet> transactions, stashedFutureTransactions;
253  String newTransactionName;
254  int totalUnitsStored = 0, maxNumUnitsToKeep = 0, minimumTransactionsToKeep = 0, nextIndex = 0;
255  bool newTransaction = true, isInsideUndoRedoCall = false;
256  ActionSet* getCurrentSet() const;
257  ActionSet* getNextSet() const;
258  void moveFutureTransactionsToStash();
259  void restoreStashedFutureTransactions();
260  void dropOldTransactionsIfTooLarge();
261 
262  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (UndoManager)
263 };
264 
265 } // namespace juce