mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +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 IProfileEditorService _profileEditorService;
|
||||
private readonly ISettingsService _settingsService;
|
||||
private Layer _lastSelectedLayer;
|
||||
|
||||
public LayerPropertiesViewModel(IProfileEditorService profileEditorService,
|
||||
ICoreService coreService,
|
||||
@ -74,7 +75,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
||||
PropertyTree = _propertyTreeVmFactory.Create(this);
|
||||
PropertyTimeline = _propertyTimelineVmFactory.Create(this);
|
||||
|
||||
PopulateProperties(_profileEditorService.SelectedProfileElement, null);
|
||||
PopulateProperties(_profileEditorService.SelectedProfileElement);
|
||||
|
||||
_profileEditorService.ProfileElementSelected += ProfileEditorServiceOnProfileElementSelected;
|
||||
_profileEditorService.CurrentTimeChanged += ProfileEditorServiceOnCurrentTimeChanged;
|
||||
@ -86,6 +87,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
||||
{
|
||||
_profileEditorService.ProfileElementSelected -= ProfileEditorServiceOnProfileElementSelected;
|
||||
_profileEditorService.CurrentTimeChanged -= ProfileEditorServiceOnCurrentTimeChanged;
|
||||
|
||||
if (_lastSelectedLayer != null)
|
||||
{
|
||||
_lastSelectedLayer.LayerPropertyRegistered -= LayerOnPropertyRegistered;
|
||||
_lastSelectedLayer.LayerPropertyRemoved -= LayerOnPropertyRemoved;
|
||||
}
|
||||
|
||||
PropertyTree?.Dispose();
|
||||
PropertyTimeline?.Dispose();
|
||||
@ -102,7 +109,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
||||
|
||||
private void ProfileEditorServiceOnProfileElementSelected(object sender, ProfileElementEventArgs e)
|
||||
{
|
||||
PopulateProperties(e.ProfileElement, e.PreviousProfileElement);
|
||||
PopulateProperties(e.ProfileElement);
|
||||
}
|
||||
|
||||
private void ProfileEditorServiceOnCurrentTimeChanged(object sender, EventArgs e)
|
||||
@ -113,12 +120,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
||||
|
||||
#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;
|
||||
previousLayer.LayerPropertyRemoved -= LayerOnPropertyRemoved;
|
||||
_lastSelectedLayer.LayerPropertyRegistered -= LayerOnPropertyRegistered;
|
||||
_lastSelectedLayer.LayerPropertyRemoved -= LayerOnPropertyRemoved;
|
||||
}
|
||||
|
||||
if (profileElement is Layer layer)
|
||||
@ -137,6 +144,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
||||
RemovePropertyViewModel(layerPropertyViewModel);
|
||||
}
|
||||
|
||||
_lastSelectedLayer = layer;
|
||||
layer.LayerPropertyRegistered += LayerOnPropertyRegistered;
|
||||
layer.LayerPropertyRemoved += LayerOnPropertyRemoved;
|
||||
}
|
||||
@ -144,19 +152,21 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
||||
{
|
||||
foreach (var layerPropertyViewModel in _layerPropertyViewModels.ToList())
|
||||
RemovePropertyViewModel(layerPropertyViewModel);
|
||||
|
||||
_lastSelectedLayer = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void LayerOnPropertyRegistered(object sender, LayerPropertyEventArgs e)
|
||||
{
|
||||
Console.WriteLine("LayerOnPropertyRegistered");
|
||||
PopulateProperties(e.LayerProperty.Layer, e.LayerProperty.Layer);
|
||||
PopulateProperties(e.LayerProperty.Layer);
|
||||
}
|
||||
|
||||
private void LayerOnPropertyRemoved(object sender, LayerPropertyEventArgs e)
|
||||
{
|
||||
Console.WriteLine("LayerOnPropertyRemoved");
|
||||
PopulateProperties(e.LayerProperty.Layer, e.LayerProperty.Layer);
|
||||
PopulateProperties(e.LayerProperty.Layer);
|
||||
}
|
||||
|
||||
private LayerPropertyViewModel CreatePropertyViewModel(BaseLayerProperty layerProperty)
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Plugins.LayerBrush;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
@ -21,7 +22,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.P
|
||||
_pluginService = pluginService;
|
||||
EnumValues = new BindableCollection<ValueDescription>();
|
||||
|
||||
_pluginService.PluginLoaded += (sender, args) => UpdateEnumValues();
|
||||
_pluginService.PluginLoaded += PluginServiceOnPluginLoaded;
|
||||
}
|
||||
|
||||
public BindableCollection<ValueDescription> EnumValues { get; }
|
||||
@ -59,10 +60,21 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.P
|
||||
NotifyOfPropertyChange(() => BrushInputValue);
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
_pluginService.PluginLoaded -= PluginServiceOnPluginLoaded;
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
UpdateEnumValues();
|
||||
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
|
||||
{
|
||||
public abstract class PropertyInputViewModel : PropertyChangedBase
|
||||
public abstract class PropertyInputViewModel : PropertyChangedBase, IDisposable
|
||||
{
|
||||
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}");
|
||||
|
||||
LayerPropertyViewModel = layerPropertyViewModel;
|
||||
layerPropertyViewModel.LayerProperty.ValueChanged += (sender, args) => Update();
|
||||
LayerPropertyViewModel.LayerProperty.ValueChanged += LayerPropertyOnValueChanged;
|
||||
Update();
|
||||
|
||||
Initialized = true;
|
||||
@ -50,6 +50,11 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.P
|
||||
protected virtual void OnInitialized()
|
||||
{
|
||||
}
|
||||
|
||||
private void LayerPropertyOnValueChanged(object? sender, EventArgs e)
|
||||
{
|
||||
Update();
|
||||
}
|
||||
|
||||
private void UpdateInputValue(object value)
|
||||
{
|
||||
@ -77,5 +82,11 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.P
|
||||
}
|
||||
|
||||
#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 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
|
||||
{
|
||||
public abstract class PropertyTreeItemViewModel : PropertyChangedBase
|
||||
public abstract class PropertyTreeItemViewModel : PropertyChangedBase, IDisposable
|
||||
{
|
||||
protected PropertyTreeItemViewModel(LayerPropertyViewModel layerPropertyViewModel)
|
||||
{
|
||||
@ -28,5 +29,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree
|
||||
/// </summary>
|
||||
/// <param name="layerPropertyViewModel"></param>
|
||||
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())
|
||||
{
|
||||
if (child.LayerPropertyViewModel == layerPropertyViewModel)
|
||||
{
|
||||
Children.Remove(child);
|
||||
child.Dispose();
|
||||
}
|
||||
else
|
||||
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.SelectedProfileElementUpdated -= OnSelectedProfileElementUpdated;
|
||||
|
||||
foreach (var propertyTreeItemViewModel in PropertyTreeItemViewModels)
|
||||
propertyTreeItemViewModel.Dispose();
|
||||
}
|
||||
|
||||
public void AddLayerProperty(LayerPropertyViewModel layerPropertyViewModel)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user