Profile tree - Implemented proper copy/pasting

This commit is contained in:
Robert committed 2020-12-01 19:08:10 +01:00
1 parent f694f39219
commit aae4e71d8e
21 files changed
+524 -294

No files matched your search

+7 -1
View File
@@ -33,7 +33,13 @@ namespace Artemis.Core
Parent.AddChild(this);
}
internal Folder(Profile profile, ProfileElement parent, FolderEntity folderEntity) : base(parent.Profile)
/// <summary>
/// Creates a new instance of the <see cref="Folder" /> class based on the provided folder entity
/// </summary>
/// <param name="profile">The profile the folder belongs to</param>
/// <param name="parent">The parent of the folder</param>
/// <param name="folderEntity">The entity of the folder</param>
public Folder(Profile profile, ProfileElement parent, FolderEntity folderEntity) : base(parent.Profile)
{
FolderEntity = folderEntity;
EntityId = folderEntity.Id;
+8 -24
View File
@@ -122,29 +122,6 @@ namespace Artemis.Core
internal override RenderElementEntity RenderElementEntity => LayerEntity;
/// <summary>
/// Creates a deep copy of the layer
/// </summary>
/// <returns>The newly created copy</returns>
public Layer CreateCopy()
{
if (Parent == null)
throw new ArtemisCoreException("Cannot create a copy of a layer without a parent");
LayerEntity entityCopy = CoreJson.DeserializeObject<LayerEntity>(CoreJson.SerializeObject(LayerEntity, true), true)!;
entityCopy.Id = Guid.NewGuid();
entityCopy.Name += " - Copy";
Layer copy = new Layer(Profile, Parent, entityCopy);
if (LayerBrush?.Descriptor != null)
copy.ChangeLayerBrush(LayerBrush.Descriptor);
copy.AddLeds(Leds);
Parent.AddChild(copy, Order + 1);
return copy;
}
/// <inheritdoc />
public override List<ILayerProperty> GetAllLayerProperties()
{
@@ -399,7 +376,14 @@ namespace Artemis.Core
}
finally
{
canvas.Restore();
try
{
canvas.Restore();
}
catch
{
// ignored
}
Renderer.Close();
}
}
+18 -11
View File
@@ -12,8 +12,8 @@ namespace Artemis.Core
/// </summary>
public sealed class Profile : ProfileElement
{
private bool _isActivated;
private readonly object _lock = new object();
private bool _isActivated;
internal Profile(ProfileModule module, string name) : base(null!)
{
@@ -57,7 +57,10 @@ namespace Artemis.Core
private set => SetAndNotify(ref _isActivated, value);
}
internal ProfileEntity ProfileEntity { get; set; }
/// <summary>
/// Gets the profile entity this profile uses for persistent storage
/// </summary>
public ProfileEntity ProfileEntity { get; internal set; }
internal Stack<string> UndoStack { get; set; }
internal Stack<string> RedoStack { get; set; }
@@ -118,6 +121,19 @@ namespace Artemis.Core
return $"[Profile] {nameof(Name)}: {Name}, {nameof(IsActivated)}: {IsActivated}, {nameof(Module)}: {Module}";
}
/// <summary>
/// Populates all the LEDs on the elements in this profile
/// </summary>
/// <param name="surface">The currently active surface that contains the LEDs</param>
public void PopulateLeds(ArtemisSurface surface)
{
if (Disposed)
throw new ObjectDisposedException("Profile");
foreach (Layer layer in GetAllLayers())
layer.PopulateLeds(surface);
}
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
@@ -196,15 +212,6 @@ namespace Artemis.Core
}
}
internal void PopulateLeds(ArtemisSurface surface)
{
if (Disposed)
throw new ObjectDisposedException("Profile");
foreach (Layer layer in GetAllLayers())
layer.PopulateLeds(surface);
}
#region Events
/// <summary>
+4 -1
View File
@@ -5,7 +5,10 @@ using Newtonsoft.Json;
namespace Artemis.Core
{
internal static class CoreJson
/// <summary>
/// A static helper class that serializes and deserializes JSON with the Artemis Core JSON settings
/// </summary>
public static class CoreJson
{
#region Serialize