Populate BOM plugins list if the list is empty
Fixes: lp:1464893 * https://bugs.launchpad.net/kicad/+bug/1464893
This commit is contained in:
parent
15772e4b0b
commit
2ee2d9014a
|
@ -57,6 +57,21 @@ BOM_PLUGIN::BOM_PLUGIN( const wxString& aFile )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool BOM_PLUGIN::IsPlugin( const wxString& aFile )
|
||||||
|
{
|
||||||
|
wxFileName fn( aFile );
|
||||||
|
wxString ext = fn.GetExt().Lower();
|
||||||
|
|
||||||
|
for( const auto& pluginExt : { "xsl", "py", "pyw" } )
|
||||||
|
{
|
||||||
|
if( pluginExt == ext )
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
wxString BOM_PLUGIN::readHeader( const wxString& aEndSection )
|
wxString BOM_PLUGIN::readHeader( const wxString& aEndSection )
|
||||||
{
|
{
|
||||||
if( aEndSection.IsEmpty() )
|
if( aEndSection.IsEmpty() )
|
||||||
|
|
|
@ -45,6 +45,12 @@ public:
|
||||||
*/
|
*/
|
||||||
BOM_PLUGIN( const wxString& aFile );
|
BOM_PLUGIN( const wxString& aFile );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if a file name matches a recognized plugin format.
|
||||||
|
* @param aFile is path to the plugin file.
|
||||||
|
*/
|
||||||
|
static bool IsPlugin( const wxString& aFile );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns plugin description stored in the plugin header file (if available).
|
* Returns plugin description stored in the plugin header file (if available).
|
||||||
*/
|
*/
|
||||||
|
@ -121,6 +127,7 @@ protected:
|
||||||
///> Description of the plugin (normally from the plugin header)
|
///> Description of the plugin (normally from the plugin header)
|
||||||
wxString m_info;
|
wxString m_info;
|
||||||
|
|
||||||
|
///> Plugin specific options
|
||||||
wxArrayString m_options;
|
wxArrayString m_options;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
#include <confirm.h>
|
#include <confirm.h>
|
||||||
#include <gestfich.h>
|
#include <gestfich.h>
|
||||||
#include <sch_edit_frame.h>
|
#include <sch_edit_frame.h>
|
||||||
#include <wx/ffile.h>
|
|
||||||
#include <netlist.h>
|
#include <netlist.h>
|
||||||
#include <netlist_exporter_generic.h>
|
#include <netlist_exporter_generic.h>
|
||||||
#include <invoke_sch_dialog.h>
|
#include <invoke_sch_dialog.h>
|
||||||
|
@ -45,6 +44,8 @@
|
||||||
#include <bom_plugins.h>
|
#include <bom_plugins.h>
|
||||||
#include <make_unique.h>
|
#include <make_unique.h>
|
||||||
|
|
||||||
|
static constexpr wxChar BOM_TRACE[] = wxT( "BOM_PLUGINS" );
|
||||||
|
|
||||||
static constexpr wxChar BOM_PLUGINS_KEY[] = wxT( "bom_plugins" );
|
static constexpr wxChar BOM_PLUGINS_KEY[] = wxT( "bom_plugins" );
|
||||||
static constexpr wxChar BOM_PLUGIN_SELECTED_KEY[] = wxT( "bom_plugin_selected" );
|
static constexpr wxChar BOM_PLUGIN_SELECTED_KEY[] = wxT( "bom_plugin_selected" );
|
||||||
|
|
||||||
|
@ -186,6 +187,8 @@ private:
|
||||||
|
|
||||||
void pluginInit();
|
void pluginInit();
|
||||||
void installPluginsList();
|
void installPluginsList();
|
||||||
|
BOM_PLUGIN* addPlugin( const wxString& aPath, const wxString& aName = wxEmptyString );
|
||||||
|
bool pluginExists( const wxString& aName );
|
||||||
|
|
||||||
BOM_PLUGIN* selectedPlugin()
|
BOM_PLUGIN* selectedPlugin()
|
||||||
{
|
{
|
||||||
|
@ -232,6 +235,7 @@ DIALOG_BOM::DIALOG_BOM( SCH_EDIT_FRAME* parent ) :
|
||||||
|
|
||||||
SetInitialFocus( m_lbPlugins );
|
SetInitialFocus( m_lbPlugins );
|
||||||
m_sdbSizer1OK->SetDefault();
|
m_sdbSizer1OK->SetDefault();
|
||||||
|
wxLogDebug( "TEEEEST" );
|
||||||
|
|
||||||
// Now all widgets have the size fixed, call FinishDialogSettings
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
||||||
FinishDialogSettings();
|
FinishDialogSettings();
|
||||||
|
@ -299,21 +303,105 @@ void DIALOG_BOM::installPluginsList()
|
||||||
{
|
{
|
||||||
DisplayError( nullptr, e.what() );
|
DisplayError( nullptr, e.what() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Populate list box
|
||||||
|
for( unsigned ii = 0; ii < m_plugins.size(); ii++ )
|
||||||
|
{
|
||||||
|
m_lbPlugins->Append( m_plugins[ii]->GetName() );
|
||||||
|
|
||||||
|
if( active_plugin_name == m_plugins[ii]->GetName() )
|
||||||
|
m_lbPlugins->SetSelection( ii );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populate list box
|
if( m_plugins.empty() ) // No plugins found?
|
||||||
for( unsigned ii = 0; ii < m_plugins.size(); ii++ )
|
|
||||||
{
|
{
|
||||||
m_lbPlugins->Append( m_plugins[ii]->GetName() );
|
// Load plugins from the default locations
|
||||||
|
std::vector<wxString> pluginPaths = {
|
||||||
|
#if defined(__WXGTK__)
|
||||||
|
"/usr/share/kicad/plugins",
|
||||||
|
"/usr/local/share/kicad/plugins",
|
||||||
|
#elif defined(__WXMSW__)
|
||||||
|
wxString::Format( "%s\\scripting\\plugins", Pgm().GetExecutablePath() ),
|
||||||
|
#elif defined(__WXMAC__)
|
||||||
|
wxString::Format( "%s/plugins", GetOSXKicadDataDir() ),
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
if( active_plugin_name == m_plugins[ii]->GetName() )
|
wxFileName pluginPath;
|
||||||
m_lbPlugins->SetSelection( ii );
|
|
||||||
|
for( const auto& path : pluginPaths )
|
||||||
|
{
|
||||||
|
wxLogDebug( wxString::Format( "Searching directory %s for BOM plugins", path ) );
|
||||||
|
wxDir dir( path );
|
||||||
|
|
||||||
|
if( !dir.IsOpened() )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
pluginPath.AssignDir( dir.GetName() );
|
||||||
|
wxString fileName;
|
||||||
|
bool cont = dir.GetFirst( &fileName, "*", wxDIR_FILES );
|
||||||
|
|
||||||
|
while( cont )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
wxLogTrace( BOM_TRACE, wxString::Format( "Checking if %s is a BOM plugin", fileName ) );
|
||||||
|
|
||||||
|
if( BOM_PLUGIN::IsPlugin( fileName ) )
|
||||||
|
{
|
||||||
|
pluginPath.SetFullName( fileName );
|
||||||
|
addPlugin( pluginPath.GetFullPath() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch( ... ) { /* well, no big deal */ }
|
||||||
|
|
||||||
|
cont = dir.GetNext( &fileName );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pluginInit();
|
pluginInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BOM_PLUGIN* DIALOG_BOM::addPlugin( const wxString& aPath, const wxString& aName )
|
||||||
|
{
|
||||||
|
BOM_PLUGIN* ret = nullptr;
|
||||||
|
auto plugin = std::make_unique<BOM_PLUGIN>( aPath );
|
||||||
|
|
||||||
|
if( !plugin )
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
if( !aName.IsEmpty() )
|
||||||
|
{
|
||||||
|
plugin->SetName( aName );
|
||||||
|
m_lbPlugins->Append( aName );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_lbPlugins->Append( plugin->GetName() );
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = plugin.get();
|
||||||
|
m_plugins.push_back( std::move( plugin ) );
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool DIALOG_BOM::pluginExists( const wxString& aName )
|
||||||
|
{
|
||||||
|
for( unsigned ii = 0; ii < m_plugins.size(); ii++ )
|
||||||
|
{
|
||||||
|
if( aName == m_plugins[ii]->GetName() )
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void DIALOG_BOM::OnPluginSelected( wxCommandEvent& event )
|
void DIALOG_BOM::OnPluginSelected( wxCommandEvent& event )
|
||||||
{
|
{
|
||||||
pluginInit();
|
pluginInit();
|
||||||
|
@ -338,7 +426,7 @@ void DIALOG_BOM::pluginInit()
|
||||||
m_Messages->SetSelection( 0, 0 );
|
m_Messages->SetSelection( 0, 0 );
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
if( plugin.Options().Index( wxT( "show_console" ) ) == wxNOT_FOUND )
|
if( plugin->Options().Index( wxT( "show_console" ) ) == wxNOT_FOUND )
|
||||||
m_checkBoxShowConsole->SetValue( false );
|
m_checkBoxShowConsole->SetValue( false );
|
||||||
else
|
else
|
||||||
m_checkBoxShowConsole->SetValue( true );
|
m_checkBoxShowConsole->SetValue( true );
|
||||||
|
@ -406,29 +494,22 @@ void DIALOG_BOM::OnAddPlugin( wxCommandEvent& event )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Verify if it does not exists
|
// Verify if it does not exists
|
||||||
for( unsigned ii = 0; ii < m_plugins.size(); ii++ )
|
if( pluginExists( name ) )
|
||||||
{
|
{
|
||||||
if( name == m_plugins[ii]->GetName() )
|
wxMessageBox( wxString::Format( _( "Nickname \"%s\" already in use." ), name ) );
|
||||||
{
|
return;
|
||||||
wxMessageBox( wxString::Format( _( "Nickname \"%s\" already in use." ), name ) );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto plugin = std::make_unique<BOM_PLUGIN>( fn.GetFullPath() );
|
auto plugin = addPlugin( fn.GetFullPath(), name );
|
||||||
|
|
||||||
if( !plugin )
|
if( plugin )
|
||||||
return;
|
{
|
||||||
|
m_lbPlugins->SetSelection( m_lbPlugins->GetCount() - 1 );
|
||||||
plugin->SetName( name );
|
m_textCtrlCommand->SetValue( plugin->GetCommand() );
|
||||||
m_lbPlugins->Append( name );
|
pluginInit();
|
||||||
m_lbPlugins->SetSelection( m_lbPlugins->GetCount() - 1 );
|
}
|
||||||
m_textCtrlCommand->SetValue( plugin->GetCommand() );
|
|
||||||
|
|
||||||
m_plugins.push_back( std::move( plugin ) );
|
|
||||||
pluginInit();
|
|
||||||
}
|
}
|
||||||
catch( const std::runtime_error& e )
|
catch( const std::runtime_error& e )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue