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::string FrameNamespacePrefix (FRAME_T aFrameType)
 Return the action-name namespace prefix (e.g.
 
static void PromoteUserBoundFrameAction (std::vector< const TOOL_ACTION * > &aGlobalActions, FRAME_T aFrameType, int aMatchedHotKey)
 Reorder global actions sharing a hotkey so that one native to the given frame is tried first when the user has bound the matched slot away from its default.
 
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 83 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 207 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 34 of file action_manager.cpp.

References GetActionList(), group, kicadTraceToolStack, m_toolMgr, 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 129 of file action_manager.cpp.

References m_actionNameIndex.

Referenced by TOOLS_HOLDER::ShowChangedLanguage().

◆ FrameNamespacePrefix()

std::string ACTION_MANAGER::FrameNamespacePrefix ( FRAME_T aFrameType)
static

Return the action-name namespace prefix (e.g.

"pcbnew.", "eeschema.") shared by the actions native to a given frame, or an empty string when the frame has no namespace.

Definition at line 260 of file action_manager.cpp.

References FRAME_FOOTPRINT_EDITOR, FRAME_FOOTPRINT_VIEWER, FRAME_GERBER, FRAME_PCB_EDITOR, FRAME_PL_EDITOR, FRAME_SCH, FRAME_SCH_SYMBOL_EDITOR, FRAME_SCH_VIEWER, and FRAME_SIMULATOR.

Referenced by PANEL_TOOLBAR_CUSTOMIZATION::isActionSupported(), and PromoteUserBoundFrameAction().

◆ 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 313 of file action_manager.cpp.

References m_actionNameIndex.

Referenced by DIALOG_LIST_HOTKEYS::DIALOG_LIST_HOTKEYS(), and EDA_BASE_FRAME::ShowPreferences().

◆ 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 109 of file action_manager.cpp.

References TOOL_ACTION::GetId(), and m_uiConditions.

Referenced by RunHotKey(), NL_3D_VIEWER_PLUGIN_IMPL::SetActiveCommand(), NL_GERBVIEW_PLUGIN_IMPL::SetActiveCommand(), NL_PCBNEW_PLUGIN_IMPL::SetActiveCommand(), NL_PL_EDITOR_PLUGIN_IMPL::SetActiveCommand(), and NL_SCHEMATIC_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 319 of file action_manager.cpp.

References TOOL_ACTION::GetId(), and m_hotkeys.

◆ IsActionUIId()

bool ACTION_MANAGER::IsActionUIId ( int aId) const

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

Definition at line 300 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 121 of file action_manager.cpp.

Referenced by ACTION_GROUP::ACTION_GROUP(), 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 369 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().

◆ PromoteUserBoundFrameAction()

void ACTION_MANAGER::PromoteUserBoundFrameAction ( std::vector< const TOOL_ACTION * > & aGlobalActions,
FRAME_T aFrameType,
int aMatchedHotKey )
static

Reorder global actions sharing a hotkey so that one native to the given frame is tried first when the user has bound the matched slot away from its default.

Definition at line 282 of file action_manager.cpp.

References FrameNamespacePrefix().

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and RunHotKey().

◆ 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 140 of file action_manager.cpp.

References AS_GLOBAL, GetCondition(), TOOL_BASE::GetId(), TOOL_ACTION::GetName(), KeyNameFromKeyCode(), kicadTraceToolStack, m_actionHotKeys, m_toolMgr, MD_MODIFIER_MASK, MD_SHIFT, and PromoteUserBoundFrameAction().

◆ SetConditions()

◆ UpdateHotKeys()

void ACTION_MANAGER::UpdateHotKeys ( bool aFullUpdate)

Optionally read the hotkey config files and then rebuilds the internal hotkey maps.

Definition at line 330 of file action_manager.cpp.

References TOOL_ACTION::GetHotKey(), TOOL_ACTION::GetHotKeyAlt(), TOOL_ACTION::GetId(), m_actionHotKeys, m_actionNameIndex, m_hotkeys, m_toolMgr, processHotKey(), ReadHotKeyConfig(), and ReadLegacyHotkeyConfig().

Referenced by TOOLS_HOLDER::CommonSettingsChanged().

Member Data Documentation

◆ m_actionHotKeys

HOTKEY_LIST ACTION_MANAGER::m_actionHotKeys
private

Quick action<->hot key lookup.

Definition at line 208 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 201 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 204 of file action_manager.h.

Referenced by IsActionUIId(), and RegisterAction().

◆ m_hotkeys

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

Definition at line 211 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 198 of file action_manager.h.

Referenced by ACTION_MANAGER(), 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 215 of file action_manager.h.

Referenced by GetCondition(), and SetConditions().


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