Plasma Engine  2.0
Loading...
Searching...
No Matches
Command.h
1#pragma once
2
3#include <Foundation/Reflection/Reflection.h>
4#include <Foundation/Types/Status.h>
5#include <ToolsFoundation/ToolsFoundationDLL.h>
6
7class plDocument;
9
14class PL_TOOLSFOUNDATION_DLL plCommand : public plReflectedClass
15{
16 PL_ADD_DYNAMIC_REFLECTION(plCommand, plReflectedClass);
17
18public:
19 plCommand();
20 ~plCommand();
21
22 bool IsUndoable() const { return m_bUndoable; };
23 bool HasChildActions() const { return !m_ChildActions.IsEmpty(); }
24 bool HasModifiedDocument() const;
25
26 enum class CommandState
27 {
28 WasDone,
29 WasUndone
30 };
31
32protected:
33 plStatus Do(bool bRedo);
34 plStatus Undo(bool bFireEvents);
35 void Cleanup(CommandState state);
36
37 plStatus AddSubCommand(plCommand& command);
38 plDocument* GetDocument() { return m_pDocument; };
39
40private:
41 virtual bool HasReturnValues() const { return false; }
42 virtual plStatus DoInternal(bool bRedo) = 0;
43 virtual plStatus UndoInternal(bool bFireEvents) = 0;
44 virtual void CleanupInternal(CommandState state) = 0;
45
46protected:
47 friend class plCommandHistory;
48 friend class plCommandTransaction;
49
50 plString m_sDescription;
51 bool m_bUndoable = true;
52 bool m_bModifiedDocument = true;
53 plHybridArray<plCommand*, 8> m_ChildActions;
54 plDocument* m_pDocument = nullptr;
55};
Stores the undo / redo stacks of transactions done on a document.
Definition CommandHistory.h:52
Interface for a command.
Definition Command.h:15
Definition CommandHistory.h:11
Definition Document.h:57
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
All classes that should be dynamically reflectable, need to be derived from this base class.
Definition DynamicRTTI.h:86
An plResult with an additional message for the reason of failure.
Definition Status.h:12