2007-08-30 08:15:05 +00:00
|
|
|
/*********************/
|
|
|
|
/* hotkeys_basic.cpp */
|
|
|
|
/*********************/
|
2007-08-20 11:33:45 +00:00
|
|
|
|
|
|
|
/* Some functions to handle hotkeys in kicad
|
2007-08-30 08:15:05 +00:00
|
|
|
*/
|
2007-09-06 11:52:26 +00:00
|
|
|
|
2007-08-20 11:33:45 +00:00
|
|
|
#include "fctsys.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2007-08-20 11:33:45 +00:00
|
|
|
#include "common.h"
|
|
|
|
#include "hotkeys_basic.h"
|
2007-08-21 19:37:31 +00:00
|
|
|
#include "macros.h"
|
2007-09-19 15:29:50 +00:00
|
|
|
#include "bitmaps.h"
|
|
|
|
#include "id.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "confirm.h"
|
|
|
|
#include "kicad_string.h"
|
|
|
|
#include "gestfich.h"
|
|
|
|
#include "wxstruct.h"
|
2007-09-19 15:29:50 +00:00
|
|
|
|
2009-04-06 18:54:57 +00:00
|
|
|
#include <wx/apptrait.h>
|
|
|
|
#include <wx/stdpaths.h>
|
|
|
|
|
2007-08-20 11:33:45 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
wxString g_CommonSectionTag( wxT( "[common]" ) );
|
|
|
|
wxString g_SchematicSectionTag( wxT( "[eeschema]" ) );
|
|
|
|
wxString g_LibEditSectionTag( wxT( "[libedit]" ) );
|
|
|
|
wxString g_BoardEditorSectionTag( wxT( "[pcbnew]" ) );
|
|
|
|
wxString g_ModuleEditSectionTag( wxT( "[footprinteditor]" ) );
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/* 0 = files are in Home directory (usefull under unix)
|
|
|
|
* 1 = kicad/template ( usefull only under windows )
|
|
|
|
* 2 ... = unused
|
|
|
|
*/
|
|
|
|
int g_ConfigFileLocationChoice;
|
|
|
|
|
|
|
|
|
2007-08-20 11:33:45 +00:00
|
|
|
/* Class to handle hotkey commnands. hotkeys have a default value
|
2009-11-23 15:16:50 +00:00
|
|
|
* This class allows the real key code changed by user from a key code list
|
|
|
|
* file.
|
2007-08-30 08:15:05 +00:00
|
|
|
*/
|
2007-08-20 11:33:45 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
Ki_HotkeyInfo::Ki_HotkeyInfo( const wxChar* infomsg, int idcommand,
|
|
|
|
int keycode, int idmenuevent )
|
2007-08-20 11:33:45 +00:00
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
m_KeyCode = keycode; // Key code (ascii value for ascii keys
|
|
|
|
// or wxWidgets code for function key
|
2007-09-22 14:31:20 +00:00
|
|
|
m_InfoMsg = infomsg; // info message.
|
2009-11-23 15:16:50 +00:00
|
|
|
m_Idcommand = idcommand; // internal id for the corresponding
|
|
|
|
// command (see hotkey_id_commnand list)
|
|
|
|
m_IdMenuEvent = idmenuevent; // id to call the corresponding event
|
|
|
|
// (if any) (see id.h)
|
2007-08-20 11:33:45 +00:00
|
|
|
}
|
|
|
|
|
2007-08-30 08:15:05 +00:00
|
|
|
|
2007-08-21 19:37:31 +00:00
|
|
|
/* class to handle the printable name and the keycode
|
2007-08-30 08:15:05 +00:00
|
|
|
*/
|
|
|
|
struct hotkey_name_descr
|
|
|
|
{
|
2007-10-31 08:34:05 +00:00
|
|
|
const wxChar* m_Name;
|
2007-08-30 08:15:05 +00:00
|
|
|
int m_KeyCode;
|
2007-08-21 19:37:31 +00:00
|
|
|
};
|
|
|
|
|
2007-09-06 11:52:26 +00:00
|
|
|
|
|
|
|
static struct hotkey_name_descr s_Hotkey_Name_List[] =
|
2007-08-30 08:15:05 +00:00
|
|
|
{
|
2007-09-22 14:31:20 +00:00
|
|
|
{ wxT( "F1" ), WXK_F1 },
|
|
|
|
{ wxT( "F2" ), WXK_F2 },
|
|
|
|
{ wxT( "F3" ), WXK_F3 },
|
|
|
|
{ wxT( "F4" ), WXK_F4 },
|
|
|
|
{ wxT( "F5" ), WXK_F5 },
|
|
|
|
{ wxT( "F6" ), WXK_F6 },
|
|
|
|
{ wxT( "F7" ), WXK_F7 },
|
|
|
|
{ wxT( "F8" ), WXK_F8 },
|
|
|
|
{ wxT( "F9" ), WXK_F9 },
|
|
|
|
{ wxT( "F10" ), WXK_F10 },
|
|
|
|
{ wxT( "F11" ), WXK_F11 },
|
|
|
|
{ wxT( "F12" ), WXK_F12 },
|
|
|
|
|
|
|
|
{ wxT( "Esc" ), WXK_ESCAPE },
|
|
|
|
{ wxT( "Delete" ), WXK_DELETE },
|
|
|
|
{ wxT( "Tab" ), '\t' },
|
2007-08-30 08:15:05 +00:00
|
|
|
{ wxT( "Backspace" ), WXK_BACK },
|
2007-09-22 14:31:20 +00:00
|
|
|
{ wxT( "Insert" ), WXK_INSERT },
|
2007-08-30 08:15:05 +00:00
|
|
|
|
2009-09-27 14:09:26 +00:00
|
|
|
{ wxT( "Home" ), WXK_HOME },
|
2007-09-22 14:31:20 +00:00
|
|
|
{ wxT( "End" ), WXK_END },
|
|
|
|
{ wxT( "Page Up" ), WXK_PAGEUP },
|
2007-08-30 08:15:05 +00:00
|
|
|
{ wxT( "Page Down" ), WXK_PAGEDOWN },
|
2007-12-11 06:35:52 +00:00
|
|
|
{ wxT( "+" ), '+' },
|
|
|
|
{ wxT( "-" ), '-' },
|
2007-09-22 14:31:20 +00:00
|
|
|
|
|
|
|
{ wxT( "Up" ), WXK_UP },
|
|
|
|
{ wxT( "Down" ), WXK_DOWN },
|
|
|
|
{ wxT( "Left" ), WXK_LEFT },
|
|
|
|
{ wxT( "Right" ), WXK_RIGHT },
|
|
|
|
|
|
|
|
{ wxT( "space" ), ' ' },
|
|
|
|
{ wxT( "?" ), '?' },
|
|
|
|
{ wxT( "!" ), '!' },
|
|
|
|
{ wxT( ":" ), ':' },
|
|
|
|
{ wxT( "," ), ',' },
|
|
|
|
{ wxT( "*" ), '*' },
|
|
|
|
{ wxT( "+" ), '+' },
|
|
|
|
{ wxT( "-" ), '-' },
|
2009-05-21 17:42:42 +00:00
|
|
|
{ wxT( "%%" ), '%' },
|
2007-09-22 14:31:20 +00:00
|
|
|
{ wxT( "A" ), 'A' },
|
|
|
|
{ wxT( "B" ), 'B' },
|
|
|
|
{ wxT( "C" ), 'C' },
|
|
|
|
{ wxT( "D" ), 'D' },
|
|
|
|
{ wxT( "E" ), 'E' },
|
|
|
|
{ wxT( "F" ), 'F' },
|
|
|
|
{ wxT( "G" ), 'G' },
|
|
|
|
{ wxT( "H" ), 'H' },
|
|
|
|
{ wxT( "I" ), 'I' },
|
|
|
|
{ wxT( "J" ), 'J' },
|
|
|
|
{ wxT( "K" ), 'K' },
|
|
|
|
{ wxT( "L" ), 'L' },
|
|
|
|
{ wxT( "M" ), 'M' },
|
|
|
|
{ wxT( "N" ), 'N' },
|
|
|
|
{ wxT( "O" ), 'O' },
|
|
|
|
{ wxT( "P" ), 'P' },
|
|
|
|
{ wxT( "Q" ), 'Q' },
|
|
|
|
{ wxT( "R" ), 'R' },
|
|
|
|
{ wxT( "S" ), 'S' },
|
|
|
|
{ wxT( "T" ), 'T' },
|
|
|
|
{ wxT( "U" ), 'U' },
|
|
|
|
{ wxT( "V" ), 'V' },
|
|
|
|
{ wxT( "W" ), 'W' },
|
|
|
|
{ wxT( "X" ), 'X' },
|
|
|
|
{ wxT( "Y" ), 'Y' },
|
|
|
|
{ wxT( "Z" ), 'Z' },
|
|
|
|
|
|
|
|
{ wxT( "Ctrl A" ), GR_KB_CTRL + 'A' },
|
|
|
|
{ wxT( "Ctrl B" ), GR_KB_CTRL + 'B' },
|
|
|
|
{ wxT( "Ctrl C" ), GR_KB_CTRL + 'C' },
|
|
|
|
{ wxT( "Ctrl D" ), GR_KB_CTRL + 'D' },
|
|
|
|
{ wxT( "Ctrl E" ), GR_KB_CTRL + 'E' },
|
|
|
|
{ wxT( "Ctrl F" ), GR_KB_CTRL + 'F' },
|
|
|
|
{ wxT( "Ctrl G" ), GR_KB_CTRL + 'G' },
|
|
|
|
{ wxT( "Ctrl H" ), GR_KB_CTRL + 'H' },
|
|
|
|
{ wxT( "Ctrl I" ), GR_KB_CTRL + 'I' },
|
|
|
|
{ wxT( "Ctrl J" ), GR_KB_CTRL + 'J' },
|
|
|
|
{ wxT( "Ctrl K" ), GR_KB_CTRL + 'K' },
|
|
|
|
{ wxT( "Ctrl L" ), GR_KB_CTRL + 'L' },
|
|
|
|
{ wxT( "Ctrl M" ), GR_KB_CTRL + 'M' },
|
|
|
|
{ wxT( "Ctrl N" ), GR_KB_CTRL + 'N' },
|
|
|
|
{ wxT( "Ctrl O" ), GR_KB_CTRL + 'O' },
|
|
|
|
{ wxT( "Ctrl P" ), GR_KB_CTRL + 'P' },
|
|
|
|
{ wxT( "Ctrl Q" ), GR_KB_CTRL + 'Q' },
|
|
|
|
{ wxT( "Ctrl R" ), GR_KB_CTRL + 'R' },
|
|
|
|
{ wxT( "Ctrl S" ), GR_KB_CTRL + 'S' },
|
|
|
|
{ wxT( "Ctrl T" ), GR_KB_CTRL + 'T' },
|
|
|
|
{ wxT( "Ctrl U" ), GR_KB_CTRL + 'U' },
|
|
|
|
{ wxT( "Ctrl V" ), GR_KB_CTRL + 'V' },
|
|
|
|
{ wxT( "Ctrl W" ), GR_KB_CTRL + 'W' },
|
|
|
|
{ wxT( "Ctrl X" ), GR_KB_CTRL + 'X' },
|
|
|
|
{ wxT( "Ctrl Y" ), GR_KB_CTRL + 'Y' },
|
|
|
|
{ wxT( "Ctrl Z" ), GR_KB_CTRL + 'Z' },
|
|
|
|
|
|
|
|
{ wxT( "" ), 0 } // Do not change: end of list
|
2007-08-21 19:37:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-08-20 11:33:45 +00:00
|
|
|
/*
|
2007-08-30 08:15:05 +00:00
|
|
|
* return the key name from the key code
|
2009-11-23 15:16:50 +00:00
|
|
|
* Only some wxWidgets key values are handled for function key ( see
|
|
|
|
* s_Hotkey_Name_List[] )
|
2007-08-30 08:15:05 +00:00
|
|
|
* @param key = key code (ascii value, or wxWidgets value for function keys)
|
|
|
|
* @return the key name in a wxString
|
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
wxString ReturnKeyNameFromKeyCode( int keycode )
|
2007-08-20 11:33:45 +00:00
|
|
|
{
|
2007-08-30 08:15:05 +00:00
|
|
|
wxString keyname, modifier, fullkeyname;
|
|
|
|
int ii;
|
|
|
|
|
|
|
|
if( (keycode & GR_KB_CTRL) != 0 )
|
|
|
|
modifier << wxT( "Ctrl " );
|
|
|
|
if( (keycode & GR_KB_ALT) != 0 )
|
|
|
|
modifier << wxT( "Alt " );
|
|
|
|
if( (keycode & GR_KB_SHIFT) != 0 )
|
|
|
|
modifier << wxT( "Shift " );
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
keycode &= ~( GR_KB_CTRL | GR_KB_ALT | GR_KB_SHIFT );
|
2007-08-30 08:15:05 +00:00
|
|
|
for( ii = 0; ; ii++ )
|
|
|
|
{
|
|
|
|
if( s_Hotkey_Name_List[ii].m_KeyCode == 0 )
|
|
|
|
{
|
|
|
|
keyname = wxT( "<unknown>" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if( s_Hotkey_Name_List[ii].m_KeyCode == keycode )
|
|
|
|
{
|
|
|
|
keyname = s_Hotkey_Name_List[ii].m_Name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fullkeyname = modifier + keyname;
|
|
|
|
return fullkeyname;
|
2007-08-21 19:37:31 +00:00
|
|
|
}
|
2007-08-20 11:33:45 +00:00
|
|
|
|
2007-08-30 08:15:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Add the key name from the Command id value ( m_Idcommand member value)
|
|
|
|
* @param List = pointer to a Ki_HotkeyInfo list of commands
|
|
|
|
* @param CommandId = Command Id value
|
|
|
|
* @return text (key name) in a wxString if found or text without modification
|
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
wxString AddHotkeyName( const wxString& text, Ki_HotkeyInfo** List,
|
|
|
|
int CommandId )
|
2007-08-30 08:15:05 +00:00
|
|
|
{
|
|
|
|
wxString msg = text;
|
|
|
|
wxString keyname = ReturnKeyNameFromCommandId( List, CommandId );
|
|
|
|
|
|
|
|
if( !keyname.IsEmpty() )
|
|
|
|
msg << wxT( " (" ) << keyname << wxT( ")" );
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-06 11:52:26 +00:00
|
|
|
/*
|
|
|
|
* Add the key name from the Command id value ( m_Idcommand member value)
|
2009-11-23 15:16:50 +00:00
|
|
|
* @param List = pointer to a Ki_HotkeyInfoSectionDescriptor* DescrList of
|
|
|
|
* commands
|
2007-09-06 11:52:26 +00:00
|
|
|
* @param CommandId = Command Id value
|
|
|
|
* @return text (key name) in a wxString if found or text without modification
|
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
wxString AddHotkeyName( const wxString& text,
|
|
|
|
struct Ki_HotkeyInfoSectionDescriptor* DescList,
|
|
|
|
int CommandId )
|
2007-09-06 11:52:26 +00:00
|
|
|
{
|
2007-09-19 15:29:50 +00:00
|
|
|
wxString msg = text;
|
2007-09-06 11:52:26 +00:00
|
|
|
wxString keyname;
|
|
|
|
Ki_HotkeyInfo** List;
|
|
|
|
|
|
|
|
for( ; DescList->m_HK_InfoList != NULL; DescList++ )
|
|
|
|
{
|
|
|
|
List = DescList->m_HK_InfoList;
|
|
|
|
keyname = ReturnKeyNameFromCommandId( List, CommandId );
|
|
|
|
if( !keyname.IsEmpty() )
|
|
|
|
{
|
|
|
|
msg << wxT( " (" ) << keyname << wxT( ")" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-30 08:15:05 +00:00
|
|
|
/*
|
|
|
|
* return the key name from the Command id value ( m_Idcommand member value)
|
|
|
|
* @param List = pointer to a Ki_HotkeyInfo list of commands
|
|
|
|
* @param CommandId = Command Id value
|
|
|
|
* @return the key name in a wxString
|
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
wxString ReturnKeyNameFromCommandId( Ki_HotkeyInfo** List, int CommandId )
|
2007-08-30 08:15:05 +00:00
|
|
|
{
|
|
|
|
wxString keyname;
|
|
|
|
|
|
|
|
for( ; *List != NULL; List++ )
|
|
|
|
{
|
|
|
|
Ki_HotkeyInfo* hk_decr = *List;
|
|
|
|
if( hk_decr->m_Idcommand == CommandId )
|
|
|
|
{
|
|
|
|
keyname = ReturnKeyNameFromKeyCode( hk_decr->m_KeyCode );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return keyname;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-21 19:37:31 +00:00
|
|
|
/*
|
2007-08-30 08:15:05 +00:00
|
|
|
* return the key code from its key name
|
|
|
|
* Only some wxWidgets key values are handled for function key
|
2009-11-23 15:16:50 +00:00
|
|
|
* @param keyname = wxString key name to find in s_Hotkey_Name_List[],
|
|
|
|
* like F2 or space or an usual (ascii) char.
|
2007-08-30 08:15:05 +00:00
|
|
|
* @return the key code
|
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
static int ReturnKeyCodeFromKeyName( const wxString& keyname )
|
2007-08-21 19:37:31 +00:00
|
|
|
{
|
2007-08-30 08:15:05 +00:00
|
|
|
int ii, keycode = 0;
|
|
|
|
|
|
|
|
for( ii = 0; ; ii++ )
|
|
|
|
{
|
|
|
|
if( s_Hotkey_Name_List[ii].m_KeyCode == 0 ) // End of list reached
|
|
|
|
break;
|
2008-09-03 16:19:06 +00:00
|
|
|
|
2007-08-30 08:15:05 +00:00
|
|
|
if( keyname.CmpNoCase( s_Hotkey_Name_List[ii].m_Name ) == 0 )
|
|
|
|
{
|
|
|
|
keycode = s_Hotkey_Name_List[ii].m_KeyCode;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return keycode;
|
2007-08-20 11:33:45 +00:00
|
|
|
}
|
|
|
|
|
2007-08-30 08:15:05 +00:00
|
|
|
|
2007-08-20 11:33:45 +00:00
|
|
|
/*
|
2007-08-30 08:15:05 +00:00
|
|
|
* Displays the current hotkey list
|
2007-09-06 11:52:26 +00:00
|
|
|
* @param frame = current active frame
|
2009-11-23 15:16:50 +00:00
|
|
|
* @param List = pointer to a Ki_HotkeyInfoSectionDescriptor list
|
|
|
|
* (Null terminated)
|
2007-08-30 08:15:05 +00:00
|
|
|
* @return none
|
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void DisplayHotkeyList( WinEDA_DrawFrame* frame,
|
|
|
|
struct Ki_HotkeyInfoSectionDescriptor* DescList )
|
2007-08-20 11:33:45 +00:00
|
|
|
{
|
2007-09-06 11:52:26 +00:00
|
|
|
wxString keyname;
|
|
|
|
Ki_HotkeyInfo** List;
|
2007-08-30 08:15:05 +00:00
|
|
|
|
2007-09-06 11:52:26 +00:00
|
|
|
wxString msg = _( "Current hotkey list:\n\n" );
|
2007-08-30 08:15:05 +00:00
|
|
|
|
2007-09-06 11:52:26 +00:00
|
|
|
for( ; DescList->m_HK_InfoList != NULL; DescList++ )
|
2007-08-30 08:15:05 +00:00
|
|
|
{
|
2007-09-06 11:52:26 +00:00
|
|
|
List = DescList->m_HK_InfoList;
|
|
|
|
for( ; *List != NULL; List++ )
|
|
|
|
{
|
|
|
|
Ki_HotkeyInfo* hk_decr = *List;
|
|
|
|
msg += _( "key " );
|
|
|
|
keyname = ReturnKeyNameFromKeyCode( hk_decr->m_KeyCode );
|
|
|
|
msg += keyname + wxT( ": " ) + hk_decr->m_InfoMsg + wxT( "\n" );
|
|
|
|
}
|
2007-08-30 08:15:05 +00:00
|
|
|
}
|
|
|
|
|
2009-04-17 08:51:02 +00:00
|
|
|
DisplayInfoMessage( frame, msg );
|
2007-08-20 11:33:45 +00:00
|
|
|
}
|
|
|
|
|
2007-08-30 08:15:05 +00:00
|
|
|
|
2007-08-20 11:33:45 +00:00
|
|
|
/*
|
2007-09-22 14:31:20 +00:00
|
|
|
* Return a Ki_HotkeyInfo * pointer fron a key code for OnHotKey() function
|
2007-08-30 08:15:05 +00:00
|
|
|
* @param key = key code (ascii value, or wxWidgets value for function keys
|
|
|
|
* @param List = pointer to a Ki_HotkeyInfo list of commands
|
2009-11-23 15:16:50 +00:00
|
|
|
* @return the corresponding Ki_HotkeyInfo pointer from the Ki_HotkeyInfo List
|
2007-08-30 08:15:05 +00:00
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
Ki_HotkeyInfo* GetDescriptorFromHotkey( int key, Ki_HotkeyInfo** List )
|
2007-08-20 11:33:45 +00:00
|
|
|
{
|
2007-08-30 08:15:05 +00:00
|
|
|
for( ; *List != NULL; List++ )
|
|
|
|
{
|
|
|
|
Ki_HotkeyInfo* hk_decr = *List;
|
|
|
|
if( hk_decr->m_KeyCode == key )
|
2007-09-22 14:31:20 +00:00
|
|
|
return hk_decr;
|
2007-08-30 08:15:05 +00:00
|
|
|
}
|
|
|
|
|
2007-09-22 14:31:20 +00:00
|
|
|
return NULL;
|
2007-08-20 11:33:45 +00:00
|
|
|
}
|
|
|
|
|
2007-08-30 08:15:05 +00:00
|
|
|
|
2007-08-21 19:37:31 +00:00
|
|
|
/*
|
|
|
|
* Create a configuration file (*.key) from the current hotkey list
|
2009-11-23 15:16:50 +00:00
|
|
|
* @param Filename = default full file name to create. If void, A filename
|
|
|
|
* will be asked
|
2007-08-21 19:37:31 +00:00
|
|
|
* @param List = pointer to the current hotkey list.
|
|
|
|
* the ouput format is: shortcut "key" "function"
|
2007-09-19 15:29:50 +00:00
|
|
|
* lines starting with # are comments
|
2007-08-30 08:15:05 +00:00
|
|
|
*
|
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
int WinEDA_BasicFrame::WriteHotkeyConfigFile(
|
|
|
|
const wxString& Filename,
|
|
|
|
struct Ki_HotkeyInfoSectionDescriptor* DescList,
|
|
|
|
bool verbose )
|
2007-08-21 19:37:31 +00:00
|
|
|
{
|
2007-08-30 08:15:05 +00:00
|
|
|
wxString FullFilename = Filename;
|
|
|
|
FILE* cfgfile;
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
if( FullFilename.IsEmpty() || verbose )
|
|
|
|
{
|
|
|
|
wxString Mask, Path, Ext;
|
|
|
|
Ext = DEFAULT_HOTKEY_FILENAME_EXT;
|
2009-06-19 20:13:22 +00:00
|
|
|
Mask = wxT( "*." ) + Ext;
|
2007-09-19 15:29:50 +00:00
|
|
|
Path = ReturnHotkeyConfigFilePath( g_ConfigFileLocationChoice );
|
2009-02-21 15:12:26 +00:00
|
|
|
FullFilename = EDA_FileSelector( _( "Save Hotkey Configuration File:" ),
|
2009-11-23 15:16:50 +00:00
|
|
|
Path,
|
|
|
|
FullFilename,
|
|
|
|
Ext,
|
|
|
|
Mask,
|
2007-08-30 08:15:05 +00:00
|
|
|
this,
|
|
|
|
wxFD_SAVE,
|
2009-11-23 15:16:50 +00:00
|
|
|
TRUE );
|
2007-08-30 08:15:05 +00:00
|
|
|
}
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2007-08-30 08:15:05 +00:00
|
|
|
if( FullFilename.IsEmpty() )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cfgfile = wxFopen( FullFilename, wxT( "wt" ) );
|
|
|
|
|
|
|
|
if( cfgfile == NULL )
|
|
|
|
{
|
|
|
|
if( verbose )
|
|
|
|
{
|
|
|
|
msg = _( "Unable to create " ) + FullFilename;
|
|
|
|
DisplayError( this, msg );
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString keyname, infokey;
|
|
|
|
|
|
|
|
msg = wxT( "$hotkey list\n" );
|
2009-10-05 04:22:27 +00:00
|
|
|
fprintf( cfgfile, "%s", CONV_TO_UTF8( msg ) );
|
2007-08-30 08:15:05 +00:00
|
|
|
|
|
|
|
/* print the allowed keys, for info
|
|
|
|
*/
|
|
|
|
msg = wxT( "# " ); msg += _( "Allowed keys:\n" );
|
2009-10-05 04:22:27 +00:00
|
|
|
fprintf( cfgfile, "%s", CONV_TO_UTF8( msg ) );
|
2007-08-30 08:15:05 +00:00
|
|
|
msg.Empty();
|
|
|
|
for( int ii = 0; ; ii++ )
|
|
|
|
{
|
|
|
|
if( s_Hotkey_Name_List[ii].m_KeyCode == 0 )
|
|
|
|
break;;
|
|
|
|
if( msg.IsEmpty() )
|
|
|
|
msg = wxT( "# " );
|
|
|
|
else
|
|
|
|
msg += wxT( ", " );
|
|
|
|
msg += s_Hotkey_Name_List[ii].m_Name;
|
|
|
|
if( msg.Len() > 60 )
|
|
|
|
{
|
|
|
|
msg += wxT( "\n" );
|
2009-10-05 04:22:27 +00:00
|
|
|
fprintf( cfgfile, "%s", CONV_TO_UTF8( msg ) );
|
2007-08-30 08:15:05 +00:00
|
|
|
msg.Empty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-06 11:52:26 +00:00
|
|
|
/* print the last line of the info section */
|
2007-08-30 08:15:05 +00:00
|
|
|
if( !msg.IsEmpty() )
|
|
|
|
msg += wxT( "\n" );
|
|
|
|
msg += wxT( "#\n#\n" );
|
2009-10-05 04:22:27 +00:00
|
|
|
fprintf( cfgfile, "%s", CONV_TO_UTF8( msg ) );
|
2007-08-30 08:15:05 +00:00
|
|
|
|
2007-09-06 11:52:26 +00:00
|
|
|
/* Print the current hotkey list */
|
|
|
|
Ki_HotkeyInfo** List;
|
|
|
|
for( ; DescList->m_HK_InfoList != NULL; DescList++ )
|
2007-08-30 08:15:05 +00:00
|
|
|
{
|
2007-09-06 11:52:26 +00:00
|
|
|
if( DescList->m_Comment )
|
|
|
|
{
|
|
|
|
fprintf( cfgfile, "# " );
|
2009-10-05 04:22:27 +00:00
|
|
|
fprintf( cfgfile, "%s\n", DescList->m_Comment );
|
2007-09-06 11:52:26 +00:00
|
|
|
}
|
2007-09-19 15:29:50 +00:00
|
|
|
msg = *DescList->m_SectionTag;
|
2009-10-05 04:22:27 +00:00
|
|
|
fprintf( cfgfile, "%s\n", CONV_TO_UTF8( msg ) );
|
2007-09-06 11:52:26 +00:00
|
|
|
List = DescList->m_HK_InfoList;
|
|
|
|
for( ; *List != NULL; List++ )
|
|
|
|
{
|
|
|
|
Ki_HotkeyInfo* hk_decr = *List;
|
|
|
|
msg = wxT( "shortcut " );
|
|
|
|
keyname = ReturnKeyNameFromKeyCode( hk_decr->m_KeyCode );
|
|
|
|
AddDelimiterString( keyname );
|
|
|
|
infokey = hk_decr->m_InfoMsg;
|
|
|
|
AddDelimiterString( infokey );
|
|
|
|
msg += keyname + wxT( ": " ) + infokey + wxT( "\n" );
|
2009-10-05 04:22:27 +00:00
|
|
|
fprintf( cfgfile, "%s", CONV_TO_UTF8( msg ) );
|
2007-09-06 11:52:26 +00:00
|
|
|
}
|
2007-08-30 08:15:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
msg = wxT( "$Endlist\n" );
|
2009-10-05 04:22:27 +00:00
|
|
|
fprintf( cfgfile, "%s\n", CONV_TO_UTF8( msg ) );
|
2007-08-30 08:15:05 +00:00
|
|
|
fclose( cfgfile );
|
|
|
|
return 1;
|
2007-08-21 19:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-11-23 15:16:50 +00:00
|
|
|
* Read a configuration file (<file>.key) and fill the current hotkey list
|
|
|
|
* with hotkeys
|
|
|
|
* @param Filename = default full file name to create. If void, A filename
|
|
|
|
* will be asked
|
2007-09-06 11:52:26 +00:00
|
|
|
* @param DescList = current hotkey list descr. to initialise.
|
2007-08-21 19:37:31 +00:00
|
|
|
* the input format is: shortcut "key" "function"
|
|
|
|
* lines starting by # are ignored (comments)
|
2009-11-23 15:16:50 +00:00
|
|
|
* lines like [xxx] are tags (example: [common] or [libedit] which identify
|
|
|
|
* sections
|
2007-08-30 08:15:05 +00:00
|
|
|
*
|
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
int WinEDA_BasicFrame::ReadHotkeyConfigFile(
|
|
|
|
const wxString& Filename,
|
|
|
|
struct Ki_HotkeyInfoSectionDescriptor* DescList,
|
|
|
|
bool verbose )
|
2007-08-21 19:37:31 +00:00
|
|
|
{
|
2007-08-30 08:15:05 +00:00
|
|
|
wxString FullFilename = Filename;
|
|
|
|
FILE* cfgfile;
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
if( FullFilename.IsEmpty() || verbose )
|
|
|
|
{
|
|
|
|
wxString Mask, Path, Ext;
|
|
|
|
Ext = DEFAULT_HOTKEY_FILENAME_EXT;
|
2009-06-19 20:13:22 +00:00
|
|
|
Mask = wxT( "*." ) + Ext;
|
2007-09-19 15:29:50 +00:00
|
|
|
Path = ReturnHotkeyConfigFilePath( g_ConfigFileLocationChoice );
|
2009-02-21 15:12:26 +00:00
|
|
|
FullFilename = EDA_FileSelector( _( "Open Hotkey Configuration File:" ),
|
2009-11-23 15:16:50 +00:00
|
|
|
Path,
|
|
|
|
FullFilename,
|
|
|
|
Ext,
|
|
|
|
Mask,
|
2007-08-30 08:15:05 +00:00
|
|
|
this,
|
|
|
|
wxFD_OPEN,
|
2009-11-23 15:16:50 +00:00
|
|
|
TRUE );
|
2007-08-30 08:15:05 +00:00
|
|
|
if( FullFilename.IsEmpty() )
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cfgfile = wxFopen( FullFilename, wxT( "rt" ) );
|
|
|
|
|
|
|
|
if( cfgfile == NULL )
|
|
|
|
{
|
|
|
|
if( verbose )
|
|
|
|
{
|
|
|
|
msg = _( "Unable to read " ) + FullFilename;
|
|
|
|
DisplayError( this, msg );
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-09-06 11:52:26 +00:00
|
|
|
wxString keyname;
|
|
|
|
char Line[1024];
|
|
|
|
int LineNum = 0;
|
|
|
|
Ki_HotkeyInfo** CurrentHotkeyList = NULL;
|
|
|
|
|
2007-08-30 08:15:05 +00:00
|
|
|
/* Read the file */
|
2007-08-21 19:37:31 +00:00
|
|
|
while( GetLine( cfgfile, Line, &LineNum ) != NULL )
|
|
|
|
{
|
2007-08-30 08:15:05 +00:00
|
|
|
char* line_type, * keyname, * fctname;
|
|
|
|
line_type = strtok( Line, " \t\n\r" );
|
|
|
|
msg = CONV_FROM_UTF8( line_type );
|
2007-09-06 11:52:26 +00:00
|
|
|
if( msg[0] == '[' ) // A tag is found. search infos in list
|
|
|
|
{
|
|
|
|
CurrentHotkeyList = NULL;
|
|
|
|
Ki_HotkeyInfoSectionDescriptor* DList = DescList;
|
|
|
|
for( ; DList->m_HK_InfoList != NULL; DList++ )
|
|
|
|
{
|
|
|
|
if( *DList->m_SectionTag == msg )
|
|
|
|
{
|
|
|
|
CurrentHotkeyList = DList->m_HK_InfoList;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
2007-08-30 08:15:05 +00:00
|
|
|
if( msg != wxT( "shortcut" ) )
|
|
|
|
continue;
|
|
|
|
if( msg == wxT( "$Endlist" ) )
|
|
|
|
break;
|
2007-09-06 11:52:26 +00:00
|
|
|
if( CurrentHotkeyList == NULL )
|
|
|
|
continue;
|
2007-08-30 08:15:05 +00:00
|
|
|
|
|
|
|
/* Get the key name */
|
|
|
|
strtok( NULL, "\"\n\r" );
|
|
|
|
keyname = strtok( NULL, "\"\n\r" );
|
2008-09-03 16:19:06 +00:00
|
|
|
|
2007-08-30 08:15:05 +00:00
|
|
|
strtok( NULL, "\"\n\r" );
|
2008-09-03 16:19:06 +00:00
|
|
|
|
2007-08-30 08:15:05 +00:00
|
|
|
/* Get the command name */
|
|
|
|
fctname = strtok( NULL, "\"\n\r" );
|
|
|
|
msg = CONV_FROM_UTF8( fctname );
|
2008-09-03 16:19:06 +00:00
|
|
|
|
2007-08-30 08:15:05 +00:00
|
|
|
/* search the hotkey in current hotkey list */
|
|
|
|
for( Ki_HotkeyInfo** List = CurrentHotkeyList; *List != NULL; List++ )
|
|
|
|
{
|
|
|
|
Ki_HotkeyInfo* hk_decr = *List;
|
|
|
|
if( hk_decr->m_InfoMsg == msg )
|
|
|
|
{
|
|
|
|
msg = CONV_FROM_UTF8( keyname );
|
2008-09-03 16:19:06 +00:00
|
|
|
|
2007-08-30 08:15:05 +00:00
|
|
|
int code = ReturnKeyCodeFromKeyName( msg );
|
|
|
|
if( code )
|
|
|
|
hk_decr->m_KeyCode = code;
|
2008-09-03 16:19:06 +00:00
|
|
|
|
2007-08-30 08:15:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose( cfgfile );
|
|
|
|
return 1;
|
2007-08-21 19:37:31 +00:00
|
|
|
}
|
2007-09-19 15:29:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* return the hotkey config file path
|
2008-09-03 16:19:06 +00:00
|
|
|
* @param choice : 0 = home, 1 = kicad/share/template
|
2007-09-19 15:29:50 +00:00
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
wxString ReturnHotkeyConfigFilePath( int choice )
|
2007-09-19 15:29:50 +00:00
|
|
|
{
|
|
|
|
wxString path;
|
2009-04-06 18:54:57 +00:00
|
|
|
wxAppTraits* traits = wxGetApp().GetTraits();
|
2007-09-19 15:29:50 +00:00
|
|
|
|
|
|
|
switch( choice )
|
|
|
|
{
|
|
|
|
case 0:
|
2009-04-06 18:54:57 +00:00
|
|
|
path = traits->GetStandardPaths().GetUserConfigDir() +
|
|
|
|
wxFileName::GetPathSeparator();
|
2007-09-19 15:29:50 +00:00
|
|
|
|
|
|
|
case 1:
|
2009-04-06 18:54:57 +00:00
|
|
|
/* TODO: This is broken under a normal Poxis system. Users
|
|
|
|
* generally do no have write permissions to this path
|
|
|
|
* and there is no provision for prompting for the root
|
|
|
|
* password. Suggest we remove this unless someone has
|
|
|
|
* a workable solution (Wayne).
|
|
|
|
*/
|
2008-09-03 16:19:06 +00:00
|
|
|
path = ReturnKicadDatasPath() + wxT( "template/" );
|
2007-09-19 15:29:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-27 13:48:24 +00:00
|
|
|
/** add hotkey config options submenu to a menu
|
2007-11-14 16:02:19 +00:00
|
|
|
* @param menu : initial menu
|
2007-09-19 15:29:50 +00:00
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void AddHotkeyConfigMenu( wxMenu* menu )
|
2007-09-19 15:29:50 +00:00
|
|
|
{
|
|
|
|
wxMenuItem* item;
|
2009-10-27 13:48:24 +00:00
|
|
|
wxMenu* HotkeySubmenu = new wxMenu();
|
2007-09-19 15:29:50 +00:00
|
|
|
|
|
|
|
if( menu == NULL )
|
|
|
|
return;
|
2007-11-14 16:02:19 +00:00
|
|
|
|
2009-10-27 13:48:24 +00:00
|
|
|
/* Show hotkey configuration */
|
2009-11-23 15:16:50 +00:00
|
|
|
item = new wxMenuItem( HotkeySubmenu,
|
|
|
|
ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST,
|
2009-10-27 13:48:24 +00:00
|
|
|
_( "Show" ),
|
|
|
|
_( "Show the current hotkey configuration" ) );
|
2007-11-14 16:02:19 +00:00
|
|
|
item->SetBitmap( info_xpm );
|
2009-10-27 13:48:24 +00:00
|
|
|
HotkeySubmenu->Append( item );
|
2007-11-14 16:02:19 +00:00
|
|
|
|
2009-10-27 13:48:24 +00:00
|
|
|
/* (Re)create hotkey file */
|
|
|
|
item = new wxMenuItem( HotkeySubmenu, ID_PREFERENCES_HOTKEY_CREATE_CONFIG,
|
|
|
|
_( "(Re)create" ),
|
|
|
|
_( "Create or recreate the hotkey configuration file from current hotkey list" )
|
2007-09-22 14:31:20 +00:00
|
|
|
);
|
2007-09-19 15:29:50 +00:00
|
|
|
item->SetBitmap( save_setup_xpm );
|
2009-10-27 13:48:24 +00:00
|
|
|
HotkeySubmenu->Append( item );
|
2007-11-14 16:02:19 +00:00
|
|
|
|
2009-10-27 13:48:24 +00:00
|
|
|
/* Reload hotkey file */
|
|
|
|
item = new wxMenuItem( HotkeySubmenu, ID_PREFERENCES_HOTKEY_READ_CONFIG,
|
|
|
|
_( "Reload" ),
|
|
|
|
_( "Reload the hotkey configuration file" ) );
|
2007-09-19 15:29:50 +00:00
|
|
|
item->SetBitmap( reload_xpm );
|
2009-10-27 13:48:24 +00:00
|
|
|
HotkeySubmenu->Append( item );
|
|
|
|
|
|
|
|
/* Edit hotkey file */
|
|
|
|
item = new wxMenuItem( HotkeySubmenu, ID_PREFERENCES_HOTKEY_EDIT_CONFIG,
|
|
|
|
_( "Edit" ),
|
|
|
|
_( "Edit the hotkey configuration file in a text editor" ) );
|
2007-09-19 15:29:50 +00:00
|
|
|
item->SetBitmap( editor_xpm );
|
2009-10-27 13:48:24 +00:00
|
|
|
HotkeySubmenu->Append( item );
|
|
|
|
|
|
|
|
/* Append HotkeySubmenu to menu */
|
|
|
|
menu->Append( ID_PREFERENCES_HOTKEY_SUBMENU,
|
|
|
|
_("Hotkey"),
|
|
|
|
HotkeySubmenu,
|
|
|
|
_("Hotkey configuration and preferences"));
|
|
|
|
|
|
|
|
/* Hotkey path */
|
|
|
|
wxMenu* HotkeyLocationSubmenu = new wxMenu();
|
2007-09-19 15:29:50 +00:00
|
|
|
|
2009-10-27 13:48:24 +00:00
|
|
|
/* Home directory */
|
2009-11-23 15:16:50 +00:00
|
|
|
item = new wxMenuItem( HotkeyLocationSubmenu,
|
|
|
|
ID_PREFERENCES_HOTKEY_PATH_IS_HOME,
|
2009-10-27 13:48:24 +00:00
|
|
|
_( "Home directory" ),
|
2007-10-28 20:33:19 +00:00
|
|
|
_( "Use home directory to load or store Hotkey config files" ),
|
2007-09-22 14:31:20 +00:00
|
|
|
wxITEM_CHECK );
|
2009-10-27 13:48:24 +00:00
|
|
|
HotkeyLocationSubmenu->Append( item );
|
2007-09-19 15:29:50 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
/* KiCad template directory */
|
|
|
|
item = new wxMenuItem( HotkeyLocationSubmenu,
|
|
|
|
ID_PREFERENCES_HOTKEY_PATH_IS_KICAD,
|
2009-10-27 13:48:24 +00:00
|
|
|
_( "KiCad template directory" ),
|
2007-10-28 20:33:19 +00:00
|
|
|
_( "Use kicad/template directory to load or store Hotkey config files" ),
|
2007-09-22 14:31:20 +00:00
|
|
|
wxITEM_CHECK );
|
2009-10-27 13:48:24 +00:00
|
|
|
HotkeyLocationSubmenu->Append( item );
|
2007-09-19 15:29:50 +00:00
|
|
|
|
2009-10-27 13:48:24 +00:00
|
|
|
/* Append location submenu to HotkeySubmenu */
|
2009-11-23 15:16:50 +00:00
|
|
|
ADD_MENUITEM_WITH_HELP_AND_SUBMENU( HotkeySubmenu, HotkeyLocationSubmenu,
|
|
|
|
-1, _( "Location" ),
|
|
|
|
_( "Select hotkey configuration file location" ),
|
|
|
|
right_xpm );
|
2009-10-27 13:48:24 +00:00
|
|
|
HotkeyLocationSubmenu->Check( ID_PREFERENCES_HOTKEY_PATH_IS_HOME,
|
2009-11-23 15:16:50 +00:00
|
|
|
g_ConfigFileLocationChoice == 0 );
|
2009-10-27 13:48:24 +00:00
|
|
|
HotkeyLocationSubmenu->Check( ID_PREFERENCES_HOTKEY_PATH_IS_KICAD,
|
2009-11-23 15:16:50 +00:00
|
|
|
g_ConfigFileLocationChoice == 1 );
|
2007-09-19 15:29:50 +00:00
|
|
|
}
|
2007-09-20 05:41:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* called on hotkey file location selecton menu
|
2007-09-22 14:31:20 +00:00
|
|
|
* @param frame = current WinEDA_DrawFrame
|
|
|
|
* @param id = selected menu id
|
|
|
|
* @return g_ConfigFileLocationChoice (global) = new selection
|
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void HandleHotkeyConfigMenuSelection( WinEDA_DrawFrame* frame, int id )
|
2007-09-20 05:41:40 +00:00
|
|
|
{
|
2007-09-22 14:31:20 +00:00
|
|
|
wxMenuBar* menu = frame->GetMenuBar();
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
wxConfig* config = wxGetApp().m_EDA_CommonConfig;
|
2007-09-22 14:31:20 +00:00
|
|
|
|
|
|
|
switch( id )
|
|
|
|
{
|
|
|
|
case ID_PREFERENCES_HOTKEY_PATH_IS_HOME:
|
|
|
|
if( g_ConfigFileLocationChoice != 0 )
|
|
|
|
{
|
|
|
|
g_ConfigFileLocationChoice = 0;
|
|
|
|
menu->Check( ID_PREFERENCES_HOTKEY_PATH_IS_HOME, true );
|
|
|
|
menu->Check( ID_PREFERENCES_HOTKEY_PATH_IS_KICAD, false );
|
2008-12-08 15:27:13 +00:00
|
|
|
config->Write( HOTKEY_CFG_PATH_OPT, g_ConfigFileLocationChoice );
|
2007-09-22 14:31:20 +00:00
|
|
|
}
|
|
|
|
break;
|
2007-09-20 05:41:40 +00:00
|
|
|
|
2007-09-22 14:31:20 +00:00
|
|
|
case ID_PREFERENCES_HOTKEY_PATH_IS_KICAD:
|
|
|
|
if( g_ConfigFileLocationChoice != 1 )
|
|
|
|
{
|
|
|
|
g_ConfigFileLocationChoice = 1;
|
|
|
|
menu->Check( ID_PREFERENCES_HOTKEY_PATH_IS_HOME, false );
|
|
|
|
menu->Check( ID_PREFERENCES_HOTKEY_PATH_IS_KICAD, true );
|
2008-12-08 15:27:13 +00:00
|
|
|
config->Write( HOTKEY_CFG_PATH_OPT, g_ConfigFileLocationChoice );
|
2007-09-22 14:31:20 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|