Cosmetic refinement in conditional menu: avoid adding useless separators in menu.

A useless separator is a separator added when no menuitem was previously added.
This commit is contained in:
jean-pierre charras 2019-05-20 10:53:32 +02:00
parent 4ac20d7ab1
commit 97ddefd01a
1 changed files with 9 additions and 1 deletions

View File

@ -106,6 +106,9 @@ void CONDITIONAL_MENU::Evaluate( SELECTION& aSelection )
{ {
Clear(); Clear();
// We try to avoid adding useless separators (when no menuitems between separators)
int menu_count = 0; // number of menus since the latest separator
for( const ENTRY& entry : m_entries ) for( const ENTRY& entry : m_entries )
{ {
const SELECTION_CONDITION& cond = entry.Condition(); const SELECTION_CONDITION& cond = entry.Condition();
@ -128,16 +131,21 @@ void CONDITIONAL_MENU::Evaluate( SELECTION& aSelection )
{ {
case ENTRY::ACTION: case ENTRY::ACTION:
menuItem = Add( *entry.Action(), entry.IsCheckmarkEntry() ); menuItem = Add( *entry.Action(), entry.IsCheckmarkEntry() );
menu_count++;
break; break;
case ENTRY::MENU: case ENTRY::MENU:
menuItem = Add( entry.Menu() ); menuItem = Add( entry.Menu() );
menu_count++;
break; break;
case ENTRY::WXITEM: case ENTRY::WXITEM:
menuItem = Append( entry.wxItem()->GetId(), entry.wxItem()->GetItemLabel(), menuItem = Append( entry.wxItem()->GetId(), entry.wxItem()->GetItemLabel(),
entry.wxItem()->GetHelp(), entry.wxItem()->GetKind() ); entry.wxItem()->GetHelp(), entry.wxItem()->GetKind() );
menu_count++;
break; break;
case ENTRY::SEPARATOR: case ENTRY::SEPARATOR:
if( menu_count )
menuItem = AppendSeparator(); menuItem = AppendSeparator();
menu_count = 0;
break; break;
default: default:
assert( false ); assert( false );