2013-09-20 16:21:01 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 CERN
|
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ACTION_MANAGER_H_
|
|
|
|
#define ACTION_MANAGER_H_
|
|
|
|
|
2014-04-09 15:05:05 +00:00
|
|
|
#include <list>
|
2013-09-20 16:21:01 +00:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
class TOOL_BASE;
|
|
|
|
class TOOL_MANAGER;
|
|
|
|
class TOOL_ACTION;
|
|
|
|
|
2013-09-27 16:51:21 +00:00
|
|
|
/**
|
|
|
|
* Class ACTION_MANAGER
|
|
|
|
*
|
|
|
|
* Takes care of TOOL_ACTION objects. Registers them and allows to run them using associated
|
|
|
|
* hot keys, names or ids.
|
|
|
|
*/
|
2013-09-20 16:21:01 +00:00
|
|
|
class ACTION_MANAGER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
* @param aToolManager is a tool manager instance that is used to pass events to tools.
|
|
|
|
*/
|
|
|
|
ACTION_MANAGER( TOOL_MANAGER* aToolManager );
|
|
|
|
|
2013-11-28 14:24:19 +00:00
|
|
|
/**
|
|
|
|
* Destructor.
|
|
|
|
* Unregisters every registered action.
|
|
|
|
*/
|
|
|
|
~ACTION_MANAGER();
|
|
|
|
|
2013-09-20 16:21:01 +00:00
|
|
|
/**
|
|
|
|
* Function RegisterAction()
|
2013-09-27 14:23:43 +00:00
|
|
|
* Adds a tool action to the manager and sets it up. After that is is possible to invoke
|
|
|
|
* the action using hotkeys or sending a command event with its name.
|
2013-09-20 16:21:01 +00:00
|
|
|
* @param aAction: action to be added. Ownership is not transferred.
|
|
|
|
*/
|
|
|
|
void RegisterAction( TOOL_ACTION* aAction );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function UnregisterAction()
|
2013-09-27 14:23:43 +00:00
|
|
|
* Removes a tool action from the manager and makes it unavailable for further usage.
|
2013-09-20 16:21:01 +00:00
|
|
|
* @param aAction: action to be removed.
|
|
|
|
*/
|
|
|
|
void UnregisterAction( TOOL_ACTION* aAction );
|
|
|
|
|
|
|
|
/**
|
2013-09-27 14:23:43 +00:00
|
|
|
* Generates an unique ID from for an action with given name.
|
2013-09-20 16:21:01 +00:00
|
|
|
*/
|
|
|
|
static int MakeActionId( const std::string& aActionName );
|
|
|
|
|
|
|
|
/**
|
2014-07-09 14:25:50 +00:00
|
|
|
* Function FindAction()
|
|
|
|
* Finds an action with a given name (if there is one available).
|
|
|
|
* @param aActionName is the searched action.
|
|
|
|
* @return Pointer to a TOOL_ACTION object or NULL if there is no such action.
|
2013-09-20 16:21:01 +00:00
|
|
|
*/
|
2014-07-09 14:25:50 +00:00
|
|
|
TOOL_ACTION* FindAction( const std::string& aActionName ) const;
|
2014-02-28 14:46:05 +00:00
|
|
|
|
2013-09-20 16:21:01 +00:00
|
|
|
/**
|
|
|
|
* Function RunHotKey()
|
|
|
|
* Runs an action associated with a hotkey (if there is one available).
|
2013-12-05 13:48:44 +00:00
|
|
|
* @param aHotKey is the hotkey to be handled.
|
2013-09-20 16:21:01 +00:00
|
|
|
* @return True if there was an action associated with the hotkey, false otherwise.
|
|
|
|
*/
|
|
|
|
bool RunHotKey( int aHotKey ) const;
|
|
|
|
|
2015-05-05 18:39:41 +00:00
|
|
|
/**
|
2015-05-05 18:39:42 +00:00
|
|
|
* Function UpdateHotKeys()
|
|
|
|
* Updates TOOL_ACTIONs hot key assignment according to the current frame's Hot Key Editor settings.
|
|
|
|
*/
|
|
|
|
void UpdateHotKeys();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetActionList()
|
2015-05-05 18:39:41 +00:00
|
|
|
* Returns list of TOOL_ACTIONs. TOOL_ACTIONs add themselves to the list upon their
|
|
|
|
* creation.
|
|
|
|
* @return List of TOOL_ACTIONs.
|
|
|
|
*/
|
|
|
|
static std::list<TOOL_ACTION*>& GetActionList()
|
|
|
|
{
|
|
|
|
// TODO I am afraid this approach won't work when we reach multitab version of kicad.
|
|
|
|
static std::list<TOOL_ACTION*> actionList;
|
|
|
|
|
|
|
|
return actionList;
|
|
|
|
}
|
|
|
|
|
2013-09-20 16:21:01 +00:00
|
|
|
private:
|
2015-05-05 18:39:42 +00:00
|
|
|
///> Resolves a reference to legacy hot key settings to a particular hot key.
|
|
|
|
///> @param aAction is the action to be resolved.
|
|
|
|
///> @param aForceUpdate determines whether it should be resolved only when the current hot key
|
|
|
|
///> setting contains a reference to legacy settings, or update the hot key basing on the
|
|
|
|
///> originally assigned reference.
|
|
|
|
int processHotKey( TOOL_ACTION* aAction, bool aForceUpdate = false );
|
|
|
|
|
2013-09-27 14:23:43 +00:00
|
|
|
///> Tool manager needed to run actions
|
2013-09-20 16:21:01 +00:00
|
|
|
TOOL_MANAGER* m_toolMgr;
|
2013-09-27 14:23:43 +00:00
|
|
|
|
|
|
|
///> Map for indexing actions by their IDs
|
2013-09-20 16:21:01 +00:00
|
|
|
std::map<int, TOOL_ACTION*> m_actionIdIndex;
|
2013-09-27 14:23:43 +00:00
|
|
|
|
|
|
|
///> Map for indexing actions by their names
|
2013-09-20 16:21:01 +00:00
|
|
|
std::map<std::string, TOOL_ACTION*> m_actionNameIndex;
|
2013-09-27 14:23:43 +00:00
|
|
|
|
|
|
|
///> Map for indexing actions by their hotkeys
|
2014-04-09 15:05:05 +00:00
|
|
|
typedef std::map<int, std::list<TOOL_ACTION*> > HOTKEY_LIST;
|
|
|
|
HOTKEY_LIST m_actionHotKeys;
|
2013-09-20 16:21:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* ACTION_MANAGER_H_ */
|