KiCad PCB EDA Suite
hotkeys_basic.cpp File Reference

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

#include <fctsys.h>
#include <kiface_i.h>
#include <hotkeys_basic.h>
#include <id.h>
#include <confirm.h>
#include <kicad_string.h>
#include <gestfich.h>
#include <wxstruct.h>
#include <macros.h>
#include <dialog_hotkeys_editor.h>
#include <menus_helpers.h>
#include <tool/tool_manager.h>
#include <wx/apptrait.h>
#include <wx/stdpaths.h>
#include <wx/tokenzr.h>
#include <html_messagebox.h>

Go to the source code of this file.

Classes

struct  hotkey_name_descr
 

Macros

#define HOTKEYS_CONFIG_KEY   wxT( "Keys" )
 
#define MODIFIER_CTRL   wxT( "Ctrl+" )
 
#define MODIFIER_CMD_MAC   wxT( "Cmd+" )
 
#define MODIFIER_CTRL_BASE   wxT( "Ctrl+" )
 
#define MODIFIER_ALT   wxT( "Alt+" )
 
#define MODIFIER_SHIFT   wxT( "Shift+" )
 

Functions

wxString g_CommonSectionTag (wxT("[common]"))
 
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 hotkeyNameList[] ) More...
 
static void AddModifierToKey (wxString &aFullKey, const wxString &aKey)
 
wxString AddHotkeyName (const wxString &aText, EDA_HOTKEY **aList, int aCommandId, HOTKEY_ACTION_TYPE aShortCutType)
 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 *aDescList, int aCommandId, HOTKEY_ACTION_TYPE aShortCutType)
 Function AddHotkeyName Add the key name from the Command id value ( m_Idcommand member value) 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...
 
void DisplayHotkeyList (EDA_BASE_FRAME *aFrame, struct EDA_HOTKEY_CONFIG *aDescList)
 Function DisplayHotkeyList Displays the current hotkey list. More...
 
EDA_HOTKEYGetDescriptorFromHotkey (int aKey, EDA_HOTKEY **aList)
 Function GetDescriptorFromHotkey Return 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...
 
void ReadHotkeyConfig (const wxString &Appname, struct EDA_HOTKEY_CONFIG *aDescList)
 Function ReadHotkeyConfig Read hotkey configuration for a given app, possibly before the frame for that app has been created. More...
 
void ParseHotkeyConfig (const wxString &data, struct EDA_HOTKEY_CONFIG *aDescList)
 
void AddHotkeyConfigMenu (wxMenu *aMenu)
 

Variables

static struct hotkey_name_descr hotkeyNameList []
 

Detailed Description

Some functions to handle hotkeys in KiCad.

Definition in file hotkeys_basic.cpp.

Macro Definition Documentation

#define HOTKEYS_CONFIG_KEY   wxT( "Keys" )

Definition at line 48 of file hotkeys_basic.cpp.

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

#define MODIFIER_ALT   wxT( "Alt+" )

Definition at line 151 of file hotkeys_basic.cpp.

Referenced by AddModifierToKey(), KeyCodeFromKeyName(), and KeyNameFromKeyCode().

#define MODIFIER_CMD_MAC   wxT( "Cmd+" )

Definition at line 149 of file hotkeys_basic.cpp.

Referenced by AddHotkeyName(), and KeyCodeFromKeyName().

#define MODIFIER_CTRL   wxT( "Ctrl+" )

Definition at line 147 of file hotkeys_basic.cpp.

Referenced by KeyNameFromKeyCode().

#define MODIFIER_CTRL_BASE   wxT( "Ctrl+" )

Definition at line 150 of file hotkeys_basic.cpp.

Referenced by AddHotkeyName(), and KeyCodeFromKeyName().

#define MODIFIER_SHIFT   wxT( "Shift+" )

Definition at line 152 of file hotkeys_basic.cpp.

Referenced by AddModifierToKey(), KeyCodeFromKeyName(), and KeyNameFromKeyCode().

Function Documentation

void AddHotkeyConfigMenu ( wxMenu *  aMenu)

Definition at line 801 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 preparePreferencesMenu(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), KICAD_MANAGER_FRAME::ReCreateMenuBar(), and GERBVIEW_FRAME::ReCreateMenuBar().

802 {
803  if( aMenu == NULL )
804  return;
805 
806  wxMenu* HotkeySubmenu = new wxMenu();
807 
808  // Call hotkeys editor
810  _( "&Edit Hotkeys" ),
811  _( "Call the hotkeys editor" ),
812  KiBitmap( editor_xpm ) );
813 
814  HotkeySubmenu->AppendSeparator();
815 
816  // create hotkey file to export current hotkeys config
818  _( "E&xport Hotkeys" ),
819  _( "Create a hotkey configuration file to export the current hotkeys" ),
820  KiBitmap( save_setup_xpm ) );
821 
822  // Reload hotkey file
824  _( "&Import Hotkeys" ),
825  _( "Load an existing hotkey configuration file" ),
826  KiBitmap( reload_xpm ) );
827 
828  // Append HotkeySubmenu to menu
829  AddMenuItem( aMenu, HotkeySubmenu,
830  wxID_ANY, _( "&Hotkeys" ),
831  _( "Hotkeys configuration and preferences" ),
832  KiBitmap( hotkeys_xpm ) );
833 }
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:55
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
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 248 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(), 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(), PL_EDITOR_FRAME::OnRightClick(), LIB_EDIT_FRAME::OnRightClick(), SCH_EDIT_FRAME::OnRightClick(), PCB_EDIT_FRAME::OnRightClick(), prepareEditMenu(), prepareFilesMenu(), preparePlaceMenu(), prepareToolsMenu(), prepareViewMenu(), LIB_VIEW_FRAME::ReCreateHToolbar(), FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateHToolbar(), PL_EDITOR_FRAME::ReCreateHToolbar(), FOOTPRINT_WIZARD_FRAME::ReCreateHToolbar(), GERBVIEW_FRAME::ReCreateHToolbar(), LIB_EDIT_FRAME::ReCreateHToolbar(), SCH_EDIT_FRAME::ReCreateHToolbar(), PCB_EDIT_FRAME::ReCreateHToolbar(), LIB_VIEW_FRAME::ReCreateMenuBar(), FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), KICAD_MANAGER_FRAME::ReCreateMenuBar(), and PCB_LAYER_BOX_SELECTOR::Resync().

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

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

Definition at line 227 of file hotkeys_basic.cpp.

References MODIFIER_ALT, and MODIFIER_SHIFT.

Referenced by AddHotkeyName().

228 {
229  if( (aKey.Length() == 1) && (aKey[0] >= 'A') && (aKey[0] <= 'Z'))
230  // We can use Shift+<key> as accelerator and <key> for hot key
231  aFullKey << wxT( "\t" ) << MODIFIER_SHIFT << aKey;
232  else
233  // We must use Alt+<key> as accelerator and <key> for hot key
234  aFullKey << wxT( "\t" ) << MODIFIER_ALT << aKey;
235 }
#define MODIFIER_SHIFT
#define MODIFIER_ALT
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 449 of file hotkeys_basic.cpp.

References HTML_MESSAGE_BOX::AddHTML_Text(), DisplayHtmlInfoMessage(), KeyNameFromKeyCode(), EDA_HOTKEY_CONFIG::m_HK_InfoList, EDA_HOTKEY::m_InfoMsg, EDA_HOTKEY::m_KeyCode, 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(), LIB_EDIT_FRAME::OnHotKey(), SCH_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(), and PCBNEW_CONTROL::ShowHelp().

450 {
451  wxString keyname;
452  wxString keymessage;
453  EDA_HOTKEY** list;
454 
455  wxString msg = wxT( "<html><body bgcolor=\"#E2E2E2\">" );
456 
457  msg += wxT( "<H3>" );
458  msg += _( "Hotkeys List" );
459  msg += wxT( "</H3> <table cellpadding=\"0\">" );
460 
461  for( ; aDescList->m_HK_InfoList != NULL; aDescList++ )
462  {
463  list = aDescList->m_HK_InfoList;
464 
465  for( ; *list != NULL; list++ )
466  {
467  EDA_HOTKEY* hk_decr = *list;
468 
469  if( !hk_decr->m_InfoMsg.Contains( wxT( "Macros" ) ) )
470  {
471  keyname = KeyNameFromKeyCode( hk_decr->m_KeyCode );
472  keymessage = wxGetTranslation( hk_decr->m_InfoMsg );
473 
474  // Some chars are modified, using html encoding, to be
475  // displayed by DisplayHtmlInfoMessage()
476  keyname.Replace( wxT( "<" ), wxT( "&lt;" ) );
477  keyname.Replace( wxT( ">" ), wxT( "&gt;" ) );
478  msg += wxT( "<tr><td>" ) + keymessage + wxT( "</td>" );
479  msg += wxT( "<td><b>&nbsp;&nbsp;" ) + keyname + wxT( "</b></td></tr>" );
480  }
481  }
482  }
483 
484  msg += wxT( "</table></html></body>" );
485 
486 #if 0 // Set to 1 to create a modal dialog (blocking)
487  DisplayHtmlInfoMessage( aFrame, _( "Hotkeys List" ), msg, wxSize( 340, 750 ) );
488 #else
489  // Create a non modal dialog, which shows the list of hotkeys until dismissed
490  // but does not block the parent window
491  HTML_MESSAGE_BOX *dlg = new HTML_MESSAGE_BOX( aFrame, _( "Hotkeys List" ),
492  wxDefaultPosition, wxSize( 340, 750 ) );
493  dlg->AddHTML_Text( msg );
494  dlg->Show( true );
495 #endif
496 }
EDA_HOTKEY ** m_HK_InfoList
Definition: hotkeys_basic.h:91
Class HTML_MESSAGE_BOX.
bool Show(bool show) override
wxString m_InfoMsg
Definition: hotkeys_basic.h:64
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:57
void DisplayHtmlInfoMessage(wxWindow *parent, const wxString &title, const wxString &text, const wxSize &size)
Function DisplayHtmlInforMessage displays aMessage in HTML format.
Definition: confirm.cpp:101
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 ...
wxString g_CommonSectionTag ( wxT("[common]")  )
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 520 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(), LIB_EDIT_FRAME::GetHotKeyDescription(), SCH_EDIT_FRAME::GetHotKeyDescription(), PCB_EDIT_FRAME::GetHotKeyDescription(), and GERBVIEW_FRAME::GetHotKeyDescription().

521 {
522  for( ; *aList != NULL; aList++ )
523  {
524  EDA_HOTKEY* hk_decr = *aList;
525 
526  if( hk_decr->m_Idcommand == aCommand )
527  return hk_decr;
528  }
529 
530  return NULL;
531 }
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:57
EDA_HOTKEY* GetDescriptorFromHotkey ( int  aKey,
EDA_HOTKEY **  aList 
)

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

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 506 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(), LIB_EDIT_FRAME::OnHotKey(), SCH_EDIT_FRAME::OnHotKey(), PCB_EDIT_FRAME::OnHotKey(), and GERBVIEW_FRAME::OnHotKey().

507 {
508  for( ; *aList != NULL; aList++ )
509  {
510  EDA_HOTKEY* hk_decr = *aList;
511 
512  if( hk_decr->m_KeyCode == aKey )
513  return hk_decr;
514  }
515 
516  return NULL;
517 }
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:57
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 hotkeyNameList[], like F2 or space or an usual (ascii) char.
Returns
the key code

Definition at line 377 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 ParseHotkeyConfig().

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

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

Referenced by AddHotkeyName().

351 {
352  wxString keyname;
353 
354  for( ; *aList != NULL; aList++ )
355  {
356  EDA_HOTKEY* hk_decr = *aList;
357 
358  if( hk_decr->m_Idcommand == aCommandId )
359  {
360  keyname = KeyNameFromKeyCode( hk_decr->m_KeyCode );
361  break;
362  }
363  }
364 
365  return keyname;
366 }
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:57
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 hotkeyNameList[] )

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 NULL default)
Returns
the key name in a wxString

Definition at line 164 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_CTRL, and MODIFIER_SHIFT.

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

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

Definition at line 670 of file hotkeys_basic.cpp.

References KeyCodeFromKeyName(), EDA_HOTKEY_CONFIG::m_HK_InfoList, EDA_HOTKEY::m_InfoMsg, EDA_HOTKEY::m_KeyCode, and EDA_HOTKEY_CONFIG::m_SectionTag.

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

672 {
673  // Read the config
674  wxStringTokenizer tokenizer( data, L"\r\n", wxTOKEN_STRTOK );
675  EDA_HOTKEY** CurrentHotkeyList = 0;
676 
677  while( tokenizer.HasMoreTokens() )
678  {
679  wxString line = tokenizer.GetNextToken();
680  wxStringTokenizer lineTokenizer( line );
681 
682  wxString line_type = lineTokenizer.GetNextToken();
683 
684  if( line_type[0] == '#' ) //comment
685  continue;
686 
687  if( line_type[0] == '[' ) // A tag is found. search infos in list
688  {
689  CurrentHotkeyList = 0;
690  EDA_HOTKEY_CONFIG* DList = aDescList;
691 
692  for( ; DList->m_HK_InfoList; DList++ )
693  {
694  if( *DList->m_SectionTag == line_type )
695  {
696  CurrentHotkeyList = DList->m_HK_InfoList;
697  break;
698  }
699  }
700 
701  continue;
702  }
703 
704  if( line_type == wxT( "$Endlist" ) )
705  break;
706 
707  if( line_type != wxT( "shortcut" ) )
708  continue;
709 
710  if( CurrentHotkeyList == NULL )
711  continue;
712 
713  // Get the key name
714  lineTokenizer.SetString( lineTokenizer.GetString(), L"\"\r\n\t ", wxTOKEN_STRTOK );
715  wxString keyname = lineTokenizer.GetNextToken();
716 
717  wxString remainder = lineTokenizer.GetString();
718 
719  // Get the command name
720  wxString fctname = remainder.AfterFirst( '\"' ).BeforeFirst( '\"' );
721 
722  // search the hotkey in current hotkey list
723  for( EDA_HOTKEY** list = CurrentHotkeyList; *list != NULL; list++ )
724  {
725  EDA_HOTKEY* hk_decr = *list;
726 
727  if( hk_decr->m_InfoMsg == fctname )
728  {
729  hk_decr->m_KeyCode = KeyCodeFromKeyName( keyname );
730  break;
731  }
732  }
733  }
734 }
Structure EDA_HOTKEY_CONFIG contains the information required to save hot key information to a config...
Definition: hotkeys_basic.h:87
EDA_HOTKEY ** m_HK_InfoList
Definition: hotkeys_basic.h:91
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:90
wxString m_InfoMsg
Definition: hotkeys_basic.h:64
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:57
void ReadHotkeyConfig ( const wxString &  Appname,
struct EDA_HOTKEY_CONFIG aDescList 
)

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

Parameters
Appname= the value of the app's m_FrameName
aDescList= the hotkey data

Definition at line 633 of file hotkeys_basic.cpp.

References DEFAULT_HOTKEY_FILENAME_EXT, GetNewConfig(), HOTKEYS_CONFIG_KEY, and ParseHotkeyConfig().

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

634 {
635  wxFileName fn( Appname );
636  fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
637 
638  std::unique_ptr<wxConfigBase> config;
639  config.reset( GetNewConfig( fn.GetFullPath() ) );
640 
641  if( !config->HasEntry( HOTKEYS_CONFIG_KEY ) )
642  {
643  // assume defaults are ok
644  return;
645  }
646 
647  wxString data;
648  config->Read( HOTKEYS_CONFIG_KEY, &data );
649 
650  ParseHotkeyConfig( data, aDescList );
651 }
void ParseHotkeyConfig(const wxString &data, struct EDA_HOTKEY_CONFIG *aDescList)
wxConfigBase * GetNewConfig(const wxString &aProgName)
Function GetNewConfig.
Definition: common.cpp:205
#define HOTKEYS_CONFIG_KEY
#define DEFAULT_HOTKEY_FILENAME_EXT
Definition: hotkeys_basic.h:34

Variable Documentation

struct hotkey_name_descr hotkeyNameList[]
static

Definition at line 96 of file hotkeys_basic.cpp.