From 6d2dfbb5c390cd21094f6e5b981a8cc3588a7cd6 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 20 Jul 2018 23:26:37 +0100 Subject: [PATCH] Add Select Footprint and Show Datasheet to Symbol Fields Editor. Fixes: lp:1782848 * https://bugs.launchpad.net/kicad/+bug/1782848 --- .../dialogs/dialog_fields_editor_global.cpp | 70 +++++++++++++++++-- 1 file changed, 64 insertions(+), 6 deletions(-) diff --git a/eeschema/dialogs/dialog_fields_editor_global.cpp b/eeschema/dialogs/dialog_fields_editor_global.cpp index c819f1b355..7662d1dc37 100644 --- a/eeschema/dialogs/dialog_fields_editor_global.cpp +++ b/eeschema/dialogs/dialog_fields_editor_global.cpp @@ -36,22 +36,69 @@ #include #include #include +#include +#include #include "dialog_fields_editor_global.h" +enum +{ + MYID_SELECT_FOOTPRINT = 991, // must be within GRID_TRICKS' enum range + MYID_SHOW_DATASHEET +}; + + class FIELDS_EDITOR_GRID_TRICKS : public GRID_TRICKS { public: - FIELDS_EDITOR_GRID_TRICKS( wxGrid* aGrid, wxDataViewListCtrl* aFieldsCtrl ) : + FIELDS_EDITOR_GRID_TRICKS( DIALOG_SHIM* aParent, wxGrid* aGrid, + wxDataViewListCtrl* aFieldsCtrl ) : GRID_TRICKS( aGrid ), + m_dlg( aParent ), m_fieldsCtrl( aFieldsCtrl ) {} protected: + void showPopupMenu( wxMenu& menu ) override + { + if( m_grid->GetGridCursorCol() == FOOTPRINT ) + { + menu.Append( MYID_SELECT_FOOTPRINT, _( "Select Footprint..." ), _( "Browse for footprint" ) ); + menu.AppendSeparator(); + } + else if( m_grid->GetGridCursorCol() == DATASHEET ) + { + menu.Append( MYID_SHOW_DATASHEET, _( "Show Datasheet" ), _( "Show datasheet in browser" ) ); + menu.AppendSeparator(); + } + + GRID_TRICKS::showPopupMenu( menu ); + } + void doPopupSelection( wxCommandEvent& event ) override { - GRID_TRICKS::doPopupSelection( event ); + if( event.GetId() == MYID_SELECT_FOOTPRINT ) + { + // pick a footprint using the footprint picker. + wxString fpid = m_grid->GetCellValue( m_grid->GetGridCursorRow(), FOOTPRINT ); + KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_PCB_MODULE_VIEWER_MODAL, true, m_dlg ); + + if( frame->ShowModal( &fpid, m_dlg ) ) + m_grid->SetCellValue( m_grid->GetGridCursorRow(), FOOTPRINT, fpid ); + + frame->Destroy(); + } + else if (event.GetId() == MYID_SHOW_DATASHEET ) + { + wxString datasheet_uri = m_grid->GetCellValue( m_grid->GetGridCursorRow(), DATASHEET ); + datasheet_uri = ResolveUriByEnvVars( datasheet_uri ); + GetAssociatedDocument( m_dlg, datasheet_uri ); + } + else + { + GRID_TRICKS::doPopupSelection( event ); + } if( event.GetId() >= GRIDTRICKS_FIRST_SHOWHIDE && event.GetId() < GRIDTRICKS_LAST_ID ) { @@ -61,6 +108,7 @@ protected: } } + DIALOG_SHIM* m_dlg; wxDataViewListCtrl* m_fieldsCtrl; }; @@ -609,17 +657,27 @@ DIALOG_FIELDS_EDITOR_GLOBAL::DIALOG_FIELDS_EDITOR_GLOBAL( SCH_EDIT_FRAME* parent } // add Cut, Copy, and Paste to wxGrid - m_grid->PushEventHandler( new FIELDS_EDITOR_GRID_TRICKS( m_grid, m_fieldsCtrl ) ); + m_grid->PushEventHandler( new FIELDS_EDITOR_GRID_TRICKS( this, m_grid, m_fieldsCtrl ) ); - // give a bit more room for editing - m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 2 ); + // give a bit more room for comboboxes + m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 ); // set reference column attributes wxGridCellAttr* attr = new wxGridCellAttr; attr->SetReadOnly(); - m_grid->SetColAttr( 0, attr ); + m_grid->SetColAttr( REFERENCE, attr ); m_grid->SetColMinimalWidth( 0, 100 ); + // set footprint column browse button + attr = new wxGridCellAttr; + attr->SetEditor( new GRID_CELL_FOOTPRINT_EDITOR( this ) ); + m_grid->SetColAttr( FOOTPRINT, attr ); + + // set datasheet column viewer button + attr = new wxGridCellAttr; + attr->SetEditor( new GRID_CELL_URL_EDITOR( this ) ); + m_grid->SetColAttr( DATASHEET, attr ); + // set quantities column attributes attr = new wxGridCellAttr; attr->SetReadOnly();