Library Editor: select part in the widget component on create/paste/duplicate component
This commit is contained in:
parent
7d45d8b23c
commit
ba4515885b
|
@ -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
|
bool CMP_TREE_MODEL_ADAPTER_BASE::HasContainerColumns( wxDataViewItem const& aItem ) const
|
||||||
{
|
{
|
||||||
return IsContainer( aItem );
|
return IsContainer( aItem );
|
||||||
|
|
|
@ -233,6 +233,14 @@ public:
|
||||||
*/
|
*/
|
||||||
int GetComponentsCount() const;
|
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:
|
protected:
|
||||||
static wxDataViewItem ToItem( CMP_TREE_NODE const* aNode );
|
static wxDataViewItem ToItem( CMP_TREE_NODE const* aNode );
|
||||||
static CMP_TREE_NODE const* ToNode( wxDataViewItem aItem );
|
static CMP_TREE_NODE const* ToNode( wxDataViewItem aItem );
|
||||||
|
|
|
@ -424,6 +424,7 @@ void LIB_EDIT_FRAME::OnPasteDuplicatePart( wxCommandEvent& aEvent )
|
||||||
LIB_PART newPart( *srcPart );
|
LIB_PART newPart( *srcPart );
|
||||||
fixDuplicateAliases( &newPart, lib );
|
fixDuplicateAliases( &newPart, lib );
|
||||||
m_libMgr->UpdatePart( &newPart, lib );
|
m_libMgr->UpdatePart( &newPart, lib );
|
||||||
|
m_treePane->GetCmpTree()->SelectLibId( LIB_ID( lib, newPart.GetName() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1012,6 +1012,10 @@ void LIB_EDIT_FRAME::SetCurPart( LIB_PART* aPart )
|
||||||
m_my_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();
|
wxString partName = aPart ? aPart->GetName() : wxString();
|
||||||
m_libMgr->SetCurrentPart( partName );
|
m_libMgr->SetCurrentPart( partName );
|
||||||
|
|
||||||
|
|
|
@ -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 )
|
void COMPONENT_TREE::selectIfValid( const wxDataViewItem& aTreeId )
|
||||||
{
|
{
|
||||||
if( aTreeId.IsOk() )
|
if( aTreeId.IsOk() )
|
||||||
|
|
|
@ -60,6 +60,13 @@ public:
|
||||||
*/
|
*/
|
||||||
LIB_ID GetSelectedLibId( int* aUnit = nullptr ) const;
|
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.
|
* Associates a right click context menu for a specific node type.
|
||||||
* @param aType is the node type to have a menu associated.
|
* @param aType is the node type to have a menu associated.
|
||||||
|
|
Loading…
Reference in New Issue