Plasma Engine  2.0
Loading...
Searching...
No Matches
ActionMap.h
1#pragma once
2
3#include <GuiFoundation/Action/Action.h>
4#include <GuiFoundation/GuiFoundationDLL.h>
5#include <ToolsFoundation/Object/DocumentObjectManager.h>
6
7class plDocument;
8
15PL_DECLARE_REFLECTABLE_TYPE(PL_NO_LINKAGE, plActionMapDescriptor);
16
17template <typename T>
19{
20public:
22 : m_pParent(nullptr)
23 {
24 }
25 plTreeNode(const T& data)
26 : m_Data(data)
27 , m_pParent(nullptr)
28 {
29 }
31 {
32 while (!m_Children.IsEmpty())
33 {
34 RemoveChild(0);
35 }
36 }
37
38 const plUuid& GetGuid() const { return m_Guid; }
39 const plTreeNode<T>* GetParent() const { return m_pParent; }
40 plTreeNode<T>* GetParent() { return m_pParent; }
41 const plHybridArray<plTreeNode<T>*, 8>& GetChildren() const { return m_Children; }
42 plHybridArray<plTreeNode<T>*, 8>& GetChildren() { return m_Children; }
43
44 plTreeNode<T>* InsertChild(const T& data, plUInt32 uiIndex)
45 {
46 plTreeNode<T>* pNode = PL_DEFAULT_NEW(plTreeNode<T>, data);
47 pNode->m_Guid = plUuid::MakeUuid();
48 m_Children.InsertAt(uiIndex, pNode);
49 pNode->m_pParent = this;
50 return pNode;
51 }
52
53 bool RemoveChild(plUInt32 uiIndex)
54 {
55 if (uiIndex > m_Children.GetCount())
56 return false;
57
58 plTreeNode<T>* pChild = m_Children[uiIndex];
59 m_Children.RemoveAtAndCopy(uiIndex);
60 PL_DEFAULT_DELETE(pChild);
61 return true;
62 }
63
64 plUInt32 GetParentIndex() const
65 {
66 PL_ASSERT_DEV(m_pParent != nullptr, "Can't compute parent index if no parent is present!");
67 for (plUInt32 i = 0; i < m_pParent->GetChildren().GetCount(); i++)
68 {
69 if (m_pParent->GetChildren()[i] == this)
70 return i;
71 }
72 PL_REPORT_FAILURE("Couldn't find oneself in own parent!");
73 return -1;
74 }
75
76 T m_Data;
77 plUuid m_Guid;
78
79private:
80 plTreeNode<T>* m_pParent;
81 plHybridArray<plTreeNode<T>*, 8> m_Children;
82};
83
101class PL_GUIFOUNDATION_DLL plActionMap
102{
103public:
105 plActionMap();
106 ~plActionMap();
107
128 void MapAction(plActionDescriptorHandle hAction, plStringView sPath, float fOrder);
129
134 void MapAction(plActionDescriptorHandle hAction, plStringView sPath, plStringView sSubPath, float fOrder);
135
137 plResult UnmapAction(plActionDescriptorHandle hAction, plStringView sPath);
138
142 plResult SearchPathForAction(plStringView sUniqueName, plStringBuilder& out_sPath) const;
143
144 const TreeNode* GetRootObject() const { return &m_Root; }
145
146 const plActionMapDescriptor* GetDescriptor(const plTreeNode<plActionMapDescriptor>* pObject) const;
147
148private:
149 plUuid MapAction(const plActionMapDescriptor& desc);
150 plResult UnmapAction(const plActionMapDescriptor& desc);
151 plResult UnmapAction(const plUuid& guid);
152
153 const plActionMapDescriptor* GetDescriptor(const plUuid& guid) const;
154
155 bool FindObjectByPath(plStringView sPath, plUuid& out_guid) const;
156 bool FindObjectPathByName(const plTreeNode<plActionMapDescriptor>* pObject, plStringView sName, plStringBuilder& out_sPath) const;
157 const plTreeNode<plActionMapDescriptor>* GetChildByName(const plTreeNode<plActionMapDescriptor>* pObject, plStringView sName) const;
158
159 TreeNode m_Root;
161};
Handle for a plAction.
Definition Action.h:27
Defines the structure of how actions are organized in a particular context.
Definition ActionMap.h:102
void RemoveAtAndCopy(plUInt32 uiIndex, plUInt32 uiNumElements=1)
Removes the element at index and fills the gap by shifting all following elements.
Definition ArrayBase_inl.h:253
void InsertAt(plUInt32 uiIndex, const T &value)
Inserts value at index by shifting all following elements.
Definition ArrayBase_inl.h:197
bool IsEmpty() const
Returns true, if the array does not contain any elements.
Definition ArrayBase_inl.h:178
plUInt32 GetCount() const
Returns the number of active elements in the array.
Definition ArrayBase_inl.h:172
Definition Document.h:57
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Definition Map.h:408
plStringBuilder is a class that is meant for creating and modifying strings.
Definition StringBuilder.h:35
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
Definition ActionMap.h:19
This data type is the abstraction for 128-bit Uuid (also known as GUID) instances.
Definition Uuid.h:11
static plUuid MakeUuid()
Returns a new Uuid.
Definition UuidGenerator_Posix.h:30
Definition ActionMap.h:10
plActionDescriptorHandle m_hAction
Action to be mapped.
Definition ActionMap.h:11
plString m_sPath
Path where the action should be mapped excluding the action's name, e.g. "File/New" for a menu item "...
Definition ActionMap.h:12
float m_fOrder
Ordering key to sort actions in the mapping path.
Definition ActionMap.h:13
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54