KiCad PCB EDA Suite
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  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef ACTION_MANAGER_H_
26 #define ACTION_MANAGER_H_
27 
28 #include <list>
29 #include <map>
30 #include <string>
31 
32 class TOOL_BASE;
33 class TOOL_MANAGER;
34 class TOOL_ACTION;
35 
43 {
44 public:
49  ACTION_MANAGER( TOOL_MANAGER* aToolManager );
50 
56 
63  void RegisterAction( TOOL_ACTION* aAction );
64 
70  void UnregisterAction( TOOL_ACTION* aAction );
71 
75  static int MakeActionId( const std::string& aActionName );
76 
83  TOOL_ACTION* FindAction( const std::string& aActionName ) const;
84 
91  bool RunHotKey( int aHotKey ) const;
92 
98  int GetHotKey( const TOOL_ACTION& aAction ) const;
99 
104  void UpdateHotKeys();
105 
112  static std::list<TOOL_ACTION*>& GetActionList()
113  {
114  static std::list<TOOL_ACTION*> actionList;
115 
116  return actionList;
117  }
118 
119 private:
122  int processHotKey( TOOL_ACTION* aAction );
123 
126 
128  std::map<std::string, TOOL_ACTION*> m_actionNameIndex;
129 
131  typedef std::map<int, std::list<TOOL_ACTION*> > HOTKEY_LIST;
132  HOTKEY_LIST m_actionHotKeys;
133 
135  std::map<int, int> m_hotkeys;
136 };
137 
138 #endif /* ACTION_MANAGER_H_ */
std::map< int, int > m_hotkeys
Quick action<->hot key lookup
static int MakeActionId(const std::string &aActionName)
Generates an unique ID from for an action with given name.
void UpdateHotKeys()
Function UpdateHotKeys() Updates TOOL_ACTIONs hot key assignment according to the current frame's Hot...
std::map< int, std::list< TOOL_ACTION * > > HOTKEY_LIST
Map for indexing actions by their hotkeys
~ACTION_MANAGER()
Destructor.
Class ACTION_MANAGER.
TOOL_ACTION * FindAction(const std::string &aActionName) const
Function FindAction() Finds an action with a given name (if there is one available).
static std::list< TOOL_ACTION * > & GetActionList()
Function GetActionList() Returns list of TOOL_ACTIONs.
Class TOOL_MANAGER.
Definition: tool_manager.h:49
int GetHotKey(const TOOL_ACTION &aAction) const
Function GetHotKey() Returns the hot key associated with a given action or 0 if there is none...
bool RunHotKey(int aHotKey) const
Function RunHotKey() Runs an action associated with a hotkey (if there is one available).
ACTION_MANAGER(TOOL_MANAGER *aToolManager)
Constructor.
void UnregisterAction(TOOL_ACTION *aAction)
Function UnregisterAction() Removes a tool action from the manager and makes it unavailable for furth...
std::map< std::string, TOOL_ACTION * > m_actionNameIndex
Map for indexing actions by their names
int processHotKey(TOOL_ACTION *aAction)
Resolves a reference to legacy hot key settings to a particular hot key.
HOTKEY_LIST m_actionHotKeys
TOOL_MANAGER * m_toolMgr
Tool manager needed to run actions
void RegisterAction(TOOL_ACTION *aAction)
Function RegisterAction() Adds a tool action to the manager and sets it up.
Class TOOL_BASE.
Definition: tool_base.h:68
Class TOOL_ACTION.
Definition: tool_action.h:46