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

Sorted out sorting <3

This commit is contained in:
SpoinkyNL 2016-06-02 15:20:35 +02:00
parent 76cfc09fa4
commit 35de216762
2 changed files with 75 additions and 55 deletions

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Media;
@ -59,11 +60,12 @@ namespace Artemis.Models.Profiles
}
else
appliedProperties = GeneralHelpers.Clone(Properties);
// Update animations on layer types that support them
if ((LayerType == LayerType.Keyboard || LayerType == LayerType.KeyboardGif))
if (LayerType == LayerType.Keyboard || LayerType == LayerType.KeyboardGif)
{
AnimationUpdater.UpdateAnimation((KeyboardPropertiesModel) Properties, (KeyboardPropertiesModel) appliedProperties, updateAnimations);
AnimationUpdater.UpdateAnimation((KeyboardPropertiesModel) Properties,
(KeyboardPropertiesModel) appliedProperties, updateAnimations);
}
switch (LayerType)
@ -148,7 +150,7 @@ namespace Artemis.Models.Profiles
Brush = new SolidColorBrush(ColorHelpers.GetRandomRainbowMediaColor())
};
}
public void FixOrder()
{
Children.Sort(l => l.Order);
@ -179,22 +181,6 @@ namespace Artemis.Models.Profiles
return layers;
}
#region IChildItem<Parent> Members
LayerModel IChildItem<LayerModel>.Parent
{
get { return Parent; }
set { Parent = value; }
}
ProfileModel IChildItem<ProfileModel>.Parent
{
get { return Profile; }
set { Profile = value; }
}
#endregion
public static LayerModel CreateLayer()
{
return new LayerModel
@ -215,6 +201,56 @@ namespace Artemis.Models.Profiles
}
};
}
public void InsertBefore(LayerModel source)
{
source.Order = Order;
Insert(source);
}
public void InsertAfter(LayerModel source)
{
source.Order = Order + 1;
Insert(source);
}
private void Insert(LayerModel source)
{
if (Parent != null)
{
foreach (var child in Parent.Children.OrderBy(c => c.Order))
{
if (child.Order >= source.Order)
child.Order++;
}
Parent.Children.Add(source);
}
else if (Profile != null)
{
foreach (var layer in Profile.Layers.OrderBy(l => l.Order))
{
if (layer.Order >= source.Order)
layer.Order++;
}
Profile.Layers.Add(source);
}
}
#region IChildItem<Parent> Members
LayerModel IChildItem<LayerModel>.Parent
{
get { return Parent; }
set { Parent = value; }
}
ProfileModel IChildItem<ProfileModel>.Parent
{
get { return Profile; }
set { Profile = value; }
}
#endregion
}
public enum LayerType

View File

@ -150,9 +150,17 @@ namespace Artemis.ViewModels.Profiles
// Remove the source from it's old profile/parent
if (source.Parent == null)
{
var profile = source.Profile;
source.Profile.Layers.Remove(source);
profile.FixOrder();
}
else
{
var parent = source.Parent;
source.Parent.Children.Remove(source);
parent.FixOrder();
}
if (dropInfo.InsertPosition == RelativeInsertPosition.TargetItemCenter &&
target.LayerType == LayerType.Folder)
@ -165,18 +173,14 @@ namespace Artemis.ViewModels.Profiles
else
{
// Insert the source into it's new profile/parent and update the order
if (dropInfo.InsertPosition == RelativeInsertPosition.AfterTargetItem)
source.Order = target.Order + 1;
if (dropInfo.InsertPosition == RelativeInsertPosition.AfterTargetItem ||
dropInfo.InsertPosition ==
(RelativeInsertPosition.TargetItemCenter | RelativeInsertPosition.AfterTargetItem))
target.InsertAfter(source);
else
source.Order = target.Order - 1;
if (target.Parent == null)
target.Profile.Layers.Add(source);
else
target.Parent.Children.Add(source);
target.InsertBefore(source);
}
target.Profile?.FixOrder();
target.Parent?.FixOrder();
UpdateLayerList(source);
}
@ -310,19 +314,10 @@ namespace Artemis.ViewModels.Profiles
// Create a new layer
var layer = LayerModel.CreateLayer();
// If there is a selected layer and it has a parent, bind the new layer to it
if (ProfileViewModel.SelectedLayer?.Parent != null)
{
layer.Order = ProfileViewModel.SelectedLayer.Order + 1;
ProfileViewModel.SelectedLayer.Parent.Children.Add(layer);
ProfileViewModel.SelectedLayer.Parent.FixOrder();
}
if (ProfileViewModel.SelectedLayer != null)
ProfileViewModel.SelectedLayer.InsertAfter(layer);
else
{
// If there was no parent but there is a layer selected, put it below the selected layer
if (ProfileViewModel.SelectedLayer != null)
layer.Order = ProfileViewModel.SelectedLayer.Order + 1;
SelectedProfile.Layers.Add(layer);
SelectedProfile.FixOrder();
}
@ -385,7 +380,7 @@ namespace Artemis.ViewModels.Profiles
}
/// <summary>
/// Clones the currently selected layer and adds it to the profile, on top of the original
/// Clones the currently selected layer and adds it to the profile, after the original
/// </summary>
public void CloneLayer()
{
@ -396,24 +391,13 @@ namespace Artemis.ViewModels.Profiles
}
/// <summary>
/// Clones the given layer and adds it to the profile, on top of the original
/// Clones the given layer and adds it to the profile, after the original
/// </summary>
/// <param name="layer"></param>
public void CloneLayer(LayerModel layer)
{
var clone = GeneralHelpers.Clone(layer);
clone.Order++;
if (layer.Parent != null)
{
layer.Parent.Children.Add(clone);
layer.Parent.FixOrder();
}
else if (layer.Profile != null)
{
layer.Profile.Layers.Add(clone);
layer.Profile.FixOrder();
}
layer.InsertAfter(clone);
UpdateLayerList(clone);
}