Use lambdas to fix paste conditions

`SELECTION_CONDITIONS::Idle && ` was evaluating as always true because this was referencing the function pointer
This commit is contained in:
Marek Roszko 2021-05-30 20:37:16 -04:00
parent a7d1ef9927
commit 65c7c77c3d
5 changed files with 52 additions and 14 deletions

View File

@ -385,6 +385,12 @@ void SCH_EDIT_FRAME::setupUIConditions()
#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
#define CHECK( x ) ACTION_CONDITIONS().Check( x )
auto idleCond =
[&]( const SELECTION& aSel )
{
return SELECTION_CONDITIONS::Idle( aSel );
};
mgr->SetConditions( ACTIONS::save, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
mgr->SetConditions( ACTIONS::undo, ENABLE( cond.UndoAvailable() ) );
mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) );
@ -397,8 +403,8 @@ void SCH_EDIT_FRAME::setupUIConditions()
mgr->SetConditions( ACTIONS::cut, ENABLE( hasElements ) );
mgr->SetConditions( ACTIONS::copy, ENABLE( hasElements ) );
mgr->SetConditions( ACTIONS::paste, ENABLE( SELECTION_CONDITIONS::Idle ) );
mgr->SetConditions( ACTIONS::pasteSpecial, ENABLE( SELECTION_CONDITIONS::Idle ) );
mgr->SetConditions( ACTIONS::paste, ENABLE( idleCond ) );
mgr->SetConditions( ACTIONS::pasteSpecial, ENABLE( idleCond ) );
mgr->SetConditions( ACTIONS::doDelete, ENABLE( hasElements ) );
mgr->SetConditions( ACTIONS::duplicate, ENABLE( hasElements ) );
mgr->SetConditions( ACTIONS::selectAll, ENABLE( hasElements ) );

View File

@ -385,6 +385,12 @@ void SYMBOL_EDIT_FRAME::setupUIConditions()
return !sel.GetLibNickname().empty() && !sel.GetLibItemName().empty();
};
auto haveNoToolIdleCond =
[&]( const SELECTION& aSel )
{
return isEditableCond( aSel ) && SELECTION_CONDITIONS::Idle( aSel );
};
mgr->SetConditions( ACTIONS::saveAll, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
mgr->SetConditions( ACTIONS::save, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
mgr->SetConditions( EE_ACTIONS::saveLibraryAs, ENABLE( libSelectedCondition ) );
@ -404,7 +410,7 @@ void SYMBOL_EDIT_FRAME::setupUIConditions()
mgr->SetConditions( ACTIONS::cut, ENABLE( isEditableCond ) );
mgr->SetConditions( ACTIONS::copy, ENABLE( haveSymbolCond ) );
mgr->SetConditions( ACTIONS::paste, ENABLE( isEditableCond && SELECTION_CONDITIONS::Idle ) );
mgr->SetConditions( ACTIONS::paste, ENABLE( haveNoToolIdleCond ) );
mgr->SetConditions( ACTIONS::doDelete, ENABLE( isEditableCond ) );
mgr->SetConditions( ACTIONS::duplicate, ENABLE( isEditableCond ) );
mgr->SetConditions( ACTIONS::selectAll, ENABLE( haveSymbolCond ) );

View File

@ -264,6 +264,22 @@ void PL_EDITOR_FRAME::setupUIConditions()
#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
#define CHECK( x ) ACTION_CONDITIONS().Check( x )
auto idleCond =
[&]( const SELECTION& aSel )
{
return SELECTION_CONDITIONS::Idle( aSel );
};
auto notEmptyCond =
[&]( const SELECTION& aSel )
{
return SELECTION_CONDITIONS::NotEmpty( aSel );
};
auto neverCond = [&]( const SELECTION& aSel ) {
return SELECTION_CONDITIONS::ShowNever( aSel );
};
mgr->SetConditions( ACTIONS::save, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
mgr->SetConditions( ACTIONS::undo, ENABLE( cond.UndoAvailable() ) );
mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) );
@ -274,10 +290,10 @@ void PL_EDITOR_FRAME::setupUIConditions()
mgr->SetConditions( ACTIONS::inchesUnits, CHECK( cond.Units( EDA_UNITS::INCHES ) ) );
mgr->SetConditions( ACTIONS::milsUnits, CHECK( cond.Units( EDA_UNITS::MILS ) ) );
mgr->SetConditions( ACTIONS::cut, ENABLE( SELECTION_CONDITIONS::NotEmpty ) );
mgr->SetConditions( ACTIONS::copy, ENABLE( SELECTION_CONDITIONS::NotEmpty ) );
mgr->SetConditions( ACTIONS::paste, ENABLE( SELECTION_CONDITIONS::Idle ) );
mgr->SetConditions( ACTIONS::doDelete, ENABLE( SELECTION_CONDITIONS::NotEmpty ) );
mgr->SetConditions( ACTIONS::cut, ENABLE( notEmptyCond ) );
mgr->SetConditions( ACTIONS::copy, ENABLE( notEmptyCond ) );
mgr->SetConditions( ACTIONS::paste, ENABLE( idleCond ) );
mgr->SetConditions( ACTIONS::doDelete, ENABLE( notEmptyCond ) );
mgr->SetConditions( ACTIONS::zoomTool, CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) );
mgr->SetConditions( ACTIONS::selectionTool, CHECK( cond.CurrentTool( ACTIONS::selectionTool ) ) );
@ -289,7 +305,7 @@ void PL_EDITOR_FRAME::setupUIConditions()
mgr->SetConditions( PL_ACTIONS::placeImage, CHECK( cond.CurrentTool( PL_ACTIONS::placeImage ) ) );
// Not a tool, just a way to activate the action
mgr->SetConditions( PL_ACTIONS::appendImportedWorksheet, CHECK( SELECTION_CONDITIONS::ShowNever ) );
mgr->SetConditions( PL_ACTIONS::appendImportedWorksheet, CHECK( neverCond ) );
auto titleBlockNormalMode =
[] ( const SELECTION& )

View File

@ -985,6 +985,12 @@ void FOOTPRINT_EDIT_FRAME::setupUIConditions()
return !GetTargetFPID().GetLibItemName().empty();
};
auto haveNoToolIdleCond =
[&]( const SELECTION& aSel )
{
return SELECTION_CONDITIONS::Idle( aSel ) && cond.NoActiveTool();
};
mgr->SetConditions( ACTIONS::saveAs, ENABLE( footprintTargettedCond ) );
mgr->SetConditions( ACTIONS::revert, ENABLE( cond.ContentModified() ) );
mgr->SetConditions( ACTIONS::save, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
@ -1000,8 +1006,8 @@ void FOOTPRINT_EDIT_FRAME::setupUIConditions()
mgr->SetConditions( ACTIONS::cut, ENABLE( cond.HasItems() ) );
mgr->SetConditions( ACTIONS::copy, ENABLE( cond.HasItems() ) );
mgr->SetConditions( ACTIONS::paste, ENABLE( SELECTION_CONDITIONS::Idle && cond.NoActiveTool() ) );
mgr->SetConditions( ACTIONS::pasteSpecial, ENABLE( SELECTION_CONDITIONS::Idle && cond.NoActiveTool() ) );
mgr->SetConditions( ACTIONS::paste, ENABLE( haveNoToolIdleCond ) );
mgr->SetConditions( ACTIONS::pasteSpecial, ENABLE( haveNoToolIdleCond ) );
mgr->SetConditions( ACTIONS::doDelete, ENABLE( cond.HasItems() ) );
mgr->SetConditions( ACTIONS::duplicate, ENABLE( cond.HasItems() ) );
mgr->SetConditions( ACTIONS::selectAll, ENABLE( cond.HasItems() ) );

View File

@ -523,6 +523,12 @@ void PCB_EDIT_FRAME::setupUIConditions()
#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
#define CHECK( x ) ACTION_CONDITIONS().Check( x )
auto haveNoToolIdleCond =
[&]( const SELECTION& aSel )
{
return SELECTION_CONDITIONS::Idle( aSel ) && cond.NoActiveTool();
};
mgr->SetConditions( ACTIONS::save, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
mgr->SetConditions( ACTIONS::undo, ENABLE( cond.UndoAvailable() ) );
mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) );
@ -536,10 +542,8 @@ void PCB_EDIT_FRAME::setupUIConditions()
mgr->SetConditions( ACTIONS::cut, ENABLE( cond.HasItems() ) );
mgr->SetConditions( ACTIONS::copy, ENABLE( cond.HasItems() ) );
mgr->SetConditions( ACTIONS::paste,
ENABLE( SELECTION_CONDITIONS::Idle && cond.NoActiveTool() ) );
mgr->SetConditions( ACTIONS::pasteSpecial,
ENABLE( SELECTION_CONDITIONS::Idle && cond.NoActiveTool() ) );
mgr->SetConditions( ACTIONS::paste, ENABLE( haveNoToolIdleCond ) );
mgr->SetConditions( ACTIONS::pasteSpecial, ENABLE( haveNoToolIdleCond ) );
mgr->SetConditions( ACTIONS::selectAll, ENABLE( cond.HasItems() ) );
mgr->SetConditions( ACTIONS::doDelete, ENABLE( cond.HasItems() ) );
mgr->SetConditions( ACTIONS::duplicate, ENABLE( cond.HasItems() ) );