DIALOG_SYMBOL_FIELDS_TABLE::OnExport(): better error messages.

This commit is contained in:
jean-pierre charras 2023-10-06 13:50:59 +02:00
parent bf29b25190
commit e48256d41a
1 changed files with 14 additions and 11 deletions

View File

@ -1232,23 +1232,25 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnExport( wxCommandEvent& aEvent )
};
wxString path = m_outputFileName->GetValue();
if( path.IsEmpty() )
{
DisplayError( this, _( "No filename specified in exporter" ) );
return;
}
path = ExpandTextVars( path, &textResolver );
path = ExpandEnvVarSubstitutions( path, nullptr );
wxFileName outputFile = wxFileName::FileName( path );
auto displayErr = [&]()
{
wxString msg;
msg.Printf( _( "Could not write BOM output to '%s'." ), outputFile.GetPath() );
DisplayError( this, msg );
};
if( !EnsureFileDirectoryExists( &outputFile,
Prj().AbsolutePath( m_parent->Schematic().GetFileName() ),
&NULL_REPORTER::GetInstance() ) )
{
displayErr();
msg.Printf( _( "Could not open/create path '%s'." ), outputFile.GetPath() );
DisplayError( this, msg );
return;
}
@ -1256,7 +1258,8 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnExport( wxCommandEvent& aEvent )
if( !out.IsOpened() )
{
displayErr();
msg.Printf( _( "Could not create BOM output '%s'." ), outputFile.GetFullPath() );
DisplayError( this, msg );
return;
}
@ -1264,11 +1267,11 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnExport( wxCommandEvent& aEvent )
if( !out.Write( m_textOutput->GetValue() ) )
{
displayErr();
msg.Printf( _( "Could not write BOM output '%s'." ), outputFile.GetFullPath() );
DisplayError( this, msg );
return;
}
wxString msg;
msg.Printf( _( "Wrote BOM output to '%s'" ), outputFile.GetFullPath() );
DisplayInfoMessage( this, msg );
}