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:
parent
32ebf5f000
commit
b503906b9a
@ -267,18 +267,6 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public event EventHandler? RenderPropertiesUpdated;
|
public event EventHandler? RenderPropertiesUpdated;
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override void Activate()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override void Deactivate()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -488,18 +488,6 @@ namespace Artemis.Core
|
|||||||
baseLayerEffect.InternalUpdate(Timeline);
|
baseLayerEffect.InternalUpdate(Timeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override void Activate()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override void Deactivate()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Disable()
|
public override void Disable()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -182,7 +182,7 @@ namespace Artemis.Core
|
|||||||
private void StreamlineOrder()
|
private void StreamlineOrder()
|
||||||
{
|
{
|
||||||
for (int index = 0; index < ChildrenList.Count; index++)
|
for (int index = 0; index < ChildrenList.Count; index++)
|
||||||
ChildrenList[index].Order = index;
|
ChildrenList[index].Order = index + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -53,16 +53,6 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public event EventHandler? LayerEffectsUpdated;
|
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 />
|
/// <inheritdoc />
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -12,6 +12,7 @@ public class RemoveProfileElement : IProfileEditorCommand, IDisposable
|
|||||||
private readonly RenderProfileElement _subject;
|
private readonly RenderProfileElement _subject;
|
||||||
private readonly ProfileElement _target;
|
private readonly ProfileElement _target;
|
||||||
private bool _isRemoved;
|
private bool _isRemoved;
|
||||||
|
private readonly bool _wasEnabled;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new instance of the <see cref="RemoveProfileElement"/> class.
|
/// Creates a new instance of the <see cref="RemoveProfileElement"/> class.
|
||||||
@ -23,7 +24,8 @@ public class RemoveProfileElement : IProfileEditorCommand, IDisposable
|
|||||||
|
|
||||||
_subject = subject;
|
_subject = subject;
|
||||||
_target = _subject.Parent;
|
_target = _subject.Parent;
|
||||||
_index = _subject.Children.IndexOf(_subject);
|
_index = _target.Children.IndexOf(_subject);
|
||||||
|
_wasEnabled = _subject.Enabled;
|
||||||
|
|
||||||
DisplayName = subject switch
|
DisplayName = subject switch
|
||||||
{
|
{
|
||||||
@ -50,15 +52,17 @@ public class RemoveProfileElement : IProfileEditorCommand, IDisposable
|
|||||||
{
|
{
|
||||||
_isRemoved = true;
|
_isRemoved = true;
|
||||||
_target.RemoveChild(_subject);
|
_target.RemoveChild(_subject);
|
||||||
_subject.Deactivate();
|
_subject.Disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Undo()
|
public void Undo()
|
||||||
{
|
{
|
||||||
_isRemoved = false;
|
_isRemoved = false;
|
||||||
_subject.Activate();
|
|
||||||
_target.AddChild(_subject, _index);
|
_target.AddChild(_subject, _index);
|
||||||
|
|
||||||
|
if (_wasEnabled)
|
||||||
|
_subject.Enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
x:Class="Artemis.UI.Screens.ProfileEditor.ProfileTree.ProfileTreeView"
|
x:Class="Artemis.UI.Screens.ProfileEditor.ProfileTree.ProfileTreeView"
|
||||||
x:DataType="profileTree:ProfileTreeViewModel">
|
x:DataType="profileTree:ProfileTreeViewModel">
|
||||||
<Grid RowDefinitions="*,Auto">
|
<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>
|
<TreeView.Styles>
|
||||||
<Style Selector="TreeViewItem">
|
<Style Selector="TreeViewItem">
|
||||||
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
|
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
using System;
|
||||||
|
using Avalonia.Controls;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
using Avalonia.ReactiveUI;
|
using Avalonia.ReactiveUI;
|
||||||
|
|
||||||
@ -5,6 +7,8 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
|
|||||||
{
|
{
|
||||||
public class ProfileTreeView : ReactiveUserControl<ProfileTreeViewModel>
|
public class ProfileTreeView : ReactiveUserControl<ProfileTreeViewModel>
|
||||||
{
|
{
|
||||||
|
private TreeView _treeView;
|
||||||
|
|
||||||
public ProfileTreeView()
|
public ProfileTreeView()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -13,6 +17,12 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
AvaloniaXamlLoader.Load(this);
|
AvaloniaXamlLoader.Load(this);
|
||||||
|
_treeView = this.Get<TreeView>("ProfileTreeView");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ProfileTreeView_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
_treeView.Focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -162,18 +162,28 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
|
|||||||
Observable.FromEventPattern<ProfileElementEventArgs>(x => ProfileElement.ChildAdded += x, x => ProfileElement.ChildAdded -= x)
|
Observable.FromEventPattern<ProfileElementEventArgs>(x => ProfileElement.ChildAdded += x, x => ProfileElement.ChildAdded -= x)
|
||||||
.Subscribe(c => AddTreeItemIfMissing(c.EventArgs.ProfileElement)).DisposeWith(d);
|
.Subscribe(c => AddTreeItemIfMissing(c.EventArgs.ProfileElement)).DisposeWith(d);
|
||||||
Observable.FromEventPattern<ProfileElementEventArgs>(x => ProfileElement.ChildRemoved += x, x => ProfileElement.ChildRemoved -= x)
|
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();
|
List<TreeItemViewModel> toRemove = Children.Where(t => t.ProfileElement == profileElement).ToList();
|
||||||
foreach (TreeItemViewModel treeItemViewModel in toRemove)
|
foreach (TreeItemViewModel treeItemViewModel in toRemove)
|
||||||
Children.Remove(treeItemViewModel);
|
Children.Remove(treeItemViewModel);
|
||||||
|
|
||||||
// Deselect the current profile element if removed
|
if (_currentProfileElement != profileElement)
|
||||||
if (_currentProfileElement == profileElement)
|
return;
|
||||||
_profileEditorService.ChangeCurrentProfileElement(null);
|
|
||||||
|
// 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)
|
protected void AddTreeItemIfMissing(ProfileElement profileElement)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user