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 61 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 82 of file hotkey_store.cpp.

83 {
84 }

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 182 of file hotkey_store.cpp.

183 {
184  wxString sectionName = GetSectionName( aAction );
185 
186  for( HOTKEY_SECTION& section: m_hk_sections )
187  {
188  if( section.m_SectionName != sectionName )
189  continue;
190 
191  for( HOTKEY& hotkey: section.m_HotKeys )
192  {
193  if( hotkey.m_Actions[ 0 ] == aAction )
194  continue;
195 
196  if( hotkey.m_EditKeycode == aKey )
197  {
198  *aConflict = &hotkey;
199  return true;
200  }
201  }
202  }
203 
204  return false;
205 }
std::vector< TOOL_ACTION * > m_Actions
Definition: hotkey_store.h:35
std::vector< HOTKEY_SECTION > m_hk_sections
Definition: hotkey_store.h:110
int m_EditKeycode
Definition: hotkey_store.h:36
static wxString GetSectionName(TOOL_ACTION *aAction)

References 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 55 of file hotkey_store.cpp.

56 {
57  wxString name( aAction->GetName() );
58  return name.BeforeFirst( '.' );
59 }
const char * name
Definition: DXF_plotter.cpp:61
const std::string & GetName() const
Function GetName() Returns name of the action.
Definition: tool_action.h:78

References TOOL_ACTION::GetName(), and name.

Referenced by GetSectionName(), and Init().

◆ GetSectionName()

wxString HOTKEY_STORE::GetSectionName ( TOOL_ACTION aAction)
static

Definition at line 62 of file hotkey_store.cpp.

63 {
64  std::map<wxString, wxString> s_AppNames = {
65  { wxT( "common" ), _( "Common" ) },
66  { wxT( "kicad" ), _( "Kicad Manager" ) },
67  { wxT( "eeschema" ), _( "Eeschema" ) },
68  { wxT( "pcbnew" ), _( "Pcbnew" ) },
69  { wxT( "plEditor" ), _( "Page Layout Editor" ), },
70  { wxT( "3DViewer" ), _( "3D Viewer" ) }
71  };
72 
73  wxString appName = GetAppName( aAction );
74 
75  if( s_AppNames.count( appName ) )
76  return s_AppNames[ appName ];
77  else
78  return appName;
79 }
static wxString GetAppName(TOOL_ACTION *aAction)
#define _(s)

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 143 of file hotkey_store.cpp.

144 {
145  return m_hk_sections;
146 }
std::vector< HOTKEY_SECTION > m_hk_sections
Definition: hotkey_store.h:110

References m_hk_sections.

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

◆ Init()

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

Definition at line 87 of file hotkey_store.cpp.

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

163 {
164  for( HOTKEY_SECTION& section : m_hk_sections )
165  {
166  for( HOTKEY& hotkey : section.m_HotKeys )
167  hotkey.m_EditKeycode = hotkey.m_Actions[ 0 ]->GetDefaultHotKey();
168  }
169 }
std::vector< TOOL_ACTION * > m_Actions
Definition: hotkey_store.h:35
std::vector< HOTKEY_SECTION > m_hk_sections
Definition: hotkey_store.h:110
int m_EditKeycode
Definition: hotkey_store.h:36

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 172 of file hotkey_store.cpp.

173 {
174  for( HOTKEY_SECTION& section : m_hk_sections )
175  {
176  for( HOTKEY& hotkey : section.m_HotKeys )
177  hotkey.m_EditKeycode = hotkey.m_Actions[ 0 ]->GetHotKey();
178  }
179 }
std::vector< TOOL_ACTION * > m_Actions
Definition: hotkey_store.h:35
std::vector< HOTKEY_SECTION > m_hk_sections
Definition: hotkey_store.h:110
int m_EditKeycode
Definition: hotkey_store.h:36

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 149 of file hotkey_store.cpp.

150 {
151  for( HOTKEY_SECTION& section : m_hk_sections )
152  {
153  for( HOTKEY& hotkey : section.m_HotKeys )
154  {
155  for( TOOL_ACTION* action : hotkey.m_Actions )
156  action->SetHotKey( hotkey.m_EditKeycode );
157  }
158  }
159 }
void SetHotKey(int aKeycode)
Definition: tool_action.cpp:94
std::vector< TOOL_ACTION * > m_Actions
Definition: hotkey_store.h:35
std::vector< HOTKEY_SECTION > m_hk_sections
Definition: hotkey_store.h:110
Class TOOL_ACTION.
Definition: tool_action.h:46
int m_EditKeycode
Definition: hotkey_store.h:36

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 109 of file hotkey_store.h.

Referenced by Init().


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