diff --git a/eeschema/eeschema_id.h b/eeschema/eeschema_id.h index 07bdc73f20..422255963c 100644 --- a/eeschema/eeschema_id.h +++ b/eeschema/eeschema_id.h @@ -219,6 +219,9 @@ enum id_eeschema_frm ID_LIBEDIT_IMPORT_PART, ID_LIBEDIT_EXPORT_PART, ID_LIBEDIT_REMOVE_PART, + ID_LIBEDIT_CUT_PART, + ID_LIBEDIT_COPY_PART, + ID_LIBEDIT_PASTE_PART, ID_LIBEDIT_DUPLICATE_PART, /* Library editor horizontal toolbar IDs. */ diff --git a/eeschema/lib_edit_frame.cpp b/eeschema/lib_edit_frame.cpp index d53a8c27b7..d89e41e703 100644 --- a/eeschema/lib_edit_frame.cpp +++ b/eeschema/lib_edit_frame.cpp @@ -103,7 +103,10 @@ BEGIN_EVENT_TABLE( LIB_EDIT_FRAME, EDA_DRAW_FRAME ) EVT_TOOL( ID_LIBEDIT_IMPORT_PART, LIB_EDIT_FRAME::OnImportPart ) EVT_TOOL( ID_LIBEDIT_EXPORT_PART, LIB_EDIT_FRAME::OnExportPart ) EVT_TOOL( ID_LIBEDIT_REMOVE_PART, LIB_EDIT_FRAME::OnRemovePart ) - EVT_TOOL( ID_LIBEDIT_DUPLICATE_PART, LIB_EDIT_FRAME::OnDuplicatePart ) + EVT_TOOL( ID_LIBEDIT_CUT_PART, LIB_EDIT_FRAME::OnCopyCutPart ) + EVT_TOOL( ID_LIBEDIT_COPY_PART, LIB_EDIT_FRAME::OnCopyCutPart ) + EVT_TOOL( ID_LIBEDIT_PASTE_PART, LIB_EDIT_FRAME::OnPasteDuplicatePart ) + EVT_TOOL( ID_LIBEDIT_DUPLICATE_PART, LIB_EDIT_FRAME::OnPasteDuplicatePart ) // Main horizontal toolbar. EVT_TOOL( ID_TO_LIBVIEW, LIB_EDIT_FRAME::OnOpenLibraryViewer ) diff --git a/eeschema/lib_edit_frame.h b/eeschema/lib_edit_frame.h index 6d93935a3b..0caedeb393 100644 --- a/eeschema/lib_edit_frame.h +++ b/eeschema/lib_edit_frame.h @@ -62,6 +62,9 @@ class LIB_EDIT_FRAME : public SCH_BASE_FRAME SYMBOL_TREE_PANE* m_treePane; ///< component search tree widget LIB_MANAGER* m_libMgr; ///< manager taking care of temporary modificatoins + // Copy/cut/paste buffer to move parts between libraries + std::unique_ptr m_copiedPart; + /** Convert of the item currently being drawn. */ bool m_drawSpecificConvert; @@ -293,6 +296,8 @@ public: void OnRemovePart( wxCommandEvent& aEvent ); void OnDuplicatePart( wxCommandEvent& aEvent ); + void OnCopyCutPart( wxCommandEvent& aEvent ); + void OnPasteDuplicatePart( wxCommandEvent& aEvent ); void OnSelectPart( wxCommandEvent& event ); diff --git a/eeschema/libedit.cpp b/eeschema/libedit.cpp index ccc67dc946..7cbbe89ddc 100644 --- a/eeschema/libedit.cpp +++ b/eeschema/libedit.cpp @@ -490,16 +490,39 @@ void LIB_EDIT_FRAME::OnRemovePart( wxCommandEvent& aEvent ) } -void LIB_EDIT_FRAME::OnDuplicatePart( wxCommandEvent& aEvent ) +void LIB_EDIT_FRAME::OnCopyCutPart( wxCommandEvent& aEvent ) { - int unit = 0; - LIB_ID libId = m_treePane->GetLibTree()->GetSelectedLibId( &unit ); + int dummyUnit; + LIB_ID libId = m_treePane->GetLibTree()->GetSelectedLibId( &dummyUnit ); + LIB_PART* part = m_libMgr->GetBufferedPart( libId.GetLibItemName(), libId.GetLibNickname() ); + + if( !part ) + return; + + m_copiedPart.reset( new LIB_PART( *part ) ); + + if( aEvent.GetId() == ID_LIBEDIT_CUT_PART ) + OnRemovePart( aEvent ); +} + + +void LIB_EDIT_FRAME::OnPasteDuplicatePart( wxCommandEvent& aEvent ) +{ + int dummyUnit; + LIB_ID libId = m_treePane->GetLibTree()->GetSelectedLibId( &dummyUnit ); wxString lib = libId.GetLibNickname(); if( !m_libMgr->LibraryExists( lib ) ) return; - LIB_PART* srcPart = m_libMgr->GetBufferedPart( libId.GetLibItemName(), lib ); + LIB_PART* srcPart = nullptr; + + if( aEvent.GetId() == ID_LIBEDIT_DUPLICATE_PART ) + srcPart = m_libMgr->GetBufferedPart( libId.GetLibItemName(), lib ); + else if( aEvent.GetId() == ID_LIBEDIT_PASTE_PART ) + srcPart = m_copiedPart.get(); + else + wxFAIL; if( !srcPart ) return; diff --git a/eeschema/widgets/symbol_tree_pane.cpp b/eeschema/widgets/symbol_tree_pane.cpp index 560b9507f1..45c267d16e 100644 --- a/eeschema/widgets/symbol_tree_pane.cpp +++ b/eeschema/widgets/symbol_tree_pane.cpp @@ -65,6 +65,8 @@ SYMBOL_TREE_PANE::SYMBOL_TREE_PANE( LIB_EDIT_FRAME* aParent, LIB_MANAGER* aLibMg KiBitmap( new_component_xpm ) ); AddMenuItem( menuLibrary.get(), ID_LIBEDIT_IMPORT_PART, _( "&Import Symbol..." ), KiBitmap( import_part_xpm ) ); + AddMenuItem( menuLibrary.get(), ID_LIBEDIT_PASTE_PART, _( "Paste Symbol" ), + KiBitmap( paste_xpm ) ); std::unique_ptr menuPart = std::make_unique(); AddMenuItem( menuPart.get(), ID_LIBEDIT_EDIT_PART, _( "&Edit Symbol" ), @@ -82,6 +84,12 @@ SYMBOL_TREE_PANE::SYMBOL_TREE_PANE( LIB_EDIT_FRAME* aParent, LIB_MANAGER* aLibMg AddMenuItem( menuPart.get(), ID_LIBEDIT_REVERT, _( "Revert" ), KiBitmap( undo_xpm ) ); + menuPart->AppendSeparator(); + AddMenuItem( menuPart.get(), ID_LIBEDIT_CUT_PART, _( "Cut" ), + KiBitmap( cut_xpm ) ); + AddMenuItem( menuPart.get(), ID_LIBEDIT_COPY_PART, _( "Copy" ), + KiBitmap( copy_xpm ) ); + menuPart->AppendSeparator(); AddMenuItem( menuPart.get(), ID_LIBEDIT_EXPORT_PART, _( "E&xport Symbol..." ), KiBitmap( export_part_xpm ) );