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 261 of file hotkeys_basic.h.

261  {
262  HK_NOT_FOUND = 0,
263  HK_NEW,
264  HK_OPEN,
265  HK_SAVE,
266  HK_SAVEAS,
267  HK_PRINT,
268  HK_UNDO,
269  HK_REDO,
270  HK_EDIT_CUT,
271  HK_EDIT_COPY,
276  HK_HELP,
277  HK_ZOOM_IN,
278  HK_ZOOM_OUT,
281  HK_ZOOM_AUTO,
286 };

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 169 of file hotkeys_basic.h.

Function Documentation

void AddHotkeyConfigMenu ( wxMenu *  menu)
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 251 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(), SCH_EDIT_FRAME::OnRightClick(), LIB_EDIT_FRAME::OnRightClick(), PCB_EDIT_FRAME::OnRightClick(), prepareEditMenu(), prepareFilesMenu(), prepareHelpMenu(), prepareInspectMenu(), preparePlaceMenu(), preparePreferencesMenu(), prepareRouteMenu(), prepareToolsMenu(), prepareViewMenu(), LIB_VIEW_FRAME::ReCreateHToolbar(), PL_EDITOR_FRAME::ReCreateHToolbar(), FOOTPRINT_EDIT_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().

253 {
254  wxString msg = aText;
255  wxString keyname;
256 
257  if( aList )
258  keyname = KeyNameFromCommandId( aList, aCommandId );
259 
260  if( !keyname.IsEmpty() )
261  {
262  switch( aShortCutType )
263  {
264  case IS_HOTKEY:
265  msg << wxT( "\t" ) << keyname;
266  break;
267 
268  case IS_ACCELERATOR:
269  AddModifierToKey( msg, keyname );
270  break;
271 
272  case IS_COMMENT:
273  msg << wxT( " (" ) << keyname << wxT( ")" );
274  break;
275  }
276  }
277 
278 #ifdef USING_MAC_CMD
279  // On OSX, the modifier equivalent to the Ctrl key of PCs
280  // is the Cmd key, but in code we should use Ctrl as prefix in menus
281  msg.Replace( MODIFIER_CMD_MAC, MODIFIER_CTRL_BASE );
282 #endif
283 
284  return msg;
285 }
#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 298 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.

302 {
303  wxString msg = aText;
304  wxString keyname;
305  EDA_HOTKEY** list;
306 
307  if( aDescList )
308  {
309  for( ; aDescList->m_HK_InfoList != nullptr; aDescList++ )
310  {
311  list = aDescList->m_HK_InfoList;
312  keyname = KeyNameFromCommandId( list, aCommandId );
313 
314  if( !keyname.IsEmpty() )
315  {
316  switch( aShortCutType )
317  {
318  case IS_HOTKEY:
319  msg << wxT( "\t" ) << keyname;
320  break;
321 
322  case IS_ACCELERATOR:
323  AddModifierToKey( msg, keyname );
324  break;
325 
326  case IS_COMMENT:
327  msg << wxT( " (" ) << keyname << wxT( ")" );
328  break;
329  }
330 
331  break;
332  }
333  }
334  }
335 
336 #ifdef USING_MAC_CMD
337  // On OSX, the modifier equivalent to the Ctrl key of PCs
338  // is the Cmd key, but in code we should use Ctrl as prefix in menus
339  msg.Replace( MODIFIER_CMD_MAC, MODIFIER_CTRL_BASE );
340 #endif
341 
342  return msg;
343 }
#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
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 475 of file hotkeys_basic.cpp.

References EDA_HOTKEY::m_Idcommand.

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

476 {
477  for( ; *aList != nullptr; aList++ )
478  {
479  EDA_HOTKEY* hk_decr = *aList;
480 
481  if( hk_decr->m_Idcommand == aCommand )
482  return hk_decr;
483  }
484 
485  return nullptr;
486 }
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 461 of file hotkeys_basic.cpp.

References EDA_HOTKEY::m_KeyCode.

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

462 {
463  for( ; *aList != nullptr; aList++ )
464  {
465  EDA_HOTKEY* hk_decr = *aList;
466 
467  if( hk_decr->m_KeyCode == aKey )
468  return hk_decr;
469  }
470 
471  return nullptr;
472 }
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 380 of file hotkeys_basic.cpp.

References GR_KB_ALT, GR_KB_CTRL, GR_KB_SHIFT, KEY_NON_FOUND, 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().

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

354 {
355  wxString keyname;
356 
357  for( ; *aList != nullptr; aList++ )
358  {
359  EDA_HOTKEY* hk_decr = *aList;
360 
361  if( hk_decr->m_Idcommand == aCommandId )
362  {
363  keyname = KeyNameFromKeyCode( hk_decr->m_KeyCode );
364  break;
365  }
366  }
367 
368  return keyname;
369 }
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 170 of file hotkeys_basic.cpp.

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

Referenced by WIDGET_HOTKEY_LIST::changeHotkey(), HOTKEY_FILTER::FilterMatches(), EDA_HOTKEY_CLIENT_DATA::GetPosition(), KeyNameFromCommandId(), WIDGET_HOTKEY_LIST::ResolveKeyConflicts(), DIALOG_SET_GRID::TransferDataToWindow(), WIDGET_HOTKEY_LIST::UpdateFromClientData(), and EDA_BASE_FRAME::WriteHotkeyConfig().

171 {
172  wxString keyname, modifier, fullkeyname;
173  int ii;
174  bool found = false;
175 
176  // Assume keycode of 0 is "unassigned"
177  if( (aKeycode & GR_KB_CTRL) != 0 )
178  modifier << MODIFIER_CTRL;
179 
180  if( (aKeycode & GR_KB_ALT) != 0 )
181  modifier << MODIFIER_ALT;
182 
183  if( (aKeycode & GR_KB_SHIFT) != 0 )
184  modifier << MODIFIER_SHIFT;
185 
186  aKeycode &= ~( GR_KB_CTRL | GR_KB_ALT | GR_KB_SHIFT );
187 
188  if( (aKeycode > ' ') && (aKeycode < 0x7F ) )
189  {
190  found = true;
191  keyname.Append( (wxChar)aKeycode );
192  }
193  else
194  {
195  for( ii = 0; ; ii++ )
196  {
197  if( hotkeyNameList[ii].m_KeyCode == KEY_NON_FOUND ) // End of list
198  {
199  keyname = wxT( "<unknown>" );
200  break;
201  }
202 
203  if( hotkeyNameList[ii].m_KeyCode == aKeycode )
204  {
205  keyname = hotkeyNameList[ii].m_Name;
206  found = true;
207  break;
208  }
209  }
210  }
211 
212  if( aIsFound )
213  *aIsFound = found;
214 
215  fullkeyname = modifier + keyname;
216  return fullkeyname;
217 }
#define GR_KB_ALT
const wxChar * m_Name
#define KEY_NON_FOUND
#define GR_KB_CTRL
#define MODIFIER_CTRL
#define MODIFIER_SHIFT
#define GR_KB_SHIFT
#define MODIFIER_ALT
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 624 of file hotkeys_basic.cpp.

References FOOTPRINT_EDIT_FRAME_NAME, KEY_NON_FOUND, 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().

627 {
628  // Read the config
629  wxStringTokenizer tokenizer( data, L"\r\n", wxTOKEN_STRTOK );
630  EDA_HOTKEY** CurrentHotkeyList = nullptr;
631 
632  while( tokenizer.HasMoreTokens() )
633  {
634  wxString line = tokenizer.GetNextToken();
635  wxStringTokenizer lineTokenizer( line );
636 
637  wxString line_type = lineTokenizer.GetNextToken();
638 
639  if( line_type[0] == '#' ) //comment
640  continue;
641 
642  if( line_type[0] == '[' ) // A tag is found. search infos in list
643  {
644  CurrentHotkeyList = nullptr;
645  EDA_HOTKEY_CONFIG* DList = aDescList;
646 
647  for( ; DList->m_HK_InfoList; DList++ )
648  {
649  if( *DList->m_SectionTag == line_type )
650  {
651  CurrentHotkeyList = DList->m_HK_InfoList;
652  break;
653  }
654  }
655 
656  continue;
657  }
658 
659  // Do not accept hotkey assignments from hotkey files that don't match the application
660  if( aAppname == LIB_EDIT_FRAME_NAME && line_type == wxT( "[eeschema]" ) )
661  CurrentHotkeyList = nullptr;
662 
663  if( aAppname == SCH_EDIT_FRAME_NAME && line_type == wxT( "[libedit]" ) )
664  CurrentHotkeyList = nullptr;
665 
666  if( aAppname == PCB_EDIT_FRAME_NAME && line_type == wxT( "[footprinteditor]" ) )
667  CurrentHotkeyList = nullptr;
668 
669  if( aAppname == FOOTPRINT_EDIT_FRAME_NAME && line_type == wxT( "[pcbnew]" ) )
670  CurrentHotkeyList = nullptr;
671 
672  if( line_type == wxT( "$Endlist" ) )
673  break;
674 
675  if( line_type != wxT( "shortcut" ) )
676  continue;
677 
678  if( CurrentHotkeyList == nullptr )
679  continue;
680 
681  // Get the key name
682  lineTokenizer.SetString( lineTokenizer.GetString(), L"\"\r\n\t ", wxTOKEN_STRTOK );
683  wxString keyname = lineTokenizer.GetNextToken();
684 
685  wxString remainder = lineTokenizer.GetString();
686 
687  // Get the command name
688  wxString fctname = remainder.AfterFirst( '\"' ).BeforeFirst( '\"' );
689 
690  // search the hotkey in current hotkey list
691  for( EDA_HOTKEY** list = CurrentHotkeyList; *list != nullptr; list++ )
692  {
693  EDA_HOTKEY* hk_decr = *list;
694 
695  if( hk_decr->m_InfoMsg == fctname )
696  {
697  int keycode = KeyCodeFromKeyName( keyname );
698 
699  if( keycode != KEY_NON_FOUND ) // means the key name is found in list or unassigned
700  hk_decr->m_KeyCode = keycode;
701 
702  break;
703  }
704  }
705  }
706 }
#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:94
#define KEY_NON_FOUND
EDA_HOTKEY ** m_HK_InfoList
Definition: hotkeys_basic.h:98
#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:97
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 602 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().

603 {
604  // For Eeschema and Pcbnew frames, we read the new combined file.
605  // For other kifaces, we read the frame-based file
606  if( aAppname == LIB_EDIT_FRAME_NAME || aAppname == SCH_EDIT_FRAME_NAME )
607  {
608  return ReadHotkeyConfigFile( EESCHEMA_HOTKEY_NAME, aDescList );
609  }
610  else if( aAppname == PCB_EDIT_FRAME_NAME || aAppname == FOOTPRINT_EDIT_FRAME_NAME )
611  {
612  return ReadHotkeyConfigFile( PCBNEW_HOTKEY_NAME, aDescList );
613  }
614 
615  return ReadHotkeyConfigFile( aAppname, aDescList );
616 }
#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 561 of file hotkeys_basic.cpp.

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

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

563 {
564  wxFileName fn( aFilename );
565 
566  if( aDefaultLocation )
567  {
568  fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
569  fn.SetPath( GetKicadConfigPath() );
570  }
571 
572  if( !wxFile::Exists( fn.GetFullPath() ) )
573  return 0;
574 
575  wxFile cfgfile( fn.GetFullPath() );
576  if( !cfgfile.IsOpened() ) // There is a problem to open file
577  return 0;
578 
579  // get length
580  cfgfile.SeekEnd();
581  wxFileOffset size = cfgfile.Tell();
582  cfgfile.Seek( 0 );
583 
584  // read data
585  std::vector<char> buffer( size );
586  cfgfile.Read( buffer.data(), size );
587  wxString data( buffer.data(), wxConvUTF8, size );
588 
589  // Is this the wxConfig format? If so, remove "Keys=" and parse the newlines.
590  if( data.StartsWith( wxT("Keys="), &data ) )
591  data.Replace( "\\n", "\n", true );
592 
593  // parse
594  ParseHotkeyConfig( data, aDescList, aFilename );
595 
596  // cleanup
597  cfgfile.Close();
598  return 1;
599 }
wxString GetKicadConfigPath()
Return the user configuration path used to store KiCad&#39;s configuration files.
Definition: common.cpp:263
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