From 7ecc70a79d5ed62b8dfb85953b531c3c6c3ed7f1 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Thu, 3 Mar 2022 15:19:24 -0800 Subject: [PATCH] Duplicate from selected or current When double-clicking to open a symbol, it is no longer selected in the tree. We need to use the `GetTargetLibId()` to pick the correct symbol (first selected, then current) when using the duplicate command Fixes https://gitlab.com/kicad/code/kicad/issues/11034 (cherry picked from commit 802d20c4097c190ed6364e5dc697ffbb10ac90c2) --- eeschema/symbol_editor/symbol_editor.cpp | 3 +-- eeschema/tools/symbol_editor_control.cpp | 13 ++++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/eeschema/symbol_editor/symbol_editor.cpp b/eeschema/symbol_editor/symbol_editor.cpp index 0d99850f3c..e4302f438e 100644 --- a/eeschema/symbol_editor/symbol_editor.cpp +++ b/eeschema/symbol_editor/symbol_editor.cpp @@ -828,8 +828,7 @@ void SYMBOL_EDIT_FRAME::CopySymbolToClipboard() void SYMBOL_EDIT_FRAME::DuplicateSymbol( bool aFromClipboard ) { - int dummyUnit; - LIB_ID libId = m_treePane->GetLibTree()->GetSelectedLibId( &dummyUnit ); + LIB_ID libId = GetTargetLibId(); wxString lib = libId.GetLibNickname(); if( !m_libMgr->LibraryExists( lib ) ) diff --git a/eeschema/tools/symbol_editor_control.cpp b/eeschema/tools/symbol_editor_control.cpp index 389fe9908a..a29b48a00f 100644 --- a/eeschema/tools/symbol_editor_control.cpp +++ b/eeschema/tools/symbol_editor_control.cpp @@ -160,7 +160,7 @@ int SYMBOL_EDITOR_CONTROL::AddSymbol( const TOOL_EVENT& aEvent ) if( libName.IsEmpty() ) { - msg.Printf( _( "No symbol library selected." ), libName ); + msg.Printf( _( "No symbol library selected." ) ); m_frame->ShowInfoBarError( msg ); return 0; } @@ -255,10 +255,17 @@ int SYMBOL_EDITOR_CONTROL::DuplicateSymbol( const TOOL_EVENT& aEvent ) if( m_frame->IsType( FRAME_SCH_SYMBOL_EDITOR ) ) { SYMBOL_EDIT_FRAME* editFrame = static_cast( m_frame ); + LIB_ID sel = editFrame->GetTargetLibId(); + wxString msg; + + if( !sel.IsValid() ) + { + msg.Printf( _( "No symbol selected" ) ); + m_frame->ShowInfoBarError( msg ); + return 0; + } - LIB_ID sel = editFrame->GetTreeLIBID(); const wxString& libName = sel.GetLibNickname(); - wxString msg; if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) ) {