KiCad PCB EDA Suite
Loading...
Searching...
No Matches
action_manager.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2013 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Maciej Suminski <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifndef ACTION_MANAGER_H_
24#define ACTION_MANAGER_H_
25
26#include <list>
27#include <map>
28#include <string>
29#include <set>
30#include <vector>
31
32#include <frame_type.h>
34
35class TOOL_BASE;
36class TOOL_MANAGER;
37class TOOL_ACTION;
38
47{
49 {
50 checkCondition = SELECTION_CONDITIONS::ShowNever; // Never check by default
51 enableCondition = SELECTION_CONDITIONS::ShowAlways; // Always enable by default
52 showCondition = SELECTION_CONDITIONS::ShowAlways; // Always show by default
53 }
54
56 {
57 checkCondition = aCondition;
58 return *this;
59 }
60
62 {
63 enableCondition = aCondition;
64 return *this;
65 }
66
68 {
69 showCondition = aCondition;
70 return *this;
71 }
72
76};
77
84{
85public:
89 ACTION_MANAGER( TOOL_MANAGER* aToolManager );
90
95
102 void RegisterAction( TOOL_ACTION* aAction );
103
107 static int MakeActionId( const std::string& aActionName );
108
112 const std::map<std::string, TOOL_ACTION*>& GetActions() const;
113
117 bool IsActionUIId( int aId ) const;
118
125 TOOL_ACTION* FindAction( const std::string& aActionName ) const;
126
133 bool RunHotKey( int aHotKey ) const;
134
139 static std::string FrameNamespacePrefix( FRAME_T aFrameType );
140
145 static void PromoteUserBoundFrameAction( std::vector<const TOOL_ACTION*>& aGlobalActions, FRAME_T aFrameType,
146 int aMatchedHotKey );
147
153 int GetHotKey( const TOOL_ACTION& aAction ) const;
154
158 void UpdateHotKeys( bool aFullUpdate );
159
167 static std::list<TOOL_ACTION*>& GetActionList()
168 {
169 static std::list<TOOL_ACTION*> actionList;
170
171 return actionList;
172 }
173
181 void SetConditions( const TOOL_ACTION& aAction, const ACTION_CONDITIONS& aConditions );
182
189 const ACTION_CONDITIONS* GetCondition( const TOOL_ACTION& aAction ) const;
190
191private:
192 // Resolve a hotkey by applying legacy and current settings over the action's
193 // default hotkey.
194 void processHotKey( TOOL_ACTION* aAction, const std::map<std::string, int>& aLegacyMap,
195 const std::map<std::string, std::pair<int, int>>& aHotKeyMap );
196
199
201 std::map<std::string, TOOL_ACTION*> m_actionNameIndex;
202
204 std::map<int, TOOL_ACTION*> m_customUIIdIndex;
205
207 typedef std::map<int, std::list<TOOL_ACTION*> > HOTKEY_LIST;
209
211 std::map<int, int> m_hotkeys;
212
215 std::map<int, ACTION_CONDITIONS> m_uiConditions;
216};
217
218#endif /* ACTION_MANAGER_H_ */
~ACTION_MANAGER()
Unregister every registered action.
HOTKEY_LIST m_actionHotKeys
Quick action<->hot key lookup.
const ACTION_CONDITIONS * GetCondition(const TOOL_ACTION &aAction) const
Get the conditions to use for a specific tool action.
std::map< int, TOOL_ACTION * > m_customUIIdIndex
Map for indexing actions by their hotkeys.
TOOL_MANAGER * m_toolMgr
Map for indexing actions by their names.
void processHotKey(TOOL_ACTION *aAction, const std::map< std::string, int > &aLegacyMap, const std::map< std::string, std::pair< int, int > > &aHotKeyMap)
Tool manager needed to run actions.
const std::map< std::string, TOOL_ACTION * > & GetActions() const
Get a list of currently-registered actions mapped by their name.
std::map< std::string, TOOL_ACTION * > m_actionNameIndex
Map for recording actions that have custom UI IDs.
std::map< int, int > m_hotkeys
bool RunHotKey(int aHotKey) const
Run an action associated with a hotkey (if there is one available).
void SetConditions(const TOOL_ACTION &aAction, const ACTION_CONDITIONS &aConditions)
Set the conditions the UI elements for activating a specific tool action should use for determining t...
void RegisterAction(TOOL_ACTION *aAction)
Add a tool action to the manager and sets it up.
TOOL_ACTION * FindAction(const std::string &aActionName) const
Find an action with a given name (if there is one available).
static void PromoteUserBoundFrameAction(std::vector< const TOOL_ACTION * > &aGlobalActions, FRAME_T aFrameType, int aMatchedHotKey)
Reorder global actions sharing a hotkey so that one native to the given frame is tried first when the...
static std::list< TOOL_ACTION * > & GetActionList()
Return list of TOOL_ACTIONs.
bool IsActionUIId(int aId) const
Test if a UI ID corresponds to an action ID in our system.
int GetHotKey(const TOOL_ACTION &aAction) const
Return the hot key associated with a given action or 0 if there is none.
static int MakeActionId(const std::string &aActionName)
Generate an unique ID from for an action with given name.
std::map< int, ACTION_CONDITIONS > m_uiConditions
Map the command ID that wx uses for the action to the UI conditions for the menu/toolbar items.
std::map< int, std::list< TOOL_ACTION * > > HOTKEY_LIST
void UpdateHotKeys(bool aFullUpdate)
Optionally read the hotkey config files and then rebuilds the internal hotkey maps.
ACTION_MANAGER(TOOL_MANAGER *aToolManager)
static std::string FrameNamespacePrefix(FRAME_T aFrameType)
Return the action-name namespace prefix (e.g.
static bool ShowAlways(const SELECTION &aSelection)
The default condition function (always returns true).
static bool ShowNever(const SELECTION &aSelection)
Always returns false.
Represent a single user action.
Base abstract interface for all kinds of tools.
Definition tool_base.h:62
Master controller class:
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition frame_type.h:29
std::function< bool(const SELECTION &)> SELECTION_CONDITION
Functor type that checks a specific condition for selected items.
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
SELECTION_CONDITION enableCondition
Returns true if the UI control should be enabled.
SELECTION_CONDITION checkCondition
Returns true if the UI control should be checked.
ACTION_CONDITIONS & Enable(const SELECTION_CONDITION &aCondition)
SELECTION_CONDITION showCondition
Returns true if the UI control should be shown.
ACTION_CONDITIONS & Check(const SELECTION_CONDITION &aCondition)
ACTION_CONDITIONS & Show(const SELECTION_CONDITION &aCondition)