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 (C) 2020 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, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27#ifndef ACTION_MANAGER_H_
28#define ACTION_MANAGER_H_
29
30#include <list>
31#include <map>
32#include <string>
33#include <set>
34
36
37class TOOL_BASE;
38class TOOL_MANAGER;
39class TOOL_ACTION;
40
49{
51 {
52 checkCondition = SELECTION_CONDITIONS::ShowNever; // Never check by default
53 enableCondition = SELECTION_CONDITIONS::ShowAlways; // Always enable by default
54 showCondition = SELECTION_CONDITIONS::ShowAlways; // Always show by default
55 }
56
58 {
59 checkCondition = aCondition;
60 return *this;
61 }
62
64 {
65 enableCondition = aCondition;
66 return *this;
67 }
68
70 {
71 showCondition = aCondition;
72 return *this;
73 }
74
78};
79
86{
87public:
91 ACTION_MANAGER( TOOL_MANAGER* aToolManager );
92
97
104 void RegisterAction( TOOL_ACTION* aAction );
105
109 static int MakeActionId( const std::string& aActionName );
110
114 const std::map<std::string, TOOL_ACTION*>& GetActions() const;
115
119 bool IsActionUIId( int aId ) const;
120
127 TOOL_ACTION* FindAction( const std::string& aActionName ) const;
128
135 bool RunHotKey( int aHotKey ) const;
136
142 int GetHotKey( const TOOL_ACTION& aAction ) const;
143
147 void UpdateHotKeys( bool aFullUpdate );
148
156 static std::list<TOOL_ACTION*>& GetActionList()
157 {
158 static std::list<TOOL_ACTION*> actionList;
159
160 return actionList;
161 }
162
170 void SetConditions( const TOOL_ACTION& aAction, const ACTION_CONDITIONS& aConditions );
171
178 const ACTION_CONDITIONS* GetCondition( const TOOL_ACTION& aAction ) const;
179
180private:
181 // Resolve a hotkey by applying legacy and current settings over the action's
182 // default hotkey.
183 void processHotKey( TOOL_ACTION* aAction, const std::map<std::string, int>& aLegacyMap,
184 const std::map<std::string, std::pair<int, int>>& aHotKeyMap );
185
188
190 std::map<std::string, TOOL_ACTION*> m_actionNameIndex;
191
193 std::map<int, TOOL_ACTION*> m_customUIIdIndex;
194
196 typedef std::map<int, std::list<TOOL_ACTION*> > HOTKEY_LIST;
198
200 std::map<int, int> m_hotkeys;
201
204 std::map<int, ACTION_CONDITIONS> m_uiConditions;
205};
206
207#endif /* ACTION_MANAGER_H_ */
Manage TOOL_ACTION objects.
~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 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.
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.
Definition: tool_action.h:269
Base abstract interface for all kinds of tools.
Definition: tool_base.h:66
Master controller class:
Definition: tool_manager.h:57
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)