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.
This commit is contained in:
Jeff Young 2018-02-14 23:46:33 +00:00 committed by Maciej Suminski
parent 93999f7af6
commit 29b28de317
2 changed files with 19 additions and 8 deletions

View File

@ -156,12 +156,11 @@ int MODULE_EDITOR_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent )
int padNumber = settingsDlg.GetStartNumber(); int padNumber = settingsDlg.GetStartNumber();
wxString padPrefix = settingsDlg.GetPrefix(); wxString padPrefix = settingsDlg.GetPrefix();
frame()->DisplayToolMsg( _( frame()->SetToolID( ID_MODEDIT_PAD_TOOL, wxCURSOR_HAND,
"Hold left mouse button and move cursor over pads to enumerate them" ) ); _( "Click on successive pads to renumber them" ) );
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
getViewControls()->ShowCursor( true ); getViewControls()->ShowCursor( true );
frame()->GetGalCanvas()->SetCursor( wxCURSOR_HAND );
KIGFX::VIEW* view = m_toolMgr->GetView(); KIGFX::VIEW* view = m_toolMgr->GetView();
VECTOR2I oldCursorPos; // store the previous mouse cursor position, during mouse drag 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 ) || else if( ( evt->IsKeyPressed() && evt->KeyCode() == WXK_RETURN ) ||
evt->IsDblClick( BUT_LEFT ) ) evt->IsDblClick( BUT_LEFT ) )
{ {
commit.Push( _( "Enumerate pads" ) ); commit.Push( _( "Renumber pads" ) );
break; break;
} }
else if( evt->IsCancel() || evt->IsActivate() ) else if( evt->IsCancel() || TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{ {
commit.Revert(); commit.Revert();
break; break;
} }
else
{
// Delegate BUT_RIGHT, etc. to SELECTION_TOOL
m_toolMgr->PassEvent();
}
// Prepare the next loop by updating the old cursor mouse position // Prepare the next loop by updating the old cursor mouse position
// to this last mouse cursor position // to this last mouse cursor position
oldCursorPos = getViewControls()->GetCursorPosition(); oldCursorPos = getViewControls()->GetCursorPosition();
@ -265,7 +270,7 @@ int MODULE_EDITOR_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent )
view->Update( p ); view->Update( p );
} }
frame()->DisplayToolMsg( wxEmptyString ); frame()->SetNoToolSelected();
frame()->GetGalCanvas()->SetCursor( wxCURSOR_ARROW ); frame()->GetGalCanvas()->SetCursor( wxCURSOR_ARROW );
return 0; return 0;

View File

@ -185,9 +185,11 @@ bool PAD_TOOL::Init()
toolMenu.AddSubMenu( contextMenu ); toolMenu.AddSubMenu( contextMenu );
SELECTION_CONDITION canShowMenuCond = [this, contextMenu] ( const SELECTION& aSel ) { auto canShowMenuCond = [this, contextMenu] ( const SELECTION& aSel ) {
contextMenu->UpdateAll(); 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 // 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 ) ); || SELECTION_CONDITIONS::Count( 0 ) );
menu.AddMenu( contextMenu.get(), false, showCond, 1000 ); 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; return true;