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

Profile editor - Added basic layer copy/paste

This commit is contained in:
Robert 2020-11-26 19:23:12 +01:00
parent 253c2f069b
commit f694f39219
9 changed files with 87 additions and 12 deletions

View File

@ -52,7 +52,10 @@ namespace Artemis.Core
/// </summary>
public bool IsRootFolder => Parent == Profile;
internal FolderEntity FolderEntity { get; set; }
/// <summary>
/// Gets the folder entity this folder uses for persistent storage
/// </summary>
public FolderEntity FolderEntity { get; internal set; }
internal override RenderElementEntity RenderElementEntity => FolderEntity;

View File

@ -6,7 +6,6 @@ using Artemis.Core.LayerBrushes;
using Artemis.Core.LayerEffects;
using Artemis.Storage.Entities.Profile;
using Artemis.Storage.Entities.Profile.Abstract;
using Newtonsoft.Json;
using SkiaSharp;
namespace Artemis.Core
@ -18,9 +17,9 @@ namespace Artemis.Core
{
private LayerGeneralProperties _general;
private BaseLayerBrush? _layerBrush;
private LayerTransformProperties _transform;
private LayerShape? _layerShape;
private List<ArtemisLed> _leds;
private LayerTransformProperties _transform;
/// <summary>
/// Creates a new instance of the <see cref="Layer" /> class and adds itself to the child collection of the provided
@ -46,7 +45,13 @@ namespace Artemis.Core
Parent.AddChild(this);
}
internal Layer(Profile profile, ProfileElement parent, LayerEntity layerEntity) : base(parent.Profile)
/// <summary>
/// Creates a new instance of the <see cref="Layer" /> class based on the provided layer entity
/// </summary>
/// <param name="profile">The profile the layer belongs to</param>
/// <param name="parent">The parent of the layer</param>
/// <param name="layerEntity">The entity of the layer</param>
public Layer(Profile profile, ProfileElement parent, LayerEntity layerEntity) : base(parent.Profile)
{
LayerEntity = layerEntity;
EntityId = layerEntity.Id;
@ -82,7 +87,7 @@ namespace Artemis.Core
}
/// <summary>
/// Gets the general properties of the layer
/// Gets the general properties of the layer
/// </summary>
[PropertyGroupDescription(Name = "General", Description = "A collection of general properties")]
public LayerGeneralProperties General
@ -92,7 +97,7 @@ namespace Artemis.Core
}
/// <summary>
/// Gets the transform properties of the layer
/// Gets the transform properties of the layer
/// </summary>
[PropertyGroupDescription(Name = "Transform", Description = "A collection of transformation properties")]
public LayerTransformProperties Transform
@ -110,7 +115,10 @@ namespace Artemis.Core
internal set => SetAndNotify(ref _layerBrush, value);
}
internal LayerEntity LayerEntity { get; set; }
/// <summary>
/// Gets the layer entity this layer uses for persistent storage
/// </summary>
public LayerEntity LayerEntity { get; internal set; }
internal override RenderElementEntity RenderElementEntity => LayerEntity;

View File

@ -143,6 +143,8 @@ namespace Artemis.Core
// Shift everything after the given order
else
{
if (order < 0)
order = 0;
foreach (ProfileElement profileElement in ChildrenList.Where(c => c.Order >= order).ToList())
profileElement.Order++;

View File

@ -114,7 +114,6 @@ namespace Artemis.Core
#region Properties
private ProfileElement? _parent;
private SKPath? _path;
internal abstract RenderElementEntity RenderElementEntity { get; }
@ -123,10 +122,11 @@ namespace Artemis.Core
/// </summary>
public new ProfileElement? Parent
{
get => _parent;
get => base.Parent;
internal set
{
SetAndNotify(ref _parent, value);
base.Parent = value;
OnPropertyChanged(nameof(Parent));
Renderer.Invalidate();
}
}

View File

@ -36,6 +36,8 @@
<TreeView.InputBindings>
<KeyBinding Key="F2" Command="{s:Action RenameElement}" s:View.ActionTarget="{Binding SelectedTreeItem}"/>
<KeyBinding Key="Delete" Command="{s:Action DeleteElement}" s:View.ActionTarget="{Binding SelectedTreeItem}"/>
<KeyBinding Key="C" Modifiers="Control" Command="{s:Action CopyElement}" s:View.ActionTarget="{Binding SelectedTreeItem}"/>
<KeyBinding Key="V" Modifiers="Control" Command="{s:Action PasteElement}" s:View.ActionTarget="{Binding SelectedTreeItem}"/>
</TreeView.InputBindings>
<b:Interaction.Behaviors>
<behaviors:TreeViewSelectionBehavior ExpandSelected="True" SelectedItem="{Binding SelectedTreeItem}" />

View File

@ -18,7 +18,7 @@
<materialDesign:PackIcon Kind="RenameBox" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Copy" Command="{s:Action CopyElement}">
<MenuItem Header="Duplicate" Command="{s:Action DuplicateElement}">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="ContentCopy" />
</MenuItem.Icon>

View File

@ -21,7 +21,7 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
_profileEditorService = profileEditorService;
}
public void CopyElement()
public void DuplicateElement()
{
Layer layer = Layer.CreateCopy();

View File

@ -5,10 +5,12 @@ using System.Threading.Tasks;
using Artemis.Core;
using Artemis.Core.LayerBrushes;
using Artemis.Core.Services;
using Artemis.Storage.Entities.Profile;
using Artemis.UI.Exceptions;
using Artemis.UI.Ninject.Factories;
using Artemis.UI.Screens.ProfileEditor.Dialogs;
using Artemis.UI.Shared.Services;
using Artemis.UI.Utilities;
using Stylet;
namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
@ -185,6 +187,29 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
_profileEditorService.ChangeSelectedProfileElement(null);
}
public void CopyElement()
{
if (ProfileElement is Layer layer)
JsonClipboard.SetObject(layer.LayerEntity);
else if (ProfileElement is Folder folder)
JsonClipboard.SetObject(folder.FolderEntity);
}
public void PasteElement()
{
object? clipboardObject = JsonClipboard.GetData();
if (clipboardObject is LayerEntity layerEntity)
{
layerEntity.Id = Guid.NewGuid();
layerEntity.Name += " - copy";
Layer pasted = new Layer(ProfileElement.Profile, ProfileElement.Parent, layerEntity);
ProfileElement.Parent.AddChild(pasted, ProfileElement.Order - 1);
}
else if (clipboardObject is FolderEntity folderEntity)
{
}
}
public void UpdateProfileElements()
{
// Remove VMs that are no longer a child

View File

@ -0,0 +1,35 @@
using System.Windows;
using Newtonsoft.Json;
namespace Artemis.UI.Utilities
{
public static class JsonClipboard
{
private static readonly JsonSerializerSettings JsonSettings = new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.All};
public static void SetObject(object clipboardObject)
{
string json = JsonConvert.SerializeObject(clipboardObject, JsonSettings);
Clipboard.SetData("Artemis", json);
}
public static object GetData()
{
string json = Clipboard.GetData("Artemis")?.ToString();
if (json != null)
return JsonConvert.DeserializeObject(json, JsonSettings);
return null;
}
public static T GetData<T>()
{
object data = GetData();
return data is T castData ? castData : default;
}
public static bool ContainsArtemisData()
{
return Clipboard.ContainsData("Artemis");
}
}
}