Loading...
Searching...
No Matches
ActionManager.hpp
1#pragma once
3#include <score/tools/std/HashMap.hpp>
4
5namespace score
6{
7template <typename T1, typename T2>
8using enable_if_base_of = std::enable_if<std::is_base_of<T1, T2>::value, void*>;
9
18class SCORE_LIB_BASE_EXPORT ActionManager : public QObject
19{
20public:
23
24 void insert(Action val);
25
26 void insert(std::vector<Action> vals);
27
28 auto& get() { return m_container; }
29 auto& get() const { return m_container; }
30 template <typename T>
31 auto& action()
32 {
33 return m_container.at(MetaAction<T>::key());
34 }
35 template <typename T>
36 auto& action() const
37 {
38 return m_container.at(MetaAction<T>::key());
39 }
40
41 void reset(Document* doc);
42
43 void onDocumentChange(std::shared_ptr<ActionCondition> cond);
44 void onFocusChange(std::shared_ptr<ActionCondition> cond);
45 void onSelectionChange(std::shared_ptr<ActionCondition> cond);
46 void onCustomChange(std::shared_ptr<ActionCondition> cond);
47
48 const auto& documentConditions() const { return m_docConditions; }
49 const auto& focusConditions() const { return m_focusConditions; }
50 const auto& selectionConditions() const { return m_selectionConditions; }
51 const auto& customConditions() const { return m_customConditions; }
52
53 template <typename Condition_T>
54 requires(std::is_base_of_v<DocumentActionCondition, Condition_T>)
55 auto& condition() const
56 {
57 return *m_docConditions.at(Condition_T::static_key());
58 }
59 template <typename Condition_T>
60 requires(std::is_base_of_v<FocusActionCondition, Condition_T>)
61 auto& condition() const
62 {
63 return *m_focusConditions.at(Condition_T::static_key());
64 }
65 template <typename Condition_T>
66 requires(std::is_base_of_v<SelectionActionCondition, Condition_T>)
67 auto& condition() const
68 {
69 return *m_selectionConditions.at(Condition_T::static_key());
70 }
71 template <typename Condition_T>
72 requires(std::is_base_of_v<CustomActionCondition, Condition_T>)
73 auto& condition() const
74 {
75 return *m_customConditions.at(Condition_T::static_key());
76 }
77
78 template <typename Condition_T>
79 requires(
80 !std::is_base_of_v<DocumentActionCondition, Condition_T>
81 && !std::is_base_of_v<FocusActionCondition, Condition_T>
82 && !std::is_base_of_v<SelectionActionCondition, Condition_T>
83 && !std::is_base_of_v<CustomActionCondition, Condition_T>
84 && std::is_base_of_v<ActionCondition, Condition_T>)
85 auto& condition() const
86 {
87 return *m_conditions.at(Condition_T::static_key());
88 }
89
90private:
91 void documentChanged(MaybeDocument doc);
92 void focusChanged(MaybeDocument doc);
93 void selectionChanged(MaybeDocument doc);
94 void resetCustomActions(MaybeDocument doc);
95
96 score::hash_map<ActionKey, Action> m_container;
97
98 // Conditions for the enablement of the actions
99 score::hash_map<StringKey<ActionCondition>, std::shared_ptr<ActionCondition>>
100 m_docConditions;
101 score::hash_map<StringKey<ActionCondition>, std::shared_ptr<ActionCondition>>
102 m_focusConditions;
103 score::hash_map<StringKey<ActionCondition>, std::shared_ptr<ActionCondition>>
104 m_selectionConditions;
105 score::hash_map<StringKey<ActionCondition>, std::shared_ptr<ActionCondition>>
106 m_customConditions;
107 score::hash_map<StringKey<ActionCondition>, std::shared_ptr<ActionCondition>>
108 m_conditions;
109
110 QMetaObject::Connection focusConnection;
111 QMetaObject::Connection selectionConnection;
112};
113}
The Action class.
Definition Action.hpp:79
The ActionManager class.
Definition ActionManager.hpp:19
The Document class is the central part of the software.
Definition Document.hpp:51
Base toolkit upon which the software is built.
Definition Application.cpp:90
Definition DocumentContext.hpp:18
Definition Action.hpp:114