37 #include <wx/apptrait.h> 38 #include <wx/stdpaths.h> 39 #include <wx/tokenzr.h> 40 #include <wx/txtstrm.h> 41 #include <wx/wfstream.h> 63 #define KEY_NON_FOUND -1 66 { wxT(
"F1" ), WXK_F1 },
67 { wxT(
"F2" ), WXK_F2 },
68 { wxT(
"F3" ), WXK_F3 },
69 { wxT(
"F4" ), WXK_F4 },
70 { wxT(
"F5" ), WXK_F5 },
71 { wxT(
"F6" ), WXK_F6 },
72 { wxT(
"F7" ), WXK_F7 },
73 { wxT(
"F8" ), WXK_F8 },
74 { wxT(
"F9" ), WXK_F9 },
75 { wxT(
"F10" ), WXK_F10 },
76 { wxT(
"F11" ), WXK_F11 },
77 { wxT(
"F12" ), WXK_F12 },
79 { wxT(
"Esc" ), WXK_ESCAPE },
80 { wxT(
"Del" ), WXK_DELETE },
81 { wxT(
"Tab" ), WXK_TAB },
82 { wxT(
"Back" ), WXK_BACK },
83 { wxT(
"Ins" ), WXK_INSERT },
85 { wxT(
"Home" ), WXK_HOME },
86 { wxT(
"End" ), WXK_END },
87 { wxT(
"PgUp" ), WXK_PAGEUP },
88 { wxT(
"PgDn" ), WXK_PAGEDOWN },
90 { wxT(
"Up" ), WXK_UP },
91 { wxT(
"Down" ), WXK_DOWN },
92 { wxT(
"Left" ), WXK_LEFT },
93 { wxT(
"Right" ), WXK_RIGHT },
95 { wxT(
"Return" ), WXK_RETURN },
97 { wxT(
"Space" ), WXK_SPACE },
99 { wxT(
"Num Pad 0" ), WXK_NUMPAD0 },
100 { wxT(
"Num Pad 1" ), WXK_NUMPAD1 },
101 { wxT(
"Num Pad 2" ), WXK_NUMPAD2 },
102 { wxT(
"Num Pad 3" ), WXK_NUMPAD3 },
103 { wxT(
"Num Pad 4" ), WXK_NUMPAD4 },
104 { wxT(
"Num Pad 5" ), WXK_NUMPAD5 },
105 { wxT(
"Num Pad 6" ), WXK_NUMPAD6 },
106 { wxT(
"Num Pad 7" ), WXK_NUMPAD7 },
107 { wxT(
"Num Pad 8" ), WXK_NUMPAD8 },
108 { wxT(
"Num Pad 9" ), WXK_NUMPAD9 },
109 { wxT(
"Num Pad +" ), WXK_NUMPAD_ADD },
110 { wxT(
"Num Pad -" ), WXK_NUMPAD_SUBTRACT },
111 { wxT(
"Num Pad *" ), WXK_NUMPAD_MULTIPLY },
112 { wxT(
"Num Pad /" ), WXK_NUMPAD_DIVIDE },
113 { wxT(
"Num Pad ." ), WXK_NUMPAD_SEPARATOR },
115 { wxEmptyString, 0 },
132 #define USING_MAC_CMD 136 #define MODIFIER_CTRL wxT( "Cmd+" ) 137 #define MODIFIER_ALT wxT( "Option+" ) 139 #define MODIFIER_CTRL wxT( "Ctrl+" ) 140 #define MODIFIER_ALT wxT( "Alt+" ) 142 #define MODIFIER_CMD_MAC wxT( "Cmd+" ) 143 #define MODIFIER_CTRL_BASE wxT( "Ctrl+" ) 144 #define MODIFIER_SHIFT wxT( "Shift+" ) 158 wxString keyname, modifier, fullkeyname;
163 if( (aKeycode &
MD_CTRL) != 0 )
166 if( (aKeycode &
MD_ALT) != 0 )
174 if( (aKeycode >
' ') && (aKeycode < 0x7F ) )
177 keyname.Append( (wxChar)aKeycode );
181 for( ii = 0; ; ii++ )
185 keyname = wxT(
"<unknown>" );
201 fullkeyname = modifier + keyname;
214 wxString msg = aText;
217 if( !keyname.IsEmpty() )
228 msg << wxT(
"\t" ) << keyname;
234 msg << wxT(
" (" ) << keyname << wxT(
")" );
259 wxString key = keyname;
292 if( !prefix.IsEmpty() )
293 key.Remove( 0, prefix.Len() );
296 if( (key.length() == 1) && (key[0] >
' ') && (key[0] < 0x7F) )
328 wxString fileName = aFileName;
330 if( fileName.IsEmpty() )
332 wxFileName fn( wxT(
"user" ) );
335 fileName = fn.GetFullPath();
338 if( !wxFile::Exists( fileName ) )
341 wxFFile file( fileName, wxT(
"rb" ) );
343 if( !file.IsOpened() )
347 file.ReadAll( &input );
348 input.Replace( wxT(
"\r\n" ), wxT(
"\n" ) );
349 wxStringTokenizer fileTokenizer( input, wxT(
"\n" ), wxTOKEN_STRTOK );
351 while( fileTokenizer.HasMoreTokens() )
353 wxStringTokenizer lineTokenizer( fileTokenizer.GetNextToken(), wxT(
"\t" ) );
355 wxString cmdName = lineTokenizer.GetNextToken();
356 wxString keyName = lineTokenizer.GetNextToken();
358 if( !cmdName.IsEmpty() )
366 std::map<std::string, int>
hotkeys;
367 wxFileName fn( wxT(
"user" ) );
376 for(
const auto& ii : aActionMap )
377 hotkeys[ ii.first ] = ii.second->GetHotKey();
380 wxFFileOutputStream outStream( fn.GetFullPath() );
381 wxTextOutputStream txtStream( outStream, wxEOL_UNIX );
383 for(
const auto& ii :
hotkeys )
413 wxFileName fn( aFilename );
418 if( !wxFile::Exists( fn.GetFullPath() ) )
421 wxFFile cfgfile( fn.GetFullPath(), wxT(
"rb" ) );
423 if( !cfgfile.IsOpened() )
427 wxFileOffset size = cfgfile.Length();
430 std::vector<char> buffer( size );
431 cfgfile.Read( buffer.data(), size );
432 wxString data( buffer.data(), wxConvUTF8, size );
435 if( data.StartsWith( wxT(
"Keys="), &data ) )
436 data.Replace( wxT(
"\\n" ), wxT(
"\n" ),
true );
439 wxStringTokenizer tokenizer( data, L
"\r\n", wxTOKEN_STRTOK );
441 while( tokenizer.HasMoreTokens() )
443 wxString line = tokenizer.GetNextToken();
444 wxStringTokenizer lineTokenizer( line );
446 wxString line_type = lineTokenizer.GetNextToken();
448 if( line_type[0] ==
'#' )
451 if( line_type[0] ==
'[' )
454 if( line_type == wxT(
"$Endlist" ) )
457 if( line_type != wxT(
"shortcut" ) )
461 lineTokenizer.SetString( lineTokenizer.GetString(), L
"\"\r\n\t ", wxTOKEN_STRTOK );
462 wxString keyname = lineTokenizer.GetNextToken();
464 wxString remainder = lineTokenizer.GetString();
467 wxString fctname = remainder.AfterFirst(
'\"' ).BeforeFirst(
'\"' );
#define MODIFIER_CTRL_BASE
Hotkey list dialog (as opposed to editor)
A dialog that presents the user with a read-only list of hotkeys and their current bindings.
wxString AddHotkeyName(const wxString &aText, int aHotKey, HOTKEY_ACTION_TYPE aStyle)
void ReadHotKeyConfig(const wxString &aFileName, std::map< std::string, int > &aHotKeys)
Reads a hotkey config file into a map.
int ReadLegacyHotkeyConfigFile(const wxString &aFilename, std::map< std::string, int > &aMap)
Read hotkey configuration for a given app.
#define LIB_EDIT_FRAME_NAME
#define SCH_EDIT_FRAME_NAME
int ReadLegacyHotkeyConfig(const wxString &aAppname, std::map< std::string, int > &aMap)
Read configuration data and fill the current hotkey list with hotkeys.
void DisplayHotkeyList(EDA_BASE_FRAME *aParent, TOOL_MANAGER *aToolManager)
Display the current hotkey list.
int KeyCodeFromKeyName(const wxString &keyname)
Return the key code from its user-friendly key name (ie: "Ctrl+M").
Definition of file extensions used in Kicad.
Base window classes and related definitions.
#define FOOTPRINT_EDIT_FRAME_NAME
static wxString GetUserSettingsPath()
Return the user configuration path used to store KiCad's configuration files.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
const std::string HotkeyFileExtension
The base frame for deriving all KiCad main window classes.
#define EESCHEMA_HOTKEY_NAME
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
#define PCB_EDIT_FRAME_NAME
#define PSEUDO_WXK_DBLCLICK
HOTKEY_ACTION_TYPE
In menus we can add a hot key, or an accelerator, or sometimes just a comment.
#define PCBNEW_HOTKEY_NAME
int WriteHotKeyConfig(const std::map< std::string, TOOL_ACTION * > &aActionMap)
Update the hotkeys config file with the hotkeys from the given actions map.
static struct hotkey_name_descr hotkeyNameList[]