From dd9b0c2dc68f8e2f47d604d9e896a86a3656e753 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 22 Sep 2018 16:20:45 +0100 Subject: [PATCH] Select assigned footprint in right panel. Fixes: lp:1793294 * https://bugs.launchpad.net/kicad/+bug/1793294 --- cvpcb/cvpcb_mainframe.cpp | 5 ++++- cvpcb/footprints_listbox.cpp | 25 +++++++++++++++++++------ cvpcb/listboxes.h | 1 + 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/cvpcb/cvpcb_mainframe.cpp b/cvpcb/cvpcb_mainframe.cpp index c95b165a1f..89c02ae182 100644 --- a/cvpcb/cvpcb_mainframe.cpp +++ b/cvpcb/cvpcb_mainframe.cpp @@ -480,7 +480,10 @@ void CVPCB_MAINFRAME::OnSelectComponent( wxListEvent& event ) m_footprintListBox->SetFootprints( *m_FootprintsList, libraryName, component, m_currentSearchPattern, m_filteringOptions); - m_footprintListBox->SetSelection( m_footprintListBox->GetSelection(), false ); + if( component && component->GetFPID().IsValid() ) + m_footprintListBox->SetSelectedFootprint( component->GetFPID() ); + else + m_footprintListBox->SetSelection( m_footprintListBox->GetSelection(), false ); refreshAfterComponentSearch (component); } diff --git a/cvpcb/footprints_listbox.cpp b/cvpcb/footprints_listbox.cpp index 11b1df27b2..03e876f941 100644 --- a/cvpcb/footprints_listbox.cpp +++ b/cvpcb/footprints_listbox.cpp @@ -112,15 +112,28 @@ void FOOTPRINTS_LISTBOX::SetSelection( int index, bool State ) if( (index >= 0) && (GetCount() > 0) ) { -#ifndef __WXMAC__ Select( index, State ); -#endif - EnsureVisible( index ); - -#ifdef __WXMAC__ Refresh(); -#endif + } +} + + +void FOOTPRINTS_LISTBOX::SetSelectedFootprint( const LIB_ID& aFPID ) +{ + wxString id = wxString::Format( "%s:%s", + GetChars( aFPID.GetLibNickname() ), + GetChars( aFPID.GetLibItemName() ) ); + + for( size_t i = 0; i < GetCount(); ++i ) + { + wxString candidate = m_footprintList.Item( i ).substr( 4 ); + + if( candidate.CmpNoCase( id ) == 0 ) + { + SetSelection( i, true ); + return; + } } } diff --git a/cvpcb/listboxes.h b/cvpcb/listboxes.h index 5d7be68b2f..c90a967328 100644 --- a/cvpcb/listboxes.h +++ b/cvpcb/listboxes.h @@ -110,6 +110,7 @@ public: int GetCount(); void SetSelection( int index, bool State = true ); + void SetSelectedFootprint( const LIB_ID& aFPID ); void SetString( unsigned linecount, const wxString& text ); void AppendLine( const wxString& text );