From 29b28de3175ccbc6c67861cd6c972bc9beff26dd Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 14 Feb 2018 23:46:33 +0000 Subject: [PATCH] Promote pad renumberer to a proper tool. This gives it a context menu with a Cancel item. Commit also includes a couple of fixes to the Pads submenu. --- pcbnew/tools/module_editor_tools.cpp | 17 +++++++++++------ pcbnew/tools/pad_tool.cpp | 10 ++++++++-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/pcbnew/tools/module_editor_tools.cpp b/pcbnew/tools/module_editor_tools.cpp index f6a2cf0aba..495feb3c1a 100644 --- a/pcbnew/tools/module_editor_tools.cpp +++ b/pcbnew/tools/module_editor_tools.cpp @@ -156,12 +156,11 @@ int MODULE_EDITOR_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent ) int padNumber = settingsDlg.GetStartNumber(); wxString padPrefix = settingsDlg.GetPrefix(); - frame()->DisplayToolMsg( _( - "Hold left mouse button and move cursor over pads to enumerate them" ) ); + frame()->SetToolID( ID_MODEDIT_PAD_TOOL, wxCURSOR_HAND, + _( "Click on successive pads to renumber them" ) ); m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); getViewControls()->ShowCursor( true ); - frame()->GetGalCanvas()->SetCursor( wxCURSOR_HAND ); KIGFX::VIEW* view = m_toolMgr->GetView(); VECTOR2I oldCursorPos; // store the previous mouse cursor position, during mouse drag @@ -244,16 +243,22 @@ int MODULE_EDITOR_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent ) else if( ( evt->IsKeyPressed() && evt->KeyCode() == WXK_RETURN ) || evt->IsDblClick( BUT_LEFT ) ) { - commit.Push( _( "Enumerate pads" ) ); + commit.Push( _( "Renumber pads" ) ); break; } - else if( evt->IsCancel() || evt->IsActivate() ) + else if( evt->IsCancel() || TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() ) { commit.Revert(); break; } + else + { + // Delegate BUT_RIGHT, etc. to SELECTION_TOOL + m_toolMgr->PassEvent(); + } + // Prepare the next loop by updating the old cursor mouse position // to this last mouse cursor position oldCursorPos = getViewControls()->GetCursorPosition(); @@ -265,7 +270,7 @@ int MODULE_EDITOR_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent ) view->Update( p ); } - frame()->DisplayToolMsg( wxEmptyString ); + frame()->SetNoToolSelected(); frame()->GetGalCanvas()->SetCursor( wxCURSOR_ARROW ); return 0; diff --git a/pcbnew/tools/pad_tool.cpp b/pcbnew/tools/pad_tool.cpp index 7114f3611b..74e3e27e5d 100644 --- a/pcbnew/tools/pad_tool.cpp +++ b/pcbnew/tools/pad_tool.cpp @@ -185,9 +185,11 @@ bool PAD_TOOL::Init() toolMenu.AddSubMenu( contextMenu ); - SELECTION_CONDITION canShowMenuCond = [this, contextMenu] ( const SELECTION& aSel ) { + auto canShowMenuCond = [this, contextMenu] ( const SELECTION& aSel ) { contextMenu->UpdateAll(); - return haveFootprints() && contextMenu->HasEnabledItems(); + return frame()->GetToolId() == ID_NO_TOOL_SELECTED + && haveFootprints() + && contextMenu->HasEnabledItems(); }; // show menu when there is a footprint, and the menu has any items @@ -196,6 +198,10 @@ bool PAD_TOOL::Init() || SELECTION_CONDITIONS::Count( 0 ) ); menu.AddMenu( contextMenu.get(), false, showCond, 1000 ); + + // we need a separator only when the selection is empty + auto separatorCond = canShowMenuCond && SELECTION_CONDITIONS::Count( 0 ); + menu.AddSeparator( separatorCond, 1000 ); } return true;