Library Editor: select part in the widget component on create/paste/duplicate component

This commit is contained in:
Maciej Suminski 2017-11-14 12:03:19 +01:00
parent 7d45d8b23c
commit ba4515885b
6 changed files with 50 additions and 0 deletions

View File

@ -228,6 +228,30 @@ int CMP_TREE_MODEL_ADAPTER_BASE::GetComponentsCount() const
}
wxDataViewItem CMP_TREE_MODEL_ADAPTER_BASE::FindItem( const LIB_ID& aLibId )
{
for( auto& lib: m_tree.Children )
{
if( lib->Name != aLibId.GetLibNickname() )
continue;
// if part name is not specified, return the library node
if( aLibId.GetLibItemName() == "" )
return ToItem( lib.get() );
for( auto& alias: lib->Children )
{
if( alias->Name == aLibId.GetLibItemName() )
return ToItem( alias.get() );
}
break; // could not find the part in the requested library
}
return wxDataViewItem();
}
bool CMP_TREE_MODEL_ADAPTER_BASE::HasContainerColumns( wxDataViewItem const& aItem ) const
{
return IsContainer( aItem );

View File

@ -233,6 +233,14 @@ public:
*/
int GetComponentsCount() const;
/**
* Returns tree item corresponding to part.
*
* @param aLibId specifies the part and library name to be searched for.
* @return Tree data item representing the part. Might be invalid if nothings was found.
*/
wxDataViewItem FindItem( const LIB_ID& aLibId );
protected:
static wxDataViewItem ToItem( CMP_TREE_NODE const* aNode );
static CMP_TREE_NODE const* ToNode( wxDataViewItem aItem );

View File

@ -424,6 +424,7 @@ void LIB_EDIT_FRAME::OnPasteDuplicatePart( wxCommandEvent& aEvent )
LIB_PART newPart( *srcPart );
fixDuplicateAliases( &newPart, lib );
m_libMgr->UpdatePart( &newPart, lib );
m_treePane->GetCmpTree()->SelectLibId( LIB_ID( lib, newPart.GetName() ) );
}

View File

@ -1012,6 +1012,10 @@ void LIB_EDIT_FRAME::SetCurPart( LIB_PART* aPart )
m_my_part = aPart;
}
// select the current component in the tree widget
if( aPart )
m_treePane->GetCmpTree()->SelectLibId( aPart->GetLibId() );
wxString partName = aPart ? aPart->GetName() : wxString();
m_libMgr->SetCurrentPart( partName );

View File

@ -131,6 +131,12 @@ LIB_ID COMPONENT_TREE::GetSelectedLibId( int* aUnit ) const
}
void COMPONENT_TREE::SelectLibId( const LIB_ID& aLibId )
{
selectIfValid( m_adapter->FindItem( aLibId ) );
}
void COMPONENT_TREE::selectIfValid( const wxDataViewItem& aTreeId )
{
if( aTreeId.IsOk() )

View File

@ -60,6 +60,13 @@ public:
*/
LIB_ID GetSelectedLibId( int* aUnit = nullptr ) const;
/**
* Select a part in the tree widget.
*
* @param aLibId is the identifier of part to be selected.
*/
void SelectLibId( const LIB_ID& aLibId );
/**
* Associates a right click context menu for a specific node type.
* @param aType is the node type to have a menu associated.