Whittle down library tree context menus to be more contextual.

(From discussion on Zulip.)
This commit is contained in:
Jeff Young 2021-02-18 20:37:27 +00:00
parent 48853d0c88
commit c2f68ca4da
2 changed files with 17 additions and 22 deletions

View File

@ -98,21 +98,14 @@ bool SYMBOL_EDITOR_CONTROL::Init()
ctxMenu.AddItem( ACTIONS::pinLibrary, unpinnedLibSelectedCondition );
ctxMenu.AddItem( ACTIONS::unpinLibrary, pinnedLibSelectedCondition );
ctxMenu.AddSeparator();
ctxMenu.AddItem( ACTIONS::newLibrary, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddItem( ACTIONS::addLibrary, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddItem( ACTIONS::save, libSelectedCondition );
ctxMenu.AddItem( EE_ACTIONS::saveLibraryAs, libSelectedCondition );
ctxMenu.AddItem( ACTIONS::revert, libSelectedCondition );
ctxMenu.AddSeparator();
ctxMenu.AddItem( EE_ACTIONS::newSymbol, libInferredCondition && canEditLibrary );
ctxMenu.AddItem( EE_ACTIONS::editSymbol, symbolSelectedCondition && canEditLibrary );
ctxMenu.AddSeparator();
ctxMenu.AddItem( ACTIONS::save, symbolSelectedCondition );
ctxMenu.AddItem( ACTIONS::save, symbolSelectedCondition || libInferredCondition );
ctxMenu.AddItem( EE_ACTIONS::saveLibraryAs, libSelectedCondition );
ctxMenu.AddItem( EE_ACTIONS::saveSymbolAs, saveSymbolAsCondition );
ctxMenu.AddItem( ACTIONS::revert, symbolSelectedCondition );
ctxMenu.AddItem( ACTIONS::revert, symbolSelectedCondition || libInferredCondition );
ctxMenu.AddSeparator();
ctxMenu.AddItem( EE_ACTIONS::cutSymbol, symbolSelectedCondition && canEditLibrary );

View File

@ -76,6 +76,15 @@ bool FOOTPRINT_EDITOR_CONTROL::Init()
LIB_ID sel = m_frame->GetTreeFPID();
return !sel.GetLibNickname().empty() && sel.GetLibItemName().empty();
};
// The libInferredCondition allows you to do things like New Symbol and Paste with a
// symbol selected (in other words, when we know the library context even if the library
// itself isn't selected.
auto libInferredCondition =
[ this ]( const SELECTION& aSel )
{
LIB_ID sel = m_frame->GetTreeFPID();
return !sel.GetLibNickname().empty();
};
auto pinnedLibSelectedCondition =
[ this ]( const SELECTION& aSel )
{
@ -98,33 +107,26 @@ bool FOOTPRINT_EDITOR_CONTROL::Init()
ctxMenu.AddItem( ACTIONS::pinLibrary, unpinnedLibSelectedCondition );
ctxMenu.AddItem( ACTIONS::unpinLibrary, pinnedLibSelectedCondition );
ctxMenu.AddSeparator();
ctxMenu.AddItem( ACTIONS::newLibrary, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddItem( ACTIONS::addLibrary, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddItem( ACTIONS::save, libSelectedCondition );
ctxMenu.AddItem( ACTIONS::saveAs, libSelectedCondition );
ctxMenu.AddItem( ACTIONS::revert, libSelectedCondition );
ctxMenu.AddSeparator();
ctxMenu.AddItem( PCB_ACTIONS::newFootprint, libSelectedCondition );
#ifdef KICAD_SCRIPTING
ctxMenu.AddItem( PCB_ACTIONS::createFootprint, libSelectedCondition );
#endif
ctxMenu.AddItem( PCB_ACTIONS::editFootprint, fpSelectedCondition );
ctxMenu.AddSeparator();
ctxMenu.AddItem( ACTIONS::save, fpSelectedCondition );
ctxMenu.AddItem( ACTIONS::save, libSelectedCondition || libInferredCondition );
ctxMenu.AddItem( ACTIONS::saveAs, libSelectedCondition );
ctxMenu.AddItem( ACTIONS::saveCopyAs, fpSelectedCondition );
ctxMenu.AddItem( ACTIONS::revert, fpSelectedCondition );
ctxMenu.AddItem( ACTIONS::revert, libSelectedCondition || libInferredCondition );
ctxMenu.AddSeparator();
ctxMenu.AddItem( PCB_ACTIONS::cutFootprint, fpSelectedCondition );
ctxMenu.AddItem( PCB_ACTIONS::copyFootprint, fpSelectedCondition );
ctxMenu.AddItem( PCB_ACTIONS::pasteFootprint, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddItem( PCB_ACTIONS::pasteFootprint, libInferredCondition );
ctxMenu.AddItem( PCB_ACTIONS::deleteFootprint, fpSelectedCondition );
ctxMenu.AddSeparator();
ctxMenu.AddItem( PCB_ACTIONS::importFootprint, libSelectedCondition );
ctxMenu.AddItem( PCB_ACTIONS::importFootprint, libInferredCondition );
ctxMenu.AddItem( PCB_ACTIONS::exportFootprint, fpSelectedCondition );
return true;