From 7415bf0c627760247b7a12b4a83bdefcf437a49b Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 14 Mar 2021 21:50:20 +0000 Subject: [PATCH] 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. --- eeschema/symbol_editor/symbol_edit_frame.cpp | 18 ++----- eeschema/tools/symbol_editor_control.cpp | 54 +++++++++++++++----- 2 files changed, 46 insertions(+), 26 deletions(-) diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index 2a97b60b56..3eefb72a76 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -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; } diff --git a/eeschema/tools/symbol_editor_control.cpp b/eeschema/tools/symbol_editor_control.cpp index 7d13e5a1fe..c303e961bc 100644 --- a/eeschema/tools/symbol_editor_control.cpp +++ b/eeschema/tools/symbol_editor_control.cpp @@ -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( 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( 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 ) ); }