KiCad PCB EDA Suite
HOTKEY_STORE Class Reference

A class that contains a set of hotkeys, arranged into "sections" and provides some book-keeping functions for them. More...

#include <hotkey_store.h>

Public Member Functions

 HOTKEY_STORE ()
 Construct a HOTKEY_STORE from a list of hotkey sections. More...
 
void Init (std::vector< TOOL_MANAGER * > aToolManagerList, bool aIncludeGestures)
 
std::vector< HOTKEY_SECTION > & GetSections ()
 Get the list of sections managed by this store. More...
 
void SaveAllHotkeys ()
 Persist all changes to hotkeys in the store to the underlying data structures. More...
 
void ResetAllHotkeysToDefault ()
 Reset every hotkey in the store to the default values. More...
 
void ResetAllHotkeysToOriginal ()
 Resets every hotkey to the original values. More...
 
bool CheckKeyConflicts (TOOL_ACTION *aAction, long aKey, HOTKEY **aConflict)
 Check whether the given key conflicts with anything in this store. More...
 

Static Public Member Functions

static wxString GetAppName (TOOL_ACTION *aAction)
 
static wxString GetSectionName (TOOL_ACTION *aAction)
 

Private Attributes

std::vector< TOOL_MANAGER * > m_toolManagers
 
std::vector< HOTKEY_SECTIONm_hk_sections
 

Detailed Description

A class that contains a set of hotkeys, arranged into "sections" and provides some book-keeping functions for them.

Definition at line 62 of file hotkey_store.h.

Constructor & Destructor Documentation

◆ HOTKEY_STORE()

HOTKEY_STORE::HOTKEY_STORE ( )

Construct a HOTKEY_STORE from a list of hotkey sections.

Parameters
aHotkeysthe hotkey configs that will be managed by this store.

Definition at line 89 of file hotkey_store.cpp.

90 {
91 }

Member Function Documentation

◆ CheckKeyConflicts()

bool HOTKEY_STORE::CheckKeyConflicts ( TOOL_ACTION aAction,
long  aKey,
HOTKEY **  aConflict 
)

Check whether the given key conflicts with anything in this store.

Parameters
aAction- the action the key is proposed to be assigned to. Only conflicts within the same section will be flagged.
aKey- key to check
aConflict- outparam getting the section this one conflicts with

Definition at line 189 of file hotkey_store.cpp.

190 {
191  wxString sectionName = GetSectionName( aAction );
192 
193  // Create a fake "TOOL_ACTION" so we can get the section name for "Common" through the API.
194  // Simply declaring a wxString with the value "Common" works, but the goal is to futureproof
195  // the code here as much as possible.
196  TOOL_ACTION commonAction( "common.Control.Fake", AS_GLOBAL, 0, "", "", "" );
197  wxString commonName = GetSectionName( &commonAction );
198 
199  for( HOTKEY_SECTION& section : m_hk_sections )
200  {
201  // We can have the same hotkey in multiple sections (i.e. Kicad programs), but if a hotkey
202  // is in "Common" it can't be in any other section and vice versa.
203 
204  if( !( section.m_SectionName == sectionName || section.m_SectionName == commonName ) )
205  continue;
206 
207  for( HOTKEY& hotkey : section.m_HotKeys )
208  {
209  if( hotkey.m_Actions[0] == aAction )
210  continue;
211 
212  if( hotkey.m_EditKeycode == aKey )
213  {
214  *aConflict = &hotkey;
215  return true;
216  }
217  }
218  }
219 
220  return false;
221 }
Global action (toolbar/main menu event, global shortcut)
Definition: tool_event.h:151
std::vector< TOOL_ACTION * > m_Actions
Definition: hotkey_store.h:36
std::vector< HOTKEY_SECTION > m_hk_sections
Definition: hotkey_store.h:111
Represent a single user action.
Definition: tool_action.h:49
int m_EditKeycode
Definition: hotkey_store.h:37
static wxString GetSectionName(TOOL_ACTION *aAction)

References AS_GLOBAL, GetSectionName(), HOTKEY::m_Actions, HOTKEY::m_EditKeycode, and m_hk_sections.

Referenced by WIDGET_HOTKEY_LIST::resolveKeyConflicts().

◆ GetAppName()

wxString HOTKEY_STORE::GetAppName ( TOOL_ACTION aAction)
static

Definition at line 62 of file hotkey_store.cpp.

63 {
64  wxString name( aAction->GetName() );
65  return name.BeforeFirst( '.' );
66 }
const char * name
Definition: DXF_plotter.cpp:59
const std::string & GetName() const
Return name of the action.
Definition: tool_action.h:83

References TOOL_ACTION::GetName(), and name.

Referenced by GetSectionName(), and Init().

◆ GetSectionName()

wxString HOTKEY_STORE::GetSectionName ( TOOL_ACTION aAction)
static

Definition at line 69 of file hotkey_store.cpp.

70 {
71  std::map<wxString, wxString> s_AppNames = {
72  { wxT( "common" ), _( "Common" ) },
73  { wxT( "kicad" ), _( "Project Manager" ) },
74  { wxT( "eeschema" ), _( "Schematic Editor" ) },
75  { wxT( "pcbnew" ), _( "PCB Editor" ) },
76  { wxT( "plEditor" ), _( "Drawing Sheet Editor" ), },
77  { wxT( "3DViewer" ), _( "3D Viewer" ) }
78  };
79 
80  wxString appName = GetAppName( aAction );
81 
82  if( s_AppNames.count( appName ) )
83  return s_AppNames[ appName ];
84  else
85  return appName;
86 }
static wxString GetAppName(TOOL_ACTION *aAction)
#define _(s)
Definition: 3d_actions.cpp:33

References _, and GetAppName().

Referenced by CheckKeyConflicts(), Init(), and WIDGET_HOTKEY_LIST::resolveKeyConflicts().

◆ GetSections()

std::vector< HOTKEY_SECTION > & HOTKEY_STORE::GetSections ( )

Get the list of sections managed by this store.

Definition at line 150 of file hotkey_store.cpp.

151 {
152  return m_hk_sections;
153 }
std::vector< HOTKEY_SECTION > m_hk_sections
Definition: hotkey_store.h:111

References m_hk_sections.

Referenced by PANEL_HOTKEYS_EDITOR::dumpHotkeys(), PANEL_HOTKEYS_EDITOR::ImportHotKeys(), and WIDGET_HOTKEY_LIST::updateShownItems().

◆ Init()

void HOTKEY_STORE::Init ( std::vector< TOOL_MANAGER * >  aToolManagerList,
bool  aIncludeGestures 
)

Definition at line 94 of file hotkey_store.cpp.

95 {
96  m_toolManagers = std::move( aToolManagerList );
97 
98  // Collect all action maps into a single master map. This will re-group everything
99  // and collect duplicates together
100  std::map<std::string, HOTKEY> masterMap;
101 
102  for( TOOL_MANAGER* toolMgr : m_toolManagers )
103  {
104  for( const auto& entry : toolMgr->GetActions() )
105  {
106  // Internal actions probably shouldn't be allowed hotkeys
107  if( entry.second->GetLabel().IsEmpty() )
108  continue;
109 
110  HOTKEY& hotkey = masterMap[ entry.first ];
111  hotkey.m_Actions.push_back( entry.second );
112  hotkey.m_EditKeycode = entry.second->GetHotKey();
113  }
114  }
115 
116  wxString currentApp;
117  HOTKEY_SECTION* currentSection = nullptr;
118 
119  // If a previous list was built, ensure this previous list is cleared:
120  m_hk_sections.clear();
121 
122  for( const auto& entry : masterMap )
123  {
124  TOOL_ACTION* entryAction = entry.second.m_Actions[ 0 ];
125  wxString entryApp = GetAppName( entryAction );
126 
127  if( !currentSection || entryApp != currentApp )
128  {
129  m_hk_sections.emplace_back( HOTKEY_SECTION() );
130  currentApp = entryApp;
131  currentSection = &m_hk_sections.back();
132  currentSection->m_SectionName = GetSectionName( entryAction );
133  }
134 
135  currentSection->m_HotKeys.emplace_back( HOTKEY( entry.second ) );
136  }
137 
138  if( aIncludeGestures )
139  {
140  m_hk_sections.emplace_back( HOTKEY_SECTION() );
141  currentSection = &m_hk_sections.back();
142  currentSection->m_SectionName = _( "Gestures" );
143 
144  for( TOOL_ACTION* gesture : g_gesturePseudoActions )
145  currentSection->m_HotKeys.emplace_back( HOTKEY( gesture ) );
146  }
147 }
static GESTURE_PSEUDO_ACTION * g_gesturePseudoActions[]
std::vector< HOTKEY > m_HotKeys
Definition: hotkey_store.h:54
Master controller class:
Definition: tool_manager.h:52
std::vector< TOOL_MANAGER * > m_toolManagers
Definition: hotkey_store.h:110
static wxString GetAppName(TOOL_ACTION *aAction)
std::vector< TOOL_ACTION * > m_Actions
Definition: hotkey_store.h:36
#define _(s)
Definition: 3d_actions.cpp:33
std::vector< HOTKEY_SECTION > m_hk_sections
Definition: hotkey_store.h:111
Represent a single user action.
Definition: tool_action.h:49
int m_EditKeycode
Definition: hotkey_store.h:37
wxString m_SectionName
Definition: hotkey_store.h:53
static wxString GetSectionName(TOOL_ACTION *aAction)

References _, g_gesturePseudoActions, GetAppName(), GetSectionName(), HOTKEY::m_Actions, HOTKEY::m_EditKeycode, m_hk_sections, HOTKEY_SECTION::m_HotKeys, HOTKEY_SECTION::m_SectionName, and m_toolManagers.

Referenced by PANEL_HOTKEYS_EDITOR::TransferDataToWindow().

◆ ResetAllHotkeysToDefault()

void HOTKEY_STORE::ResetAllHotkeysToDefault ( )

Reset every hotkey in the store to the default values.

Definition at line 169 of file hotkey_store.cpp.

170 {
171  for( HOTKEY_SECTION& section : m_hk_sections )
172  {
173  for( HOTKEY& hotkey : section.m_HotKeys )
174  hotkey.m_EditKeycode = hotkey.m_Actions[ 0 ]->GetDefaultHotKey();
175  }
176 }
std::vector< TOOL_ACTION * > m_Actions
Definition: hotkey_store.h:36
std::vector< HOTKEY_SECTION > m_hk_sections
Definition: hotkey_store.h:111
int m_EditKeycode
Definition: hotkey_store.h:37

References HOTKEY::m_Actions, HOTKEY::m_EditKeycode, and m_hk_sections.

Referenced by WIDGET_HOTKEY_LIST::ResetAllHotkeys().

◆ ResetAllHotkeysToOriginal()

void HOTKEY_STORE::ResetAllHotkeysToOriginal ( )

Resets every hotkey to the original values.

Definition at line 179 of file hotkey_store.cpp.

180 {
181  for( HOTKEY_SECTION& section : m_hk_sections )
182  {
183  for( HOTKEY& hotkey : section.m_HotKeys )
184  hotkey.m_EditKeycode = hotkey.m_Actions[ 0 ]->GetHotKey();
185  }
186 }
std::vector< TOOL_ACTION * > m_Actions
Definition: hotkey_store.h:36
std::vector< HOTKEY_SECTION > m_hk_sections
Definition: hotkey_store.h:111
int m_EditKeycode
Definition: hotkey_store.h:37

References HOTKEY::m_Actions, HOTKEY::m_EditKeycode, and m_hk_sections.

Referenced by WIDGET_HOTKEY_LIST::ResetAllHotkeys().

◆ SaveAllHotkeys()

void HOTKEY_STORE::SaveAllHotkeys ( )

Persist all changes to hotkeys in the store to the underlying data structures.

Definition at line 156 of file hotkey_store.cpp.

157 {
158  for( HOTKEY_SECTION& section : m_hk_sections )
159  {
160  for( HOTKEY& hotkey : section.m_HotKeys )
161  {
162  for( TOOL_ACTION* action : hotkey.m_Actions )
163  action->SetHotKey( hotkey.m_EditKeycode );
164  }
165  }
166 }
void SetHotKey(int aKeycode)
Definition: tool_action.cpp:95
std::vector< TOOL_ACTION * > m_Actions
Definition: hotkey_store.h:36
std::vector< HOTKEY_SECTION > m_hk_sections
Definition: hotkey_store.h:111
Represent a single user action.
Definition: tool_action.h:49
int m_EditKeycode
Definition: hotkey_store.h:37

References HOTKEY::m_Actions, HOTKEY::m_EditKeycode, m_hk_sections, and TOOL_ACTION::SetHotKey().

Referenced by WIDGET_HOTKEY_LIST::TransferDataFromControl().

Member Data Documentation

◆ m_hk_sections

std::vector<HOTKEY_SECTION> HOTKEY_STORE::m_hk_sections
private

◆ m_toolManagers

std::vector<TOOL_MANAGER*> HOTKEY_STORE::m_toolManagers
private

Definition at line 110 of file hotkey_store.h.

Referenced by Init().


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