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.
This commit is contained in:
Wayne Stambaugh 2020-05-16 17:25:13 -04:00
parent b624c7090a
commit 6c8b937e1b
5 changed files with 29 additions and 9 deletions

View File

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

View File

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

View File

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

View File

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

View File

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