void WIDGET_HOTKEY_LIST::UpdateFromClientData()
{
    for( wxTreeListItem i = GetFirstItem(); i.IsOk(); i = GetNextItem( i ) )
    {
        WIDGET_HOTKEY_CLIENT_DATA* hkdata = GetHKClientData( i );

        if( hkdata )
        {
            const auto& changed_hk = hkdata->GetChangedHotkey();
            const EDA_HOTKEY& hk = changed_hk.GetCurrentValue();

            wxString key_text = KeyNameFromKeyCode( hk.m_KeyCode );

            // mark unsaved changes
            if( changed_hk.HasUnsavedChange() )
                key_text += " *";

            SetItemText( i, 0, wxGetTranslation( hk.m_InfoMsg ) );
            SetItemText( i, 1, key_text);
        }
    }

    // Trigger a resize in case column widths have changed
    wxSizeEvent dummy_evt;
    TWO_COLUMN_TREE_LIST::OnSize( dummy_evt );
}
bool WIDGET_HOTKEY_LIST::ResolveKeyConflicts( long aKey, const wxString& aSectionTag )
{
    EDA_HOTKEY* conflicting_key = NULL;
    EDA_HOTKEY_CONFIG* conflicting_section = NULL;

    CheckKeyConflicts( aKey, aSectionTag, &conflicting_key, &conflicting_section );

    if( conflicting_key != NULL )
    {
        wxString    info    = wxGetTranslation( conflicting_key->m_InfoMsg );
        wxString    msg     = wxString::Format(
                _( "<%s> is already assigned to \"%s\" in section \"%s\". Are you sure you want "
                   "to change its assignment?" ),
                KeyNameFromKeyCode( aKey ), GetChars( info ),
                *(conflicting_section->m_Title) );

        wxMessageDialog dlg( GetParent(), msg, _( "Confirm change" ), wxYES_NO | wxNO_DEFAULT );

        if( dlg.ShowModal() == wxID_YES )
        {
            conflicting_key->m_KeyCode = 0;
            UpdateFromClientData();
            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        return true;
    }
}
bool HOTKEYS_EDITOR_DIALOG::CanSetKey( long aKey, const wxString* sectionTag )
{
    std::vector<HOTKEY_SECTION_PAGE*>::iterator i;

    EDA_HOTKEY* conflictingKey = NULL;
    HOTKEY_SECTION_PAGE* conflictingSection = NULL;

    for( i = m_hotkeySectionPages.begin(); i != m_hotkeySectionPages.end(); ++i )
    {
        // Any non Common section can only conflict with itself and Common
        if( *sectionTag != g_CommonSectionTag
                 && *((*i)->GetHotkeySection()->m_SectionTag) != g_CommonSectionTag
                 && *((*i)->GetHotkeySection()->m_SectionTag) != *sectionTag )
            continue;

        std::vector<EDA_HOTKEY*>& hotkey_vec = (*i)->GetHotkeys();
        /* find the corresponding hotkey */
        std::vector<EDA_HOTKEY*>::iterator j;

        for( j = hotkey_vec.begin(); j != hotkey_vec.end(); ++j )
        {
            if( aKey == (*j)->m_KeyCode )
            {
                conflictingKey = (*j);
                conflictingSection = (*i);

                break;
            }
        }
    }

    if( conflictingKey != NULL )
    {
        wxString info = wxGetTranslation( conflictingKey->m_InfoMsg );
        wxString msg = wxString::Format(
            _( "<%s> is already assigned to \"%s\" in section \"%s\". Are you sure you want "
               "to change its assignment?" ),
            KeyNameFromKeyCode( aKey ), GetChars( info ),
            *(conflictingSection->GetHotkeySection()->m_Title) );

        wxMessageDialog dlg( this, msg, _( "Confirm change" ), wxYES_NO | wxNO_DEFAULT );

        if( dlg.ShowModal() == wxID_YES )
        {
            conflictingKey->m_KeyCode = 0;
            return true;
        }
        else
        {
            return false;
        }
    }

    return true;
}
wxString HOTKEY_LIST_CTRL::OnGetItemText( long aRow, long aColumn ) const
{
    EDA_HOTKEY* hotkey_descr = m_hotkeys[aRow];

    if( aColumn == 0 )
    {
        return wxGetTranslation( hotkey_descr->m_InfoMsg );
    }
    else
    {
        return KeyNameFromKeyCode( hotkey_descr->m_KeyCode );
    }
}
void WIDGET_HOTKEY_LIST::UpdateFromClientData()
{
    for( wxTreeListItem i = GetFirstItem(); i.IsOk(); i = GetNextItem( i ) )
    {
        WIDGET_HOTKEY_CLIENT_DATA* hkdata = GetHKClientData( i );

        if( hkdata )
        {
            EDA_HOTKEY& hk = hkdata->GetHotkey();

            SetItemText( i, 0, wxGetTranslation( hk.m_InfoMsg ) );
            SetItemText( i, 1, KeyNameFromKeyCode( hk.m_KeyCode ) );
        }
    }
}
Пример #6
0
void DisplayHotkeyList( EDA_BASE_FRAME* aFrame, struct EDA_HOTKEY_CONFIG* aDescList )
{
    wxString     keyname;
    wxString     keymessage;
    EDA_HOTKEY** list;

    wxString     msg = wxT( "<html><body bgcolor=\"#E2E2E2\">" );

    msg += wxT( "<H3>" );
    msg += _( "Hotkeys List" );
    msg += wxT( "</H3> <table cellpadding=\"0\">" );

    for( ; aDescList->m_HK_InfoList != NULL; aDescList++ )
    {
        list = aDescList->m_HK_InfoList;

        for( ; *list != NULL; list++ )
        {
            EDA_HOTKEY* hk_decr = *list;

            if( !hk_decr->m_InfoMsg.Contains( wxT( "Macros" ) ) )
            {
                keyname = KeyNameFromKeyCode( hk_decr->m_KeyCode );
                keymessage = wxGetTranslation( hk_decr->m_InfoMsg );

                // Some chars are modified, using html encoding, to be
                // displayed by DisplayHtmlInfoMessage()
                keyname.Replace( wxT( "<" ), wxT( "&lt;" ) );
                keyname.Replace( wxT( ">" ), wxT( "&gt;" ) );
                msg    += wxT( "<tr><td>" ) + keymessage + wxT( "</td>" );
                msg    += wxT( "<td><b>&nbsp;&nbsp;" ) + keyname + wxT( "</b></td></tr>" );
            }
        }
    }

    msg += wxT( "</table></html></body>" );

#if 0   // Set to 1 to create a modal dialog (blocking)
    DisplayHtmlInfoMessage( aFrame, _( "Hotkeys List" ), msg, wxSize( 340, 750 ) );
#else
    // Create a non modal dialog, which shows the list of hotkeys until dismissed
    // but does not block the parent window
    HTML_MESSAGE_BOX *dlg = new HTML_MESSAGE_BOX( aFrame, _( "Hotkeys List" ),
                                        wxDefaultPosition, wxSize( 340, 750 ) );
    dlg->AddHTML_Text( msg );
    dlg->Show( true );
#endif
}
    /**
     * Method FilterMatches
     *
     * Checks if the filter matches the given hotkey
     *
     * @return true on match (or if filter is disabled)
     */
    bool FilterMatches( const EDA_HOTKEY& aHotkey ) const
    {
        if( !m_valid )
            return true;

        // Match in the (translated) filter string
        const auto normedInfo = wxGetTranslation( aHotkey.m_InfoMsg ).Upper();
        if( normedInfo.Contains( m_normalised_filter_str ) )
            return true;

        const wxString keyName = KeyNameFromKeyCode( aHotkey.m_KeyCode );
        if( keyName.Upper().Contains( m_normalised_filter_str ) )
            return true;

        return false;
    }
Пример #8
0
/**
 * Function KeyNameFromCommandId
 * return the key name from the Command id value ( m_Idcommand member value)
 * @param aList = pointer to a EDA_HOTKEY list of commands
 * @param aCommandId = Command Id value
 * @return the key name in a wxString
 */
wxString KeyNameFromCommandId( EDA_HOTKEY** aList, int aCommandId )
{
    wxString keyname;

    for( ; *aList != NULL; aList++ )
    {
        EDA_HOTKEY* hk_decr = *aList;

        if( hk_decr->m_Idcommand == aCommandId )
        {
            keyname = KeyNameFromKeyCode( hk_decr->m_KeyCode );
            break;
        }
    }

    return keyname;
}
void WIDGET_HOTKEY_LIST::changeHotkey( CHANGED_HOTKEY& aHotkey, long aKey )
{
    // See if this key code is handled in hotkeys names list
    bool exists;
    KeyNameFromKeyCode( aKey, &exists );

    auto& curr_hk = aHotkey.GetCurrentValue();

    if( exists && curr_hk.m_KeyCode != aKey )
    {
        const auto& tag = aHotkey.GetSectionTag();
        bool can_update = ResolveKeyConflicts( aKey, tag );

        if( can_update )
        {
            curr_hk.m_KeyCode = aKey;
        }
    }
}
void WIDGET_HOTKEY_LIST::EditItem( wxTreeListItem aItem )
{
    WIDGET_HOTKEY_CLIENT_DATA* hkdata = GetHKClientData( aItem );

    if( !hkdata )
    {
        // Activated item was not a hotkey row
        return;
    }

    wxString    name = GetItemText( aItem, 0 );
    wxString    current_key = GetItemText( aItem, 1 );

    wxKeyEvent key_event = HK_PROMPT_DIALOG::PromptForKey( GetParent(), name, current_key );
    long key = MapKeypressToKeycode( key_event );

    if( hkdata && key )
    {
        // See if this key code is handled in hotkeys names list
        bool exists;
        KeyNameFromKeyCode( key, &exists );

        if( exists && hkdata->GetHotkey().m_KeyCode != key )
        {
            wxString tag = hkdata->GetSectionTag();
            bool canUpdate = ResolveKeyConflicts( key, tag );

            if( canUpdate )
            {
                hkdata->GetHotkey().m_KeyCode = key;
            }
        }

        UpdateFromClientData();

        // Trigger a resize in case column widths have changed
        wxSizeEvent dummy_evt;
        OnSize( dummy_evt );
    }
}
Пример #11
0
/* DisplayHotkeyList
 * Displays the current hotkey list
 * aList = a EDA_HOTKEY_CONFIG list(Null terminated)
 */
void DisplayHotkeyList( EDA_DRAW_FRAME* aFrame, struct EDA_HOTKEY_CONFIG* aDescList )
{
    wxString     keyname;
    EDA_HOTKEY** list;

    wxString     msg = wxT( "<html><body bgcolor=\"#E2E2E2\">" );

    msg += wxT( "<H3>");
    msg += _("Hotkeys List");
    msg += wxT("</H3> <table cellpadding=\"0\">");

    for( ; aDescList->m_HK_InfoList != NULL; aDescList++ )
    {
        list = aDescList->m_HK_InfoList;

        for( ; *list != NULL; list++ )
        {
            EDA_HOTKEY* hk_decr = *list;

            if( !hk_decr->m_InfoMsg.Contains( wxT( "Macros" ) ) )
            {
                keyname = KeyNameFromKeyCode( hk_decr->m_KeyCode );

                // Some chars should be modified, using html encoding, to be
                // displayed by DisplayHtmlInfoMessage()
                keyname.Replace( wxT("<"), wxT("&lt;") );
                keyname.Replace( wxT(">"), wxT("&gt;") );
                msg    += wxT( "<tr><td>" ) + hk_decr->m_InfoMsg + wxT("</td>");
                msg    += wxT("<td><b>&nbsp;&nbsp;") + keyname + wxT( "</b></td></tr>" );
            }
        }
    }

    msg += wxT("</table></html></body>");
    DisplayHtmlInfoMessage( aFrame, _("Hotkeys List"), msg, wxSize(340, 750));
}
Пример #12
0
int EDA_BASE_FRAME::WriteHotkeyConfig( struct EDA_HOTKEY_CONFIG* aDescList,
                                       wxString*                 aFullFileName )
{
    wxString msg;
    wxString keyname, infokey;

    msg = wxT( "$hotkey list\n" );

    // Print the current hotkey list
    EDA_HOTKEY** list;

    for( ; aDescList->m_HK_InfoList != NULL; aDescList++ )
    {
        if( aDescList->m_Title )
        {
            msg += wxT( "# " );
            msg += *aDescList->m_Title;
            msg += wxT( "\n" );
        }

        msg += *aDescList->m_SectionTag;
        msg += wxT( "\n" );

        list = aDescList->m_HK_InfoList;

        for( ; *list != NULL; list++ )
        {
            EDA_HOTKEY* hk_decr = *list;
            msg    += wxT( "shortcut   " );
            keyname = KeyNameFromKeyCode( hk_decr->m_KeyCode );
            AddDelimiterString( keyname );
            infokey = hk_decr->m_InfoMsg;
            AddDelimiterString( infokey );
            msg += keyname + wxT( ":    " ) + infokey + wxT( "\n" );
        }
    }

    msg += wxT( "$Endlist\n" );

    if( aFullFileName )
    {
        FILE* file = wxFopen( *aFullFileName, wxT( "wt" ) );

        if( file )
        {
            fputs( TO_UTF8( msg ), file );
            fclose( file );
        }
        else
        {
            msg.Printf( wxT( "Unable to write file %s" ), GetChars( *aFullFileName ) );
            return 0;
        }
    }
    else
    {
        wxFileName fn( GetName() );
        fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
        wxConfigBase* config = GetNewConfig( fn.GetFullPath() );
        config->Write( HOTKEYS_CONFIG_KEY, msg );
        delete config;
    }

    return 1;
}
void HOTKEY_LIST_CTRL::OnChar( wxKeyEvent& aEvent )
{
    if( m_curEditingRow != -1 )
    {
        long key = aEvent.GetKeyCode();

        switch( key )
        {
        case WXK_ESCAPE:
            // Remove selection
            DeselectRow( m_curEditingRow );
            m_curEditingRow = -1;
            break;

        default:
            if( key >= 'a' && key <= 'z' ) // convert to uppercase
                key = key + ('A' - 'a');

            // Remap Ctrl A (=1+GR_KB_CTRL) to Ctrl Z(=26+GR_KB_CTRL)
            // to GR_KB_CTRL+'A' .. GR_KB_CTRL+'Z'
            if( aEvent.ControlDown() && key >= WXK_CONTROL_A && key <= WXK_CONTROL_Z )
                key += 'A' - 1;

            /* Disallow shift for keys that have two keycodes on them (e.g. number and
             * punctuation keys) leaving only the "letter keys" of A-Z.
             * Then, you can have, e.g. Ctrl-5 and Ctrl-% (GB layout)
             * and Ctrl-( and Ctrl-5 (FR layout).
             * Otherwise, you'd have to have to say Ctrl-Shift-5 on a FR layout
             */
            bool keyIsLetter = key >= 'A' && key <= 'Z';

            if( aEvent.ShiftDown() && ( keyIsLetter || key > 256 ) )
                key |= GR_KB_SHIFT;

            if( aEvent.ControlDown() )
                key |= GR_KB_CTRL;

            if( aEvent.AltDown() )
                key |= GR_KB_ALT;

            // See if this key code is handled in hotkeys names list
            bool exists;
            KeyNameFromKeyCode( key, &exists );

            if( exists && m_hotkeys[m_curEditingRow]->m_KeyCode != key )
            {
                bool canUpdate = ((HOTKEY_SECTION_PAGE *)m_parent)->GetDialog()->CanSetKey( key, m_sectionTag );

                if( canUpdate )
                {
                    m_hotkeys[m_curEditingRow]->m_KeyCode = key;
                    recalculateColumns();
                }

                // Remove selection
                DeselectRow( m_curEditingRow );
                m_curEditingRow = -1;
            }
        }
    }
    RefreshItems(0,m_hotkeys.size()-1);
}