Turn CONDITIONAL_MENU's conditions into only show/hide conditions

This leaves the decision to check/enable menu items to the main UI
conditions, and only the menu has control over showing/hiding the menu
items. Also rip out a special case for the preferenes item that isn't
needed on OSX anymore since all the main menus have been moved to
ACTION_MENUs now.
This commit is contained in:
Ian McInerney 2020-08-17 23:40:02 +01:00
parent e825a99b9a
commit 5955091eb3
3 changed files with 16 additions and 38 deletions

View File

@ -29,15 +29,15 @@
#include <kiface_i.h>
CONDITIONAL_MENU::CONDITIONAL_MENU( bool isContextMenu, TOOL_INTERACTIVE* aTool ) :
ACTION_MENU( isContextMenu, aTool )
CONDITIONAL_MENU::CONDITIONAL_MENU( TOOL_INTERACTIVE* aTool ) :
ACTION_MENU( true, aTool )
{
}
ACTION_MENU* CONDITIONAL_MENU::create() const
{
CONDITIONAL_MENU* clone = new CONDITIONAL_MENU( m_isContextMenu, m_tool );
CONDITIONAL_MENU* clone = new CONDITIONAL_MENU( m_tool );
clone->m_entries = m_entries;
return clone;
}
@ -137,7 +137,7 @@ void CONDITIONAL_MENU::Evaluate( SELECTION& aSelection )
continue;
}
if( m_isContextMenu && !result )
if( !result )
continue;
switch( entry.Type() )
@ -153,15 +153,6 @@ void CONDITIONAL_MENU::Evaluate( SELECTION& aSelection )
break;
case ENTRY::WXITEM:
#ifdef __WXMAC__
// Instantiate the Preferences item only on the first Resolve(); after that
// wxWidgets will have moved it to the Application menu
if( entry.wxItem()->GetId() == wxID_PREFERENCES )
{
if( &aSelection != &g_resolveDummySelection )
continue;
}
#endif
menuItem = new wxMenuItem( this,
entry.wxItem()->GetId(),
entry.wxItem()->GetItemLabel(),
@ -188,14 +179,6 @@ void CONDITIONAL_MENU::Evaluate( SELECTION& aSelection )
wxASSERT( false );
break;
}
if( menuItem )
{
if( entry.IsCheckmarkEntry() )
menuItem->Check( result );
else
menuItem->Enable( result );
}
}
// Recursively call Evaluate on all the submenus that are CONDITIONAL_MENUs to ensure

View File

@ -32,7 +32,7 @@
TOOL_MENU::TOOL_MENU( TOOL_INTERACTIVE& aTool ) :
m_menu( true, &aTool ),
m_menu( &aTool ),
m_tool( aTool )
{
}

View File

@ -41,16 +41,15 @@ public:
///> Constant to indicate that we do not care about an ENTRY location in the menu.
static const int ANY_ORDER = -1;
CONDITIONAL_MENU( bool isContextMenu, TOOL_INTERACTIVE* aTool );
CONDITIONAL_MENU( TOOL_INTERACTIVE* aTool );
ACTION_MENU* create() const override;
/**
* Function AddItem()
*
* Adds a menu entry to run a TOOL_ACTION on selected items.
*
* @param aAction is a menu entry to be added.
* @param aCondition is a condition that has to be fulfilled to enable the menu entry.
* @param aCondition is a condition that has to be fulfilled to show the menu entry in the menu.
* @param aOrder determines location of the added item, higher numbers are put on the bottom.
* You may use ANY_ORDER here if you think it does not matter.
*/
@ -61,11 +60,13 @@ public:
const SELECTION_CONDITION& aCondition, int aOrder = ANY_ORDER );
/**
* Function AddCheckItem()
*
* Adds a checked menu entry to run a TOOL_ACTION on selected items.
*
* The condition for checking the menu entry should be supplied through a ACTION_CONDITION
* registered with the ACTION_MANAGER.
*
* @param aAction is a menu entry to be added.
* @param aCondition is a condition that has to be fulfilled to check the menu entry.
* @param aCondition is a condition that has to be fulfilled to show the menu entry in the menu.
* @param aOrder determines location of the added item, higher numbers are put on the bottom.
* You may use ANY_ORDER here if you think it does not matter.
*/
@ -76,14 +77,13 @@ public:
const SELECTION_CONDITION& aCondition, int aOrder = ANY_ORDER );
/**
* Function AddMenu()
*
* Adds a submenu to the menu. CONDITIONAL_MENU takes ownership of the added menu, so it will
* be freed when the CONDITIONAL_MENU object is destroyed.
*
* @param aMenu is the submenu to be added.
* @param aExpand determines if the added submenu items should be added as individual items
* or as a submenu.
* @param aCondition is a condition that has to be fulfilled to enable the submenu entry.
* @param aCondition is a condition that has to be fulfilled to show the submenu entry in the menu.
* @param aOrder determines location of the added menu, higher numbers are put on the bottom.
* You may use ANY_ORDER here if you think it does not matter.
*/
@ -92,23 +92,18 @@ public:
int aOrder = ANY_ORDER );
/**
* Function AddSeparator()
*
* Adds a separator to the menu.
*
* @param aOrder determines location of the separator, higher numbers are put on the bottom.
*/
void AddSeparator( int aOrder = ANY_ORDER );
/**
* Function Evaluate()
*
* Updates the contents of the menu based on the supplied conditions.
*/
void Evaluate( SELECTION& aSelection );
/**
* Function Resolve()
*
* Updates the initial contents so that wxWidgets doesn't get its knickers tied in a knot
* over the menu being empty (mainly an issue on GTK, but also on OSX with the preferences
* and quit menu items).