Fix library table file filters
The schematic librayr table was missing the Kicad Sexpr filter, and also the filter inside the grid editor was never updated when the library plugin type was changed in the grid, so a library of the new type could not be selected. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16278
This commit is contained in:
parent
855486f849
commit
be9c3b08b5
|
@ -384,6 +384,11 @@ public:
|
|||
Customize( wxCC_IFLAG_HAS_NONSTANDARD_BUTTON );
|
||||
}
|
||||
|
||||
void UpdateFileFilter( wxString* aFileFilter )
|
||||
{
|
||||
m_fileFilter = aFileFilter;
|
||||
}
|
||||
|
||||
protected:
|
||||
void DoSetPopupControl( wxComboPopup* popup ) override
|
||||
{
|
||||
|
@ -493,3 +498,18 @@ void GRID_CELL_PATH_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
|
|||
|
||||
wxGridCellEditor::Create( aParent, aId, aEventHandler );
|
||||
}
|
||||
|
||||
|
||||
void GRID_CELL_PATH_EDITOR::UpdateFilterString( const wxString& aFilterString )
|
||||
{
|
||||
if( m_fileFilterFn )
|
||||
m_fileFilter = m_fileFilterFn( m_grid, m_grid->GetGridCursorRow() );
|
||||
else
|
||||
m_fileFilter = aFilterString;
|
||||
|
||||
// Ensure that the control switches between files and directories properly
|
||||
if( m_fileFilter.IsEmpty() )
|
||||
static_cast<TEXT_BUTTON_FILE_BROWSER*>( m_control )->UpdateFileFilter( nullptr );
|
||||
else
|
||||
static_cast<TEXT_BUTTON_FILE_BROWSER*>( m_control )->UpdateFileFilter( &m_fileFilter );
|
||||
}
|
|
@ -84,6 +84,7 @@ enum {
|
|||
*/
|
||||
class SYMBOL_LIB_TABLE_GRID : public LIB_TABLE_GRID, public SYMBOL_LIB_TABLE
|
||||
{
|
||||
friend class PANEL_SYM_LIB_TABLE;
|
||||
friend class SYMBOL_GRID_TRICKS;
|
||||
|
||||
protected:
|
||||
|
@ -125,6 +126,19 @@ public:
|
|||
|
||||
SetValue( aRow, COL_TYPE, SCH_IO_MGR::ShowType( pluginType ) );
|
||||
}
|
||||
// If plugin type is changed, update the filter string in the chooser dialog
|
||||
else if( aCol == COL_TYPE )
|
||||
{
|
||||
wxGridCellEditor* editor = GetView()->GetCellEditor( aRow, COL_URI );
|
||||
|
||||
if( editor )
|
||||
{
|
||||
if( GRID_CELL_PATH_EDITOR* pathEditor = dynamic_cast<GRID_CELL_PATH_EDITOR*>( editor ) )
|
||||
pathEditor->UpdateFilterString();
|
||||
|
||||
editor->DecRef();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -286,36 +300,26 @@ PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, P
|
|||
wxString fileFiltersStr;
|
||||
wxString allWildcardsStr;
|
||||
|
||||
for( const SCH_IO_MGR::SCH_FILE_T& fileType : SCH_IO_MGR::SCH_FILE_T_vector )
|
||||
{
|
||||
if( fileType == SCH_IO_MGR::SCH_KICAD || fileType == SCH_IO_MGR::SCH_LEGACY )
|
||||
continue; // this is "Import non-KiCad schematic"
|
||||
|
||||
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( fileType ) );
|
||||
|
||||
if( !pi )
|
||||
continue;
|
||||
|
||||
const PLUGIN_FILE_DESC& desc = pi->GetLibraryFileDesc();
|
||||
|
||||
if( desc.m_FileExtensions.empty() )
|
||||
continue;
|
||||
|
||||
if( !fileFiltersStr.IsEmpty() )
|
||||
fileFiltersStr += wxChar( '|' );
|
||||
|
||||
fileFiltersStr += desc.FileFilter();
|
||||
|
||||
for( const std::string& ext : desc.m_FileExtensions )
|
||||
allWildcardsStr << wxT( "*." ) << formatWildcardExt( ext ) << wxT( ";" );
|
||||
}
|
||||
|
||||
fileFiltersStr = _( "All supported formats" ) + wxT( "|" ) + allWildcardsStr + wxT( "|" )
|
||||
+ fileFiltersStr;
|
||||
|
||||
attr->SetEditor( new GRID_CELL_PATH_EDITOR( m_parent, aGrid,
|
||||
&cfg->m_lastSymbolLibDir, fileFiltersStr,
|
||||
true, m_project->GetProjectPath() ) );
|
||||
&cfg->m_lastSymbolLibDir,
|
||||
true, m_project->GetProjectPath(),
|
||||
[]( WX_GRID* grid, int row ) -> wxString
|
||||
{
|
||||
auto* libTable = static_cast<SYMBOL_LIB_TABLE_GRID*>( grid->GetTable() );
|
||||
auto* tableRow = static_cast<SYMBOL_LIB_TABLE_ROW*>( libTable->at( row ) );
|
||||
|
||||
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( tableRow->GetFileType() ) );
|
||||
|
||||
if( pi )
|
||||
{
|
||||
const PLUGIN_FILE_DESC& desc = pi->GetLibraryFileDesc();
|
||||
|
||||
if( desc.m_IsFile )
|
||||
return desc.FileFilter();
|
||||
}
|
||||
|
||||
return wxEmptyString;
|
||||
} ) );
|
||||
aGrid->SetColAttr( COL_URI, attr );
|
||||
|
||||
attr = new wxGridCellAttr;
|
||||
|
|
|
@ -112,6 +112,8 @@ public:
|
|||
plugin->GetDefaultSymbolFields( aNames );
|
||||
}
|
||||
|
||||
SCH_IO_MGR::SCH_FILE_T GetFileType() { return type; }
|
||||
|
||||
protected:
|
||||
SYMBOL_LIB_TABLE_ROW( const SYMBOL_LIB_TABLE_ROW& aRow ) :
|
||||
LIB_TABLE_ROW( aRow ),
|
||||
|
|
|
@ -188,8 +188,8 @@ public:
|
|||
{
|
||||
if( m_fileFilterFn )
|
||||
{
|
||||
return new GRID_CELL_PATH_EDITOR( m_dlg, m_grid, m_currentDir, m_normalize,
|
||||
m_normalizeBasePath, m_fileFilterFn );
|
||||
return new GRID_CELL_PATH_EDITOR( m_dlg, m_grid, m_currentDir, m_normalize,
|
||||
m_normalizeBasePath, m_fileFilterFn );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -200,6 +200,15 @@ public:
|
|||
|
||||
void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
|
||||
|
||||
/**
|
||||
* Update the filter string for the control's file chooser dialog. If a file filter function
|
||||
* was provided on control creation, then that function is called to update the filter. Otherwise,
|
||||
* the value of aFilterString is used.
|
||||
*
|
||||
* @param aFilterString is the new filter string to use when the control doesn't have a filter function.
|
||||
*/
|
||||
void UpdateFilterString( const wxString& aFilterString = wxEmptyString );
|
||||
|
||||
protected:
|
||||
DIALOG_SHIM* m_dlg;
|
||||
WX_GRID* m_grid;
|
||||
|
|
|
@ -185,6 +185,35 @@ public:
|
|||
{
|
||||
m_rows = aTableToEdit.m_rows;
|
||||
}
|
||||
|
||||
void SetValue( int aRow, int aCol, const wxString &aValue ) override
|
||||
{
|
||||
LIB_TABLE_GRID::SetValue( aRow, aCol, aValue );
|
||||
|
||||
// If setting a filepath, attempt to auto-detect the format
|
||||
if( aCol == COL_URI )
|
||||
{
|
||||
IO_MGR::PCB_FILE_T pluginType = IO_MGR::GuessPluginTypeFromLibPath( aValue );
|
||||
|
||||
if( pluginType == IO_MGR::UNKNOWN )
|
||||
pluginType = IO_MGR::KICAD_SEXP;
|
||||
|
||||
SetValue( aRow, COL_TYPE, IO_MGR::ShowType( pluginType ) );
|
||||
}
|
||||
// If plugin type is changed, update the filter string in the chooser dialog
|
||||
else if( aCol == COL_TYPE )
|
||||
{
|
||||
wxGridCellEditor* editor = GetView()->GetCellEditor( aRow, COL_URI );
|
||||
|
||||
if( editor )
|
||||
{
|
||||
if( GRID_CELL_PATH_EDITOR* pathEditor = dynamic_cast<GRID_CELL_PATH_EDITOR*>( editor ) )
|
||||
pathEditor->UpdateFilterString();
|
||||
|
||||
editor->DecRef();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue