42 if( action->m_id == -1 )
46 std::string groupName =
"none";
48 std::optional<TOOL_ACTION_GROUP>
group = action->GetActionGroup();
50 if(
group.has_value() )
52 groupID =
group.value().GetGroupID();
53 groupName =
group.value().GetName();
56 wxLogTrace(
kicadTraceToolStack,
"ACTION_MANAGER::ACTION_MANAGER: Registering action %s with ID %d, UI ID %d, "
57 "group %s(%d), toolbar state %s",
58 action->m_name, action->m_id, action->GetUIId(), groupName, groupID,
59 action->m_toolbarState.to_string() );
75 wxASSERT( aAction->
GetName().find(
'.', 0 ) != std::string::npos );
79 wxString::Format(
"Action '%s' already registered", aAction->
m_name ) );
93 m_toolMgr->GetToolHolder()->UnregisterUIUpdateHandler( aAction );
97 wxLogTrace(
kicadTraceToolStack, wxS(
"ACTION_MANAGER::SetConditions: Registering conditions for ID %d - %s" ),
102 m_toolMgr->GetToolHolder()->RegisterUIUpdateHandler( aAction, aConditions );
120 static int currentActionId = 1;
122 return currentActionId++;
128 std::map<std::string, TOOL_ACTION*>::const_iterator it =
m_actionNameIndex.find( aActionName );
142 if( key >=
'a' && key <=
'z' )
143 key = std::toupper( key );
147 int matchedHotKey = key | mod;
157 matchedHotKey = key | ( mod &
~MD_SHIFT );
159 wxLogTrace(
kicadTraceToolStack, wxS(
"ACTION_MANAGER::RunHotKey No actions found, searching with key: %s" ),
169 const std::list<TOOL_ACTION*>& actions = it->second;
173 int highestPriority = -1;
176 std::vector<const TOOL_ACTION*> global;
183 global.emplace_back( action );
195 if( priority >= 0 && priority > highestPriority )
197 highestPriority = priority;
203 if( !context && global.size() > 1 )
214 bool runAction =
true;
217 runAction = aCond->GetHotkeyCondition()( sel );
219 wxLogTrace(
kicadTraceToolStack, wxS(
"ACTION_MANAGER::RunHotKey %s context action: %s for hotkey %s" ),
220 runAction ? wxS(
"Running" ) : wxS(
"Not running" ),
226 else if( !global.empty() )
230 bool runAction =
true;
233 runAction = aCond->GetHotkeyCondition()( sel );
235 wxLogTrace(
kicadTraceToolStack, wxS(
"ACTION_MANAGER::RunHotKey %s global action: %s for hotkey %s" ),
236 runAction ? wxS(
"Running" ) : wxS(
"Not running" ),
239 if( runAction &&
m_toolMgr->RunAction( *act ) )
244 wxLogTrace(
kicadTraceToolStack, wxS(
"ACTION_MANAGER::RunHotKey No action found for key %s" ),
290 if( framePrefix.empty() )
293 auto userBoundInFrame = [&](
const TOOL_ACTION* aAction )
295 return aAction->GetName().starts_with( framePrefix ) && aAction->IsHotKeyUserBound( aMatchedHotKey );
298 if( std::any_of( aGlobalActions.begin(), aGlobalActions.end(), userBoundInFrame ) )
299 std::stable_partition( aGlobalActions.begin(), aGlobalActions.end(), userBoundInFrame );
324 std::map<int, int>::const_iterator it =
m_hotkeys.find( aAction.
GetId() );
335 static std::map<std::string, int> legacyHotKeyMap;
336 static std::map<std::string, std::pair<int, int>> userHotKeyMap;
337 static bool mapsInitialized =
false;
342 if(
m_toolMgr->GetToolHolder() && ( aFullUpdate || !mapsInitialized ) )
346 mapsInitialized =
true;
373 const std::map<std::string, int>& aLegacyMap,
374 const std::map<std::string, std::pair<int, int>>& aHotKeyMap )
382 if( aHotKeyMap.count( aAction->
m_name ) )
384 std::pair<int, int> keys = aHotKeyMap.at( aAction->
m_name );
386 alternate = keys.second;
~ACTION_MANAGER()
Unregister every registered action.
const ACTION_CONDITIONS * GetCondition(const TOOL_ACTION &aAction) const
Get the conditions to use for a specific tool action.
std::map< int, TOOL_ACTION * > m_customUIIdIndex
Map for recording actions that have custom UI IDs.
TOOL_MANAGER * m_toolMgr
Tool manager needed to run actions.
void processHotKey(TOOL_ACTION *aAction, const std::map< std::string, int > &aLegacyMap, const std::map< std::string, std::pair< int, int > > &aHotKeyMap)
const std::map< std::string, TOOL_ACTION * > & GetActions() const
Get a list of currently-registered actions mapped by their name.
std::map< std::string, TOOL_ACTION * > m_actionNameIndex
Map for indexing actions by their names.
std::map< int, int > m_hotkeys
Quick action<->hot key lookup.
bool RunHotKey(int aHotKey) const
Run an action associated with a hotkey (if there is one available).
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 t...
void RegisterAction(TOOL_ACTION *aAction)
Add a tool action to the manager and sets it up.
TOOL_ACTION * FindAction(const std::string &aActionName) const
Find an action with a given name (if there is one available).
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...
static std::list< TOOL_ACTION * > & GetActionList()
Return list of TOOL_ACTIONs.
bool IsActionUIId(int aId) const
Test if a UI ID corresponds to an action ID in our system.
int GetHotKey(const TOOL_ACTION &aAction) const
Return the hot key associated with a given action or 0 if there is none.
static int MakeActionId(const std::string &aActionName)
Generate an unique ID from for an action with given name.
std::map< int, std::list< TOOL_ACTION * > > m_actionHotKeys
Map for indexing actions by their hotkeys.
std::map< int, ACTION_CONDITIONS > m_uiConditions
Map the command ID that wx uses for the action to the UI conditions for the menu/toolbar items.
void UpdateHotKeys(bool aFullUpdate)
Optionally read the hotkey config files and then rebuilds the internal hotkey maps.
ACTION_MANAGER(TOOL_MANAGER *aToolManager)
static std::string FrameNamespacePrefix(FRAME_T aFrameType)
Return the action-name namespace prefix (e.g.
The base frame for deriving all KiCad main window classes.
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
@ FRAME_SCH_SYMBOL_EDITOR
const wxChar *const kicadTraceToolStack
Flag to enable tracing of the tool handling stack.
void ReadHotKeyConfig(const wxString &aFileName, std::map< std::string, std::pair< int, int > > &aHotKeys)
Read a hotkey config file into a map.
int ReadLegacyHotkeyConfig(const wxString &aAppname, std::map< std::string, int > &aMap)
Read configuration data and fill the current hotkey list with hotkeys.
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
wxLogTrace helper definitions.