mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Conditions - Moved non-list conditions to new paths API
Conditions - Move list conditions to new paths API (WIP)
This commit is contained in:
1 parent
9417332a07
commit
725bb2a128
16 files changed
+168
-273
No files matched your search
+4
-4
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using Artemis.Core.DataModelExpansions;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Shared.Services;
|
||||
|
||||
namespace Artemis.UI.Shared
|
||||
@@ -10,9 +10,9 @@ namespace Artemis.UI.Shared
|
||||
private int _index;
|
||||
private Type _listType;
|
||||
|
||||
public DataModelListPropertiesViewModel(DataModel dataModel, object listItem) : base(null, null, null)
|
||||
public DataModelListPropertiesViewModel(object listItem) : base(null, null, null)
|
||||
{
|
||||
DataModel = dataModel;
|
||||
DataModel = ListPredicateWrapperDataModel.Create(listItem.GetType());
|
||||
ListType = listItem.GetType();
|
||||
DisplayValue = listItem;
|
||||
}
|
||||
@@ -44,7 +44,7 @@ namespace Artemis.UI.Shared
|
||||
return;
|
||||
|
||||
ListType = DisplayValue.GetType();
|
||||
PopulateProperties(dataModelUIService, DisplayValue);
|
||||
PopulateProperties(dataModelUIService);
|
||||
foreach (DataModelVisualizationViewModel dataModelVisualizationViewModel in Children)
|
||||
dataModelVisualizationViewModel.Update(dataModelUIService);
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using Artemis.Core.DataModelExpansions;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Shared.Services;
|
||||
|
||||
namespace Artemis.UI.Shared
|
||||
@@ -9,17 +9,17 @@ namespace Artemis.UI.Shared
|
||||
private int _index;
|
||||
private Type _listType;
|
||||
|
||||
public DataModelListPropertyViewModel(DataModel dataModel, object listItem, DataModelDisplayViewModel displayViewModel) : base(null, null, null)
|
||||
public DataModelListPropertyViewModel(object listItem, DataModelDisplayViewModel displayViewModel) : base(null, null, null)
|
||||
{
|
||||
DataModel = dataModel;
|
||||
DataModel = ListPredicateWrapperDataModel.Create(listItem.GetType());
|
||||
ListType = listItem.GetType();
|
||||
DisplayValue = listItem;
|
||||
DisplayViewModel = displayViewModel;
|
||||
}
|
||||
|
||||
public DataModelListPropertyViewModel(DataModel dataModel, object listItem) : base(null, null, null)
|
||||
public DataModelListPropertyViewModel(object listItem) : base(null, null, null)
|
||||
{
|
||||
DataModel = dataModel;
|
||||
DataModel = ListPredicateWrapperDataModel.Create(listItem.GetType());
|
||||
ListType = listItem.GetType();
|
||||
DisplayValue = listItem;
|
||||
}
|
||||
|
||||
@@ -11,8 +11,7 @@ namespace Artemis.UI.Shared
|
||||
{
|
||||
private string _count;
|
||||
private IList _list;
|
||||
private DataModelVisualizationViewModel _listTypePropertyViewModel;
|
||||
|
||||
|
||||
internal DataModelListViewModel(DataModel dataModel, DataModelVisualizationViewModel parent, DataModelPath dataModelPath) : base(dataModel, parent, dataModelPath)
|
||||
{
|
||||
ListChildren = new BindableCollection<DataModelVisualizationViewModel>();
|
||||
@@ -44,8 +43,6 @@ namespace Artemis.UI.Shared
|
||||
// Put an empty value into the list type property view model
|
||||
if (viewModel is DataModelListPropertiesViewModel dataModelListClassViewModel)
|
||||
{
|
||||
dataModelListClassViewModel.DisplayValue = Activator.CreateInstance(dataModelListClassViewModel.ListType);
|
||||
dataModelListClassViewModel.Update(dataModelUIService);
|
||||
return dataModelListClassViewModel;
|
||||
}
|
||||
|
||||
@@ -109,13 +106,13 @@ namespace Artemis.UI.Shared
|
||||
// If a display VM was found, prefer to use that in any case
|
||||
DataModelDisplayViewModel typeViewModel = dataModelUIService.GetDataModelDisplayViewModel(listType);
|
||||
if (typeViewModel != null)
|
||||
return new DataModelListPropertyViewModel(DataModel, listItem, typeViewModel);
|
||||
return new DataModelListPropertyViewModel(listItem, typeViewModel);
|
||||
// For primitives, create a property view model, it may be null that is fine
|
||||
if (listType.IsPrimitive || listType.IsEnum || listType == typeof(string))
|
||||
return new DataModelListPropertyViewModel(DataModel, listItem);
|
||||
return new DataModelListPropertyViewModel(listItem);
|
||||
// For other value types create a child view model
|
||||
if (listType.IsClass || listType.IsStruct())
|
||||
return new DataModelListPropertiesViewModel(DataModel, listItem);
|
||||
return new DataModelListPropertiesViewModel(listItem);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Artemis.UI.Shared
|
||||
public override void Update(IDataModelUIService dataModelUIService)
|
||||
{
|
||||
// Always populate properties
|
||||
PopulateProperties(dataModelUIService, null);
|
||||
PopulateProperties(dataModelUIService);
|
||||
|
||||
// Only update children if the parent is expanded
|
||||
if (Parent != null && !Parent.IsVisualizationExpanded && !Parent.IsRootViewModel)
|
||||
|
||||
+10
-24
@@ -125,7 +125,7 @@ namespace Artemis.UI.Shared
|
||||
}
|
||||
|
||||
// If the type couldn't be retrieved either way, assume false
|
||||
Type type = DataModelPath.GetPropertyType();
|
||||
Type type = DataModelPath?.GetPropertyType();
|
||||
if (type == null)
|
||||
{
|
||||
IsMatchingFilteredTypes = false;
|
||||
@@ -178,18 +178,12 @@ namespace Artemis.UI.Shared
|
||||
return 0;
|
||||
}
|
||||
|
||||
internal void PopulateProperties(IDataModelUIService dataModelUIService, object overrideValue)
|
||||
internal void PopulateProperties(IDataModelUIService dataModelUIService)
|
||||
{
|
||||
if (IsRootViewModel && overrideValue == null)
|
||||
if (IsRootViewModel)
|
||||
return;
|
||||
|
||||
Type modelType;
|
||||
if (overrideValue != null)
|
||||
modelType = overrideValue.GetType();
|
||||
else if (Parent.IsRootViewModel)
|
||||
modelType = DataModel.GetType();
|
||||
else
|
||||
modelType = DataModelPath.GetPropertyType();
|
||||
Type modelType = Parent.IsRootViewModel ? DataModel.GetType() : DataModelPath.GetPropertyType();
|
||||
|
||||
// Add missing static children
|
||||
foreach (PropertyInfo propertyInfo in modelType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
|
||||
@@ -200,17 +194,13 @@ namespace Artemis.UI.Shared
|
||||
if (propertyInfo.GetCustomAttribute<DataModelIgnoreAttribute>() != null)
|
||||
continue;
|
||||
|
||||
DataModelVisualizationViewModel child = CreateChild(dataModelUIService, childPath, GetChildDepth(), overrideValue);
|
||||
DataModelVisualizationViewModel child = CreateChild(dataModelUIService, childPath, GetChildDepth());
|
||||
if (child != null)
|
||||
Children.Add(child);
|
||||
}
|
||||
|
||||
// Remove static children that should be hidden
|
||||
ReadOnlyCollection<PropertyInfo> hiddenProperties;
|
||||
if (overrideValue != null && overrideValue is DataModel overrideValueDataModel)
|
||||
hiddenProperties = overrideValueDataModel.GetHiddenProperties();
|
||||
else
|
||||
hiddenProperties = DataModel.GetHiddenProperties();
|
||||
ReadOnlyCollection<PropertyInfo> hiddenProperties = DataModel.GetHiddenProperties();
|
||||
foreach (PropertyInfo hiddenProperty in hiddenProperties)
|
||||
{
|
||||
string childPath = AppendToPath(hiddenProperty.Name);
|
||||
@@ -220,11 +210,7 @@ namespace Artemis.UI.Shared
|
||||
}
|
||||
|
||||
// Add missing dynamic children
|
||||
object value;
|
||||
if (overrideValue != null)
|
||||
value = overrideValue;
|
||||
else
|
||||
value = Parent.IsRootViewModel ? DataModel : DataModelPath.GetValue();
|
||||
object value = Parent.IsRootViewModel ? DataModel : DataModelPath.GetValue();
|
||||
if (value is DataModel dataModel)
|
||||
{
|
||||
foreach (KeyValuePair<string, DataModel> kvp in dataModel.DynamicDataModels)
|
||||
@@ -233,7 +219,7 @@ namespace Artemis.UI.Shared
|
||||
if (Children.Any(c => c.Path != null && c.Path.Equals(childPath)))
|
||||
continue;
|
||||
|
||||
DataModelVisualizationViewModel child = CreateChild(dataModelUIService, childPath, GetChildDepth(), overrideValue);
|
||||
DataModelVisualizationViewModel child = CreateChild(dataModelUIService, childPath, GetChildDepth());
|
||||
if (child != null)
|
||||
Children.Add(child);
|
||||
}
|
||||
@@ -245,12 +231,12 @@ namespace Artemis.UI.Shared
|
||||
Children.RemoveRange(toRemoveDynamic);
|
||||
}
|
||||
|
||||
private DataModelVisualizationViewModel CreateChild(IDataModelUIService dataModelUIService, string path, int depth, object overrideValue)
|
||||
private DataModelVisualizationViewModel CreateChild(IDataModelUIService dataModelUIService, string path, int depth)
|
||||
{
|
||||
if (depth > MaxDepth)
|
||||
return null;
|
||||
|
||||
DataModelPath dataModelPath = new DataModelPath(overrideValue ?? DataModel, path);
|
||||
DataModelPath dataModelPath = new DataModelPath(DataModel, path);
|
||||
if (!dataModelPath.IsValid)
|
||||
return null;
|
||||
|
||||
|
||||
Reference in new issue
Block a user