30#include <wx/filedlg.h>
32#include <wx/srchctrl.h>
33#include <wx/txtstrm.h>
34#include <wx/wfstream.h>
49 wxSearchCtrl* search_widget =
new wxSearchCtrl( aParent, wxID_ANY );
51 search_widget->ShowSearchButton(
false );
52 search_widget->ShowCancelButton(
true );
54 search_widget->SetDescriptiveText( aDescriptiveText );
59 search_widget->SetMinSize( wxSize( -1, aParent->GetTextExtent( wxT(
"qb" ) ).y + 10 ) );
71 wxBoxSizer* mainSizer =
new wxBoxSizer( wxVERTICAL );
72 wxBoxSizer* bMargins =
new wxBoxSizer( wxVERTICAL );
84 mainSizer->Add( bMargins, 1, wxEXPAND, 0 );
89#if wxVERSION_NUMBER < 3203
98 SetSizer( mainSizer );
100 mainSizer->Fit(
this );
125 _(
"Undo All Changes" ),
126 _(
"Undo all changes made so far in this dialog" ),
127 [
this]( wxCommandEvent& )
134 _(
"Import Hotkeys..." ),
135 _(
"Import hotkey definitions from an external file, replacing the current values" ),
136 [
this]( wxCommandEvent& )
146 l_btn_defs.push_back( {
147 wxID_ANY, wxT(
"Dump Hotkeys" ), wxEmptyString,
148 [
this]( wxCommandEvent& )
158 auto btnPanel = std::make_unique<BUTTON_ROW_PANEL>(
this, l_btn_defs, r_btn_defs );
192 const auto searchStr = aEvent.GetString();
199 wxString filename = wxFileSelector(
_(
"Import Hotkeys File:" ),
m_frame->GetMruPath(),
202 wxGetTopLevelParent(
this ) );
204 if( filename.IsEmpty() )
207 std::map<std::string, std::pair<int, int>> importedHotKeys;
209 m_frame->SetMruPath( wxFileName( filename ).GetPath() );
212 std::set<wxString> ignoredReservedKeys;
216 for(
HOTKEY& hotkey: section.m_HotKeys )
218 auto imported = importedHotKeys.find( hotkey.
m_Actions[0]->GetName() );
220 if( imported != importedHotKeys.end() )
222 auto importKey = [&](
int aKey,
int& aDestination )
224 wxString reservedKeyName;
227 ignoredReservedKeys.insert( reservedKeyName );
238 if( !ignoredReservedKeys.empty() )
242 for(
const wxString& keyName : ignoredReservedKeys )
244 if( !keyNames.IsEmpty() )
245 keyNames += wxS(
", " );
251 "(%s). These assignments were ignored." ),
261 wxString filename = wxFileSelector( wxT(
"Hotkeys File" ),
m_frame->GetMruPath(),
264 wxFD_SAVE, wxGetTopLevelParent(
this ) );
266 if( filename.IsEmpty() )
269 wxFileName fn( filename );
271 wxFFileOutputStream fileStream( fn.GetFullPath(),
"w" );
272 wxTextOutputStream stream( fileStream );
274 if( !fn.IsDirWritable() || ( fn.Exists() && !fn.IsFileWritable() ) )
279 stream << wxT(
"=== " ) << section.m_SectionName << endl << endl;
281 stream << wxT(
"[width=\"100%\",options=\"header\",cols=\"20%,15%,65%\"]" ) << endl;
282 stream << wxT(
"|===" ) << endl;
283 stream <<
_(
"| Action | Default Hotkey | Description" ) << endl;
285 for(
HOTKEY& hk : section.m_HotKeys )
287 stream << wxT(
"| " ) << hk.
m_Actions[0]->GetFriendlyName() << endl;
296 stream << wxT(
" |" ) << endl;
299 stream << wxT(
" | " ) << hk.
m_Actions[0]->GetDescription() << endl;
302 stream << wxT(
"|===" ) << endl << endl;
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
The base frame for deriving all KiCad main window classes.
HOTKEY_STORE m_hotkeyStore
PANEL_HOTKEYS_EDITOR(EDA_BASE_FRAME *aFrame, wxWindow *aWindow, bool readOnly)
void OnFilterSearch(wxCommandEvent &aEvent)
Handle a change in the hotkey filter text.
void ResetPanel() override
Reset the contents of this panel.
std::vector< TOOL_ACTION * > m_actions
void installButtons(wxSizer *aSizer)
Install the button panel (global reset/default, import/export)
WIDGET_HOTKEY_LIST * m_hotkeyListCtrl
bool TransferDataToWindow() override
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.
wxSearchCtrl * m_filterSearch
bool TransferDataFromWindow() override
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)
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
static const std::string TextFileExtension
static const std::string HotkeyFileExtension
static wxString HotkeyFileWildcard()
static wxString TextFileWildcard()
void ReadHotKeyConfig(const wxString &aFileName, std::map< std::string, std::pair< int, int > > &aHotKeys)
Read a hotkey config file into a map.
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
int WriteHotKeyConfig(const std::vector< TOOL_ACTION * > &aActions)
Update the hotkeys config file with the hotkeys from the given actions map.
KICOMMON_API int GetStdMargin()
Get the standard margin around a widget in the KiCad UI.
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.
std::vector< TOOL_ACTION * > m_Actions
Functions to provide common constants and other functions to assist in making a consistent UI.
Definition of file extensions used in Kicad.