KiCad PCB EDA Suite
Loading...
Searching...
No Matches
ACTION_MANAGER Class Reference

Manage TOOL_ACTION objects. More...

#include <action_manager.h>

Public Member Functions

 ACTION_MANAGER (TOOL_MANAGER *aToolManager)
 
 ~ACTION_MANAGER ()
 Unregister every registered action.
 
void RegisterAction (TOOL_ACTION *aAction)
 Add a tool action to the manager and sets it up.
 
const std::map< std::string, TOOL_ACTION * > & GetActions () const
 Get a list of currently-registered actions mapped by their name.
 
bool IsActionUIId (int aId) const
 Test if a UI ID corresponds to an action ID in our system.
 
TOOL_ACTIONFindAction (const std::string &aActionName) const
 Find an action with a given name (if there is one available).
 
bool RunHotKey (int aHotKey) const
 Run an action associated with a hotkey (if there is one available).
 
int GetHotKey (const TOOL_ACTION &aAction) const
 Return the hot key associated with a given action or 0 if there is none.
 
void UpdateHotKeys (bool aFullUpdate)
 Optionally read the hotkey config files and then rebuilds the internal hotkey maps.
 
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 the current UI state (e.g.
 
const ACTION_CONDITIONSGetCondition (const TOOL_ACTION &aAction) const
 Get the conditions to use for a specific tool action.
 

Static Public Member Functions

static int MakeActionId (const std::string &aActionName)
 Generate an unique ID from for an action with given name.
 
static std::list< TOOL_ACTION * > & GetActionList ()
 Return list of TOOL_ACTIONs.
 

Private Types

typedef std::map< int, std::list< TOOL_ACTION * > > HOTKEY_LIST
 

Private Member Functions

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.
 

Private Attributes

TOOL_MANAGERm_toolMgr
 Map for indexing actions by their names.
 
std::map< std::string, TOOL_ACTION * > m_actionNameIndex
 Map for recording actions that have custom UI IDs.
 
std::map< int, TOOL_ACTION * > m_customUIIdIndex
 Map for indexing actions by their hotkeys.
 
HOTKEY_LIST m_actionHotKeys
 Quick action<->hot key lookup.
 
std::map< int, int > m_hotkeys
 
std::map< int, ACTION_CONDITIONSm_uiConditions
 Map the command ID that wx uses for the action to the UI conditions for the menu/toolbar items.
 

Detailed Description

Manage TOOL_ACTION objects.

Registering them and allows one to run them using associated hot keys, names or ids.

Definition at line 85 of file action_manager.h.

Member Typedef Documentation

◆ HOTKEY_LIST

typedef std::map<int, std::list<TOOL_ACTION*> > ACTION_MANAGER::HOTKEY_LIST
private

Definition at line 196 of file action_manager.h.

Constructor & Destructor Documentation

◆ ACTION_MANAGER()

ACTION_MANAGER::ACTION_MANAGER ( TOOL_MANAGER aToolManager)
Parameters
aToolManageris a tool manager instance that is used to pass events to tools.

Definition at line 36 of file action_manager.cpp.

References GetActionList(), group, kicadTraceToolStack, MakeActionId(), and RegisterAction().

◆ ~ACTION_MANAGER()

ACTION_MANAGER::~ACTION_MANAGER ( )

Unregister every registered action.

Definition at line 67 of file action_manager.cpp.

Member Function Documentation

◆ FindAction()

TOOL_ACTION * ACTION_MANAGER::FindAction ( const std::string &  aActionName) const

Find an action with a given name (if there is one available).

Parameters
aActionNameis the searched action.
Returns
Pointer to a TOOL_ACTION object or NULL if there is no such action.

Definition at line 128 of file action_manager.cpp.

References m_actionNameIndex.

Referenced by TOOL_MANAGER::doRunAction(), TOOLS_HOLDER::PopTool(), TOOLS_HOLDER::PushTool(), and TOOLS_HOLDER::ShowChangedLanguage().

◆ GetActionList()

◆ GetActions()

const std::map< std::string, TOOL_ACTION * > & ACTION_MANAGER::GetActions ( ) const

Get a list of currently-registered actions mapped by their name.

Definition at line 262 of file action_manager.cpp.

References m_actionNameIndex.

◆ GetCondition()

const ACTION_CONDITIONS * ACTION_MANAGER::GetCondition ( const TOOL_ACTION aAction) const

Get the conditions to use for a specific tool action.

Parameters
aActionis the tool action.
Returns
the action conditions, returns nullptr if no conditions are registered.

Definition at line 108 of file action_manager.cpp.

References TOOL_ACTION::GetId(), and m_uiConditions.

Referenced by ACTION_TOOLBAR::doSelectAction(), RunHotKey(), NL_3D_VIEWER_PLUGIN_IMPL::SetActiveCommand(), NL_SCHEMATIC_PLUGIN_IMPL::SetActiveCommand(), and NL_PCBNEW_PLUGIN_IMPL::SetActiveCommand().

◆ GetHotKey()

int ACTION_MANAGER::GetHotKey ( const TOOL_ACTION aAction) const

Return the hot key associated with a given action or 0 if there is none.

Parameters
aActionis the queried action.

Definition at line 268 of file action_manager.cpp.

References TOOL_ACTION::GetId(), and m_hotkeys.

Referenced by TOOL_MANAGER::GetHotKey().

◆ IsActionUIId()

bool ACTION_MANAGER::IsActionUIId ( int  aId) const

Test if a UI ID corresponds to an action ID in our system.

Definition at line 249 of file action_manager.cpp.

References TOOL_ACTION::GetBaseUIId(), and m_customUIIdIndex.

Referenced by ACTION_MENU::OnMenuEvent().

◆ MakeActionId()

int ACTION_MANAGER::MakeActionId ( const std::string &  aActionName)
static

Generate an unique ID from for an action with given name.

Definition at line 120 of file action_manager.cpp.

Referenced by ACTION_GROUP::ACTION_GROUP(), and ACTION_MANAGER().

◆ processHotKey()

void ACTION_MANAGER::processHotKey ( TOOL_ACTION aAction,
const std::map< std::string, int > &  aLegacyMap,
const std::map< std::string, std::pair< int, int > > &  aHotKeyMap 
)
private

Tool manager needed to run actions.

Definition at line 318 of file action_manager.cpp.

References TOOL_ACTION::m_defaultHotKey, TOOL_ACTION::m_hotKey, TOOL_ACTION::m_legacyName, TOOL_ACTION::m_name, and TOOL_ACTION::SetHotKey().

Referenced by UpdateHotKeys().

◆ RegisterAction()

void ACTION_MANAGER::RegisterAction ( TOOL_ACTION aAction)

Add a tool action to the manager and sets it up.

After that it is possible to invoke the action using hotkeys or sending a command event with its name.

Parameters
aActionaction to be added. Ownership is not transferred.

Definition at line 72 of file action_manager.cpp.

References TOOL_ACTION::GetName(), TOOL_ACTION::GetUIId(), TOOL_ACTION::HasCustomUIId(), m_actionNameIndex, m_customUIIdIndex, and TOOL_ACTION::m_name.

Referenced by ACTION_MANAGER().

◆ RunHotKey()

bool ACTION_MANAGER::RunHotKey ( int  aHotKey) const

Run an action associated with a hotkey (if there is one available).

Parameters
aHotKeyis the hotkey to be handled.
Returns
True if there was an action associated with the hotkey, false otherwise.

Definition at line 139 of file action_manager.cpp.

References AS_GLOBAL, TOOL_MANAGER::FindTool(), GetCondition(), TOOLS_HOLDER::GetCurrentSelection(), TOOL_BASE::GetId(), TOOL_ACTION::GetName(), TOOL_MANAGER::GetPriority(), TOOL_MANAGER::GetToolHolder(), KeyNameFromKeyCode(), kicadTraceToolStack, m_actionHotKeys, m_toolMgr, MD_MODIFIER_MASK, MD_SHIFT, and TOOL_MANAGER::RunAction().

Referenced by TOOL_MANAGER::DispatchHotKey().

◆ SetConditions()

◆ UpdateHotKeys()

void ACTION_MANAGER::UpdateHotKeys ( bool  aFullUpdate)

Member Data Documentation

◆ m_actionHotKeys

HOTKEY_LIST ACTION_MANAGER::m_actionHotKeys
private

Quick action<->hot key lookup.

Definition at line 197 of file action_manager.h.

Referenced by RunHotKey(), and UpdateHotKeys().

◆ m_actionNameIndex

std::map<std::string, TOOL_ACTION*> ACTION_MANAGER::m_actionNameIndex
private

Map for recording actions that have custom UI IDs.

Definition at line 190 of file action_manager.h.

Referenced by FindAction(), GetActions(), RegisterAction(), and UpdateHotKeys().

◆ m_customUIIdIndex

std::map<int, TOOL_ACTION*> ACTION_MANAGER::m_customUIIdIndex
private

Map for indexing actions by their hotkeys.

Definition at line 193 of file action_manager.h.

Referenced by IsActionUIId(), and RegisterAction().

◆ m_hotkeys

std::map<int, int> ACTION_MANAGER::m_hotkeys
private

Definition at line 200 of file action_manager.h.

Referenced by GetHotKey(), and UpdateHotKeys().

◆ m_toolMgr

TOOL_MANAGER* ACTION_MANAGER::m_toolMgr
private

Map for indexing actions by their names.

Definition at line 187 of file action_manager.h.

Referenced by RunHotKey(), SetConditions(), and UpdateHotKeys().

◆ m_uiConditions

std::map<int, ACTION_CONDITIONS> ACTION_MANAGER::m_uiConditions
private

Map the command ID that wx uses for the action to the UI conditions for the menu/toolbar items.

Definition at line 204 of file action_manager.h.

Referenced by GetCondition(), and SetConditions().


The documentation for this class was generated from the following files: