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 
68  static int MakeActionId( const std::string& aActionName );
69 
73  const std::map<std::string, TOOL_ACTION*>& GetActions();
74 
81  TOOL_ACTION* FindAction( const std::string& aActionName ) const;
82 
89  bool RunHotKey( int aHotKey ) const;
90 
96  int GetHotKey( const TOOL_ACTION& aAction ) const;
97 
102  void UpdateHotKeys( bool aFullUpdate );
103 
110  static std::list<TOOL_ACTION*>& GetActionList()
111  {
112  static std::list<TOOL_ACTION*> actionList;
113 
114  return actionList;
115  }
116 
117 private:
118  // Resolves a hotkey by applying legacy and current settings over the action's
119  // default hotkey.
120  int processHotKey( TOOL_ACTION* aAction, std::map<std::string, int> aLegacyMap,
121  std::map<std::string, int> aHotKeyMap );
122 
125 
127  std::map<std::string, TOOL_ACTION*> m_actionNameIndex;
128 
130  typedef std::map<int, std::list<TOOL_ACTION*> > HOTKEY_LIST;
132 
134  std::map<int, int> m_hotkeys;
135 };
136 
137 #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(bool aFullUpdate)
Function UpdateHotKeys() Optionally reads the hotkey config files and then rebuilds the internal hotk...
std::map< int, std::list< TOOL_ACTION * > > HOTKEY_LIST
Map for indexing actions by their hotkeys
~ACTION_MANAGER()
Destructor.
ACTION_MANAGER.
static std::list< TOOL_ACTION * > & GetActionList()
Function GetActionList() Returns list of TOOL_ACTIONs.
const std::map< std::string, TOOL_ACTION * > & GetActions()
Get a list of currently-registered actions mapped by their name.
TOOL_ACTION * FindAction(const std::string &aActionName) const
Function FindAction() Finds an action with a given name (if there is one available).
bool RunHotKey(int aHotKey) const
Function RunHotKey() Runs an action associated with a hotkey (if there is one available).
TOOL_MANAGER.
Definition: tool_manager.h:50
int GetHotKey(const TOOL_ACTION &aAction) const
Function GetHotKey() Returns the hot key associated with a given action or 0 if there is none.
ACTION_MANAGER(TOOL_MANAGER *aToolManager)
Constructor.
std::map< std::string, TOOL_ACTION * > m_actionNameIndex
Map for indexing actions by their names
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.
int processHotKey(TOOL_ACTION *aAction, std::map< std::string, int > aLegacyMap, std::map< std::string, int > aHotKeyMap)
TOOL_BASE.
Definition: tool_base.h:66
TOOL_ACTION.
Definition: tool_action.h:46