1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Profile editor - Added element removal

This commit is contained in:
Robert 2022-02-14 23:51:55 +01:00
parent 32ebf5f000
commit b503906b9a
8 changed files with 36 additions and 46 deletions

View File

@ -266,19 +266,7 @@ namespace Artemis.Core
/// Occurs when a property affecting the rendering properties of this folder has been updated
/// </summary>
public event EventHandler? RenderPropertiesUpdated;
/// <inheritdoc />
public override void Activate()
{
throw new NotImplementedException();
}
/// <inheritdoc />
public override void Deactivate()
{
throw new NotImplementedException();
}
/// <inheritdoc />
protected override void Dispose(bool disposing)
{

View File

@ -488,18 +488,6 @@ namespace Artemis.Core
baseLayerEffect.InternalUpdate(Timeline);
}
/// <inheritdoc />
public override void Activate()
{
throw new NotImplementedException();
}
/// <inheritdoc />
public override void Deactivate()
{
throw new NotImplementedException();
}
/// <inheritdoc />
public override void Disable()
{

View File

@ -182,7 +182,7 @@ namespace Artemis.Core
private void StreamlineOrder()
{
for (int index = 0; index < ChildrenList.Count; index++)
ChildrenList[index].Order = index;
ChildrenList[index].Order = index + 1;
}
/// <summary>

View File

@ -52,17 +52,7 @@ namespace Artemis.Core
/// Occurs when a layer effect has been added or removed to this render element
/// </summary>
public event EventHandler? LayerEffectsUpdated;
/// <summary>
/// Activates the render profile element, loading required brushes, effects or anything else needed for rendering
/// </summary>
public abstract void Activate();
/// <summary>
/// Deactivates the render profile element, disposing required brushes, effects or anything else needed for rendering
/// </summary>
public abstract void Deactivate();
/// <inheritdoc />
protected override void Dispose(bool disposing)
{

View File

@ -12,6 +12,7 @@ public class RemoveProfileElement : IProfileEditorCommand, IDisposable
private readonly RenderProfileElement _subject;
private readonly ProfileElement _target;
private bool _isRemoved;
private readonly bool _wasEnabled;
/// <summary>
/// Creates a new instance of the <see cref="RemoveProfileElement"/> class.
@ -23,7 +24,8 @@ public class RemoveProfileElement : IProfileEditorCommand, IDisposable
_subject = subject;
_target = _subject.Parent;
_index = _subject.Children.IndexOf(_subject);
_index = _target.Children.IndexOf(_subject);
_wasEnabled = _subject.Enabled;
DisplayName = subject switch
{
@ -50,15 +52,17 @@ public class RemoveProfileElement : IProfileEditorCommand, IDisposable
{
_isRemoved = true;
_target.RemoveChild(_subject);
_subject.Deactivate();
_subject.Disable();
}
/// <inheritdoc />
public void Undo()
{
_isRemoved = false;
_subject.Activate();
_target.AddChild(_subject, _index);
if (_wasEnabled)
_subject.Enable();
}
#endregion

View File

@ -8,7 +8,7 @@
x:Class="Artemis.UI.Screens.ProfileEditor.ProfileTree.ProfileTreeView"
x:DataType="profileTree:ProfileTreeViewModel">
<Grid RowDefinitions="*,Auto">
<TreeView Classes="no-right-margin" Items="{CompiledBinding Children}" SelectedItem="{CompiledBinding SelectedChild}">
<TreeView Name="ProfileTreeView" Classes="no-right-margin" Items="{CompiledBinding Children}" SelectedItem="{CompiledBinding SelectedChild}" SelectionChanged="ProfileTreeView_OnSelectionChanged">
<TreeView.Styles>
<Style Selector="TreeViewItem">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />

View File

@ -1,3 +1,5 @@
using System;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI;
@ -5,6 +7,8 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
{
public class ProfileTreeView : ReactiveUserControl<ProfileTreeViewModel>
{
private TreeView _treeView;
public ProfileTreeView()
{
InitializeComponent();
@ -13,6 +17,12 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
_treeView = this.Get<TreeView>("ProfileTreeView");
}
private void ProfileTreeView_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
{
_treeView.Focus();
}
}
}

View File

@ -162,18 +162,28 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
Observable.FromEventPattern<ProfileElementEventArgs>(x => ProfileElement.ChildAdded += x, x => ProfileElement.ChildAdded -= x)
.Subscribe(c => AddTreeItemIfMissing(c.EventArgs.ProfileElement)).DisposeWith(d);
Observable.FromEventPattern<ProfileElementEventArgs>(x => ProfileElement.ChildRemoved += x, x => ProfileElement.ChildRemoved -= x)
.Subscribe(c => RemoveTreeItemsIfFound(c.EventArgs.ProfileElement)).DisposeWith(d);
.Subscribe(c => RemoveTreeItemsIfFound(c.Sender, c.EventArgs.ProfileElement)).DisposeWith(d);
}
protected void RemoveTreeItemsIfFound(ProfileElement profileElement)
protected void RemoveTreeItemsIfFound(object? sender, ProfileElement profileElement)
{
List<TreeItemViewModel> toRemove = Children.Where(t => t.ProfileElement == profileElement).ToList();
foreach (TreeItemViewModel treeItemViewModel in toRemove)
Children.Remove(treeItemViewModel);
// Deselect the current profile element if removed
if (_currentProfileElement == profileElement)
_profileEditorService.ChangeCurrentProfileElement(null);
if (_currentProfileElement != profileElement)
return;
// Find a good candidate for a new selection, preferring the next sibling, falling back to the previous sibling and finally the parent
ProfileElement? parent = sender as ProfileElement;
ProfileElement? newSelection = null;
if (parent != null)
{
newSelection = parent.Children.FirstOrDefault(c => c.Order == profileElement.Order) ?? parent.Children.FirstOrDefault(c => c.Order == profileElement.Order - 1);
if (newSelection == null && parent is Folder { IsRootFolder: false })
newSelection = parent;
}
_profileEditorService.ChangeCurrentProfileElement(newSelection as RenderProfileElement);
}
protected void AddTreeItemIfMissing(ProfileElement profileElement)