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

(cherry picked from commit 16acba34d3)
This commit is contained in:
Jeff Young 2022-04-11 22:14:54 +01:00
parent c8cd214cb0
commit 03bc9551c7
2 changed files with 49 additions and 18 deletions

View File

@ -814,7 +814,9 @@ SYMBOL_LIBRARY_MANAGER& SYMBOL_EDIT_FRAME::GetLibManager()
void SYMBOL_EDIT_FRAME::OnModify() void SYMBOL_EDIT_FRAME::OnModify()
{ {
GetScreen()->SetContentModified(); GetScreen()->SetContentModified();
storeCurrentSymbol();
if( !IsSymbolFromSchematic() )
storeCurrentSymbol();
m_treePane->GetLibTree()->RefreshLibTree(); m_treePane->GetLibTree()->RefreshLibTree();

View File

@ -234,14 +234,33 @@ bool SYMBOL_EDIT_FRAME::saveCurrentSymbol()
{ {
if( GetCurSymbol() ) if( GetCurSymbol() )
{ {
LIB_ID libId = GetCurSymbol()->GetLibId(); if( IsSymbolFromSchematic() )
const wxString& libName = libId.GetLibNickname();
const wxString& symbolName = libId.GetLibItemName();
if( m_libMgr->FlushSymbol( symbolName, libName ) )
{ {
m_libMgr->ClearSymbolModified( symbolName, libName ); SCH_EDIT_FRAME* schframe = (SCH_EDIT_FRAME*) Kiway().Player( FRAME_SCH, false );
return true;
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 ) bool SYMBOL_EDIT_FRAME::LoadSymbol( const LIB_ID& aLibId, int aUnit, int aConvert )
{ {
if( !IsSymbolFromSchematic() if( GetCurSymbol() && !IsSymbolFromSchematic()
&& GetCurSymbol() && GetCurSymbol()->GetLibId() == aLibId && GetCurSymbol()->GetLibId() == aLibId
&& GetUnit() == aUnit && GetConvert() == aConvert ) && GetUnit() == aUnit
&& GetConvert() == aConvert )
{ {
return true; return true;
} }
if( GetScreen()->IsContentModified() && GetCurSymbol() ) if( GetCurSymbol() && IsSymbolFromSchematic() && GetScreen()->IsContentModified() )
{ {
if( !HandleUnsavedChanges( this, _( "The current symbol has been modified. Save changes?" ), if( !HandleUnsavedChanges( this, _( "The current symbol has been modified. Save changes?" ),
[&]() -> bool [&]() -> bool
@ -986,16 +1006,25 @@ void SYMBOL_EDIT_FRAME::RevertAll()
void SYMBOL_EDIT_FRAME::LoadSymbol( const wxString& aAlias, const wxString& aLibrary, int aUnit ) 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 ); LIB_SYMBOL* symbol = m_libMgr->GetBufferedSymbol( aAlias, aLibrary );
if( !symbol ) if( !symbol )
{ {
wxString msg; DisplayError( this, wxString::Format( _( "Symbol %s not found in library '%s'." ),
aAlias,
msg.Printf( _( "Symbol %s not found in library '%s'." ), aLibrary ) );
aAlias,
aLibrary );
DisplayError( this, msg );
return; return;
} }