diff --git a/eeschema/lib_manager.cpp b/eeschema/lib_manager.cpp index ffbf51d981..0df9ef3b2f 100644 --- a/eeschema/lib_manager.cpp +++ b/eeschema/lib_manager.cpp @@ -202,6 +202,40 @@ bool LIB_MANAGER::IsPartModified( const wxString& aAlias, const wxString& aLibra } +bool LIB_MANAGER::ClearLibraryModified( const wxString& aLibrary ) const +{ + auto libIt = m_libs.find( aLibrary ); + + if( libIt == m_libs.end() ) + return false; + + for( auto& partBuf : libIt->second.GetBuffers() ) + { + SCH_SCREEN* screen = partBuf->GetScreen(); + + if( screen ) + screen->ClrModify(); + } + + return true; +} + + +bool LIB_MANAGER::ClearPartModified( const wxString& aAlias, const wxString& aLibrary ) const +{ + auto libI = m_libs.find( aLibrary ); + + if( libI == m_libs.end() ) + return false; + + auto partBuf = libI->second.GetBuffer( aAlias ); + wxCHECK( partBuf, false ); + + partBuf->GetScreen()->ClrModify(); + return true; +} + + bool LIB_MANAGER::IsLibraryReadOnly( const wxString& aLibrary ) const { wxCHECK( LibraryExists( aLibrary ), true ); @@ -348,8 +382,6 @@ bool LIB_MANAGER::RevertPart( const wxString& aAlias, const wxString& aLibrary ) auto partBuf = it->second.GetBuffer( aAlias ); wxCHECK( partBuf, false ); - - partBuf->GetScreen()->ClrModify(); partBuf->SetPart( new LIB_PART( *partBuf->GetOriginal() ) ); return true; @@ -648,9 +680,8 @@ bool LIB_MANAGER::LIB_BUFFER::SaveBuffer( LIB_MANAGER::PART_BUFFER::PTR aPartBuf wxCHECK( aPartBuf, false ); LIB_PART* part = aPartBuf->GetPart(); wxCHECK( part, false ); - wxCHECK( aLibTable->SaveSymbol( m_libName, new LIB_PART( *part ) ) != SYMBOL_LIB_TABLE::SAVE_OK, false ); + wxCHECK( aLibTable->SaveSymbol( m_libName, new LIB_PART( *part ) ) == SYMBOL_LIB_TABLE::SAVE_OK, false ); - aPartBuf->GetScreen()->ClrModify(); aPartBuf->SetOriginal( new LIB_PART( *part ) ); ++m_hash; return true; @@ -670,7 +701,6 @@ bool LIB_MANAGER::LIB_BUFFER::SaveBuffer( LIB_MANAGER::PART_BUFFER::PTR aPartBuf // TODO there is no way to check if symbol has been successfully saved aPlugin->SaveSymbol( m_libName, new LIB_PART( *part ), aBuffer ? &properties : nullptr ); - aPartBuf->GetScreen()->ClrModify(); aPartBuf->SetOriginal( new LIB_PART( *part ) ); ++m_hash; return true; diff --git a/eeschema/lib_manager.h b/eeschema/lib_manager.h index 55b63c514e..31cddd85e0 100644 --- a/eeschema/lib_manager.h +++ b/eeschema/lib_manager.h @@ -144,6 +144,16 @@ public: */ bool IsPartModified( const wxString& aAlias, const wxString& aLibrary ) const; + /** + * Clears the modified flag for all parts in a library. + */ + bool ClearLibraryModified( const wxString& aLibrary ) const; + + /** + * Clears the modified flag for a part. + */ + bool ClearPartModified( const wxString& aAlias, const wxString& aLibrary ) const; + /** * Returns true if the library is stored in a read-only file. * @return True on success, false otherwise. diff --git a/eeschema/libedit.cpp b/eeschema/libedit.cpp index d0e3afd94d..b5e1ac6f47 100644 --- a/eeschema/libedit.cpp +++ b/eeschema/libedit.cpp @@ -352,8 +352,11 @@ void LIB_EDIT_FRAME::OnEditPart( wxCommandEvent& aEvent ) void LIB_EDIT_FRAME::OnSavePart( wxCommandEvent& aEvent ) { LIB_ID libId = getTargetLibId(); - m_libMgr->FlushPart( libId.GetLibItemName(), libId.GetLibNickname() ); - m_treePane->Refresh();; + + if( m_libMgr->FlushPart( libId.GetLibItemName(), libId.GetLibNickname() ) ) + m_libMgr->ClearPartModified( libId.GetLibItemName(), libId.GetLibNickname() ); + + m_treePane->Refresh(); } @@ -459,7 +462,8 @@ void LIB_EDIT_FRAME::OnRevertPart( wxCommandEvent& aEvent ) if( currentPart ) emptyScreen(); - m_libMgr->RevertPart( libId.GetLibItemName(), libId.GetLibNickname() ); + if( m_libMgr->RevertPart( libId.GetLibItemName(), libId.GetLibNickname() ) ) + m_libMgr->ClearPartModified( libId.GetLibItemName(), libId.GetLibNickname() ); if( currentPart && m_libMgr->PartExists( libId.GetLibItemName(), libId.GetLibNickname() ) ) loadPart( libId.GetLibItemName(), libId.GetLibNickname(), unit ); @@ -559,6 +563,9 @@ bool LIB_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile ) return false; } + if( !aNewFile ) + m_libMgr->ClearLibraryModified( aLibrary ); + msg.Printf( _( "Symbol library file '%s' saved" ), fn.GetFullPath() ); wxString msg1; msg1.Printf( _( "Symbol library documentation file '%s' saved" ), docFileName.GetFullPath() );