Symlib table: Need button handler for files

The folder button handler works will for footprint libraries but we
needed a specific class for the schematic libraries as well.

Fixes: lp:1818346
* https://bugs.launchpad.net/kicad/+bug/1818346
This commit is contained in:
Seth Hillbrand 2019-03-02 20:04:17 -08:00
parent db31b7902a
commit 38be0fccb7
3 changed files with 58 additions and 8 deletions

View File

@ -305,10 +305,12 @@ void GRID_CELL_URL_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
class TEXT_BUTTON_FILE_BROWSER : public wxComboCtrl
{
public:
TEXT_BUTTON_FILE_BROWSER( wxWindow* aParent, DIALOG_SHIM* aParentDlg, wxString* aCurrentDir ) :
TEXT_BUTTON_FILE_BROWSER( wxWindow* aParent, DIALOG_SHIM* aParentDlg,
wxString* aCurrentDir, wxString* aExt = nullptr ) :
wxComboCtrl( aParent ),
m_dlg( aParentDlg ),
m_currentDir( aCurrentDir )
m_currentDir( aCurrentDir ),
m_ext( aExt )
{
SetButtonBitmaps( KiBitmap( folder_xpm ) );
}
@ -328,18 +330,33 @@ protected:
else
path = ExpandEnvVarSubstitutions( path );
wxDirDialog dlg( nullptr, _( "Select Path" ), path,
if( m_ext )
{
wxFileDialog dlg( nullptr, _( "Select a File" ), path, wxEmptyString, *m_ext,
wxFD_FILE_MUST_EXIST | wxFD_OPEN );
if( dlg.ShowModal() == wxID_OK )
{
SetValue( dlg.GetPath() );
*m_currentDir = dlg.GetPath();
}
}
else
{
wxDirDialog dlg( nullptr, _( "Select Path" ), path,
wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
if( dlg.ShowModal() == wxID_OK )
{
SetValue( dlg.GetPath() );
*m_currentDir = dlg.GetPath();
if( dlg.ShowModal() == wxID_OK )
{
SetValue( dlg.GetPath() );
*m_currentDir = dlg.GetPath();
}
}
}
DIALOG_SHIM* m_dlg;
wxString* m_currentDir;
wxString* m_ext;
};
@ -352,3 +369,12 @@ void GRID_CELL_PATH_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
}
void GRID_CELL_SYMLIB_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
wxEvtHandler* aEventHandler )
{
m_control = new TEXT_BUTTON_FILE_BROWSER( aParent, m_dlg, m_currentDir, &m_ext );
wxGridCellEditor::Create(aParent, aId, aEventHandler);
}

View File

@ -192,7 +192,8 @@ PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent,
wxGridCellAttr* attr;
attr = new wxGridCellAttr;
attr->SetEditor( new GRID_CELL_PATH_EDITOR( m_parent, &m_lastBrowseDir ) );
attr->SetEditor( new GRID_CELL_SYMLIB_EDITOR( m_parent, &m_lastBrowseDir,
SchematicLibraryFileWildcard() ) );
g->SetColAttr( COL_URI, attr );
attr = new wxGridCellAttr;

View File

@ -141,4 +141,27 @@ protected:
};
class GRID_CELL_SYMLIB_EDITOR : public GRID_CELL_TEXT_BUTTON
{
public:
GRID_CELL_SYMLIB_EDITOR( DIALOG_SHIM* aParent, wxString* aCurrentDir, const wxString& aExt ) :
m_dlg( aParent ),
m_currentDir( aCurrentDir ),
m_ext( aExt )
{ }
wxGridCellEditor* Clone() const override
{
return new GRID_CELL_SYMLIB_EDITOR( m_dlg, m_currentDir, m_ext );
}
void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
protected:
DIALOG_SHIM* m_dlg;
wxString* m_currentDir;
wxString m_ext;
};
#endif // GRID_TEXT_BUTTON_HELPERS_H