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)
 
void AddHotKeys (TOOL_MANAGER *aToolMgr)
 
bool TransferDataToWindow () override
 
bool TransferDataFromWindow () override
 
void ResetPanel () override
 Reset the contents of this panel. More...
 
wxString GetResetTooltip () override
 Get the tooltip the reset button should display when showing this panel. More...
 

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)
 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 ()
 Dumps 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, default_dialog_size ),
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.
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.
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)
static const wxSize default_dialog_size
int GetStdMargin()
Get the standard margin around a widget in the KiCad UI.
Definition: ui_common.cpp:38
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()

◆ dumpHotkeys()

void PANEL_HOTKEYS_EDITOR::dumpHotkeys ( )
private

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

224 {
225  wxString filename = wxFileSelector( wxT( "Hotkeys File" ), m_frame->GetMruPath(),
226  wxEmptyString, TextFileExtension, TextFileWildcard(),
227  wxFD_SAVE, this );
228 
229  if( filename.IsEmpty() )
230  return;
231 
232  wxFileName fn( filename );
233 
234  wxFFileOutputStream fileStream( fn.GetFullPath(), "w" );
235  wxTextOutputStream stream( fileStream );
236 
237  if( !fn.IsDirWritable() || ( fn.Exists() && !fn.IsFileWritable() ) )
238  return;
239 
240  for( HOTKEY_SECTION& section : m_hotkeyStore.GetSections() )
241  {
242  stream << wxT( "=== " ) << section.m_SectionName << endl << endl;
243 
244  stream << wxT( "[width=\"100%\",options=\"header\",cols=\"20%,15%,65%\"]" ) << endl;
245  stream << wxT( "|===" ) << endl;
246  stream << _( "| Action | Default Hotkey | Description" ) << endl;
247 
248  for( HOTKEY& hk : section.m_HotKeys )
249  {
250  stream << wxT( "| " ) << hk.m_Actions[0]->GetLabel() << endl;
251 
252  if( hk.m_EditKeycode > 0 )
253  {
254  stream << wxT( " | kbd:[" ) << KeyNameFromKeyCode( hk.m_EditKeycode ) << ']'
255  << endl;
256  }
257  else
258  {
259  stream << wxT( " |" ) << endl;
260  }
261 
262  stream << wxT( " | " ) << hk.m_Actions[0]->GetDescription( false ) << endl;
263  }
264 
265  stream << wxT( "|===" ) << endl << endl;
266  }
267 
268  stream.Flush();
269  fileStream.Close();
270 }
EDA_BASE_FRAME * m_frame
wxString GetMruPath() const
#define _(s)
const std::string TextFileExtension
std::vector< TOOL_ACTION * > m_Actions
Definition: hotkey_store.h:36
std::vector< HOTKEY_SECTION > & GetSections()
Get the list of sections managed by this store.
wxString TextFileWildcard()
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
int m_EditKeycode
Definition: hotkey_store.h:37

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().

◆ GetResetTooltip()

wxString PANEL_HOTKEYS_EDITOR::GetResetTooltip ( )
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  }
#define _(s)

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

197 {
198  wxString filename = wxFileSelector( _( "Import Hotkeys File:" ), m_frame->GetMruPath(),
199  wxEmptyString, HotkeyFileExtension,
200  HotkeyFileWildcard(), wxFD_OPEN, this );
201 
202  if( filename.IsEmpty() )
203  return;
204 
205  std::map<std::string, int> importedHotKeys;
206  ReadHotKeyConfig( filename, importedHotKeys );
207  m_frame->SetMruPath( wxFileName( filename ).GetPath() );
208 
209  // Overlay the imported hotkeys onto the hotkey store
210  for( HOTKEY_SECTION& section: m_hotkeyStore.GetSections() )
211  {
212  for( HOTKEY& hotkey: section.m_HotKeys )
213  {
214  if( importedHotKeys.count( hotkey.m_Actions[ 0 ]->GetName() ) )
215  hotkey.m_EditKeycode = importedHotKeys[ hotkey.m_Actions[ 0 ]->GetName() ];
216  }
217  }
218 
220 }
void SetMruPath(const wxString &aPath)
bool TransferDataToControl()
Method TransferDataToControl Load the hotkey data from the store into the control.
void ReadHotKeyConfig(const wxString &aFileName, std::map< std::string, int > &aHotKeys)
Reads a hotkey config file into a map.
EDA_BASE_FRAME * m_frame
wxString GetMruPath() const
wxString HotkeyFileWildcard()
#define _(s)
std::vector< TOOL_ACTION * > m_Actions
Definition: hotkey_store.h:36
std::vector< HOTKEY_SECTION > & GetSections()
Get the list of sections managed by this store.
const std::string HotkeyFileExtension
WIDGET_HOTKEY_LIST * m_hotkeyListCtrl
int m_EditKeycode
Definition: hotkey_store.h:37

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

122 {
123  BUTTON_ROW_PANEL::BTN_DEF_LIST l_btn_defs = {
124  {
125  wxID_RESET,
126  _( "Undo All Changes" ),
127  _( "Undo all changes made so far in this dialog" ),
128  [this]( wxCommandEvent& )
129  {
131  }
132  },
133  {
134  wxID_ANY,
135  _( "Import Hotkeys..." ),
136  _( "Import hotkey definitions from an external file, replacing the current values" ),
137  [this]( wxCommandEvent& )
138  {
139  ImportHotKeys();
140  }
141  }
142  };
143 
144 
145  if( ADVANCED_CFG::GetCfg().m_HotkeysDumper )
146  {
147  // Add hotkeys dumper (does not need translation, it's a dev tool only)
148  l_btn_defs.push_back( {
149  wxID_ANY, wxT( "Dump Hotkeys" ), wxEmptyString,
150  [this]( wxCommandEvent& )
151  {
152  dumpHotkeys();
153  }
154  } );
155  }
156 
157  const BUTTON_ROW_PANEL::BTN_DEF_LIST r_btn_defs = {
158  };
159 
160  auto btnPanel = std::make_unique<BUTTON_ROW_PANEL>( this, l_btn_defs, r_btn_defs );
161 
162  aSizer->Add( btnPanel.release(), 0, wxEXPAND | wxTOP, KIUI::GetStdMargin() );
163 }
void ImportHotKeys()
Put up a dialog allowing the user to select a hotkeys file and then overlays those hotkeys onto the c...
int GetStdMargin()
Get the standard margin around a widget in the KiCad UI.
Definition: ui_common.cpp:38
#define _(s)
void dumpHotkeys()
Dumps all actions and their hotkeys to a text file for inclusion in documentation.
std::vector< BTN_DEF > BTN_DEF_LIST
A list of BTN_DEFs, used to group buttons into the left/right groups.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
WIDGET_HOTKEY_LIST * m_hotkeyListCtrl
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 189 of file panel_hotkeys_editor.cpp.

190 {
191  const auto searchStr = aEvent.GetString();
192  m_hotkeyListCtrl->ApplyFilterString( searchStr );
193 }
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().

◆ ResetPanel()

void PANEL_HOTKEYS_EDITOR::ResetPanel ( )
overridevirtual

Reset the contents of this panel.

Implements RESETTABLE_PANEL.

Definition at line 115 of file panel_hotkeys_editor.cpp.

116 {
118 }
WIDGET_HOTKEY_LIST * m_hotkeyListCtrl
void ResetAllHotkeys(bool aResetToDefault)
Set hotkeys in the control to default or original values.

References m_hotkeyListCtrl, and WIDGET_HOTKEY_LIST::ResetAllHotkeys().

◆ TransferDataFromWindow()

bool PANEL_HOTKEYS_EDITOR::TransferDataFromWindow ( )
override

Definition at line 173 of file panel_hotkeys_editor.cpp.

174 {
176  return false;
177 
178  if( m_readOnly )
179  return true;
180 
181  // save the hotkeys
182  for( TOOL_MANAGER* toolMgr : m_toolManagers )
183  WriteHotKeyConfig( toolMgr->GetActions() );
184 
185  return true;
186 }
std::vector< TOOL_MANAGER * > m_toolManagers
Master controller class:
Definition: tool_manager.h:54
WIDGET_HOTKEY_LIST * m_hotkeyListCtrl
int WriteHotKeyConfig(const std::map< std::string, TOOL_ACTION * > &aActionMap)
Update the hotkeys config file with the hotkeys from the given actions map.
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 166 of file panel_hotkeys_editor.cpp.

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

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 87 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

◆ m_toolManagers

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

Definition at line 90 of file panel_hotkeys_editor.h.

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


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