Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ namespace Stride.Assets.Presentation.NodePresenters.Keys
public static class EntityHierarchyData
{
public const string EntityComponentAvailableTypes = nameof(EntityComponentAvailableTypes);
public static readonly PropertyKey<IEnumerable<AbstractNodeType>> EntityComponentAvailableTypesKey = new PropertyKey<IEnumerable<AbstractNodeType>>(EntityComponentAvailableTypes, typeof(EntityHierarchyData), new PropertyCombinerMetadata(AbstractNodeEntryData.CombineProperty));

public static readonly PropertyKey<IEnumerable<AbstractNodeType>> EntityComponentAvailableTypesKey = new PropertyKey<IEnumerable<AbstractNodeType>>(EntityComponentAvailableTypes, typeof(EntityHierarchyData), new PropertyCombinerMetadata(AbstractNodeEntryData.CombineProperties<AbstractNodeType>));

public const string EntityComponentAvailableTypeGroups = nameof(EntityComponentAvailableTypeGroups);
public static readonly PropertyKey<IEnumerable<AbstractNodeTypeGroup>> EntityComponentAvailableTypeGroupsKey = new PropertyKey<IEnumerable<AbstractNodeTypeGroup>>(EntityComponentAvailableTypeGroups, typeof(EntityHierarchyData), new PropertyCombinerMetadata(AbstractNodeEntryData.CombineProperty));
public static readonly PropertyKey<IEnumerable<AbstractNodeTypeGroup>> EntityComponentAvailableTypeGroupsKey = new PropertyKey<IEnumerable<AbstractNodeTypeGroup>>(EntityComponentAvailableTypeGroups, typeof(EntityHierarchyData), new PropertyCombinerMetadata(AbstractNodeEntryData.CombineProperties<AbstractNodeTypeGroup>));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ namespace Stride.Core.Assets.Editor.Quantum.NodePresenters.Keys
public static class AbstractNodeEntryData
{
public const string AbstractNodeMatchingEntries = nameof(AbstractNodeMatchingEntries);
public static readonly PropertyKey<IEnumerable<AbstractNodeEntry>> Key = new PropertyKey<IEnumerable<AbstractNodeEntry>>(AbstractNodeMatchingEntries, typeof(AbstractNodeEntryData), new PropertyCombinerMetadata(CombineProperty));

public static readonly PropertyKey<IEnumerable<AbstractNodeEntry>> Key = new PropertyKey<IEnumerable<AbstractNodeEntry>>(AbstractNodeMatchingEntries, typeof(AbstractNodeEntryData), new PropertyCombinerMetadata(CombineProperties<AbstractNodeEntry>));

[Obsolete("Use the generic version of CombineProperties instead, which allows to specify the type of the properties to combine. This method is kept for backward compatibility, but it is recommended to use the generic version instead.")]
public static object CombineProperty(IEnumerable<object> properties)
{
Comment on lines +15 to 17
var result = new HashSet<AbstractNodeEntry>();
Expand All @@ -25,5 +26,29 @@ public static object CombineProperty(IEnumerable<object> properties)
}
return result.OrderBy(x => x.Order).ThenBy(x => x.DisplayValue);
}

/// <summary>
/// Combines the properties of type <typeparamref name="TAbstractNodeEntry"/> by intersecting them and ordering them by their order and display value.
/// This method allows to specify the type of the properties to combine, which can be useful when the properties are of a more specific type than <see cref="AbstractNodeEntry"/>.
/// E.g. WPF cannot coerce IEnumerable&lt;AbstractNodeEntry&gt; into IEnumerable&lt;AbstractNodeType&gt; since covariance only goes the other direction — you can widen to AbstractNodeEntry, not narrow back to AbstractNodeType.
/// In those cases, the binding would silently fall back to the DependencyProperty's default value: null.
/// </summary>
/// <param name="properties"></param>
/// <typeparam name="TAbstractNodeEntry"></typeparam>
/// <returns></returns>
Comment on lines +36 to +38
public static IEnumerable<TAbstractNodeEntry> CombineProperties<TAbstractNodeEntry>(IEnumerable<object> properties)
where TAbstractNodeEntry : AbstractNodeEntry
{
var result = new HashSet<TAbstractNodeEntry>();
var hashSets = new List<HashSet<TAbstractNodeEntry>>();
hashSets.AddRange(properties.Cast<IEnumerable<TAbstractNodeEntry>>().Select(x => new HashSet<TAbstractNodeEntry>(x)));
result = hashSets[0];
// We display only component types that are available for all entities
for (var i = 1; i < hashSets.Count; ++i)
{
result.IntersectWith(hashSets[i]);
}
return result.OrderBy(x => x.Order).ThenBy(x => x.DisplayValue);
}
}
}
Loading