diff --git a/eeschema/dialogs/dialog_edit_components_libid.cpp b/eeschema/dialogs/dialog_edit_components_libid.cpp
index 454eac8d33..7630743bba 100644
--- a/eeschema/dialogs/dialog_edit_components_libid.cpp
+++ b/eeschema/dialogs/dialog_edit_components_libid.cpp
@@ -111,6 +111,12 @@ private:
/// Reverts all changes already made
void revertChanges();
+ /** run the lib browser and set the selected LIB_ID for row aRow
+ * @param aRow is the row to edit
+ * @return false if the command was aborted
+ */
+ bool setLibIdByBrowser( int aRow );
+
// Events handlers
// called on a right click or a left double click:
@@ -127,14 +133,23 @@ private:
event.Skip();
}
+ void onButtonBrowseLibraries( wxCommandEvent& event ) override;
+
// Undo all changes, and clear the list of new lib_ids
void onUndoChangesButton( wxCommandEvent& event ) override;
+ // UI event, to enable/disable buttons
void updateUIChangesButton( wxUpdateUIEvent& event ) override
{
m_buttonUndo->Enable( m_isModified );
}
+ void updateUIBrowseButton( wxUpdateUIEvent& event ) override
+ {
+ wxArrayInt rows = m_grid->GetSelectedRows();
+ m_buttonBrowseLibs->Enable( rows.GetCount() == 1 );
+ }
+
// Automatically called when click on OK button
bool TransferDataFromWindow() override;
};
@@ -282,6 +297,9 @@ void DIALOG_EDIT_COMPONENTS_LIBID::initDlg()
// ensure the column title is correctly displayed
m_grid->SetColMinimalWidth( COL_NEW_LIBID, m_grid->GetColSize( COL_NEW_LIBID ) );
m_grid->AutoSizeColLabelSize( COL_NEW_LIBID );
+
+ // Allows only the selection by row
+ m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
}
@@ -365,19 +383,51 @@ void DIALOG_EDIT_COMPONENTS_LIBID::onUndoChangesButton( wxCommandEvent& event )
void DIALOG_EDIT_COMPONENTS_LIBID::onCellBrowseLib( wxGridEvent& event )
{
int row = event.GetRow();
+ m_grid->SelectRow( row ); // only for user, to show the selected line
- SCH_BASE_FRAME::HISTORY_LIST dummy;
+ setLibIdByBrowser( row );
- auto sel = m_parent->SelectComponentFromLibrary( NULL, dummy, true, 0, 0 );
+}
- if( !sel.LibId.IsValid() )
+
+void DIALOG_EDIT_COMPONENTS_LIBID::onButtonBrowseLibraries( wxCommandEvent& event )
+{
+ wxArrayInt rows = m_grid->GetSelectedRows();
+
+ if( rows.GetCount() != 1 ) // Should not occur, because the button is disabled
return;
+ setLibIdByBrowser( rows[0] );
+}
+
+
+bool DIALOG_EDIT_COMPONENTS_LIBID::setLibIdByBrowser( int aRow )
+{
+#if 0
+ SCH_BASE_FRAME::HISTORY_LIST dummy;
+ SCH_BASE_FRAME::COMPONENT_SELECTION sel =
+ m_parent->SelectComponentFromLibrary( NULL, dummy, true, 0, 0 );
+#else
+ LIB_ID aPreselectedLibid;
+ SCH_BASE_FRAME::COMPONENT_SELECTION sel =
+ m_parent->SelectComponentFromLibBrowser( NULL, aPreselectedLibid, 0, 0 );
+#endif
+
+ if( sel.LibId.empty() ) // command aborted
+ return false;
+
+ if( !sel.LibId.IsValid() ) // Should not occur
+ {
+ wxMessageBox( _( "Invalid symbol library identifier" ) );
+ return false;
+ }
+
wxString new_libid;
new_libid = sel.LibId.Format();
- m_grid->SetCellValue( row, COL_NEW_LIBID, new_libid );
+ m_grid->SetCellValue( aRow, COL_NEW_LIBID, new_libid );
+ return true;
}
diff --git a/eeschema/dialogs/dialog_edit_components_libid_base.cpp b/eeschema/dialogs/dialog_edit_components_libid_base.cpp
index 147bb3ef37..78b8dde747 100644
--- a/eeschema/dialogs/dialog_edit_components_libid_base.cpp
+++ b/eeschema/dialogs/dialog_edit_components_libid_base.cpp
@@ -92,6 +92,9 @@ DIALOG_EDIT_COMPONENTS_LIBID_BASE::DIALOG_EDIT_COMPONENTS_LIBID_BASE( wxWindow*
m_buttonUndo = new wxButton( this, wxID_ANY, _("Undo Changes"), wxDefaultPosition, wxDefaultSize, 0 );
bSizerButtons->Add( m_buttonUndo, 0, wxTOP|wxBOTTOM|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5 );
+ m_buttonBrowseLibs = new wxButton( this, wxID_ANY, _("Browse Libraries"), wxDefaultPosition, wxDefaultSize, 0 );
+ bSizerButtons->Add( m_buttonBrowseLibs, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
+
bSizerMain->Add( bSizerButtons, 0, wxALIGN_RIGHT, 5 );
@@ -104,10 +107,14 @@ 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_GRID_LABEL_LEFT_DCLICK, wxGridEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCellBrowseLib ), NULL, this );
+ m_grid->Connect( wxEVT_GRID_LABEL_RIGHT_CLICK, wxGridEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCellBrowseLib ), NULL, this );
m_sdbSizerApply->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onApplyButton ), NULL, this );
m_sdbSizerCancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCancel ), 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 );
+ m_buttonBrowseLibs->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onButtonBrowseLibraries ), NULL, this );
+ m_buttonBrowseLibs->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::updateUIBrowseButton ), NULL, this );
}
DIALOG_EDIT_COMPONENTS_LIBID_BASE::~DIALOG_EDIT_COMPONENTS_LIBID_BASE()
@@ -115,9 +122,13 @@ 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_GRID_LABEL_LEFT_DCLICK, wxGridEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCellBrowseLib ), NULL, this );
+ m_grid->Disconnect( wxEVT_GRID_LABEL_RIGHT_CLICK, wxGridEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCellBrowseLib ), NULL, this );
m_sdbSizerApply->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onApplyButton ), NULL, this );
m_sdbSizerCancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCancel ), 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 );
+ m_buttonBrowseLibs->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onButtonBrowseLibraries ), NULL, this );
+ m_buttonBrowseLibs->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::updateUIBrowseButton ), NULL, this );
}
diff --git a/eeschema/dialogs/dialog_edit_components_libid_base.fbp b/eeschema/dialogs/dialog_edit_components_libid_base.fbp
index 43f27ffbb2..ac764c204a 100644
--- a/eeschema/dialogs/dialog_edit_components_libid_base.fbp
+++ b/eeschema/dialogs/dialog_edit_components_libid_base.fbp
@@ -291,8 +291,8 @@
-
-
+ onCellBrowseLib
+ onCellBrowseLib
@@ -620,6 +620,94 @@
updateUIChangesButton
+
diff --git a/eeschema/dialogs/dialog_edit_components_libid_base.h b/eeschema/dialogs/dialog_edit_components_libid_base.h
index 91549be06c..8485c666d8 100644
--- a/eeschema/dialogs/dialog_edit_components_libid_base.h
+++ b/eeschema/dialogs/dialog_edit_components_libid_base.h
@@ -47,6 +47,7 @@ class DIALOG_EDIT_COMPONENTS_LIBID_BASE : public DIALOG_SHIM
wxButton* m_sdbSizerApply;
wxButton* m_sdbSizerCancel;
wxButton* m_buttonUndo;
+ wxButton* m_buttonBrowseLibs;
// Virtual event handlers, overide them in your derived class
virtual void onCellBrowseLib( wxGridEvent& event ) { event.Skip(); }
@@ -54,6 +55,8 @@ class DIALOG_EDIT_COMPONENTS_LIBID_BASE : public DIALOG_SHIM
virtual void onCancel( wxCommandEvent& event ) { event.Skip(); }
virtual void onUndoChangesButton( wxCommandEvent& event ) { event.Skip(); }
virtual void updateUIChangesButton( wxUpdateUIEvent& event ) { event.Skip(); }
+ virtual void onButtonBrowseLibraries( wxCommandEvent& event ) { event.Skip(); }
+ virtual void updateUIBrowseButton( wxUpdateUIEvent& event ) { event.Skip(); }
public:
diff --git a/eeschema/sch_base_frame.h b/eeschema/sch_base_frame.h
index 030de47feb..231f4e1803 100644
--- a/eeschema/sch_base_frame.h
+++ b/eeschema/sch_base_frame.h
@@ -218,8 +218,6 @@ public:
LIB_PART* GetLibPart( const LIB_ID& aLibId, bool aUseCacheLib = false,
bool aShowErrorMsg = false );
-protected:
-
/**
* Function SelectComponentFromLibBrowser
* Calls the library viewer to select component to import into schematic.
@@ -237,6 +235,8 @@ protected:
const LIB_ID& aPreselectedLibid,
int aUnit, int aConvert );
+protected:
+
/**
* Open the library viewer only to browse library contents.
* If the viewed is already opened from this, raise the viewer