mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-31 09:43:46 +00:00
UI - Fixed a few events that weren't being unsubscribed
This commit is contained in:
parent
6604f55f0e
commit
88ac5a3951
@ -27,6 +27,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
|||||||
private readonly IPropertyTimelineVmFactory _propertyTimelineVmFactory;
|
private readonly IPropertyTimelineVmFactory _propertyTimelineVmFactory;
|
||||||
private readonly IProfileEditorService _profileEditorService;
|
private readonly IProfileEditorService _profileEditorService;
|
||||||
private readonly ISettingsService _settingsService;
|
private readonly ISettingsService _settingsService;
|
||||||
|
private Layer _lastSelectedLayer;
|
||||||
|
|
||||||
public LayerPropertiesViewModel(IProfileEditorService profileEditorService,
|
public LayerPropertiesViewModel(IProfileEditorService profileEditorService,
|
||||||
ICoreService coreService,
|
ICoreService coreService,
|
||||||
@ -74,7 +75,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
|||||||
PropertyTree = _propertyTreeVmFactory.Create(this);
|
PropertyTree = _propertyTreeVmFactory.Create(this);
|
||||||
PropertyTimeline = _propertyTimelineVmFactory.Create(this);
|
PropertyTimeline = _propertyTimelineVmFactory.Create(this);
|
||||||
|
|
||||||
PopulateProperties(_profileEditorService.SelectedProfileElement, null);
|
PopulateProperties(_profileEditorService.SelectedProfileElement);
|
||||||
|
|
||||||
_profileEditorService.ProfileElementSelected += ProfileEditorServiceOnProfileElementSelected;
|
_profileEditorService.ProfileElementSelected += ProfileEditorServiceOnProfileElementSelected;
|
||||||
_profileEditorService.CurrentTimeChanged += ProfileEditorServiceOnCurrentTimeChanged;
|
_profileEditorService.CurrentTimeChanged += ProfileEditorServiceOnCurrentTimeChanged;
|
||||||
@ -87,6 +88,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
|||||||
_profileEditorService.ProfileElementSelected -= ProfileEditorServiceOnProfileElementSelected;
|
_profileEditorService.ProfileElementSelected -= ProfileEditorServiceOnProfileElementSelected;
|
||||||
_profileEditorService.CurrentTimeChanged -= ProfileEditorServiceOnCurrentTimeChanged;
|
_profileEditorService.CurrentTimeChanged -= ProfileEditorServiceOnCurrentTimeChanged;
|
||||||
|
|
||||||
|
if (_lastSelectedLayer != null)
|
||||||
|
{
|
||||||
|
_lastSelectedLayer.LayerPropertyRegistered -= LayerOnPropertyRegistered;
|
||||||
|
_lastSelectedLayer.LayerPropertyRemoved -= LayerOnPropertyRemoved;
|
||||||
|
}
|
||||||
|
|
||||||
PropertyTree?.Dispose();
|
PropertyTree?.Dispose();
|
||||||
PropertyTimeline?.Dispose();
|
PropertyTimeline?.Dispose();
|
||||||
PropertyTree = null;
|
PropertyTree = null;
|
||||||
@ -102,7 +109,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
|||||||
|
|
||||||
private void ProfileEditorServiceOnProfileElementSelected(object sender, ProfileElementEventArgs e)
|
private void ProfileEditorServiceOnProfileElementSelected(object sender, ProfileElementEventArgs e)
|
||||||
{
|
{
|
||||||
PopulateProperties(e.ProfileElement, e.PreviousProfileElement);
|
PopulateProperties(e.ProfileElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProfileEditorServiceOnCurrentTimeChanged(object sender, EventArgs e)
|
private void ProfileEditorServiceOnCurrentTimeChanged(object sender, EventArgs e)
|
||||||
@ -113,12 +120,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
|||||||
|
|
||||||
#region View model managament
|
#region View model managament
|
||||||
|
|
||||||
private void PopulateProperties(ProfileElement profileElement, ProfileElement previousProfileElement)
|
private void PopulateProperties(ProfileElement profileElement)
|
||||||
{
|
{
|
||||||
if (previousProfileElement is Layer previousLayer)
|
if (_lastSelectedLayer != null)
|
||||||
{
|
{
|
||||||
previousLayer.LayerPropertyRegistered -= LayerOnPropertyRegistered;
|
_lastSelectedLayer.LayerPropertyRegistered -= LayerOnPropertyRegistered;
|
||||||
previousLayer.LayerPropertyRemoved -= LayerOnPropertyRemoved;
|
_lastSelectedLayer.LayerPropertyRemoved -= LayerOnPropertyRemoved;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (profileElement is Layer layer)
|
if (profileElement is Layer layer)
|
||||||
@ -137,6 +144,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
|||||||
RemovePropertyViewModel(layerPropertyViewModel);
|
RemovePropertyViewModel(layerPropertyViewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_lastSelectedLayer = layer;
|
||||||
layer.LayerPropertyRegistered += LayerOnPropertyRegistered;
|
layer.LayerPropertyRegistered += LayerOnPropertyRegistered;
|
||||||
layer.LayerPropertyRemoved += LayerOnPropertyRemoved;
|
layer.LayerPropertyRemoved += LayerOnPropertyRemoved;
|
||||||
}
|
}
|
||||||
@ -144,19 +152,21 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
|||||||
{
|
{
|
||||||
foreach (var layerPropertyViewModel in _layerPropertyViewModels.ToList())
|
foreach (var layerPropertyViewModel in _layerPropertyViewModels.ToList())
|
||||||
RemovePropertyViewModel(layerPropertyViewModel);
|
RemovePropertyViewModel(layerPropertyViewModel);
|
||||||
|
|
||||||
|
_lastSelectedLayer = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LayerOnPropertyRegistered(object sender, LayerPropertyEventArgs e)
|
private void LayerOnPropertyRegistered(object sender, LayerPropertyEventArgs e)
|
||||||
{
|
{
|
||||||
Console.WriteLine("LayerOnPropertyRegistered");
|
Console.WriteLine("LayerOnPropertyRegistered");
|
||||||
PopulateProperties(e.LayerProperty.Layer, e.LayerProperty.Layer);
|
PopulateProperties(e.LayerProperty.Layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LayerOnPropertyRemoved(object sender, LayerPropertyEventArgs e)
|
private void LayerOnPropertyRemoved(object sender, LayerPropertyEventArgs e)
|
||||||
{
|
{
|
||||||
Console.WriteLine("LayerOnPropertyRemoved");
|
Console.WriteLine("LayerOnPropertyRemoved");
|
||||||
PopulateProperties(e.LayerProperty.Layer, e.LayerProperty.Layer);
|
PopulateProperties(e.LayerProperty.Layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private LayerPropertyViewModel CreatePropertyViewModel(BaseLayerProperty layerProperty)
|
private LayerPropertyViewModel CreatePropertyViewModel(BaseLayerProperty layerProperty)
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Artemis.Core.Events;
|
||||||
using Artemis.Core.Models.Profile;
|
using Artemis.Core.Models.Profile;
|
||||||
using Artemis.Core.Plugins.LayerBrush;
|
using Artemis.Core.Plugins.LayerBrush;
|
||||||
using Artemis.Core.Services.Interfaces;
|
using Artemis.Core.Services.Interfaces;
|
||||||
@ -21,7 +22,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.P
|
|||||||
_pluginService = pluginService;
|
_pluginService = pluginService;
|
||||||
EnumValues = new BindableCollection<ValueDescription>();
|
EnumValues = new BindableCollection<ValueDescription>();
|
||||||
|
|
||||||
_pluginService.PluginLoaded += (sender, args) => UpdateEnumValues();
|
_pluginService.PluginLoaded += PluginServiceOnPluginLoaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BindableCollection<ValueDescription> EnumValues { get; }
|
public BindableCollection<ValueDescription> EnumValues { get; }
|
||||||
@ -59,10 +60,21 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.P
|
|||||||
NotifyOfPropertyChange(() => BrushInputValue);
|
NotifyOfPropertyChange(() => BrushInputValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
_pluginService.PluginLoaded -= PluginServiceOnPluginLoaded;
|
||||||
|
base.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnInitialized()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
UpdateEnumValues();
|
UpdateEnumValues();
|
||||||
base.OnInitialized();
|
base.OnInitialized();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void PluginServiceOnPluginLoaded(object sender, PluginEventArgs e)
|
||||||
|
{
|
||||||
|
UpdateEnumValues();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -6,7 +6,7 @@ using Stylet;
|
|||||||
|
|
||||||
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput
|
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput
|
||||||
{
|
{
|
||||||
public abstract class PropertyInputViewModel : PropertyChangedBase
|
public abstract class PropertyInputViewModel : PropertyChangedBase, IDisposable
|
||||||
{
|
{
|
||||||
protected PropertyInputViewModel(IProfileEditorService profileEditorService)
|
protected PropertyInputViewModel(IProfileEditorService profileEditorService)
|
||||||
{
|
{
|
||||||
@ -37,7 +37,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.P
|
|||||||
throw new ArtemisUIException($"This input VM does not support the provided type {type.Name}");
|
throw new ArtemisUIException($"This input VM does not support the provided type {type.Name}");
|
||||||
|
|
||||||
LayerPropertyViewModel = layerPropertyViewModel;
|
LayerPropertyViewModel = layerPropertyViewModel;
|
||||||
layerPropertyViewModel.LayerProperty.ValueChanged += (sender, args) => Update();
|
LayerPropertyViewModel.LayerProperty.ValueChanged += LayerPropertyOnValueChanged;
|
||||||
Update();
|
Update();
|
||||||
|
|
||||||
Initialized = true;
|
Initialized = true;
|
||||||
@ -51,6 +51,11 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.P
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void LayerPropertyOnValueChanged(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Update();
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateInputValue(object value)
|
private void UpdateInputValue(object value)
|
||||||
{
|
{
|
||||||
LayerPropertyViewModel.LayerProperty.SetCurrentValue(value, ProfileEditorService.CurrentTime);
|
LayerPropertyViewModel.LayerProperty.SetCurrentValue(value, ProfileEditorService.CurrentTime);
|
||||||
@ -77,5 +82,11 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.P
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
public virtual void Dispose()
|
||||||
|
{
|
||||||
|
if (LayerPropertyViewModel != null)
|
||||||
|
LayerPropertyViewModel.LayerProperty.ValueChanged -= LayerPropertyOnValueChanged;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -30,5 +30,13 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree
|
|||||||
public override void AddLayerProperty(LayerPropertyViewModel layerPropertyViewModel)
|
public override void AddLayerProperty(LayerPropertyViewModel layerPropertyViewModel)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
PropertyInputViewModel?.Dispose();
|
||||||
|
PropertyInputViewModel = null;
|
||||||
|
|
||||||
|
base.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,8 +1,9 @@
|
|||||||
using Stylet;
|
using System;
|
||||||
|
using Stylet;
|
||||||
|
|
||||||
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree
|
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree
|
||||||
{
|
{
|
||||||
public abstract class PropertyTreeItemViewModel : PropertyChangedBase
|
public abstract class PropertyTreeItemViewModel : PropertyChangedBase, IDisposable
|
||||||
{
|
{
|
||||||
protected PropertyTreeItemViewModel(LayerPropertyViewModel layerPropertyViewModel)
|
protected PropertyTreeItemViewModel(LayerPropertyViewModel layerPropertyViewModel)
|
||||||
{
|
{
|
||||||
@ -28,5 +29,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="layerPropertyViewModel"></param>
|
/// <param name="layerPropertyViewModel"></param>
|
||||||
public abstract void AddLayerProperty(LayerPropertyViewModel layerPropertyViewModel);
|
public abstract void AddLayerProperty(LayerPropertyViewModel layerPropertyViewModel);
|
||||||
|
|
||||||
|
public virtual void Dispose()
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,10 +45,19 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree
|
|||||||
foreach (var child in Children.ToList())
|
foreach (var child in Children.ToList())
|
||||||
{
|
{
|
||||||
if (child.LayerPropertyViewModel == layerPropertyViewModel)
|
if (child.LayerPropertyViewModel == layerPropertyViewModel)
|
||||||
|
{
|
||||||
Children.Remove(child);
|
Children.Remove(child);
|
||||||
|
child.Dispose();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
child.RemoveLayerProperty(layerPropertyViewModel);
|
child.RemoveLayerProperty(layerPropertyViewModel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
foreach (var child in Children.ToList())
|
||||||
|
child.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -31,6 +31,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree
|
|||||||
{
|
{
|
||||||
_profileEditorService.CurrentTimeChanged -= OnCurrentTimeChanged;
|
_profileEditorService.CurrentTimeChanged -= OnCurrentTimeChanged;
|
||||||
_profileEditorService.SelectedProfileElementUpdated -= OnSelectedProfileElementUpdated;
|
_profileEditorService.SelectedProfileElementUpdated -= OnSelectedProfileElementUpdated;
|
||||||
|
|
||||||
|
foreach (var propertyTreeItemViewModel in PropertyTreeItemViewModels)
|
||||||
|
propertyTreeItemViewModel.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddLayerProperty(LayerPropertyViewModel layerPropertyViewModel)
|
public void AddLayerProperty(LayerPropertyViewModel layerPropertyViewModel)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user