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 },
78 { wxT(
"F13" ), WXK_F13 },
79 { wxT(
"F14" ), WXK_F14 },
80 { wxT(
"F15" ), WXK_F15 },
81 { wxT(
"F16" ), WXK_F16 },
82 { wxT(
"F17" ), WXK_F17 },
83 { wxT(
"F18" ), WXK_F18 },
84 { wxT(
"F19" ), WXK_F19 },
85 { wxT(
"F20" ), WXK_F20 },
86 { wxT(
"F21" ), WXK_F21 },
87 { wxT(
"F22" ), WXK_F22 },
88 { wxT(
"F23" ), WXK_F23 },
89 { wxT(
"F24" ), WXK_F24 },
91 { wxT(
"Esc" ), WXK_ESCAPE },
92 { wxT(
"Del" ), WXK_DELETE },
93 { wxT(
"Tab" ), WXK_TAB },
94 { wxT(
"Back" ), WXK_BACK },
95 { wxT(
"Ins" ), WXK_INSERT },
97 { wxT(
"Home" ), WXK_HOME },
98 { wxT(
"End" ), WXK_END },
99 { wxT(
"PgUp" ), WXK_PAGEUP },
100 { wxT(
"PgDn" ), WXK_PAGEDOWN },
102 { wxT(
"Up" ), WXK_UP },
103 { wxT(
"Down" ), WXK_DOWN },
104 { wxT(
"Left" ), WXK_LEFT },
105 { wxT(
"Right" ), WXK_RIGHT },
107 { wxT(
"Return" ), WXK_RETURN },
109 { wxT(
"Space" ), WXK_SPACE },
111 { wxT(
"Num Pad 0" ), WXK_NUMPAD0 },
112 { wxT(
"Num Pad 1" ), WXK_NUMPAD1 },
113 { wxT(
"Num Pad 2" ), WXK_NUMPAD2 },
114 { wxT(
"Num Pad 3" ), WXK_NUMPAD3 },
115 { wxT(
"Num Pad 4" ), WXK_NUMPAD4 },
116 { wxT(
"Num Pad 5" ), WXK_NUMPAD5 },
117 { wxT(
"Num Pad 6" ), WXK_NUMPAD6 },
118 { wxT(
"Num Pad 7" ), WXK_NUMPAD7 },
119 { wxT(
"Num Pad 8" ), WXK_NUMPAD8 },
120 { wxT(
"Num Pad 9" ), WXK_NUMPAD9 },
121 { wxT(
"Num Pad +" ), WXK_NUMPAD_ADD },
122 { wxT(
"Num Pad -" ), WXK_NUMPAD_SUBTRACT },
123 { wxT(
"Num Pad *" ), WXK_NUMPAD_MULTIPLY },
124 { wxT(
"Num Pad /" ), WXK_NUMPAD_DIVIDE },
125 { wxT(
"Num Pad ." ), WXK_NUMPAD_SEPARATOR },
126 { wxT(
"Num Pad Enter" ), WXK_NUMPAD_ENTER },
127 { wxT(
"Num Pad F1"), WXK_NUMPAD_F1 },
128 { wxT(
"Num Pad F2"), WXK_NUMPAD_F2 },
129 { wxT(
"Num Pad F3"), WXK_NUMPAD_F3 },
130 { wxT(
"Num Pad F4"), WXK_NUMPAD_F4 },
153#define MODIFIER_CTRL wxT( "Cmd+" )
154#define MODIFIER_ALT wxT( "Option+" )
156#define MODIFIER_CTRL wxT( "Ctrl+" )
157#define MODIFIER_ALT wxT( "Alt+" )
159#define MODIFIER_CMD_MAC wxT( "Cmd+" )
160#define MODIFIER_CTRL_BASE wxT( "Ctrl+" )
161#define MODIFIER_SHIFT wxT( "Shift+" )
175 wxString keyname, modifier, fullkeyname;
179 if( aKeycode == WXK_CONTROL )
181 else if( aKeycode == WXK_RAW_CONTROL )
183 else if( aKeycode == WXK_SHIFT )
185 else if( aKeycode == WXK_ALT )
189 if( (aKeycode &
MD_CTRL) != 0 )
192 if( (aKeycode &
MD_ALT) != 0 )
200 if( (aKeycode >
' ') && (aKeycode < 0x7F ) )
203 keyname.Append( (wxChar)aKeycode );
207 for( ii = 0; ; ii++ )
211 keyname = wxT(
"<unknown>" );
227 fullkeyname = modifier + keyname;
240 wxString msg = aText;
243 if( !keyname.IsEmpty() )
254 msg << wxT(
"\t" ) << keyname;
260 msg << wxT(
" (" ) << keyname << wxT(
")" );
285 wxString key = keyname;
318 if( !prefix.IsEmpty() )
319 key.Remove( 0, prefix.Len() );
322 if( (key.length() == 1) && (key[0] >
' ') && (key[0] < 0x7F) )
353 std::map<std::string, std::pair<int, int>>& aHotKeys )
355 wxString fileName = aFileName;
357 if( fileName.IsEmpty() )
359 wxFileName fn( wxS(
"user" ) );
362 fileName = fn.GetFullPath();
365 if( !wxFile::Exists( fileName ) )
368 wxFFile file( fileName,
"rb" );
370 if( !file.IsOpened() )
374 file.ReadAll( &input );
375 input.Replace(
"\r\n",
"\n" );
376 wxStringTokenizer fileTokenizer( input, wxS(
"\n" ), wxTOKEN_STRTOK );
378 while( fileTokenizer.HasMoreTokens() )
380 wxStringTokenizer lineTokenizer( fileTokenizer.GetNextToken(), wxS(
"\t" ) );
382 wxString cmdName = lineTokenizer.GetNextToken();
383 wxString primary = lineTokenizer.GetNextToken();
384 wxString secondary = lineTokenizer.GetNextToken();
386 if( !cmdName.IsEmpty() )
387 aHotKeys[cmdName.ToStdString()] = std::pair<int, int>(
395 std::map<std::string, std::pair<int, int>>
hotkeys;
404 std::pair<int, int> keys =
hotkeys[action->GetName()];
405 action->SetHotKey( keys.first, keys.second );
412 std::map<std::string, std::pair<int, int>>
hotkeys;
413 wxFileName fn(
"user" );
423 hotkeys[ action->GetName() ] = std::pair<int, int>( action->GetHotKey(), action->GetHotKeyAlt() );
426 wxFFileOutputStream outStream( fn.GetFullPath() );
427 wxTextOutputStream txtStream( outStream, wxEOL_UNIX );
429 for(
const std::pair<
const std::string, std::pair<int, int>>& entry :
hotkeys )
430 txtStream << entry.first
460 wxFileName fn( aFilename );
465 if( !wxFile::Exists( fn.GetFullPath() ) )
468 wxFFile cfgfile( fn.GetFullPath(),
"rb" );
470 if( !cfgfile.IsOpened() )
474 wxFileOffset size = cfgfile.Length();
477 std::vector<char> buffer( size );
478 cfgfile.Read( buffer.data(), size );
479 wxString data( buffer.data(), wxConvUTF8, size );
482 if( data.StartsWith( wxT(
"Keys="), &data ) )
483 data.Replace(
"\\n",
"\n",
true );
486 wxStringTokenizer tokenizer( data, L
"\r\n", wxTOKEN_STRTOK );
488 while( tokenizer.HasMoreTokens() )
490 wxString line = tokenizer.GetNextToken();
491 wxStringTokenizer lineTokenizer( line );
493 wxString line_type = lineTokenizer.GetNextToken();
495 if( line_type[0] ==
'#' )
498 if( line_type[0] ==
'[' )
501 if( line_type == wxT(
"$Endlist" ) )
504 if( line_type != wxT(
"shortcut" ) )
508 lineTokenizer.SetString( lineTokenizer.GetString(), L
"\"\r\n\t ", wxTOKEN_STRTOK );
509 wxString keyname = lineTokenizer.GetNextToken();
511 wxString remainder = lineTokenizer.GetString();
514 wxString fctname = remainder.AfterFirst(
'\"' ).BeforeFirst(
'\"' );
A dialog that presents the user with a read-only list of hotkeys and their current bindings.
The base frame for deriving all KiCad main window classes.
static wxString GetUserSettingsPath()
Return the user configuration path used to store KiCad's configuration files.
Hotkey list dialog (as opposed to editor)
Base window classes and related definitions.
#define LIB_EDIT_FRAME_NAME
#define FOOTPRINT_EDIT_FRAME_NAME
#define SCH_EDIT_FRAME_NAME
#define PCB_EDIT_FRAME_NAME
static const std::string HotkeyFileExtension
int ReadLegacyHotkeyConfigFile(const wxString &aFilename, std::map< std::string, int > &aMap)
Read hotkey configuration for a given app.
wxString AddHotkeyName(const wxString &aText, int aHotKey, HOTKEY_ACTION_TYPE aStyle)
void ReadHotKeyConfig(const wxString &aFileName, std::map< std::string, std::pair< int, int > > &aHotKeys)
Reads a hotkey config file into a map.
void DisplayHotkeyList(EDA_BASE_FRAME *aParent)
Display the current hotkey list.
int ReadLegacyHotkeyConfig(const wxString &aAppname, std::map< std::string, int > &aMap)
Read configuration data and fill the current hotkey list with hotkeys.
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
int WriteHotKeyConfig(const std::vector< TOOL_ACTION * > &aActions)
Update the hotkeys config file with the hotkeys from the given actions map.
#define MODIFIER_CTRL_BASE
static struct hotkey_name_descr hotkeyNameList[]
int KeyCodeFromKeyName(const wxString &keyname)
Return the key code from its user-friendly key name (ie: "Ctrl+M").
void ReadHotKeyConfigIntoActions(const wxString &aFileName, std::vector< TOOL_ACTION * > &aActions)
Reads a hotkey config file into a list of actions.
#define EESCHEMA_HOTKEY_NAME
#define PCBNEW_HOTKEY_NAME
HOTKEY_ACTION_TYPE
In menus we can add a hot key, or an accelerator, or sometimes just a comment.
#define PSEUDO_WXK_DBLCLICK
Definition of file extensions used in Kicad.