1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-01 16:19:43 +02: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);
}
else
if (const auto pGroup = dynamic_cast<GroupItem*>( pItem )) {
wxASSERT( pGroup->Transparent() );
if ( pItem->Transparent() ) {
}
else
if ( const auto pGroup = dynamic_cast<MenuSection*>( pItem ) ) {
manager.AddSeparator();
}
else
wxASSERT( false );
@ -394,8 +397,11 @@ struct MenuItemVisitor : MenuVisitor
flags.pop_back();
}
else
if (const auto pGroup = dynamic_cast<GroupItem*>( pItem )) {
wxASSERT( pGroup->Transparent() );
if ( pItem->Transparent() ) {
}
else
if ( const auto pGroup = dynamic_cast<MenuSection*>( pItem ) ) {
manager.AddSeparator();
}
else
wxASSERT( false );

View File

@ -755,6 +755,7 @@ namespace MenuTable {
{}
};
using MenuItems = MenuPart< true >;
using MenuSection = MenuPart< false >;
// 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 };
void BeginGroup( GroupItem &item, const Path& ) override
{
Indent();
// using GET for alpha only diagnostic tool
info += item.name.GET();
Return();
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 {
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
{
static const wxString separatorName{ '=', 20 };
Indent();
info += dynamic_cast<SeparatorItem*>(&item)
? separatorName
// using GET for alpha only diagnostic tool
: item.name.GET();
Return();
bool separate = false;
if ( !needSeparator.empty() ) {
separate = needSeparator.back();
needSeparator.back() = false;
}
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; }
@ -417,6 +448,8 @@ void OnMenuTree(const CommandContext &context)
unsigned level{};
wxString indentation;
wxString info;
std::vector<bool> needSeparator;
} visitor{ project };
MenuManager::Visit( visitor );