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"
|
2010-08-28 18:02:24 +00:00
|
|
|
#include "dialog_hotkeys_editor.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>
|
2010-08-28 18:02:24 +00:00
|
|
|
#include <wx/tokenzr.h>
|
2009-04-06 18:54:57 +00:00
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
#define HOTKEYS_CONFIG_KEY wxT( "Keys" )
|
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
|
|
|
|
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
|
|
|
{
|
2010-01-20 18:59:46 +00:00
|
|
|
m_KeyCode = keycode; // Key code (ascii value for ascii keys
|
|
|
|
// or wxWidgets code for function key
|
|
|
|
m_InfoMsg = infomsg; // info message.
|
|
|
|
m_Idcommand = idcommand; // internal id for the corresponding
|
|
|
|
// command (see hotkey_id_commnand list)
|
2009-11-23 15:16:50 +00:00
|
|
|
m_IdMenuEvent = idmenuevent; // id to call the corresponding event
|
2010-01-20 18:59:46 +00:00
|
|
|
// (if any) (see id.h)
|
2007-08-20 11:33:45 +00:00
|
|
|
}
|
|
|
|
|
2007-08-30 08:15:05 +00:00
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
Ki_HotkeyInfo::Ki_HotkeyInfo( const Ki_HotkeyInfo* base )
|
|
|
|
{
|
|
|
|
m_KeyCode = base->m_KeyCode;
|
|
|
|
m_InfoMsg = base->m_InfoMsg;
|
|
|
|
m_Idcommand = base->m_Idcommand;
|
|
|
|
m_IdMenuEvent = base->m_IdMenuEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2010-01-20 18:59:46 +00:00
|
|
|
int m_KeyCode;
|
2007-08-21 19:37:31 +00:00
|
|
|
};
|
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
/* table giving the hotkey name from the hotkey code, for special keys
|
|
|
|
* Note : when modifiers (ATL, SHIFT, CTRL) do not modify
|
|
|
|
* the code of the key, do need to enter the modified key code
|
|
|
|
* For instance wxT( "F1" ), WXK_F1 handle F1, AltF1, CtrlF1 ...
|
2010-08-29 16:36:52 +00:00
|
|
|
* Key names are:
|
|
|
|
* "Space","Ctrl+Space","Alt+Space" or
|
|
|
|
* "Alt+A","Ctrl+F1", ...
|
2010-08-28 18:02:24 +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
|
|
|
{
|
2010-08-28 18:02:24 +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( "Del" ), WXK_DELETE },
|
2010-08-29 16:36:52 +00:00
|
|
|
{ wxT( "Tab" ), WXK_TAB },
|
2010-08-28 18:02:24 +00:00
|
|
|
{ wxT( "BkSp" ), WXK_BACK },
|
|
|
|
{ wxT( "Ins" ), WXK_INSERT },
|
|
|
|
|
|
|
|
{ wxT( "Home" ), WXK_HOME },
|
|
|
|
{ wxT( "End" ), WXK_END },
|
|
|
|
{ wxT( "PgUp" ), WXK_PAGEUP },
|
|
|
|
{ wxT( "PgDn" ), WXK_PAGEDOWN },
|
|
|
|
|
|
|
|
{ wxT( "Up" ), WXK_UP },
|
|
|
|
{ wxT( "Down" ), WXK_DOWN },
|
|
|
|
{ wxT( "Left" ), WXK_LEFT },
|
|
|
|
{ wxT( "Right" ), WXK_RIGHT },
|
2010-01-20 18:59:46 +00:00
|
|
|
|
2010-08-29 16:36:52 +00:00
|
|
|
{ wxT( "Space" ), WXK_SPACE },
|
|
|
|
|
2010-01-20 18:59:46 +00:00
|
|
|
// Do not change this line: end of list
|
2010-08-28 18:02:24 +00:00
|
|
|
{ wxT( "" ), 0 }
|
2007-08-21 19:37:31 +00:00
|
|
|
};
|
|
|
|
|
2010-08-28 19:08:58 +00:00
|
|
|
#define MODIFIER_CTRL wxT( "Ctrl+" )
|
|
|
|
#define MODIFIER_ALT wxT( "Alt+" )
|
|
|
|
#define MODIFIER_SHIFT wxT( "Shift+" )
|
|
|
|
|
2007-08-21 19:37:31 +00:00
|
|
|
|
2010-01-19 20:43:44 +00:00
|
|
|
/** function ReturnKeyNameFromKeyCode
|
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[] )
|
2010-02-16 10:42:57 +00:00
|
|
|
* @param aKeycode = key code (ascii value, or wxWidgets value for function keys)
|
2010-08-28 18:02:24 +00:00
|
|
|
* @param aIsFound = a pointer to a bool to return true if found, or false. an be NULL default)
|
2007-08-30 08:15:05 +00:00
|
|
|
* @return the key name in a wxString
|
|
|
|
*/
|
2010-08-28 18:02:24 +00:00
|
|
|
wxString ReturnKeyNameFromKeyCode( int aKeycode, bool* aIsFound )
|
2007-08-20 11:33:45 +00:00
|
|
|
{
|
2007-08-30 08:15:05 +00:00
|
|
|
wxString keyname, modifier, fullkeyname;
|
|
|
|
int ii;
|
2010-08-28 18:02:24 +00:00
|
|
|
bool found = false;
|
2007-08-30 08:15:05 +00:00
|
|
|
|
2010-02-16 10:42:57 +00:00
|
|
|
if( (aKeycode & GR_KB_CTRL) != 0 )
|
2010-08-28 19:08:58 +00:00
|
|
|
modifier << MODIFIER_CTRL;
|
2010-02-16 10:42:57 +00:00
|
|
|
if( (aKeycode & GR_KB_ALT) != 0 )
|
2010-08-28 19:08:58 +00:00
|
|
|
modifier << MODIFIER_ALT;
|
2010-02-16 10:42:57 +00:00
|
|
|
if( (aKeycode & GR_KB_SHIFT) != 0 )
|
2010-08-28 19:08:58 +00:00
|
|
|
modifier << MODIFIER_SHIFT;
|
2007-08-30 08:15:05 +00:00
|
|
|
|
2010-02-16 10:42:57 +00:00
|
|
|
aKeycode &= ~( GR_KB_CTRL | GR_KB_ALT | GR_KB_SHIFT );
|
2010-08-28 18:02:24 +00:00
|
|
|
|
2010-08-29 16:36:52 +00:00
|
|
|
if( (aKeycode > ' ') && (aKeycode < 0x7F ) )
|
2007-08-30 08:15:05 +00:00
|
|
|
{
|
2010-08-28 18:02:24 +00:00
|
|
|
found = true;
|
|
|
|
keyname.Append((wxChar)aKeycode);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( ii = 0; ; ii++ )
|
2007-08-30 08:15:05 +00:00
|
|
|
{
|
2010-08-28 18:02:24 +00:00
|
|
|
if( s_Hotkey_Name_List[ii].m_KeyCode == 0 ) // End of list
|
|
|
|
{
|
|
|
|
keyname = wxT( "<unknown>" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if( s_Hotkey_Name_List[ii].m_KeyCode == aKeycode )
|
|
|
|
{
|
|
|
|
keyname = s_Hotkey_Name_List[ii].m_Name;
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
2007-08-30 08:15:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
if( aIsFound )
|
|
|
|
*aIsFound = found;
|
2007-08-30 08:15:05 +00:00
|
|
|
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
|
|
|
|
2010-01-19 20:43:44 +00:00
|
|
|
/** function AddHotkeyName
|
2007-08-30 08:15:05 +00:00
|
|
|
* Add the key name from the Command id value ( m_Idcommand member value)
|
2010-02-16 10:42:57 +00:00
|
|
|
* @param aText = a wxString. returns aText + key name
|
|
|
|
* @param aList = pointer to a Ki_HotkeyInfo list of commands
|
|
|
|
* @param aCommandId = Command Id value
|
|
|
|
* @param aIsShortCut = true to add <tab><keyname> (active shortcuts in menus)
|
|
|
|
* = false to add <spaces><(keyname)>
|
|
|
|
* @return a wxString (aTest + key name) if key found or aText without modification
|
2007-08-30 08:15:05 +00:00
|
|
|
*/
|
2010-02-14 18:14:33 +00:00
|
|
|
wxString AddHotkeyName( const wxString& aText, Ki_HotkeyInfo** aList,
|
2010-08-28 18:02:24 +00:00
|
|
|
int aCommandId, bool aIsShortCut )
|
2007-08-30 08:15:05 +00:00
|
|
|
{
|
2010-08-28 18:02:24 +00:00
|
|
|
wxString msg = aText;
|
2010-02-14 18:14:33 +00:00
|
|
|
wxString keyname;
|
2010-08-28 18:02:24 +00:00
|
|
|
|
2010-02-14 18:14:33 +00:00
|
|
|
if( aList )
|
|
|
|
keyname = ReturnKeyNameFromCommandId( aList, aCommandId );
|
2007-08-30 08:15:05 +00:00
|
|
|
|
|
|
|
if( !keyname.IsEmpty() )
|
2010-02-16 10:42:57 +00:00
|
|
|
{
|
2010-08-28 18:02:24 +00:00
|
|
|
if( aIsShortCut )
|
2010-02-16 10:42:57 +00:00
|
|
|
msg << wxT( "\t" ) << keyname;
|
|
|
|
else
|
2010-08-28 18:02:24 +00:00
|
|
|
msg << wxT( " <" ) << keyname << wxT( ">" );
|
2010-02-16 10:42:57 +00:00
|
|
|
}
|
2007-08-30 08:15:05 +00:00
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
|
2010-01-19 20:43:44 +00:00
|
|
|
/** function AddHotkeyName
|
2007-09-06 11:52:26 +00:00
|
|
|
* Add the key name from the Command id value ( m_Idcommand member value)
|
2010-02-16 10:42:57 +00:00
|
|
|
* @param aText = a wxString. returns aText + key name
|
|
|
|
* @param aList = pointer to a Ki_HotkeyInfoSectionDescriptor DescrList of commands
|
|
|
|
* @param aCommandId = Command Id value
|
|
|
|
* @param aIsShortCut = true to add <tab><keyname> (active shortcuts in menus)
|
|
|
|
* = false to add <spaces><(keyname)>
|
|
|
|
* @return a wxString (aTest + key name) if key found or aText without modification
|
2007-09-06 11:52:26 +00:00
|
|
|
*/
|
2010-02-14 18:14:33 +00:00
|
|
|
wxString AddHotkeyName( const wxString& aText,
|
|
|
|
struct Ki_HotkeyInfoSectionDescriptor* aDescList,
|
2010-02-16 10:42:57 +00:00
|
|
|
int aCommandId,
|
|
|
|
bool aIsShortCut )
|
2007-09-06 11:52:26 +00:00
|
|
|
{
|
2010-02-14 18:14:33 +00:00
|
|
|
wxString msg = aText;
|
2007-09-06 11:52:26 +00:00
|
|
|
wxString keyname;
|
|
|
|
Ki_HotkeyInfo** List;
|
|
|
|
|
2010-02-14 18:14:33 +00:00
|
|
|
if( aDescList )
|
2007-09-06 11:52:26 +00:00
|
|
|
{
|
2010-02-14 18:14:33 +00:00
|
|
|
for( ; aDescList->m_HK_InfoList != NULL; aDescList++ )
|
2007-09-06 11:52:26 +00:00
|
|
|
{
|
2010-02-14 18:14:33 +00:00
|
|
|
List = aDescList->m_HK_InfoList;
|
|
|
|
keyname = ReturnKeyNameFromCommandId( List, aCommandId );
|
|
|
|
if( !keyname.IsEmpty() )
|
|
|
|
{
|
2010-08-28 18:02:24 +00:00
|
|
|
if( aIsShortCut )
|
2010-02-16 10:42:57 +00:00
|
|
|
msg << wxT( "\t" ) << keyname;
|
|
|
|
else
|
2010-08-28 18:02:24 +00:00
|
|
|
msg << wxT( " <" ) << keyname << wxT( ">" );
|
2010-02-14 18:14:33 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-09-06 11:52:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-19 20:43:44 +00:00
|
|
|
/** function ReturnKeyNameFromCommandId
|
2007-08-30 08:15:05 +00:00
|
|
|
* return the key name from the Command id value ( m_Idcommand member value)
|
2010-02-16 10:42:57 +00:00
|
|
|
* @param aList = pointer to a Ki_HotkeyInfo list of commands
|
|
|
|
* @param aCommandId = Command Id value
|
2007-08-30 08:15:05 +00:00
|
|
|
* @return the key name in a wxString
|
|
|
|
*/
|
2010-02-16 10:42:57 +00:00
|
|
|
wxString ReturnKeyNameFromCommandId( Ki_HotkeyInfo** aList, int aCommandId )
|
2007-08-30 08:15:05 +00:00
|
|
|
{
|
|
|
|
wxString keyname;
|
|
|
|
|
2010-02-16 10:42:57 +00:00
|
|
|
for( ; *aList != NULL; aList++ )
|
2007-08-30 08:15:05 +00:00
|
|
|
{
|
2010-02-16 10:42:57 +00:00
|
|
|
Ki_HotkeyInfo* hk_decr = *aList;
|
|
|
|
if( hk_decr->m_Idcommand == aCommandId )
|
2007-08-30 08:15:05 +00:00
|
|
|
{
|
|
|
|
keyname = ReturnKeyNameFromKeyCode( hk_decr->m_KeyCode );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return keyname;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-19 20:43:44 +00:00
|
|
|
/** function ReturnKeyCodeFromKeyName
|
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[],
|
2010-01-20 18:59:46 +00:00
|
|
|
* like F2 or space or an usual (ascii) char.
|
2007-08-30 08:15:05 +00:00
|
|
|
* @return the key code
|
|
|
|
*/
|
2010-08-29 16:36:52 +00:00
|
|
|
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;
|
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
// Search for modifiers: Ctrl+ Alt+ and Shift+
|
|
|
|
wxString key = keyname;
|
|
|
|
int modifier = 0;
|
|
|
|
while( 1 )
|
|
|
|
{
|
2010-08-28 19:08:58 +00:00
|
|
|
if( key.StartsWith( MODIFIER_CTRL ) )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
modifier |= GR_KB_CTRL;
|
|
|
|
key.Remove( 0, 5 );
|
|
|
|
}
|
|
|
|
|
2010-08-28 19:08:58 +00:00
|
|
|
else if( key.StartsWith( MODIFIER_ALT ) )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
modifier |= GR_KB_ALT;
|
|
|
|
key.Remove( 0, 4 );
|
|
|
|
}
|
2010-08-28 19:08:58 +00:00
|
|
|
else if( key.StartsWith( MODIFIER_SHIFT ) )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
modifier |= GR_KB_SHIFT;
|
|
|
|
key.Remove( 0, 6 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-08-29 16:36:52 +00:00
|
|
|
if( (key.length() == 1) && (key[0] > ' ') && (key[0] < 0x7F) )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
keycode = key[0];
|
|
|
|
keycode += modifier;
|
2010-08-29 16:36:52 +00:00
|
|
|
return keycode;
|
2010-08-28 18:02:24 +00:00
|
|
|
}
|
|
|
|
|
2007-08-30 08:15:05 +00:00
|
|
|
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
|
|
|
|
2010-08-29 16:36:52 +00:00
|
|
|
if( key.CmpNoCase( s_Hotkey_Name_List[ii].m_Name ) == 0 )
|
2007-08-30 08:15:05 +00:00
|
|
|
{
|
2010-08-28 18:02:24 +00:00
|
|
|
keycode = s_Hotkey_Name_List[ii].m_KeyCode + modifier;
|
2007-08-30 08:15:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return keycode;
|
2007-08-20 11:33:45 +00:00
|
|
|
}
|
|
|
|
|
2007-08-30 08:15:05 +00:00
|
|
|
|
2010-01-19 20:43:44 +00:00
|
|
|
/** function DisplayHotkeyList
|
2007-08-30 08:15:05 +00:00
|
|
|
* Displays the current hotkey list
|
2010-02-16 11:02:20 +00:00
|
|
|
* @param aFrame = current active frame
|
|
|
|
* @param aList = pointer to a Ki_HotkeyInfoSectionDescriptor list
|
2010-01-20 18:59:46 +00:00
|
|
|
*(Null terminated)
|
2007-08-30 08:15:05 +00:00
|
|
|
* @return none
|
|
|
|
*/
|
2010-02-16 11:02:20 +00:00
|
|
|
void DisplayHotkeyList( WinEDA_DrawFrame* aFrame,
|
|
|
|
struct Ki_HotkeyInfoSectionDescriptor* aDescList )
|
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
|
|
|
|
2010-02-16 11:02:20 +00:00
|
|
|
for( ; aDescList->m_HK_InfoList != NULL; aDescList++ )
|
2007-08-30 08:15:05 +00:00
|
|
|
{
|
2010-02-16 11:02:20 +00:00
|
|
|
List = aDescList->m_HK_InfoList;
|
2007-09-06 11:52:26 +00:00
|
|
|
for( ; *List != NULL; List++ )
|
|
|
|
{
|
|
|
|
Ki_HotkeyInfo* hk_decr = *List;
|
|
|
|
msg += _( "key " );
|
|
|
|
keyname = ReturnKeyNameFromKeyCode( hk_decr->m_KeyCode );
|
2010-01-20 18:59:46 +00:00
|
|
|
msg += keyname + wxT( ": " ) + hk_decr->m_InfoMsg + wxT( "\n" );
|
2007-09-06 11:52:26 +00:00
|
|
|
}
|
2007-08-30 08:15:05 +00:00
|
|
|
}
|
|
|
|
|
2010-02-16 11:02:20 +00:00
|
|
|
DisplayInfoMessage( aFrame, msg );
|
2007-08-20 11:33:45 +00:00
|
|
|
}
|
|
|
|
|
2007-08-30 08:15:05 +00:00
|
|
|
|
2010-01-19 20:43:44 +00:00
|
|
|
/** function GetDescriptorFromHotkey
|
2007-09-22 14:31:20 +00:00
|
|
|
* Return a Ki_HotkeyInfo * pointer fron a key code for OnHotKey() function
|
2010-02-16 11:02:20 +00:00
|
|
|
* @param aKey = key code (ascii value, or wxWidgets value for function keys
|
|
|
|
* @param aList = 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
|
|
|
*/
|
2010-02-16 11:02:20 +00:00
|
|
|
Ki_HotkeyInfo* GetDescriptorFromHotkey( int aKey, Ki_HotkeyInfo** aList )
|
2007-08-20 11:33:45 +00:00
|
|
|
{
|
2010-02-16 11:02:20 +00:00
|
|
|
for( ; *aList != NULL; aList++ )
|
2007-08-30 08:15:05 +00:00
|
|
|
{
|
2010-02-16 11:02:20 +00:00
|
|
|
Ki_HotkeyInfo* hk_decr = *aList;
|
|
|
|
if( hk_decr->m_KeyCode == aKey )
|
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
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
/** Function WriteHotkeyConfig
|
|
|
|
* Store the current hotkey list
|
|
|
|
* It is stored using the standard wxConfig mechanism or a file.
|
2007-08-30 08:15:05 +00:00
|
|
|
*
|
2010-08-28 18:02:24 +00:00
|
|
|
* @param aDescList = pointer to the current hotkey list.
|
|
|
|
* @param aFullFileName = a wxString pointer to a fuill file name.
|
|
|
|
* if NULL, use the standard wxConfig mechanism (default)
|
|
|
|
* the output format is: shortcut "key" "function"
|
|
|
|
* lines starting with # are comments
|
2007-08-30 08:15:05 +00:00
|
|
|
*/
|
2010-08-28 18:02:24 +00:00
|
|
|
int WinEDA_BasicFrame::WriteHotkeyConfig( struct Ki_HotkeyInfoSectionDescriptor* aDescList,
|
|
|
|
wxString* aFullFileName )
|
2007-08-21 19:37:31 +00:00
|
|
|
{
|
2007-08-30 08:15:05 +00:00
|
|
|
wxString msg;
|
|
|
|
wxString keyname, infokey;
|
|
|
|
|
|
|
|
msg = wxT( "$hotkey list\n" );
|
|
|
|
|
2007-09-06 11:52:26 +00:00
|
|
|
/* Print the current hotkey list */
|
|
|
|
Ki_HotkeyInfo** List;
|
2010-08-28 18:02:24 +00:00
|
|
|
for( ; aDescList->m_HK_InfoList != NULL; aDescList++ )
|
2007-08-30 08:15:05 +00:00
|
|
|
{
|
2010-08-28 18:02:24 +00:00
|
|
|
if( aDescList->m_Comment )
|
2007-09-06 11:52:26 +00:00
|
|
|
{
|
2010-08-28 18:02:24 +00:00
|
|
|
msg += wxT( "# " );
|
|
|
|
msg += wxString( aDescList->m_Comment );
|
|
|
|
msg += wxT( "\n" );
|
2007-09-06 11:52:26 +00:00
|
|
|
}
|
2010-08-28 18:02:24 +00:00
|
|
|
msg += *aDescList->m_SectionTag;
|
|
|
|
msg += wxT( "\n" );
|
|
|
|
|
|
|
|
List = aDescList->m_HK_InfoList;
|
2007-09-06 11:52:26 +00:00
|
|
|
for( ; *List != NULL; List++ )
|
|
|
|
{
|
|
|
|
Ki_HotkeyInfo* hk_decr = *List;
|
2010-08-28 18:02:24 +00:00
|
|
|
msg += wxT( "shortcut " );
|
2007-09-06 11:52:26 +00:00
|
|
|
keyname = ReturnKeyNameFromKeyCode( hk_decr->m_KeyCode );
|
|
|
|
AddDelimiterString( keyname );
|
|
|
|
infokey = hk_decr->m_InfoMsg;
|
|
|
|
AddDelimiterString( infokey );
|
|
|
|
msg += keyname + wxT( ": " ) + infokey + wxT( "\n" );
|
|
|
|
}
|
2007-08-30 08:15:05 +00:00
|
|
|
}
|
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
msg += wxT( "$Endlist\n" );
|
|
|
|
|
|
|
|
if( aFullFileName )
|
|
|
|
{
|
|
|
|
FILE* file = wxFopen( *aFullFileName, wxT( "wt" ) );
|
|
|
|
if( file )
|
|
|
|
fputs( CONV_TO_UTF8( msg ), file );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg.Printf( wxT( "Unable to write file %s" ), GetChars( *aFullFileName ) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxConfig config( m_FrameName );
|
|
|
|
config.Write( HOTKEYS_CONFIG_KEY, msg );
|
|
|
|
}
|
|
|
|
|
2007-08-30 08:15:05 +00:00
|
|
|
return 1;
|
2007-08-21 19:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
/** Function ReadHotkeyConfigFile
|
|
|
|
* Read an old configuration file (<file>.key) and fill the current hotkey list
|
2009-11-23 15:16:50 +00:00
|
|
|
* with hotkeys
|
2010-08-28 18:02:24 +00:00
|
|
|
* @param aFilename = file name to read.
|
|
|
|
* @param aDescList = current hotkey list descr. to initialise.
|
2007-08-30 08:15:05 +00:00
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
int WinEDA_BasicFrame::ReadHotkeyConfigFile(
|
2010-08-28 18:02:24 +00:00
|
|
|
const wxString& aFilename,
|
|
|
|
struct Ki_HotkeyInfoSectionDescriptor* aDescList )
|
2007-08-21 19:37:31 +00:00
|
|
|
{
|
2010-08-28 18:02:24 +00:00
|
|
|
wxFile cfgfile( aFilename );
|
2007-08-30 08:15:05 +00:00
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
/* get length */
|
|
|
|
cfgfile.SeekEnd();
|
|
|
|
wxFileOffset size = cfgfile.Tell();
|
|
|
|
cfgfile.Seek( 0 );
|
|
|
|
|
|
|
|
/* read data */
|
|
|
|
char* buffer = new char[size];
|
|
|
|
cfgfile.Read( buffer, size );
|
|
|
|
|
|
|
|
wxString data( buffer, wxConvUTF8 );
|
2007-08-30 08:15:05 +00:00
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
/* parse */
|
|
|
|
ParseHotkeyConfig( data, aDescList );
|
2007-08-30 08:15:05 +00:00
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
/* cleanup */
|
|
|
|
delete buffer;
|
|
|
|
cfgfile.Close();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ReadHotkeyConfig( const wxString& Appname,
|
|
|
|
struct Ki_HotkeyInfoSectionDescriptor* aDescList )
|
|
|
|
{
|
|
|
|
wxConfig config( Appname );
|
|
|
|
|
|
|
|
if( !config.HasEntry( HOTKEYS_CONFIG_KEY ) )
|
2007-08-30 08:15:05 +00:00
|
|
|
{
|
2010-08-28 18:02:24 +00:00
|
|
|
// assume defaults are ok
|
|
|
|
return;
|
2007-08-30 08:15:05 +00:00
|
|
|
}
|
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
wxString data;
|
|
|
|
config.Read( HOTKEYS_CONFIG_KEY, &data );
|
|
|
|
|
|
|
|
ParseHotkeyConfig( data, aDescList );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Function ReadHotkeyConfig
|
|
|
|
* Read configuration data and fill the current hotkey list with hotkeys
|
|
|
|
* @param aDescList = current hotkey list descr. to initialise.
|
|
|
|
*/
|
|
|
|
int WinEDA_BasicFrame::ReadHotkeyConfig( struct Ki_HotkeyInfoSectionDescriptor* aDescList )
|
|
|
|
{
|
|
|
|
::ReadHotkeyConfig( m_FrameName, aDescList );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-09-06 11:52:26 +00:00
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
/** Function ParseHotkeyConfig
|
|
|
|
* the input format is: shortcut "key" "function"
|
|
|
|
* lines starting by # are ignored (comments)
|
|
|
|
* lines like [xxx] are tags (example: [common] or [libedit] which identify
|
|
|
|
* sections
|
|
|
|
*/
|
|
|
|
void ParseHotkeyConfig(
|
|
|
|
const wxString& data,
|
|
|
|
struct Ki_HotkeyInfoSectionDescriptor* DescList )
|
|
|
|
{
|
|
|
|
/* Read the config */
|
|
|
|
wxStringTokenizer tokenizer( data, L"\r\n", wxTOKEN_STRTOK );
|
|
|
|
Ki_HotkeyInfo** CurrentHotkeyList = 0;
|
|
|
|
|
|
|
|
while( tokenizer.HasMoreTokens() )
|
2007-08-21 19:37:31 +00:00
|
|
|
{
|
2010-08-28 18:02:24 +00:00
|
|
|
wxString line = tokenizer.GetNextToken();
|
|
|
|
wxStringTokenizer lineTokenizer( line );
|
|
|
|
|
|
|
|
wxString line_type = lineTokenizer.GetNextToken();
|
|
|
|
if( line_type[0] == '#' ) //comment
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( line_type[0] == '[' ) // A tag is found. search infos in list
|
2007-09-06 11:52:26 +00:00
|
|
|
{
|
2010-08-28 18:02:24 +00:00
|
|
|
CurrentHotkeyList = 0;
|
2007-09-06 11:52:26 +00:00
|
|
|
Ki_HotkeyInfoSectionDescriptor* DList = DescList;
|
2010-08-28 18:02:24 +00:00
|
|
|
for( ; DList->m_HK_InfoList; DList++ )
|
2007-09-06 11:52:26 +00:00
|
|
|
{
|
2010-08-28 18:02:24 +00:00
|
|
|
if( *DList->m_SectionTag == line_type )
|
2007-09-06 11:52:26 +00:00
|
|
|
{
|
|
|
|
CurrentHotkeyList = DList->m_HK_InfoList;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
2010-08-28 18:02:24 +00:00
|
|
|
if( line_type == wxT( "$Endlist" ) )
|
2007-08-30 08:15:05 +00:00
|
|
|
break;
|
2010-08-28 18:02:24 +00:00
|
|
|
if( line_type != wxT( "shortcut" ) )
|
|
|
|
continue;
|
2007-09-06 11:52:26 +00:00
|
|
|
if( CurrentHotkeyList == NULL )
|
|
|
|
continue;
|
2007-08-30 08:15:05 +00:00
|
|
|
|
|
|
|
/* Get the key name */
|
2010-08-28 18:02:24 +00:00
|
|
|
lineTokenizer.SetString( lineTokenizer.GetString(), L"\"\r\n\t ", wxTOKEN_STRTOK );
|
|
|
|
wxString keyname = lineTokenizer.GetNextToken();
|
2008-09-03 16:19:06 +00:00
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
wxString remainder = lineTokenizer.GetString();
|
2008-09-03 16:19:06 +00:00
|
|
|
|
2007-08-30 08:15:05 +00:00
|
|
|
/* Get the command name */
|
2010-08-28 18:02:24 +00:00
|
|
|
wxString fctname = remainder.AfterFirst( '\"' ).BeforeFirst( '\"' );
|
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;
|
2010-08-28 18:02:24 +00:00
|
|
|
if( hk_decr->m_InfoMsg == fctname )
|
2007-08-30 08:15:05 +00:00
|
|
|
{
|
2010-08-28 18:02:24 +00:00
|
|
|
int code = ReturnKeyCodeFromKeyName( keyname );
|
2007-08-30 08:15:05 +00:00
|
|
|
if( code )
|
|
|
|
hk_decr->m_KeyCode = code;
|
2008-09-03 16:19:06 +00:00
|
|
|
|
2007-08-30 08:15:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-08-21 19:37:31 +00:00
|
|
|
}
|
2007-09-19 15:29:50 +00:00
|
|
|
|
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
/** Function ImportHotkeyConfigFromFile
|
|
|
|
* Prompt the user for an old hotkey file to read, and read it.
|
|
|
|
* @param aDescList = current hotkey list descr. to initialise.
|
2007-09-19 15:29:50 +00:00
|
|
|
*/
|
2010-08-28 18:02:24 +00:00
|
|
|
void WinEDA_BasicFrame::ImportHotkeyConfigFromFile(
|
|
|
|
struct Ki_HotkeyInfoSectionDescriptor* aDescList )
|
2007-09-19 15:29:50 +00:00
|
|
|
{
|
2010-08-28 18:02:24 +00:00
|
|
|
wxString ext = DEFAULT_HOTKEY_FILENAME_EXT;
|
|
|
|
wxString mask = wxT( "*." ) + ext;
|
|
|
|
wxString path = wxGetCwd();
|
|
|
|
wxString filename;
|
|
|
|
|
|
|
|
filename = EDA_FileSelector( _( "Read Hotkey Configuration File:" ),
|
|
|
|
path,
|
|
|
|
filename,
|
|
|
|
ext,
|
|
|
|
mask,
|
|
|
|
this,
|
|
|
|
wxFD_OPEN,
|
|
|
|
TRUE );
|
|
|
|
|
|
|
|
if( filename.IsEmpty() )
|
|
|
|
return;
|
2007-09-19 15:29:50 +00:00
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
ReadHotkeyConfigFile( filename, aDescList );
|
|
|
|
}
|
2007-09-19 15:29:50 +00:00
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
|
|
|
|
/** Function ExportHotkeyConfigToFile
|
|
|
|
* Prompt the user for an old hotkey file to read, and read it.
|
|
|
|
* @param aDescList = current hotkey list descr. to initialise.
|
|
|
|
*/
|
|
|
|
void WinEDA_BasicFrame::ExportHotkeyConfigToFile(
|
|
|
|
struct Ki_HotkeyInfoSectionDescriptor* aDescList )
|
|
|
|
{
|
|
|
|
wxString ext = DEFAULT_HOTKEY_FILENAME_EXT;
|
|
|
|
wxString mask = wxT( "*." ) + ext;
|
|
|
|
wxString path = wxGetCwd();
|
|
|
|
wxString filename;
|
|
|
|
|
|
|
|
filename = EDA_FileSelector( _( "Read Hotkey Configuration File:" ),
|
|
|
|
path,
|
|
|
|
filename,
|
|
|
|
ext,
|
|
|
|
mask,
|
|
|
|
this,
|
|
|
|
wxFD_OPEN,
|
|
|
|
TRUE );
|
|
|
|
|
|
|
|
if( filename.IsEmpty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
WriteHotkeyConfig( aDescList, &filename );
|
2007-09-19 15:29:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-27 13:48:24 +00:00
|
|
|
/** add hotkey config options submenu to a menu
|
2010-08-28 18:02:24 +00:00
|
|
|
* @param menu : root menu
|
2007-09-19 15:29:50 +00:00
|
|
|
*/
|
2010-01-18 12:37:53 +00:00
|
|
|
void AddHotkeyConfigMenu( wxMenu* aMenu )
|
2007-09-19 15:29:50 +00:00
|
|
|
{
|
2010-01-18 12:37:53 +00:00
|
|
|
if( aMenu == NULL )
|
|
|
|
return;
|
|
|
|
|
2007-09-19 15:29:50 +00:00
|
|
|
wxMenuItem* item;
|
2010-01-20 18:59:46 +00:00
|
|
|
wxMenu* HotkeySubmenu = new wxMenu();
|
2007-09-19 15:29:50 +00:00
|
|
|
|
2010-01-18 12:37:53 +00:00
|
|
|
/* List existing hotkey menu*/
|
2009-11-23 15:16:50 +00:00
|
|
|
item = new wxMenuItem( HotkeySubmenu,
|
2010-01-20 18:59:46 +00:00
|
|
|
ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST,
|
|
|
|
_( "List Current Keys" ),
|
|
|
|
_( "Displays the current hotkeys list and corresponding commands" ) );
|
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
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
/* Call hotkeys editor*/
|
|
|
|
item = new wxMenuItem( HotkeySubmenu, ID_PREFERENCES_HOTKEY_SHOW_EDITOR,
|
|
|
|
_( "Edit Hotkeys" ),
|
|
|
|
_( "Call the hotkeys editor" ) );
|
|
|
|
item->SetBitmap( editor_xpm );
|
|
|
|
HotkeySubmenu->Append( item );
|
|
|
|
|
|
|
|
HotkeySubmenu->AppendSeparator();
|
|
|
|
|
|
|
|
/* create hotkey file to export current hotkeys config */
|
|
|
|
item = new wxMenuItem( HotkeySubmenu, ID_PREFERENCES_HOTKEY_EXPORT_CONFIG,
|
|
|
|
_( "Export Hotkeys Config" ),
|
2010-01-20 18:59:46 +00:00
|
|
|
_(
|
2010-08-28 18:02:24 +00:00
|
|
|
"Create a hotkey configuration file to export the current hotkey config" )
|
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 */
|
2010-08-28 18:02:24 +00:00
|
|
|
item = new wxMenuItem( HotkeySubmenu, ID_PREFERENCES_HOTKEY_IMPORT_CONFIG,
|
|
|
|
_( "Import Hotkeys Config" ),
|
|
|
|
_( "Load an existing 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 );
|
|
|
|
|
|
|
|
/* Append HotkeySubmenu to menu */
|
2010-01-18 12:37:53 +00:00
|
|
|
ADD_MENUITEM_WITH_HELP_AND_SUBMENU( aMenu, HotkeySubmenu,
|
|
|
|
ID_PREFERENCES_HOTKEY_SUBMENU, _( "Hotkeys" ),
|
2010-01-20 18:59:46 +00:00
|
|
|
_( "Hotkeys configuration and preferences" ), hotkeys_xpm );
|
2007-09-22 14:31:20 +00:00
|
|
|
}
|