1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2026-01-01 18:23:32 +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.ComponentModel;
using System.Linq; using System.Linq;
using System.Windows.Media; using System.Windows.Media;
@ -59,11 +60,12 @@ namespace Artemis.Models.Profiles
} }
else else
appliedProperties = GeneralHelpers.Clone(Properties); appliedProperties = GeneralHelpers.Clone(Properties);
// Update animations on layer types that support them // 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) switch (LayerType)
@ -148,7 +150,7 @@ namespace Artemis.Models.Profiles
Brush = new SolidColorBrush(ColorHelpers.GetRandomRainbowMediaColor()) Brush = new SolidColorBrush(ColorHelpers.GetRandomRainbowMediaColor())
}; };
} }
public void FixOrder() public void FixOrder()
{ {
Children.Sort(l => l.Order); Children.Sort(l => l.Order);
@ -179,22 +181,6 @@ namespace Artemis.Models.Profiles
return layers; 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() public static LayerModel CreateLayer()
{ {
return new LayerModel 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 public enum LayerType

View File

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