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 71 of file panel_hotkeys_editor.cpp.

72 :
73 RESETTABLE_PANEL( aWindow, wxID_ANY, wxDefaultPosition, wxDefaultSize ),
74 m_frame( aFrame ),
75 m_readOnly( aReadOnly ),
77{
78 const auto margin = KIUI::GetStdMargin();
79 wxBoxSizer* mainSizer = new wxBoxSizer( wxVERTICAL );
80
81 const int side_margins = margin * 2;
82 wxBoxSizer* bMargins = new wxBoxSizer( wxVERTICAL );
83
84 wxSearchCtrl* filterSearch = CreateTextFilterBox( this, _( "Type filter text" ) );
85 bMargins->Add( filterSearch, 0, wxALL | wxEXPAND, margin );
86
88 bMargins->Add( m_hotkeyListCtrl, 1, wxALL | wxEXPAND, margin );
89
90 if( !m_readOnly )
91 installButtons( bMargins );
92
93 mainSizer->Add( bMargins, 1, wxEXPAND | wxRIGHT | wxLEFT, side_margins );
94
95#ifdef __WXGTK__
96 // Work around a bug that clips the text vertically in the wxSearchCtrl on GTK
97 filterSearch->SetMinSize( wxSize( filterSearch->GetSize().x,
98 int( filterSearch->GetSize().y * 1.6 ) ) );
99#endif
100
101 SetSizer( mainSizer );
102 Layout();
103
104 // Connect Events
105 filterSearch->Bind( wxEVT_COMMAND_TEXT_UPDATED, &PANEL_HOTKEYS_EDITOR::OnFilterSearch, this );
106}
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)
int GetStdMargin()
Get the standard margin around a widget in the KiCad UI.
Definition: ui_common.cpp:41
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(), KIUI::GetStdMargin(), 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 218 of file panel_hotkeys_editor.cpp.

219{
220 wxString filename = wxFileSelector( wxT( "Hotkeys File" ), m_frame->GetMruPath(),
221 wxEmptyString, TextFileExtension, TextFileWildcard(),
222 wxFD_SAVE, this );
223
224 if( filename.IsEmpty() )
225 return;
226
227 wxFileName fn( filename );
228
229 wxFFileOutputStream fileStream( fn.GetFullPath(), "w" );
230 wxTextOutputStream stream( fileStream );
231
232 if( !fn.IsDirWritable() || ( fn.Exists() && !fn.IsFileWritable() ) )
233 return;
234
235 for( HOTKEY_SECTION& section : m_hotkeyStore.GetSections() )
236 {
237 stream << wxT( "=== " ) << section.m_SectionName << endl << endl;
238
239 stream << wxT( "[width=\"100%\",options=\"header\",cols=\"20%,15%,65%\"]" ) << endl;
240 stream << wxT( "|===" ) << endl;
241 stream << _( "| Action | Default Hotkey | Description" ) << endl;
242
243 for( HOTKEY& hk : section.m_HotKeys )
244 {
245 stream << wxT( "| " ) << hk.m_Actions[0]->GetLabel() << endl;
246
247 if( hk.m_EditKeycode > 0 )
248 {
249 stream << wxT( " | kbd:[" ) << KeyNameFromKeyCode( hk.m_EditKeycode ) << ']'
250 << endl;
251 }
252 else
253 {
254 stream << wxT( " |" ) << endl;
255 }
256
257 stream << wxT( " | " ) << hk.m_Actions[0]->GetDescription( false ) << endl;
258 }
259
260 stream << wxT( "|===" ) << endl << endl;
261 }
262
263 stream.Flush();
264 fileStream.Close();
265}
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 191 of file panel_hotkeys_editor.cpp.

192{
193 wxString filename = wxFileSelector( _( "Import Hotkeys File:" ), m_frame->GetMruPath(),
194 wxEmptyString, HotkeyFileExtension,
195 HotkeyFileWildcard(), wxFD_OPEN, this );
196
197 if( filename.IsEmpty() )
198 return;
199
200 std::map<std::string, int> importedHotKeys;
201 ReadHotKeyConfig( filename, importedHotKeys );
202 m_frame->SetMruPath( wxFileName( filename ).GetPath() );
203
204 // Overlay the imported hotkeys onto the hotkey store
205 for( HOTKEY_SECTION& section: m_hotkeyStore.GetSections() )
206 {
207 for( HOTKEY& hotkey: section.m_HotKeys )
208 {
209 if( importedHotKeys.count( hotkey.m_Actions[ 0 ]->GetName() ) )
210 hotkey.m_EditKeycode = importedHotKeys[ hotkey.m_Actions[ 0 ]->GetName() ];
211 }
212 }
213
215}
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 115 of file panel_hotkeys_editor.cpp.

116{
117 BUTTON_ROW_PANEL::BTN_DEF_LIST l_btn_defs = {
118 {
119 wxID_RESET,
120 _( "Undo All Changes" ),
121 _( "Undo all changes made so far in this dialog" ),
122 [this]( wxCommandEvent& )
123 {
125 }
126 },
127 {
128 wxID_ANY,
129 _( "Import Hotkeys..." ),
130 _( "Import hotkey definitions from an external file, replacing the current values" ),
131 [this]( wxCommandEvent& )
132 {
134 }
135 }
136 };
137
138 if( ADVANCED_CFG::GetCfg().m_HotkeysDumper )
139 {
140 // Add hotkeys dumper (does not need translation, it's a dev tool only)
141 l_btn_defs.push_back( {
142 wxID_ANY, wxT( "Dump Hotkeys" ), wxEmptyString,
143 [this]( wxCommandEvent& )
144 {
145 dumpHotkeys();
146 }
147 } );
148 }
149
150 const BUTTON_ROW_PANEL::BTN_DEF_LIST r_btn_defs = {
151 };
152
153 auto btnPanel = std::make_unique<BUTTON_ROW_PANEL>( this, l_btn_defs, r_btn_defs );
154
155 aSizer->Add( btnPanel.release(), 0, wxEXPAND | wxTOP, KIUI::GetStdMargin() );
156}
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.

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 184 of file panel_hotkeys_editor.cpp.

185{
186 const auto searchStr = aEvent.GetString();
188}
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 109 of file panel_hotkeys_editor.cpp.

110{
112}

References m_hotkeyListCtrl, and WIDGET_HOTKEY_LIST::ResetAllHotkeys().

◆ TransferDataFromWindow()

bool PANEL_HOTKEYS_EDITOR::TransferDataFromWindow ( )
override

Definition at line 170 of file panel_hotkeys_editor.cpp.

171{
172 if( m_readOnly )
173 return true;
174
176 return false;
177
179
180 return true;
181}
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 159 of file panel_hotkeys_editor.cpp.

160{
162
164 return false;
165
166 return true;
167}
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: