From 6c8b937e1bcad7361fde148be8d3dbed8ae199c5 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Sat, 16 May 2020 17:25:13 -0400 Subject: [PATCH] Symbol editor: disable saving legacy symbol libraries. CHANGED: The symbol library save menu entry is now only enable when the currently selected library is modified. CHANGED: The symbol library save all menu entry and tool bar button are enabled when one or more of the symbol libraries have been modified. REMOVED: The ability to save symbol libraries in the legacy file format. --- eeschema/libedit/lib_edit_frame.cpp | 5 ++++- eeschema/libedit/lib_manager.cpp | 4 ++-- eeschema/libedit/libedit.cpp | 18 +++++++++++++++--- eeschema/libedit/menubar_libedit.cpp | 9 +++++++-- eeschema/libedit/toolbars_libedit.cpp | 2 +- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/eeschema/libedit/lib_edit_frame.cpp b/eeschema/libedit/lib_edit_frame.cpp index 2290e4d0b8..08fcfdb6a1 100644 --- a/eeschema/libedit/lib_edit_frame.cpp +++ b/eeschema/libedit/lib_edit_frame.cpp @@ -417,6 +417,8 @@ wxString LIB_EDIT_FRAME::SetCurLib( const wxString& aLibNickname ) m_libMgr->SetCurrentLib( aLibNickname ); + ReCreateMenuBar(); + return old; } @@ -909,7 +911,8 @@ bool LIB_EDIT_FRAME::IsContentModified() // Test if any library has been modified for( const auto& libNickname : m_libMgr->GetLibraryNames() ) { - if( m_libMgr->IsLibraryModified( libNickname ) ) + if( m_libMgr->IsLibraryModified( libNickname ) + && !m_libMgr->IsLibraryReadOnly( libNickname ) ) return true; } diff --git a/eeschema/libedit/lib_manager.cpp b/eeschema/libedit/lib_manager.cpp index a0d300a928..90d860733e 100644 --- a/eeschema/libedit/lib_manager.cpp +++ b/eeschema/libedit/lib_manager.cpp @@ -282,8 +282,8 @@ bool LIB_MANAGER::IsLibraryReadOnly( const wxString& aLibrary ) const if( row ) fileType = SCH_IO_MGR::EnumFromStr( row->GetType() ); - return ( fileType != SCH_IO_MGR::SCH_FILE_T::SCH_LEGACY ) && fn.FileExists() && - ( !fn.IsFileWritable() || !fn.IsDirWritable() ); + return ( fileType == SCH_IO_MGR::SCH_FILE_T::SCH_LEGACY ) || + ( fn.FileExists() && !fn.IsFileWritable() ) || !fn.IsDirWritable(); } diff --git a/eeschema/libedit/libedit.cpp b/eeschema/libedit/libedit.cpp index 23a3a6a4ad..c67702b0fb 100644 --- a/eeschema/libedit/libedit.cpp +++ b/eeschema/libedit/libedit.cpp @@ -55,6 +55,9 @@ void LIB_EDIT_FRAME::updateTitle() if( GetCurPart() ) title += wxT( " \u2014 " ) + GetCurPart()->GetLibId().Format(); + if( GetCurPart() && m_libMgr && m_libMgr->IsLibraryReadOnly( GetCurLib() ) ) + title += " [Read Only Library]"; + SetTitle( title ); } @@ -375,9 +378,14 @@ void LIB_EDIT_FRAME::Save() { saveLibrary( libName, false ); } + else if( !libName.IsEmpty() && m_libMgr->IsLibraryReadOnly( libName ) ) + { + // Force a "Save As..." if the modified library is read only. + saveLibrary( libName, true ); + } else { - // Save Part + // Save a single library. if( m_libMgr->FlushPart( partName, libName ) ) m_libMgr->ClearPartModified( partName, libName ); } @@ -838,7 +846,7 @@ bool LIB_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile ) ClearMsgPanel(); - // Copy .lib file to .bak. + // Copy .kicad_symb file to .bak. if( !backupFile( fn, "bak" ) ) return false; @@ -895,7 +903,11 @@ bool LIB_EDIT_FRAME::saveAllLibraries( bool aRequireConfirmation ) { // If saving under existing name fails then do a Save As..., and if that // fails then cancel close action. - if( !saveLibrary( libNickname, false ) && !saveLibrary( libNickname, true ) ) + if( !m_libMgr->IsLibraryReadOnly( libNickname ) + && !saveLibrary( libNickname, false ) ) + return false; + + if( !saveLibrary( libNickname, true ) ) return false; } } diff --git a/eeschema/libedit/menubar_libedit.cpp b/eeschema/libedit/menubar_libedit.cpp index 598488df9e..71a074afa3 100644 --- a/eeschema/libedit/menubar_libedit.cpp +++ b/eeschema/libedit/menubar_libedit.cpp @@ -45,7 +45,7 @@ void LIB_EDIT_FRAME::ReCreateMenuBar() LIB_ID libId = getTargetLibId(); const wxString& libName = libId.GetLibNickname(); const wxString& partName = libId.GetLibItemName(); - bool readOnly = libName.IsEmpty() || m_libMgr->IsLibraryReadOnly( libName ); + bool readOnly = libName.IsEmpty(); if( partName.IsEmpty() ) return ( !readOnly && m_libMgr->IsLibraryModified( libName ) ); @@ -53,6 +53,11 @@ void LIB_EDIT_FRAME::ReCreateMenuBar() return ( !readOnly && m_libMgr->IsPartModified( partName, libName ) ); }; + auto saveAllEnableCondition = [this] ( const SELECTION& sel ) + { + return m_libMgr->HasModifications(); + }; + //-- File menu ----------------------------------------------- // CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, selTool ); @@ -64,7 +69,7 @@ void LIB_EDIT_FRAME::ReCreateMenuBar() fileMenu->AddSeparator(); fileMenu->AddItem( ACTIONS::save, modifiedDocumentCondition ); fileMenu->AddItem( ACTIONS::saveCopyAs, EE_CONDITIONS::ShowAlways ); - fileMenu->AddItem( ACTIONS::saveAll, EE_CONDITIONS::ShowAlways ); + fileMenu->AddItem( ACTIONS::saveAll, saveAllEnableCondition ); fileMenu->AddItem( ACTIONS::revert, modifiedDocumentCondition ); fileMenu->AddSeparator(); diff --git a/eeschema/libedit/toolbars_libedit.cpp b/eeschema/libedit/toolbars_libedit.cpp index 59520a8ece..6b5a4420c8 100644 --- a/eeschema/libedit/toolbars_libedit.cpp +++ b/eeschema/libedit/toolbars_libedit.cpp @@ -157,7 +157,7 @@ void LIB_EDIT_FRAME::SyncToolbars() bool isEditable = m_my_part && m_my_part->IsRoot(); - m_mainToolBar->Toggle( ACTIONS::saveAll, IsContentModified() ); + m_mainToolBar->Toggle( ACTIONS::saveAll, m_libMgr->HasModifications() ); m_mainToolBar->Toggle( ACTIONS::undo, GetScreen() && GetScreen()->GetUndoCommandCount() > 0 ); m_mainToolBar->Toggle( ACTIONS::redo, GetScreen() && GetScreen()->GetRedoCommandCount() > 0 ); m_mainToolBar->Toggle( ACTIONS::zoomTool, IsCurrentTool( ACTIONS::zoomTool ) );