From 16acba34d3f8988ef2a6beed5234c35e6ca94d40 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 11 Apr 2022 22:14:54 +0100 Subject: [PATCH] Don't save schematic symbol back to lib manager. Also, since it doesn't get saved, changing symbols will lose any edits. Make sure to ask the user first. Fixes https://gitlab.com/kicad/code/kicad/issues/10767 --- eeschema/symbol_editor/symbol_edit_frame.cpp | 4 +- eeschema/symbol_editor/symbol_editor.cpp | 63 ++++++++++++++------ 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index 0db87fdd12..ad2415a7f4 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -811,7 +811,9 @@ SYMBOL_LIBRARY_MANAGER& SYMBOL_EDIT_FRAME::GetLibManager() void SYMBOL_EDIT_FRAME::OnModify() { GetScreen()->SetContentModified(); - storeCurrentSymbol(); + + if( !IsSymbolFromSchematic() ) + storeCurrentSymbol(); m_treePane->GetLibTree()->RefreshLibTree(); diff --git a/eeschema/symbol_editor/symbol_editor.cpp b/eeschema/symbol_editor/symbol_editor.cpp index 15749a9a33..9b64fba9ff 100644 --- a/eeschema/symbol_editor/symbol_editor.cpp +++ b/eeschema/symbol_editor/symbol_editor.cpp @@ -234,14 +234,33 @@ bool SYMBOL_EDIT_FRAME::saveCurrentSymbol() { if( GetCurSymbol() ) { - LIB_ID libId = GetCurSymbol()->GetLibId(); - const wxString& libName = libId.GetLibNickname(); - const wxString& symbolName = libId.GetLibItemName(); - - if( m_libMgr->FlushSymbol( symbolName, libName ) ) + if( IsSymbolFromSchematic() ) { - m_libMgr->ClearSymbolModified( symbolName, libName ); - return true; + SCH_EDIT_FRAME* schframe = (SCH_EDIT_FRAME*) Kiway().Player( FRAME_SCH, false ); + + if( !schframe ) // happens when the schematic editor has been closed + { + DisplayErrorMessage( this, _( "No schematic currently open." ) ); + return false; + } + else + { + schframe->SaveSymbolToSchematic( *m_symbol, m_schematicSymbolUUID ); + GetScreen()->SetContentModified( false ); + return true; + } + } + else + { + LIB_ID libId = GetCurSymbol()->GetLibId(); + const wxString& libName = libId.GetLibNickname(); + const wxString& symbolName = libId.GetLibItemName(); + + if( m_libMgr->FlushSymbol( symbolName, libName ) ) + { + m_libMgr->ClearSymbolModified( symbolName, libName ); + return true; + } } } @@ -251,14 +270,15 @@ bool SYMBOL_EDIT_FRAME::saveCurrentSymbol() bool SYMBOL_EDIT_FRAME::LoadSymbol( const LIB_ID& aLibId, int aUnit, int aConvert ) { - if( !IsSymbolFromSchematic() - && GetCurSymbol() && GetCurSymbol()->GetLibId() == aLibId - && GetUnit() == aUnit && GetConvert() == aConvert ) + if( GetCurSymbol() && !IsSymbolFromSchematic() + && GetCurSymbol()->GetLibId() == aLibId + && GetUnit() == aUnit + && GetConvert() == aConvert ) { return true; } - if( GetScreen()->IsContentModified() && GetCurSymbol() ) + if( GetCurSymbol() && IsSymbolFromSchematic() && GetScreen()->IsContentModified() ) { if( !HandleUnsavedChanges( this, _( "The current symbol has been modified. Save changes?" ), [&]() -> bool @@ -986,16 +1006,25 @@ void SYMBOL_EDIT_FRAME::RevertAll() void SYMBOL_EDIT_FRAME::LoadSymbol( const wxString& aAlias, const wxString& aLibrary, int aUnit ) { + if( GetCurSymbol() && IsSymbolFromSchematic() && GetScreen()->IsContentModified() ) + { + if( !HandleUnsavedChanges( this, _( "The current symbol has been modified. Save changes?" ), + [&]() -> bool + { + return saveCurrentSymbol(); + } ) ) + { + return; + } + } + LIB_SYMBOL* symbol = m_libMgr->GetBufferedSymbol( aAlias, aLibrary ); if( !symbol ) { - wxString msg; - - msg.Printf( _( "Symbol %s not found in library '%s'." ), - aAlias, - aLibrary ); - DisplayError( this, msg ); + DisplayError( this, wxString::Format( _( "Symbol %s not found in library '%s'." ), + aAlias, + aLibrary ) ); return; }