diff --git a/eeschema/libeditframe.cpp b/eeschema/libeditframe.cpp index 2beadba1f1..47f13d0a79 100644 --- a/eeschema/libeditframe.cpp +++ b/eeschema/libeditframe.cpp @@ -341,9 +341,14 @@ void LIB_EDIT_FRAME::SetDrawItem( LIB_ITEM* drawItem ) void LIB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event ) { if( saveAllLibraries() ) + { + saveSymbolLibTables( true, true ); Destroy(); + } else + { Event.Veto(); + } } diff --git a/eeschema/sch_base_frame.cpp b/eeschema/sch_base_frame.cpp index 11554d7231..028731b20a 100644 --- a/eeschema/sch_base_frame.cpp +++ b/eeschema/sch_base_frame.cpp @@ -268,37 +268,7 @@ void SCH_BASE_FRAME::OnEditSymbolLibTable( wxCommandEvent& aEvent ) if( dlg.ShowModal() == wxID_CANCEL ) return; - try - { - FILE_OUTPUTFORMATTER sf( SYMBOL_LIB_TABLE::GetGlobalTableFileName() ); - - SYMBOL_LIB_TABLE::GetGlobalLibTable().Format( &sf, 0 ); - } - catch( const IO_ERROR& ioe ) - { - wxString msg = wxString::Format( _( "Error occurred saving the global symbol library " - "table:\n\n%s" ), - GetChars( ioe.What().GetData() ) ); - wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR ); - } - - if( !Prj().GetProjectName().IsEmpty() ) - { - wxFileName fn( Prj().GetProjectPath(), SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() ); - - try - { - Prj().SchSymbolLibTable()->Save( fn.GetFullPath() ); - } - catch( const IO_ERROR& ioe ) - { - wxString msg = wxString::Format( _( "Error occurred saving project specific " - "symbol library table:\n\n%s" ), - GetChars( ioe.What() ) ); - wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR ); - } - } - + saveSymbolLibTables( true, true ); LIB_EDIT_FRAME* editor = (LIB_EDIT_FRAME*) Kiway().Player( FRAME_SCH_LIB_EDITOR, false ); @@ -335,3 +305,47 @@ LIB_PART* SCH_BASE_FRAME::GetLibPart( const LIB_ID& aLibId, bool aUseCacheLib, b return SchGetLibPart( aLibId, Prj().SchSymbolLibTable(), cache, this, aShowErrorMsg ); } + + +bool SCH_BASE_FRAME::saveSymbolLibTables( bool aGlobal, bool aProject ) +{ + bool success = true; + + if( aGlobal ) + { + try + { + FILE_OUTPUTFORMATTER sf( SYMBOL_LIB_TABLE::GetGlobalTableFileName() ); + + SYMBOL_LIB_TABLE::GetGlobalLibTable().Format( &sf, 0 ); + } + catch( const IO_ERROR& ioe ) + { + success = false; + wxString msg = wxString::Format( _( "Error occurred saving the global symbol library " + "table:\n\n%s" ), + GetChars( ioe.What().GetData() ) ); + wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR ); + } + } + + if( aProject && !Prj().GetProjectName().IsEmpty() ) + { + wxFileName fn( Prj().GetProjectPath(), SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() ); + + try + { + Prj().SchSymbolLibTable()->Save( fn.GetFullPath() ); + } + catch( const IO_ERROR& ioe ) + { + success = false; + wxString msg = wxString::Format( _( "Error occurred saving project specific " + "symbol library table:\n\n%s" ), + GetChars( ioe.What() ) ); + wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR ); + } + } + + return success; +} diff --git a/eeschema/sch_base_frame.h b/eeschema/sch_base_frame.h index 121f0c62e1..030de47feb 100644 --- a/eeschema/sch_base_frame.h +++ b/eeschema/sch_base_frame.h @@ -281,6 +281,15 @@ protected: * false on cancel */ bool SelectPartNameToLoad( wxString& aLibrary, wxString& aBufName ); + + /** + * Saves Symbol Library Tables to disk. + * + * @param aGlobal when true, the Global Table is saved. + * @param aProject when true, the Project Table is saved. + * @return True when all requested actions succeeded. + */ + bool saveSymbolLibTables( bool aGlobal, bool aProject ); }; #endif // SCH_BASE_FRAME_H_