From 8cba785375094d0181b09a6d00a41d3ce7f38fe3 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 27 Oct 2023 14:57:20 +0100 Subject: [PATCH] Single warning for all locked sheets when saving schematic. Also checks for modified before trying to save at all. Fixes https://gitlab.com/kicad/code/kicad/-/issues/15946 Fixes https://gitlab.com/kicad/code/kicad/-/issues/15963 --- eeschema/files-io.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 6e404ff530..4fb5404c3b 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -1009,6 +1009,10 @@ bool SCH_EDIT_FRAME::SaveProject( bool aSaveAs ) // File doesn't exist yet; true if we just imported something updateFileHistory = true; } + else if( !Schematic().GetSheets().IsModified() ) + { + return true; + } if( filenameMap.empty() || !saveCopy ) { @@ -1018,6 +1022,7 @@ bool SCH_EDIT_FRAME::SaveProject( bool aSaveAs ) // Warn user on potential file overwrite. This can happen on shared sheets. wxArrayString overwrittenFiles; + wxArrayString lockedFiles; for( size_t i = 0; i < screens.GetCount(); i++ ) { @@ -1031,6 +1036,9 @@ bool SCH_EDIT_FRAME::SaveProject( bool aSaveAs ) if( !tmpFn.IsOk() ) continue; + if( tmpFn.FileExists() && !tmpFn.IsFileWritable() ) + lockedFiles.Add( tmpFn.GetFullPath() ); + if( tmpFn.GetExt() == KiCadSchematicFileExtension ) continue; @@ -1040,6 +1048,26 @@ bool SCH_EDIT_FRAME::SaveProject( bool aSaveAs ) overwrittenFiles.Add( tmpFn.GetFullPath() ); } + if( !lockedFiles.IsEmpty() ) + { + for( const wxString& lockedFile : lockedFiles ) + { + if( msg.IsEmpty() ) + msg = lockedFile; + else + msg += "\n" + lockedFile; + } + + wxRichMessageDialog dlg( this, wxString::Format( _( "Failed to save %s." ), + Schematic().Root().GetFileName() ), + _( "Locked File Warning" ), + wxOK | wxICON_WARNING | wxCENTER ); + dlg.SetExtendedMessage( _( "You do not have write permissions to:\n\n" ) + msg ); + + dlg.ShowModal(); + return false; + } + if( !overwrittenFiles.IsEmpty() ) { for( const wxString& overwrittenFile : overwrittenFiles )