From 97cb15dd472f29c3b3a67e816bd1f82bb2c84d77 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 18 Jan 2024 00:21:06 +0000 Subject: [PATCH] Make sub menus conditional on them having child items. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16631 --- common/tool/conditional_menu.cpp | 2 +- include/tool/conditional_menu.h | 2 +- pcbnew/tools/edit_tool.cpp | 20 ++++++++++++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/common/tool/conditional_menu.cpp b/common/tool/conditional_menu.cpp index 73adf100c0..02b902f5b1 100644 --- a/common/tool/conditional_menu.cpp +++ b/common/tool/conditional_menu.cpp @@ -124,7 +124,7 @@ void CONDITIONAL_MENU::Resolve() } -void CONDITIONAL_MENU::Evaluate( SELECTION& aSelection ) +void CONDITIONAL_MENU::Evaluate( const SELECTION& aSelection ) { Clear(); diff --git a/include/tool/conditional_menu.h b/include/tool/conditional_menu.h index 9025898b50..b6d3fc267d 100644 --- a/include/tool/conditional_menu.h +++ b/include/tool/conditional_menu.h @@ -108,7 +108,7 @@ public: /** * Update the contents of the menu based on the supplied conditions. */ - void Evaluate( SELECTION& aSelection ); + void Evaluate( const SELECTION& aSelection ); /** * Update the initial contents so that wxWidgets doesn't get its knickers tied in a knot diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index eefb6b6b65..d0b5eff9a0 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -182,6 +182,22 @@ bool EDIT_TOOL::Init() std::shared_ptr shapeModificationSubMenu = makeShapeModificationMenu( this ); m_selectionTool->GetToolMenu().RegisterSubMenu( shapeModificationSubMenu ); + auto positioningToolsCondition = + [&]( const SELECTION& aSel ) + { + std::shared_ptr subMenu = makePositioningToolsMenu( this ); + subMenu->Evaluate( aSel ); + return subMenu->GetMenuItemCount() > 0; + }; + + auto shapeModificationCondition = + [&]( const SELECTION& aSel ) + { + std::shared_ptr subMenu = makeShapeModificationMenu( this ); + subMenu->Evaluate( aSel ); + return subMenu->GetMenuItemCount() > 0; + }; + auto propertiesCondition = [&]( const SELECTION& aSel ) { @@ -337,8 +353,8 @@ bool EDIT_TOOL::Init() // Add the submenu for the special tools: modfiers and positioning tools menu.AddSeparator( 100 ); - menu.AddMenu( shapeModificationSubMenu.get(), SELECTION_CONDITIONS::NotEmpty, 100 ); - menu.AddMenu( positioningToolsSubMenu.get(), SELECTION_CONDITIONS::NotEmpty, 100 ); + menu.AddMenu( shapeModificationSubMenu.get(), shapeModificationCondition, 100 ); + menu.AddMenu( positioningToolsSubMenu.get(), positioningToolsCondition, 100 ); menu.AddSeparator( 150 ); menu.AddItem( ACTIONS::cut, SELECTION_CONDITIONS::NotEmpty, 150 );