Library Editor: save libraries added in the editor to sym-lib-tables

This commit is contained in:
Maciej Suminski 2017-11-13 11:53:19 +01:00
parent 26304c54ed
commit dfcd42f5ef
3 changed files with 59 additions and 31 deletions

View File

@ -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();
}
}

View File

@ -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;
}

View File

@ -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_