KiCad PCB EDA Suite
panel_hotkeys_editor.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KICAD, a free EDA CAD application.
3  *
4  * Copyright (C) 1992-2018 Kicad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #include <panel_hotkeys_editor.h>
25 #include <eda_base_frame.h>
26 
27 #include <wx/srchctrl.h>
28 #include <wx/panel.h>
29 #include <wx/button.h>
30 #include <wx/sizer.h>
31 
33 #include <widgets/ui_common.h>
34 
35 
36 static const wxSize default_dialog_size { 500, 350 };
37 static const wxSize min_dialog_size { -1, 350 };
38 
47 static wxSearchCtrl* CreateTextFilterBox( wxWindow* aParent, const wxString& aDescriptiveText )
48 {
49  auto search_widget = new wxSearchCtrl( aParent, wxID_ANY );
50 
51  search_widget->ShowSearchButton( false );
52  search_widget->ShowCancelButton( true );
53 
54  search_widget->SetDescriptiveText( aDescriptiveText);
55 
56  return search_widget;
57 }
58 
59 
61  bool aReadOnly,
62  EDA_HOTKEY_CONFIG* aHotkeys,
63  EDA_HOTKEY_CONFIG* aShowHotkeys,
64  const wxString& aNickname ) :
65  wxPanel( aWindow, wxID_ANY, wxDefaultPosition, default_dialog_size ),
66  m_frame( aFrame ),
67  m_readOnly( aReadOnly ),
68  m_hotkeys( aHotkeys ),
69  m_nickname( aNickname ),
70  m_hotkeyStore( aShowHotkeys )
71 {
72  const auto margin = KIUI::GetStdMargin();
73  auto mainSizer = new wxBoxSizer( wxVERTICAL );
74 
75  // Sub-sizer for setting a wider side margin
76  // TODO: Can this be set by the parent widget- doesn't seem to be
77  // this panel's responsibility?
78  const int side_margins = 10; // seems to be hardcoded in wxFB
79  auto bMargins = new wxBoxSizer( wxVERTICAL );
80 
81  auto filterSearch = CreateTextFilterBox( this, _( "Type filter text" ) );
82  bMargins->Add( filterSearch, 0, wxBOTTOM | wxEXPAND | wxTOP, margin );
83 
85  bMargins->Add( m_hotkeyListCtrl, 1, wxALL | wxEXPAND, margin );
86 
87  if( !m_readOnly )
88  installButtons( bMargins );
89 
90  mainSizer->Add( bMargins, 1, wxEXPAND | wxRIGHT | wxLEFT, side_margins );
91 
92  this->SetSizer( mainSizer );
93  this->Layout();
94 
95  // Connect Events
96  filterSearch->Bind( wxEVT_COMMAND_TEXT_UPDATED,
98 }
99 
100 
102 {
103  const BUTTON_ROW_PANEL::BTN_DEF_LIST l_btn_defs = {
104  {
105  wxID_RESET,
106  _( "Reset Hotkeys" ),
107  _( "Undo all changes made so far in this dialog" ),
108  [this]( wxCommandEvent ){
110  }
111  },
112  {
113  wxID_ANY,
114  _( "Set to Defaults" ),
115  _( "Set all hotkeys to the built-in KiCad defaults" ),
116  [this]( wxCommandEvent ){
118  }
119  }
120  };
121 
122  const BUTTON_ROW_PANEL::BTN_DEF_LIST r_btn_defs = {
123  {
124  wxID_ANY,
125  _( "Import..." ),
126  _( "Import hotkey definitions from an external file, replacing the current values" ),
127  [this]( wxCommandEvent ){
129  }
130  },
131  {
132  wxID_ANY,
133  _( "Export..." ),
134  _( "Export these hotkey definitions to an external file" ),
135  [this]( wxCommandEvent ){
137  }
138  },
139  };
140 
141  auto btnPanel = new BUTTON_ROW_PANEL( this, l_btn_defs, r_btn_defs );
142 
143  aSizer->Add( btnPanel, 0, wxEXPAND | wxTOP, KIUI::GetStdMargin() );
144 }
145 
146 
148 {
150 }
151 
152 
154 {
156  return false;
157 
158  // save the hotkeys
160 
161  return true;
162 }
163 
164 
165 void PANEL_HOTKEYS_EDITOR::OnFilterSearch( wxCommandEvent& aEvent )
166 {
167  const auto searchStr = aEvent.GetString();
168  m_hotkeyListCtrl->ApplyFilterString( searchStr );
169 }
void OnFilterSearch(wxCommandEvent &aEvent)
Function OnFilterSearch Handle a change in the hoteky filter text.
Structure EDA_HOTKEY_CONFIG contains the information required to save hot key information to a config...
Definition: hotkeys_basic.h:94
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...
static const wxSize default_dialog_size
void ExportHotkeyConfigToFile(EDA_HOTKEY_CONFIG *aDescList, const wxString &aDefaultShortname)
Function ExportHotkeyConfigToFile Prompt the user for an old hotkey file to read, and read it...
bool TransferDataToControl()
Method TransferDataToControl Load the hotkey data from the store into the control.
int GetStdMargin()
Get the standard margin around a widget in the KiCad UI.
Definition: ui_common.cpp:23
EDA_BASE_FRAME * m_frame
static const wxSize min_dialog_size
void installButtons(wxSizer *aSizer)
Install the button panel (global reset/default, import/export)
A panel that contains buttons, arranged on the left and/or right sides.
Base window classes and related definitions.
Functions to provide common constants and other functions to assist in making a consistent UI...
void ApplyFilterString(const wxString &aFilterStr)
Method ApplyFilterString Apply a filter string to the hotkey list, selecting which hotkeys to show...
struct EDA_HOTKEY_CONFIG * m_hotkeys
bool TransferDataFromWindow() override
bool TransferDataToWindow() override
virtual int WriteHotkeyConfig(struct EDA_HOTKEY_CONFIG *aDescList, wxString *aFullFileName=NULL)
Function WriteHotkeyConfig Store the current hotkey list It is stored using the standard wxConfig mec...
Class EDA_BASE_FRAME is the base frame for deriving all KiCad main window classes.
std::vector< BTN_DEF > BTN_DEF_LIST
A list of BTN_DEFs, used to group buttons into the left/right groups.
WIDGET_HOTKEY_LIST * m_hotkeyListCtrl
void ImportHotkeyConfigFromFile(EDA_HOTKEY_CONFIG *aDescList, const wxString &aDefaultShortname)
Function ImportHotkeyConfigFromFile Prompt the user for an old hotkey file to read, and read it.
PANEL_HOTKEYS_EDITOR(EDA_BASE_FRAME *aFrame, wxWindow *aWindow, bool aReadOnly, EDA_HOTKEY_CONFIG *aHotkeys, EDA_HOTKEY_CONFIG *aShowHotkeys, const wxString &aNickname)
void ResetAllHotkeys(bool aResetToDefault)
Set hotkeys in the control to default or original values.
bool TransferDataFromControl()
Method TransferDataFromControl Save the hotkey data from the control.