From 42ead9fb06e2b672ded82304d9cf5b07c683f511 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Tue, 2 Jan 2018 17:12:04 -0800 Subject: [PATCH] Library Editor: Keep cmptree synchronized while updating When changing the component name, we need to ensure we don't use references to the LIB_ID when storing the tree state. We do this by selecting the containing library and re-selecting the renamed part if needed after the tree is synchronized. Fixes: lp:1740952 * https://bugs.launchpad.net/kicad/+bug/1740952 --- eeschema/libfield.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/eeschema/libfield.cpp b/eeschema/libfield.cpp index c4fdb2ecc..51d69127d 100644 --- a/eeschema/libfield.cpp +++ b/eeschema/libfield.cpp @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include #include #include @@ -43,6 +45,7 @@ void LIB_EDIT_FRAME::EditField( LIB_FIELD* aField ) wxString newFieldValue; wxString title; wxString caption; + bool reselectPartID = false; if( aField == NULL ) return; @@ -117,6 +120,19 @@ void LIB_EDIT_FRAME::EditField( LIB_FIELD* aField ) parent->RemoveAlias( newFieldValue ); } + // If we are renaming the currently selected part, move the selection to the library + // to avoid dereferencing an invalid LIB_ID. We try to reset it to the new part after + // syncing the tree + if( m_treePane ) + { + if( m_treePane->GetCmpTree()->GetSelectedLibId() == parent->GetLibId() ) + { + m_treePane->GetCmpTree()->SelectLibId( + LIB_ID( parent->GetLibId().GetLibNickname(), "" ) ); + reselectPartID = true; + } + } + parent->SetName( newFieldValue ); // Test the library for any conflicts with the any aliases in the current component. @@ -168,6 +184,9 @@ void LIB_EDIT_FRAME::EditField( LIB_FIELD* aField ) //m_libMgr->RemovePart( fieldText, lib ); m_libMgr->UpdatePart( parent, lib, fieldText ); + + if( reselectPartID ) + m_treePane->GetCmpTree()->SelectLibId( parent->GetLibId() ); } -- 2.11.0