1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-02 16:49:41 +02:00

Demote convenience function that makes computed items to base class

This commit is contained in:
Paul Licameli 2020-02-15 14:03:38 -05:00
parent 4d7a9f00a1
commit 87382d51d8

View File

@ -141,6 +141,22 @@ public:
return mTop;
}
// Forms a computed item, which may be omitted when function returns null
// and thus can be a conditional item
template< typename Table >
static Registry::BaseItemPtr Computed(
const std::function< Registry::BaseItemPtr( Table& ) > &factory )
{
using namespace Registry;
return std::make_unique< ComputedItem >(
[factory]( Visitor &baseVisitor ){
auto &visitor = static_cast< PopupMenuVisitor& >( baseVisitor );
auto &table = static_cast< Table& >( visitor.mTable );
return factory( table );
}
);
}
private:
void RegisterItem(
const Registry::Placement &placement, Registry::BaseItemPtr pItem );
@ -197,16 +213,14 @@ public:
// Appends a computed item, which may be omitted when function returns null
// and thus can be a conditional item
using Factory = std::function< Registry::BaseItemPtr( Derived& ) >;
static Registry::BaseItemPtr Computed( const Factory &factory )
{
return Base::Computed( factory );
}
void Append( const Factory &factory )
{
using namespace Registry;
Append( std::make_unique< ComputedItem >(
[factory]( Visitor &baseVisitor ){
auto &visitor = static_cast< PopupMenuVisitor& >( baseVisitor );
auto &table = static_cast< Derived& >( visitor.mTable );
return factory( table );
}
) );
Append( Computed( factory ) );
}
};