KiCad PCB EDA Suite
PANEL_HOTKEYS_EDITOR Class Reference

#include <panel_hotkeys_editor.h>

Inheritance diagram for PANEL_HOTKEYS_EDITOR:

Public Member Functions

 PANEL_HOTKEYS_EDITOR (EDA_BASE_FRAME *aFrame, wxWindow *aWindow, bool aReadOnly)
 
void AddHotKeys (TOOL_MANAGER *aToolMgr)
 
bool TransferDataToWindow () override
 
bool TransferDataFromWindow () override
 

Protected Attributes

EDA_BASE_FRAMEm_frame
 
bool m_readOnly
 
std::vector< TOOL_MANAGER * > m_toolManagers
 
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)
 Function OnFilterSearch Handle a change in the hoteky filter text. More...
 
void ImportHotKeys ()
 Function ImportHotKeys Puts up a dialog allowing the user to select a hotkeys file and then overlays those hotkeys onto the current hotkey store. More...
 

Detailed Description

Definition at line 40 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 62 of file panel_hotkeys_editor.cpp.

63  :
64  wxPanel( aWindow, wxID_ANY, wxDefaultPosition, default_dialog_size ),
65  m_frame( aFrame ),
66  m_readOnly( aReadOnly ),
68 {
69  const auto margin = KIUI::GetStdMargin();
70  auto mainSizer = new wxBoxSizer( wxVERTICAL );
71 
72  // Sub-sizer for setting a wider side margin
73  // TODO: Can this be set by the parent widget- doesn't seem to be
74  // this panel's responsibility?
75  const int side_margins = 10; // seems to be hardcoded in wxFB
76  auto bMargins = new wxBoxSizer( wxVERTICAL );
77 
78  auto filterSearch = CreateTextFilterBox( this, _( "Type filter text" ) );
79  bMargins->Add( filterSearch, 0, wxBOTTOM | wxEXPAND | wxTOP, margin );
80 
82  bMargins->Add( m_hotkeyListCtrl, 1, wxALL | wxEXPAND, margin );
83 
84  if( !m_readOnly )
85  installButtons( bMargins );
86 
87  mainSizer->Add( bMargins, 1, wxEXPAND | wxRIGHT | wxLEFT, side_margins );
88 
89  this->SetSizer( mainSizer );
90  this->Layout();
91 
92  // Connect Events
93  filterSearch->Bind( wxEVT_COMMAND_TEXT_UPDATED, &PANEL_HOTKEYS_EDITOR::OnFilterSearch, this );
94 }
void OnFilterSearch(wxCommandEvent &aEvent)
Function OnFilterSearch Handle a change in the hoteky 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.
static const wxSize default_dialog_size
int GetStdMargin()
Get the standard margin around a widget in the KiCad UI.
Definition: ui_common.cpp:23
EDA_BASE_FRAME * m_frame
void installButtons(wxSizer *aSizer)
Install the button panel (global reset/default, import/export)
#define _(s)
WIDGET_HOTKEY_LIST * m_hotkeyListCtrl

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

Member Function Documentation

◆ AddHotKeys()

◆ ImportHotKeys()

void PANEL_HOTKEYS_EDITOR::ImportHotKeys ( )
private

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

Definition at line 171 of file panel_hotkeys_editor.cpp.

172 {
173  wxString ext = DEFAULT_HOTKEY_FILENAME_EXT;
174  wxString mask = wxT( "*." ) + ext;
175  wxString filename = EDA_FILE_SELECTOR( _( "Import Hotkeys File:" ), m_frame->GetMruPath(),
176  wxEmptyString, ext, mask, this, wxFD_OPEN, true );
177 
178  if( filename.IsEmpty() )
179  return;
180 
181  std::map<std::string, int> importedHotKeys;
182  ReadHotKeyConfig( filename, importedHotKeys );
183  m_frame->SetMruPath( wxFileName( filename ).GetPath() );
184 
185  // Overlay the imported hotkeys onto the hotkey store
186  for( HOTKEY_SECTION& section: m_hotkeyStore.GetSections() )
187  {
188  for( HOTKEY& hotkey: section.m_HotKeys )
189  {
190  if( importedHotKeys.count( hotkey.m_Actions[ 0 ]->GetName() ) )
191  hotkey.m_EditKeycode = importedHotKeys[ hotkey.m_Actions[ 0 ]->GetName() ];
192  }
193  }
194 
196 }
void SetMruPath(const wxString &aPath)
bool TransferDataToControl()
Method TransferDataToControl Load the hotkey data from the store into the control.
void ReadHotKeyConfig(wxString fileName, std::map< std::string, int > &aHotKeys)
Function ReadotKeyConfig Reads a hotkey config file into a map.
EDA_BASE_FRAME * m_frame
wxString GetMruPath() const
wxString EDA_FILE_SELECTOR(const wxString &aTitle, const wxString &aPath, const wxString &aFileName, const wxString &aExtension, const wxString &aWildcard, wxWindow *aParent, int aStyle, const bool aKeepWorkingDirectory, const wxPoint &aPosition, wxString *aMruPath)
Function EDA_FILE_SELECTOR.
Definition: gestfich.cpp:82
#define _(s)
std::vector< TOOL_ACTION * > m_Actions
Definition: hotkey_store.h:35
std::vector< HOTKEY_SECTION > & GetSections()
Get the list of sections managed by this store.
WIDGET_HOTKEY_LIST * m_hotkeyListCtrl
#define DEFAULT_HOTKEY_FILENAME_EXT
Definition: hotkeys_basic.h:30
int m_EditKeycode
Definition: hotkey_store.h:36

References _, DEFAULT_HOTKEY_FILENAME_EXT, EDA_FILE_SELECTOR(), EDA_BASE_FRAME::GetMruPath(), HOTKEY_STORE::GetSections(), 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 103 of file panel_hotkeys_editor.cpp.

104 {
105  const BUTTON_ROW_PANEL::BTN_DEF_LIST l_btn_defs = {
106  {
107  wxID_RESET,
108  _( "Undo All Changes" ),
109  _( "Undo all changes made so far in this dialog" ),
110  [this]( wxCommandEvent& ){
112  }
113  },
114  {
115  wxID_ANY,
116  _( "Restore All to Defaults" ),
117  _( "Set all hotkeys to the built-in KiCad defaults" ),
118  [this]( wxCommandEvent& ){
120  }
121  },
122  {
123  wxID_ANY,
124  _( "Import Hotkeys..." ),
125  _( "Import hotkey definitions from an external file, replacing the current values" ),
126  [this]( wxCommandEvent& ){
127  ImportHotKeys();
128  }
129  }
130  };
131 
132  const BUTTON_ROW_PANEL::BTN_DEF_LIST r_btn_defs = {
133  };
134 
135  auto btnPanel = std::make_unique<BUTTON_ROW_PANEL>( this, l_btn_defs, r_btn_defs );
136 
137  aSizer->Add( btnPanel.release(), 0, wxEXPAND | wxTOP, KIUI::GetStdMargin() );
138 }
void ImportHotKeys()
Function ImportHotKeys Puts up a dialog allowing the user to select a hotkeys file and then overlays ...
int GetStdMargin()
Get the standard margin around a widget in the KiCad UI.
Definition: ui_common.cpp:23
#define _(s)
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 ResetAllHotkeys(bool aResetToDefault)
Set hotkeys in the control to default or original values.

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

Referenced by PANEL_HOTKEYS_EDITOR().

◆ OnFilterSearch()

void PANEL_HOTKEYS_EDITOR::OnFilterSearch ( wxCommandEvent &  aEvent)
private

Function OnFilterSearch Handle a change in the hoteky filter text.

Parameters
aEventthe search event, used to get the search query

Definition at line 164 of file panel_hotkeys_editor.cpp.

165 {
166  const auto searchStr = aEvent.GetString();
167  m_hotkeyListCtrl->ApplyFilterString( searchStr );
168 }
void ApplyFilterString(const wxString &aFilterStr)
Method ApplyFilterString Apply a filter string to the hotkey list, selecting which hotkeys to show.
WIDGET_HOTKEY_LIST * m_hotkeyListCtrl

References WIDGET_HOTKEY_LIST::ApplyFilterString(), and m_hotkeyListCtrl.

Referenced by PANEL_HOTKEYS_EDITOR().

◆ TransferDataFromWindow()

bool PANEL_HOTKEYS_EDITOR::TransferDataFromWindow ( )
override

Definition at line 148 of file panel_hotkeys_editor.cpp.

149 {
151  return false;
152 
153  if( m_readOnly )
154  return true;
155 
156  // save the hotkeys
157  for( TOOL_MANAGER* toolMgr : m_toolManagers )
158  WriteHotKeyConfig( toolMgr->GetActions() );
159 
160  return true;
161 }
std::vector< TOOL_MANAGER * > m_toolManagers
Class TOOL_MANAGER.
Definition: tool_manager.h:50
WIDGET_HOTKEY_LIST * m_hotkeyListCtrl
int WriteHotKeyConfig(const std::map< std::string, TOOL_ACTION * > &aActionMap)
Function WriteHotKeyConfig Updates the hotkeys config file with the hotkeys from the given actions ma...
bool TransferDataFromControl()
Method TransferDataFromControl Save the hotkey data from the control.

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

◆ TransferDataToWindow()

bool PANEL_HOTKEYS_EDITOR::TransferDataToWindow ( )
override

Definition at line 141 of file panel_hotkeys_editor.cpp.

142 {
145 }
bool TransferDataToControl()
Method TransferDataToControl Load the hotkey data from the store into the control.
std::vector< TOOL_MANAGER * > m_toolManagers
WIDGET_HOTKEY_LIST * m_hotkeyListCtrl
void Init(std::vector< TOOL_MANAGER * > aToolManagerList, bool aIncludeGestures)

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

Referenced by DIALOG_LIST_HOTKEYS::TransferDataToWindow().

Member Data Documentation

◆ m_frame

EDA_BASE_FRAME* PANEL_HOTKEYS_EDITOR::m_frame
protected

Definition at line 43 of file panel_hotkeys_editor.h.

Referenced by 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

◆ m_toolManagers

std::vector<TOOL_MANAGER*> PANEL_HOTKEYS_EDITOR::m_toolManagers
protected

Definition at line 46 of file panel_hotkeys_editor.h.

Referenced by AddHotKeys(), TransferDataFromWindow(), and TransferDataToWindow().


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