From 38be0fccb7b8cbcd9aee9e5a056ef6708c7266f5 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Sat, 2 Mar 2019 20:04:17 -0800 Subject: [PATCH] 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 --- common/widgets/grid_text_button_helpers.cpp | 40 +++++++++++++++++---- eeschema/dialogs/panel_sym_lib_table.cpp | 3 +- include/widgets/grid_text_button_helpers.h | 23 ++++++++++++ 3 files changed, 58 insertions(+), 8 deletions(-) diff --git a/common/widgets/grid_text_button_helpers.cpp b/common/widgets/grid_text_button_helpers.cpp index 082018265c..b4ce2f0356 100644 --- a/common/widgets/grid_text_button_helpers.cpp +++ b/common/widgets/grid_text_button_helpers.cpp @@ -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); +} + + diff --git a/eeschema/dialogs/panel_sym_lib_table.cpp b/eeschema/dialogs/panel_sym_lib_table.cpp index daf06975d8..5c1ef541a4 100644 --- a/eeschema/dialogs/panel_sym_lib_table.cpp +++ b/eeschema/dialogs/panel_sym_lib_table.cpp @@ -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; diff --git a/include/widgets/grid_text_button_helpers.h b/include/widgets/grid_text_button_helpers.h index 4c79675a53..169f4364e3 100644 --- a/include/widgets/grid_text_button_helpers.h +++ b/include/widgets/grid_text_button_helpers.h @@ -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