1 // This file is part of VSTGUI. It is subject to the license terms
2 // in the LICENSE file found in the top-level directory of this
3 // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
4 
5 #pragma once
6 
7 #include "../../lib/vstguibase.h"
8 
9 #if VSTGUI_LIVE_EDITING
10 
11 #include "../../lib/dispatchlist.h"
12 #include <list>
13 #include <deque>
14 
15 namespace VSTGUI {
16 class IAction;
17 class UIGroupAction;
18 class UIUndoManager;
19 
20 //----------------------------------------------------------------------------------------------------
21 struct IUIUndoManagerListener
22 {
23 	virtual ~IUIUndoManagerListener () noexcept = default;
24 	virtual void onUndoManagerChange () = 0;
25 };
26 
27 //----------------------------------------------------------------------------------------------------
28 class UIUndoManager : public NonAtomicReferenceCounted,
29                       protected ListenerProvider<UIUndoManager, IUIUndoManagerListener>,
30                       protected std::list<IAction*>
31 {
32 public:
33 	UIUndoManager ();
34 	~UIUndoManager () override;
35 
36 	void pushAndPerform (IAction* action);
37 
38 	UTF8StringPtr getUndoName ();
39 	UTF8StringPtr getRedoName ();
40 
41 	void performUndo ();
42 	void performRedo ();
43 	bool canUndo ();
44 	bool canRedo ();
45 
46 	void startGroupAction (UTF8StringPtr name);
47 	void endGroupAction ();
48 	void cancelGroupAction ();
49 
50 	void clear ();
51 
52 	void markSavePosition ();
53 	bool isSavePosition () const;
54 
55 	using ListenerProvider<UIUndoManager, IUIUndoManagerListener>::registerListener;
56 	using ListenerProvider<UIUndoManager, IUIUndoManagerListener>::unregisterListener;
57 protected:
58 	iterator position;
59 	iterator savePosition;
60 	using GroupActionDeque = std::deque<UIGroupAction*>;
61 	GroupActionDeque groupQueue;
62 };
63 
64 } // VSTGUI
65 
66 #endif // VSTGUI_LIVE_EDITING
67