34 #include <wx/filedlg.h> 37 #include <wx/srchctrl.h> 38 #include <wx/tokenzr.h> 39 #include <wx/txtstrm.h> 40 #include <wx/wfstream.h> 54 wxSearchCtrl* search_widget =
new wxSearchCtrl( aParent, wxID_ANY );
56 search_widget->ShowSearchButton(
false );
57 search_widget->ShowCancelButton(
true );
59 search_widget->SetDescriptiveText( aDescriptiveText );
64 search_widget->SetMinSize( wxSize( -1, aParent->GetTextExtent( wxT(
"qb" ) ).y + 10 ) );
75 m_readOnly( aReadOnly ),
79 wxBoxSizer* mainSizer =
new wxBoxSizer( wxVERTICAL );
81 const int side_margins = margin * 2;
82 wxBoxSizer* bMargins =
new wxBoxSizer( wxVERTICAL );
85 bMargins->Add( filterSearch, 0, wxALL | wxEXPAND, margin );
93 mainSizer->Add( bMargins, 1, wxEXPAND | wxRIGHT | wxLEFT, side_margins );
97 filterSearch->SetMinSize( wxSize( filterSearch->GetSize().x,
98 int( filterSearch->GetSize().y * 1.6 ) ) );
101 SetSizer( mainSizer );
126 _(
"Undo All Changes" ),
127 _(
"Undo all changes made so far in this dialog" ),
128 [
this]( wxCommandEvent& )
135 _(
"Import Hotkeys..." ),
136 _(
"Import hotkey definitions from an external file, replacing the current values" ),
137 [
this]( wxCommandEvent& )
148 l_btn_defs.push_back( {
149 wxID_ANY, wxT(
"Dump Hotkeys" ), wxEmptyString,
150 [
this]( wxCommandEvent& )
160 auto btnPanel = std::make_unique<BUTTON_ROW_PANEL>(
this, l_btn_defs, r_btn_defs );
191 const auto searchStr = aEvent.GetString();
198 wxString filename = wxFileSelector(
_(
"Import Hotkeys File:" ),
m_frame->
GetMruPath(),
202 if( filename.IsEmpty() )
205 std::map<std::string, int> importedHotKeys;
212 for(
HOTKEY& hotkey: section.m_HotKeys )
214 if( importedHotKeys.count( hotkey.
m_Actions[ 0 ]->GetName() ) )
225 wxString filename = wxFileSelector( wxT(
"Hotkeys File" ),
m_frame->
GetMruPath(),
229 if( filename.IsEmpty() )
232 wxFileName fn( filename );
234 wxFFileOutputStream fileStream( fn.GetFullPath(), wxT(
"w" ) );
235 wxTextOutputStream stream( fileStream );
237 if( !fn.IsDirWritable() || ( fn.Exists() && !fn.IsFileWritable() ) )
242 stream << wxT(
"=== " ) << section.m_SectionName << endl << endl;
244 stream << wxT(
"[width=\"100%\",options=\"header\",cols=\"20%,15%,65%\"]" ) << endl;
245 stream << wxT(
"|===" ) << endl;
246 stream <<
_(
"| Action | Default Hotkey | Description" ) << endl;
248 for(
HOTKEY& hk : section.m_HotKeys )
250 stream << wxT(
"| " ) << hk.
m_Actions[0]->GetLabel() << endl;
259 stream << wxT(
" |" ) << endl;
262 stream << wxT(
" | " ) << hk.
m_Actions[0]->GetDescription(
false ) << endl;
265 stream << wxT(
"|===" ) << endl << endl;
void OnFilterSearch(wxCommandEvent &aEvent)
Handle a change in the hotkey filter text.
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.
void SetMruPath(const wxString &aPath)
static const wxSize default_dialog_size
void ImportHotKeys()
Put up a dialog allowing the user to select a hotkeys file and then overlays those hotkeys onto the c...
void ResetPanel() override
Reset the contents of this panel.
void ReadHotKeyConfig(const wxString &aFileName, std::map< std::string, int > &aHotKeys)
Reads a hotkey config file into a map.
void AddHotKeys(TOOL_MANAGER *aToolMgr)
int GetStdMargin()
Get the standard margin around a widget in the KiCad UI.
std::vector< TOOL_MANAGER * > m_toolManagers
wxString GetMruPath() const
void installButtons(wxSizer *aSizer)
Install the button panel (global reset/default, import/export)
Definition of file extensions used in Kicad.
Functions to provide common constants and other functions to assist in making a consistent UI.
wxString HotkeyFileWildcard()
HOTKEY_STORE m_hotkeyStore
void dumpHotkeys()
Dumps all actions and their hotkeys to a text file for inclusion in documentation.
const std::string TextFileExtension
bool TransferDataFromWindow() override
std::vector< TOOL_ACTION * > m_Actions
bool TransferDataToWindow() override
std::vector< HOTKEY_SECTION > & GetSections()
Get the list of sections managed by this store.
const std::string HotkeyFileExtension
The base frame for deriving all KiCad main window classes.
wxString TextFileWildcard()
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
void Init(std::vector< TOOL_MANAGER * > aToolManagerList, bool aIncludeReadOnlyCmds)
PANEL_HOTKEYS_EDITOR(EDA_BASE_FRAME *aFrame, wxWindow *aWindow, bool aReadOnly)
WIDGET_HOTKEY_LIST * m_hotkeyListCtrl
A wxPanel that is designed to be reset in a standard manner.
int WriteHotKeyConfig(const std::map< std::string, TOOL_ACTION * > &aActionMap)
Update the hotkeys config file with the hotkeys from the given actions map.