1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-11-21 16:37:12 +01:00

Use class MenuSection in visitors

This commit is contained in:
Paul Licameli
2020-01-29 16:31:35 -05:00
parent d84c994088
commit c7fac7ae09
3 changed files with 57 additions and 17 deletions

View File

@@ -371,8 +371,11 @@ struct MenuItemVisitor : MenuVisitor
flags.push_back(flag); flags.push_back(flag);
} }
else else
if (const auto pGroup = dynamic_cast<GroupItem*>( pItem )) { if ( pItem->Transparent() ) {
wxASSERT( pGroup->Transparent() ); }
else
if ( const auto pGroup = dynamic_cast<MenuSection*>( pItem ) ) {
manager.AddSeparator();
} }
else else
wxASSERT( false ); wxASSERT( false );
@@ -394,8 +397,11 @@ struct MenuItemVisitor : MenuVisitor
flags.pop_back(); flags.pop_back();
} }
else else
if (const auto pGroup = dynamic_cast<GroupItem*>( pItem )) { if ( pItem->Transparent() ) {
wxASSERT( pGroup->Transparent() ); }
else
if ( const auto pGroup = dynamic_cast<MenuSection*>( pItem ) ) {
manager.AddSeparator();
} }
else else
wxASSERT( false ); wxASSERT( false );

View File

@@ -755,6 +755,7 @@ namespace MenuTable {
{} {}
}; };
using MenuItems = MenuPart< true >; using MenuItems = MenuPart< true >;
using MenuSection = MenuPart< false >;
// Following are the functions to use directly in writing table definitions. // Following are the functions to use directly in writing table definitions.

View File

@@ -387,28 +387,59 @@ void OnMenuTree(const CommandContext &context)
enum : unsigned { TAB = 3 }; enum : unsigned { TAB = 3 };
void BeginGroup( GroupItem &item, const Path& ) override void BeginGroup( GroupItem &item, const Path& ) override
{ {
Indent(); auto pItem = &item;
// using GET for alpha only diagnostic tool if ( pItem->Transparent() ) {
info += item.name.GET(); }
Return(); else if ( const auto pGroup = dynamic_cast<MenuSection*>( pItem ) ) {
indentation = wxString{ ' ', TAB * ++level }; if ( !needSeparator.empty() )
needSeparator.back() = true;
}
else {
Indent();
// using GET for alpha only diagnostic tool
info += item.name.GET();
Return();
indentation = wxString{ ' ', TAB * ++level };
needSeparator.push_back( false );
}
} }
void EndGroup( GroupItem &, const Path& ) override void EndGroup( GroupItem &item, const Path& ) override
{ {
indentation = wxString{ ' ', TAB * --level }; auto pItem = &item;
if ( pItem->Transparent() ) {
}
else if ( const auto pGroup = dynamic_cast<MenuSection*>( pItem ) ) {
if ( !needSeparator.empty() )
needSeparator.back() = true;
}
else {
needSeparator.pop_back();
indentation = wxString{ ' ', TAB * --level };
}
} }
void Visit( SingleItem &item, const Path& ) override void Visit( SingleItem &item, const Path& ) override
{ {
static const wxString separatorName{ '=', 20 }; static const wxString separatorName{ '=', 20 };
Indent(); bool separate = false;
info += dynamic_cast<SeparatorItem*>(&item) if ( !needSeparator.empty() ) {
? separatorName separate = needSeparator.back();
// using GET for alpha only diagnostic tool needSeparator.back() = false;
: item.name.GET(); }
Return();
if ( separate || dynamic_cast<SeparatorItem*>(&item) ) {
Indent();
info += separatorName;
Return();
}
if ( !dynamic_cast<SeparatorItem*>(&item) ) {
// using GET for alpha only diagnostic tool
Indent();
info += item.name.GET();
Return();
}
} }
void Indent() { info += indentation; } void Indent() { info += indentation; }
@@ -417,6 +448,8 @@ void OnMenuTree(const CommandContext &context)
unsigned level{}; unsigned level{};
wxString indentation; wxString indentation;
wxString info; wxString info;
std::vector<bool> needSeparator;
} visitor{ project }; } visitor{ project };
MenuManager::Visit( visitor ); MenuManager::Visit( visitor );