From 887f2b2a70b66a2be2431e020e2ba2c6bfa5d9ad Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 23 Feb 2017 10:45:27 +0100 Subject: [PATCH] Adjusted "Select" context menu conditions Shows "Select" submenu when there is at least one item selected. It is necessary to use "select same sheet" and selection filter effectively. --- pcbnew/tools/selection_tool.cpp | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index bac75cf03d..96eda2c07c 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -128,21 +128,19 @@ private: void update() override { - SELECTION_TOOL* selTool = getToolManager()->GetTool(); + using S_C = SELECTION_CONDITIONS; - // lines like this make me really think about a better name for SELECTION_CONDITIONS class - bool selEnabled = ( SELECTION_CONDITIONS::OnlyType( PCB_VIA_T ) - || SELECTION_CONDITIONS::OnlyType( PCB_TRACE_T ) ) - ( selTool->GetSelection() ); + const auto& selection = getToolManager()->GetTool()->GetSelection(); - bool sheetSelEnabled = ( SELECTION_CONDITIONS::OnlyType( PCB_MODULE_T ) ) - ( selTool->GetSelection() ); + bool connItem = ( S_C::OnlyType( PCB_VIA_T ) || S_C::OnlyType( PCB_TRACE_T ) )( selection ); + bool sheetSelEnabled = ( S_C::OnlyType( PCB_MODULE_T ) )( selection ); - Enable( getMenuId( PCB_ACTIONS::selectNet ), selEnabled ); - Enable( getMenuId( PCB_ACTIONS::selectCopper ), selEnabled ); - Enable( getMenuId( PCB_ACTIONS::selectConnection ), selEnabled ); + Enable( getMenuId( PCB_ACTIONS::selectNet ), connItem ); + Enable( getMenuId( PCB_ACTIONS::selectCopper ), connItem ); + Enable( getMenuId( PCB_ACTIONS::selectConnection ), connItem ); Enable( getMenuId( PCB_ACTIONS::selectSameSheet ), sheetSelEnabled ); } + CONTEXT_MENU* create() const override { return new SELECT_MENU(); @@ -179,22 +177,15 @@ SELECTION_TOOL::~SELECTION_TOOL() bool SELECTION_TOOL::Init() { - using S_C = SELECTION_CONDITIONS; - - auto showSelectMenuFunctor = ( S_C::OnlyType( PCB_VIA_T ) || - S_C::OnlyType( PCB_TRACE_T ) || - S_C::OnlyType( PCB_MODULE_T ) ) && - S_C::Count( 1 ); - auto selectMenu = std::make_shared(); selectMenu->SetTool( this ); m_menu.AddSubMenu( selectMenu ); auto& menu = m_menu.GetMenu(); - menu.AddMenu( selectMenu.get(), false, showSelectMenuFunctor ); + menu.AddMenu( selectMenu.get(), false, SELECTION_CONDITIONS::NotEmpty ); // only show separator if there is a Select menu to show above it - menu.AddSeparator( showSelectMenuFunctor, 1000 ); + menu.AddSeparator( SELECTION_CONDITIONS::NotEmpty, 1000 ); m_menu.AddStandardSubMenus( *getEditFrame() );