From 7fda7438f9f09c85c8abee8e22f59d17af25b3a8 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Thu, 25 Feb 2021 22:31:44 -0500 Subject: [PATCH] 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 --- eeschema/bom_plugins.cpp | 3 ++- eeschema/bom_plugins.h | 5 ++++ eeschema/dialogs/dialog_bom.cpp | 46 ++++++++++++++++++++++++--------- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/eeschema/bom_plugins.cpp b/eeschema/bom_plugins.cpp index f2f8f793f4..d2577cbaa1 100644 --- a/eeschema/bom_plugins.cpp +++ b/eeschema/bom_plugins.cpp @@ -32,9 +32,10 @@ const wxChar BOM_TRACE[] = wxT( "BOM_GENERATORS" ); BOM_GENERATOR_HANDLER::BOM_GENERATOR_HANDLER( const wxString& aFile ) - : m_file( aFile ) + : m_storedPath( aFile ) { m_isOk = false; + m_file = wxFileName( aFile ); if( !wxFile::Exists( m_file.GetFullPath() ) ) m_file = FindFilePath(); diff --git a/eeschema/bom_plugins.h b/eeschema/bom_plugins.h index 32f46f4759..485e61e4bf 100644 --- a/eeschema/bom_plugins.h +++ b/eeschema/bom_plugins.h @@ -80,6 +80,8 @@ public: return m_file; } + wxString GetStoredPath() const { return m_storedPath; } + /** * 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 @@ -154,6 +156,9 @@ protected: ///< Path to the plugin wxFileName m_file; + ///< Path to the plugin stored in config (can be absolute or just a filename) + const wxString m_storedPath; + ///< User customisable name wxString m_name; diff --git a/eeschema/dialogs/dialog_bom.cpp b/eeschema/dialogs/dialog_bom.cpp index b175ae6655..7254667a5d 100644 --- a/eeschema/dialogs/dialog_bom.cpp +++ b/eeschema/dialogs/dialog_bom.cpp @@ -164,7 +164,7 @@ DIALOG_BOM::~DIALOG_BOM() for( const std::unique_ptr& plugin : m_generators ) { wxString name = plugin->GetName(); - wxFileName path = plugin->GetFile(); + wxFileName path( plugin->GetStoredPath() ); // handle empty nickname by stripping path if( name.IsEmpty() ) @@ -207,16 +207,21 @@ void DIALOG_BOM::installGeneratorsList() { for( unsigned ii = 0; ii < m_generators.size(); ii++ ) { + wxString name = m_generators[ii]->GetName(); + if( !m_generators[ii]->FindFilePath().Exists( wxFILE_EXISTS_REGULAR ) ) { wxLogTrace( BOM_TRACE, "BOM plugin %s not found", 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 ); } } @@ -269,7 +274,7 @@ void DIALOG_BOM::OnGeneratorSelected( wxCommandEvent& event ) void DIALOG_BOM::pluginInit() { - auto plugin = selectedGenerator(); + BOM_GENERATOR_HANDLER* plugin = selectedGenerator(); if( !plugin ) { @@ -279,6 +284,26 @@ void DIALOG_BOM::pluginInit() 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_textCtrlCommand->SetValue( plugin->GetCommand() ); m_Messages->SetValue( plugin->GetInfo() ); @@ -390,13 +415,7 @@ wxString DIALOG_BOM::chooseGenerator() static wxString lastPath; if( lastPath.IsEmpty() ) - { -#ifndef __WXMAC__ - lastPath = Pgm().GetExecutablePath(); -#else - lastPath = PATHS::GetOSXKicadDataDir() + "/plugins"; -#endif - } + lastPath = PATHS::GetUserPluginsPath(); wxString fullFileName = EDA_FILE_SELECTOR( _( "Generator files:" ), lastPath, wxEmptyString, wxEmptyString, wxFileSelectorDefaultWildcardStr, @@ -461,6 +480,9 @@ void DIALOG_BOM::OnCommandLineEdited( wxCommandEvent& event ) void DIALOG_BOM::OnNameEdited( wxCommandEvent& event ) { + if( m_textCtrlName->GetValue().IsEmpty() ) + return; + int ii = m_lbGenerators->GetSelection(); if( ii < 0 )