BOM dialog: explain when we can't find scripts

Also default to the user plugin dir when adding a new plugin,
and don't convert filenames to full path on save.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/7719
This commit is contained in:
Jon Evans 2021-02-25 22:31:44 -05:00
parent 808ab92834
commit 7fda7438f9
3 changed files with 41 additions and 13 deletions

View File

@ -32,9 +32,10 @@ const wxChar BOM_TRACE[] = wxT( "BOM_GENERATORS" );
BOM_GENERATOR_HANDLER::BOM_GENERATOR_HANDLER( const wxString& aFile ) BOM_GENERATOR_HANDLER::BOM_GENERATOR_HANDLER( const wxString& aFile )
: m_file( aFile ) : m_storedPath( aFile )
{ {
m_isOk = false; m_isOk = false;
m_file = wxFileName( aFile );
if( !wxFile::Exists( m_file.GetFullPath() ) ) if( !wxFile::Exists( m_file.GetFullPath() ) )
m_file = FindFilePath(); m_file = FindFilePath();

View File

@ -80,6 +80,8 @@ public:
return m_file; return m_file;
} }
wxString GetStoredPath() const { return m_storedPath; }
/** /**
* Returns the calculated path to the plugin: if the path is already absolute and exists, * Returns the calculated path to the plugin: if the path is already absolute and exists,
* just return it. Otherwise if the path is just a filename, look for that file in the user * just return it. Otherwise if the path is just a filename, look for that file in the user
@ -154,6 +156,9 @@ protected:
///< Path to the plugin ///< Path to the plugin
wxFileName m_file; wxFileName m_file;
///< Path to the plugin stored in config (can be absolute or just a filename)
const wxString m_storedPath;
///< User customisable name ///< User customisable name
wxString m_name; wxString m_name;

View File

@ -164,7 +164,7 @@ DIALOG_BOM::~DIALOG_BOM()
for( const std::unique_ptr<BOM_GENERATOR_HANDLER>& plugin : m_generators ) for( const std::unique_ptr<BOM_GENERATOR_HANDLER>& plugin : m_generators )
{ {
wxString name = plugin->GetName(); wxString name = plugin->GetName();
wxFileName path = plugin->GetFile(); wxFileName path( plugin->GetStoredPath() );
// handle empty nickname by stripping path // handle empty nickname by stripping path
if( name.IsEmpty() ) if( name.IsEmpty() )
@ -207,16 +207,21 @@ void DIALOG_BOM::installGeneratorsList()
{ {
for( unsigned ii = 0; ii < m_generators.size(); ii++ ) for( unsigned ii = 0; ii < m_generators.size(); ii++ )
{ {
wxString name = m_generators[ii]->GetName();
if( !m_generators[ii]->FindFilePath().Exists( wxFILE_EXISTS_REGULAR ) ) if( !m_generators[ii]->FindFilePath().Exists( wxFILE_EXISTS_REGULAR ) )
{ {
wxLogTrace( BOM_TRACE, "BOM plugin %s not found", wxLogTrace( BOM_TRACE, "BOM plugin %s not found",
m_generators[ii]->FindFilePath().GetFullName() ); m_generators[ii]->FindFilePath().GetFullName() );
continue; name.Append( wxT( " " ) + _( "(file missing)" ) );
if( active_plugin_name == name )
active_plugin_name.Clear();
} }
m_lbGenerators->Append( m_generators[ii]->GetName() ); m_lbGenerators->Append( name );
if( active_plugin_name == m_generators[ii]->GetName() ) if( active_plugin_name == name )
m_lbGenerators->SetSelection( ii ); m_lbGenerators->SetSelection( ii );
} }
} }
@ -269,7 +274,7 @@ void DIALOG_BOM::OnGeneratorSelected( wxCommandEvent& event )
void DIALOG_BOM::pluginInit() void DIALOG_BOM::pluginInit()
{ {
auto plugin = selectedGenerator(); BOM_GENERATOR_HANDLER* plugin = selectedGenerator();
if( !plugin ) if( !plugin )
{ {
@ -279,6 +284,26 @@ void DIALOG_BOM::pluginInit()
return; return;
} }
if( !plugin->FindFilePath().Exists( wxFILE_EXISTS_REGULAR ) )
{
m_textCtrlName->SetValue( wxEmptyString );
m_textCtrlCommand->SetValue( wxEmptyString );
wxString msg =
wxString::Format( _( "The selected BOM generator script %s could not be found." ),
plugin->GetFile().GetFullPath() );
if( !plugin->GetFile().IsAbsolute() )
{
msg.Append( wxString::Format( _( "\n\nSearched:\n\t%s\n\t%s" ),
PATHS::GetUserPluginsPath(),
PATHS::GetStockPluginsPath() ) );
}
m_Messages->SetValue( msg );
return;
}
m_textCtrlName->SetValue( plugin->GetName() ); m_textCtrlName->SetValue( plugin->GetName() );
m_textCtrlCommand->SetValue( plugin->GetCommand() ); m_textCtrlCommand->SetValue( plugin->GetCommand() );
m_Messages->SetValue( plugin->GetInfo() ); m_Messages->SetValue( plugin->GetInfo() );
@ -390,13 +415,7 @@ wxString DIALOG_BOM::chooseGenerator()
static wxString lastPath; static wxString lastPath;
if( lastPath.IsEmpty() ) if( lastPath.IsEmpty() )
{ lastPath = PATHS::GetUserPluginsPath();
#ifndef __WXMAC__
lastPath = Pgm().GetExecutablePath();
#else
lastPath = PATHS::GetOSXKicadDataDir() + "/plugins";
#endif
}
wxString fullFileName = EDA_FILE_SELECTOR( _( "Generator files:" ), lastPath, wxEmptyString, wxString fullFileName = EDA_FILE_SELECTOR( _( "Generator files:" ), lastPath, wxEmptyString,
wxEmptyString, wxFileSelectorDefaultWildcardStr, wxEmptyString, wxFileSelectorDefaultWildcardStr,
@ -461,6 +480,9 @@ void DIALOG_BOM::OnCommandLineEdited( wxCommandEvent& event )
void DIALOG_BOM::OnNameEdited( wxCommandEvent& event ) void DIALOG_BOM::OnNameEdited( wxCommandEvent& event )
{ {
if( m_textCtrlName->GetValue().IsEmpty() )
return;
int ii = m_lbGenerators->GetSelection(); int ii = m_lbGenerators->GetSelection();
if( ii < 0 ) if( ii < 0 )