KiCad PCB EDA Suite
hotkeys_basic.h File Reference

Some functions to handle hotkeys in KiCad. More...

#include <common.h>
#include <i18n_utility.h>

Go to the source code of this file.

Classes

class  EDA_HOTKEY
 class EDA_HOTKEY is a class to handle hot key commands. More...
 
struct  EDA_HOTKEY_CONFIG
 Structure EDA_HOTKEY_CONFIG contains the information required to save hot key information to a configuration file. More...
 
class  EDA_HOTKEY_CLIENT_DATA
 Class EDA_HOTKEY_CLIENT_DATA provides client data member for hotkeys to include in command events generated by the hot key. More...
 

Macros

#define DEFAULT_HOTKEY_FILENAME_EXT   wxT( "hotkeys" )
 
#define EESCHEMA_HOTKEY_NAME   wxT( "Eeschema" )
 
#define PCBNEW_HOTKEY_NAME   wxT( "PcbNew" )
 

Enumerations

enum  HOTKEY_ACTION_TYPE { IS_HOTKEY, IS_ACCELERATOR, IS_COMMENT }
 An helper enum for AddHotkeyName function In menus we can add a hot key, or an accelerator , or sometimes just a comment Hot keys can perform actions using the current mouse cursor position Accelerators perform the same action as the associated menu A comment is used in tool tips for some tools (zoom ..) to show the hot key that performs this action. More...
 
enum  common_hotkey_id_commnand {
  HK_NOT_FOUND = 0, HK_NEW, HK_OPEN, HK_SAVE,
  HK_SAVEAS, HK_PRINT, HK_UNDO, HK_REDO,
  HK_EDIT_CUT, HK_EDIT_COPY, HK_EDIT_PASTE, HK_RESET_LOCAL_COORD,
  HK_SET_GRID_ORIGIN, HK_RESET_GRID_ORIGIN, HK_HELP, HK_ZOOM_IN,
  HK_ZOOM_OUT, HK_ZOOM_REDRAW, HK_ZOOM_CENTER, HK_ZOOM_AUTO,
  HK_ZOOM_SELECTION, HK_TOGGLE_CURSOR, HK_MEASURE_TOOL, HK_COMMON_END
}
 

Functions

void AddHotkeyConfigMenu (wxMenu *menu)
 
void HandleHotkeyConfigMenuSelection (EDA_BASE_FRAME *frame, int id)
 
wxString KeyNameFromKeyCode (int aKeycode, bool *aIsFound=NULL)
 Function KeyNameFromKeyCode return the key name from the key code. More...
 
wxString KeyNameFromCommandId (EDA_HOTKEY **aList, int aCommandId)
 Function KeyNameFromCommandId return the key name from the Command id value ( m_Idcommand member value) More...
 
int KeyCodeFromKeyName (const wxString &keyname)
 Function KeyCodeFromKeyName return the key code from its key name Only some wxWidgets key values are handled for function key. More...
 
wxString AddHotkeyName (const wxString &aText, EDA_HOTKEY **aList, int aCommandId, HOTKEY_ACTION_TYPE aShortCutType=IS_HOTKEY)
 Function AddHotkeyName Add the key name from the Command id value ( m_Idcommand member value) More...
 
wxString AddHotkeyName (const wxString &aText, struct EDA_HOTKEY_CONFIG *aDescrList, int aCommandId, HOTKEY_ACTION_TYPE aShortCutType=IS_HOTKEY)
 Function AddHotkeyName Add the key name from the Command id value ( m_Idcommand member value) More...
 
void DisplayHotkeyList (EDA_BASE_FRAME *aFrame, struct EDA_HOTKEY_CONFIG *aList)
 Function DisplayHotkeyList Displays the current hotkey list. More...
 
EDA_HOTKEYGetDescriptorFromHotkey (int aKey, EDA_HOTKEY **aList)
 Function GetDescriptorFromHotkey Returns a EDA_HOTKEY* pointer from a key code for OnHotKey() function. More...
 
EDA_HOTKEYGetDescriptorFromCommand (int aCommand, EDA_HOTKEY **aList)
 Function GetDescriptorFromCommand Returns a EDA_HOTKEY* pointer from a hot key identifier. More...
 
int ReadHotkeyConfigFile (const wxString &aFilename, struct EDA_HOTKEY_CONFIG *aDescList, const bool aDefaultLocation=true)
 Function ReadHotkeyConfig Read hotkey configuration for a given app, possibly before the frame for that app has been created. More...
 
int ReadHotkeyConfig (const wxString &aAppname, struct EDA_HOTKEY_CONFIG *aDescList)
 Function ReadHotkeyConfig Read configuration data and fill the current hotkey list with hotkeys. More...
 
void ParseHotkeyConfig (const wxString &data, struct EDA_HOTKEY_CONFIG *aDescList, const wxString &aAppname)
 Function ParseHotkeyConfig Translates hotkey string data into application hotkeys. More...
 

Variables

wxString g_CommonSectionTag
 

Detailed Description

Some functions to handle hotkeys in KiCad.

Definition in file hotkeys_basic.h.

Macro Definition Documentation

#define DEFAULT_HOTKEY_FILENAME_EXT   wxT( "hotkeys" )
#define EESCHEMA_HOTKEY_NAME   wxT( "Eeschema" )

Definition at line 35 of file hotkeys_basic.h.

Referenced by ReadHotkeyConfig(), and EDA_BASE_FRAME::WriteHotkeyConfig().

#define PCBNEW_HOTKEY_NAME   wxT( "PcbNew" )

Definition at line 36 of file hotkeys_basic.h.

Referenced by ReadHotkeyConfig(), and EDA_BASE_FRAME::WriteHotkeyConfig().

Enumeration Type Documentation

Enumerator
HK_NOT_FOUND 
HK_NEW 
HK_OPEN 
HK_SAVE 
HK_SAVEAS 
HK_PRINT 
HK_UNDO 
HK_REDO 
HK_EDIT_CUT 
HK_EDIT_COPY 
HK_EDIT_PASTE 
HK_RESET_LOCAL_COORD 
HK_SET_GRID_ORIGIN 
HK_RESET_GRID_ORIGIN 
HK_HELP 
HK_ZOOM_IN 
HK_ZOOM_OUT 
HK_ZOOM_REDRAW 
HK_ZOOM_CENTER 
HK_ZOOM_AUTO 
HK_ZOOM_SELECTION 
HK_TOGGLE_CURSOR 
HK_MEASURE_TOOL 
HK_COMMON_END 

Definition at line 256 of file hotkeys_basic.h.

256  {
257  HK_NOT_FOUND = 0,
258  HK_NEW,
259  HK_OPEN,
260  HK_SAVE,
261  HK_SAVEAS,
262  HK_PRINT,
263  HK_UNDO,
264  HK_REDO,
265  HK_EDIT_CUT,
266  HK_EDIT_COPY,
271  HK_HELP,
272  HK_ZOOM_IN,
273  HK_ZOOM_OUT,
276  HK_ZOOM_AUTO,
281 };

An helper enum for AddHotkeyName function In menus we can add a hot key, or an accelerator , or sometimes just a comment Hot keys can perform actions using the current mouse cursor position Accelerators perform the same action as the associated menu A comment is used in tool tips for some tools (zoom ..) to show the hot key that performs this action.

Enumerator
IS_HOTKEY 
IS_ACCELERATOR 
IS_COMMENT 

Definition at line 164 of file hotkeys_basic.h.

Function Documentation

void AddHotkeyConfigMenu ( wxMenu *  menu)

Definition at line 810 of file hotkeys_basic.cpp.

References AddMenuItem(), ID_PREFERENCES_HOTKEY_EXPORT_CONFIG, ID_PREFERENCES_HOTKEY_IMPORT_CONFIG, ID_PREFERENCES_HOTKEY_SHOW_EDITOR, and KiBitmap().

Referenced by EDA_HOTKEY_CLIENT_DATA::GetPosition(), preparePreferencesMenu(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), KICAD_MANAGER_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), and GERBVIEW_FRAME::ReCreateMenuBar().

811 {
812  if( aMenu == nullptr )
813  return;
814 
815  wxMenu* HotkeySubmenu = new wxMenu();
816 
817  // Call hotkeys editor
819  _( "&Edit Hotkeys..." ),
820  _( "Edit hotkeys list" ),
821  KiBitmap( config_xpm ) );
822 
823  HotkeySubmenu->AppendSeparator();
824 
825  // create hotkey file to export current hotkeys config
827  _( "E&xport Hotkeys..." ),
828  _( "Export current hotkeys into configuration file" ),
829  KiBitmap( hotkeys_export_xpm ) );
830 
831  // Reload hotkey file
833  _( "&Import Hotkeys..." ),
834  _( "Load existing hotkey configuration file" ),
835  KiBitmap( hotkeys_import_xpm ) );
836 
837  // Append HotkeySubmenu to menu
838  AddMenuItem( aMenu, HotkeySubmenu,
839  wxID_ANY, _( "&Hotkeys Options" ),
840  _( "Edit hotkeys configuration and preferences" ),
841  KiBitmap( hotkeys_xpm ) );
842 }
wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into ...
Definition: bitmap.cpp:174
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:78
wxString AddHotkeyName ( const wxString &  aText,
EDA_HOTKEY **  aList,
int  aCommandId,
HOTKEY_ACTION_TYPE  aShortCutType = IS_HOTKEY 
)

Function AddHotkeyName Add the key name from the Command id value ( m_Idcommand member value)

Parameters
aText= a wxString. returns aText + key name
aList= pointer to a EDA_HOTKEY list of commands
aCommandId= Command Id value
aShortCutTypeThe HOTKEY_ACTION_TYPE of the shortcut.
Returns
a wxString (aTest + key name) if key found or aText without modification

Definition at line 249 of file hotkeys_basic.cpp.

References AddModifierToKey(), IS_ACCELERATOR, IS_COMMENT, IS_HOTKEY, KeyNameFromCommandId(), MODIFIER_CMD_MAC, and MODIFIER_CTRL_BASE.

Referenced by SCH_EDIT_FRAME::addJunctionMenuEntries(), AddMenusForBitmap(), AddMenusForBlock(), AddMenusForBus(), AddMenusForBusEntry(), AddMenusForComponent(), AddMenusForComponentField(), AddMenusForEditComponent(), AddMenusForGLabel(), AddMenusForHierchicalSheet(), AddMenusForHLabel(), AddMenusForLabel(), AddMenusForPin(), AddMenusForSheetPin(), AddMenusForText(), AddMenusForWire(), EDA_DRAW_FRAME::AddMenuZoomAndGrid(), EDA_3D_VIEWER::CreateMenuBar(), PCB_EDIT_FRAME::createPopUpMenuForFootprints(), PCB_EDIT_FRAME::createPopUpMenuForFpPads(), PCB_EDIT_FRAME::createPopUpMenuForFpTexts(), PCB_EDIT_FRAME::createPopUpMenuForTexts(), PCB_EDIT_FRAME::createPopupMenuForTracks(), PCB_EDIT_FRAME::createPopUpMenuForZones(), FOOTPRINT_EDIT_FRAME::OnRightClick(), EDA_3D_CANVAS::OnRightClick(), PL_EDITOR_FRAME::OnRightClick(), LIB_EDIT_FRAME::OnRightClick(), SCH_EDIT_FRAME::OnRightClick(), PCB_EDIT_FRAME::OnRightClick(), prepareEditMenu(), prepareFilesMenu(), prepareHelpMenu(), preparePlaceMenu(), preparePreferencesMenu(), prepareRouteMenu(), prepareToolsMenu(), prepareViewMenu(), LIB_VIEW_FRAME::ReCreateHToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateHToolbar(), PL_EDITOR_FRAME::ReCreateHToolbar(), FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar(), FOOTPRINT_WIZARD_FRAME::ReCreateHToolbar(), GERBVIEW_FRAME::ReCreateHToolbar(), SCH_EDIT_FRAME::ReCreateHToolbar(), LIB_EDIT_FRAME::ReCreateHToolbar(), PCB_EDIT_FRAME::ReCreateHToolbar(), LIB_VIEW_FRAME::ReCreateMenuBar(), FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), KICAD_MANAGER_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), and PCB_LAYER_BOX_SELECTOR::Resync().

251 {
252  wxString msg = aText;
253  wxString keyname;
254 
255  if( aList )
256  keyname = KeyNameFromCommandId( aList, aCommandId );
257 
258  if( !keyname.IsEmpty() )
259  {
260  switch( aShortCutType )
261  {
262  case IS_HOTKEY:
263  msg << wxT( "\t" ) << keyname;
264  break;
265 
266  case IS_ACCELERATOR:
267  AddModifierToKey( msg, keyname );
268  break;
269 
270  case IS_COMMENT:
271  msg << wxT( " (" ) << keyname << wxT( ")" );
272  break;
273  }
274  }
275 
276 #ifdef USING_MAC_CMD
277  // On OSX, the modifier equivalent to the Ctrl key of PCs
278  // is the Cmd key, but in code we should use Ctrl as prefix in menus
279  msg.Replace( MODIFIER_CMD_MAC, MODIFIER_CTRL_BASE );
280 #endif
281 
282  return msg;
283 }
#define MODIFIER_CTRL_BASE
wxString KeyNameFromCommandId(EDA_HOTKEY **aList, int aCommandId)
Function KeyNameFromCommandId return the key name from the Command id value ( m_Idcommand member valu...
static void AddModifierToKey(wxString &aFullKey, const wxString &aKey)
#define MODIFIER_CMD_MAC
wxString AddHotkeyName ( const wxString &  aText,
struct EDA_HOTKEY_CONFIG aDescrList,
int  aCommandId,
HOTKEY_ACTION_TYPE  aShortCutType = IS_HOTKEY 
)

Function AddHotkeyName Add the key name from the Command id value ( m_Idcommand member value)

Parameters
aText= a wxString. returns aText + key name
aDescrList= pointer to a EDA_HOTKEY_CONFIG DescrList of commands
aCommandId= Command Id value
aShortCutTypeThe HOTKEY_ACTION_TYPE of the shortcut.
Returns
a wxString (aTest + key name) if key found or aText without modification

Definition at line 296 of file hotkeys_basic.cpp.

References AddModifierToKey(), IS_ACCELERATOR, IS_COMMENT, IS_HOTKEY, KeyNameFromCommandId(), EDA_HOTKEY_CONFIG::m_HK_InfoList, MODIFIER_CMD_MAC, and MODIFIER_CTRL_BASE.

300 {
301  wxString msg = aText;
302  wxString keyname;
303  EDA_HOTKEY** list;
304 
305  if( aDescList )
306  {
307  for( ; aDescList->m_HK_InfoList != nullptr; aDescList++ )
308  {
309  list = aDescList->m_HK_InfoList;
310  keyname = KeyNameFromCommandId( list, aCommandId );
311 
312  if( !keyname.IsEmpty() )
313  {
314  switch( aShortCutType )
315  {
316  case IS_HOTKEY:
317  msg << wxT( "\t" ) << keyname;
318  break;
319 
320  case IS_ACCELERATOR:
321  AddModifierToKey( msg, keyname );
322  break;
323 
324  case IS_COMMENT:
325  msg << wxT( " (" ) << keyname << wxT( ")" );
326  break;
327  }
328 
329  break;
330  }
331  }
332  }
333 
334 #ifdef USING_MAC_CMD
335  // On OSX, the modifier equivalent to the Ctrl key of PCs
336  // is the Cmd key, but in code we should use Ctrl as prefix in menus
337  msg.Replace( MODIFIER_CMD_MAC, MODIFIER_CTRL_BASE );
338 #endif
339 
340  return msg;
341 }
#define MODIFIER_CTRL_BASE
wxString KeyNameFromCommandId(EDA_HOTKEY **aList, int aCommandId)
Function KeyNameFromCommandId return the key name from the Command id value ( m_Idcommand member valu...
static void AddModifierToKey(wxString &aFullKey, const wxString &aKey)
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:59
#define MODIFIER_CMD_MAC
void DisplayHotkeyList ( EDA_BASE_FRAME aFrame,
struct EDA_HOTKEY_CONFIG aList 
)

Function DisplayHotkeyList Displays the current hotkey list.

Parameters
aFrame= current active frame
aList= pointer to a EDA_HOTKEY_CONFIG list (Null terminated)

Definition at line 447 of file hotkeys_basic.cpp.

References HTML_MESSAGE_BOX::AddHTML_Text(), KeyNameFromKeyCode(), EDA_HOTKEY_CONFIG::m_HK_InfoList, EDA_HOTKEY::m_InfoMsg, EDA_HOTKEY::m_KeyCode, HTML_MESSAGE_BOX::SetDialogSizeInDU(), and DIALOG_SHIM::Show().

Referenced by EDA_3D_VIEWER::DisplayHotKeys(), LIB_VIEW_FRAME::OnHotKey(), FOOTPRINT_VIEWER_FRAME::OnHotKey(), FOOTPRINT_EDIT_FRAME::OnHotKey(), PL_EDITOR_FRAME::OnHotKey(), SCH_EDIT_FRAME::OnHotKey(), LIB_EDIT_FRAME::OnHotKey(), PCB_EDIT_FRAME::OnHotKey(), GERBVIEW_FRAME::OnHotKey(), KICAD_MANAGER_FRAME::Process_Config(), LIB_EDIT_FRAME::Process_Config(), SCH_EDIT_FRAME::Process_Config(), PL_EDITOR_FRAME::Process_Config(), PCB_EDIT_FRAME::Process_Config(), GERBVIEW_FRAME::Process_Config(), FOOTPRINT_EDIT_FRAME::ProcessPreferences(), GERBVIEW_CONTROL::ShowHelp(), and PCBNEW_CONTROL::ShowHelp().

448 {
449  wxString keyname;
450  wxString keymessage;
451  EDA_HOTKEY** list;
452 
453  wxString msg = wxT( "<html><body bgcolor=\"#E2E2E2\">" );
454 
455  msg += wxT( "<H3>" );
456  msg += _( "Hotkeys List" );
457  msg += wxT( "</H3> <table cellpadding=\"0\">" );
458 
459  for( ; aDescList->m_HK_InfoList != nullptr; aDescList++ )
460  {
461  list = aDescList->m_HK_InfoList;
462 
463  for( ; *list != nullptr; list++ )
464  {
465  EDA_HOTKEY* hk_decr = *list;
466 
467  if( !hk_decr->m_InfoMsg.Contains( wxT( "Macros" ) ) )
468  {
469  keyname = KeyNameFromKeyCode( hk_decr->m_KeyCode );
470  keymessage = wxGetTranslation( hk_decr->m_InfoMsg );
471 
472  // Some chars are modified, using html encoding, to be
473  // displayed by DisplayHtmlInfoMessage()
474  keyname.Replace( wxT( "<" ), wxT( "&lt;" ) );
475  keyname.Replace( wxT( ">" ), wxT( "&gt;" ) );
476  msg += wxT( "<tr><td>" ) + keymessage + wxT( "</td>" );
477  msg += wxT( "<td><b>&nbsp;&nbsp;" ) + keyname + wxT( "</b></td></tr>" );
478  }
479  }
480  }
481 
482  msg += wxT( "</table></html></body>" );
483 
484  // Create a non modal dialog, which shows the list of hotkeys until dismissed
485  // but does not block the parent window
486  HTML_MESSAGE_BOX *dlg = new HTML_MESSAGE_BOX( aFrame, _( "Hotkeys List" ) );
487  dlg->SetDialogSizeInDU( 300, 250 );
488 
489  dlg->AddHTML_Text( msg );
490  dlg->Show( true );
491 }
Class HTML_MESSAGE_BOX.
bool Show(bool show) override
void SetDialogSizeInDU(int aWidth, int aHeight)
set the dialog size, using a "logical value.
wxString m_InfoMsg
Definition: hotkeys_basic.h:66
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:59
void AddHTML_Text(const wxString &message)
Function AddHTML_Text adds html text (without any change) to message list.
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Function KeyNameFromKeyCode return the key name from the key code Only some wxWidgets key values are ...
EDA_HOTKEY* GetDescriptorFromCommand ( int  aCommand,
EDA_HOTKEY **  aList 
)

Function GetDescriptorFromCommand Returns a EDA_HOTKEY* pointer from a hot key identifier.

Parameters
aCommand= hot key identifier (
See also
hotkeys.h)
Parameters
aList= pointer to a EDA_HOTKEY list of commands
Returns
the corresponding EDA_HOTKEY pointer from the EDA_HOTKEY List

Definition at line 515 of file hotkeys_basic.cpp.

References EDA_HOTKEY::m_Idcommand.

Referenced by LIB_VIEW_FRAME::GetHotKeyDescription(), FOOTPRINT_VIEWER_FRAME::GetHotKeyDescription(), FOOTPRINT_EDIT_FRAME::GetHotKeyDescription(), PL_EDITOR_FRAME::GetHotKeyDescription(), SCH_EDIT_FRAME::GetHotKeyDescription(), LIB_EDIT_FRAME::GetHotKeyDescription(), PCB_EDIT_FRAME::GetHotKeyDescription(), and GERBVIEW_FRAME::GetHotKeyDescription().

516 {
517  for( ; *aList != nullptr; aList++ )
518  {
519  EDA_HOTKEY* hk_decr = *aList;
520 
521  if( hk_decr->m_Idcommand == aCommand )
522  return hk_decr;
523  }
524 
525  return nullptr;
526 }
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:59
EDA_HOTKEY* GetDescriptorFromHotkey ( int  aKey,
EDA_HOTKEY **  aList 
)

Function GetDescriptorFromHotkey Returns a EDA_HOTKEY* pointer from a key code for OnHotKey() function.

Parameters
aKey= key code (ascii value, or wxWidgets value for function keys
aList= pointer to a EDA_HOTKEY list of commands
Returns
the corresponding EDA_HOTKEY pointer from the EDA_HOTKEY List

Function GetDescriptorFromHotkey Returns a EDA_HOTKEY* pointer from a key code for OnHotKey() function.

Parameters
aKey= key code (ascii value, or wxWidgets value for function keys
aList= pointer to a EDA_HOTKEY list of commands
Returns
the corresponding EDA_HOTKEY pointer from the EDA_HOTKEY List

Definition at line 501 of file hotkeys_basic.cpp.

References EDA_HOTKEY::m_KeyCode.

Referenced by LIB_VIEW_FRAME::OnHotKey(), FOOTPRINT_VIEWER_FRAME::OnHotKey(), FOOTPRINT_EDIT_FRAME::OnHotKey(), PL_EDITOR_FRAME::OnHotKey(), SCH_EDIT_FRAME::OnHotKey(), LIB_EDIT_FRAME::OnHotKey(), PCB_EDIT_FRAME::OnHotKey(), and GERBVIEW_FRAME::OnHotKey().

502 {
503  for( ; *aList != nullptr; aList++ )
504  {
505  EDA_HOTKEY* hk_decr = *aList;
506 
507  if( hk_decr->m_KeyCode == aKey )
508  return hk_decr;
509  }
510 
511  return nullptr;
512 }
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:59
void HandleHotkeyConfigMenuSelection ( EDA_BASE_FRAME frame,
int  id 
)
int KeyCodeFromKeyName ( const wxString &  keyname)

Function KeyCodeFromKeyName return the key code from its key name Only some wxWidgets key values are handled for function key.

Parameters
keyname= wxString key name to find in s_Hotkey_Name_List[], like F2 or space or an usual (ascii) char.
Returns
the key code
Parameters
keyname= wxString key name to find in hotkeyNameList[], like F2 or space or an usual (ascii) char.
Returns
the key code

Definition at line 378 of file hotkeys_basic.cpp.

References GR_KB_ALT, GR_KB_CTRL, GR_KB_SHIFT, hotkey_name_descr::m_KeyCode, hotkey_name_descr::m_Name, MODIFIER_ALT, MODIFIER_CMD_MAC, MODIFIER_CTRL_BASE, and MODIFIER_SHIFT.

Referenced by EDA_HOTKEY_CLIENT_DATA::GetPosition(), and ParseHotkeyConfig().

379 {
380  int ii, keycode = 0;
381 
382  // Search for modifiers: Ctrl+ Alt+ and Shift+
383  // Note: on Mac OSX, the Cmd key is equiv here to Ctrl
384  wxString key = keyname;
385  wxString prefix;
386  int modifier = 0;
387 
388  while( 1 )
389  {
390  prefix.Empty();
391 
392  if( key.StartsWith( MODIFIER_CTRL_BASE ) )
393  {
394  modifier |= GR_KB_CTRL;
395  prefix = MODIFIER_CTRL_BASE;
396  }
397  else if( key.StartsWith( MODIFIER_CMD_MAC ) )
398  {
399  modifier |= GR_KB_CTRL;
400  prefix = MODIFIER_CMD_MAC;
401  }
402  else if( key.StartsWith( MODIFIER_ALT ) )
403  {
404  modifier |= GR_KB_ALT;
405  prefix = MODIFIER_ALT;
406  }
407  else if( key.StartsWith( MODIFIER_SHIFT ) )
408  {
409  modifier |= GR_KB_SHIFT;
410  prefix = MODIFIER_SHIFT;
411  }
412  else
413  {
414  break;
415  }
416 
417  if( !prefix.IsEmpty() )
418  key.Remove( 0, prefix.Len() );
419  }
420 
421  if( (key.length() == 1) && (key[0] > ' ') && (key[0] < 0x7F) )
422  {
423  keycode = key[0];
424  keycode += modifier;
425  return keycode;
426  }
427 
428  for( ii = 0; hotkeyNameList[ii].m_KeyCode != 0; ii++ )
429  {
430  if( key.CmpNoCase( hotkeyNameList[ii].m_Name ) == 0 )
431  {
432  keycode = hotkeyNameList[ii].m_KeyCode + modifier;
433  break;
434  }
435  }
436 
437  return keycode;
438 }
const wxChar * m_Name
#define MODIFIER_CTRL_BASE
#define GR_KB_ALT
Definition: common.h:65
#define GR_KB_SHIFT
Definition: common.h:66
#define MODIFIER_SHIFT
#define MODIFIER_ALT
#define MODIFIER_CMD_MAC
#define GR_KB_CTRL
Definition: common.h:64
static struct hotkey_name_descr hotkeyNameList[]
wxString KeyNameFromCommandId ( EDA_HOTKEY **  aList,
int  aCommandId 
)

Function KeyNameFromCommandId return the key name from the Command id value ( m_Idcommand member value)

Parameters
aList= pointer to a EDA_HOTKEY list of commands
aCommandId= Command Id value
Returns
the key name in a wxString

Definition at line 351 of file hotkeys_basic.cpp.

References KeyNameFromKeyCode(), EDA_HOTKEY::m_Idcommand, and EDA_HOTKEY::m_KeyCode.

Referenced by AddHotkeyName(), and EDA_HOTKEY_CLIENT_DATA::GetPosition().

352 {
353  wxString keyname;
354 
355  for( ; *aList != nullptr; aList++ )
356  {
357  EDA_HOTKEY* hk_decr = *aList;
358 
359  if( hk_decr->m_Idcommand == aCommandId )
360  {
361  keyname = KeyNameFromKeyCode( hk_decr->m_KeyCode );
362  break;
363  }
364  }
365 
366  return keyname;
367 }
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:59
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Function KeyNameFromKeyCode return the key name from the key code Only some wxWidgets key values are ...
wxString KeyNameFromKeyCode ( int  aKeycode,
bool *  aIsFound 
)

Function KeyNameFromKeyCode return the key name from the key code.

  • Only some wxWidgets key values are handled for function key ( see s_Hotkey_Name_List[] )
    Parameters
    aKeycode= key code (ascii value, or wxWidgets value for function keys)
    aIsFound= a pointer to a bool to return true if found, or false. an be NULL default)
    Returns
    the key name in a wxString
    Function KeyNameFromKeyCode return the key name from the key code.
Parameters
aKeycode= key code (ascii value, or wxWidgets value for function keys)
aIsFound= a pointer to a bool to return true if found, or false. an be nullptr default)
Returns
the key name in a wxString

Definition at line 165 of file hotkeys_basic.cpp.

References GR_KB_ALT, GR_KB_CTRL, GR_KB_SHIFT, EDA_HOTKEY::m_KeyCode, hotkey_name_descr::m_Name, MODIFIER_ALT, MODIFIER_CTRL, and MODIFIER_SHIFT.

Referenced by DisplayHotkeyList(), WIDGET_HOTKEY_LIST::EditItem(), EDA_HOTKEY_CLIENT_DATA::GetPosition(), KeyNameFromCommandId(), WIDGET_HOTKEY_LIST::ResolveKeyConflicts(), WIDGET_HOTKEY_LIST::UpdateFromClientData(), and EDA_BASE_FRAME::WriteHotkeyConfig().

166 {
167  wxString keyname, modifier, fullkeyname;
168  int ii;
169  bool found = false;
170 
171  // Assume keycode of 0 is "unassigned"
172  if( aKeycode == 0 )
173  return wxT( "<unassigned>");
174 
175  if( (aKeycode & GR_KB_CTRL) != 0 )
176  modifier << MODIFIER_CTRL;
177 
178  if( (aKeycode & GR_KB_ALT) != 0 )
179  modifier << MODIFIER_ALT;
180 
181  if( (aKeycode & GR_KB_SHIFT) != 0 )
182  modifier << MODIFIER_SHIFT;
183 
184  aKeycode &= ~( GR_KB_CTRL | GR_KB_ALT | GR_KB_SHIFT );
185 
186  if( (aKeycode > ' ') && (aKeycode < 0x7F ) )
187  {
188  found = true;
189  keyname.Append( (wxChar)aKeycode );
190  }
191  else
192  {
193  for( ii = 0; ; ii++ )
194  {
195  if( hotkeyNameList[ii].m_KeyCode == 0 ) // End of list
196  {
197  keyname = wxT( "<unknown>" );
198  break;
199  }
200 
201  if( hotkeyNameList[ii].m_KeyCode == aKeycode )
202  {
203  keyname = hotkeyNameList[ii].m_Name;
204  found = true;
205  break;
206  }
207  }
208  }
209 
210  if( aIsFound )
211  *aIsFound = found;
212 
213  fullkeyname = modifier + keyname;
214  return fullkeyname;
215 }
const wxChar * m_Name
#define GR_KB_ALT
Definition: common.h:65
#define MODIFIER_CTRL
#define GR_KB_SHIFT
Definition: common.h:66
#define MODIFIER_SHIFT
#define MODIFIER_ALT
#define GR_KB_CTRL
Definition: common.h:64
static struct hotkey_name_descr hotkeyNameList[]
void ParseHotkeyConfig ( const wxString &  data,
struct EDA_HOTKEY_CONFIG aDescList,
const wxString &  aAppname 
)

Function ParseHotkeyConfig Translates hotkey string data into application hotkeys.

Parameters
dataThe string of data read from the configuration files
aDescListThe list of hotkeys to update
aAppnameThe application interface requesting hotkey updates or empty for all

Definition at line 667 of file hotkeys_basic.cpp.

References FOOTPRINT_EDIT_FRAME_NAME, KeyCodeFromKeyName(), LIB_EDIT_FRAME_NAME, EDA_HOTKEY_CONFIG::m_HK_InfoList, EDA_HOTKEY::m_InfoMsg, EDA_HOTKEY::m_KeyCode, EDA_HOTKEY_CONFIG::m_SectionTag, PCB_EDIT_FRAME_NAME, and SCH_EDIT_FRAME_NAME.

Referenced by ReadHotkeyConfigFile().

670 {
671  // Read the config
672  wxStringTokenizer tokenizer( data, L"\r\n", wxTOKEN_STRTOK );
673  EDA_HOTKEY** CurrentHotkeyList = nullptr;
674 
675  while( tokenizer.HasMoreTokens() )
676  {
677  wxString line = tokenizer.GetNextToken();
678  wxStringTokenizer lineTokenizer( line );
679 
680  wxString line_type = lineTokenizer.GetNextToken();
681 
682  if( line_type[0] == '#' ) //comment
683  continue;
684 
685  if( line_type[0] == '[' ) // A tag is found. search infos in list
686  {
687  CurrentHotkeyList = nullptr;
688  EDA_HOTKEY_CONFIG* DList = aDescList;
689 
690  for( ; DList->m_HK_InfoList; DList++ )
691  {
692  if( *DList->m_SectionTag == line_type )
693  {
694  CurrentHotkeyList = DList->m_HK_InfoList;
695  break;
696  }
697  }
698 
699  continue;
700  }
701 
702  // Do not accept hotkey assignments from hotkey files that don't match the application
703  if( aAppname == LIB_EDIT_FRAME_NAME && line_type == wxT( "[eeschema]" ) )
704  CurrentHotkeyList = nullptr;
705 
706  if( aAppname == SCH_EDIT_FRAME_NAME && line_type == wxT( "[libedit]" ) )
707  CurrentHotkeyList = nullptr;
708 
709  if( aAppname == PCB_EDIT_FRAME_NAME && line_type == wxT( "[footprinteditor]" ) )
710  CurrentHotkeyList = nullptr;
711 
712  if( aAppname == FOOTPRINT_EDIT_FRAME_NAME && line_type == wxT( "[pcbnew]" ) )
713  CurrentHotkeyList = nullptr;
714 
715  if( line_type == wxT( "$Endlist" ) )
716  break;
717 
718  if( line_type != wxT( "shortcut" ) )
719  continue;
720 
721  if( CurrentHotkeyList == nullptr )
722  continue;
723 
724  // Get the key name
725  lineTokenizer.SetString( lineTokenizer.GetString(), L"\"\r\n\t ", wxTOKEN_STRTOK );
726  wxString keyname = lineTokenizer.GetNextToken();
727 
728  wxString remainder = lineTokenizer.GetString();
729 
730  // Get the command name
731  wxString fctname = remainder.AfterFirst( '\"' ).BeforeFirst( '\"' );
732 
733  // search the hotkey in current hotkey list
734  for( EDA_HOTKEY** list = CurrentHotkeyList; *list != nullptr; list++ )
735  {
736  EDA_HOTKEY* hk_decr = *list;
737 
738  if( hk_decr->m_InfoMsg == fctname )
739  {
740  hk_decr->m_KeyCode = KeyCodeFromKeyName( keyname );
741  break;
742  }
743  }
744  }
745 }
#define LIB_EDIT_FRAME_NAME
Definition: draw_frame.h:49
Structure EDA_HOTKEY_CONFIG contains the information required to save hot key information to a config...
Definition: hotkeys_basic.h:89
EDA_HOTKEY ** m_HK_InfoList
Definition: hotkeys_basic.h:93
#define PCB_EDIT_FRAME_NAME
Definition: draw_frame.h:56
#define SCH_EDIT_FRAME_NAME
Definition: draw_frame.h:50
#define FOOTPRINT_EDIT_FRAME_NAME
Definition: draw_frame.h:53
int KeyCodeFromKeyName(const wxString &keyname)
Function KeyCodeFromKeyName return the key code from its key name Only some wxWidgets key values are ...
wxString * m_SectionTag
Definition: hotkeys_basic.h:92
wxString m_InfoMsg
Definition: hotkeys_basic.h:66
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:59
int ReadHotkeyConfig ( const wxString &  aAppname,
struct EDA_HOTKEY_CONFIG aDescList 
)

Function ReadHotkeyConfig Read configuration data and fill the current hotkey list with hotkeys.

Parameters
aAppname= the value of the app's m_FrameName
aDescList= current hotkey list descr. to initialize.

Definition at line 642 of file hotkeys_basic.cpp.

References EESCHEMA_HOTKEY_NAME, FOOTPRINT_EDIT_FRAME_NAME, LIB_EDIT_FRAME_NAME, PCB_EDIT_FRAME_NAME, PCBNEW_HOTKEY_NAME, ReadHotkeyConfigFile(), and SCH_EDIT_FRAME_NAME.

Referenced by SCH_EDIT_FRAME::LoadSettings(), LIB_EDIT_FRAME::LoadSettings(), PGE::IFACE::OnKifaceStart(), GERBV::IFACE::OnKifaceStart(), SCH::IFACE::OnKifaceStart(), PCB::IFACE::OnKifaceStart(), and PGM_KICAD::OnPgmInit().

643 {
644  // For Eeschema and Pcbnew frames, we try twice.
645  // The first time, we try to read the new combined file. If it doesn't exist,
646  // we fall back to reading the old, frame-based file
647  if( aAppname == LIB_EDIT_FRAME_NAME || aAppname == SCH_EDIT_FRAME_NAME )
648  {
649  if( ReadHotkeyConfigFile( EESCHEMA_HOTKEY_NAME, aDescList ) )
650  return 1;
651  }
652  else if( aAppname == PCB_EDIT_FRAME_NAME || aAppname == FOOTPRINT_EDIT_FRAME_NAME )
653  {
654  if( ReadHotkeyConfigFile( PCBNEW_HOTKEY_NAME, aDescList ) )
655  return 1;
656  }
657 
658  return ReadHotkeyConfigFile( aAppname, aDescList );
659 }
#define LIB_EDIT_FRAME_NAME
Definition: draw_frame.h:49
int ReadHotkeyConfigFile(const wxString &aFilename, struct EDA_HOTKEY_CONFIG *aDescList, const bool aDefaultLocation)
Function ReadHotkeyConfig Read hotkey configuration for a given app, possibly before the frame for th...
#define PCB_EDIT_FRAME_NAME
Definition: draw_frame.h:56
#define SCH_EDIT_FRAME_NAME
Definition: draw_frame.h:50
#define FOOTPRINT_EDIT_FRAME_NAME
Definition: draw_frame.h:53
#define EESCHEMA_HOTKEY_NAME
Definition: hotkeys_basic.h:35
#define PCBNEW_HOTKEY_NAME
Definition: hotkeys_basic.h:36
int ReadHotkeyConfigFile ( const wxString &  aFilename,
struct EDA_HOTKEY_CONFIG aDescList,
const bool  aDefaultLocation = true 
)

Function ReadHotkeyConfig Read hotkey configuration for a given app, possibly before the frame for that app has been created.

Parameters
aFilename= the filename to save the hotkeys as
aDescList= the hotkey data
aDefaultLocation= if true, add hotkey path and extension to aFilename
Returns
1 on success, 0 on failure

Definition at line 601 of file hotkeys_basic.cpp.

References DEFAULT_HOTKEY_FILENAME_EXT, GetKicadConfigPath(), and ParseHotkeyConfig().

Referenced by EDA_BASE_FRAME::ImportHotkeyConfigFromFile(), and ReadHotkeyConfig().

603 {
604  wxFileName fn( aFilename );
605 
606  if( aDefaultLocation )
607  {
608  fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
609  fn.SetPath( GetKicadConfigPath() );
610  }
611 
612  if( !wxFile::Exists( fn.GetFullPath() ) )
613  return 0;
614 
615  wxFile cfgfile( fn.GetFullPath() );
616  if( !cfgfile.IsOpened() ) // There is a problem to open file
617  return 0;
618 
619  // get length
620  cfgfile.SeekEnd();
621  wxFileOffset size = cfgfile.Tell();
622  cfgfile.Seek( 0 );
623 
624  // read data
625  std::vector<char> buffer( size );
626  cfgfile.Read( buffer.data(), size );
627  wxString data( buffer.data(), wxConvUTF8 );
628 
629  // Is this the wxConfig format? If so, remove "Keys=" and parse the newlines.
630  if( data.StartsWith( wxT("Keys="), &data ) )
631  data.Replace( "\\n", "\n", true );
632 
633  // parse
634  ParseHotkeyConfig( data, aDescList, aFilename );
635 
636  // cleanup
637  cfgfile.Close();
638  return 1;
639 }
wxString GetKicadConfigPath()
Return the user configuration path used to store KiCad&#39;s configuration files.
Definition: common.cpp:211
void ParseHotkeyConfig(const wxString &data, struct EDA_HOTKEY_CONFIG *aDescList, const wxString &aAppname)
Function ParseHotkeyConfig Translates hotkey string data into application hotkeys.
#define DEFAULT_HOTKEY_FILENAME_EXT
Definition: hotkeys_basic.h:34

Variable Documentation

wxString g_CommonSectionTag