From ba7b970817a284d7266d868de9b3bcd66a45e634 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 31 Jan 2019 01:07:53 +0000 Subject: [PATCH] Add pre-select architecture to grid helper icon-text-buttons. Fixes: lp:1813973 * https://bugs.launchpad.net/kicad/+bug/1813973 --- common/widgets/grid_text_button_helpers.cpp | 26 +++++++++--- .../dialogs/dialog_edit_components_libid.cpp | 19 +++++++-- .../dialog_edit_components_libid_base.cpp | 2 - .../dialog_edit_components_libid_base.fbp | 1 - eeschema/viewlib_frame.cpp | 42 ++++++++++++++++++- eeschema/viewlib_frame.h | 9 ++++ include/widgets/grid_text_button_helpers.h | 16 ++++--- 7 files changed, 97 insertions(+), 18 deletions(-) diff --git a/common/widgets/grid_text_button_helpers.cpp b/common/widgets/grid_text_button_helpers.cpp index d6ff3b2b4e..082018265c 100644 --- a/common/widgets/grid_text_button_helpers.cpp +++ b/common/widgets/grid_text_button_helpers.cpp @@ -157,9 +157,11 @@ void GRID_CELL_TEXT_BUTTON::Reset() class TEXT_BUTTON_SYMBOL_CHOOSER : public wxComboCtrl { public: - TEXT_BUTTON_SYMBOL_CHOOSER( wxWindow* aParent, DIALOG_SHIM* aParentDlg ) : + TEXT_BUTTON_SYMBOL_CHOOSER( wxWindow* aParent, DIALOG_SHIM* aParentDlg, + const wxString& aPreselect ) : wxComboCtrl( aParent ), - m_dlg( aParentDlg ) + m_dlg( aParentDlg ), + m_preselect( aPreselect ) { SetButtonBitmaps( KiBitmap( small_library_xpm ) ); } @@ -174,6 +176,10 @@ protected: { // pick a footprint using the footprint picker. wxString compid = GetValue(); + + if( compid.IsEmpty() ) + compid = m_preselect; + KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_SCH_VIEWER_MODAL, true, m_dlg ); if( frame->ShowModal( &compid, m_dlg ) ) @@ -183,13 +189,14 @@ protected: } DIALOG_SHIM* m_dlg; + wxString m_preselect; }; void GRID_CELL_SYMBOL_ID_EDITOR::Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) { - m_control = new TEXT_BUTTON_SYMBOL_CHOOSER( aParent, m_dlg ); + m_control = new TEXT_BUTTON_SYMBOL_CHOOSER( aParent, m_dlg, m_preselect ); wxGridCellEditor::Create(aParent, aId, aEventHandler); } @@ -202,9 +209,11 @@ void GRID_CELL_SYMBOL_ID_EDITOR::Create( wxWindow* aParent, wxWindowID aId, class TEXT_BUTTON_FP_CHOOSER : public wxComboCtrl { public: - TEXT_BUTTON_FP_CHOOSER( wxWindow* aParent, DIALOG_SHIM* aParentDlg ) : + TEXT_BUTTON_FP_CHOOSER( wxWindow* aParent, DIALOG_SHIM* aParentDlg, + const wxString& aPreselect ) : wxComboCtrl( aParent ), - m_dlg( aParentDlg ) + m_dlg( aParentDlg ), + m_preselect( aPreselect ) { SetButtonBitmaps( KiBitmap( small_library_xpm ) ); } @@ -219,6 +228,10 @@ protected: { // pick a footprint using the footprint picker. wxString fpid = GetValue(); + + if( fpid.IsEmpty() ) + fpid = m_preselect; + KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_PCB_MODULE_VIEWER_MODAL, true, m_dlg ); if( frame->ShowModal( &fpid, m_dlg ) ) @@ -228,13 +241,14 @@ protected: } DIALOG_SHIM* m_dlg; + wxString m_preselect; }; void GRID_CELL_FOOTPRINT_ID_EDITOR::Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) { - m_control = new TEXT_BUTTON_FP_CHOOSER( aParent, m_dlg ); + m_control = new TEXT_BUTTON_FP_CHOOSER( aParent, m_dlg, m_preselect ); wxGridCellEditor::Create(aParent, aId, aEventHandler); } diff --git a/eeschema/dialogs/dialog_edit_components_libid.cpp b/eeschema/dialogs/dialog_edit_components_libid.cpp index ab22113ad9..91ef906414 100644 --- a/eeschema/dialogs/dialog_edit_components_libid.cpp +++ b/eeschema/dialogs/dialog_edit_components_libid.cpp @@ -347,7 +347,12 @@ private: { if( m_isModified ) revertChanges(); - event.Skip(); + + // Just skipping the event doesn't work after the library browser was run + if( IsQuasiModal() ) + EndQuasiModal( wxID_CANCEL ); + else + event.Skip(); } // Undo all changes, and clear the list of new lib_ids @@ -550,8 +555,8 @@ void DIALOG_EDIT_COMPONENTS_LIBID::AddRowToGrid( bool aMarkRow, const wxString& // set new libid column browse button wxGridCellAttr* attr = new wxGridCellAttr; - attr->SetEditor( new GRID_CELL_SYMBOL_ID_EDITOR( this ) ); - m_grid->SetColAttr( COL_NEW_LIBID, attr ); + attr->SetEditor( new GRID_CELL_SYMBOL_ID_EDITOR( this, aStrLibId ) ); + m_grid->SetAttr( row, COL_NEW_LIBID, attr ); } @@ -727,6 +732,14 @@ bool DIALOG_EDIT_COMPONENTS_LIBID::setLibIdByBrowser( int aRow ) #else // Use library viewer to choose a symbol LIB_ID aPreselectedLibid; + wxString current = m_grid->GetCellValue( aRow, COL_NEW_LIBID ); + + if( current.IsEmpty() ) + current = m_grid->GetCellValue( aRow, COL_CURR_LIBID ); + + if( !current.IsEmpty() ) + aPreselectedLibid.Parse( current, LIB_ID::ID_SCH, true ); + SCH_BASE_FRAME::COMPONENT_SELECTION sel = m_parent->SelectComponentFromLibBrowser( this, NULL, aPreselectedLibid, 0, 0 ); #endif diff --git a/eeschema/dialogs/dialog_edit_components_libid_base.cpp b/eeschema/dialogs/dialog_edit_components_libid_base.cpp index b4c335c60d..d5117cbd8b 100644 --- a/eeschema/dialogs/dialog_edit_components_libid_base.cpp +++ b/eeschema/dialogs/dialog_edit_components_libid_base.cpp @@ -103,7 +103,6 @@ DIALOG_EDIT_COMPONENTS_LIBID_BASE::DIALOG_EDIT_COMPONENTS_LIBID_BASE( wxWindow* // Connect Events m_grid->Connect( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCellBrowseLib ), NULL, this ); - m_grid->Connect( wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCellBrowseLib ), NULL, this ); m_grid->Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::OnSizeGrid ), NULL, this ); m_buttonUndo->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onUndoChangesButton ), NULL, this ); m_buttonUndo->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::updateUIChangesButton ), NULL, this ); @@ -116,7 +115,6 @@ DIALOG_EDIT_COMPONENTS_LIBID_BASE::~DIALOG_EDIT_COMPONENTS_LIBID_BASE() { // Disconnect Events m_grid->Disconnect( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCellBrowseLib ), NULL, this ); - m_grid->Disconnect( wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCellBrowseLib ), NULL, this ); m_grid->Disconnect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::OnSizeGrid ), NULL, this ); m_buttonUndo->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onUndoChangesButton ), NULL, this ); m_buttonUndo->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::updateUIChangesButton ), NULL, this ); diff --git a/eeschema/dialogs/dialog_edit_components_libid_base.fbp b/eeschema/dialogs/dialog_edit_components_libid_base.fbp index 7e511653a7..edb0af076e 100644 --- a/eeschema/dialogs/dialog_edit_components_libid_base.fbp +++ b/eeschema/dialogs/dialog_edit_components_libid_base.fbp @@ -185,7 +185,6 @@ onCellBrowseLib - onCellBrowseLib diff --git a/eeschema/viewlib_frame.cpp b/eeschema/viewlib_frame.cpp index 336e4df4c5..259150381f 100644 --- a/eeschema/viewlib_frame.cpp +++ b/eeschema/viewlib_frame.cpp @@ -47,7 +47,7 @@ #include #include #include - +#include // Save previous component library viewer state. wxString LIB_VIEW_FRAME::m_libraryName; @@ -320,6 +320,46 @@ void LIB_VIEW_FRAME::onUpdateNormalBodyStyleButton( wxUpdateUIEvent& aEvent ) } +bool LIB_VIEW_FRAME::ShowModal( wxString* aSymbol, wxWindow* aParent ) +{ + if( aSymbol && !aSymbol->IsEmpty() ) + { + wxString msg; + LIB_TABLE* libTable = Prj().SchSymbolLibTable(); + LIB_ID libid; + + libid.Parse( *aSymbol, LIB_ID::ID_SCH, true ); + + if( libid.IsValid() ) + { + wxString nickname = libid.GetLibNickname(); + + if( !libTable->HasLibrary( libid.GetLibNickname(), false ) ) + { + msg.sprintf( _( "The current configuration does not include a library with the\n" + "nickname \"%s\". Use Manage Symbol Libraries\n" + "to edit the configuration." ), nickname ); + DisplayErrorMessage( aParent, _( "Symbol library not found." ), msg ); + } + else if ( !libTable->HasLibrary( libid.GetLibNickname(), true ) ) + { + msg.sprintf( _( "The library with the nickname \"%s\" is not enabled\n" + "in the current configuration. Use Manage Symbol Libraries to\n" + "edit the configuration." ), nickname ); + DisplayErrorMessage( aParent, _( "Symbol library not enabled." ), msg ); + } + else + { + SetSelectedLibrary( libid.GetLibNickname() ); + SetSelectedComponent( libid.GetLibItemName() ); + } + } + } + + return KIWAY_PLAYER::ShowModal( aSymbol, aParent ); +} + + void LIB_VIEW_FRAME::OnCloseWindow( wxCloseEvent& Event ) { GetCanvas()->StopDrawing(); diff --git a/eeschema/viewlib_frame.h b/eeschema/viewlib_frame.h index c73143df84..d9b94ddbf9 100644 --- a/eeschema/viewlib_frame.h +++ b/eeschema/viewlib_frame.h @@ -58,6 +58,15 @@ public: ~LIB_VIEW_FRAME(); + /** + * Function ShowModal + * + * Runs the Symbol Viewer as a modal dialog. + * @param aSymbol an optional FPID string to initialize the viewer with and to + * return a selected footprint through. + */ + bool ShowModal( wxString* aSymbol, wxWindow* aParent ) override; + void OnSize( wxSizeEvent& event ) override; /** diff --git a/include/widgets/grid_text_button_helpers.h b/include/widgets/grid_text_button_helpers.h index db942d3f92..4c79675a53 100644 --- a/include/widgets/grid_text_button_helpers.h +++ b/include/widgets/grid_text_button_helpers.h @@ -60,27 +60,32 @@ protected: class GRID_CELL_SYMBOL_ID_EDITOR : public GRID_CELL_TEXT_BUTTON { public: - GRID_CELL_SYMBOL_ID_EDITOR( DIALOG_SHIM* aParent ) : - m_dlg( aParent ) + GRID_CELL_SYMBOL_ID_EDITOR( DIALOG_SHIM* aParent, + const wxString& aPreselect = wxEmptyString ) : + m_dlg( aParent ), + m_preselect( aPreselect ) { } wxGridCellEditor* Clone() const override { - return new GRID_CELL_SYMBOL_ID_EDITOR( m_dlg ); + return new GRID_CELL_SYMBOL_ID_EDITOR( m_dlg, m_preselect ); } void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override; protected: DIALOG_SHIM* m_dlg; + wxString m_preselect; }; class GRID_CELL_FOOTPRINT_ID_EDITOR : public GRID_CELL_TEXT_BUTTON { public: - GRID_CELL_FOOTPRINT_ID_EDITOR( DIALOG_SHIM* aParent ) : - m_dlg( aParent ) + GRID_CELL_FOOTPRINT_ID_EDITOR( DIALOG_SHIM* aParent, + const wxString& aPreselect = wxEmptyString ) : + m_dlg( aParent ), + m_preselect( aPreselect ) { } wxGridCellEditor* Clone() const override @@ -92,6 +97,7 @@ public: protected: DIALOG_SHIM* m_dlg; + wxString m_preselect; };