From da6d0c9de68739894acc6c241ba202dffa620df2 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Thu, 16 Jul 2020 02:22:29 +0100 Subject: [PATCH] Add cancel to the selection context menu if a tool is running The selection tool's context menu is displayed during the move tool, so it should contain the ability to cancel the current action. --- pcbnew/tools/edit_tool.cpp | 24 ++++++++---------------- pcbnew/tools/selection_tool.cpp | 10 ++++++++++ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 84e5f744d2..83f1f2a176 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -174,10 +174,17 @@ bool EDIT_TOOL::Init() return frame()->ToolStackIsEmpty(); }; + auto notMovingCondition = + [ this ] ( const SELECTION& aSelection ) + { + return !frame()->IsCurrentTool( PCB_ACTIONS::move ) + && !frame()->IsCurrentTool( PCB_ACTIONS::moveWithReference ); + }; + // Add context menu entries that are displayed when selection tool is active CONDITIONAL_MENU& menu = m_selectionTool->GetToolMenu().GetMenu(); - menu.AddItem( PCB_ACTIONS::move, SELECTION_CONDITIONS::NotEmpty ); + menu.AddItem( PCB_ACTIONS::move, SELECTION_CONDITIONS::NotEmpty && notMovingCondition ); menu.AddItem( PCB_ACTIONS::inlineBreakTrack, SELECTION_CONDITIONS::Count( 1 ) && SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) ); menu.AddItem( PCB_ACTIONS::drag45Degree, SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) ); @@ -213,21 +220,6 @@ bool EDIT_TOOL::Init() menu.AddItem( PCB_ACTIONS::updateFootprint, singleModuleCondition ); menu.AddItem( PCB_ACTIONS::changeFootprint, singleModuleCondition ); - // Populate the context menu displayed during the edit tool (primarily the measure tool) - auto activeToolCondition = [ this ] ( const SELECTION& aSel ) { - return !frame()->ToolStackIsEmpty(); - }; - - auto frame = getEditFrame(); - auto& ctxMenu = m_menu.GetMenu(); - - // "Cancel" goes at the top of the context menu when a tool is active - ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolCondition, 1 ); - ctxMenu.AddSeparator( 1 ); - - if( frame ) - frame->AddStandardSubMenus( m_menu ); - return true; } diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index a63d667d02..ec0bddd5b0 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -157,9 +157,19 @@ bool SELECTION_TOOL::Init() auto& menu = m_menu.GetMenu(); + auto activeToolCondition = + [ frame ] ( const SELECTION& aSel ) + { + return !frame->ToolStackIsEmpty(); + }; + menu.AddMenu( selectMenu.get(), SELECTION_CONDITIONS::NotEmpty ); menu.AddSeparator( 1000 ); + // "Cancel" goes at the top of the context menu when a tool is active + menu.AddItem( ACTIONS::cancelInteractive, activeToolCondition, 1 ); + menu.AddSeparator( 1 ); + if( frame ) frame->AddStandardSubMenus( m_menu );