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+" )
166 wxString keyname, modifier, fullkeyname;
170 if( aKeycode == WXK_CONTROL )
172 else if( aKeycode == WXK_RAW_CONTROL )
174 else if( aKeycode == WXK_SHIFT )
176 else if( aKeycode == WXK_ALT )
180 if( (aKeycode &
MD_CTRL) != 0 )
183 if( (aKeycode &
MD_ALT) != 0 )
191 if( (aKeycode >
' ') && (aKeycode < 0x7F ) )
194 keyname.Append( (wxChar)aKeycode );
198 for( ii = 0; ; ii++ )
202 keyname = wxT(
"<unknown>" );
218 fullkeyname = modifier + keyname;
225 wxString msg = aText;
228 if( !keyname.IsEmpty() )
239 msg << wxT(
"\t" ) << keyname;
245 msg << wxT(
" (" ) << keyname << wxT(
")" );
267 wxString key = keyname;
300 if( !prefix.IsEmpty() )
301 key.Remove( 0, prefix.Len() );
304 if( (key.length() == 1) && (key[0] >
' ') && (key[0] < 0x7F) )
332 std::map<std::string, std::pair<int, int>>& aHotKeys )
334 wxString fileName = aFileName;
336 if( fileName.IsEmpty() )
338 wxFileName fn( wxS(
"user" ) );
341 fileName = fn.GetFullPath();
344 if( !wxFile::Exists( fileName ) )
347 wxFFile file( fileName,
"rb" );
349 if( !file.IsOpened() )
353 file.ReadAll( &input );
354 input.Replace(
"\r\n",
"\n" );
355 wxStringTokenizer fileTokenizer( input, wxS(
"\n" ), wxTOKEN_STRTOK );
357 while( fileTokenizer.HasMoreTokens() )
359 wxStringTokenizer lineTokenizer( fileTokenizer.GetNextToken(), wxS(
"\t" ) );
361 wxString cmdName = lineTokenizer.GetNextToken();
362 wxString primary = lineTokenizer.GetNextToken();
363 wxString secondary = lineTokenizer.GetNextToken();
365 if( !cmdName.IsEmpty() )
366 aHotKeys[cmdName.ToStdString()] = std::pair<int, int>(
374 std::map<std::string, std::pair<int, int>>
hotkeys;
384 std::pair<int, int> keys =
hotkeys[action->GetName()];
385 action->SetHotKey( keys.first, keys.second );
393 std::map<std::string, std::pair<int, int>>
hotkeys;
394 wxFileName fn(
"user" );
404 hotkeys[ action->GetName() ] = std::pair<int, int>( action->GetHotKey(),
405 action->GetHotKeyAlt() );
408 wxFFileOutputStream outStream( fn.GetFullPath() );
409 wxTextOutputStream txtStream( outStream, wxEOL_UNIX );
411 for(
const std::pair<
const std::string, std::pair<int, int>>& entry :
hotkeys )
412 txtStream << entry.first
442 wxFileName fn( aFilename );
447 if( !wxFile::Exists( fn.GetFullPath() ) )
450 wxFFile cfgfile( fn.GetFullPath(),
"rb" );
452 if( !cfgfile.IsOpened() )
456 wxFileOffset size = cfgfile.Length();
459 std::vector<char> buffer( size );
460 cfgfile.Read( buffer.data(), size );
461 wxString data( buffer.data(), wxConvUTF8, size );
464 if( data.StartsWith( wxT(
"Keys="), &data ) )
465 data.Replace(
"\\n",
"\n",
true );
468 wxStringTokenizer tokenizer( data, L
"\r\n", wxTOKEN_STRTOK );
470 while( tokenizer.HasMoreTokens() )
472 wxString line = tokenizer.GetNextToken();
473 wxStringTokenizer lineTokenizer( line );
475 wxString line_type = lineTokenizer.GetNextToken();
477 if( line_type[0] ==
'#' )
480 if( line_type[0] ==
'[' )
483 if( line_type == wxT(
"$Endlist" ) )
486 if( line_type != wxT(
"shortcut" ) )
490 lineTokenizer.SetString( lineTokenizer.GetString(), L
"\"\r\n\t ", wxTOKEN_STRTOK );
491 wxString keyname = lineTokenizer.GetNextToken();
493 wxString remainder = lineTokenizer.GetString();
496 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)
Read 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)
Read 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
Common command IDs shared by more than one of the KiCad applications.
Definition of file extensions used in Kicad.