Provide a callback for supplying file filters just-in-time.
This allows us to make them dependent on the current plugin type in the fp lib table. Fixes https://gitlab.com/kicad/code/kicad/-/issues/13959
This commit is contained in:
parent
171458a27b
commit
6c6a7cf862
|
@ -374,7 +374,7 @@ public:
|
|||
m_dlg( aParentDlg ),
|
||||
m_grid( aGrid ),
|
||||
m_currentDir( aCurrentDir ),
|
||||
m_ext( aExt ),
|
||||
m_fileFilter( aExt ),
|
||||
m_normalize( aNormalize ),
|
||||
m_normalizeBasePath( aNormalizeBasePath )
|
||||
{
|
||||
|
@ -399,10 +399,10 @@ protected:
|
|||
else
|
||||
fn.SetPath( ExpandEnvVarSubstitutions( fn.GetPath(), &m_dlg->Prj() ) );
|
||||
|
||||
if( m_ext )
|
||||
if( m_fileFilter )
|
||||
{
|
||||
wxFileDialog dlg( m_dlg, _( "Select a File" ), fn.GetPath(), fn.GetFullName(), *m_ext,
|
||||
wxFD_FILE_MUST_EXIST | wxFD_OPEN );
|
||||
wxFileDialog dlg( m_dlg, _( "Select a File" ), fn.GetPath(), fn.GetFullName(),
|
||||
*m_fileFilter, wxFD_FILE_MUST_EXIST | wxFD_OPEN );
|
||||
|
||||
if( dlg.ShowModal() == wxID_OK )
|
||||
{
|
||||
|
@ -464,7 +464,7 @@ protected:
|
|||
DIALOG_SHIM* m_dlg;
|
||||
WX_GRID* m_grid;
|
||||
wxString* m_currentDir;
|
||||
wxString* m_ext;
|
||||
wxString* m_fileFilter;
|
||||
bool m_normalize;
|
||||
wxString m_normalizeBasePath;
|
||||
};
|
||||
|
@ -473,11 +473,14 @@ protected:
|
|||
void GRID_CELL_PATH_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
|
||||
wxEvtHandler* aEventHandler )
|
||||
{
|
||||
if( m_ext.IsEmpty() )
|
||||
if( m_fileFilterFn )
|
||||
m_fileFilter = m_fileFilterFn( m_grid, m_grid->GetGridCursorRow() );
|
||||
|
||||
if( m_fileFilter.IsEmpty() )
|
||||
m_control = new TEXT_BUTTON_FILE_BROWSER( aParent, m_dlg, m_grid, m_currentDir, nullptr,
|
||||
m_normalize, m_normalizeBasePath );
|
||||
else
|
||||
m_control = new TEXT_BUTTON_FILE_BROWSER( aParent, m_dlg, m_grid, m_currentDir, &m_ext,
|
||||
m_control = new TEXT_BUTTON_FILE_BROWSER( aParent, m_dlg, m_grid, m_currentDir, &m_fileFilter,
|
||||
m_normalize, m_normalizeBasePath );
|
||||
|
||||
#if wxUSE_VALIDATORS
|
||||
|
|
|
@ -40,8 +40,6 @@ class FP_LIB_TABLE_GRID;
|
|||
class FP_LIB_TABLE_ROW : public LIB_TABLE_ROW
|
||||
{
|
||||
public:
|
||||
typedef IO_MGR::PCB_FILE_T LIB_T;
|
||||
|
||||
FP_LIB_TABLE_ROW( const wxString& aNick, const wxString& aURI, const wxString& aType,
|
||||
const wxString& aOptions, const wxString& aDescr = wxEmptyString ) :
|
||||
LIB_TABLE_ROW( aNick, aURI, aOptions, aDescr )
|
||||
|
@ -68,6 +66,8 @@ public:
|
|||
*/
|
||||
void SetType( const wxString& aType ) override;
|
||||
|
||||
IO_MGR::PCB_FILE_T GetFileType() { return type; }
|
||||
|
||||
protected:
|
||||
FP_LIB_TABLE_ROW( const FP_LIB_TABLE_ROW& aRow ) :
|
||||
LIB_TABLE_ROW( aRow ),
|
||||
|
@ -88,8 +88,9 @@ private:
|
|||
|
||||
friend class FP_LIB_TABLE;
|
||||
|
||||
PLUGIN::RELEASER plugin;
|
||||
LIB_T type;
|
||||
private:
|
||||
PLUGIN::RELEASER plugin;
|
||||
IO_MGR::PCB_FILE_T type;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -145,27 +145,57 @@ public:
|
|||
* Constructor
|
||||
*
|
||||
* @param aCurrentDir is current directory the path editor will open at
|
||||
* @param aExt is the file extension(s) to filter by. If empty, the path editor will switch
|
||||
* to folder mode instead of file.
|
||||
* @param aNormalize indicates whether to normalize the selected path (replace part of path
|
||||
* with variables or relative path)
|
||||
* @param aNormalizeBasePath is the path to use when trying to base variables (generally
|
||||
* current project path)
|
||||
* @param aFileFilterFn a callback which provides a file extension(s) filter.
|
||||
*/
|
||||
GRID_CELL_PATH_EDITOR( DIALOG_SHIM* aParentDialog, WX_GRID* aGrid, wxString* aCurrentDir,
|
||||
bool aNormalize, const wxString& aNormalizeBasePath,
|
||||
std::function<wxString( WX_GRID* grid, int row )> aFileFilterFn ) :
|
||||
m_dlg( aParentDialog ),
|
||||
m_grid( aGrid ),
|
||||
m_currentDir( aCurrentDir ),
|
||||
m_normalize( aNormalize ),
|
||||
m_normalizeBasePath( aNormalizeBasePath ),
|
||||
m_fileFilterFn( std::move( aFileFilterFn ) )
|
||||
{ }
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param aCurrentDir is current directory the path editor will open at
|
||||
* @param aFileFilter is the file extension(s) to filter by. If empty, the path editor will
|
||||
* switch to folder mode instead of file.
|
||||
* @param aNormalize indicates whether to normalize the selected path (replace part of path
|
||||
* with variables or relative path)
|
||||
* @param aNormalizeBasePath is the path to use when trying to base variables (generally
|
||||
* current project path)
|
||||
*/
|
||||
GRID_CELL_PATH_EDITOR( DIALOG_SHIM* aParentDialog, WX_GRID* aGrid, wxString* aCurrentDir,
|
||||
const wxString& aExt, bool aNormalize = false,
|
||||
const wxString& aFileFilter, bool aNormalize = false,
|
||||
const wxString& aNormalizeBasePath = wxEmptyString ) :
|
||||
m_dlg( aParentDialog ),
|
||||
m_grid( aGrid ),
|
||||
m_currentDir( aCurrentDir ),
|
||||
m_ext( aExt ),
|
||||
m_normalize( aNormalize ),
|
||||
m_normalizeBasePath( aNormalizeBasePath )
|
||||
m_normalizeBasePath( aNormalizeBasePath ),
|
||||
m_fileFilter( aFileFilter )
|
||||
{ }
|
||||
|
||||
wxGridCellEditor* Clone() const override
|
||||
{
|
||||
return new GRID_CELL_PATH_EDITOR( m_dlg, m_grid, m_currentDir, m_ext );
|
||||
if( m_fileFilterFn )
|
||||
{
|
||||
return new GRID_CELL_PATH_EDITOR( m_dlg, m_grid, m_currentDir, m_normalize,
|
||||
m_normalizeBasePath, m_fileFilterFn );
|
||||
}
|
||||
else
|
||||
{
|
||||
return new GRID_CELL_PATH_EDITOR( m_dlg, m_grid, m_currentDir, m_fileFilter,
|
||||
m_normalize, m_normalizeBasePath );
|
||||
}
|
||||
}
|
||||
|
||||
void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
|
||||
|
@ -174,9 +204,11 @@ protected:
|
|||
DIALOG_SHIM* m_dlg;
|
||||
WX_GRID* m_grid;
|
||||
wxString* m_currentDir;
|
||||
wxString m_ext;
|
||||
bool m_normalize;
|
||||
wxString m_normalizeBasePath;
|
||||
|
||||
wxString m_fileFilter;
|
||||
std::function<wxString( WX_GRID* aGrid, int aRow )> m_fileFilterFn;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -330,9 +330,19 @@ PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, PRO
|
|||
|
||||
attr = new wxGridCellAttr;
|
||||
attr->SetEditor( new GRID_CELL_PATH_EDITOR( m_parent, aGrid,
|
||||
&cfg->m_lastFootprintLibDir,
|
||||
wxEmptyString, true,
|
||||
m_projectBasePath ) );
|
||||
&cfg->m_lastFootprintLibDir, true, m_projectBasePath,
|
||||
[this]( WX_GRID* grid, int row ) -> wxString
|
||||
{
|
||||
auto* libTable = static_cast<FP_LIB_TABLE_GRID*>( grid->GetTable() );
|
||||
auto* tableRow = static_cast<FP_LIB_TABLE_ROW*>( libTable->at( row ) );
|
||||
IO_MGR::PCB_FILE_T fileType = tableRow->GetFileType();
|
||||
const PLUGIN_FILE_DESC& pluginDesc = m_supportedFpFiles.at( fileType );
|
||||
|
||||
if( pluginDesc.m_IsFile )
|
||||
return pluginDesc.FileFilter();
|
||||
else
|
||||
return wxEmptyString;
|
||||
} ) );
|
||||
aGrid->SetColAttr( COL_URI, attr );
|
||||
|
||||
attr = new wxGridCellAttr;
|
||||
|
@ -426,12 +436,13 @@ PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, PRO
|
|||
|
||||
if( desc.m_IsFile && !desc.m_FileExtensions.empty() )
|
||||
{
|
||||
entryStr << wxString::Format( wxS( " (%s)" ), joinExts( desc.m_FileExtensions ) );
|
||||
entryStr << wxString::Format( wxS( " (%s)" ),
|
||||
joinExts( desc.m_FileExtensions ) );
|
||||
}
|
||||
else if( !desc.m_IsFile && !desc.m_ExtensionsInDir.empty() )
|
||||
{
|
||||
wxString midPart =
|
||||
wxString::Format( _( "folder with %s files" ), joinExts( desc.m_ExtensionsInDir ) );
|
||||
wxString midPart = wxString::Format( _( "folder with %s files" ),
|
||||
joinExts( desc.m_ExtensionsInDir ) );
|
||||
|
||||
entryStr << wxString::Format( wxS( " (%s)" ), midPart );
|
||||
}
|
||||
|
|
|
@ -52,8 +52,9 @@ public:
|
|||
*/
|
||||
enum PCB_FILE_T
|
||||
{
|
||||
KICAD_SEXP, ///< S-expression Pcbnew file format.
|
||||
LEGACY, ///< Legacy Pcbnew file formats prior to s-expression.
|
||||
UNKNOWN = 0, ///< 0 is not a legal menu id on Mac
|
||||
KICAD_SEXP, ///< S-expression Pcbnew file format.
|
||||
LEGACY, ///< Legacy Pcbnew file formats prior to s-expression.
|
||||
ALTIUM_CIRCUIT_MAKER,
|
||||
ALTIUM_CIRCUIT_STUDIO,
|
||||
ALTIUM_DESIGNER,
|
||||
|
|
Loading…
Reference in New Issue