1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00
Artemis/src/Artemis.UI/DryIoc/InstanceProviders/LayerPropertyViewModelInstanceProvider.cs
Robert 3c8d8b2387 Plugins - Allow config window to be mandatory
UI - Move profile editor into Profile screen, profile page no longer always has to show the editor
2025-12-09 20:42:13 +01:00

50 lines
2.3 KiB
C#

using System;
using Artemis.Core;
using Artemis.UI.DryIoc.Factories;
using Artemis.UI.Exceptions;
using Artemis.UI.Screens.Profile.ProfileEditor.Properties.Timeline;
using Artemis.UI.Screens.Profile.ProfileEditor.Properties.Tree;
using Artemis.UI.Screens.ProfileEditor.Properties;
using Artemis.UI.Screens.ProfileEditor.Properties.Timeline;
using Artemis.UI.Screens.ProfileEditor.Properties.Tree;
using DryIoc;
using PropertyViewModel = Artemis.UI.Screens.Profile.ProfileEditor.Properties.PropertyViewModel;
namespace Artemis.UI.DryIoc.InstanceProviders;
public class PropertyVmFactory : IPropertyVmFactory
{
private readonly IContainer _container;
public PropertyVmFactory(IContainer container)
{
_container = container;
}
public ITimelinePropertyViewModel TimelinePropertyViewModel(ILayerProperty layerProperty, PropertyViewModel propertyViewModel)
{
// Find LayerProperty type
Type? layerPropertyType = layerProperty.GetType();
while (layerPropertyType != null && (!layerPropertyType.IsGenericType || layerPropertyType.GetGenericTypeDefinition() != typeof(LayerProperty<>)))
layerPropertyType = layerPropertyType.BaseType;
if (layerPropertyType == null)
throw new ArtemisUIException("Could not find the LayerProperty type");
Type? genericType = typeof(TimelinePropertyViewModel<>).MakeGenericType(layerPropertyType.GetGenericArguments());
return (ITimelinePropertyViewModel)_container.Resolve(genericType, new object[] { layerProperty, propertyViewModel });
}
public ITreePropertyViewModel TreePropertyViewModel(ILayerProperty layerProperty, PropertyViewModel propertyViewModel)
{
// Find LayerProperty type
Type? layerPropertyType = layerProperty.GetType();
while (layerPropertyType != null && (!layerPropertyType.IsGenericType || layerPropertyType.GetGenericTypeDefinition() != typeof(LayerProperty<>)))
layerPropertyType = layerPropertyType.BaseType;
if (layerPropertyType == null)
throw new ArtemisUIException("Could not find the LayerProperty type");
Type? genericType = typeof(TreePropertyViewModel<>).MakeGenericType(layerPropertyType.GetGenericArguments());
return (ITreePropertyViewModel)_container.Resolve(genericType, new object[] { layerProperty, propertyViewModel });
}
}