mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Data model visualization - Simplified and improved VMs
Layer conditions - Added left side property selection
This commit is contained in:
parent
55555ed6a8
commit
4e1a09308f
@ -0,0 +1,36 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions.Abstract
|
||||
{
|
||||
public abstract class DisplayConditionPart
|
||||
{
|
||||
private readonly List<DisplayConditionPart> _children;
|
||||
|
||||
protected DisplayConditionPart()
|
||||
{
|
||||
_children = new List<DisplayConditionPart>();
|
||||
}
|
||||
|
||||
public DisplayConditionPart Parent { get; set; }
|
||||
public IReadOnlyList<DisplayConditionPart> Children => _children.AsReadOnly();
|
||||
|
||||
public void AddChild(DisplayConditionPart displayConditionPart)
|
||||
{
|
||||
if (!_children.Contains(displayConditionPart))
|
||||
{
|
||||
displayConditionPart.Parent = this;
|
||||
_children.Add(displayConditionPart);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveChild(DisplayConditionPart displayConditionPart)
|
||||
{
|
||||
if (_children.Contains(displayConditionPart))
|
||||
{
|
||||
displayConditionPart.Parent = null;
|
||||
_children.Remove(displayConditionPart);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions.Abstract
|
||||
{
|
||||
public abstract class LayerConditionPart
|
||||
{
|
||||
protected LayerConditionPart()
|
||||
{
|
||||
Children = new List<LayerConditionPart>();
|
||||
}
|
||||
|
||||
public List<LayerConditionPart> Children { get; set; }
|
||||
}
|
||||
}
|
||||
@ -4,9 +4,9 @@ using Artemis.Core.Plugins.Abstract.DataModels;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions
|
||||
{
|
||||
public class LayerCondition
|
||||
public class DisplayCondition
|
||||
{
|
||||
public Expression<Func<DataModel, bool>> ExpressionTree { get; set; }
|
||||
public LayerConditionGroup RootGroup { get; set; }
|
||||
public DisplayConditionGroup RootGroup { get; set; }
|
||||
}
|
||||
}
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions
|
||||
{
|
||||
public class LayerConditionGroup : LayerConditionPart
|
||||
public class DisplayConditionGroup : DisplayConditionPart
|
||||
{
|
||||
public BooleanOperator BooleanOperator { get; set; }
|
||||
}
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions
|
||||
{
|
||||
public class LayerConditionListStatement : LayerConditionPart
|
||||
public class DisplayConditionListPredicate : DisplayConditionPart
|
||||
{
|
||||
public ListOperator ListOperator { get; set; }
|
||||
|
||||
@ -6,7 +6,7 @@ using Artemis.Core.Services.Interfaces;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions
|
||||
{
|
||||
public abstract class LayerConditionOperator
|
||||
public abstract class DisplayConditionOperator
|
||||
{
|
||||
private IDataModelService _dataModelService;
|
||||
private bool _registered;
|
||||
@ -3,12 +3,12 @@ using Artemis.Core.Models.Profile.Conditions.Abstract;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions
|
||||
{
|
||||
public class LayerConditionStatement : LayerConditionPart
|
||||
public class DisplayConditionPredicate : DisplayConditionPart
|
||||
{
|
||||
public Guid DataModelGuid { get; set; }
|
||||
public string PropertyPath { get; set; }
|
||||
|
||||
public LayerConditionOperator Operator { get; set; }
|
||||
public DisplayConditionOperator Operator { get; set; }
|
||||
public object Value { get; set; }
|
||||
}
|
||||
}
|
||||
@ -4,7 +4,7 @@ using System.Linq.Expressions;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions.Operators
|
||||
{
|
||||
public class GreaterThanConditionOperator : LayerConditionOperator
|
||||
public class GreaterThanConditionOperator : DisplayConditionOperator
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type>
|
||||
{
|
||||
|
||||
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Extensions;
|
||||
using Artemis.Core.Models.Profile.Conditions;
|
||||
using Artemis.Core.Models.Profile.LayerProperties;
|
||||
using Artemis.Core.Models.Profile.LayerProperties.Attributes;
|
||||
using Artemis.Core.Models.Profile.LayerShapes;
|
||||
@ -22,6 +23,7 @@ namespace Artemis.Core.Models.Profile
|
||||
/// </summary>
|
||||
public sealed class Layer : EffectProfileElement
|
||||
{
|
||||
private DisplayConditionGroup _displayConditionGroup;
|
||||
private LayerGeneralProperties _general;
|
||||
private SKBitmap _layerBitmap;
|
||||
private BaseLayerBrush _layerBrush;
|
||||
@ -115,6 +117,15 @@ namespace Artemis.Core.Models.Profile
|
||||
internal set => SetAndNotify(ref _layerBrush, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the root display condition group
|
||||
/// </summary>
|
||||
public DisplayConditionGroup DisplayConditionGroup
|
||||
{
|
||||
get => _displayConditionGroup;
|
||||
set => SetAndNotify(ref _displayConditionGroup, value);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[Layer] {nameof(Name)}: {Name}, {nameof(Order)}: {Order}";
|
||||
|
||||
@ -21,13 +21,13 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
private readonly List<DataModel> _dataModelExpansions;
|
||||
private readonly IPluginService _pluginService;
|
||||
private readonly List<LayerConditionOperator> _registeredConditionOperators;
|
||||
private readonly List<DisplayConditionOperator> _registeredConditionOperators;
|
||||
|
||||
internal DataModelService(IPluginService pluginService)
|
||||
{
|
||||
_pluginService = pluginService;
|
||||
_dataModelExpansions = new List<DataModel>();
|
||||
_registeredConditionOperators = new List<LayerConditionOperator>();
|
||||
_registeredConditionOperators = new List<DisplayConditionOperator>();
|
||||
|
||||
_pluginService.PluginEnabled += PluginServiceOnPluginEnabled;
|
||||
_pluginService.PluginDisabled += PluginServiceOnPluginDisabled;
|
||||
@ -81,40 +81,50 @@ namespace Artemis.Core.Services
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool GetPluginExtendsDataModel(Plugin plugin)
|
||||
{
|
||||
if (plugin is Module module)
|
||||
return module.InternalExpandsMainDataModel;
|
||||
if (plugin is BaseDataModelExpansion)
|
||||
return true;
|
||||
|
||||
public void RegisterConditionOperator(PluginInfo pluginInfo, LayerConditionOperator layerConditionOperator)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void RegisterConditionOperator(PluginInfo pluginInfo, DisplayConditionOperator displayConditionOperator)
|
||||
{
|
||||
if (pluginInfo == null)
|
||||
throw new ArgumentNullException(nameof(pluginInfo));
|
||||
if (layerConditionOperator == null)
|
||||
throw new ArgumentNullException(nameof(layerConditionOperator));
|
||||
if (displayConditionOperator == null)
|
||||
throw new ArgumentNullException(nameof(displayConditionOperator));
|
||||
|
||||
lock (_registeredConditionOperators)
|
||||
{
|
||||
if (_registeredConditionOperators.Contains(layerConditionOperator))
|
||||
if (_registeredConditionOperators.Contains(displayConditionOperator))
|
||||
return;
|
||||
|
||||
layerConditionOperator.Register(pluginInfo, this);
|
||||
_registeredConditionOperators.Add(layerConditionOperator);
|
||||
displayConditionOperator.Register(pluginInfo, this);
|
||||
_registeredConditionOperators.Add(displayConditionOperator);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveConditionOperator(LayerConditionOperator layerConditionOperator)
|
||||
public void RemoveConditionOperator(DisplayConditionOperator displayConditionOperator)
|
||||
{
|
||||
if (layerConditionOperator == null)
|
||||
throw new ArgumentNullException(nameof(layerConditionOperator));
|
||||
if (displayConditionOperator == null)
|
||||
throw new ArgumentNullException(nameof(displayConditionOperator));
|
||||
|
||||
lock (_registeredConditionOperators)
|
||||
{
|
||||
if (!_registeredConditionOperators.Contains(layerConditionOperator))
|
||||
if (!_registeredConditionOperators.Contains(displayConditionOperator))
|
||||
return;
|
||||
|
||||
layerConditionOperator.Unsubscribe();
|
||||
_registeredConditionOperators.Remove(layerConditionOperator);
|
||||
displayConditionOperator.Unsubscribe();
|
||||
_registeredConditionOperators.Remove(displayConditionOperator);
|
||||
}
|
||||
}
|
||||
|
||||
public List<LayerConditionOperator> GetCompatibleConditionOperators(Type type)
|
||||
public List<DisplayConditionOperator> GetCompatibleConditionOperators(Type type)
|
||||
{
|
||||
lock (_registeredConditionOperators)
|
||||
{
|
||||
|
||||
@ -29,17 +29,24 @@ namespace Artemis.Core.Services.Interfaces
|
||||
/// <param name="plugin">Should be a module with a data model or a data model expansion</param>
|
||||
DataModel GetPluginDataModel(Plugin plugin);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the given plugin expands the main data model
|
||||
/// </summary>
|
||||
/// <param name="plugin"></param>
|
||||
/// <returns></returns>
|
||||
bool GetPluginExtendsDataModel(Plugin plugin);
|
||||
|
||||
/// <summary>
|
||||
/// Registers a new condition operator for use in layer conditions
|
||||
/// </summary>
|
||||
/// <param name="pluginInfo">The PluginInfo of the plugin this condition operator belongs to</param>
|
||||
/// <param name="layerConditionOperator">The condition operator to register</param>
|
||||
void RegisterConditionOperator([NotNull] PluginInfo pluginInfo, [NotNull] LayerConditionOperator layerConditionOperator);
|
||||
/// <param name="displayConditionOperator">The condition operator to register</param>
|
||||
void RegisterConditionOperator([NotNull] PluginInfo pluginInfo, [NotNull] DisplayConditionOperator displayConditionOperator);
|
||||
|
||||
/// <summary>
|
||||
/// Removes a condition operator so it is no longer available for use in layer conditions
|
||||
/// </summary>
|
||||
/// <param name="layerConditionOperator">The layer condition operator to remove</param>
|
||||
void RemoveConditionOperator([NotNull] LayerConditionOperator layerConditionOperator);
|
||||
/// <param name="displayConditionOperator">The layer condition operator to remove</param>
|
||||
void RemoveConditionOperator([NotNull] DisplayConditionOperator displayConditionOperator);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels;
|
||||
using Artemis.UI.Shared.Services;
|
||||
|
||||
namespace Artemis.UI.Shared.DataModelVisualization.Shared
|
||||
{
|
||||
public class DataModelListPropertiesViewModel : DataModelPropertiesViewModel
|
||||
{
|
||||
private object _displayValue;
|
||||
private int _index;
|
||||
private Type _listType;
|
||||
|
||||
public DataModelListPropertiesViewModel(DataModel dataModel, DataModelVisualizationViewModel parent, PropertyInfo propertyInfo) : base(dataModel, parent, propertyInfo)
|
||||
{
|
||||
}
|
||||
|
||||
public int Index
|
||||
{
|
||||
get => _index;
|
||||
set => SetAndNotify(ref _index, value);
|
||||
}
|
||||
|
||||
public Type ListType
|
||||
{
|
||||
get => _listType;
|
||||
set => SetAndNotify(ref _listType, value);
|
||||
}
|
||||
|
||||
public object DisplayValue
|
||||
{
|
||||
get => _displayValue;
|
||||
set => SetAndNotify(ref _displayValue, value);
|
||||
}
|
||||
|
||||
public override void Update(IDataModelVisualizationService dataModelVisualizationService)
|
||||
{
|
||||
// Display value gets updated by parent, don't do anything if it is null
|
||||
if (DisplayValue == null)
|
||||
return;
|
||||
|
||||
ListType = DisplayValue.GetType();
|
||||
PopulateProperties(dataModelVisualizationService);
|
||||
foreach (var dataModelVisualizationViewModel in Children)
|
||||
dataModelVisualizationViewModel.Update(dataModelVisualizationService);
|
||||
}
|
||||
|
||||
public override object GetCurrentValue()
|
||||
{
|
||||
return DisplayValue;
|
||||
}
|
||||
|
||||
private void PopulateProperties(IDataModelVisualizationService dataModelVisualizationService)
|
||||
{
|
||||
if (Children.Any())
|
||||
return;
|
||||
|
||||
foreach (var propertyInfo in ListType.GetProperties())
|
||||
{
|
||||
var child = CreateChild(dataModelVisualizationService, propertyInfo);
|
||||
if (child != null)
|
||||
Children.Add(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels;
|
||||
using Artemis.UI.Shared.Services;
|
||||
|
||||
namespace Artemis.UI.Shared.DataModelVisualization.Shared
|
||||
{
|
||||
public class DataModelListPropertyViewModel : DataModelPropertyViewModel
|
||||
{
|
||||
private int _index;
|
||||
private Type _listType;
|
||||
|
||||
public DataModelListPropertyViewModel(DataModel dataModel, DataModelVisualizationViewModel parent, PropertyInfo propertyInfo) : base(dataModel, parent, propertyInfo)
|
||||
{
|
||||
}
|
||||
|
||||
public int Index
|
||||
{
|
||||
get => _index;
|
||||
set => SetAndNotify(ref _index, value);
|
||||
}
|
||||
|
||||
public Type ListType
|
||||
{
|
||||
get => _listType;
|
||||
set => SetAndNotify(ref _listType, value);
|
||||
}
|
||||
|
||||
public override object GetCurrentValue()
|
||||
{
|
||||
return DisplayValue;
|
||||
}
|
||||
|
||||
public override void Update(IDataModelVisualizationService dataModelVisualizationService)
|
||||
{
|
||||
// Display value gets updated by parent, don't do anything if it is null
|
||||
if (DisplayValue == null)
|
||||
return;
|
||||
|
||||
if (DisplayViewModel == null && dataModelVisualizationService.RegisteredDataModelDisplays.Any(d => d.SupportedType == DisplayValue.GetType()))
|
||||
dataModelVisualizationService.GetDataModelDisplayViewModel(DisplayValue.GetType());
|
||||
|
||||
ListType = DisplayValue.GetType();
|
||||
UpdateDisplayParameters();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,8 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Reflection;
|
||||
using Artemis.Core.Extensions;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Stylet;
|
||||
@ -10,25 +11,12 @@ namespace Artemis.UI.Shared.DataModelVisualization.Shared
|
||||
{
|
||||
public class DataModelListViewModel : DataModelVisualizationViewModel
|
||||
{
|
||||
private readonly IDataModelVisualizationService _dataModelVisualizationService;
|
||||
private BindableCollection<DataModelVisualizationViewModel> _children;
|
||||
private string _count;
|
||||
private IList _list;
|
||||
|
||||
internal DataModelListViewModel(PropertyInfo propertyInfo, DataModelPropertyAttribute propertyDescription, DataModelVisualizationViewModel parent,
|
||||
IDataModelVisualizationService dataModelVisualizationService)
|
||||
internal DataModelListViewModel(DataModel dataModel, DataModelVisualizationViewModel parent, PropertyInfo propertyInfo) : base(dataModel, parent, propertyInfo)
|
||||
{
|
||||
_dataModelVisualizationService = dataModelVisualizationService;
|
||||
PropertyInfo = propertyInfo;
|
||||
Parent = parent;
|
||||
PropertyDescription = propertyDescription;
|
||||
Children = new BindableCollection<DataModelVisualizationViewModel>();
|
||||
}
|
||||
|
||||
public BindableCollection<DataModelVisualizationViewModel> Children
|
||||
{
|
||||
get => _children;
|
||||
set => SetAndNotify(ref _children, value);
|
||||
ListChildren = new BindableCollection<DataModelVisualizationViewModel>();
|
||||
}
|
||||
|
||||
public IList List
|
||||
@ -37,43 +25,67 @@ namespace Artemis.UI.Shared.DataModelVisualization.Shared
|
||||
set => SetAndNotify(ref _list, value);
|
||||
}
|
||||
|
||||
public BindableCollection<DataModelVisualizationViewModel> ListChildren { get; set; }
|
||||
|
||||
public string Count
|
||||
{
|
||||
get => _count;
|
||||
set => SetAndNotify(ref _count, value);
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
public override void Update(IDataModelVisualizationService dataModelVisualizationService)
|
||||
{
|
||||
if (PropertyInfo != null && Parent?.Model != null && PropertyInfo.GetValue(Parent.Model) is IList listValue)
|
||||
{
|
||||
Model = new List<object>(listValue.Cast<object>());
|
||||
List = (IList) Model;
|
||||
}
|
||||
List = GetCurrentValue() as IList;
|
||||
if (List == null)
|
||||
return;
|
||||
|
||||
var index = 0;
|
||||
foreach (var item in List)
|
||||
{
|
||||
DataModelVisualizationViewModel child;
|
||||
if (Children.Count <= index)
|
||||
if (ListChildren.Count <= index)
|
||||
{
|
||||
child = CreateChild(_dataModelVisualizationService, item);
|
||||
Children.Add(child);
|
||||
child = CreateListChild(dataModelVisualizationService, item.GetType());
|
||||
ListChildren.Add(child);
|
||||
}
|
||||
else
|
||||
child = ListChildren[index];
|
||||
|
||||
if (child is DataModelListPropertiesViewModel dataModelListClassViewModel)
|
||||
{
|
||||
child = Children[index];
|
||||
child.Model = item;
|
||||
dataModelListClassViewModel.DisplayValue = item;
|
||||
dataModelListClassViewModel.Index = index;
|
||||
}
|
||||
else if (child is DataModelListPropertyViewModel dataModelListPropertyViewModel)
|
||||
{
|
||||
dataModelListPropertyViewModel.DisplayValue = item;
|
||||
dataModelListPropertyViewModel.Index = index;
|
||||
}
|
||||
|
||||
child.Update();
|
||||
child.Update(dataModelVisualizationService);
|
||||
index++;
|
||||
}
|
||||
|
||||
while (Children.Count > List.Count)
|
||||
Children.RemoveAt(Children.Count - 1);
|
||||
while (ListChildren.Count > List.Count)
|
||||
ListChildren.RemoveAt(ListChildren.Count - 1);
|
||||
|
||||
Count = $"{Children.Count} {(Children.Count == 1 ? "item" : "items")}";
|
||||
Count = $"{ListChildren.Count} {(ListChildren.Count == 1 ? "item" : "items")}";
|
||||
}
|
||||
|
||||
protected DataModelVisualizationViewModel CreateListChild(IDataModelVisualizationService dataModelVisualizationService, Type listType)
|
||||
{
|
||||
// If a display VM was found, prefer to use that in any case
|
||||
var typeViewModel = dataModelVisualizationService.GetDataModelDisplayViewModel(listType);
|
||||
if (typeViewModel != null)
|
||||
return new DataModelListPropertyViewModel(DataModel, this, PropertyInfo) {DisplayViewModel = typeViewModel};
|
||||
// For primitives, create a property view model, it may be null that is fine
|
||||
if (listType.IsPrimitive || listType == typeof(string))
|
||||
return new DataModelListPropertyViewModel(DataModel, this, PropertyInfo);
|
||||
// For other value types create a child view model
|
||||
if (listType.IsClass || listType.IsStruct())
|
||||
return new DataModelListPropertiesViewModel(DataModel, this, PropertyInfo);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels;
|
||||
using Artemis.UI.Shared.Services;
|
||||
|
||||
namespace Artemis.UI.Shared.DataModelVisualization.Shared
|
||||
{
|
||||
public class DataModelPropertiesViewModel : DataModelVisualizationViewModel
|
||||
{
|
||||
internal DataModelPropertiesViewModel(DataModel dataModel, DataModelVisualizationViewModel parent, PropertyInfo propertyInfo) : base(dataModel, parent, propertyInfo)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Update(IDataModelVisualizationService dataModelVisualizationService)
|
||||
{
|
||||
PopulateProperties(dataModelVisualizationService);
|
||||
foreach (var dataModelVisualizationViewModel in Children)
|
||||
dataModelVisualizationViewModel.Update(dataModelVisualizationService);
|
||||
}
|
||||
|
||||
public override object GetCurrentValue()
|
||||
{
|
||||
return Parent.IsRootViewModel ? DataModel : base.GetCurrentValue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void PopulateProperties(IDataModelVisualizationService dataModelVisualizationService)
|
||||
{
|
||||
if (Children.Any())
|
||||
return;
|
||||
|
||||
var modelType = Parent.IsRootViewModel ? DataModel.GetType() : PropertyInfo.PropertyType;
|
||||
foreach (var propertyInfo in modelType.GetProperties())
|
||||
{
|
||||
var child = CreateChild(dataModelVisualizationService, propertyInfo);
|
||||
if (child != null)
|
||||
Children.Add(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,20 +1,26 @@
|
||||
using System.Reflection;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels;
|
||||
using Artemis.UI.Shared.Services;
|
||||
|
||||
namespace Artemis.UI.Shared.DataModelVisualization.Shared
|
||||
{
|
||||
public class DataModelPropertyViewModel : DataModelVisualizationViewModel
|
||||
{
|
||||
private object _displayValue;
|
||||
private DataModelDisplayViewModel _displayViewModel;
|
||||
private bool _showNull;
|
||||
private bool _showToString;
|
||||
private bool _showViewModel;
|
||||
|
||||
internal DataModelPropertyViewModel(PropertyInfo propertyInfo, DataModelPropertyAttribute propertyDescription, DataModelVisualizationViewModel parent)
|
||||
internal DataModelPropertyViewModel(DataModel dataModel, DataModelVisualizationViewModel parent, PropertyInfo propertyInfo) : base(dataModel, parent, propertyInfo)
|
||||
{
|
||||
PropertyInfo = propertyInfo;
|
||||
Parent = parent;
|
||||
PropertyDescription = propertyDescription;
|
||||
}
|
||||
|
||||
public object DisplayValue
|
||||
{
|
||||
get => _displayValue;
|
||||
set => SetAndNotify(ref _displayValue, value);
|
||||
}
|
||||
|
||||
public DataModelDisplayViewModel DisplayViewModel
|
||||
@ -41,19 +47,22 @@ namespace Artemis.UI.Shared.DataModelVisualization.Shared
|
||||
set => SetAndNotify(ref _showViewModel, value);
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
public override void Update(IDataModelVisualizationService dataModelVisualizationService)
|
||||
{
|
||||
if (PropertyInfo != null && Parent?.Model != null)
|
||||
{
|
||||
Model = PropertyInfo.GetValue(Parent.Model);
|
||||
DisplayViewModel?.UpdateValue(Model);
|
||||
if (DisplayViewModel == null && dataModelVisualizationService.RegisteredDataModelDisplays.Any(d => d.SupportedType == PropertyInfo.PropertyType))
|
||||
dataModelVisualizationService.GetDataModelDisplayViewModel(PropertyInfo.PropertyType);
|
||||
|
||||
DisplayValue = GetCurrentValue();
|
||||
UpdateDisplayParameters();
|
||||
}
|
||||
|
||||
ShowToString = Model != null && DisplayViewModel == null;
|
||||
ShowNull = Model == null;
|
||||
ShowViewModel = Model != null && DisplayViewModel != null;
|
||||
protected void UpdateDisplayParameters()
|
||||
{
|
||||
ShowToString = DisplayValue != null && DisplayViewModel == null;
|
||||
ShowNull = DisplayValue == null;
|
||||
ShowViewModel = DisplayValue != null && DisplayViewModel != null;
|
||||
|
||||
UpdateListStatus();
|
||||
DisplayViewModel?.UpdateValue(DisplayValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,60 +0,0 @@
|
||||
using System.Reflection;
|
||||
using Artemis.Core.Extensions;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Shared.DataModelVisualization.Shared
|
||||
{
|
||||
public class DataModelViewModel : DataModelVisualizationViewModel
|
||||
{
|
||||
private readonly IDataModelVisualizationService _dataModelVisualizationService;
|
||||
private BindableCollection<DataModelVisualizationViewModel> _children;
|
||||
|
||||
internal DataModelViewModel()
|
||||
{
|
||||
Children = new BindableCollection<DataModelVisualizationViewModel>();
|
||||
}
|
||||
|
||||
internal DataModelViewModel(PropertyInfo propertyInfo, object model, DataModelPropertyAttribute propertyDescription, DataModelVisualizationViewModel parent,
|
||||
IDataModelVisualizationService dataModelVisualizationService)
|
||||
{
|
||||
_dataModelVisualizationService = dataModelVisualizationService;
|
||||
PropertyInfo = propertyInfo;
|
||||
Model = model;
|
||||
PropertyDescription = propertyDescription;
|
||||
Parent = parent;
|
||||
Children = new BindableCollection<DataModelVisualizationViewModel>();
|
||||
|
||||
PopulateProperties();
|
||||
}
|
||||
|
||||
public BindableCollection<DataModelVisualizationViewModel> Children
|
||||
{
|
||||
get => _children;
|
||||
set => SetAndNotify(ref _children, value);
|
||||
}
|
||||
|
||||
public void PopulateProperties()
|
||||
{
|
||||
Children.Clear();
|
||||
foreach (var propertyInfo in Model.GetType().GetProperties())
|
||||
{
|
||||
var child = CreateChild(_dataModelVisualizationService, propertyInfo);
|
||||
if (child != null)
|
||||
Children.Add(child);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
if (PropertyInfo != null && PropertyInfo.PropertyType.IsStruct())
|
||||
Model = PropertyInfo.GetValue(Parent.Model);
|
||||
|
||||
foreach (var dataModelVisualizationViewModel in Children)
|
||||
dataModelVisualizationViewModel.Update();
|
||||
|
||||
UpdateListStatus();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,11 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Artemis.Core.Extensions;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
|
||||
using Artemis.UI.Shared.Exceptions;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Humanizer;
|
||||
using Stylet;
|
||||
@ -11,22 +14,31 @@ namespace Artemis.UI.Shared.DataModelVisualization.Shared
|
||||
{
|
||||
public abstract class DataModelVisualizationViewModel : PropertyChangedBase
|
||||
{
|
||||
private bool _isListProperty;
|
||||
private string _listDescription;
|
||||
private object _model;
|
||||
private BindableCollection<DataModelVisualizationViewModel> _children;
|
||||
private DataModel _dataModel;
|
||||
private DataModelVisualizationViewModel _parent;
|
||||
private DataModelPropertyAttribute _propertyDescription;
|
||||
private PropertyInfo _propertyInfo;
|
||||
private Type _propertyType;
|
||||
|
||||
internal DataModelVisualizationViewModel()
|
||||
internal DataModelVisualizationViewModel(DataModel dataModel, DataModelVisualizationViewModel parent, PropertyInfo propertyInfo)
|
||||
{
|
||||
DataModel = dataModel;
|
||||
PropertyInfo = propertyInfo;
|
||||
Parent = parent;
|
||||
Children = new BindableCollection<DataModelVisualizationViewModel>();
|
||||
|
||||
if (dataModel == null && parent == null && propertyInfo == null)
|
||||
IsRootViewModel = true;
|
||||
else
|
||||
GetDescription();
|
||||
}
|
||||
|
||||
public DataModelPropertyAttribute PropertyDescription
|
||||
public bool IsRootViewModel { get; }
|
||||
|
||||
public DataModel DataModel
|
||||
{
|
||||
get => _propertyDescription;
|
||||
protected set => SetAndNotify(ref _propertyDescription, value);
|
||||
get => _dataModel;
|
||||
set => SetAndNotify(ref _dataModel, value);
|
||||
}
|
||||
|
||||
public PropertyInfo PropertyInfo
|
||||
@ -35,10 +47,10 @@ namespace Artemis.UI.Shared.DataModelVisualization.Shared
|
||||
protected set => SetAndNotify(ref _propertyInfo, value);
|
||||
}
|
||||
|
||||
public Type PropertyType
|
||||
public DataModelPropertyAttribute PropertyDescription
|
||||
{
|
||||
get => _propertyType;
|
||||
set => SetAndNotify(ref _propertyType, value);
|
||||
get => _propertyDescription;
|
||||
protected set => SetAndNotify(ref _propertyDescription, value);
|
||||
}
|
||||
|
||||
public DataModelVisualizationViewModel Parent
|
||||
@ -47,25 +59,53 @@ namespace Artemis.UI.Shared.DataModelVisualization.Shared
|
||||
protected set => SetAndNotify(ref _parent, value);
|
||||
}
|
||||
|
||||
public object Model
|
||||
public BindableCollection<DataModelVisualizationViewModel> Children
|
||||
{
|
||||
get => _model;
|
||||
set => SetAndNotify(ref _model, value);
|
||||
get => _children;
|
||||
set => SetAndNotify(ref _children, value);
|
||||
}
|
||||
|
||||
public bool IsListProperty
|
||||
public abstract void Update(IDataModelVisualizationService dataModelVisualizationService);
|
||||
|
||||
public virtual object GetCurrentValue()
|
||||
{
|
||||
get => _isListProperty;
|
||||
set => SetAndNotify(ref _isListProperty, value);
|
||||
return Parent == null ? null : PropertyInfo.GetValue(Parent.GetCurrentValue());
|
||||
}
|
||||
|
||||
public string ListDescription
|
||||
public DataModelVisualizationViewModel GetChildByPath(Guid dataModelGuid, string propertyPath)
|
||||
{
|
||||
get => _listDescription;
|
||||
set => SetAndNotify(ref _listDescription, value);
|
||||
var path = propertyPath.Split(".");
|
||||
var currentPart = path.First();
|
||||
|
||||
if (IsRootViewModel)
|
||||
{
|
||||
var child = Children.FirstOrDefault(c => c.DataModel.PluginInfo.Guid == dataModelGuid);
|
||||
return child?.GetChildByPath(dataModelGuid, propertyPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
var child = Children.FirstOrDefault(c => c.DataModel.PluginInfo.Guid == dataModelGuid && c.PropertyInfo?.Name == currentPart);
|
||||
if (child == null)
|
||||
return null;
|
||||
|
||||
if (path.Length > 1)
|
||||
return child.GetChildByPath(dataModelGuid, string.Join(".", path.Skip(1)));
|
||||
return child;
|
||||
}
|
||||
|
||||
public abstract void Update();
|
||||
}
|
||||
|
||||
public string GetCurrentPath()
|
||||
{
|
||||
if (Parent == null)
|
||||
return PropertyInfo?.Name;
|
||||
|
||||
if (PropertyInfo == null)
|
||||
return Parent.GetCurrentPath();
|
||||
|
||||
var parentPath = Parent.GetCurrentPath();
|
||||
return parentPath != null ? $"{parentPath}.{PropertyInfo.Name}" : PropertyInfo.Name;
|
||||
}
|
||||
|
||||
protected DataModelVisualizationViewModel CreateChild(IDataModelVisualizationService dataModelVisualizationService, PropertyInfo propertyInfo)
|
||||
{
|
||||
@ -73,64 +113,33 @@ namespace Artemis.UI.Shared.DataModelVisualization.Shared
|
||||
if (Attribute.IsDefined(propertyInfo, typeof(DataModelIgnoreAttribute)))
|
||||
return null;
|
||||
|
||||
var dataModelPropertyAttribute = (DataModelPropertyAttribute) Attribute.GetCustomAttribute(propertyInfo, typeof(DataModelPropertyAttribute));
|
||||
// If no DataModelProperty attribute was provided, pull one out of our ass
|
||||
if (dataModelPropertyAttribute == null)
|
||||
dataModelPropertyAttribute = new DataModelPropertyAttribute {Name = propertyInfo.Name.Humanize()};
|
||||
|
||||
// If a display VM was found, prefer to use that in any case
|
||||
var typeViewModel = dataModelVisualizationService.GetDataModelDisplayViewModel(propertyInfo.PropertyType);
|
||||
if (typeViewModel != null)
|
||||
return new DataModelPropertyViewModel(propertyInfo, dataModelPropertyAttribute, this) {DisplayViewModel = typeViewModel};
|
||||
return new DataModelPropertyViewModel(DataModel, this, propertyInfo) {DisplayViewModel = typeViewModel};
|
||||
// For primitives, create a property view model, it may be null that is fine
|
||||
if (propertyInfo.PropertyType.IsPrimitive || propertyInfo.PropertyType == typeof(string))
|
||||
return new DataModelPropertyViewModel(propertyInfo, dataModelPropertyAttribute, this);
|
||||
return new DataModelPropertyViewModel(DataModel, this, propertyInfo);
|
||||
if (typeof(IList).IsAssignableFrom(propertyInfo.PropertyType))
|
||||
return new DataModelListViewModel(propertyInfo, dataModelPropertyAttribute, this, dataModelVisualizationService);
|
||||
// For other value types create a child view model if the value type is not null
|
||||
return new DataModelListViewModel(DataModel, this, propertyInfo);
|
||||
// For other value types create a child view model
|
||||
if (propertyInfo.PropertyType.IsClass || propertyInfo.PropertyType.IsStruct())
|
||||
{
|
||||
var value = propertyInfo.GetValue(Model);
|
||||
if (value == null)
|
||||
return null;
|
||||
|
||||
return new DataModelViewModel(propertyInfo, value, dataModelPropertyAttribute, this, dataModelVisualizationService);
|
||||
}
|
||||
return new DataModelPropertiesViewModel(DataModel, this, propertyInfo);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected DataModelVisualizationViewModel CreateChild(IDataModelVisualizationService dataModelVisualizationService, object value)
|
||||
private void GetDescription()
|
||||
{
|
||||
var dataModelPropertyAttribute = new DataModelPropertyAttribute {Name = "Unknown property"};
|
||||
|
||||
// If a display VM was found, prefer to use that in any case
|
||||
var typeViewModel = dataModelVisualizationService.GetDataModelDisplayViewModel(value.GetType());
|
||||
if (typeViewModel != null)
|
||||
return new DataModelPropertyViewModel(null, dataModelPropertyAttribute, this) {Model = value, DisplayViewModel = typeViewModel};
|
||||
// For primitives, create a property view model, it may be null that is fine
|
||||
if (value.GetType().IsPrimitive || value is string)
|
||||
return new DataModelPropertyViewModel(null, dataModelPropertyAttribute, this) {Model = value};
|
||||
// For other value types create a child view model if the value type is not null
|
||||
if (value.GetType().IsClass || value.GetType().IsStruct())
|
||||
return new DataModelViewModel(null, value, dataModelPropertyAttribute, this, dataModelVisualizationService);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void UpdateListStatus()
|
||||
{
|
||||
if (Parent is DataModelListViewModel listViewModel)
|
||||
{
|
||||
IsListProperty = true;
|
||||
ListDescription = $"List item [{listViewModel.List.IndexOf(Model)}]";
|
||||
PropertyType = Model.GetType();
|
||||
}
|
||||
// If this is the first child of a root view model, use the data model description
|
||||
if (Parent.IsRootViewModel)
|
||||
PropertyDescription = DataModel?.DataModelDescription;
|
||||
// Rely on property info for the description
|
||||
else if (PropertyInfo != null)
|
||||
PropertyDescription = (DataModelPropertyAttribute) Attribute.GetCustomAttribute(PropertyInfo, typeof(DataModelPropertyAttribute)) ??
|
||||
new DataModelPropertyAttribute {Name = PropertyInfo.Name.Humanize()};
|
||||
else
|
||||
{
|
||||
IsListProperty = false;
|
||||
PropertyType = PropertyInfo?.PropertyType;
|
||||
}
|
||||
throw new ArtemisSharedUIException("Failed to get property description because plugin info is null but the parent has a datamodel");
|
||||
}
|
||||
}
|
||||
}
|
||||
19
src/Artemis.UI.Shared/Exceptions/ArtemisUIException.cs
Normal file
19
src/Artemis.UI.Shared/Exceptions/ArtemisUIException.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace Artemis.UI.Shared.Exceptions
|
||||
{
|
||||
public class ArtemisSharedUIException : Exception
|
||||
{
|
||||
internal ArtemisSharedUIException()
|
||||
{
|
||||
}
|
||||
|
||||
internal ArtemisSharedUIException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
internal ArtemisSharedUIException(string message, Exception inner) : base(message, inner)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -18,6 +18,8 @@ namespace Artemis.UI.Shared.Services
|
||||
private readonly IKernel _kernel;
|
||||
private readonly List<DataModelVisualizationRegistration> _registeredDataModelDisplays;
|
||||
private readonly List<DataModelVisualizationRegistration> _registeredDataModelEditors;
|
||||
private DataModelPropertiesViewModel _cachedMainDataModel;
|
||||
private Dictionary<Plugin, DataModelPropertiesViewModel> _cachedDataModels;
|
||||
|
||||
public DataModelVisualizationService(IDataModelService dataModelService, IKernel kernel)
|
||||
{
|
||||
@ -25,28 +27,66 @@ namespace Artemis.UI.Shared.Services
|
||||
_kernel = kernel;
|
||||
_registeredDataModelEditors = new List<DataModelVisualizationRegistration>();
|
||||
_registeredDataModelDisplays = new List<DataModelVisualizationRegistration>();
|
||||
_cachedDataModels = new Dictionary<Plugin, DataModelPropertiesViewModel>();
|
||||
}
|
||||
|
||||
public DataModelViewModel GetMainDataModelVisualization()
|
||||
public IReadOnlyCollection<DataModelVisualizationRegistration> RegisteredDataModelEditors => _registeredDataModelEditors.AsReadOnly();
|
||||
public IReadOnlyCollection<DataModelVisualizationRegistration> RegisteredDataModelDisplays => _registeredDataModelDisplays.AsReadOnly();
|
||||
|
||||
public DataModelPropertiesViewModel GetMainDataModelVisualization(bool useCache)
|
||||
{
|
||||
var viewModel = new DataModelViewModel();
|
||||
// Return from cache if found
|
||||
if (useCache && _cachedMainDataModel != null)
|
||||
return _cachedMainDataModel;
|
||||
|
||||
var viewModel = new DataModelPropertiesViewModel(null, null, null);
|
||||
foreach (var dataModelExpansion in _dataModelService.DataModelExpansions)
|
||||
viewModel.Children.Add(new DataModelViewModel(null, dataModelExpansion, dataModelExpansion.DataModelDescription, viewModel, this));
|
||||
viewModel.Children.Add(new DataModelPropertiesViewModel(dataModelExpansion, viewModel, null));
|
||||
|
||||
// Update to populate children
|
||||
viewModel.Update(this);
|
||||
|
||||
// Add to cache
|
||||
_cachedMainDataModel = viewModel;
|
||||
|
||||
return viewModel;
|
||||
}
|
||||
|
||||
public DataModelViewModel GetPluginDataModelVisualization(Plugin plugin)
|
||||
public DataModelPropertiesViewModel GetPluginDataModelVisualization(Plugin plugin, bool useCache)
|
||||
{
|
||||
// Return from cache if found
|
||||
var isCached = _cachedDataModels.TryGetValue(plugin, out var cachedMainDataModel);
|
||||
if (useCache && isCached)
|
||||
return cachedMainDataModel;
|
||||
|
||||
var dataModel = _dataModelService.GetPluginDataModel(plugin);
|
||||
if (dataModel == null)
|
||||
return null;
|
||||
|
||||
var viewModel = new DataModelViewModel();
|
||||
viewModel.Children.Add(new DataModelViewModel(null, dataModel, dataModel.DataModelDescription, viewModel, this));
|
||||
var viewModel = new DataModelPropertiesViewModel(null, null, null);
|
||||
viewModel.Children.Add(new DataModelPropertiesViewModel(dataModel, viewModel, null));
|
||||
|
||||
// Update to populate children
|
||||
viewModel.Update(this);
|
||||
|
||||
// Add to cache
|
||||
if (!isCached)
|
||||
_cachedDataModels.Add(plugin, viewModel);
|
||||
|
||||
return viewModel;
|
||||
}
|
||||
|
||||
public bool GetPluginExtendsDataModel(Plugin plugin)
|
||||
{
|
||||
return _dataModelService.GetPluginExtendsDataModel(plugin);
|
||||
}
|
||||
|
||||
public void BustCache()
|
||||
{
|
||||
_cachedMainDataModel = null;
|
||||
_cachedDataModels.Clear();
|
||||
}
|
||||
|
||||
public DataModelVisualizationRegistration RegisterDataModelInput<T>(PluginInfo pluginInfo) where T : DataModelInputViewModel
|
||||
{
|
||||
var viewModelType = typeof(T);
|
||||
@ -133,8 +173,17 @@ namespace Artemis.UI.Shared.Services
|
||||
|
||||
public interface IDataModelVisualizationService : IArtemisSharedUIService
|
||||
{
|
||||
DataModelViewModel GetMainDataModelVisualization();
|
||||
DataModelViewModel GetPluginDataModelVisualization(Plugin plugin);
|
||||
DataModelPropertiesViewModel GetMainDataModelVisualization(bool useCached);
|
||||
DataModelPropertiesViewModel GetPluginDataModelVisualization(Plugin plugin, bool useCached);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the given plugin expands the main data model
|
||||
/// </summary>
|
||||
/// <param name="plugin"></param>
|
||||
/// <returns></returns>
|
||||
bool GetPluginExtendsDataModel(Plugin plugin);
|
||||
|
||||
void BustCache();
|
||||
|
||||
DataModelVisualizationRegistration RegisterDataModelInput<T>(PluginInfo pluginInfo) where T : DataModelInputViewModel;
|
||||
DataModelVisualizationRegistration RegisterDataModelDisplay<T>(PluginInfo pluginInfo) where T : DataModelDisplayViewModel;
|
||||
@ -142,5 +191,7 @@ namespace Artemis.UI.Shared.Services
|
||||
void RemoveDataModelDisplay(DataModelVisualizationRegistration registration);
|
||||
|
||||
DataModelDisplayViewModel GetDataModelDisplayViewModel(Type propertyType);
|
||||
IReadOnlyCollection<DataModelVisualizationRegistration> RegisteredDataModelEditors { get; }
|
||||
IReadOnlyCollection<DataModelVisualizationRegistration> RegisteredDataModelDisplays { get; }
|
||||
}
|
||||
}
|
||||
@ -27,6 +27,7 @@ namespace Artemis.UI.Shared.Services.Interfaces
|
||||
void RedoUpdateProfile(ProfileModule module);
|
||||
void StopRegularRender();
|
||||
void ResumeRegularRender();
|
||||
Module GetCurrentModule();
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when a new profile is selected
|
||||
|
||||
@ -189,6 +189,11 @@ namespace Artemis.UI.Shared.Services
|
||||
}
|
||||
}
|
||||
|
||||
public Module GetCurrentModule()
|
||||
{
|
||||
return (Module) SelectedProfile?.PluginInfo.Instance;
|
||||
}
|
||||
|
||||
public event EventHandler<ProfileElementEventArgs> ProfileSelected;
|
||||
public event EventHandler<ProfileElementEventArgs> SelectedProfileUpdated;
|
||||
public event EventHandler<ProfileElementEventArgs> ProfileElementSelected;
|
||||
|
||||
@ -34,7 +34,7 @@ namespace Artemis.UI
|
||||
|
||||
protected override void Launch()
|
||||
{
|
||||
var test = new LayerCondition();
|
||||
var test = new DisplayCondition();
|
||||
|
||||
StartupArguments = Args.ToList();
|
||||
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Artemis.UI.Exceptions
|
||||
{
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public class ArtemisUIException : Exception
|
||||
{
|
||||
public ArtemisUIException()
|
||||
@ -1,9 +1,12 @@
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Profile.Conditions;
|
||||
using Artemis.Core.Models.Profile.LayerProperties.Attributes;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.UI.Screens.Module;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions.Abstract;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Abstract;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.LayerEffects;
|
||||
@ -71,6 +74,12 @@ namespace Artemis.UI.Ninject.Factories
|
||||
SelectionToolViewModel SelectionToolViewModel(ProfileViewModel profileViewModel);
|
||||
SelectionRemoveToolViewModel SelectionRemoveToolViewModel(ProfileViewModel profileViewModel);
|
||||
}
|
||||
public interface IDisplayConditionsVmFactory : IVmFactory
|
||||
{
|
||||
DisplayConditionGroupViewModel DisplayConditionGroupViewModel(DisplayConditionGroup displayConditionGroup, DisplayConditionViewModel parent);
|
||||
DisplayConditionListPredicateViewModel DisplayConditionListPredicateViewModel(DisplayConditionListPredicate displayConditionListPredicate, DisplayConditionViewModel parent);
|
||||
DisplayConditionPredicateViewModel DisplayConditionPredicateViewModel(DisplayConditionPredicate displayConditionPredicate, DisplayConditionViewModel parent);
|
||||
}
|
||||
|
||||
public interface ILayerPropertyVmFactory : IVmFactory
|
||||
{
|
||||
|
||||
@ -1,16 +1,28 @@
|
||||
using Stylet;
|
||||
using Artemis.Core.Models.Profile.Conditions;
|
||||
using Artemis.Core.Models.Profile.Conditions.Abstract;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions.Abstract
|
||||
{
|
||||
public abstract class DisplayConditionViewModel : PropertyChangedBase
|
||||
{
|
||||
protected DisplayConditionViewModel()
|
||||
protected DisplayConditionViewModel(DisplayConditionPart model, DisplayConditionViewModel parent)
|
||||
{
|
||||
Model = model;
|
||||
Parent = parent;
|
||||
Children = new BindableCollection<DisplayConditionViewModel>();
|
||||
}
|
||||
|
||||
public DisplayConditionPart Model { get; }
|
||||
public DisplayConditionViewModel Parent { get; set; }
|
||||
public BindableCollection<DisplayConditionViewModel> Children { get; }
|
||||
|
||||
public abstract void Update();
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
Model.Parent.RemoveChild(Model);
|
||||
Parent.Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -29,7 +29,8 @@
|
||||
Visibility="{Binding IsRootGroup, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}"
|
||||
Width="25"
|
||||
Height="25"
|
||||
Foreground="#E74C4C">
|
||||
Foreground="#E74C4C"
|
||||
Command="{s:Action Delete}">
|
||||
<materialDesign:PackIcon Kind="Close" Width="18" Height="18" />
|
||||
</Button>
|
||||
<Button Grid.Row="0"
|
||||
@ -37,25 +38,47 @@
|
||||
Style="{StaticResource DisplayConditionButtonLeftClickMenu}"
|
||||
Background="#E74C4C"
|
||||
BorderBrush="#E74C4C"
|
||||
Margin="3 1">
|
||||
Margin="3 1"
|
||||
Content="{Binding SelectedBooleanOperator}">
|
||||
<Button.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="And" />
|
||||
<MenuItem Header="Or" />
|
||||
<MenuItem Header="And not" />
|
||||
<MenuItem Header="Or not" />
|
||||
<MenuItem Header="And" Command="{s:Action SelectBooleanOperator}" CommandParameter="And"/>
|
||||
<MenuItem Header="Or" Command="{s:Action SelectBooleanOperator}" CommandParameter="Or"/>
|
||||
<MenuItem Header="And not" Command="{s:Action SelectBooleanOperator}" CommandParameter="AndNot"/>
|
||||
<MenuItem Header="Or not" Command="{s:Action SelectBooleanOperator}" CommandParameter="OrNot"/>
|
||||
</ContextMenu>
|
||||
</Button.ContextMenu>
|
||||
Or
|
||||
</Button>
|
||||
<Button Grid.Row="0"
|
||||
Grid.Column="2"
|
||||
Style="{StaticResource MaterialDesignIconForegroundButton}"
|
||||
HorizontalAlignment="Left"
|
||||
Foreground="#4CE758"
|
||||
Width="25"
|
||||
Height="25">
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialDesignIconForegroundButton}">
|
||||
<Style.Triggers>
|
||||
<EventTrigger RoutedEvent="Click">
|
||||
<EventTrigger.Actions>
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="ContextMenu.IsOpen">
|
||||
<DiscreteBooleanKeyFrame KeyTime="0:0:0" Value="True"/>
|
||||
</BooleanAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</EventTrigger.Actions>
|
||||
</EventTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
<materialDesign:PackIcon Kind="Add" Width="18" Height="18" />
|
||||
<Button.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="Add condition" Command="{s:Action AddCondition}" />
|
||||
<MenuItem Header="Add group" Command="{s:Action AddGroup}" />
|
||||
</ContextMenu>
|
||||
</Button.ContextMenu>
|
||||
</Button>
|
||||
|
||||
<ItemsControl Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" ItemsSource="{Binding Children}">
|
||||
|
||||
@ -1,24 +1,80 @@
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions.Abstract;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Models.Profile.Conditions;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions.Abstract;
|
||||
using Humanizer;
|
||||
|
||||
namespace Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions
|
||||
{
|
||||
public class DisplayConditionGroupViewModel : DisplayConditionViewModel
|
||||
{
|
||||
private readonly IDisplayConditionsVmFactory _displayConditionsVmFactory;
|
||||
private bool _isRootGroup;
|
||||
|
||||
public DisplayConditionGroupViewModel(DisplayConditionGroup displayConditionGroup, DisplayConditionViewModel parent, IDisplayConditionsVmFactory displayConditionsVmFactory) : base(displayConditionGroup, parent)
|
||||
{
|
||||
_displayConditionsVmFactory = displayConditionsVmFactory;
|
||||
}
|
||||
|
||||
public DisplayConditionGroup DisplayConditionGroup => (DisplayConditionGroup) Model;
|
||||
|
||||
public bool IsRootGroup
|
||||
{
|
||||
get => _isRootGroup;
|
||||
set => SetAndNotify(ref _isRootGroup, value);
|
||||
}
|
||||
|
||||
public DisplayConditionGroupViewModel()
|
||||
public string SelectedBooleanOperator => DisplayConditionGroup.BooleanOperator.Humanize();
|
||||
|
||||
public void SelectBooleanOperator(string type)
|
||||
{
|
||||
var enumValue = Enum.Parse<BooleanOperator>(type);
|
||||
DisplayConditionGroup.BooleanOperator = enumValue;
|
||||
NotifyOfPropertyChange(nameof(SelectedBooleanOperator));
|
||||
}
|
||||
|
||||
public void AddCondition()
|
||||
{
|
||||
DisplayConditionGroup.AddChild(new DisplayConditionPredicate());
|
||||
Update();
|
||||
}
|
||||
|
||||
public void AddGroup()
|
||||
{
|
||||
DisplayConditionGroup.AddChild(new DisplayConditionGroup());
|
||||
Update();
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
NotifyOfPropertyChange(nameof(SelectedBooleanOperator));
|
||||
|
||||
// Remove VMs of effects no longer applied on the layer
|
||||
var toRemove = Children.Where(c => !DisplayConditionGroup.Children.Contains(c.Model)).ToList();
|
||||
Children.RemoveRange(toRemove);
|
||||
|
||||
foreach (var childModel in Model.Children)
|
||||
{
|
||||
if (Children.Any(c => c.Model == childModel))
|
||||
continue;
|
||||
|
||||
switch (childModel)
|
||||
{
|
||||
case DisplayConditionGroup displayConditionGroup:
|
||||
Children.Add(_displayConditionsVmFactory.DisplayConditionGroupViewModel(displayConditionGroup, this));
|
||||
break;
|
||||
case DisplayConditionListPredicate displayConditionListPredicate:
|
||||
Children.Add(_displayConditionsVmFactory.DisplayConditionListPredicateViewModel(displayConditionListPredicate, this));
|
||||
break;
|
||||
case DisplayConditionPredicate displayConditionPredicate:
|
||||
Children.Add(_displayConditionsVmFactory.DisplayConditionPredicateViewModel(displayConditionPredicate, this));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var childViewModel in Children)
|
||||
childViewModel.Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions.DisplayConditionListPredicateView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance Type=local:DisplayConditionListPredicateViewModel, IsDesignTimeCreatable=False}">
|
||||
<Grid>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@ -0,0 +1,18 @@
|
||||
using Artemis.Core.Models.Profile.Conditions;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions.Abstract;
|
||||
|
||||
namespace Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions
|
||||
{
|
||||
public class DisplayConditionListPredicateViewModel : DisplayConditionViewModel
|
||||
{
|
||||
public DisplayConditionListPredicateViewModel(DisplayConditionListPredicate displayConditionListPredicate, DisplayConditionViewModel parent) : base(displayConditionListPredicate, parent)
|
||||
{
|
||||
}
|
||||
|
||||
public DisplayConditionListPredicate DisplayConditionListPredicate => (DisplayConditionListPredicate) Model;
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions.DisplayConditionPredicateView"
|
||||
<UserControl
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
@ -6,11 +6,23 @@
|
||||
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:converters="clr-namespace:Artemis.UI.Converters"
|
||||
xmlns:utilities="clr-namespace:Artemis.UI.Utilities"
|
||||
x:Class="Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions.DisplayConditionPredicateView"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance Type=local:DisplayConditionPredicateViewModel, IsDesignTimeCreatable=False}">
|
||||
d:DataContext="{d:DesignInstance IsDesignTimeCreatable=False, Type={x:Type local:DisplayConditionPredicateViewModel}}"
|
||||
x:Name="DisplayConditionPredicateRoot">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="pack://application:,,,/Artemis.UI;component/ResourceDictionaries/DisplayConditions.xaml" />
|
||||
<ResourceDictionary>
|
||||
<converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
|
||||
<utilities:BindingProxy x:Key="DataContextProxy" Data="{Binding}" />
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid Margin="0 2">
|
||||
<Grid.ColumnDefinitions>
|
||||
@ -25,60 +37,45 @@
|
||||
HorizontalAlignment="Left"
|
||||
Foreground="#E74C4C"
|
||||
Width="25"
|
||||
Height="25">
|
||||
Height="25"
|
||||
Command="{s:Action Delete}">
|
||||
<materialDesign:PackIcon Kind="Close" Width="18" Height="18" />
|
||||
</Button>
|
||||
<Button Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
Style="{StaticResource DisplayConditionButtonLeftClickMenu}"
|
||||
Background="{DynamicResource SecondaryAccentBrush}"
|
||||
BorderBrush="{DynamicResource SecondaryAccentBrush}">
|
||||
BorderBrush="{DynamicResource SecondaryAccentBrush}"
|
||||
Style="{StaticResource DisplayConditionButtonLeftClickMenu}">
|
||||
<Button.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="Equals">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="Equal" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Does not equal">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="NotEqualVariant" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Contains">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="Contain" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Starts with">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="ContainStart" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Ends with">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="ContainEnd" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Does not contain">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="FormatStrikethrough" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Is null">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="Null" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<ContextMenu ItemsSource="{Binding DataModel.Children}">
|
||||
<ContextMenu.ItemContainerStyle>
|
||||
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource MaterialDesignMenuItem}">
|
||||
<Setter Property="ItemsSource" Value="{Binding Children}" />
|
||||
<Setter Property="Header" Value="{Binding PropertyDescription.Name}" />
|
||||
<Setter Property="ToolTip" Value="{Binding PropertyDescription.Description}" />
|
||||
<Setter Property="Command" Value="{Binding Data.SelectPropertyCommand, Source={StaticResource DataContextProxy}}" />
|
||||
<Setter Property="CommandParameter" Value="{Binding}" />
|
||||
<Setter Property="CommandTarget" Value="{Binding}" />
|
||||
|
||||
</Style>
|
||||
</ContextMenu.ItemContainerStyle>
|
||||
</ContextMenu>
|
||||
</Button.ContextMenu>
|
||||
Category
|
||||
<Grid>
|
||||
<TextBlock Text="{Binding SelectedLeftSideProperty.PropertyDescription.Name}"
|
||||
ToolTip="{Binding SelectedLeftSideProperty.PropertyDescription.Description}"
|
||||
Visibility="{Binding SelectedLeftSideProperty, Converter={StaticResource NullToVisibilityConverter}}" />
|
||||
<TextBlock Text="« Select a property »"
|
||||
FontStyle="Italic"
|
||||
Visibility="{Binding SelectedLeftSideProperty, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}" />
|
||||
</Grid>
|
||||
</Button>
|
||||
|
||||
<Button Grid.Row="0"
|
||||
Grid.Column="2"
|
||||
Style="{StaticResource DisplayConditionButtonLeftClickMenu}"
|
||||
Background="#7B7B7B"
|
||||
BorderBrush="#7B7B7B">
|
||||
BorderBrush="#7B7B7B" Content="Equals">
|
||||
<Button.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="Equals">
|
||||
@ -118,14 +115,11 @@
|
||||
</MenuItem>
|
||||
</ContextMenu>
|
||||
</Button.ContextMenu>
|
||||
Equals
|
||||
</Button>
|
||||
<Button Grid.Row="0"
|
||||
Grid.Column="3"
|
||||
Style="{StaticResource DisplayConditionButton}"
|
||||
Background="{DynamicResource PrimaryHueMidBrush}"
|
||||
BorderBrush="{DynamicResource PrimaryHueMidBrush}">
|
||||
Video Players
|
||||
</Button>
|
||||
BorderBrush="{DynamicResource PrimaryHueMidBrush}" Content="PredicateRightSide" />
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@ -1,16 +1,86 @@
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions.Abstract;
|
||||
using Artemis.Core.Models.Profile.Conditions;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions.Abstract;
|
||||
using Artemis.UI.Shared.DataModelVisualization.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Artemis.UI.Shared.Services.Interfaces;
|
||||
using Artemis.UI.Utilities;
|
||||
|
||||
namespace Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions
|
||||
{
|
||||
public class DisplayConditionPredicateViewModel : DisplayConditionViewModel
|
||||
{
|
||||
public DisplayConditionPredicateViewModel()
|
||||
{
|
||||
private readonly IDataModelVisualizationService _dataModelVisualizationService;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private DataModelPropertiesViewModel _dataModel;
|
||||
private DataModelVisualizationViewModel _selectedLeftSideProperty;
|
||||
private bool _leftSidePropertySelectionOpen;
|
||||
|
||||
public DisplayConditionPredicateViewModel(DisplayConditionPredicate displayConditionPredicate, DisplayConditionViewModel parent,
|
||||
IProfileEditorService profileEditorService, IDataModelVisualizationService dataModelVisualizationService) : base(displayConditionPredicate, parent)
|
||||
{
|
||||
_profileEditorService = profileEditorService;
|
||||
_dataModelVisualizationService = dataModelVisualizationService;
|
||||
|
||||
SelectPropertyCommand = new DelegateCommand(ExecuteSelectProperty);
|
||||
|
||||
GetDataModel();
|
||||
}
|
||||
|
||||
public DelegateCommand SelectPropertyCommand { get; }
|
||||
|
||||
public DataModelPropertiesViewModel DataModel
|
||||
{
|
||||
get => _dataModel;
|
||||
set => SetAndNotify(ref _dataModel, value);
|
||||
}
|
||||
|
||||
public DataModelVisualizationViewModel SelectedLeftSideProperty
|
||||
{
|
||||
get => _selectedLeftSideProperty;
|
||||
set => SetAndNotify(ref _selectedLeftSideProperty, value);
|
||||
}
|
||||
|
||||
public bool LeftSidePropertySelectionOpen
|
||||
{
|
||||
get => _leftSidePropertySelectionOpen;
|
||||
set => SetAndNotify(ref _leftSidePropertySelectionOpen, value);
|
||||
}
|
||||
|
||||
|
||||
public DisplayConditionPredicate DisplayConditionPredicate => (DisplayConditionPredicate) Model;
|
||||
|
||||
public void ToggleLeftSidePropertySelectionOpen()
|
||||
{
|
||||
LeftSidePropertySelectionOpen = !LeftSidePropertySelectionOpen;
|
||||
}
|
||||
|
||||
public void GetDataModel()
|
||||
{
|
||||
var mainDataModel = _dataModelVisualizationService.GetMainDataModelVisualization(true);
|
||||
if (!_dataModelVisualizationService.GetPluginExtendsDataModel(_profileEditorService.GetCurrentModule()))
|
||||
mainDataModel.Children.Add(_dataModelVisualizationService.GetPluginDataModelVisualization(_profileEditorService.GetCurrentModule(), true));
|
||||
|
||||
DataModel = mainDataModel;
|
||||
|
||||
Update();
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
if (DisplayConditionPredicate.PropertyPath != null)
|
||||
SelectedLeftSideProperty = DataModel.GetChildByPath(DisplayConditionPredicate.DataModelGuid, DisplayConditionPredicate.PropertyPath);
|
||||
else
|
||||
SelectedLeftSideProperty = null;
|
||||
}
|
||||
|
||||
private void ExecuteSelectProperty(object context)
|
||||
{
|
||||
if (!(context is DataModelVisualizationViewModel vm))
|
||||
return;
|
||||
|
||||
DisplayConditionPredicate.PropertyPath = vm.GetCurrentPath();
|
||||
DisplayConditionPredicate.DataModelGuid = vm.DataModel.PluginInfo.Guid;
|
||||
Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,27 +1,49 @@
|
||||
using Stylet;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Profile.Conditions;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Shared.DataModelVisualization.Shared;
|
||||
using Artemis.UI.Shared.Events;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Artemis.UI.Shared.Services.Interfaces;
|
||||
|
||||
namespace Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions
|
||||
{
|
||||
public class DisplayConditionsViewModel : ProfileEditorPanelViewModel
|
||||
{
|
||||
private readonly IDisplayConditionsVmFactory _displayConditionsVmFactory;
|
||||
private readonly IDataModelVisualizationService _dataModelVisualizationService;
|
||||
private DisplayConditionGroupViewModel _rootGroup;
|
||||
|
||||
public DisplayConditionsViewModel(IProfileEditorService profileEditorService, IDataModelVisualizationService dataModelVisualizationService,
|
||||
IDisplayConditionsVmFactory displayConditionsVmFactory)
|
||||
{
|
||||
_dataModelVisualizationService = dataModelVisualizationService;
|
||||
_displayConditionsVmFactory = displayConditionsVmFactory;
|
||||
profileEditorService.ProfileElementSelected += ProfileEditorServiceOnProfileElementSelected;
|
||||
}
|
||||
|
||||
public DisplayConditionGroupViewModel RootGroup
|
||||
{
|
||||
get => _rootGroup;
|
||||
set => SetAndNotify(ref _rootGroup, value);
|
||||
}
|
||||
|
||||
public DisplayConditionsViewModel()
|
||||
private void ProfileEditorServiceOnProfileElementSelected(object sender, ProfileElementEventArgs e)
|
||||
{
|
||||
RootGroup = new DisplayConditionGroupViewModel {IsRootGroup = true};
|
||||
var subGroup = new DisplayConditionGroupViewModel();
|
||||
_dataModelVisualizationService.BustCache();
|
||||
|
||||
RootGroup.Children.Add(new DisplayConditionPredicateViewModel());
|
||||
RootGroup.Children.Add(new DisplayConditionPredicateViewModel());
|
||||
RootGroup.Children.Add(subGroup);
|
||||
subGroup.Children.Add(new DisplayConditionPredicateViewModel());
|
||||
subGroup.Children.Add(new DisplayConditionPredicateViewModel());
|
||||
if (e.ProfileElement is Layer layer)
|
||||
{
|
||||
// Ensure the layer has a root display condition group
|
||||
if (layer.DisplayConditionGroup == null)
|
||||
layer.DisplayConditionGroup = new DisplayConditionGroup();
|
||||
|
||||
RootGroup = _displayConditionsVmFactory.DisplayConditionGroupViewModel(layer.DisplayConditionGroup, null);
|
||||
RootGroup.IsRootGroup = true;
|
||||
}
|
||||
else
|
||||
RootGroup = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,15 +5,11 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Artemis.UI.Screens.Settings.Debug.Tabs"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:converters="clr-namespace:Artemis.UI.Converters"
|
||||
xmlns:wpf="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:plugins="clr-namespace:Artemis.Core.Plugins.Abstract;assembly=Artemis.Core"
|
||||
xmlns:dataModel="clr-namespace:Artemis.UI.Shared.DataModelVisualization.Shared;assembly=Artemis.UI.Shared"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance local:DataModelDebugViewModel}">
|
||||
<UserControl.Resources>
|
||||
<converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
@ -52,7 +48,7 @@
|
||||
<DataTemplate>
|
||||
<StackPanel d:DataContext="{d:DesignInstance Type=plugins:Module}" Orientation="Horizontal">
|
||||
<wpf:PackIcon Kind="{Binding DisplayIcon}" VerticalAlignment="Center" Margin="0 0 5 0" />
|
||||
<TextBlock Text="{Binding DisplayName}" VerticalAlignment="Center"></TextBlock>
|
||||
<TextBlock Text="{Binding DisplayName}" VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
@ -60,24 +56,10 @@
|
||||
</Grid>
|
||||
<TreeView Grid.Row="1" ItemsSource="{Binding MainDataModel.Children}" HorizontalContentAlignment="Stretch">
|
||||
<TreeView.Resources>
|
||||
<HierarchicalDataTemplate DataType="{x:Type dataModel:DataModelViewModel}" ItemsSource="{Binding Children}">
|
||||
<Grid>
|
||||
<TextBlock Text="{Binding PropertyDescription.Name}"
|
||||
ToolTip="{Binding PropertyDescription.Description}"
|
||||
Visibility="{Binding IsListProperty, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}" />
|
||||
<Grid Visibility="{Binding IsListProperty, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" Margin="0 0 5 0" FontWeight="Bold">
|
||||
<Run>[</Run><Run Text="{Binding PropertyType.Name, Mode=OneWay}" /><Run>]</Run>
|
||||
</TextBlock>
|
||||
<TextBlock Grid.Column="1" Text="{Binding ListDescription}" ToolTip="{Binding PropertyDescription.Description}" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
<HierarchicalDataTemplate DataType="{x:Type dataModel:DataModelPropertiesViewModel}" ItemsSource="{Binding Children}">
|
||||
<TextBlock Text="{Binding PropertyDescription.Name}" ToolTip="{Binding PropertyDescription.Description}" />
|
||||
</HierarchicalDataTemplate>
|
||||
<HierarchicalDataTemplate DataType="{x:Type dataModel:DataModelListViewModel}" ItemsSource="{Binding Children}">
|
||||
<HierarchicalDataTemplate DataType="{x:Type dataModel:DataModelListViewModel}" ItemsSource="{Binding ListChildren}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
@ -104,20 +86,13 @@
|
||||
|
||||
<!-- Value description -->
|
||||
<TextBlock Grid.Column="0" Margin="0 0 5 0" FontWeight="Bold">
|
||||
<Run>[</Run><Run Text="{Binding PropertyType.Name, Mode=OneWay}" /><Run>]</Run>
|
||||
<Run>[</Run><Run Text="{Binding PropertyInfo.PropertyType.Name, Mode=OneWay}" /><Run>]</Run>
|
||||
</TextBlock>
|
||||
<TextBlock Grid.Column="1"
|
||||
Text="{Binding PropertyDescription.Name}"
|
||||
ToolTip="{Binding PropertyDescription.Description}"
|
||||
Visibility="{Binding IsListProperty, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}" />
|
||||
<TextBlock Grid.Column="1"
|
||||
Text="{Binding ListDescription}"
|
||||
ToolTip="{Binding PropertyDescription.Description}"
|
||||
Visibility="{Binding IsListProperty, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}" />
|
||||
<TextBlock Grid.Column="1" Text="{Binding PropertyDescription.Name}" ToolTip="{Binding PropertyDescription.Description}" />
|
||||
|
||||
<!-- Value display -->
|
||||
<TextBlock Grid.Column="2"
|
||||
Text="{Binding Model, Mode=OneWay}"
|
||||
Text="{Binding DisplayValue, Mode=OneWay}"
|
||||
FontFamily="Consolas"
|
||||
HorizontalAlignment="Right"
|
||||
Visibility="{Binding ShowToString, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}" />
|
||||
@ -131,9 +106,47 @@
|
||||
s:View.Model="{Binding DisplayViewModel}"
|
||||
FontFamily="Consolas"
|
||||
Visibility="{Binding ShowViewModel, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}" />
|
||||
|
||||
</Grid>
|
||||
</HierarchicalDataTemplate>
|
||||
<HierarchicalDataTemplate DataType="{x:Type dataModel:DataModelListPropertyViewModel}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Value description -->
|
||||
<TextBlock Grid.Column="0" Margin="0 0 5 0" FontWeight="Bold">
|
||||
<Run>[</Run><Run Text="{Binding ListType.Name, Mode=OneWay}" /><Run>]</Run>
|
||||
</TextBlock>
|
||||
<TextBlock Grid.Column="1" ToolTip="{Binding PropertyDescription.Description}">
|
||||
<Run>List item [</Run><Run Text="{Binding Index, Mode=OneWay}" /><Run>]</Run>
|
||||
</TextBlock>
|
||||
|
||||
<!-- Value display -->
|
||||
<TextBlock Grid.Column="2"
|
||||
Text="{Binding DisplayValue, Mode=OneWay}"
|
||||
FontFamily="Consolas"
|
||||
HorizontalAlignment="Right"
|
||||
Visibility="{Binding ShowToString, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}" />
|
||||
<TextBlock Grid.Column="2"
|
||||
Text="null"
|
||||
FontFamily="Consolas"
|
||||
HorizontalAlignment="Right"
|
||||
Foreground="{DynamicResource MaterialDesignCheckBoxDisabled}"
|
||||
Visibility="{Binding ShowNull, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}" />
|
||||
<ContentControl Grid.Column="2"
|
||||
s:View.Model="{Binding DisplayViewModel}"
|
||||
FontFamily="Consolas"
|
||||
Visibility="{Binding ShowViewModel, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}" />
|
||||
</Grid>
|
||||
</HierarchicalDataTemplate>
|
||||
<HierarchicalDataTemplate DataType="{x:Type dataModel:DataModelListPropertiesViewModel}" ItemsSource="{Binding Children}">
|
||||
<TextBlock>
|
||||
<Run>List item [</Run><Run Text="{Binding Index, Mode=OneWay}" /><Run>]</Run>
|
||||
</TextBlock>
|
||||
</HierarchicalDataTemplate>
|
||||
</TreeView.Resources>
|
||||
</TreeView>
|
||||
</Grid>
|
||||
|
||||
@ -17,7 +17,7 @@ namespace Artemis.UI.Screens.Settings.Debug.Tabs
|
||||
private readonly Timer _updateTimer;
|
||||
private bool _isModuleFilterEnabled;
|
||||
private Core.Plugins.Abstract.Module _selectedModule;
|
||||
private DataModelViewModel _mainDataModel;
|
||||
private DataModelPropertiesViewModel _mainDataModel;
|
||||
private string _propertySearch;
|
||||
private List<Core.Plugins.Abstract.Module> _modules;
|
||||
|
||||
@ -26,12 +26,12 @@ namespace Artemis.UI.Screens.Settings.Debug.Tabs
|
||||
_dataModelVisualizationService = dataModelVisualizationService;
|
||||
_pluginService = pluginService;
|
||||
_updateTimer = new Timer(500);
|
||||
_updateTimer.Elapsed += (sender, args) => MainDataModel.Update();
|
||||
_updateTimer.Elapsed += (sender, args) => MainDataModel.Update(_dataModelVisualizationService);
|
||||
|
||||
DisplayName = "Data model";
|
||||
}
|
||||
|
||||
public DataModelViewModel MainDataModel
|
||||
public DataModelPropertiesViewModel MainDataModel
|
||||
{
|
||||
get => _mainDataModel;
|
||||
set => SetAndNotify(ref _mainDataModel, value);
|
||||
@ -93,8 +93,8 @@ namespace Artemis.UI.Screens.Settings.Debug.Tabs
|
||||
private void GetDataModel()
|
||||
{
|
||||
MainDataModel = SelectedModule != null
|
||||
? _dataModelVisualizationService.GetPluginDataModelVisualization(SelectedModule)
|
||||
: _dataModelVisualizationService.GetMainDataModelVisualization();
|
||||
? _dataModelVisualizationService.GetPluginDataModelVisualization(SelectedModule, false)
|
||||
: _dataModelVisualizationService.GetMainDataModelVisualization(false);
|
||||
}
|
||||
|
||||
private void PluginServiceOnPluginToggled(object? sender, PluginEventArgs e)
|
||||
|
||||
26
src/Artemis.UI/Utilities/BindingProxy.cs
Normal file
26
src/Artemis.UI/Utilities/BindingProxy.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace Artemis.UI.Utilities
|
||||
{
|
||||
public class BindingProxy : Freezable
|
||||
{
|
||||
// Using a DependencyProperty as the backing store for Data. This enables animation, styling, binding, etc...
|
||||
public static readonly DependencyProperty DataProperty =
|
||||
DependencyProperty.Register("Data", typeof(object), typeof(BindingProxy), new UIPropertyMetadata(null));
|
||||
|
||||
public object Data
|
||||
{
|
||||
get => GetValue(DataProperty);
|
||||
set => SetValue(DataProperty, value);
|
||||
}
|
||||
|
||||
#region Overrides of Freezable
|
||||
|
||||
protected override Freezable CreateInstanceCore()
|
||||
{
|
||||
return new BindingProxy();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
41
src/Artemis.UI/Utilities/DelegateCommand.cs
Normal file
41
src/Artemis.UI/Utilities/DelegateCommand.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Artemis.UI.Utilities
|
||||
{
|
||||
public class DelegateCommand : ICommand
|
||||
{
|
||||
private readonly Predicate<object> _canExecute;
|
||||
private readonly Action<object> _execute;
|
||||
|
||||
public DelegateCommand(Action<object> execute) : this(execute, null)
|
||||
{
|
||||
}
|
||||
|
||||
public DelegateCommand(Action<object> execute, Predicate<object> canExecute)
|
||||
{
|
||||
_execute = execute;
|
||||
_canExecute = canExecute;
|
||||
}
|
||||
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
public bool CanExecute(object parameter)
|
||||
{
|
||||
if (_canExecute == null)
|
||||
return true;
|
||||
|
||||
return _canExecute(parameter);
|
||||
}
|
||||
|
||||
public void Execute(object parameter)
|
||||
{
|
||||
_execute(parameter);
|
||||
}
|
||||
|
||||
public void RaiseCanExecuteChanged()
|
||||
{
|
||||
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user