Improve context menu consistency.

Also fixes some interactivity issues in the microwave tools around
single-click tools that have initial properties dialogs.  Those
need to act kind of like a hybrid between single-click and two-click
tools.

Fixes: lp:1751381
* https://bugs.launchpad.net/kicad/+bug/1751381
This commit is contained in:
Jeff Young 2018-08-01 17:58:27 +01:00
parent d6c6322f95
commit c655bffac1
10 changed files with 54 additions and 67 deletions

View File

@ -43,6 +43,7 @@
#include "length_tuner_tool.h"
#include <bitmaps.h>
#include <tools/tool_event_utils.h>
using namespace KIGFX;
@ -94,10 +95,9 @@ public:
SetIcon( router_len_tuner_xpm );
DisplayTitle( true );
//Add( ACT_StartTuning );
//Add( ACT_EndTuning );
Add( ACTIONS::cancelInteractive );
//AppendSeparator();
AppendSeparator();
Add( ACT_SpacingIncrease );
Add( ACT_SpacingDecrease );
@ -172,7 +172,7 @@ void LENGTH_TUNER_TOOL::performTuning()
while( OPT_TOOL_EVENT evt = Wait() )
{
if( evt->IsCancel() || evt->IsActivate() )
if( evt->IsCancel() || evt->IsActivate() || TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
break;
else if( evt->IsMotion() )
{
@ -278,7 +278,7 @@ int LENGTH_TUNER_TOOL::mainLoop( PNS::ROUTER_MODE aMode )
// Main loop: keep receiving events
while( OPT_TOOL_EVENT evt = Wait() )
{
if( evt->IsCancel() || evt->IsActivate() )
if( evt->IsCancel() || evt->IsActivate() || TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
{
break; // Finish
}

View File

@ -152,8 +152,7 @@ DRAWING_TOOL::DRAWING_TOOL() :
PCB_TOOL( "pcbnew.InteractiveDrawing" ),
m_view( nullptr ), m_controls( nullptr ),
m_board( nullptr ), m_frame( nullptr ), m_mode( MODE::NONE ),
m_lineWidth( 1 ),
m_menu( *this )
m_lineWidth( 1 )
{
}
@ -181,14 +180,15 @@ bool DRAWING_TOOL::Init()
auto& ctxMenu = m_menu.GetMenu();
// cancel current toool goes in main context menu at the top if present
ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolFunctor, 1000 );
// cancel current tool goes in main context menu at the top if present
ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolFunctor, 1 );
ctxMenu.AddSeparator( activeToolFunctor, 1 );
// tool-specific actions
ctxMenu.AddItem( closeZoneOutline, zoneActiveFunctor, 1000 );
ctxMenu.AddItem( deleteLastPoint, canUndoPoint, 1000 );
ctxMenu.AddItem( closeZoneOutline, zoneActiveFunctor, 200 );
ctxMenu.AddItem( deleteLastPoint, canUndoPoint, 200 );
ctxMenu.AddSeparator( activeToolFunctor, 1000 );
ctxMenu.AddSeparator( canUndoPoint, 500 );
// Type-specific sub-menus will be added for us by other tools
// For example, zone fill/unfill is provided by the PCB control tool
@ -1688,6 +1688,8 @@ int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent )
VIA_PLACER placer( frame() );
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::VIA );
frame()->SetToolID( ID_PCB_DRAW_VIA_BUTT, wxCURSOR_PENCIL, _( "Add vias" ) );
doInteractiveItemPlacement( &placer, _( "Place via" ),

View File

@ -77,7 +77,8 @@ public:
DIMENSION,
KEEPOUT,
ZONE,
GRAPHIC_POLYGON
GRAPHIC_POLYGON,
VIA
};
/**
@ -280,9 +281,6 @@ private:
/// Stores the current line width for multisegment drawing.
unsigned int m_lineWidth;
/// Menu model displayed by the tool.
TOOL_MENU m_menu;
// How does line width change after one -/+ key press.
static const unsigned int WIDTH_STEP;

View File

@ -237,8 +237,7 @@ void EnsureEditableFilter( const VECTOR2I&, GENERAL_COLLECTOR& aCollector )
EDIT_TOOL::EDIT_TOOL() :
PCB_TOOL( "pcbnew.InteractiveEdit" ), m_selectionTool( NULL ),
m_dragging( false ),
m_measureMenu( *this )
m_dragging( false )
{
}
@ -319,16 +318,6 @@ bool EDIT_TOOL::Init()
menu.AddItem( PCB_ACTIONS::updateFootprints, singleModuleCondition );
menu.AddItem( PCB_ACTIONS::exchangeFootprints, singleModuleCondition );
// Initialize menu for Measurement Tool
auto& ctxMenu = m_measureMenu.GetMenu();
// cancel current toool goes in main context menu at the top if present
ctxMenu.AddItem( ACTIONS::cancelInteractive, SELECTION_CONDITIONS::ShowAlways, 1000 );
ctxMenu.AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1000 );
// Finally, add the standard zoom/grid items
m_measureMenu.AddStandardSubMenus( *getEditFrame<PCB_BASE_FRAME>() );
return true;
}
@ -1304,7 +1293,7 @@ int EDIT_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
else if( evt->IsClick( BUT_RIGHT ) )
{
m_measureMenu.ShowContextMenu();
m_menu.ShowContextMenu();
}
}

View File

@ -194,9 +194,6 @@ private:
///> of edit reference point).
VECTOR2I m_cursor;
///> A context menu for the Measurement Tool
TOOL_MENU m_measureMenu;
///> Returns the right modification point (e.g. for rotation), depending on the number of
///> selected items.
bool updateModificationPoint( SELECTION& aSelection );

View File

@ -91,8 +91,7 @@ TOOL_ACTION PCB_ACTIONS::microwaveCreateLine(
MICROWAVE_TOOL::MICROWAVE_TOOL() :
PCB_TOOL( "pcbnew.MicrowaveTool" ),
m_menu( *this )
PCB_TOOL( "pcbnew.MicrowaveTool" )
{
}
@ -106,24 +105,6 @@ void MICROWAVE_TOOL::Reset( RESET_REASON aReason )
}
bool MICROWAVE_TOOL::Init()
{
auto activeToolFunctor = [] ( const SELECTION& aSel ) {
return true;
};
auto& ctxMenu = m_menu.GetMenu();
// cancel current goes in main context menu at the top if present
ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolFunctor, 1000 );
ctxMenu.AddSeparator( activeToolFunctor, 1000 );
m_menu.AddStandardSubMenus( *getEditFrame<PCB_BASE_FRAME>() );
return true;
}
struct MICROWAVE_TOOL_INFO
{
using MOD_CREATOR = std::function<std::unique_ptr<MODULE>()>;
@ -226,7 +207,8 @@ int MICROWAVE_TOOL::addMicrowaveFootprint( const TOOL_EVENT& aEvent )
MICROWAVE_PLACER placer ( info );
doInteractiveItemPlacement( &placer, _( "Place microwave feature" ) );
doInteractiveItemPlacement( &placer, _( "Place microwave feature" ),
IPO_REPEAT | IPO_SINGLE_CLICK | IPO_ROTATE | IPO_FLIP | IPO_PROPERTIES );
frame.SetNoToolSelected();

View File

@ -43,9 +43,6 @@ public:
///> React to model/view changes
void Reset( RESET_REASON aReason ) override;
///> Basic initalization
bool Init() override;
///> Bind handlers to corresponding TOOL_ACTIONs
void setTransitions() override;
@ -59,9 +56,6 @@ private:
///> Draw a microwave inductor interactively
int drawMicrowaveInductor( const TOOL_EVENT& aEvent );
/// Menu model displayed by the tool.
TOOL_MENU m_menu;
};

View File

@ -308,10 +308,10 @@ bool PCB_EDITOR_CONTROL::Init()
toolMenu.AddSubMenu( lockMenu );
menu.AddMenu( zoneMenu.get(), false,
SELECTION_CONDITIONS::OnlyType( PCB_ZONE_AREA_T ) );
SELECTION_CONDITIONS::OnlyType( PCB_ZONE_AREA_T ), 200 );
menu.AddMenu( lockMenu.get(), false,
SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::LockableItems ) );
SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::LockableItems ), 200 );
}
DRAWING_TOOL* drawingTool = m_toolMgr->GetTool<DRAWING_TOOL>();
@ -333,7 +333,7 @@ bool PCB_EDITOR_CONTROL::Init()
};
};
menu.AddMenu( zoneMenu.get(), false, toolActiveFunctor( DRAWING_TOOL::MODE::ZONE ) );
menu.AddMenu( zoneMenu.get(), false, toolActiveFunctor( DRAWING_TOOL::MODE::ZONE ), 200 );
}
m_ratsnestTimer.SetOwner( this );

View File

@ -61,7 +61,7 @@ void PCB_TOOL::doInteractiveItemPlacement( INTERACTIVE_PLACER_BASE* aPlacer,
aPlacer->m_frame = frame();
aPlacer->m_modifiers = 0;
if( aOptions & IPO_SINGLE_CLICK )
if( aOptions & IPO_SINGLE_CLICK && !( aOptions & IPO_PROPERTIES ) )
{
VECTOR2I cursorPos = controls()->GetCursorPosition();
@ -101,7 +101,6 @@ void PCB_TOOL::doInteractiveItemPlacement( INTERACTIVE_PLACER_BASE* aPlacer,
if( evt->IsActivate() ) // now finish unconditionally
break;
}
else if( evt->IsClick( BUT_LEFT ) )
{
if( !newItem )
@ -151,7 +150,7 @@ void PCB_TOOL::doInteractiveItemPlacement( INTERACTIVE_PLACER_BASE* aPlacer,
if( !( aOptions & IPO_REPEAT ) )
break;
if( aOptions & IPO_SINGLE_CLICK )
if( aOptions & IPO_SINGLE_CLICK && !( aOptions & IPO_PROPERTIES ) )
{
VECTOR2I pos = controls()->GetCursorPosition();
@ -162,7 +161,10 @@ void PCB_TOOL::doInteractiveItemPlacement( INTERACTIVE_PLACER_BASE* aPlacer,
}
}
}
else if( evt->IsClick( BUT_RIGHT ) )
{
m_menu.ShowContextMenu();
}
else if( newItem && evt->Category() == TC_COMMAND )
{
/*
@ -198,6 +200,23 @@ void PCB_TOOL::doInteractiveItemPlacement( INTERACTIVE_PLACER_BASE* aPlacer,
view()->Remove( &preview );
}
bool PCB_TOOL::Init()
{
// A basic context manu. Many (but not all) tools will choose to override this.
auto& ctxMenu = m_menu.GetMenu();
// cancel current tool goes in main context menu at the top if present
ctxMenu.AddItem( ACTIONS::cancelInteractive, SELECTION_CONDITIONS::ShowAlways, 1 );
ctxMenu.AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1 );
// Finally, add the standard zoom/grid items
m_menu.AddStandardSubMenus( *getEditFrame<PCB_BASE_FRAME>() );
return true;
}
void PCB_TOOL::Reset( RESET_REASON aReason )
{

View File

@ -35,7 +35,7 @@
#include <pcb_view.h>
#include <functional>
#include <tool/tool_menu.h>
/**
* Class PCB_TOOL
@ -70,6 +70,7 @@ public:
* Creates a tool with given id & name. The name must be unique. */
PCB_TOOL( TOOL_ID aId, const std::string& aName ) :
TOOL_INTERACTIVE ( aId, aName ),
m_menu( *this ),
m_editModules( false ) {};
/**
@ -78,10 +79,12 @@ public:
* Creates a tool with given name. The name must be unique. */
PCB_TOOL( const std::string& aName ) :
TOOL_INTERACTIVE ( aName ),
m_menu( *this ),
m_editModules( false ) {};
virtual ~PCB_TOOL() {};
virtual bool Init() override;
virtual void Reset( RESET_REASON aReason ) override;
/**
@ -141,6 +144,9 @@ protected:
const SELECTION& selection() const;
SELECTION& selection();
/// Menu model displayed by the tool.
TOOL_MENU m_menu;
bool m_editModules;
};