Check for duplicates when adding libraries.
This is particularly important when bulk adding (by director, etc.) as otherwise the user might end up having to click OK to many many error dialogs. Fixes: lp:1764057 * https://bugs.launchpad.net/kicad/+bug/1764057
This commit is contained in:
parent
c842ddfb97
commit
af739f5b00
|
@ -218,6 +218,7 @@ DIALOG_SYMBOL_LIB_TABLE::DIALOG_SYMBOL_LIB_TABLE( wxTopLevelWindow* aParent,
|
|||
}
|
||||
|
||||
SetSizeInDU( 450, 400 );
|
||||
Center();
|
||||
|
||||
// On some window managers (Unity, XFCE), this dialog is
|
||||
// not always raised, depending on this dialog is run.
|
||||
|
@ -363,20 +364,42 @@ void DIALOG_SYMBOL_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event )
|
|||
|
||||
m_lastBrowseDir = dlg.GetDirectory();
|
||||
|
||||
bool skipRemainingDuplicates = false;
|
||||
wxArrayString files;
|
||||
dlg.GetFilenames( files );
|
||||
|
||||
for( const auto& file : files )
|
||||
{
|
||||
wxString filePath = dlg.GetDirectory() + wxFileName::GetPathSeparator() + file;
|
||||
wxFileName fn( filePath );
|
||||
wxString nickname = LIB_ID::FixIllegalChars( fn.GetName(), LIB_ID::ID_SCH );
|
||||
|
||||
if( cur_model()->ContainsNickname( nickname ) )
|
||||
{
|
||||
if( skipRemainingDuplicates )
|
||||
continue;
|
||||
|
||||
int ret = YesNoCancelDialog( this,
|
||||
_( "Warning: Duplicate Nickname" ),
|
||||
wxString::Format( _( "A library nicknamed \"%s\" already exists." ), nickname ),
|
||||
_( "Skip" ),
|
||||
_( "Skip All Remaining Duplicates" ),
|
||||
_( "Add Anyway" ) );
|
||||
|
||||
if( ret == wxID_YES )
|
||||
continue;
|
||||
else if ( ret == wxID_NO )
|
||||
{
|
||||
skipRemainingDuplicates = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if( m_cur_grid->AppendRows( 1 ) )
|
||||
{
|
||||
int last_row = m_cur_grid->GetNumberRows() - 1;
|
||||
wxFileName fn( filePath );
|
||||
|
||||
m_cur_grid->SetCellValue( last_row, COL_NICKNAME,
|
||||
LIB_ID::FixIllegalChars( fn.GetName(), LIB_ID::ID_SCH ) );
|
||||
m_cur_grid->SetCellValue( last_row, COL_NICKNAME, nickname );
|
||||
|
||||
// TODO the following code can detect only schematic types, not libs
|
||||
// SCH_IO_MGR needs to provide file extension information for libraries too
|
||||
|
|
|
@ -200,6 +200,18 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
bool ContainsNickname( const wxString& aNickname )
|
||||
{
|
||||
for( int i = 0; i < size(); ++i )
|
||||
{
|
||||
LIB_TABLE_ROW* row = at( i );
|
||||
|
||||
if( row->GetNickName() == aNickname )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual LIB_TABLE_ROW* at( size_t aIndex ) = 0;
|
||||
|
||||
|
|
|
@ -245,6 +245,7 @@ public:
|
|||
m_cur_grid->SetFocus();
|
||||
|
||||
SetSizeInDU( 450, 380 );
|
||||
Center();
|
||||
|
||||
// On some windows manager (Unity, XFCE), this dialog is
|
||||
// not always raised, depending on this dialog is run.
|
||||
|
@ -730,6 +731,7 @@ void DIALOG_FP_LIB_TABLE::OnClickLibraryWizard( wxCommandEvent& event )
|
|||
bool global_scope = dlg.GetLibScope() == WIZARD_FPLIB_TABLE::GLOBAL;
|
||||
wxGrid* libgrid = global_scope ? m_global_grid : m_project_grid;
|
||||
FP_LIB_TABLE_GRID* tbl = (FP_LIB_TABLE_GRID*) libgrid->GetTable();
|
||||
bool skipRemainingDuplicates = false;
|
||||
|
||||
for( std::vector<WIZARD_FPLIB_TABLE::LIBRARY>::const_iterator it = libs.begin();
|
||||
it != libs.end(); ++it )
|
||||
|
@ -737,13 +739,35 @@ void DIALOG_FP_LIB_TABLE::OnClickLibraryWizard( wxCommandEvent& event )
|
|||
if( it->GetStatus() == WIZARD_FPLIB_TABLE::LIBRARY::INVALID )
|
||||
continue;
|
||||
|
||||
wxString nickname = LIB_ID::FixIllegalChars( it->GetDescription(), LIB_ID::ID_PCB );
|
||||
|
||||
if( tbl->ContainsNickname( nickname ) )
|
||||
{
|
||||
if( skipRemainingDuplicates )
|
||||
continue;
|
||||
|
||||
int ret = YesNoCancelDialog( this,
|
||||
_( "Warning: Duplicate Nickname" ),
|
||||
wxString::Format( _( "A library nicknamed \"%s\" already exists." ), nickname ),
|
||||
_( "Skip" ),
|
||||
_( "Skip All Remaining Duplicates" ),
|
||||
_( "Add Anyway" ) );
|
||||
|
||||
if( ret == wxID_YES )
|
||||
continue;
|
||||
else if ( ret == wxID_NO )
|
||||
{
|
||||
skipRemainingDuplicates = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if( libgrid->AppendRows( 1 ) )
|
||||
{
|
||||
int last_row = libgrid->GetNumberRows() - 1;
|
||||
|
||||
// Add the nickname: currently make it from filename
|
||||
tbl->SetValue( last_row, COL_NICKNAME,
|
||||
LIB_ID::FixIllegalChars( it->GetDescription(), LIB_ID::ID_PCB ) );
|
||||
tbl->SetValue( last_row, COL_NICKNAME, nickname );
|
||||
|
||||
// Add the path:
|
||||
tbl->SetValue( last_row, COL_URI, it->GetAutoPath( dlg.GetLibScope() ) );
|
||||
|
|
Loading…
Reference in New Issue