Symbol editor: improve save all behavior for read only libraries.

Instead of forcing the user to save modified read only libraries to a
different file name, an info bar is displayed warning the user that read
only libraries need to be saved as a different library.  All modified
non-read only libraries are saved as normal.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/4668
This commit is contained in:
Wayne Stambaugh 2020-10-22 07:48:28 -04:00
parent 06e9a21791
commit ed03ca7ad0
2 changed files with 13 additions and 6 deletions

View File

@ -67,7 +67,7 @@ bool LIB_MANAGER::HasModifications() const
{ {
for( const auto& lib : m_libs ) for( const auto& lib : m_libs )
{ {
if( lib.second.IsModified() ) if( lib.second.IsModified() && !IsLibraryReadOnly( lib.first ) )
return true; return true;
} }

View File

@ -25,7 +25,6 @@
#include <pgm_base.h> #include <pgm_base.h>
#include <confirm.h> #include <confirm.h>
//#include <gestfich.h>
#include <widgets/infobar.h> #include <widgets/infobar.h>
#include <tools/ee_actions.h> #include <tools/ee_actions.h>
#include <tools/lib_drawing_tools.h> #include <tools/lib_drawing_tools.h>
@ -900,6 +899,7 @@ bool LIB_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile )
bool LIB_EDIT_FRAME::saveAllLibraries( bool aRequireConfirmation ) bool LIB_EDIT_FRAME::saveAllLibraries( bool aRequireConfirmation )
{ {
wxString msg;
bool doSave = true; bool doSave = true;
int dirtyCount = 0; int dirtyCount = 0;
bool applyToAll = false; bool applyToAll = false;
@ -916,8 +916,7 @@ bool LIB_EDIT_FRAME::saveAllLibraries( bool aRequireConfirmation )
{ {
if( aRequireConfirmation && !applyToAll ) if( aRequireConfirmation && !applyToAll )
{ {
wxString msg = wxString::Format( _( "Save changes to \"%s\" before closing?" ), msg.Printf( _( "Save changes to \"%s\" before closing?" ), libNickname );
libNickname );
switch( UnsavedChangesDialog( this, msg, dirtyCount > 1 ? &applyToAll : nullptr ) ) switch( UnsavedChangesDialog( this, msg, dirtyCount > 1 ? &applyToAll : nullptr ) )
{ {
@ -932,8 +931,16 @@ bool LIB_EDIT_FRAME::saveAllLibraries( bool aRequireConfirmation )
{ {
// If saving under existing name fails then do a Save As..., and if that // If saving under existing name fails then do a Save As..., and if that
// fails then cancel close action. // fails then cancel close action.
if( !m_libMgr->IsLibraryReadOnly( libNickname ) if( m_libMgr->IsLibraryReadOnly( libNickname ) )
&& saveLibrary( libNickname, false ) ) {
m_infoBar->Dismiss();
msg.Printf( _( "Library \"%s\" is read only and must be saved as a "
"different library." ), libNickname );
m_infoBar->ShowMessageFor( msg, 3000, wxICON_EXCLAMATION );
continue;
}
if( saveLibrary( libNickname, false ) )
continue; continue;
if( !saveLibrary( libNickname, true ) ) if( !saveLibrary( libNickname, true ) )