KiCad PCB EDA Suite
hotkeys_basic.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2010-2011 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
31 #include <fctsys.h>
32 #include <kiface_i.h>
33 #include <hotkeys_basic.h>
34 #include <id.h>
35 #include <confirm.h>
36 #include <kicad_string.h>
37 #include <gestfich.h>
38 #include <eda_base_frame.h>
39 #include <macros.h>
40 #include <menus_helpers.h>
41 #include <draw_frame.h>
42 
43 #include <tool/tool_manager.h>
44 
46 
47 #include <wx/apptrait.h>
48 #include <wx/stdpaths.h>
49 #include <wx/tokenzr.h>
50 
51 #define HOTKEYS_CONFIG_KEY wxT( "Keys" )
52 
53 wxString g_CommonSectionTag( wxT( "[common]" ) );
54 
55 
56 /* Class to handle hotkey commands hotkeys have a default value
57  * This class allows the real key code changed by user from a key code list
58  * file.
59  */
60 
61 EDA_HOTKEY::EDA_HOTKEY( const wxChar* infomsg, int idcommand, int keycode, int idmenuevent ) :
62  m_defaultKeyCode( keycode ), m_KeyCode( keycode ), m_InfoMsg( infomsg ),
63  m_Idcommand( idcommand ), m_IdMenuEvent( idmenuevent )
64 {
65 }
66 
67 
69 {
70  m_defaultKeyCode = base->m_defaultKeyCode; // initialize default key code
71  m_KeyCode = base->m_KeyCode;
72  m_InfoMsg = base->m_InfoMsg;
73  m_Idcommand = base->m_Idcommand;
75 }
76 
77 
79 {
80 }
81 
82 
83 /* class to handle the printable name and the keycode
84  */
86 {
87  const wxChar* m_Name;
88  int m_KeyCode;
89 };
90 
91 /* table giving the hotkey name from the hotkey code, for special keys
92  * Note : when modifiers (ATL, SHIFT, CTRL) do not modify
93  * the code of the key, do need to enter the modified key code
94  * For instance wxT( "F1" ), WXK_F1 handle F1, AltF1, CtrlF1 ...
95  * Key names are:
96  * "Space","Ctrl+Space","Alt+Space" or
97  * "Alt+A","Ctrl+F1", ...
98  */
99 #define KEY_NON_FOUND -1
101 {
102  { wxT( "F1" ), WXK_F1 },
103  { wxT( "F2" ), WXK_F2 },
104  { wxT( "F3" ), WXK_F3 },
105  { wxT( "F4" ), WXK_F4 },
106  { wxT( "F5" ), WXK_F5 },
107  { wxT( "F6" ), WXK_F6 },
108  { wxT( "F7" ), WXK_F7 },
109  { wxT( "F8" ), WXK_F8 },
110  { wxT( "F9" ), WXK_F9 },
111  { wxT( "F10" ), WXK_F10 },
112  { wxT( "F11" ), WXK_F11 },
113  { wxT( "F12" ), WXK_F12 },
114 
115  { wxT( "Esc" ), WXK_ESCAPE },
116  { wxT( "Del" ), WXK_DELETE },
117  { wxT( "Tab" ), WXK_TAB },
118  { wxT( "Back" ), WXK_BACK },
119  { wxT( "Ins" ), WXK_INSERT },
120 
121  { wxT( "Home" ), WXK_HOME },
122  { wxT( "End" ), WXK_END },
123  { wxT( "PgUp" ), WXK_PAGEUP },
124  { wxT( "PgDn" ), WXK_PAGEDOWN },
125 
126  { wxT( "Up" ), WXK_UP },
127  { wxT( "Down" ), WXK_DOWN },
128  { wxT( "Left" ), WXK_LEFT },
129  { wxT( "Right" ), WXK_RIGHT },
130 
131  { wxT( "Return" ), WXK_RETURN },
132 
133  { wxT( "Space" ), WXK_SPACE },
134 
135  { wxT( "<unassigned>" ), 0 },
136 
137  // Do not change this line: end of list
138  { wxT( "" ), KEY_NON_FOUND }
139 };
140 
141 // name of modifier keys.
142 // Note: the Ctrl key is Cmd key on Mac OS X.
143 // However, in wxWidgets defs, the key WXK_CONTROL is the Cmd key,
144 // so the code using WXK_CONTROL should be ok on any system.
145 // (on Mac OS X the actual Ctrl key code is WXK_RAW_CONTROL)
146 #ifdef __WXMAC__
147 #define USING_MAC_CMD
148 #endif
149 
150 #ifdef USING_MAC_CMD
151 #define MODIFIER_CTRL wxT( "Cmd+" )
152 #else
153 #define MODIFIER_CTRL wxT( "Ctrl+" )
154 #endif
155 #define MODIFIER_CMD_MAC wxT( "Cmd+" )
156 #define MODIFIER_CTRL_BASE wxT( "Ctrl+" )
157 #define MODIFIER_ALT wxT( "Alt+" )
158 #define MODIFIER_SHIFT wxT( "Shift+" )
159 
160 
170 wxString KeyNameFromKeyCode( int aKeycode, bool* aIsFound )
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 }
218 
219 
220 /*
221  * helper function use in AddHotkeyName to calculate an accelerator string
222  * In some menus, accelerators do not perform exactly the same action as
223  * the hotkey that perform a similar action.
224  * this is usually the case when this action uses the current mouse position
225  * for instance zoom action is ran from the F1 key or the Zoom menu.
226  * a zoom uses the mouse position from a hot key and not from the menu
227  * In this case, the accelerator if Shift+<hotkey>
228  * But for many keys, the Shift modifier is not usable, and the accelerator is Alt+<hotkey>
229  */
230 static void AddModifierToKey( wxString& aFullKey, const wxString & aKey )
231 {
232  if( (aKey.Length() == 1) && (aKey[0] >= 'A') && (aKey[0] <= 'Z'))
233  // We can use Shift+<key> as accelerator and <key> for hot key
234  aFullKey << wxT( "\t" ) << MODIFIER_SHIFT << aKey;
235  else
236  // We must use Alt+<key> as accelerator and <key> for hot key
237  aFullKey << wxT( "\t" ) << MODIFIER_ALT << aKey;
238 }
239 
240 
241 /* AddHotkeyName
242  * Add the key name from the Command id value ( m_Idcommand member value)
243  * aText = a wxString. returns aText + key name
244  * aList = pointer to a EDA_HOTKEY list of commands
245  * aCommandId = Command Id value
246  * aShortCutType = IS_HOTKEY to add <tab><keyname> (shortcuts in menus, same as hotkeys)
247  * IS_ACCELERATOR to add <tab><Shift+keyname> (accelerators in menus, not hotkeys)
248  * IS_COMMENT to add <spaces><(keyname)> mainly in tool tips
249  * Return a wxString (aTest + key name) if key found or aText without modification
250  */
251 wxString AddHotkeyName( const wxString& aText, EDA_HOTKEY** aList,
252  int aCommandId, HOTKEY_ACTION_TYPE aShortCutType )
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 }
286 
287 
288 /* AddHotkeyName
289  * Add the key name from the Command id value ( m_Idcommand member value)
290  * aText = a wxString. returns aText + key name
291  * aList = pointer to a EDA_HOTKEY_CONFIG DescrList of commands
292  * aCommandId = Command Id value
293  * aShortCutType = IS_HOTKEY to add <tab><keyname> (active shortcuts in menus)
294  * IS_ACCELERATOR to add <tab><Shift+keyname> (active accelerators in menus)
295  * IS_COMMENT to add <spaces><(keyname)>
296  * Return a wxString (aText + key name) if key found or aText without modification
297  */
298 wxString AddHotkeyName( const wxString& aText,
299  struct EDA_HOTKEY_CONFIG* aDescList,
300  int aCommandId,
301  HOTKEY_ACTION_TYPE aShortCutType )
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 }
344 
345 
353 wxString KeyNameFromCommandId( EDA_HOTKEY** aList, int aCommandId )
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 }
370 
371 
380 int KeyCodeFromKeyName( const wxString& keyname )
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 }
441 
442 
443 /* DisplayHotkeyList
444  * Displays the current hotkey list
445  * aList = a EDA_HOTKEY_CONFIG list(Null terminated)
446  */
447 void DisplayHotkeyList( EDA_BASE_FRAME* aFrame, struct EDA_HOTKEY_CONFIG* aDescList )
448 {
449  DIALOG_LIST_HOTKEYS dlg( aFrame, aDescList );
450  dlg.ShowModal();
451 }
452 
453 
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 }
473 
474 
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 }
487 
488 
490  wxString* aFullFileName )
491 {
492  wxString msg;
493  wxString keyname, infokey;
494  FILE* file;
495 
496  msg = wxT( "$hotkey list\n" );
497 
498  // Print the current hotkey list
499  EDA_HOTKEY** list;
500 
501  for( ; aDescList->m_HK_InfoList != nullptr; aDescList++ )
502  {
503  if( aDescList->m_Title )
504  {
505  msg += wxT( "# " );
506  msg += *aDescList->m_Title;
507  msg += wxT( "\n" );
508  }
509 
510  msg += *aDescList->m_SectionTag;
511  msg += wxT( "\n" );
512 
513  list = aDescList->m_HK_InfoList;
514 
515  for( ; *list != nullptr; list++ )
516  {
517  EDA_HOTKEY* hk_decr = *list;
518  msg += wxT( "shortcut " );
519  keyname = KeyNameFromKeyCode( hk_decr->m_KeyCode );
520  AddDelimiterString( keyname );
521  infokey = hk_decr->m_InfoMsg;
522  AddDelimiterString( infokey );
523  msg += keyname + wxT( ": " ) + infokey + wxT( "\n" );
524  }
525  }
526 
527  msg += wxT( "$Endlist\n" );
528 
529  if( aFullFileName )
530  file = wxFopen( *aFullFileName, wxT( "wt" ) );
531  else
532  {
533  wxString configName( ConfigBaseName() );
534  if( configName == SCH_EDIT_FRAME_NAME || configName == LIB_EDIT_FRAME_NAME )
535  configName = EESCHEMA_HOTKEY_NAME;
536  else if( configName == PCB_EDIT_FRAME_NAME ||
537  configName == FOOTPRINT_EDIT_FRAME_NAME )
538  configName = PCBNEW_HOTKEY_NAME;
539 
540  wxFileName fn( configName );
541  fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
542  fn.SetPath( GetKicadConfigPath() );
543  file = wxFopen( fn.GetFullPath(), wxT( "wt" ) );
544  }
545 
546  if( file )
547  {
548  wxFputs( msg, file );
549  fclose( file );
550  }
551  else
552  {
553  msg.Printf( wxT( "Unable to write file %s" ), GetChars( *aFullFileName ) );
554  return 0;
555  }
556 
557  return 1;
558 }
559 
560 
561 int ReadHotkeyConfigFile( const wxString& aFilename, struct EDA_HOTKEY_CONFIG* aDescList,
562  const bool aDefaultLocation )
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 }
600 
601 
602 int ReadHotkeyConfig( const wxString& aAppname, struct EDA_HOTKEY_CONFIG* aDescList )
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 }
617 
618 
619 /* Function ParseHotkeyConfig
620  * the input format is: shortcut "key" "function"
621  * lines starting by # are ignored (comments)
622  * lines like [xxx] are tags (example: [common] or [libedit] which identify sections
623  */
624 void ParseHotkeyConfig( const wxString& data,
625  struct EDA_HOTKEY_CONFIG* aDescList,
626  const wxString& aAppname )
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 }
707 
708 
710  const wxString& aDefaultShortname )
711 {
712  wxString ext = DEFAULT_HOTKEY_FILENAME_EXT;
713  wxString mask = wxT( "*." ) + ext;
714 
715 
716  wxString path = GetMruPath();
717  wxFileName fn( aDefaultShortname );
718  fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
719 
720  wxString filename = EDA_FILE_SELECTOR( _( "Read Hotkey Configuration File:" ),
721  path,
722  fn.GetFullPath(),
723  ext,
724  mask,
725  this,
726  wxFD_OPEN,
727  true );
728 
729  if( filename.IsEmpty() )
730  return;
731 
732  ::ReadHotkeyConfigFile( filename, aDescList, false );
733  WriteHotkeyConfig( aDescList );
734  SetMruPath( wxFileName( filename ).GetPath() );
735 }
736 
737 
739  const wxString& aDefaultShortname )
740 {
741  wxString ext = DEFAULT_HOTKEY_FILENAME_EXT;
742  wxString mask = wxT( "*." ) + ext;
743 
744 #if 0
745  wxString path = wxPathOnly( Prj().GetProjectFullName() );
746 #else
747  wxString path = GetMruPath();
748 #endif
749  wxFileName fn( aDefaultShortname );
750  fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
751 
752  wxString filename = EDA_FILE_SELECTOR( _( "Write Hotkey Configuration File:" ),
753  path,
754  fn.GetFullPath(),
755  ext,
756  mask,
757  this,
758  wxFD_SAVE,
759  true );
760 
761  if( filename.IsEmpty() )
762  return;
763 
764  WriteHotkeyConfig( aDescList, &filename );
765  SetMruPath( wxFileName( filename ).GetPath() );
766 }
767 
#define GR_KB_ALT
const wxChar * m_Name
#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 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...
This file is part of the common library TODO brief description.
#define KEY_NON_FOUND
static void AddModifierToKey(wxString &aFullKey, const wxString &aKey)
This file is part of the common library.
Hotkey list dialog (as opposed to editor)
PROJECT & Prj()
Definition: kicad.cpp:292
EDA_HOTKEY ** m_HK_InfoList
Definition: hotkeys_basic.h:98
void ExportHotkeyConfigToFile(EDA_HOTKEY_CONFIG *aDescList, const wxString &aDefaultShortname)
Function ExportHotkeyConfigToFile Prompt the user for an old hotkey file to read, and read it...
A dialog that presents the user with a read-only list of hotkeys and their current bindings...
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 GR_KB_CTRL
This file contains miscellaneous commonly used macros and functions.
#define PCB_EDIT_FRAME_NAME
Definition: draw_frame.h:56
#define SCH_EDIT_FRAME_NAME
Definition: draw_frame.h:50
EDA_HOTKEY * GetDescriptorFromHotkey(int aKey, EDA_HOTKEY **aList)
Function GetDescriptorFromHotkey Return a EDA_HOTKEY * pointer from a key code for OnHotKey() functio...
void DisplayHotkeyList(EDA_BASE_FRAME *aFrame, struct EDA_HOTKEY_CONFIG *aDescList)
Function DisplayHotkeyList Displays the current hotkey list.
wxString g_CommonSectionTag(wxT("[common]"))
#define MODIFIER_CTRL
#define FOOTPRINT_EDIT_FRAME_NAME
Definition: draw_frame.h:53
wxString EDA_FILE_SELECTOR(const wxString &aTitle, const wxString &aPath, const wxString &aFileName, const wxString &aExtension, const wxString &aWildcard, wxWindow *aParent, int aStyle, const bool aKeepWorkingDirectory, const wxPoint &aPosition, wxString *aMruPath)
Function EDA_FILE_SELECTOR.
Definition: gestfich.cpp:82
int KeyCodeFromKeyName(const wxString &keyname)
Function KeyCodeFromKeyName return the key code from its key name Only some wxWidgets key values are ...
#define MODIFIER_SHIFT
Base window classes and related definitions.
void AddDelimiterString(wxString &string)
Function AddDelimiterString Add un " to the start and the end of string (if not already done)...
Definition: gestfich.cpp:44
#define GR_KB_SHIFT
wxString GetKicadConfigPath()
Return the user configuration path used to store KiCad&#39;s configuration files.
Definition: common.cpp:263
wxString * m_SectionTag
Definition: hotkeys_basic.h:97
int ReadHotkeyConfig(const wxString &aAppname, struct EDA_HOTKEY_CONFIG *aDescList)
Function ReadHotkeyConfig Read configuration data and fill the current hotkey list with hotkeys...
EDA_HOTKEY(const wxChar *infomsg, int idcommand, int keycode, int idmenuevent=0)
void ParseHotkeyConfig(const wxString &data, struct EDA_HOTKEY_CONFIG *aDescList, const wxString &aAppname)
Function ParseHotkeyConfig Translates hotkey string data into application hotkeys.
wxString m_InfoMsg
Definition: hotkeys_basic.h:66
int m_defaultKeyCode
Definition: hotkeys_basic.h:62
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
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) ...
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:59
virtual int WriteHotkeyConfig(struct EDA_HOTKEY_CONFIG *aDescList, wxString *aFullFileName=NULL)
Function WriteHotkeyConfig Store the current hotkey list It is stored using the standard wxConfig mec...
wxString * m_Title
Definition: hotkeys_basic.h:99
Class EDA_BASE_FRAME is the base frame for deriving all KiCad main window classes.
#define MODIFIER_ALT
#define MODIFIER_CMD_MAC
#define EESCHEMA_HOTKEY_NAME
Definition: hotkeys_basic.h:35
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Function KeyNameFromKeyCode return the key name from the key code Only some wxWidgets key values are ...
Some functions to handle hotkeys in KiCad.
#define DEFAULT_HOTKEY_FILENAME_EXT
Definition: hotkeys_basic.h:34
void ImportHotkeyConfigFromFile(EDA_HOTKEY_CONFIG *aDescList, const wxString &aDefaultShortname)
Function ImportHotkeyConfigFromFile Prompt the user for an old hotkey file to read, and read it.
HOTKEY_ACTION_TYPE
An helper enum for AddHotkeyName function In menus we can add a hot key, or an accelerator ...
#define PCBNEW_HOTKEY_NAME
Definition: hotkeys_basic.h:36
int m_IdMenuEvent
Definition: hotkeys_basic.h:68
static struct hotkey_name_descr hotkeyNameList[]
EDA_HOTKEY * GetDescriptorFromCommand(int aCommand, EDA_HOTKEY **aList)
Function GetDescriptorFromCommand Returns a EDA_HOTKEY* pointer from a hot key identifier.