From 3c2aafd7b7dcf6b17addefa33cc39624ef1206f0 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 29 Sep 2018 17:18:55 +0100 Subject: [PATCH] Move Edit Symbol References to standard text/button control. --- common/widgets/grid_text_button_helpers.cpp | 49 ++++++++++++- .../dialogs/dialog_edit_components_libid.cpp | 43 +++++++++-- .../dialog_edit_components_libid_base.cpp | 4 +- .../dialog_edit_components_libid_base.fbp | 72 +------------------ .../dialog_edit_components_libid_base.h | 5 +- .../dialogs/dialog_fields_editor_global.cpp | 2 +- eeschema/fields_grid_table.cpp | 2 +- include/widgets/grid_text_button_helpers.h | 25 ++++++- 8 files changed, 115 insertions(+), 87 deletions(-) diff --git a/common/widgets/grid_text_button_helpers.cpp b/common/widgets/grid_text_button_helpers.cpp index 76a19739fe..ae17a36407 100644 --- a/common/widgets/grid_text_button_helpers.cpp +++ b/common/widgets/grid_text_button_helpers.cpp @@ -149,6 +149,51 @@ void GRID_CELL_TEXT_BUTTON::Reset() } +/** + * Symbol Picker + */ + +class TEXT_BUTTON_SYMBOL_CHOOSER : public wxComboCtrl +{ +public: + TEXT_BUTTON_SYMBOL_CHOOSER( wxWindow* aParent, DIALOG_SHIM* aParentDlg ) : + wxComboCtrl( aParent ), + m_dlg( aParentDlg ) + { + SetButtonBitmaps( KiBitmap( small_library_xpm ) ); + } + +protected: + void DoSetPopupControl( wxComboPopup* popup ) override + { + m_popup = nullptr; + } + + void OnButtonClick() override + { + // pick a footprint using the footprint picker. + wxString compid = GetValue(); + KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_SCH_VIEWER_MODAL, true, m_dlg ); + + if( frame->ShowModal( &compid, m_dlg ) ) + SetValue( compid ); + + frame->Destroy(); + } + + DIALOG_SHIM* m_dlg; +}; + + +void GRID_CELL_SYMBOL_ID_EDITOR::Create( wxWindow* aParent, wxWindowID aId, + wxEvtHandler* aEventHandler ) +{ + m_control = new TEXT_BUTTON_SYMBOL_CHOOSER( aParent, m_dlg ); + + wxGridCellEditor::Create(aParent, aId, aEventHandler); +} + + /** * Footprint Picker */ @@ -185,8 +230,8 @@ protected: }; -void GRID_CELL_FOOTPRINT_EDITOR::Create( wxWindow* aParent, wxWindowID aId, - wxEvtHandler* aEventHandler ) +void GRID_CELL_FOOTPRINT_ID_EDITOR::Create( wxWindow* aParent, wxWindowID aId, + wxEvtHandler* aEventHandler ) { m_control = new TEXT_BUTTON_FP_CHOOSER( aParent, m_dlg ); diff --git a/eeschema/dialogs/dialog_edit_components_libid.cpp b/eeschema/dialogs/dialog_edit_components_libid.cpp index da76cc757e..ffaa68c770 100644 --- a/eeschema/dialogs/dialog_edit_components_libid.cpp +++ b/eeschema/dialogs/dialog_edit_components_libid.cpp @@ -39,6 +39,7 @@ #include #include +#include #define COL_REFS 0 #define COL_CURR_LIBID 1 @@ -303,8 +304,8 @@ public: bool IsSchematicModified() { return m_isModified; } private: - SCH_EDIT_FRAME* m_parent; - bool m_isModified; // set to true if the schematic is modified + SCH_EDIT_FRAME* m_parent; + bool m_isModified; // set to true if the schematic is modified std::vector m_OrphansRowIndexes; // list of rows containing orphan lib_id std::vector m_components; @@ -376,6 +377,8 @@ DIALOG_EDIT_COMPONENTS_LIBID::DIALOG_EDIT_COMPONENTS_LIBID( SCH_EDIT_FRAME* aPar m_parent = aParent; m_autoWrapRenderer = new GRIDCELL_AUTOWRAP_STRINGRENDERER; + m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) ); + initDlg(); FinishDialogSettings(); @@ -384,6 +387,9 @@ DIALOG_EDIT_COMPONENTS_LIBID::DIALOG_EDIT_COMPONENTS_LIBID( SCH_EDIT_FRAME* aPar DIALOG_EDIT_COMPONENTS_LIBID::~DIALOG_EDIT_COMPONENTS_LIBID() { + // Delete the GRID_TRICKS. + m_grid->PopEventHandler( true ); + m_autoWrapRenderer->DecRef(); } @@ -541,6 +547,11 @@ void DIALOG_EDIT_COMPONENTS_LIBID::AddRowToGrid( bool aMarkRow, const wxString& // (fixed in 2014, but didn't get in to wxWidgets 3.0.2) wxClientDC dc( this ); m_grid->SetRowSize( row, m_autoWrapRenderer->GetHeight( dc, m_grid, row, COL_REFS ) ); + + // 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 ); } @@ -816,9 +827,31 @@ void DIALOG_EDIT_COMPONENTS_LIBID::AdjustGridColumns( int aWidth ) // Account for scroll bars aWidth -= ( m_grid->GetSize().x - m_grid->GetClientSize().x ); - m_grid->SetColSize( 0, aWidth / 3 ); - m_grid->SetColSize( 1, aWidth / 3 ); - m_grid->SetColSize( 2, aWidth - m_grid->GetColSize( 0 ) - m_grid->GetColSize( 1 ) ); + int colWidth = aWidth / 3; + + m_grid->SetColSize( COL_REFS, colWidth ); + aWidth -= colWidth; + + colWidth = 0; + for( int row = 0; row < m_grid->GetNumberRows(); ++row ) + { + wxString cellValue = m_grid->GetCellValue( row, COL_CURR_LIBID ); + colWidth = std::max( colWidth, GetTextSize( cellValue, m_grid ).x ); + } + + colWidth += 20; + m_grid->SetColSize( COL_CURR_LIBID, colWidth ); + aWidth -= colWidth; + + colWidth = 0; + for( int row = 0; row < m_grid->GetNumberRows(); ++row ) + { + wxString cellValue = m_grid->GetCellValue( row, COL_NEW_LIBID ); + colWidth = std::max( colWidth, GetTextSize( cellValue, m_grid ).x ); + } + + colWidth += 20; + m_grid->SetColSize( COL_NEW_LIBID, std::max( colWidth, aWidth ) ); } diff --git a/eeschema/dialogs/dialog_edit_components_libid_base.cpp b/eeschema/dialogs/dialog_edit_components_libid_base.cpp index 3fda877995..b4c335c60d 100644 --- a/eeschema/dialogs/dialog_edit_components_libid_base.cpp +++ b/eeschema/dialogs/dialog_edit_components_libid_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Jul 11 2018) +// C++ code generated with wxFormBuilder (version Dec 30 2017) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -93,7 +93,7 @@ DIALOG_EDIT_COMPONENTS_LIBID_BASE::DIALOG_EDIT_COMPONENTS_LIBID_BASE( wxWindow* bSizerButtons->Add( m_sdbSizer, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); - bSizerMain->Add( bSizerButtons, 0, wxEXPAND, 5 ); + bSizerMain->Add( bSizerButtons, 0, wxEXPAND|wxLEFT, 5 ); this->SetSizer( bSizerMain ); diff --git a/eeschema/dialogs/dialog_edit_components_libid_base.fbp b/eeschema/dialogs/dialog_edit_components_libid_base.fbp index a0bc95a189..7e511653a7 100644 --- a/eeschema/dialogs/dialog_edit_components_libid_base.fbp +++ b/eeschema/dialogs/dialog_edit_components_libid_base.fbp @@ -1,6 +1,6 @@ - + C++ @@ -14,7 +14,6 @@ dialog_edit_components_libid_base 1000 none - 1 dialog_edit_components_libid_base @@ -55,20 +54,13 @@ - + - - - - - - - @@ -83,23 +75,17 @@ - - - - - - @@ -193,14 +179,7 @@ - - - - - - - @@ -299,7 +278,6 @@ 0 wxID_ANY Warning: changes made from this dialog cannot be undone after closing it. - 0 0 @@ -325,14 +303,7 @@ -1 - - - - - - - @@ -372,31 +343,25 @@ - 1 0 1 1 - 0 0 - Dock 0 Left 1 1 - 0 0 wxID_ANY Undo Changes - - 0 0 @@ -411,8 +376,6 @@ protected 1 - - Resizable 1 @@ -427,15 +390,8 @@ - - - - - - onUndoChangesButton - @@ -518,14 +474,7 @@ - - - - - - - @@ -552,7 +501,7 @@ 5 - wxEXPAND + wxEXPAND|wxLEFT 0 @@ -574,31 +523,25 @@ - 1 0 1 1 - 0 0 - Dock 0 Left 1 1 - 0 0 wxID_ANY Map Orphans - - 0 0 @@ -613,8 +556,6 @@ protected 1 - - Resizable 1 @@ -629,15 +570,8 @@ - - - - - - onClickOrphansButton - diff --git a/eeschema/dialogs/dialog_edit_components_libid_base.h b/eeschema/dialogs/dialog_edit_components_libid_base.h index 8963f9c1ee..4b2cd23d46 100644 --- a/eeschema/dialogs/dialog_edit_components_libid_base.h +++ b/eeschema/dialogs/dialog_edit_components_libid_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Jul 11 2018) +// C++ code generated with wxFormBuilder (version Dec 30 2017) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -21,9 +21,6 @@ class WX_GRID; #include #include #include -#include -#include -#include #include #include #include diff --git a/eeschema/dialogs/dialog_fields_editor_global.cpp b/eeschema/dialogs/dialog_fields_editor_global.cpp index db18006b4c..d2d2b67005 100644 --- a/eeschema/dialogs/dialog_fields_editor_global.cpp +++ b/eeschema/dialogs/dialog_fields_editor_global.cpp @@ -704,7 +704,7 @@ DIALOG_FIELDS_EDITOR_GLOBAL::DIALOG_FIELDS_EDITOR_GLOBAL( SCH_EDIT_FRAME* parent // set footprint column browse button attr = new wxGridCellAttr; - attr->SetEditor( new GRID_CELL_FOOTPRINT_EDITOR( this ) ); + attr->SetEditor( new GRID_CELL_FOOTPRINT_ID_EDITOR( this ) ); m_grid->SetColAttr( FOOTPRINT, attr ); // set datasheet column viewer button diff --git a/eeschema/fields_grid_table.cpp b/eeschema/fields_grid_table.cpp index 2ec01f028b..d53f0a05ff 100644 --- a/eeschema/fields_grid_table.cpp +++ b/eeschema/fields_grid_table.cpp @@ -75,7 +75,7 @@ FIELDS_GRID_TABLE::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* a m_valueAttr->SetEditor( valueEditor ); m_footprintAttr = new wxGridCellAttr; - m_footprintAttr->SetEditor( new GRID_CELL_FOOTPRINT_EDITOR( aDialog ) ); + m_footprintAttr->SetEditor( new GRID_CELL_FOOTPRINT_ID_EDITOR( aDialog ) ); m_urlAttr = new wxGridCellAttr; m_urlAttr->SetEditor( new GRID_CELL_URL_EDITOR( aDialog ) ); diff --git a/include/widgets/grid_text_button_helpers.h b/include/widgets/grid_text_button_helpers.h index 54e83e7fa1..db942d3f92 100644 --- a/include/widgets/grid_text_button_helpers.h +++ b/include/widgets/grid_text_button_helpers.h @@ -57,16 +57,35 @@ protected: }; -class GRID_CELL_FOOTPRINT_EDITOR : public GRID_CELL_TEXT_BUTTON +class GRID_CELL_SYMBOL_ID_EDITOR : public GRID_CELL_TEXT_BUTTON { public: - GRID_CELL_FOOTPRINT_EDITOR( DIALOG_SHIM* aParent ) : + GRID_CELL_SYMBOL_ID_EDITOR( DIALOG_SHIM* aParent ) : m_dlg( aParent ) { } wxGridCellEditor* Clone() const override { - return new GRID_CELL_FOOTPRINT_EDITOR( m_dlg ); + return new GRID_CELL_SYMBOL_ID_EDITOR( m_dlg ); + } + + void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override; + +protected: + DIALOG_SHIM* m_dlg; +}; + + +class GRID_CELL_FOOTPRINT_ID_EDITOR : public GRID_CELL_TEXT_BUTTON +{ +public: + GRID_CELL_FOOTPRINT_ID_EDITOR( DIALOG_SHIM* aParent ) : + m_dlg( aParent ) + { } + + wxGridCellEditor* Clone() const override + { + return new GRID_CELL_FOOTPRINT_ID_EDITOR( m_dlg ); } void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;