mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Data model paths - Added events for validating/invalidating
List condition - Reinitialize when path validates/invalidates Conditions - Don't save with invalid paths Core - Fixed render exception on data model expansion deactivate
This commit is contained in:
parent
d46a610e23
commit
69ae42c039
@ -13,6 +13,7 @@ namespace Artemis.Core
|
|||||||
public class DataModelConditionList : DataModelConditionPart
|
public class DataModelConditionList : DataModelConditionPart
|
||||||
{
|
{
|
||||||
private bool _disposed;
|
private bool _disposed;
|
||||||
|
private bool _reinitializing;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new instance of the <see cref="DataModelConditionList" /> class
|
/// Creates a new instance of the <see cref="DataModelConditionList" /> class
|
||||||
@ -83,6 +84,7 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
ListPath?.Dispose();
|
ListPath?.Dispose();
|
||||||
ListPath = path != null ? new DataModelPath(path) : null;
|
ListPath = path != null ? new DataModelPath(path) : null;
|
||||||
|
SubscribeToListPath();
|
||||||
|
|
||||||
// Remove the old root group that was tied to the old data model
|
// Remove the old root group that was tied to the old data model
|
||||||
while (Children.Any())
|
while (Children.Any())
|
||||||
@ -143,6 +145,10 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
internal override void Save()
|
internal override void Save()
|
||||||
{
|
{
|
||||||
|
// Don't save an invalid state
|
||||||
|
if (ListPath != null && !ListPath.IsValid)
|
||||||
|
return;
|
||||||
|
|
||||||
// Target list
|
// Target list
|
||||||
ListPath?.Save();
|
ListPath?.Save();
|
||||||
Entity.ListPath = ListPath?.Entity;
|
Entity.ListPath = ListPath?.Entity;
|
||||||
@ -164,6 +170,9 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
internal void Initialize()
|
internal void Initialize()
|
||||||
{
|
{
|
||||||
|
while (Children.Any())
|
||||||
|
RemoveChild(Children[0]);
|
||||||
|
|
||||||
if (Entity.ListPath == null)
|
if (Entity.ListPath == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -175,6 +184,7 @@ namespace Artemis.Core
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
ListPath = listPath;
|
ListPath = listPath;
|
||||||
|
SubscribeToListPath();
|
||||||
if (ListPath.IsValid)
|
if (ListPath.IsValid)
|
||||||
{
|
{
|
||||||
ListType = listType.GetGenericArguments()[0];
|
ListType = listType.GetGenericArguments()[0];
|
||||||
@ -187,7 +197,7 @@ namespace Artemis.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
// There should only be one child and it should be a group
|
// There should only be one child and it should be a group
|
||||||
if (Entity.Children.SingleOrDefault() is DataModelConditionGroupEntity rootGroup)
|
if (Entity.Children.FirstOrDefault() is DataModelConditionGroupEntity rootGroup)
|
||||||
{
|
{
|
||||||
AddChild(new DataModelConditionGroup(this, rootGroup));
|
AddChild(new DataModelConditionGroup(this, rootGroup));
|
||||||
}
|
}
|
||||||
@ -197,6 +207,39 @@ namespace Artemis.Core
|
|||||||
AddChild(new DataModelConditionGroup(this));
|
AddChild(new DataModelConditionGroup(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SubscribeToListPath()
|
||||||
|
{
|
||||||
|
if (ListPath == null) return;
|
||||||
|
ListPath.PathValidated += ListPathOnPathValidated;
|
||||||
|
ListPath.PathInvalidated += ListPathOnPathInvalidated;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Event handlers
|
||||||
|
|
||||||
|
private void ListPathOnPathValidated(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_reinitializing)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_reinitializing = true;
|
||||||
|
ListPath?.Dispose();
|
||||||
|
Initialize();
|
||||||
|
_reinitializing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ListPathOnPathInvalidated(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_reinitializing)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_reinitializing = true;
|
||||||
|
ListPath?.Dispose();
|
||||||
|
Initialize();
|
||||||
|
_reinitializing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -205,6 +205,10 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
internal override void Save()
|
internal override void Save()
|
||||||
{
|
{
|
||||||
|
// Don't save an invalid state
|
||||||
|
if (LeftPath != null && !LeftPath.IsValid || RightPath != null && !RightPath.IsValid)
|
||||||
|
return;
|
||||||
|
|
||||||
Entity.PredicateType = (int) PredicateType;
|
Entity.PredicateType = (int) PredicateType;
|
||||||
|
|
||||||
LeftPath?.Save();
|
LeftPath?.Save();
|
||||||
|
|||||||
@ -14,9 +14,9 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class DataModelPath : IStorageModel, IDisposable
|
public class DataModelPath : IStorageModel, IDisposable
|
||||||
{
|
{
|
||||||
private bool _disposed;
|
|
||||||
private readonly LinkedList<DataModelPathSegment> _segments;
|
private readonly LinkedList<DataModelPathSegment> _segments;
|
||||||
private Expression<Func<object, object>>? _accessorLambda;
|
private Expression<Func<object, object>>? _accessorLambda;
|
||||||
|
private bool _disposed;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new instance of the <see cref="DataModelPath" /> class pointing directly to the target
|
/// Creates a new instance of the <see cref="DataModelPath" /> class pointing directly to the target
|
||||||
@ -188,6 +188,8 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
_accessorLambda = null;
|
_accessorLambda = null;
|
||||||
Accessor = null;
|
Accessor = null;
|
||||||
|
|
||||||
|
OnPathInvalidated();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Initialize()
|
internal void Initialize()
|
||||||
@ -239,6 +241,9 @@ namespace Artemis.Core
|
|||||||
),
|
),
|
||||||
parameter
|
parameter
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (IsValid)
|
||||||
|
OnPathValidated();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SubscribeToDataModelStore()
|
private void SubscribeToDataModelStore()
|
||||||
@ -307,5 +312,29 @@ namespace Artemis.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Events
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs whenever the path becomes invalid
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler PathInvalidated;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs whenever the path becomes valid
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler PathValidated;
|
||||||
|
|
||||||
|
protected virtual void OnPathValidated()
|
||||||
|
{
|
||||||
|
PathValidated?.Invoke(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnPathInvalidated()
|
||||||
|
{
|
||||||
|
PathInvalidated?.Invoke(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -166,8 +166,8 @@ namespace Artemis.Core.Services
|
|||||||
_frameStopWatch.Restart();
|
_frameStopWatch.Restart();
|
||||||
lock (_dataModelExpansions)
|
lock (_dataModelExpansions)
|
||||||
{
|
{
|
||||||
// Update all active modules
|
// Update all active modules, check Enabled status because it may go false before before the _dataModelExpansions list is updated
|
||||||
foreach (BaseDataModelExpansion dataModelExpansion in _dataModelExpansions)
|
foreach (BaseDataModelExpansion dataModelExpansion in _dataModelExpansions.Where(e => e.Enabled))
|
||||||
dataModelExpansion.Update(args.DeltaTime);
|
dataModelExpansion.Update(args.DeltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -146,7 +146,7 @@
|
|||||||
<materialDesign:PackIcon Kind="Add" Width="18" Height="18" />
|
<materialDesign:PackIcon Kind="Add" Width="18" Height="18" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<ItemsControl Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" ItemsSource="{Binding Items}">
|
<ItemsControl Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" ItemsSource="{Binding Items, IsAsync=True}">
|
||||||
<ItemsControl.ItemTemplate>
|
<ItemsControl.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<ContentControl s:View.Model="{Binding}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
|
<ContentControl s:View.Model="{Binding}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user