Plasma Engine  2.0
Loading...
Searching...
No Matches
Action.h
1#pragma once
2
3#include <Foundation/Communication/Event.h>
4#include <Foundation/Containers/IdTable.h>
5#include <Foundation/Containers/Map.h>
6#include <Foundation/Containers/Set.h>
7#include <Foundation/Strings/HashedString.h>
8#include <Foundation/Types/Enum.h>
9#include <Foundation/Types/Variant.h>
10#include <GuiFoundation/GuiFoundationDLL.h>
11#include <QKeySequence>
12#include <ToolsFoundation/Document/DocumentManager.h>
13
14class QWidget;
16class plAction;
17struct plActionContext;
18
20using CreateActionFunc = plAction* (*)(const plActionContext&);
21using DeleteActionFunc = void (*)(plAction*);
22
26class PL_GUIFOUNDATION_DLL plActionDescriptorHandle
27{
28public:
29 using StorageType = plUInt32;
30
31 PL_DECLARE_HANDLE_TYPE(plActionDescriptorHandle, plActionId);
32 friend class plActionManager;
33
34public:
35 const plActionDescriptor* GetDescriptor() const;
36};
37
40{
41 enum Enum
42 {
43 Global,
44 Document,
45 Window,
46 Default = Global
47 };
48 using StorageType = plUInt8;
49};
50
53{
54 enum Enum
55 {
56 Action,
57 Category,
58 Menu,
59 ActionAndMenu,
60 Default = Action
61 };
62 using StorageType = plUInt8;
63};
64
66struct PL_GUIFOUNDATION_DLL plActionContext
67{
68 plActionContext() = default;
69 plActionContext(plDocument* pDoc) { m_pDocument = pDoc; }
70
71 plDocument* m_pDocument = nullptr;
72 plString m_sMapping;
73 QWidget* m_pWindow = nullptr;
74};
75
76
78struct PL_GUIFOUNDATION_DLL plActionDescriptor
79{
80 plActionDescriptor() = default;
81 ;
82 plActionDescriptor(plActionType::Enum type, plActionScope::Enum scope, const char* szName, const char* szCategoryPath, const char* szShortcut,
83 CreateActionFunc createAction, DeleteActionFunc deleteAction = nullptr);
84
87
91
92 plString m_sShortcut;
93 plString m_sDefaultShortcut;
94
95 plAction* CreateAction(const plActionContext& context) const;
96 void DeleteAction(plAction* pAction) const;
97
98 void UpdateExistingActions();
99
100private:
101 CreateActionFunc m_CreateAction;
102 DeleteActionFunc m_DeleteAction;
103
104 mutable plHybridArray<plAction*, 4> m_CreatedActions;
105};
106
107
108
110class PL_GUIFOUNDATION_DLL plAction : public plReflectedClass
111{
112 PL_ADD_DYNAMIC_REFLECTION(plAction, plReflectedClass);
113 PL_DISALLOW_COPY_AND_ASSIGN(plAction);
114
115public:
116 plAction(const plActionContext& context) { m_Context = context; }
117 virtual void Execute(const plVariant& value) = 0;
118
119 void TriggerUpdate();
120 const plActionContext& GetContext() const { return m_Context; }
121 plActionDescriptorHandle GetDescriptorHandle() { return m_hDescriptorHandle; }
122
123public:
125
126protected:
127 plActionContext m_Context;
128
129private:
130 friend struct plActionDescriptor;
131 plActionDescriptorHandle m_hDescriptorHandle;
132};
Handle for a plAction.
Definition Action.h:27
Definition Action.h:111
plEvent< plAction * > m_StatusUpdateEvent
Fire when the state of the action changes (enabled, value etc...)
Definition Action.h:124
Stores 'actions' (things that can be triggered from UI).
Definition ActionManager.h:60
Definition Document.h:57
Definition Event.h:177
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
plVariant is a class that can store different types of variables, which is useful in situations where...
Definition Variant.h:44
Definition Action.h:67
Definition Action.h:79
plString m_sActionName
Unique within category path, shown in key configuration dialog.
Definition Action.h:89
plString m_sCategoryPath
Category in key configuration dialog, e.g. "Tree View" or "File".
Definition Action.h:90
Definition Action.h:40
Definition Action.h:53
A custom enum implementation that allows to define the underlying storage type to control its memory ...
Definition Enum.h:37