KiCad PCB EDA Suite
PANEL_HOTKEYS_EDITOR Class Reference

#include <panel_hotkeys_editor.h>

Inheritance diagram for PANEL_HOTKEYS_EDITOR:
RESETTABLE_PANEL

Public Member Functions

 PANEL_HOTKEYS_EDITOR (EDA_BASE_FRAME *aFrame, wxWindow *aWindow, bool aReadOnly)
 
std::vector< TOOL_ACTION * > & ActionsList ()
 
bool TransferDataToWindow () override
 
bool TransferDataFromWindow () override
 
void ResetPanel () override
 Reset the contents of this panel. More...
 
wxString GetResetTooltip () const override
 Get the tooltip the reset button should display when showing this panel. More...
 
wxString GetHelpTextAtPoint (const wxPoint &aPt, wxHelpEvent::Origin aOrigin) const override
 Overridden to supply the reset button tooltip when queried with { -INT_MAX, INT_MAX }. More...
 

Protected Attributes

EDA_BASE_FRAMEm_frame
 
bool m_readOnly
 
std::vector< TOOL_ACTION * > m_actions
 
HOTKEY_STORE m_hotkeyStore
 
WIDGET_HOTKEY_LISTm_hotkeyListCtrl
 

Private Member Functions

void installButtons (wxSizer *aSizer)
 Install the button panel (global reset/default, import/export) More...
 
void OnFilterSearch (wxCommandEvent &aEvent)
 Handle a change in the hotkey filter text. More...
 
void ImportHotKeys ()
 Put up a dialog allowing the user to select a hotkeys file and then overlays those hotkeys onto the current hotkey store. More...
 
void dumpHotkeys ()
 Dump all actions and their hotkeys to a text file for inclusion in documentation. More...
 

Detailed Description

Definition at line 41 of file panel_hotkeys_editor.h.

Constructor & Destructor Documentation

◆ PANEL_HOTKEYS_EDITOR()

PANEL_HOTKEYS_EDITOR::PANEL_HOTKEYS_EDITOR ( EDA_BASE_FRAME aFrame,
wxWindow *  aWindow,
bool  aReadOnly 
)

Definition at line 68 of file panel_hotkeys_editor.cpp.

69 :
70 RESETTABLE_PANEL( aWindow, wxID_ANY, wxDefaultPosition, wxDefaultSize ),
71 m_frame( aFrame ),
72 m_readOnly( aReadOnly ),
74{
75 wxBoxSizer* mainSizer = new wxBoxSizer( wxVERTICAL );
76 wxBoxSizer* bMargins = new wxBoxSizer( wxVERTICAL );
77
78 wxSearchCtrl* filterSearch = CreateTextFilterBox( this, _( "Type filter text" ) );
79 bMargins->Add( filterSearch, 0, wxEXPAND, 0 );
80
82 bMargins->Add( m_hotkeyListCtrl, 1, wxEXPAND, 0 );
83
84 if( !m_readOnly )
85 installButtons( bMargins );
86
87 mainSizer->Add( bMargins, 1, wxEXPAND, 0 );
88
89#ifdef __WXGTK__
90 // Work around a bug that clips the text vertically in the wxSearchCtrl on GTK
91 filterSearch->SetMinSize( wxSize( filterSearch->GetSize().x,
92 int( filterSearch->GetSize().y * 1.6 ) ) );
93#endif
94
95 SetSizer( mainSizer );
96 Layout();
97
98 // Connect Events
99 filterSearch->Bind( wxEVT_COMMAND_TEXT_UPDATED, &PANEL_HOTKEYS_EDITOR::OnFilterSearch, this );
100}
void OnFilterSearch(wxCommandEvent &aEvent)
Handle a change in the hotkey filter text.
void installButtons(wxSizer *aSizer)
Install the button panel (global reset/default, import/export)
WIDGET_HOTKEY_LIST * m_hotkeyListCtrl
EDA_BASE_FRAME * m_frame
RESETTABLE_PANEL(wxWindow *aParent, wxWindowID aId=wxID_ANY, const wxPoint &aPos=wxDefaultPosition, const wxSize &aSize=wxSize(-1,-1), long aStyle=wxTAB_TRAVERSAL, const wxString &aName=wxEmptyString)
#define _(s)
static wxSearchCtrl * CreateTextFilterBox(wxWindow *aParent, const wxString &aDescriptiveText)
Helper function to add a filter box to a panel, with some sensible defaults for that purpose.

References _, CreateTextFilterBox(), installButtons(), m_hotkeyListCtrl, m_hotkeyStore, m_readOnly, and OnFilterSearch().

Member Function Documentation

◆ ActionsList()

std::vector< TOOL_ACTION * > & PANEL_HOTKEYS_EDITOR::ActionsList ( )
inline

Definition at line 46 of file panel_hotkeys_editor.h.

46{ return m_actions; }
std::vector< TOOL_ACTION * > m_actions

References m_actions.

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

◆ dumpHotkeys()

void PANEL_HOTKEYS_EDITOR::dumpHotkeys ( )
private

Dump all actions and their hotkeys to a text file for inclusion in documentation.

The format is asciidoc-compatible table rows. This function is hidden behind an advanced config flag and not intended for users.

Definition at line 212 of file panel_hotkeys_editor.cpp.

213{
214 wxString filename = wxFileSelector( wxT( "Hotkeys File" ), m_frame->GetMruPath(),
215 wxEmptyString, TextFileExtension, TextFileWildcard(),
216 wxFD_SAVE, this );
217
218 if( filename.IsEmpty() )
219 return;
220
221 wxFileName fn( filename );
222
223 wxFFileOutputStream fileStream( fn.GetFullPath(), "w" );
224 wxTextOutputStream stream( fileStream );
225
226 if( !fn.IsDirWritable() || ( fn.Exists() && !fn.IsFileWritable() ) )
227 return;
228
229 for( HOTKEY_SECTION& section : m_hotkeyStore.GetSections() )
230 {
231 stream << wxT( "=== " ) << section.m_SectionName << endl << endl;
232
233 stream << wxT( "[width=\"100%\",options=\"header\",cols=\"20%,15%,65%\"]" ) << endl;
234 stream << wxT( "|===" ) << endl;
235 stream << _( "| Action | Default Hotkey | Description" ) << endl;
236
237 for( HOTKEY& hk : section.m_HotKeys )
238 {
239 stream << wxT( "| " ) << hk.m_Actions[0]->GetLabel() << endl;
240
241 if( hk.m_EditKeycode > 0 )
242 {
243 stream << wxT( " | kbd:[" ) << KeyNameFromKeyCode( hk.m_EditKeycode ) << ']'
244 << endl;
245 }
246 else
247 {
248 stream << wxT( " |" ) << endl;
249 }
250
251 stream << wxT( " | " ) << hk.m_Actions[0]->GetDescription( false ) << endl;
252 }
253
254 stream << wxT( "|===" ) << endl << endl;
255 }
256
257 stream.Flush();
258 fileStream.Close();
259}
wxString GetMruPath() const
std::vector< HOTKEY_SECTION > & GetSections()
Get the list of sections managed by this store.
const std::string TextFileExtension
wxString TextFileWildcard()
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
int m_EditKeycode
Definition: hotkey_store.h:37
std::vector< TOOL_ACTION * > m_Actions
Definition: hotkey_store.h:36

References _, EDA_BASE_FRAME::GetMruPath(), HOTKEY_STORE::GetSections(), KeyNameFromKeyCode(), HOTKEY::m_Actions, HOTKEY::m_EditKeycode, m_frame, m_hotkeyStore, TextFileExtension, and TextFileWildcard().

Referenced by installButtons().

◆ GetHelpTextAtPoint()

wxString RESETTABLE_PANEL::GetHelpTextAtPoint ( const wxPoint &  aPt,
wxHelpEvent::Origin  aOrigin 
) const
inlineoverrideinherited

Overridden to supply the reset button tooltip when queried with { -INT_MAX, INT_MAX }.

Definition at line 72 of file resettable_panel.h.

73 {
74 if( aPt == wxPoint( -INT_MAX, INT_MAX ) )
75 return GetResetTooltip();
76 else
77 return wxPanel::GetHelpTextAtPoint( aPt, aOrigin );
78 }
virtual wxString GetResetTooltip() const
Get the tooltip the reset button should display when showing this panel.

References RESETTABLE_PANEL::GetResetTooltip().

◆ GetResetTooltip()

wxString PANEL_HOTKEYS_EDITOR::GetResetTooltip ( ) const
inlineoverridevirtual

Get the tooltip the reset button should display when showing this panel.

Returns
the tooltip

Reimplemented from RESETTABLE_PANEL.

Definition at line 53 of file panel_hotkeys_editor.h.

54 {
55 return _( "Reset all hotkeys to the built-in KiCad defaults" );
56 }

References _.

◆ ImportHotKeys()

void PANEL_HOTKEYS_EDITOR::ImportHotKeys ( )
private

Put up a dialog allowing the user to select a hotkeys file and then overlays those hotkeys onto the current hotkey store.

Definition at line 185 of file panel_hotkeys_editor.cpp.

186{
187 wxString filename = wxFileSelector( _( "Import Hotkeys File:" ), m_frame->GetMruPath(),
188 wxEmptyString, HotkeyFileExtension,
189 HotkeyFileWildcard(), wxFD_OPEN, this );
190
191 if( filename.IsEmpty() )
192 return;
193
194 std::map<std::string, int> importedHotKeys;
195 ReadHotKeyConfig( filename, importedHotKeys );
196 m_frame->SetMruPath( wxFileName( filename ).GetPath() );
197
198 // Overlay the imported hotkeys onto the hotkey store
199 for( HOTKEY_SECTION& section: m_hotkeyStore.GetSections() )
200 {
201 for( HOTKEY& hotkey: section.m_HotKeys )
202 {
203 if( importedHotKeys.count( hotkey.m_Actions[ 0 ]->GetName() ) )
204 hotkey.m_EditKeycode = importedHotKeys[ hotkey.m_Actions[ 0 ]->GetName() ];
205 }
206 }
207
209}
void SetMruPath(const wxString &aPath)
bool TransferDataToControl()
Method TransferDataToControl Load the hotkey data from the store into the control.
const std::string HotkeyFileExtension
wxString HotkeyFileWildcard()
void ReadHotKeyConfig(const wxString &aFileName, std::map< std::string, int > &aHotKeys)
Reads a hotkey config file into a map.

References _, EDA_BASE_FRAME::GetMruPath(), HOTKEY_STORE::GetSections(), HotkeyFileExtension, HotkeyFileWildcard(), HOTKEY::m_Actions, HOTKEY::m_EditKeycode, m_frame, m_hotkeyListCtrl, m_hotkeyStore, ReadHotKeyConfig(), EDA_BASE_FRAME::SetMruPath(), and WIDGET_HOTKEY_LIST::TransferDataToControl().

Referenced by installButtons().

◆ installButtons()

void PANEL_HOTKEYS_EDITOR::installButtons ( wxSizer *  aSizer)
private

Install the button panel (global reset/default, import/export)

Parameters
aSizerthe dialog to install on.

Definition at line 109 of file panel_hotkeys_editor.cpp.

110{
111 BUTTON_ROW_PANEL::BTN_DEF_LIST l_btn_defs = {
112 {
113 wxID_RESET,
114 _( "Undo All Changes" ),
115 _( "Undo all changes made so far in this dialog" ),
116 [this]( wxCommandEvent& )
117 {
119 }
120 },
121 {
122 wxID_ANY,
123 _( "Import Hotkeys..." ),
124 _( "Import hotkey definitions from an external file, replacing the current values" ),
125 [this]( wxCommandEvent& )
126 {
128 }
129 }
130 };
131
132 if( ADVANCED_CFG::GetCfg().m_HotkeysDumper )
133 {
134 // Add hotkeys dumper (does not need translation, it's a dev tool only)
135 l_btn_defs.push_back( {
136 wxID_ANY, wxT( "Dump Hotkeys" ), wxEmptyString,
137 [this]( wxCommandEvent& )
138 {
139 dumpHotkeys();
140 }
141 } );
142 }
143
144 const BUTTON_ROW_PANEL::BTN_DEF_LIST r_btn_defs = {
145 };
146
147 auto btnPanel = std::make_unique<BUTTON_ROW_PANEL>( this, l_btn_defs, r_btn_defs );
148
149 aSizer->Add( btnPanel.release(), 0, wxEXPAND | wxALL, KIUI::GetStdMargin() * 2 );
150}
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
std::vector< BTN_DEF > BTN_DEF_LIST
A list of BTN_DEFs, used to group buttons into the left/right groups.
void ImportHotKeys()
Put up a dialog allowing the user to select a hotkeys file and then overlays those hotkeys onto the c...
void dumpHotkeys()
Dump all actions and their hotkeys to a text file for inclusion in documentation.
void ResetAllHotkeys(bool aResetToDefault)
Set hotkeys in the control to default or original values.
int GetStdMargin()
Get the standard margin around a widget in the KiCad UI.
Definition: ui_common.cpp:41

References _, dumpHotkeys(), ADVANCED_CFG::GetCfg(), KIUI::GetStdMargin(), ImportHotKeys(), m_hotkeyListCtrl, and WIDGET_HOTKEY_LIST::ResetAllHotkeys().

Referenced by PANEL_HOTKEYS_EDITOR().

◆ OnFilterSearch()

void PANEL_HOTKEYS_EDITOR::OnFilterSearch ( wxCommandEvent &  aEvent)
private

Handle a change in the hotkey filter text.

Parameters
aEventis the search event, used to get the search query.

Definition at line 178 of file panel_hotkeys_editor.cpp.

179{
180 const auto searchStr = aEvent.GetString();
182}
void ApplyFilterString(const wxString &aFilterStr)
Method ApplyFilterString Apply a filter string to the hotkey list, selecting which hotkeys to show.

References WIDGET_HOTKEY_LIST::ApplyFilterString(), and m_hotkeyListCtrl.

Referenced by PANEL_HOTKEYS_EDITOR().

◆ ResetPanel()

void PANEL_HOTKEYS_EDITOR::ResetPanel ( )
overridevirtual

Reset the contents of this panel.

Implements RESETTABLE_PANEL.

Definition at line 103 of file panel_hotkeys_editor.cpp.

104{
106}

References m_hotkeyListCtrl, and WIDGET_HOTKEY_LIST::ResetAllHotkeys().

◆ TransferDataFromWindow()

bool PANEL_HOTKEYS_EDITOR::TransferDataFromWindow ( )
override

Definition at line 164 of file panel_hotkeys_editor.cpp.

165{
166 if( m_readOnly )
167 return true;
168
170 return false;
171
173
174 return true;
175}
bool TransferDataFromControl()
Method TransferDataFromControl Save the hotkey data from the control.
int WriteHotKeyConfig(const std::vector< TOOL_ACTION * > &aActions)
Update the hotkeys config file with the hotkeys from the given actions map.

References m_actions, m_hotkeyListCtrl, m_readOnly, WIDGET_HOTKEY_LIST::TransferDataFromControl(), and WriteHotKeyConfig().

◆ TransferDataToWindow()

bool PANEL_HOTKEYS_EDITOR::TransferDataToWindow ( )
override

Definition at line 153 of file panel_hotkeys_editor.cpp.

154{
156
158 return false;
159
160 return true;
161}
void Init(std::vector< TOOL_ACTION * > aActionsList, bool aIncludeReadOnlyCmds)

References HOTKEY_STORE::Init(), m_actions, m_hotkeyListCtrl, m_hotkeyStore, m_readOnly, and WIDGET_HOTKEY_LIST::TransferDataToControl().

Referenced by DIALOG_LIST_HOTKEYS::TransferDataToWindow().

Member Data Documentation

◆ m_actions

std::vector<TOOL_ACTION*> PANEL_HOTKEYS_EDITOR::m_actions
protected

◆ m_frame

EDA_BASE_FRAME* PANEL_HOTKEYS_EDITOR::m_frame
protected

Definition at line 88 of file panel_hotkeys_editor.h.

Referenced by dumpHotkeys(), and ImportHotKeys().

◆ m_hotkeyListCtrl

WIDGET_HOTKEY_LIST* PANEL_HOTKEYS_EDITOR::m_hotkeyListCtrl
protected

◆ m_hotkeyStore

HOTKEY_STORE PANEL_HOTKEYS_EDITOR::m_hotkeyStore
protected

◆ m_readOnly

bool PANEL_HOTKEYS_EDITOR::m_readOnly
protected

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