Properties: add ability to override writeable attribute

This commit is contained in:
Mike Williams 2023-07-12 11:02:41 -04:00
parent 2e7db309bd
commit 500779fc80
3 changed files with 53 additions and 1 deletions

View File

@ -206,6 +206,18 @@ void PROPERTY_MANAGER::OverrideAvailability( TYPE_ID aDerived, TYPE_ID aBase,
}
void PROPERTY_MANAGER::OverrideWriteability( TYPE_ID aDerived, TYPE_ID aBase,
const wxString& aName,
std::function<bool( INSPECTABLE* )> aFunc )
{
wxASSERT_MSG( aDerived != aBase, "Class cannot override from itself" );
CLASS_DESC& derived = getClass( aDerived );
derived.m_writeabilityOverrides[std::make_pair( aBase, aName )] = aFunc;
m_dirty = true;
}
bool PROPERTY_MANAGER::IsAvailableFor( TYPE_ID aItemClass, PROPERTY_BASE* aProp,
INSPECTABLE* aItem )
{
@ -224,6 +236,24 @@ bool PROPERTY_MANAGER::IsAvailableFor( TYPE_ID aItemClass, PROPERTY_BASE* aProp,
}
bool PROPERTY_MANAGER::IsWriteableFor( TYPE_ID aItemClass, PROPERTY_BASE* aProp,
INSPECTABLE* aItem )
{
if( !aProp->Writeable( aItem ) )
return false;
CLASS_DESC& derived = getClass( aItemClass );
auto it = derived.m_writeabilityOverrides.find( std::make_pair( aProp->BaseHash(),
aProp->Name() ) );
if( it != derived.m_writeabilityOverrides.end() )
return it->second( aItem );
return true;
}
bool PROPERTY_MANAGER::IsOfType( TYPE_ID aDerived, TYPE_ID aBase ) const
{
if( aDerived == aBase )

View File

@ -361,7 +361,7 @@ bool PROPERTIES_PANEL::extractValueAndWritability( const SELECTION& aSelection,
return false;
// If read-only for any of the selection, read-only for the whole selection.
if( !aProperty->Writeable( item ) )
if( !propMgr.IsWriteableFor( TYPE_HASH( *item ), aProperty, item ) )
aWritable = false;
wxVariant value;

View File

@ -198,6 +198,17 @@ public:
void OverrideAvailability( TYPE_ID aDerived, TYPE_ID aBase, const wxString& aName,
std::function<bool( INSPECTABLE* )> aFunc );
/**
* Sets an override writeability functor for a base class property of a given derived class.
*
* @param aDerived is the type to apply the mask for.
* @param aBase is the type that aName belongs to.
* @param aName is the name of a property on the base class.
* @param aFunc is the new availability functor to apply.
*/
void OverrideWriteability( TYPE_ID aDerived, TYPE_ID aBase, const wxString& aName,
std::function<bool( INSPECTABLE* )> aFunc );
/**
* Checks overriden availability and original availability of a property, returns false
* if the property is unavailable in either case.
@ -206,6 +217,14 @@ public:
*/
bool IsAvailableFor( TYPE_ID aItemClass, PROPERTY_BASE* aProp, INSPECTABLE* aItem );
/**
* Checks overriden availability and original availability of a property, returns false
* if the property is unavailable in either case.
*
* TODO: This isn't the cleanest API, consider how to merge with PROPERTY_BASE::Writeable
*/
bool IsWriteableFor( TYPE_ID aItemClass, PROPERTY_BASE* aProp, INSPECTABLE* aItem );
/**
* Return true if aDerived is inherited from aBase.
*/
@ -283,6 +302,9 @@ private:
///< Overrides for base class property availabilities
PROPERTY_FUNCTOR_MAP m_availabilityOverrides;
///< Overrides for base class property writeable status
PROPERTY_FUNCTOR_MAP m_writeabilityOverrides;
///< All properties (both unique to the type and inherited)
std::vector<PROPERTY_BASE*> m_allProperties;