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 Types

using SECTION_LIST = std::vector< HOTKEY_SECTION >
 

Public Member Functions

 HOTKEY_STORE (EDA_HOTKEY_CONFIG *aHotkeys)
 Construct a HOTKEY_STORE from a list of hotkey sections. More...
 
SECTION_LISTGetSections ()
 Get the list of sections managed by this store. More...
 
CHANGED_HOTKEYFindHotkey (const wxString &aTag, int aCmdId)
 Find a hotkey with the given command ID and in the given section. 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 (long aKey, const wxString &aSectionTag, EDA_HOTKEY **aConfKey, EDA_HOTKEY_CONFIG **aConfSect)
 Check whether the given key conflicts with anything in this store. More...
 

Private Member Functions

HOTKEY_SECTION genSection (EDA_HOTKEY_CONFIG &aSection)
 Generate a HOTKEY_SECTION for a single section described by an EDA_HOTKEY_CONFIG. More...
 

Private Attributes

SECTION_LIST m_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 123 of file hotkey_store.h.

Member Typedef Documentation

Definition at line 127 of file hotkey_store.h.

Constructor & Destructor Documentation

HOTKEY_STORE::HOTKEY_STORE ( EDA_HOTKEY_CONFIG aHotkeys)

Construct a HOTKEY_STORE from a list of hotkey sections.

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

Definition at line 26 of file hotkey_store.cpp.

References genSection(), EDA_HOTKEY_CONFIG::m_HK_InfoList, and m_hk_sections.

27 {
28  for( EDA_HOTKEY_CONFIG* section = aHotkeys; section->m_HK_InfoList; ++section )
29  {
30  m_hk_sections.push_back( genSection( *section ) );
31  }
32 }
Structure EDA_HOTKEY_CONFIG contains the information required to save hot key information to a config...
Definition: hotkeys_basic.h:94
HOTKEY_SECTION genSection(EDA_HOTKEY_CONFIG &aSection)
Generate a HOTKEY_SECTION for a single section described by an EDA_HOTKEY_CONFIG. ...
EDA_HOTKEY ** m_HK_InfoList
Definition: hotkeys_basic.h:98
SECTION_LIST m_hk_sections
Definition: hotkey_store.h:184

Member Function Documentation

bool HOTKEY_STORE::CheckKeyConflicts ( long  aKey,
const wxString &  aSectionTag,
EDA_HOTKEY **  aConfKey,
EDA_HOTKEY_CONFIG **  aConfSect 
)

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

Parameters
aKey- key to check
aSectionTag- section tag into which the key is proposed to be installed
aConfKey- if not NULL, outparam getting the key this one conflicts with
aConfSect- if not NULL, outparam getting the section this one conflicts with

Definition at line 116 of file hotkey_store.cpp.

References g_CommonSectionTag, m_hk_sections, and EDA_HOTKEY_CONFIG::m_SectionTag.

118 {
119  EDA_HOTKEY* conflicting_key = nullptr;
120  EDA_HOTKEY_CONFIG* conflicting_section = nullptr;
121 
122  for( auto& section: m_hk_sections )
123  {
124  const auto& sectionTag = *section.m_section.m_SectionTag;
125 
126  if( aSectionTag != g_CommonSectionTag
127  && sectionTag != g_CommonSectionTag
128  && sectionTag != aSectionTag )
129  {
130  // This key and its conflict candidate are in orthogonal sections, so skip.
131  continue;
132  }
133 
134  // See if any *current* hotkeys are in conflict
135  for( auto& hotkey: section.m_hotkeys )
136  {
137  auto& curr_hk = hotkey.GetCurrentValue();
138  if( aKey == curr_hk.m_KeyCode )
139  {
140  conflicting_key = &curr_hk;
141  conflicting_section = &section.m_section;
142  }
143  }
144  }
145 
146  // Write the outparams
147  if( aConfKey )
148  *aConfKey = conflicting_key;
149 
150  if( aConfSect )
151  *aConfSect = conflicting_section;
152 
153  return conflicting_key == nullptr;
154 }
Structure EDA_HOTKEY_CONFIG contains the information required to save hot key information to a config...
Definition: hotkeys_basic.h:94
wxString * m_SectionTag
Definition: hotkeys_basic.h:97
SECTION_LIST m_hk_sections
Definition: hotkey_store.h:184
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:59
wxString g_CommonSectionTag
CHANGED_HOTKEY * HOTKEY_STORE::FindHotkey ( const wxString &  aTag,
int  aCmdId 
)

Find a hotkey with the given command ID and in the given section.

Returns
pointer to the hotkey if found.

Definition at line 56 of file hotkey_store.cpp.

References CHANGED_HOTKEY::GetCurrentValue(), and m_hk_sections.

57 {
58  CHANGED_HOTKEY* found_key = nullptr;
59 
60  for( auto& section: m_hk_sections )
61  {
62  if( *section.m_section.m_SectionTag != aTag)
63  continue;
64 
65  for( auto& hotkey: section.m_hotkeys )
66  {
67  auto& curr_hk = hotkey.GetCurrentValue();
68  if( curr_hk.m_Idcommand == aCmdId )
69  {
70  found_key = &hotkey;
71  break;
72  }
73  }
74  }
75 
76  return found_key;
77 }
Class that manages a hotkey that can be changed, reset to its old value, a default or saved...
Definition: hotkey_store.h:39
EDA_HOTKEY & GetCurrentValue()
Definition: hotkey_store.h:48
SECTION_LIST m_hk_sections
Definition: hotkey_store.h:184
HOTKEY_SECTION HOTKEY_STORE::genSection ( EDA_HOTKEY_CONFIG aSection)
private

Generate a HOTKEY_SECTION for a single section described by an EDA_HOTKEY_CONFIG.

Definition at line 35 of file hotkey_store.cpp.

References EDA_HOTKEY_CONFIG::m_HK_InfoList, EDA_HOTKEY_CONFIG::m_SectionTag, and EDA_HOTKEY_CONFIG::m_Title.

Referenced by HOTKEY_STORE().

36 {
37  HOTKEY_SECTION generated_section { {}, {}, aSection };
38 
39  generated_section.m_name = wxGetTranslation( *aSection.m_Title );
40 
41  for( EDA_HOTKEY** info_ptr = aSection.m_HK_InfoList; *info_ptr; ++info_ptr )
42  {
43  generated_section.m_hotkeys.push_back( { **info_ptr, *aSection.m_SectionTag } );
44  }
45 
46  return generated_section;
47 }
EDA_HOTKEY ** m_HK_InfoList
Definition: hotkeys_basic.h:98
wxString * m_SectionTag
Definition: hotkeys_basic.h:97
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:59
wxString * m_Title
Definition: hotkeys_basic.h:99
Associates a set of hotkeys (a section) with a display name and the hotkeys.
Definition: hotkey_store.h:106
std::vector< HOTKEY_SECTION > & HOTKEY_STORE::GetSections ( )

Get the list of sections managed by this store.

Definition at line 50 of file hotkey_store.cpp.

References m_hk_sections.

Referenced by WIDGET_HOTKEY_LIST::updateShownItems().

51 {
52  return m_hk_sections;
53 }
SECTION_LIST m_hk_sections
Definition: hotkey_store.h:184
void HOTKEY_STORE::ResetAllHotkeysToDefault ( )

Reset every hotkey in the store to the default values.

Definition at line 92 of file hotkey_store.cpp.

References m_hk_sections.

Referenced by WIDGET_HOTKEY_LIST::ResetAllHotkeys().

93 {
94  for( auto& section: m_hk_sections )
95  {
96  for( auto& hotkey: section.m_hotkeys )
97  {
98  hotkey.GetCurrentValue().ResetKeyCodeToDefault();
99  }
100  }
101 }
SECTION_LIST m_hk_sections
Definition: hotkey_store.h:184
void HOTKEY_STORE::ResetAllHotkeysToOriginal ( )

Resets every hotkey to the original values.

Definition at line 104 of file hotkey_store.cpp.

References m_hk_sections.

Referenced by WIDGET_HOTKEY_LIST::ResetAllHotkeys().

105 {
106  for( auto& section: m_hk_sections )
107  {
108  for( auto& hotkey: section.m_hotkeys )
109  {
110  hotkey.GetCurrentValue().m_KeyCode = hotkey.GetOriginalValue().m_KeyCode;
111  }
112  }
113 }
SECTION_LIST m_hk_sections
Definition: hotkey_store.h:184
void HOTKEY_STORE::SaveAllHotkeys ( )

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

Definition at line 80 of file hotkey_store.cpp.

References m_hk_sections.

Referenced by WIDGET_HOTKEY_LIST::TransferDataFromControl().

81 {
82  for( auto& section: m_hk_sections )
83  {
84  for( auto& hotkey: section.m_hotkeys )
85  {
86  hotkey.SaveHotkey();
87  }
88  }
89 }
SECTION_LIST m_hk_sections
Definition: hotkey_store.h:184

Member Data Documentation


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