36 #include <wx/apptrait.h> 37 #include <wx/stdpaths.h> 38 #include <wx/tokenzr.h> 39 #include <wx/txtstrm.h> 40 #include <wx/wfstream.h> 61 #define KEY_NON_FOUND -1 64 { wxT(
"F1" ), WXK_F1 },
65 { wxT(
"F2" ), WXK_F2 },
66 { wxT(
"F3" ), WXK_F3 },
67 { wxT(
"F4" ), WXK_F4 },
68 { wxT(
"F5" ), WXK_F5 },
69 { wxT(
"F6" ), WXK_F6 },
70 { wxT(
"F7" ), WXK_F7 },
71 { wxT(
"F8" ), WXK_F8 },
72 { wxT(
"F9" ), WXK_F9 },
73 { wxT(
"F10" ), WXK_F10 },
74 { wxT(
"F11" ), WXK_F11 },
75 { wxT(
"F12" ), WXK_F12 },
77 { wxT(
"Esc" ), WXK_ESCAPE },
78 { wxT(
"Del" ), WXK_DELETE },
79 { wxT(
"Tab" ), WXK_TAB },
80 { wxT(
"Back" ), WXK_BACK },
81 { wxT(
"Ins" ), WXK_INSERT },
83 { wxT(
"Home" ), WXK_HOME },
84 { wxT(
"End" ), WXK_END },
85 { wxT(
"PgUp" ), WXK_PAGEUP },
86 { wxT(
"PgDn" ), WXK_PAGEDOWN },
88 { wxT(
"Up" ), WXK_UP },
89 { wxT(
"Down" ), WXK_DOWN },
90 { wxT(
"Left" ), WXK_LEFT },
91 { wxT(
"Right" ), WXK_RIGHT },
93 { wxT(
"Return" ), WXK_RETURN },
95 { wxT(
"Space" ), WXK_SPACE },
97 { wxT(
"Num Pad 0" ), WXK_NUMPAD0 },
98 { wxT(
"Num Pad 1" ), WXK_NUMPAD1 },
99 { wxT(
"Num Pad 2" ), WXK_NUMPAD2 },
100 { wxT(
"Num Pad 3" ), WXK_NUMPAD3 },
101 { wxT(
"Num Pad 4" ), WXK_NUMPAD4 },
102 { wxT(
"Num Pad 5" ), WXK_NUMPAD5 },
103 { wxT(
"Num Pad 6" ), WXK_NUMPAD6 },
104 { wxT(
"Num Pad 7" ), WXK_NUMPAD7 },
105 { wxT(
"Num Pad 8" ), WXK_NUMPAD8 },
106 { wxT(
"Num Pad 9" ), WXK_NUMPAD9 },
107 { wxT(
"Num Pad +" ), WXK_NUMPAD_ADD },
108 { wxT(
"Num Pad -" ), WXK_NUMPAD_SUBTRACT },
109 { wxT(
"Num Pad *" ), WXK_NUMPAD_MULTIPLY },
110 { wxT(
"Num Pad /" ), WXK_NUMPAD_DIVIDE },
111 { wxT(
"Num Pad ." ), WXK_NUMPAD_SEPARATOR },
129 #define USING_MAC_CMD 133 #define MODIFIER_CTRL wxT( "Cmd+" ) 135 #define MODIFIER_CTRL wxT( "Ctrl+" ) 137 #define MODIFIER_CMD_MAC wxT( "Cmd+" ) 138 #define MODIFIER_CTRL_BASE wxT( "Ctrl+" ) 139 #define MODIFIER_ALT wxT( "Alt+" ) 140 #define MODIFIER_SHIFT wxT( "Shift+" ) 154 wxString keyname, modifier, fullkeyname;
159 if( (aKeycode &
MD_CTRL) != 0 )
162 if( (aKeycode &
MD_ALT) != 0 )
170 if( (aKeycode >
' ') && (aKeycode < 0x7F ) )
173 keyname.Append( (wxChar)aKeycode );
177 for( ii = 0; ; ii++ )
181 keyname = wxT(
"<unknown>" );
197 fullkeyname = modifier + keyname;
210 wxString msg = aText;
213 if( !keyname.IsEmpty() )
224 msg << wxT(
"\t" ) << keyname;
230 msg << wxT(
" (" ) << keyname << wxT(
")" );
255 wxString key = keyname;
288 if( !prefix.IsEmpty() )
289 key.Remove( 0, prefix.Len() );
292 if( (key.length() == 1) && (key[0] >
' ') && (key[0] < 0x7F) )
324 wxString fileName = aFileName;
326 if( fileName.IsEmpty() )
328 wxFileName fn(
"user" );
331 fileName = fn.GetFullPath();
334 if( !wxFile::Exists( fileName ) )
337 wxFFile file( fileName,
"rb" );
339 if( !file.IsOpened() )
343 file.ReadAll( &input );
344 input.Replace(
"\r\n",
"\n" );
345 wxStringTokenizer fileTokenizer( input,
"\n", wxTOKEN_STRTOK );
347 while( fileTokenizer.HasMoreTokens() )
349 wxStringTokenizer lineTokenizer( fileTokenizer.GetNextToken(),
"\t" );
351 wxString cmdName = lineTokenizer.GetNextToken();
352 wxString keyName = lineTokenizer.GetNextToken();
354 if( !cmdName.IsEmpty() )
362 std::map<std::string, int> hotkeys;
363 wxFileName fn(
"user" );
372 for(
const auto& ii : aActionMap )
373 hotkeys[ ii.first ] = ii.second->GetHotKey();
376 wxFFileOutputStream outStream( fn.GetFullPath() );
377 wxTextOutputStream txtStream( outStream, wxEOL_UNIX );
379 for(
const auto& ii : hotkeys )
409 wxFileName fn( aFilename );
414 if( !wxFile::Exists( fn.GetFullPath() ) )
417 wxFFile cfgfile( fn.GetFullPath(),
"rb" );
419 if( !cfgfile.IsOpened() )
423 wxFileOffset size = cfgfile.Length();
426 std::vector<char> buffer( size );
427 cfgfile.Read( buffer.data(), size );
428 wxString data( buffer.data(), wxConvUTF8, size );
431 if( data.StartsWith( wxT(
"Keys="), &data ) )
432 data.Replace(
"\\n",
"\n",
true );
435 wxStringTokenizer tokenizer( data, L
"\r\n", wxTOKEN_STRTOK );
437 while( tokenizer.HasMoreTokens() )
439 wxString line = tokenizer.GetNextToken();
440 wxStringTokenizer lineTokenizer( line );
442 wxString line_type = lineTokenizer.GetNextToken();
444 if( line_type[0] ==
'#' )
447 if( line_type[0] ==
'[' )
450 if( line_type == wxT(
"$Endlist" ) )
453 if( line_type != wxT(
"shortcut" ) )
457 lineTokenizer.SetString( lineTokenizer.GetString(), L
"\"\r\n\t ", wxTOKEN_STRTOK );
458 wxString keyname = lineTokenizer.GetNextToken();
460 wxString remainder = lineTokenizer.GetString();
463 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").
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.
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 DEFAULT_HOTKEY_FILENAME_EXT
#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[]