Commit 1ee86d4a authored by charras's avatar charras
Browse files

code cleanup and enhancements about hotkeys

parent e1412214
Loading
Loading
Loading
Loading
+38 −25
Original line number Diff line number Diff line
@@ -199,22 +199,22 @@ static struct hotkey_name_descr s_Hotkey_Name_List[] =
 * return the key name from the key code
 * 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)
 * @param aKeycode = key code (ascii value, or wxWidgets value for function keys)
 * @return the key name in a wxString
 */
wxString ReturnKeyNameFromKeyCode( int keycode )
wxString ReturnKeyNameFromKeyCode( int aKeycode )
{
    wxString keyname, modifier, fullkeyname;
    int      ii;

    if( (keycode & GR_KB_CTRL) != 0 )
    if( (aKeycode & GR_KB_CTRL) != 0 )
        modifier << wxT( "Ctrl+" );
    if( (keycode & GR_KB_ALT) != 0 )
    if( (aKeycode & GR_KB_ALT) != 0 )
        modifier << wxT( "Alt+" );
    if( (keycode & GR_KB_SHIFT) != 0 )
    if( (aKeycode & GR_KB_SHIFT) != 0 )
        modifier << wxT( "Shift+" );

    keycode &= ~( GR_KB_CTRL | GR_KB_ALT | GR_KB_SHIFT );
    aKeycode &= ~( GR_KB_CTRL | GR_KB_ALT | GR_KB_SHIFT );
    for( ii = 0; ; ii++ )
    {
        if( s_Hotkey_Name_List[ii].m_KeyCode == 0 )
@@ -222,7 +222,7 @@ wxString ReturnKeyNameFromKeyCode( int keycode )
            keyname = wxT( "<unknown>" );
            break;
        }
        if( s_Hotkey_Name_List[ii].m_KeyCode == keycode )
        if( s_Hotkey_Name_List[ii].m_KeyCode == aKeycode )
        {
            keyname = s_Hotkey_Name_List[ii].m_Name;
            break;
@@ -236,12 +236,15 @@ wxString ReturnKeyNameFromKeyCode( int keycode )

/** function AddHotkeyName
 * 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
 * @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
 */
wxString AddHotkeyName( const wxString& aText, Ki_HotkeyInfo** aList,
                        int aCommandId )
                        int aCommandId , bool  aIsShortCut )
{
    wxString msg     = aText;
    wxString keyname;
@@ -249,21 +252,28 @@ wxString AddHotkeyName( const wxString& aText, Ki_HotkeyInfo** aList,
        keyname = ReturnKeyNameFromCommandId( aList, aCommandId );

    if( !keyname.IsEmpty() )
    {
        if ( aIsShortCut )
            msg << wxT( "\t" ) << keyname;
        else
            msg << wxT( " <" ) << keyname << wxT(">");
    }
    return msg;
}


/** function AddHotkeyName
 * 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
 * @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
 */
wxString AddHotkeyName( const wxString&                        aText,
                        struct Ki_HotkeyInfoSectionDescriptor* aDescList,
                        int                                    aCommandId )
                        int                                    aCommandId,
                        bool                                   aIsShortCut )
{
    wxString        msg = aText;
    wxString        keyname;
@@ -277,7 +287,10 @@ wxString AddHotkeyName( const wxString& aText,
            keyname = ReturnKeyNameFromCommandId( List, aCommandId );
            if( !keyname.IsEmpty() )
            {
                if ( aIsShortCut )
                    msg << wxT( "\t" ) << keyname;
                else
                    msg << wxT( " <" ) << keyname << wxT(">");
                break;
            }
        }
@@ -289,18 +302,18 @@ wxString AddHotkeyName( const wxString& aText,

/** function ReturnKeyNameFromCommandId
 * 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
 * @param aList = pointer to a Ki_HotkeyInfo list of commands
 * @param aCommandId = Command Id value
 * @return the key name in a wxString
 */
wxString ReturnKeyNameFromCommandId( Ki_HotkeyInfo** List, int CommandId )
wxString ReturnKeyNameFromCommandId( Ki_HotkeyInfo** aList, int aCommandId )
{
    wxString keyname;

    for( ; *List != NULL; List++ )
    for( ; *aList != NULL; aList++ )
    {
        Ki_HotkeyInfo* hk_decr = *List;
        if( hk_decr->m_Idcommand == CommandId )
        Ki_HotkeyInfo* hk_decr = *aList;
        if( hk_decr->m_Idcommand == aCommandId )
        {
            keyname = ReturnKeyNameFromKeyCode( hk_decr->m_KeyCode );
            break;
+26 −6
Original line number Diff line number Diff line
@@ -52,13 +52,20 @@
 */

/* Fit on Screen */
static Ki_HotkeyInfo HkZoomAuto( wxT( "Fit on Screen" ), HK_ZOOM_AUTO,
                                 WXK_HOME );
#if !defined( __WXMAC__ )
static Ki_HotkeyInfo HkZoomAuto( wxT( "Fit on Screen" ), HK_ZOOM_AUTO, WXK_HOME );
#else
static Ki_HotkeyInfo HkZoomAuto( wxT( "Zoom Auto" ), HK_ZOOM_AUTO, GR_KB_CTRL + '0' );
#endif

static Ki_HotkeyInfo HkZoomCenter( wxT( "Zoom Center" ), HK_ZOOM_CENTER, WXK_F4 );

static Ki_HotkeyInfo HkZoomCenter( wxT( "Zoom Center" ), HK_ZOOM_CENTER,
                                   WXK_F4 );
static Ki_HotkeyInfo HkZoomRedraw( wxT( "Zoom Redraw" ), HK_ZOOM_REDRAW,
                                   WXK_F3 );
/* Refresh Screen */
#if !defined( __WXMAC__ )
static Ki_HotkeyInfo HkZoomRedraw( wxT( "Zoom Redraw" ), HK_ZOOM_REDRAW, WXK_F3 );
#else
static Ki_HotkeyInfo HkZoomRedraw( wxT( "Zoom Redraw" ), HK_ZOOM_REDRAW, GR_KB_CTRL + 'R' );
#endif

/* Zoom In */
#if !defined( __WXMAC__ )
@@ -127,6 +134,9 @@ static Ki_HotkeyInfo HkMove2Drag( wxT( "Switch move block to drag block" ),
static Ki_HotkeyInfo HkInsert( wxT( "Repeat Last Item" ), HK_REPEAT_LAST,
                               WXK_INSERT );
static Ki_HotkeyInfo HkDelete( wxT( "Delete Item" ), HK_DELETE, WXK_DELETE );

static Ki_HotkeyInfo HkFindItem( wxT( "Find Item" ), HK_FIND_ITEM, 'F'
                                 + GR_KB_CTRL );
static Ki_HotkeyInfo HkNextSearch( wxT( "Next Search" ), HK_NEXT_SEARCH,
                                   WXK_F5 );

@@ -156,6 +166,7 @@ Ki_HotkeyInfo* s_Common_Hotkey_List[] =
// List of hotkey descriptors for schematic
Ki_HotkeyInfo* s_Schematic_Hotkey_List[] =
{
    &HkFindItem,
    &HkNextSearch,
    &HkDelete,
    &HkInsert,
@@ -325,6 +336,15 @@ void WinEDA_SchematicFrame::OnHotKey( wxDC* DC, int hotkey,
            RepeatDrawItem( DC );
        break;

    case HK_FIND_ITEM:
        if( !ItemInEdit )
        {
            wxCommandEvent evt;
            evt.SetId( ID_FIND_ITEMS );
            Process_Special_Functions( evt );
        }
        break;

    case HK_NEXT_SEARCH:
        if( !ItemInEdit )
        {
+1 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@
// for shared hotkeys id
enum hotkey_id_commnand {
    HK_NEXT_SEARCH = HK_COMMON_END,
    HK_FIND_ITEM,
    HK_DELETE,
    HK_REPEAT_LAST,
	HK_EDIT_PIN,
+4 −11
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ void WinEDA_SchematicFrame::ReCreateMenuBar()

    /* Save as... */
    item = new wxMenuItem( filesMenu, ID_SAVE_ONE_SHEET_AS,
                           _( "Save Current Sheet &as\tShift+Ctrl+S" ),
                           _( "Save Current Sheet &as" ),
                           _( "Save current schematic sheet as..." ) );
    item->SetBitmap( save_as_xpm );
    filesMenu->Append( item );
@@ -88,7 +88,7 @@ void WinEDA_SchematicFrame::ReCreateMenuBar()
    filesMenu->AppendSeparator();

    /* Print */
    item = new wxMenuItem( filesMenu, wxID_PRINT, _( "P&rint\tCtrl+P" ),
    item = new wxMenuItem( filesMenu, wxID_PRINT, _( "P&rint" ),
                           _( "Print schematic" ) );
    item->SetBitmap( print_button );
    filesMenu->Append( item );
@@ -181,7 +181,8 @@ void WinEDA_SchematicFrame::ReCreateMenuBar()
    editMenu->AppendSeparator();

    /* Find */
    item = new wxMenuItem( editMenu, ID_FIND_ITEMS, _( "&Find\tCtrl+F" ),
    text = AddHotkeyName( _( "&Find" ), s_Schematic_Hokeys_Descr, HK_FIND_ITEM );
    item = new wxMenuItem( editMenu, ID_FIND_ITEMS, text,
                           _( "Find components and texts" ), wxITEM_NORMAL );
    item->SetBitmap( find_xpm );
    editMenu->Append( item );
@@ -229,12 +230,8 @@ void WinEDA_SchematicFrame::ReCreateMenuBar()
    viewMenu->Append( item );

    /* Fit on screen */
#if !defined( __WXMAC__)
    text = AddHotkeyName( _( "Fit on Screen" ), s_Schematic_Hokeys_Descr,
                          HK_ZOOM_AUTO );
#else
    text = _( "Fit on Screen\tCtrl+0" );
#endif

    item = new wxMenuItem( viewMenu, ID_ZOOM_PAGE, text,
                           _( "Fit the schematic sheet on the screen" ),
@@ -245,12 +242,8 @@ void WinEDA_SchematicFrame::ReCreateMenuBar()
    viewMenu->AppendSeparator();

    /* Redraw view */
#if !defined( __WXMAC__)
    text = AddHotkeyName( _( "Redraw" ), s_Schematic_Hokeys_Descr,
                          HK_ZOOM_REDRAW );
#else
    text = _( "Redraw\tCtrl+R" );
#endif

    item = new wxMenuItem( viewMenu, ID_ZOOM_REDRAW, text,
                           _( "Redraw the schematic view" ),
+6 −6
Original line number Diff line number Diff line
@@ -133,11 +133,11 @@ void WinEDA_LibeditFrame::ReCreateHToolbar()

    m_HToolBar->AddSeparator();
    msg = AddHotkeyName( _( "Undo last command" ), s_Schematic_Hokeys_Descr,
                         HK_UNDO );
                         HK_UNDO, false );
    m_HToolBar->AddTool( wxID_UNDO, wxEmptyString, wxBitmap( undo_xpm ),
                         msg );
    msg = AddHotkeyName( _( "Redo the last command" ), s_Schematic_Hokeys_Descr,
                         HK_REDO );
                         HK_REDO, false );
    m_HToolBar->AddTool( wxID_REDO, wxEmptyString, wxBitmap( redo_xpm ),
                         msg );

@@ -156,20 +156,20 @@ void WinEDA_LibeditFrame::ReCreateHToolbar()
                         _( "Test for duplicate pins and off grid pins" ) );

    m_HToolBar->AddSeparator();
    msg = AddHotkeyName( _( "Zoom in" ), s_Libedit_Hokeys_Descr, HK_ZOOM_IN );
    msg = AddHotkeyName( _( "Zoom in" ), s_Libedit_Hokeys_Descr, HK_ZOOM_IN, false );
    m_HToolBar->AddTool( ID_ZOOM_IN, wxEmptyString, wxBitmap( zoom_in_xpm ),
                         msg );

    msg = AddHotkeyName( _( "Zoom out" ), s_Libedit_Hokeys_Descr, HK_ZOOM_OUT );
    msg = AddHotkeyName( _( "Zoom out" ), s_Libedit_Hokeys_Descr, HK_ZOOM_OUT, false );
    m_HToolBar->AddTool( ID_ZOOM_OUT, wxEmptyString, wxBitmap( zoom_out_xpm ),
                         msg );

    msg = AddHotkeyName( _( "Redraw view" ), s_Libedit_Hokeys_Descr,
                         HK_ZOOM_REDRAW );
                         HK_ZOOM_REDRAW, false );
    m_HToolBar->AddTool( ID_ZOOM_REDRAW, wxEmptyString,
                         wxBitmap( zoom_redraw_xpm ), msg );

    msg = AddHotkeyName( _( "Zoom auto" ), s_Libedit_Hokeys_Descr, HK_ZOOM_AUTO );
    msg = AddHotkeyName( _( "Zoom auto" ), s_Libedit_Hokeys_Descr, HK_ZOOM_AUTO, false );
    m_HToolBar->AddTool( ID_ZOOM_PAGE, wxEmptyString,
                         wxBitmap( zoom_auto_xpm ), msg );

Loading