diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index be962e3103..e66cb6174b 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -355,30 +355,37 @@ void SYMBOL_EDIT_FRAME::setupUIConditions() auto libSelectedCondition = [this] ( const SELECTION& sel ) { - return !getTargetLibId().GetLibNickname().empty(); + return !GetTargetLibId().GetLibNickname().empty(); }; auto canEditLib = - [this] ( const SELECTION& sel ) - { - const wxString libName = getTargetLibId().GetLibNickname(); + [this] ( const SELECTION& sel ) + { + const wxString libName = GetTargetLibId().GetLibNickname(); - return !libName.empty() && m_libMgr->LibraryExists( libName ) - && !m_libMgr->IsLibraryReadOnly( libName ); - }; + return !libName.empty() && m_libMgr->LibraryExists( libName ) + && !m_libMgr->IsLibraryReadOnly( libName ); + }; auto canEditProperties = - [this] ( const SELECTION& sel ) - { - return m_my_part && ( !IsSymbolFromLegacyLibrary() || IsSymbolFromSchematic() ); - }; + [this] ( const SELECTION& sel ) + { + return m_my_part && ( !IsSymbolFromLegacyLibrary() || IsSymbolFromSchematic() ); + }; + + auto saveSymbolAsCondition = + [ this ]( const SELECTION& aSel ) + { + LIB_ID sel = GetTargetLibId(); + return !sel.GetLibNickname().empty() && !sel.GetLibItemName().empty(); + }; mgr->SetConditions( ACTIONS::saveAll, ENABLE( schematicModifiedCond || libModifiedCondition ) ); mgr->SetConditions( ACTIONS::save, ENABLE( schematicModifiedCond || libModifiedCondition ) ); mgr->SetConditions( EE_ACTIONS::saveLibraryAs, ENABLE( libSelectedCondition ) ); - mgr->SetConditions( EE_ACTIONS::saveSymbolAs, ENABLE( haveSymbolCond ) ); + mgr->SetConditions( EE_ACTIONS::saveSymbolAs, ENABLE( saveSymbolAsCondition ) ); mgr->SetConditions( EE_ACTIONS::newSymbol, ENABLE( !libSelectedCondition || canEditLib ) ); mgr->SetConditions( EE_ACTIONS::importSymbol, ENABLE( !libSelectedCondition || canEditLib ) ); @@ -884,7 +891,7 @@ LIB_PART* SYMBOL_EDIT_FRAME::getTargetPart() const } -LIB_ID SYMBOL_EDIT_FRAME::getTargetLibId() const +LIB_ID SYMBOL_EDIT_FRAME::GetTargetLibId() const { LIB_ID id = GetTreeLIBID(); @@ -903,7 +910,7 @@ LIB_TREE_NODE* SYMBOL_EDIT_FRAME::GetCurrentTreeNode() const wxString SYMBOL_EDIT_FRAME::getTargetLib() const { - return getTargetLibId().GetLibNickname(); + return GetTargetLibId().GetLibNickname(); } @@ -972,7 +979,7 @@ void SYMBOL_EDIT_FRAME::SyncLibraries( bool aShowProgress, const wxString& aForc void SYMBOL_EDIT_FRAME::RegenerateLibraryTree() { - LIB_ID target = getTargetLibId(); + LIB_ID target = GetTargetLibId(); m_treePane->GetLibTree()->Regenerate( true ); diff --git a/eeschema/symbol_editor/symbol_edit_frame.h b/eeschema/symbol_editor/symbol_edit_frame.h index 72a303ac08..00075e40cb 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.h +++ b/eeschema/symbol_editor/symbol_edit_frame.h @@ -350,6 +350,10 @@ public: ///< Restore the empty editor screen, without any part or library selected. void emptyScreen(); + ///< Return either the part selected in the symbol tree, if context menu is active or the + ///< currently modified part. + LIB_ID GetTargetLibId() const; + protected: void setupUIConditions() override; @@ -433,10 +437,6 @@ private: ///< Return currently edited part. LIB_PART* getTargetPart() const; - ///< Return either the part selected in the symbol tree, if context menu is active or the - ///< currently modified part. - LIB_ID getTargetLibId() const; - ///< Return either the library selected in the symbol tree, if context menu is active or ///< the library that is currently modified. wxString getTargetLib() const; diff --git a/eeschema/symbol_editor/symbol_editor.cpp b/eeschema/symbol_editor/symbol_editor.cpp index 264dc33358..994faa13e6 100644 --- a/eeschema/symbol_editor/symbol_editor.cpp +++ b/eeschema/symbol_editor/symbol_editor.cpp @@ -523,9 +523,9 @@ void SYMBOL_EDIT_FRAME::Save() saveCurrentPart(); } } - else if( !getTargetLibId().GetLibNickname().empty() ) + else if( !GetTargetLibId().GetLibNickname().empty() ) { - LIB_ID libId = getTargetLibId(); + LIB_ID libId = GetTargetLibId(); const wxString& libName = libId.GetLibNickname(); if( m_libMgr->IsLibraryReadOnly( libName ) ) @@ -549,9 +549,9 @@ void SYMBOL_EDIT_FRAME::Save() void SYMBOL_EDIT_FRAME::SaveLibraryAs() { - wxCHECK( !getTargetLibId().GetLibNickname().empty(), /* void */ ); + wxCHECK( !GetTargetLibId().GetLibNickname().empty(), /* void */ ); - const wxString& libName = getTargetLibId().GetLibNickname(); + const wxString& libName = GetTargetLibId().GetLibNickname(); saveLibrary( libName, true ); m_treePane->GetLibTree()->RefreshLibTree(); @@ -560,7 +560,7 @@ void SYMBOL_EDIT_FRAME::SaveLibraryAs() void SYMBOL_EDIT_FRAME::SaveSymbolAs() { - wxCHECK( getTargetLibId().IsValid(), /* void */ ); + wxCHECK( GetTargetLibId().IsValid(), /* void */ ); savePartAs(); @@ -713,7 +713,7 @@ void SYMBOL_EDIT_FRAME::UpdateAfterSymbolProperties( wxString* aOldName ) void SYMBOL_EDIT_FRAME::DeletePartFromLibrary() { - LIB_ID libId = getTargetLibId(); + LIB_ID libId = GetTargetLibId(); if( m_libMgr->IsPartModified( libId.GetLibItemName(), libId.GetLibNickname() ) && !IsOK( this, _( wxString::Format( "The symbol \"%s\" has been modified\n" @@ -869,7 +869,7 @@ void SYMBOL_EDIT_FRAME::ensureUniqueName( LIB_PART* aPart, const wxString& aLibr void SYMBOL_EDIT_FRAME::Revert( bool aConfirm ) { - LIB_ID libId = getTargetLibId(); + LIB_ID libId = GetTargetLibId(); const wxString& libName = libId.GetLibNickname(); // Empty if this is the library itself that is selected. diff --git a/eeschema/tools/symbol_editor_control.cpp b/eeschema/tools/symbol_editor_control.cpp index 43a8e20382..5cbd071589 100644 --- a/eeschema/tools/symbol_editor_control.cpp +++ b/eeschema/tools/symbol_editor_control.cpp @@ -79,6 +79,12 @@ bool SYMBOL_EDITOR_CONTROL::Init() LIB_ID sel = editFrame->GetTreeLIBID(); return !sel.GetLibNickname().empty() && !sel.GetLibItemName().empty(); }; + auto saveSymbolAsCondition = + [ editFrame ]( const SELECTION& aSel ) + { + LIB_ID sel = editFrame->GetTargetLibId(); + return !sel.GetLibNickname().empty() && !sel.GetLibItemName().empty(); + }; ctxMenu.AddItem( ACTIONS::pinLibrary, unpinnedLibSelectedCondition ); ctxMenu.AddItem( ACTIONS::unpinLibrary, pinnedLibSelectedCondition ); @@ -97,7 +103,7 @@ bool SYMBOL_EDITOR_CONTROL::Init() ctxMenu.AddSeparator(); ctxMenu.AddItem( ACTIONS::save, symbolSelectedCondition ); - ctxMenu.AddItem( EE_ACTIONS::saveSymbolAs, symbolSelectedCondition ); + ctxMenu.AddItem( EE_ACTIONS::saveSymbolAs, saveSymbolAsCondition ); ctxMenu.AddItem( ACTIONS::revert, symbolSelectedCondition ); ctxMenu.AddSeparator();