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) 2015 Jean-Pierre Charras, j-p.charras at wanadoo.fr
5  * Copyright (C) 2010-2011 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 1992-2016 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 <wxstruct.h>
39 #include <macros.h>
40 #include <dialog_hotkeys_editor.h>
41 #include <menus_helpers.h>
42 #include <tool/tool_manager.h>
43 
44 #include <wx/apptrait.h>
45 #include <wx/stdpaths.h>
46 #include <wx/tokenzr.h>
47 
48 #define HOTKEYS_CONFIG_KEY wxT( "Keys" )
49 
50 wxString g_CommonSectionTag( wxT( "[common]" ) );
51 
52 
53 /* Class to handle hotkey commands hotkeys have a default value
54  * This class allows the real key code changed by user from a key code list
55  * file.
56  */
57 
58 EDA_HOTKEY::EDA_HOTKEY( const wxChar* infomsg, int idcommand, int keycode, int idmenuevent ) :
59  m_defaultKeyCode( keycode ), m_KeyCode( keycode ), m_InfoMsg( infomsg ),
60  m_Idcommand( idcommand ), m_IdMenuEvent( idmenuevent )
61 {
62 }
63 
64 
66 {
67  m_defaultKeyCode = base->m_defaultKeyCode; // initialize default key code
68  m_KeyCode = base->m_KeyCode;
69  m_InfoMsg = base->m_InfoMsg;
70  m_Idcommand = base->m_Idcommand;
72 }
73 
74 
76 {
77 }
78 
79 
80 /* class to handle the printable name and the keycode
81  */
83 {
84  const wxChar* m_Name;
85  int m_KeyCode;
86 };
87 
88 /* table giving the hotkey name from the hotkey code, for special keys
89  * Note : when modifiers (ATL, SHIFT, CTRL) do not modify
90  * the code of the key, do need to enter the modified key code
91  * For instance wxT( "F1" ), WXK_F1 handle F1, AltF1, CtrlF1 ...
92  * Key names are:
93  * "Space","Ctrl+Space","Alt+Space" or
94  * "Alt+A","Ctrl+F1", ...
95  */
97 {
98  { wxT( "F1" ), WXK_F1 },
99  { wxT( "F2" ), WXK_F2 },
100  { wxT( "F3" ), WXK_F3 },
101  { wxT( "F4" ), WXK_F4 },
102  { wxT( "F5" ), WXK_F5 },
103  { wxT( "F6" ), WXK_F6 },
104  { wxT( "F7" ), WXK_F7 },
105  { wxT( "F8" ), WXK_F8 },
106  { wxT( "F9" ), WXK_F9 },
107  { wxT( "F10" ), WXK_F10 },
108  { wxT( "F11" ), WXK_F11 },
109  { wxT( "F12" ), WXK_F12 },
110 
111  { wxT( "Esc" ), WXK_ESCAPE },
112  { wxT( "Del" ), WXK_DELETE },
113  { wxT( "Tab" ), WXK_TAB },
114  { wxT( "BkSp" ), WXK_BACK },
115  { wxT( "Ins" ), WXK_INSERT },
116 
117  { wxT( "Home" ), WXK_HOME },
118  { wxT( "End" ), WXK_END },
119  { wxT( "PgUp" ), WXK_PAGEUP },
120  { wxT( "PgDn" ), WXK_PAGEDOWN },
121 
122  { wxT( "Up" ), WXK_UP },
123  { wxT( "Down" ), WXK_DOWN },
124  { wxT( "Left" ), WXK_LEFT },
125  { wxT( "Right" ), WXK_RIGHT },
126 
127  { wxT( "Return" ), WXK_RETURN },
128 
129  { wxT( "Space" ), WXK_SPACE },
130 
131  // Do not change this line: end of list
132  { wxT( "" ), 0 }
133 };
134 
135 // name of modifier keys.
136 // Note: the Ctrl key is Cmd key on Mac OS X.
137 // However, in wxWidgets defs, the key WXK_CONTROL is the Cmd key,
138 // so the code using WXK_CONTROL should be ok on any system.
139 // (on Mac OS X the actual Ctrl key code is WXK_RAW_CONTROL)
140 #ifdef __WXMAC__
141 #define USING_MAC_CMD
142 #endif
143 
144 #ifdef USING_MAC_CMD
145 #define MODIFIER_CTRL wxT( "Cmd+" )
146 #else
147 #define MODIFIER_CTRL wxT( "Ctrl+" )
148 #endif
149 #define MODIFIER_CMD_MAC wxT( "Cmd+" )
150 #define MODIFIER_CTRL_BASE wxT( "Ctrl+" )
151 #define MODIFIER_ALT wxT( "Alt+" )
152 #define MODIFIER_SHIFT wxT( "Shift+" )
153 
154 
164 wxString KeyNameFromKeyCode( int aKeycode, bool* aIsFound )
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 }
215 
216 
217 /*
218  * helper function use in AddHotkeyName to calculate an accelerator string
219  * In some menus, accelerators do not perform exactly the same action as
220  * the hotkey that perform a similar action.
221  * this is usually the case when this action uses the current mouse position
222  * for instance zoom action is ran from the F1 key or the Zoom menu.
223  * a zoom uses the mouse position from a hot key and not from the menu
224  * In this case, the accelerator if Shift+<hotkey>
225  * But for many keys, the Shift modifier is not usable, and the accelerator is Alt+<hotkey>
226  */
227 static void AddModifierToKey( wxString& aFullKey, const wxString & aKey )
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 }
236 
237 
238 /* AddHotkeyName
239  * Add the key name from the Command id value ( m_Idcommand member value)
240  * aText = a wxString. returns aText + key name
241  * aList = pointer to a EDA_HOTKEY list of commands
242  * aCommandId = Command Id value
243  * aShortCutType = IS_HOTKEY to add <tab><keyname> (shortcuts in menus, same as hotkeys)
244  * IS_ACCELERATOR to add <tab><Shift+keyname> (accelerators in menus, not hotkeys)
245  * IS_COMMENT to add <spaces><(keyname)> mainly in tool tips
246  * Return a wxString (aTest + key name) if key found or aText without modification
247  */
248 wxString AddHotkeyName( const wxString& aText, EDA_HOTKEY** aList,
249  int aCommandId, HOTKEY_ACTION_TYPE aShortCutType )
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 }
283 
284 
285 /* AddHotkeyName
286  * Add the key name from the Command id value ( m_Idcommand member value)
287  * aText = a wxString. returns aText + key name
288  * aList = pointer to a EDA_HOTKEY_CONFIG DescrList of commands
289  * aCommandId = Command Id value
290  * aShortCutType = IS_HOTKEY to add <tab><keyname> (active shortcuts in menus)
291  * IS_ACCELERATOR to add <tab><Shift+keyname> (active accelerators in menus)
292  * IS_COMMENT to add <spaces><(keyname)>
293  * Return a wxString (aText + key name) if key found or aText without modification
294  */
295 wxString AddHotkeyName( const wxString& aText,
296  struct EDA_HOTKEY_CONFIG* aDescList,
297  int aCommandId,
298  HOTKEY_ACTION_TYPE aShortCutType )
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 }
341 
342 
350 wxString KeyNameFromCommandId( EDA_HOTKEY** aList, int aCommandId )
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 }
367 
368 
377 int KeyCodeFromKeyName( const wxString& keyname )
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 }
441 
442 
443 /* DisplayHotkeyList
444  * Displays the current hotkey list
445  * aList = a EDA_HOTKEY_CONFIG list(Null terminated)
446  */
447 #include <html_messagebox.h>
448 
449 void DisplayHotkeyList( EDA_BASE_FRAME* aFrame, struct EDA_HOTKEY_CONFIG* aDescList )
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 }
497 
498 
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 }
518 
519 
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 }
532 
533 
535  wxString* aFullFileName )
536 {
537  wxString msg;
538  wxString keyname, infokey;
539 
540  msg = wxT( "$hotkey list\n" );
541 
542  // Print the current hotkey list
543  EDA_HOTKEY** list;
544 
545  for( ; aDescList->m_HK_InfoList != NULL; aDescList++ )
546  {
547  if( aDescList->m_Title )
548  {
549  msg += wxT( "# " );
550  msg += *aDescList->m_Title;
551  msg += wxT( "\n" );
552  }
553 
554  msg += *aDescList->m_SectionTag;
555  msg += wxT( "\n" );
556 
557  list = aDescList->m_HK_InfoList;
558 
559  for( ; *list != NULL; list++ )
560  {
561  EDA_HOTKEY* hk_decr = *list;
562  msg += wxT( "shortcut " );
563  keyname = KeyNameFromKeyCode( hk_decr->m_KeyCode );
564  AddDelimiterString( keyname );
565  infokey = hk_decr->m_InfoMsg;
566  AddDelimiterString( infokey );
567  msg += keyname + wxT( ": " ) + infokey + wxT( "\n" );
568  }
569  }
570 
571  msg += wxT( "$Endlist\n" );
572 
573  if( aFullFileName )
574  {
575  FILE* file = wxFopen( *aFullFileName, wxT( "wt" ) );
576 
577  if( file )
578  {
579  fputs( TO_UTF8( msg ), file );
580  fclose( file );
581  }
582  else
583  {
584  msg.Printf( wxT( "Unable to write file %s" ), GetChars( *aFullFileName ) );
585  return 0;
586  }
587  }
588  else
589  {
590  wxFileName fn( GetName() );
591  fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
592  wxConfigBase* config = GetNewConfig( fn.GetFullPath() );
593  config->Write( HOTKEYS_CONFIG_KEY, msg );
594  delete config;
595  }
596 
597  return 1;
598 }
599 
600 
601 int EDA_BASE_FRAME::ReadHotkeyConfigFile( const wxString& aFilename,
602  struct EDA_HOTKEY_CONFIG* aDescList )
603 {
604  wxFileName fn( aFilename );
605  fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
606 
607  wxFile cfgfile( fn.GetFullPath() );
608 
609  if( !cfgfile.IsOpened() ) // There is a problem to open file
610  return 0;
611 
612  // get length
613  cfgfile.SeekEnd();
614  wxFileOffset size = cfgfile.Tell();
615  cfgfile.Seek( 0 );
616 
617  // read data
618  char* buffer = new char[size];
619  cfgfile.Read( buffer, size );
620 
621  wxString data( buffer, wxConvUTF8 );
622 
623  // parse
624  ParseHotkeyConfig( data, aDescList );
625 
626  // cleanup
627  delete[] buffer;
628  cfgfile.Close();
629  return 1;
630 }
631 
632 
633 void ReadHotkeyConfig( const wxString& Appname, struct EDA_HOTKEY_CONFIG* aDescList )
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 }
652 
653 
654 /* Function ReadHotkeyConfig
655  * Read configuration data and fill the current hotkey list with hotkeys
656  * aDescList is the current hotkey list descr. to initialize.
657  */
659 {
660  ::ReadHotkeyConfig( GetName(), aDescList );
661  return 1;
662 }
663 
664 
665 /* Function ParseHotkeyConfig
666  * the input format is: shortcut "key" "function"
667  * lines starting by # are ignored (comments)
668  * lines like [xxx] are tags (example: [common] or [libedit] which identify sections
669  */
670 void ParseHotkeyConfig( const wxString& data,
671  struct EDA_HOTKEY_CONFIG* aDescList )
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 }
735 
736 
738  const wxString& aDefaultShortname )
739 {
740  wxString ext = DEFAULT_HOTKEY_FILENAME_EXT;
741  wxString mask = wxT( "*." ) + ext;
742 
743 #if 0 // pass in the project dir as an argument
744  wxString path = wxPathOnly( Prj().GetProjectFullName() );
745 #else
746  wxString path = GetMruPath();
747 #endif
748  wxFileName fn( aDefaultShortname );
749  fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
750 
751  wxString filename = EDA_FILE_SELECTOR( _( "Read Hotkey Configuration File:" ),
752  path,
753  fn.GetFullPath(),
754  ext,
755  mask,
756  this,
757  wxFD_OPEN,
758  true );
759 
760  if( filename.IsEmpty() )
761  return;
762 
763  ReadHotkeyConfigFile( filename, aDescList );
764  SetMruPath( wxFileName( filename ).GetPath() );
765 }
766 
767 
769  const wxString& aDefaultShortname )
770 {
771  wxString ext = DEFAULT_HOTKEY_FILENAME_EXT;
772  wxString mask = wxT( "*." ) + ext;
773 
774 #if 0
775  wxString path = wxPathOnly( Prj().GetProjectFullName() );
776 #else
777  wxString path = GetMruPath();
778 #endif
779  wxFileName fn( aDefaultShortname );
780  fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
781 
782  wxString filename = EDA_FILE_SELECTOR( _( "Write Hotkey Configuration File:" ),
783  path,
784  fn.GetFullPath(),
785  ext,
786  mask,
787  this,
788  wxFD_SAVE,
789  true );
790 
791  if( filename.IsEmpty() )
792  return;
793 
794  WriteHotkeyConfig( aDescList, &filename );
795  SetMruPath( wxFileName( filename ).GetPath() );
796 }
797 
798 
799 /* add hotkey config options submenu to aMenu
800  */
801 void AddHotkeyConfigMenu( wxMenu* aMenu )
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 }
void ParseHotkeyConfig(const wxString &data, struct EDA_HOTKEY_CONFIG *aDescList)
void ReadHotkeyConfig(const wxString &Appname, struct EDA_HOTKEY_CONFIG *aDescList)
Function ReadHotkeyConfig Read hotkey configuration for a given app, possibly before the frame for th...
const wxChar * m_Name
Structure EDA_HOTKEY_CONFIG contains the information required to save hot key information to a config...
Definition: hotkeys_basic.h:87
#define MODIFIER_CTRL_BASE
void SetMruPath(const wxString &aPath)
Definition: wxstruct.h:356
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.
int ReadHotkeyConfigFile(const wxString &aFilename, struct EDA_HOTKEY_CONFIG *aDescList)
Function ReadHotkeyConfigFile Read an old configuration file (<file>.key) and fill the current ho...
static void AddModifierToKey(wxString &aFullKey, const wxString &aKey)
This file is part of the common library.
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
PROJECT & Prj()
Definition: kicad.cpp:293
EDA_HOTKEY ** m_HK_InfoList
Definition: hotkeys_basic.h:91
void ExportHotkeyConfigToFile(EDA_HOTKEY_CONFIG *aDescList, const wxString &aDefaultShortname)
Function ExportHotkeyConfigToFile Prompt the user for an old hotkey file to read, and read it...
wxConfigBase * GetNewConfig(const wxString &aProgName)
Function GetNewConfig.
Definition: common.cpp:205
virtual wxConfigBase * config()
Function config returns the wxConfigBase used in SaveSettings(), and is overloaded in KICAD_MANAGER_F...
Definition: basicframe.cpp:361
int ReadHotkeyConfig(struct EDA_HOTKEY_CONFIG *aDescList)
Function ReadHotkeyConfig Read configuration data and fill the current hotkey list with hotkeys...
#define GR_KB_ALT
Definition: common.h:65
This file contains miscellaneous commonly used macros and functions.
EDA_HOTKEY * GetDescriptorFromHotkey(int aKey, EDA_HOTKEY **aList)
Function GetDescriptorFromHotkey Return a EDA_HOTKEY * pointer from a key code for OnHotKey() functio...
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
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 HOTKEYS_CONFIG_KEY
#define GR_KB_SHIFT
Definition: common.h:66
Base window classes and related definitions.
Subclass of DIALOG_DISPLAY_HTML_TEXT_BASE, which is generated by wxFormBuilder.
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
void AddDelimiterString(wxString &string)
Function AddDelimiterString Add un " to the start and the end of string (if not already done)...
Definition: gestfich.cpp:44
Class HTML_MESSAGE_BOX.
bool Show(bool show) override
wxString * m_SectionTag
Definition: hotkeys_basic.h:90
EDA_HOTKEY(const wxChar *infomsg, int idcommand, int keycode, int idmenuevent=0)
void AddHotkeyConfigMenu(wxMenu *aMenu)
wxString m_InfoMsg
Definition: hotkeys_basic.h:64
int m_defaultKeyCode
Definition: hotkeys_basic.h:60
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: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
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:92
void AddHTML_Text(const wxString &message)
Function AddHTML_Text adds html text (without any change) to message list.
Class EDA_BASE_FRAME is the base frame for deriving all KiCad main window classes.
Definition: wxstruct.h:112
#define MODIFIER_ALT
#define MODIFIER_CMD_MAC
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.
wxString GetMruPath() const
Definition: wxstruct.h:358
#define GR_KB_CTRL
Definition: common.h:64
HOTKEY_ACTION_TYPE
An helper enum for AddHotkeyName function In menus we can add a hot key, or an accelerator ...
int m_IdMenuEvent
Definition: hotkeys_basic.h:66
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.