Don't hide (or disable) options if it's not obvious why.

It deprives us of the opportunity to inform the user what the conditions
are.
This commit is contained in:
Jeff Young 2021-03-14 21:50:20 +00:00
parent a9f86c6f3d
commit 7415bf0c62
2 changed files with 46 additions and 26 deletions

View File

@ -353,15 +353,6 @@ void SYMBOL_EDIT_FRAME::setupUIConditions()
return !GetTargetLibId().GetLibNickname().empty();
};
auto canEditLib =
[this] ( const SELECTION& sel )
{
const wxString libName = GetTargetLibId().GetLibNickname();
return !libName.empty() && m_libMgr->LibraryExists( libName )
&& !m_libMgr->IsLibraryReadOnly( libName );
};
auto canEditProperties =
[this] ( const SELECTION& sel )
{
@ -379,8 +370,8 @@ void SYMBOL_EDIT_FRAME::setupUIConditions()
mgr->SetConditions( ACTIONS::save, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
mgr->SetConditions( EE_ACTIONS::saveLibraryAs, ENABLE( libSelectedCondition ) );
mgr->SetConditions( EE_ACTIONS::saveSymbolAs, ENABLE( saveSymbolAsCondition ) );
mgr->SetConditions( EE_ACTIONS::newSymbol, ENABLE( !libSelectedCondition || canEditLib ) );
mgr->SetConditions( EE_ACTIONS::importSymbol, ENABLE( !libSelectedCondition || canEditLib ) );
mgr->SetConditions( EE_ACTIONS::newSymbol, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
mgr->SetConditions( EE_ACTIONS::importSymbol, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
mgr->SetConditions( ACTIONS::undo, ENABLE( haveSymbolCond && cond.UndoAvailable() ) );
mgr->SetConditions( ACTIONS::redo, ENABLE( haveSymbolCond && cond.RedoAvailable() ) );
@ -1228,10 +1219,9 @@ bool SYMBOL_EDIT_FRAME::IsContentModified()
return true;
// Test if any library has been modified
for( const auto& libNickname : m_libMgr->GetLibraryNames() )
for( const wxString& libName : m_libMgr->GetLibraryNames() )
{
if( m_libMgr->IsLibraryModified( libNickname )
&& !m_libMgr->IsLibraryReadOnly( libNickname ) )
if( m_libMgr->IsLibraryModified( libName ) && !m_libMgr->IsLibraryReadOnly( libName ) )
return true;
}

View File

@ -65,12 +65,6 @@ bool SYMBOL_EDITOR_CONTROL::Init()
LIB_ID sel = editFrame->GetTreeLIBID();
return !sel.GetLibNickname().empty();
};
auto canEditLibrary =
[ editFrame ]( const SELECTION& aSel )
{
LIB_ID sel = editFrame->GetTreeLIBID();
return !editFrame->GetLibManager().IsLibraryReadOnly( sel.GetLibNickname() );
};
auto pinnedLibSelectedCondition =
[ editFrame ]( const SELECTION& aSel )
{
@ -100,7 +94,7 @@ bool SYMBOL_EDITOR_CONTROL::Init()
ctxMenu.AddItem( ACTIONS::unpinLibrary, pinnedLibSelectedCondition );
ctxMenu.AddSeparator();
ctxMenu.AddItem( EE_ACTIONS::newSymbol, libInferredCondition && canEditLibrary );
ctxMenu.AddItem( EE_ACTIONS::newSymbol, libInferredCondition );
ctxMenu.AddSeparator();
ctxMenu.AddItem( ACTIONS::save, symbolSelectedCondition || libInferredCondition );
@ -109,14 +103,14 @@ bool SYMBOL_EDITOR_CONTROL::Init()
ctxMenu.AddItem( ACTIONS::revert, symbolSelectedCondition || libInferredCondition );
ctxMenu.AddSeparator();
ctxMenu.AddItem( EE_ACTIONS::cutSymbol, symbolSelectedCondition && canEditLibrary );
ctxMenu.AddItem( EE_ACTIONS::cutSymbol, symbolSelectedCondition );
ctxMenu.AddItem( EE_ACTIONS::copySymbol, symbolSelectedCondition );
ctxMenu.AddItem( EE_ACTIONS::pasteSymbol, libInferredCondition && canEditLibrary );
ctxMenu.AddItem( EE_ACTIONS::duplicateSymbol, symbolSelectedCondition && canEditLibrary );
ctxMenu.AddItem( EE_ACTIONS::deleteSymbol, symbolSelectedCondition && canEditLibrary );
ctxMenu.AddItem( EE_ACTIONS::pasteSymbol, libInferredCondition );
ctxMenu.AddItem( EE_ACTIONS::duplicateSymbol, symbolSelectedCondition );
ctxMenu.AddItem( EE_ACTIONS::deleteSymbol, symbolSelectedCondition );
ctxMenu.AddSeparator();
ctxMenu.AddItem( EE_ACTIONS::importSymbol, libInferredCondition && canEditLibrary);
ctxMenu.AddItem( EE_ACTIONS::importSymbol, libInferredCondition );
ctxMenu.AddItem( EE_ACTIONS::exportSymbol, symbolSelectedCondition );
}
@ -156,6 +150,17 @@ int SYMBOL_EDITOR_CONTROL::AddSymbol( const TOOL_EVENT& aEvent )
{
SYMBOL_EDIT_FRAME* editFrame = static_cast<SYMBOL_EDIT_FRAME*>( m_frame );
LIB_ID sel = editFrame->GetTreeLIBID();
const wxString& libName = sel.GetLibNickname();
wxString msg;
if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
{
msg.Printf( _( "Symbol library '%s' is not writeable." ), libName );
m_frame->ShowInfoBarError( msg );
return 0;
}
if( aEvent.IsAction( &EE_ACTIONS::newSymbol ) )
editFrame->CreateNewPart();
else if( aEvent.IsAction( &EE_ACTIONS::importSymbol ) )
@ -214,7 +219,20 @@ int SYMBOL_EDITOR_CONTROL::CutCopyDelete( const TOOL_EVENT& aEvt )
editFrame->CopyPartToClipboard();
if( aEvt.IsAction( &EE_ACTIONS::cutSymbol ) || aEvt.IsAction( &EE_ACTIONS::deleteSymbol ) )
{
LIB_ID sel = editFrame->GetTreeLIBID();
const wxString& libName = sel.GetLibNickname();
wxString msg;
if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
{
msg.Printf( _( "Symbol library '%s' is not writeable." ), libName );
m_frame->ShowInfoBarError( msg );
return 0;
}
editFrame->DeletePartFromLibrary();
}
}
return 0;
@ -226,6 +244,18 @@ int SYMBOL_EDITOR_CONTROL::DuplicateSymbol( const TOOL_EVENT& aEvent )
if( m_frame->IsType( FRAME_SCH_SYMBOL_EDITOR ) )
{
SYMBOL_EDIT_FRAME* editFrame = static_cast<SYMBOL_EDIT_FRAME*>( m_frame );
LIB_ID sel = editFrame->GetTreeLIBID();
const wxString& libName = sel.GetLibNickname();
wxString msg;
if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
{
msg.Printf( _( "Symbol library '%s' is not writeable." ), libName );
m_frame->ShowInfoBarError( msg );
return 0;
}
editFrame->DuplicatePart( aEvent.IsAction( &EE_ACTIONS::pasteSymbol ) );
}