Only append number to name if it already exists.
Fixes https://gitlab.com/kicad/code/kicad/issues/4130
This commit is contained in:
parent
58e03be23c
commit
add4c3d4ea
|
@ -506,7 +506,7 @@ private:
|
||||||
bool isCurrentPart( const LIB_ID& aLibId ) const;
|
bool isCurrentPart( const LIB_ID& aLibId ) const;
|
||||||
|
|
||||||
///> Renames LIB_PART aliases to avoid conflicts before adding a component to a library
|
///> Renames LIB_PART aliases to avoid conflicts before adding a component to a library
|
||||||
void fixDuplicateAliases( LIB_PART* aPart, const wxString& aLibrary );
|
void ensureUniqueName( LIB_PART* aPart, const wxString& aLibrary );
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
|
|
@ -667,7 +667,7 @@ void LIB_EDIT_FRAME::DuplicatePart( bool aFromClipboard )
|
||||||
if( !newPart )
|
if( !newPart )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fixDuplicateAliases( newPart, lib );
|
ensureUniqueName( newPart, lib );
|
||||||
m_libMgr->UpdatePart( newPart, lib );
|
m_libMgr->UpdatePart( newPart, lib );
|
||||||
SyncLibraries( false );
|
SyncLibraries( false );
|
||||||
m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, newPart->GetName() ) );
|
m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, newPart->GetName() ) );
|
||||||
|
@ -676,19 +676,16 @@ void LIB_EDIT_FRAME::DuplicatePart( bool aFromClipboard )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LIB_EDIT_FRAME::fixDuplicateAliases( LIB_PART* aPart, const wxString& aLibrary )
|
void LIB_EDIT_FRAME::ensureUniqueName( LIB_PART* aPart, const wxString& aLibrary )
|
||||||
{
|
{
|
||||||
wxCHECK( aPart, /* void */ );
|
wxCHECK( aPart, /* void */ );
|
||||||
|
|
||||||
int i = 1;
|
int i = 1;
|
||||||
wxString newName;
|
wxString newName = aPart->GetName();
|
||||||
|
|
||||||
// Append a number to the name until the name is unique in the library.
|
// Append a number to the name until the name is unique in the library.
|
||||||
do
|
while( m_libMgr->PartExists( newName, aLibrary ) )
|
||||||
{
|
newName.Printf( "%s_%d", aPart->GetName(), i++ );
|
||||||
newName.Printf( "%s_%d", aPart->GetName(), i );
|
|
||||||
i++;
|
|
||||||
} while( m_libMgr->PartExists( newName, aLibrary ) );
|
|
||||||
|
|
||||||
aPart->SetName( newName );
|
aPart->SetName( newName );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue