Horizon
action.hpp
1 #pragma once
2 #include <string>
3 #include <vector>
4 #include <gdk/gdk.h>
5 #include <functional>
6 
7 namespace horizon {
8 
9 enum class ToolID;
10 enum class ActionID;
11 
12 
13 struct ActionToolID {
14  ActionToolID(ActionID a, ToolID t) : action(a), tool(t)
15  {
16  }
17 
18  ActionToolID(ActionID a);
19  ActionToolID(ToolID t);
20  ActionToolID();
21 
22  bool is_tool() const;
23  bool is_action() const;
24  bool is_valid() const;
25 
26  ActionID action;
27  ToolID tool;
28 
29 private:
30  auto tie() const
31  {
32  return std::tie(action, tool);
33  }
34 
35 public:
36  bool operator<(const ActionToolID &other) const
37  {
38  return tie() < other.tie();
39  }
40  bool operator==(const ActionToolID &other) const
41  {
42  return tie() == other.tie();
43  }
44 };
45 
46 enum class ActionGroup {
47  ALL,
48  UNKNOWN,
49  CLIPBOARD,
50  UNDO,
51  MOVE,
52  GRAPHICS,
53  SCHEMATIC,
54  SYMBOL,
55  PACKAGE,
56  PADSTACK,
57  BOARD,
58  LAYER,
59  SELECTION,
60  RULES,
61  VIEW,
62  FRAME,
63  GROUP_TAG,
64  SEARCH,
65  EXPORT_IMPORT,
66  TUNING,
67  VIEW_3D,
68 };
69 
70 enum class ActionSource {
71  UNKNOWN,
72  KEY,
73 };
74 
75 using KeySequenceItem = std::pair<unsigned int, GdkModifierType>;
76 using KeySequence = std::vector<KeySequenceItem>;
77 
78 std::string key_sequence_item_to_string(const KeySequenceItem &it);
79 std::string key_sequence_to_string(const KeySequence &keys);
80 std::string key_sequence_to_string_short(const KeySequence &keys);
81 
82 std::string key_sequences_to_string(const std::vector<KeySequence> &seqs);
83 
84 enum class KeyMatchResult { NONE, PREFIX, COMPLETE };
85 KeyMatchResult key_sequence_match(const KeySequence &keys_current, const KeySequence &keys_from_action);
86 
88 public:
89  ActionConnection(ActionToolID atid, std::function<void(const ActionConnection &, ActionSource)> c) : id(atid), cb(c)
90  {
91  }
92 
93  const ActionToolID id;
94  std::vector<KeySequence> key_sequences;
95  std::function<void(const ActionConnection &, ActionSource)> cb;
96 };
97 
98 } // namespace horizon
Definition: action.hpp:87
Definition: action.hpp:13