Commit e27d3f8c authored by CHARRAS's avatar CHARRAS
Browse files

more work on programmable hotkeys. Most of features are ok.

parent 4a8bf70d
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -4,6 +4,14 @@ Started 2007-June-11
Please add newer entries at the top, list the date and your name with 
email address.

2007-sept-6 UPDATE   Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
+ eeschema & pcbnew
    Programmable hotkeys update.
	some features are still subject to change (mainly path for config files: see 2007-aug-30 UPDATE))
	The preference menu has a command to create and reread config hotkey files.
	the hotkey ? lists the current hotkeys.
	

2007-Sep-4 UPDATE   Dick Hollenbeck <dick@softplc.com>
================================================================================
+1 −16
Original line number Diff line number Diff line
@@ -265,7 +265,7 @@ void MyFree( void* pt_mem )


/**************************************************************/
wxString ReturnPcbLayerName( int layer_number, bool is_filename, bool is_gui )
wxString ReturnPcbLayerName( int layer_number, bool is_filename )
/**************************************************************/

/* Return the name of the layer number "layer_number".
@@ -305,21 +305,6 @@ wxString ReturnPcbLayerName( int layer_number, bool is_filename, bool is_gui )
    else
        layer_name = layer_name_list[layer_number];

    if( is_gui )
    {
        static const wxString hotkey_list[] = {
            wxT( "(PgDn)" ), wxT( "(F5)" ), wxT( "(F6)" ),  wxT( "(F7)" ),
            wxT( "(F8)" ),   wxT( "(F9)" ), wxT( "(F10)" ), wxT( " " ),
            wxT( " " ),      wxT( " " ),    wxT( " " ),     wxT( " " ),
            wxT( " " ),      wxT( " " ),    wxT( " " ),     wxT( " (PgUp)" ),
            wxT( " " ),      wxT( " " ),    wxT( " " ),     wxT( " " ),
            wxT( " " ),      wxT( " " ),    wxT( " " ),     wxT( " " ),
            wxT( " " ),      wxT( " " ),    wxT( " " ),     wxT( " " ),
            wxT( " " ),      wxT( " " ),    wxT( " " ),     wxT( " " )
        };
        layer_name += wxT( " " ) + hotkey_list[layer_number];
    }

    return layer_name;
}

+1 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include "worksheet.h"
#include "id.h"
#include "build_version.h"
#include "hotkeys_basic.h"

#include "bitmaps.h"
#include "Language.xpm"
+112 −38
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@

/* Some functions to handle hotkeys in kicad
 */

#include "fctsys.h"
#include "common.h"
#include "wxstruct.h"
@@ -11,7 +12,7 @@
#include "macros.h"

/* Class to handle hotkey commnands. hotkeys have a default value
 *  This class allows (for the future..) the real key code changed by user(from a key code list file, TODO)
 *  This class allows the real key code changed by user from a key code list file
 */

Ki_HotkeyInfo::Ki_HotkeyInfo( const wxChar* infomsg, int idcommand, int keycode )
@@ -30,7 +31,8 @@ struct hotkey_name_descr
    int     m_KeyCode;
};

struct hotkey_name_descr s_Hotkey_Name_List[] =

static struct hotkey_name_descr s_Hotkey_Name_List[] =
{
    { wxT( "F1" ),        WXK_F1           },
    { wxT( "F2" ),        WXK_F2           },
@@ -136,7 +138,7 @@ wxString ReturnKeyNameFromKeyCode( int keycode )

/*
 * return the key name from the key code
 * Only some wxWidgets key values are handled for function key
 * Only some wxWidgets key values are handled for function key ( see s_Hotkey_Name_List[] )
 * @param key = key code (ascii value, or wxWidgets value for function keys)
 * @return the key name in a wxString
 */
@@ -191,9 +193,41 @@ wxString AddHotkeyName( const wxString& text, Ki_HotkeyInfo** List, int CommandI
}


/***********************************************************************/
/***********************************************************/
wxString    AddHotkeyName( const wxString&                        text,
                           struct Ki_HotkeyInfoSectionDescriptor* DescList,
                           int                                    CommandId )
/***********************************************************/

/*
 * Add the key name from the Command id value ( m_Idcommand member value)
 * @param List = pointer to a Ki_HotkeyInfoSectionDescriptor* DescrList of commands
 * @param CommandId = Command Id value
 * @return text (key name) in a wxString if found or text without modification
 */
{
    wxString        msg     = text;
    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;
}


/*************************************************************************/
wxString ReturnKeyNameFromCommandId( Ki_HotkeyInfo** List, int CommandId )
/***********************************************************************/
/*************************************************************************/

/*
 * return the key name from the Command id value ( m_Idcommand member value)
@@ -225,7 +259,7 @@ static int ReturnKeyCodeFromKeyName( const wxString& keyname )
/*
 * return the key code from its key name
 * Only some wxWidgets key values are handled for function key
 * @param keyname = wxString key name to find in s_Hotkey_Name_List[]
 * @param keyname = wxString key name to find in s_Hotkey_Name_List[], like F2 or space or an usual (ascii) char
 * @return the key code
 */
{
@@ -246,21 +280,25 @@ static int ReturnKeyCodeFromKeyName( const wxString& keyname )
}


/****************************************************************************/
void DisplayHotkeyList( WinEDA_DrawFrame* frame, Ki_HotkeyInfo** List )
/*****************************************************************************/
/********************************************************************************************/
void DisplayHotkeyList( WinEDA_DrawFrame* frame, struct Ki_HotkeyInfoSectionDescriptor* DescList )
/***************************************************************************************/

/*
 * Displays the current hotkey list
 * @param frame = current open frame
 * @param List = pointer to a Ki_HotkeyInfo list of commands
 * @param frame = current active frame
 * @param List = pointer to a Ki_HotkeyInfoSectionDescriptor list (Null terminated)
 * @return none
 */
{
    wxString        keyname;
    Ki_HotkeyInfo** List;

    wxString        msg = _( "Current hotkey list:\n\n" );

    for( ; DescList->m_HK_InfoList != NULL; DescList++ )
    {
        List = DescList->m_HK_InfoList;
        for( ; *List != NULL; List++ )
        {
            Ki_HotkeyInfo* hk_decr = *List;
@@ -268,6 +306,7 @@ void DisplayHotkeyList( WinEDA_DrawFrame* frame, Ki_HotkeyInfo** List )
            keyname = ReturnKeyNameFromKeyCode( hk_decr->m_KeyCode );
            msg += keyname + wxT( ":    " ) + hk_decr->m_InfoMsg + wxT( "\n" );
        }
    }

    DisplayInfo( frame, msg );
}
@@ -297,7 +336,8 @@ int GetCommandCodeFromHotkey( int key, Ki_HotkeyInfo** List )

/*************************************************************************/
int WinEDA_BasicFrame::WriteHotkeyConfigFile( const wxString&                        Filename,
                                              Ki_HotkeyInfo** List, bool verbose )
                                              struct Ki_HotkeyInfoSectionDescriptor* DescList,
                                              bool                                   verbose )
/*************************************************************************/

/*
@@ -371,13 +411,25 @@ int WinEDA_BasicFrame::WriteHotkeyConfigFile( const wxString& Filename,
        }
    }

    /* print the last line */
    /* print the last line of the info section */
    if( !msg.IsEmpty() )
        msg += wxT( "\n" );
    msg += wxT( "#\n#\n" );
    fprintf( cfgfile, CONV_TO_UTF8( msg ) );

    /* Print the current list */
    /* Print the current hotkey list */
    Ki_HotkeyInfo** List;
    for( ; DescList->m_HK_InfoList != NULL; DescList++ )
    {
        if( DescList->m_Comment )
        {
            fprintf( cfgfile, "# " );
            fprintf( cfgfile, DescList->m_Comment );
            fprintf( cfgfile, "\n" );
        }
        fprintf( cfgfile, CONV_TO_UTF8( *DescList->m_SectionTag ) );
        fprintf( cfgfile, "\n" );
        List = DescList->m_HK_InfoList;
        for( ; *List != NULL; List++ )
        {
            Ki_HotkeyInfo* hk_decr = *List;
@@ -389,6 +441,7 @@ int WinEDA_BasicFrame::WriteHotkeyConfigFile( const wxString& Filename,
            msg += keyname + wxT( ":    " ) + infokey + wxT( "\n" );
            fprintf( cfgfile, CONV_TO_UTF8( msg ) );
        }
    }

    msg = wxT( "$Endlist\n" );
    fprintf( cfgfile, CONV_TO_UTF8( msg ) );
@@ -399,15 +452,17 @@ int WinEDA_BasicFrame::WriteHotkeyConfigFile( const wxString& Filename,

/********************************************************************************************/
int WinEDA_BasicFrame::ReadHotkeyConfigFile( const wxString&                        Filename,
                                             Ki_HotkeyInfo** CurrentHotkeyList, bool verbose )
                                             struct Ki_HotkeyInfoSectionDescriptor* DescList,
                                             bool                                   verbose )
/********************************************************************************************/

/*
 * 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
 * @param CurrentHotkeyList = current hotkey list to initialise.
 * @param DescList = current hotkey list descr. to initialise.
 * 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
 *
 */
{
@@ -449,16 +504,35 @@ int WinEDA_BasicFrame::ReadHotkeyConfigFile( const wxString& Filename,
    wxString        keyname;
    char            Line[1024];
    int             LineNum = 0;
    Ki_HotkeyInfo** CurrentHotkeyList = NULL;

    /* Read the file */
    while(  GetLine( cfgfile, Line, &LineNum ) != NULL )
    {
        char* line_type, * keyname, * fctname;
        line_type = strtok( Line, " \t\n\r" );
        msg = CONV_FROM_UTF8( line_type );
        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;
        }
        if( msg != wxT( "shortcut" ) )
            continue;
        if( msg == wxT( "$Endlist" ) )
            break;
        if( CurrentHotkeyList == NULL )
            continue;

        /* Get the key name */
        strtok( NULL, "\"\n\r" );
+3 −13
Original line number Diff line number Diff line
@@ -11,12 +11,10 @@
#include "eeconfig.h"
#include "worksheet.h"
#include "hotkeys_basic.h"
#include "hotkeys.h"

#include "id.h"

extern Ki_HotkeyInfo *s_Schematic_Hotkey_List[];
extern Ki_HotkeyInfo *s_LibEdit_Hotkey_List[];

/* Variables locales */


@@ -80,11 +78,7 @@ wxString FullFileName;
			FullFileName = DEFAULT_HOTKEY_FILENAME_PATH;
			FullFileName += wxT("eeschema");
			FullFileName += DEFAULT_HOTKEY_FILENAME_EXT;
			WriteHotkeyConfigFile(FullFileName, s_Schematic_Hotkey_List, true);
			FullFileName = DEFAULT_HOTKEY_FILENAME_PATH;
			FullFileName += wxT("libedit");
			FullFileName += DEFAULT_HOTKEY_FILENAME_EXT;
			WriteHotkeyConfigFile(FullFileName, s_LibEdit_Hotkey_List, true);
			WriteHotkeyConfigFile(FullFileName, s_Eeschema_Hokeys_Descr, true);
			break;

		case ID_PREFERENCES_READ_CONFIG_HOTKEYS:
@@ -107,11 +101,7 @@ bool Read_Hotkey_Config( WinEDA_DrawFrame * frame, bool verbose )
	wxString FullFileName = DEFAULT_HOTKEY_FILENAME_PATH;
	FullFileName += wxT("eeschema");
	FullFileName += DEFAULT_HOTKEY_FILENAME_EXT;
	frame->ReadHotkeyConfigFile(FullFileName, s_Schematic_Hotkey_List, verbose);
	FullFileName = DEFAULT_HOTKEY_FILENAME_PATH;
	FullFileName += wxT("libedit");
	FullFileName += DEFAULT_HOTKEY_FILENAME_EXT;
	frame->ReadHotkeyConfigFile(FullFileName, s_LibEdit_Hotkey_List, verbose);
	frame->ReadHotkeyConfigFile(FullFileName, s_Eeschema_Hokeys_Descr, verbose);

	return TRUE;
}
Loading