From 86f71a9eb4cb7197cf0eb7db6cecd8f895aa437a Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 14 Nov 2017 14:19:11 +0100 Subject: [PATCH] Library Editor: notify is library is read-only --- eeschema/lib_manager.cpp | 2 +- eeschema/libedit.cpp | 2 +- eeschema/libeditframe.cpp | 22 +++++++++++++++++----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/eeschema/lib_manager.cpp b/eeschema/lib_manager.cpp index 0df9ef3b2f..2297e4783d 100644 --- a/eeschema/lib_manager.cpp +++ b/eeschema/lib_manager.cpp @@ -240,7 +240,7 @@ bool LIB_MANAGER::IsLibraryReadOnly( const wxString& aLibrary ) const { wxCHECK( LibraryExists( aLibrary ), true ); wxFileName fn( m_symbolTable->GetFullURI( aLibrary ) ); - return !fn.IsFileWritable(); + return ( fn.FileExists() && !fn.IsFileWritable() ) || !fn.IsDirWritable(); } diff --git a/eeschema/libedit.cpp b/eeschema/libedit.cpp index 605061207d..3eb4906012 100644 --- a/eeschema/libedit.cpp +++ b/eeschema/libedit.cpp @@ -67,7 +67,7 @@ void LIB_EDIT_FRAME::DisplayLibInfos() title += lib + " (" + fileName + ")"; - if( !wxFileName::IsFileWritable( fileName ) ) + if( wxFileName::FileExists( fileName ) && !wxFileName::IsFileWritable( fileName ) ) title += " " + _( "[Read Only]" ); } else diff --git a/eeschema/libeditframe.cpp b/eeschema/libeditframe.cpp index c9e2521dda..7e27a60c58 100644 --- a/eeschema/libeditframe.cpp +++ b/eeschema/libeditframe.cpp @@ -519,9 +519,20 @@ void LIB_EDIT_FRAME::OnUpdatePartModified( wxUpdateUIEvent& aEvent ) const wxString& partName = libId.GetLibItemName(); const wxString& libName = libId.GetLibNickname(); - aEvent.Enable( !partName.IsEmpty() && !libName.IsEmpty() - && m_libMgr->IsPartModified( partName, libName ) - && ( aEvent.GetId() == ID_LIBEDIT_REVERT_PART || !m_libMgr->IsLibraryReadOnly( libName ) ) ); + if( aEvent.GetId() == ID_LIBEDIT_SAVE_PART ) + { + bool readOnly = libName.IsEmpty() || m_libMgr->IsLibraryReadOnly( libName ); + + aEvent.SetText( readOnly ? _( "Save part [Read Only]" ) : _( "Save part" ) ); + aEvent.Enable( !readOnly && !partName.IsEmpty() + && m_libMgr->IsPartModified( partName, libName ) ); + } + else if( aEvent.GetId() == ID_LIBEDIT_REVERT_PART ) + { + aEvent.Enable( !partName.IsEmpty() && !libName.IsEmpty() + && m_libMgr->IsPartModified( partName, libName ) ); + } + else wxFAIL; } @@ -554,9 +565,10 @@ void LIB_EDIT_FRAME::OnUpdateRedo( wxUpdateUIEvent& event ) void LIB_EDIT_FRAME::OnUpdateSaveLib( wxUpdateUIEvent& event ) { wxString lib = getTargetLib(); + bool readOnly = lib.IsEmpty() || m_libMgr->IsLibraryReadOnly( lib ); - event.Enable( m_libMgr->LibraryExists( lib ) && !m_libMgr->IsLibraryReadOnly( lib ) && - m_libMgr->IsLibraryModified( lib ) ); + event.SetText( readOnly ? _( "Save library [Read Only]" ) : _( "Save library" ) ); + event.Enable( !readOnly && m_libMgr->IsLibraryModified( lib ) ); }