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

Added folder/layer renaming

Implemented profile saving
This commit is contained in:
SpoinkyNL 2019-11-24 23:01:11 +01:00
parent 1bb2d4a4f2
commit 602a0e6fee
20 changed files with 253 additions and 62 deletions

View File

@ -3,10 +3,11 @@ using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using Stylet;
namespace Artemis.Core.Models.Profile.Abstract namespace Artemis.Core.Models.Profile.Abstract
{ {
public abstract class ProfileElement public abstract class ProfileElement : PropertyChangedBase
{ {
protected List<ProfileElement> _children; protected List<ProfileElement> _children;
@ -55,7 +56,9 @@ namespace Artemis.Core.Models.Profile.Abstract
var folders = new List<Folder>(); var folders = new List<Folder>();
foreach (var childFolder in Children.Where(c => c is Folder).Cast<Folder>()) foreach (var childFolder in Children.Where(c => c is Folder).Cast<Folder>())
{ {
// Add all folders in this element
folders.Add(childFolder); folders.Add(childFolder);
// Add all folders in folders inside this element
folders.AddRange(childFolder.GetAllFolders()); folders.AddRange(childFolder.GetAllFolders());
} }
@ -64,14 +67,16 @@ namespace Artemis.Core.Models.Profile.Abstract
public List<Layer> GetAllLayers() public List<Layer> GetAllLayers()
{ {
var folders = new List<Layer>(); var layers = new List<Layer>();
foreach (var childLayer in Children.Where(c => c is Layer).Cast<Layer>())
{
folders.Add(childLayer);
folders.AddRange(childLayer.GetAllLayers());
}
return folders; // Add all layers in this element
layers.AddRange(Children.Where(c => c is Layer).Cast<Layer>());
// Add all layers in folders inside this element
foreach (var childFolder in Children.Where(c => c is Folder).Cast<Folder>())
layers.AddRange(childFolder.GetAllLayers());
return layers;
} }
/// <summary> /// <summary>

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using Artemis.Core.Models.Profile.Abstract; using Artemis.Core.Models.Profile.Abstract;
@ -27,6 +26,10 @@ namespace Artemis.Core.Models.Profile
Profile = profile; Profile = profile;
Parent = parent; Parent = parent;
Name = folderEntity.Name;
Order = folderEntity.Order;
// TODO: Load conditions
// Load child folders // Load child folders
foreach (var childFolder in Profile.ProfileEntity.Folders.Where(f => f.ParentId == EntityId)) foreach (var childFolder in Profile.ProfileEntity.Folders.Where(f => f.ParentId == EntityId))

View File

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Linq; using System.Linq;
using System.Reflection.Metadata.Ecma335;
using Artemis.Core.Extensions; using Artemis.Core.Extensions;
using Artemis.Core.Models.Profile.Abstract; using Artemis.Core.Models.Profile.Abstract;
using Artemis.Core.Models.Surface; using Artemis.Core.Models.Surface;
@ -11,7 +10,6 @@ using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Interfaces; using Artemis.Core.Plugins.Interfaces;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using Artemis.Storage.Entities.Profile; using Artemis.Storage.Entities.Profile;
using Device = Artemis.Core.Models.Surface.Device;
namespace Artemis.Core.Models.Profile namespace Artemis.Core.Models.Profile
{ {
@ -35,6 +33,9 @@ namespace Artemis.Core.Models.Profile
Profile = profile; Profile = profile;
Parent = parent; Parent = parent;
Name = layerEntity.Name;
Order = layerEntity.Order;
LayerType = pluginService.GetLayerTypeByGuid(layerEntity.LayerTypeGuid); LayerType = pluginService.GetLayerTypeByGuid(layerEntity.LayerTypeGuid);
Leds = new List<DeviceLed>(); Leds = new List<DeviceLed>();
} }
@ -129,7 +130,7 @@ namespace Artemis.Core.Models.Profile
path.AddRectangles(Leds.Select(l => l.AbsoluteRenderRectangle).ToArray()); path.AddRectangles(Leds.Select(l => l.AbsoluteRenderRectangle).ToArray());
RenderPath = path; RenderPath = path;
} }
public override string ToString() public override string ToString()
{ {
return $"Layer - {nameof(Name)}: {Name}, {nameof(Order)}: {Order}"; return $"Layer - {nameof(Name)}: {Name}, {nameof(Order)}: {Order}";

View File

@ -140,7 +140,7 @@ namespace Artemis.Core.Models.Profile
{ {
Deactivated?.Invoke(this, EventArgs.Empty); Deactivated?.Invoke(this, EventArgs.Empty);
} }
#endregion #endregion
} }
} }

View File

@ -96,9 +96,11 @@ namespace Artemis.Core.Services.Storage
profile.ApplyToEntity(); profile.ApplyToEntity();
if (includeChildren) if (includeChildren)
{ {
foreach (var profileElement in profile.Children) foreach (var folder in profile.GetAllFolders())
profileElement.ApplyToEntity(); folder.ApplyToEntity();
foreach (var layer in profile.GetAllLayers())
layer.ApplyToEntity();
if (_surfaceService.ActiveSurface != null) if (_surfaceService.ActiveSurface != null)
profile.ApplySurface(_surfaceService.ActiveSurface); profile.ApplySurface(_surfaceService.ActiveSurface);
} }

View File

@ -6,13 +6,20 @@ namespace Artemis.Storage.Entities.Profile
{ {
public class LayerEntity public class LayerEntity
{ {
public LayerEntity()
{
Leds = new List<LedEntity>();
Condition = new List<ProfileConditionEntity>();
Elements = new List<LayerElementEntity>();
}
public Guid Id { get; set; } public Guid Id { get; set; }
public Guid ParentId { get; set; } public Guid ParentId { get; set; }
public Guid LayerTypeGuid { get; set; } public Guid LayerTypeGuid { get; set; }
public int Order { get; set; } public int Order { get; set; }
public string Name { get; set; } public string Name { get; set; }
public List<LedEntity> Leds { get; set; } public List<LedEntity> Leds { get; set; }
public List<ProfileConditionEntity> Condition { get; set; } public List<ProfileConditionEntity> Condition { get; set; }
public List<LayerElementEntity> Elements { get; set; } public List<LayerElementEntity> Elements { get; set; }

View File

@ -166,7 +166,10 @@
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
</Compile> </Compile>
<Compile Include="Screens\Module\ProfileEditor\Dialogs\ProfileCreateViewModel.cs" /> <Compile Include="Screens\Module\ProfileEditor\Dialogs\ProfileCreateViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\Dialogs\SurfaceCreateViewModelValidator.cs" /> <Compile Include="Screens\Module\ProfileEditor\Dialogs\ProfileElementRenameView.xaml.cs">
<DependentUpon>ProfileElementRenameView.xaml</DependentUpon>
</Compile>
<Compile Include="Screens\Module\ProfileEditor\Dialogs\ProfileElementRenameViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\DisplayConditions\DisplayConditionsViewModel.cs" /> <Compile Include="Screens\Module\ProfileEditor\DisplayConditions\DisplayConditionsViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\DisplayConditions\DisplayConditionViewModel.cs" /> <Compile Include="Screens\Module\ProfileEditor\DisplayConditions\DisplayConditionViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\ElementProperties\ElementPropertiesViewModel.cs" /> <Compile Include="Screens\Module\ProfileEditor\ElementProperties\ElementPropertiesViewModel.cs" />
@ -220,6 +223,10 @@
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Page> </Page>
<Page Include="Screens\Module\ProfileEditor\Dialogs\ProfileElementRenameView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Screens\Module\ProfileEditor\DisplayConditions\DisplayConditionsView.xaml"> <Page Include="Screens\Module\ProfileEditor\DisplayConditions\DisplayConditionsView.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>

View File

@ -1,5 +1,6 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Artemis.UI.ViewModels.Dialogs; using Artemis.UI.ViewModels.Dialogs;
using FluentValidation;
using Stylet; using Stylet;
namespace Artemis.UI.Screens.Module.ProfileEditor.Dialogs namespace Artemis.UI.Screens.Module.ProfileEditor.Dialogs
@ -27,4 +28,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Dialogs
Session.Close(); Session.Close();
} }
} }
public class ProfileCreateViewModelValidator : AbstractValidator<ProfileCreateViewModel>
{
public ProfileCreateViewModelValidator()
{
RuleFor(m => m.ProfileName).NotEmpty().WithMessage("Profile name may not be empty");
}
}
} }

View File

@ -0,0 +1,39 @@
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.Dialogs.ProfileElementRenameView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
d:DesignHeight="213.053" d:DesignWidth="254.425">
<StackPanel Margin="16">
<TextBlock Style="{StaticResource MaterialDesignTitleTextBlock}">
Rename profile element
</TextBlock>
<TextBox materialDesign:HintAssist.Hint="Element name"
Margin="0 8 0 16"
Style="{StaticResource MaterialDesignFloatingHintTextBox}"
Text="{Binding ElementName, UpdateSourceTrigger=PropertyChanged}"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button Style="{StaticResource MaterialDesignFlatButton}" IsCancel="True" Margin="0 8 8 0" Command="{s:Action Cancel}">
<Button.CommandParameter>
<system:Boolean xmlns:system="clr-namespace:System;assembly=mscorlib">
False
</system:Boolean>
</Button.CommandParameter>
CANCEL
</Button>
<Button Style="{StaticResource MaterialDesignFlatButton}" IsDefault="True" Margin="0 8 8 0" Command="{s:Action Accept}">
<Button.CommandParameter>
<system:Boolean xmlns:system="clr-namespace:System;assembly=mscorlib">
True
</system:Boolean>
</Button.CommandParameter>
ACCEPT
</Button>
</StackPanel>
</StackPanel>
</UserControl>

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Artemis.UI.Screens.Module.ProfileEditor.Dialogs
{
/// <summary>
/// Interaction logic for ProfileElementRenameView.xaml
/// </summary>
public partial class ProfileElementRenameView : UserControl
{
public ProfileElementRenameView()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,41 @@
using System.Threading.Tasks;
using Artemis.Core.Models.Profile.Abstract;
using Artemis.UI.ViewModels.Dialogs;
using FluentValidation;
using Stylet;
namespace Artemis.UI.Screens.Module.ProfileEditor.Dialogs
{
public class ProfileElementRenameViewModel : DialogViewModelBase
{
public ProfileElementRenameViewModel(IModelValidator<ProfileElementRenameViewModel> validator, ProfileElement profileElement) : base(validator)
{
ElementName = profileElement.Name;
}
public string ElementName { get; set; }
public async Task Accept()
{
await ValidateAsync();
if (HasErrors)
return;
Session.Close(ElementName);
}
public void Cancel()
{
Session.Close();
}
}
public class ProfileElementRenameViewModelValidator : AbstractValidator<ProfileElementRenameViewModel>
{
public ProfileElementRenameViewModelValidator()
{
RuleFor(m => m.ElementName).NotEmpty().WithMessage("Element name may not be empty");
}
}
}

View File

@ -1,12 +0,0 @@
using FluentValidation;
namespace Artemis.UI.Screens.Module.ProfileEditor.Dialogs
{
public class ProfileCreateViewModelValidator : AbstractValidator<ProfileCreateViewModel>
{
public ProfileCreateViewModelValidator()
{
RuleFor(m => m.ProfileName).NotEmpty().WithMessage("Profile name may not be empty");
}
}
}

View File

@ -1,13 +1,16 @@
using Artemis.Core.Models.Profile; using Stylet;
using Stylet;
namespace Artemis.UI.Screens.Module.ProfileEditor namespace Artemis.UI.Screens.Module.ProfileEditor
{ {
public class ProfileEditorPanelViewModel : Screen public class ProfileEditorPanelViewModel : Screen
{ {
public Profile Profile { get; set; } public ProfileEditorViewModel ProfileEditorViewModel { get; set; }
public virtual void OnProfileChanged() public virtual void ActiveProfileChanged()
{
}
public virtual void ActiveProfileUpdated()
{ {
} }
} }

View File

@ -18,16 +18,15 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
{ {
public class ProfileEditorViewModel : Conductor<ProfileEditorPanelViewModel>.Collection.AllActive public class ProfileEditorViewModel : Conductor<ProfileEditorPanelViewModel>.Collection.AllActive
{ {
private readonly IDialogService _dialogService;
private readonly IProfileService _profileService; private readonly IProfileService _profileService;
public ProfileEditorViewModel(ProfileModule module, ICollection<ProfileEditorPanelViewModel> viewModels, IProfileService profileService, IDialogService dialogService) public ProfileEditorViewModel(ProfileModule module, ICollection<ProfileEditorPanelViewModel> viewModels, IProfileService profileService, IDialogService dialogService)
{ {
_profileService = profileService; _profileService = profileService;
_dialogService = dialogService;
DisplayName = "Profile editor"; DisplayName = "Profile editor";
Module = module; Module = module;
DialogService = dialogService;
DisplayConditionsViewModel = (DisplayConditionsViewModel) viewModels.First(vm => vm is DisplayConditionsViewModel); DisplayConditionsViewModel = (DisplayConditionsViewModel) viewModels.First(vm => vm is DisplayConditionsViewModel);
ElementPropertiesViewModel = (ElementPropertiesViewModel) viewModels.First(vm => vm is ElementPropertiesViewModel); ElementPropertiesViewModel = (ElementPropertiesViewModel) viewModels.First(vm => vm is ElementPropertiesViewModel);
@ -42,6 +41,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
} }
public ProfileModule Module { get; } public ProfileModule Module { get; }
public IDialogService DialogService { get; }
public DisplayConditionsViewModel DisplayConditionsViewModel { get; } public DisplayConditionsViewModel DisplayConditionsViewModel { get; }
public ElementPropertiesViewModel ElementPropertiesViewModel { get; } public ElementPropertiesViewModel ElementPropertiesViewModel { get; }
public LayerElementsViewModel LayerElementsViewModel { get; } public LayerElementsViewModel LayerElementsViewModel { get; }
@ -68,8 +68,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
foreach (var panelViewModel in Items) foreach (var panelViewModel in Items)
{ {
panelViewModel.Profile = profile; panelViewModel.ProfileEditorViewModel = this;
panelViewModel.OnProfileChanged(); panelViewModel.ActiveProfileChanged();
} }
if (oldProfile != null) if (oldProfile != null)
@ -87,14 +87,14 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
public async Task AddProfile() public async Task AddProfile()
{ {
var result = await _dialogService.ShowDialog<ProfileCreateViewModel>(); var result = await DialogService.ShowDialog<ProfileCreateViewModel>();
if (result is string name) if (result is string name)
CreateProfile(name); CreateProfile(name);
} }
public async Task DeleteActiveProfile() public async Task DeleteActiveProfile()
{ {
var result = await _dialogService.ShowConfirmDialog( var result = await DialogService.ShowConfirmDialog(
"Delete active profile", "Delete active profile",
"Are you sure you want to delete your currently active profile? This cannot be undone." "Are you sure you want to delete your currently active profile? This cannot be undone."
); );
@ -154,5 +154,15 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
if (!activeProfile.IsActivated) if (!activeProfile.IsActivated)
Module.ChangeActiveProfile(activeProfile); Module.ChangeActiveProfile(activeProfile);
} }
public void OnProfileUpdated()
{
_profileService.UpdateProfile(SelectedProfile, true);
foreach (var panelViewModel in Items)
{
panelViewModel.ActiveProfileUpdated();
}
}
} }
} }

View File

@ -1,17 +1,26 @@
using System.Linq; using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Artemis.Core.Models.Profile.Abstract; using Artemis.Core.Models.Profile.Abstract;
using Artemis.UI.Screens.Module.ProfileEditor.Dialogs;
using Stylet; using Stylet;
namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements.Abstract namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements.Abstract
{ {
public abstract class ProfileElementViewModel : PropertyChangedBase public abstract class ProfileElementViewModel : PropertyChangedBase
{ {
protected ProfileElementViewModel() protected ProfileElementViewModel(FolderViewModel parent, ProfileElement profileElement, ProfileEditorViewModel profileEditorViewModel)
{ {
Parent = parent;
ProfileElement = profileElement;
ProfileEditorViewModel = profileEditorViewModel;
Children = new BindableCollection<ProfileElementViewModel>(); Children = new BindableCollection<ProfileElementViewModel>();
} }
public FolderViewModel Parent { get; set; } public FolderViewModel Parent { get; set; }
public ProfileEditorViewModel ProfileEditorViewModel { get; set; }
public ProfileElement ProfileElement { get; set; } public ProfileElement ProfileElement { get; set; }
public BindableCollection<ProfileElementViewModel> Children { get; set; } public BindableCollection<ProfileElementViewModel> Children { get; set; }
@ -51,5 +60,35 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements.Abstract
Parent.Folder.AddChild(source.ProfileElement, ProfileElement.Order + 1); Parent.Folder.AddChild(source.ProfileElement, ProfileElement.Order + 1);
Parent.UpdateProfileElements(); Parent.UpdateProfileElements();
} }
public async Task RenameElement()
{
var result = await ProfileEditorViewModel.DialogService.ShowDialog<ProfileElementRenameViewModel>(
new Dictionary<string, object> {{"profileElement", ProfileElement}}
);
if (result is string newName)
{
ProfileElement.Name = newName;
ProfileEditorViewModel.OnProfileUpdated();
}
}
public async Task DeleteElement()
{
var result = await ProfileEditorViewModel.DialogService.ShowConfirmDialog(
"Delete profile element",
"Are you sure you want to delete this element? This cannot be undone."
);
if (!result)
return;
// Farewell, cruel world
ProfileElement.Parent.RemoveChild(ProfileElement);
Parent.RemoveExistingElement(this);
Parent.UpdateProfileElements();
ProfileEditorViewModel.OnProfileUpdated();
}
} }
} }

View File

@ -12,11 +12,16 @@
<StackPanel> <StackPanel>
<StackPanel.ContextMenu> <StackPanel.ContextMenu>
<ContextMenu> <ContextMenu>
<MenuItem Header="Rename" Command="{s:Action Rename}"> <MenuItem Header="Rename" Command="{s:Action RenameElement}">
<MenuItem.Icon> <MenuItem.Icon>
<materialDesign:PackIcon Kind="RenameBox" /> <materialDesign:PackIcon Kind="RenameBox" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem> </MenuItem>
<MenuItem Header="Delete" Command="{s:Action DeleteElement}">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="TrashCan" />
</MenuItem.Icon>
</MenuItem>
<Separator /> <Separator />
<MenuItem Header="Add new folder" Command="{s:Action AddFolder}"> <MenuItem Header="Add new folder" Command="{s:Action AddFolder}">
<MenuItem.Icon> <MenuItem.Icon>

View File

@ -6,11 +6,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
{ {
public class FolderViewModel : ProfileElementViewModel public class FolderViewModel : ProfileElementViewModel
{ {
public FolderViewModel(Folder folder, FolderViewModel parent) public FolderViewModel(FolderViewModel parent, Folder folder, ProfileEditorViewModel profileEditorViewModel) : base(parent, folder, profileEditorViewModel)
{ {
Folder = folder; Folder = folder;
Parent = parent; UpdateProfileElements();
ProfileElement = folder;
} }
public Folder Folder { get; } public Folder Folder { get; }
@ -19,12 +18,16 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
{ {
Folder.AddFolder("New folder"); Folder.AddFolder("New folder");
UpdateProfileElements(); UpdateProfileElements();
ProfileEditorViewModel.OnProfileUpdated();
} }
public void AddLayer() public void AddLayer()
{ {
Folder.AddLayer("New layer"); Folder.AddLayer("New layer");
UpdateProfileElements(); UpdateProfileElements();
ProfileEditorViewModel.OnProfileUpdated();
} }
public void RemoveExistingElement(ProfileElementViewModel element) public void RemoveExistingElement(ProfileElementViewModel element)
@ -32,8 +35,6 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
Folder.RemoveChild(element.ProfileElement); Folder.RemoveChild(element.ProfileElement);
Children.Remove(element); Children.Remove(element);
element.Parent = null; element.Parent = null;
UpdateProfileElements();
} }
public void AddExistingElement(ProfileElementViewModel element) public void AddExistingElement(ProfileElementViewModel element)
@ -41,11 +42,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
Folder.AddChild(element.ProfileElement); Folder.AddChild(element.ProfileElement);
Children.Add(element); Children.Add(element);
element.Parent = this; element.Parent = this;
UpdateProfileElements();
} }
public override void UpdateProfileElements() public sealed override void UpdateProfileElements()
{ {
// Ensure every child element has an up-to-date VM // Ensure every child element has an up-to-date VM
if (Folder.Children != null) if (Folder.Children != null)
@ -57,13 +56,13 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
{ {
existing = Children.FirstOrDefault(p => p is FolderViewModel vm && vm.Folder == folder); existing = Children.FirstOrDefault(p => p is FolderViewModel vm && vm.Folder == folder);
if (existing == null) if (existing == null)
Children.Add(new FolderViewModel(folder, this)); Children.Add(new FolderViewModel(this, folder, ProfileEditorViewModel));
} }
else if (profileElement is Layer layer) else if (profileElement is Layer layer)
{ {
existing = Children.FirstOrDefault(p => p is LayerViewModel vm && vm.Layer == layer); existing = Children.FirstOrDefault(p => p is LayerViewModel vm && vm.Layer == layer);
if (existing == null) if (existing == null)
Children.Add(new LayerViewModel(layer, this)); Children.Add(new LayerViewModel(this, layer, ProfileEditorViewModel));
} }
existing?.UpdateProfileElements(); existing?.UpdateProfileElements();

View File

@ -12,11 +12,16 @@
<StackPanel> <StackPanel>
<StackPanel.ContextMenu> <StackPanel.ContextMenu>
<ContextMenu> <ContextMenu>
<MenuItem Header="Rename" Command="{s:Action Rename}"> <MenuItem Header="Rename" Command="{s:Action RenameElement}">
<MenuItem.Icon> <MenuItem.Icon>
<materialDesign:PackIcon Kind="RenameBox" /> <materialDesign:PackIcon Kind="RenameBox" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem> </MenuItem>
<MenuItem Header="Delete" Command="{s:Action DeleteElement}">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="TrashCan" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu> </ContextMenu>
</StackPanel.ContextMenu> </StackPanel.ContextMenu>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">

View File

@ -5,11 +5,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
{ {
public class LayerViewModel : ProfileElementViewModel public class LayerViewModel : ProfileElementViewModel
{ {
public LayerViewModel(Layer layer, FolderViewModel parent) public LayerViewModel(FolderViewModel parent, Layer layer, ProfileEditorViewModel profileEditorViewModel) : base(parent, layer, profileEditorViewModel)
{ {
Layer = layer; Layer = layer;
Parent = parent;
ProfileElement = layer;
} }
public Layer Layer { get; } public Layer Layer { get; }

View File

@ -56,6 +56,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
target.SetElementBehind(source); target.SetElementBehind(source);
break; break;
} }
ProfileEditorViewModel.OnProfileUpdated();
} }
public void AddFolder() public void AddFolder()
@ -68,24 +70,24 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
RootFolder?.AddLayer(); RootFolder?.AddLayer();
} }
public override void OnProfileChanged() public override void ActiveProfileChanged()
{ {
CreateRootFolderViewModel(); CreateRootFolderViewModel();
base.OnProfileChanged(); base.ActiveProfileChanged();
} }
private void CreateRootFolderViewModel() private void CreateRootFolderViewModel()
{ {
if (!(Profile?.Children?.FirstOrDefault() is Folder folder)) if (!(ProfileEditorViewModel?.SelectedProfile?.Children?.FirstOrDefault() is Folder folder))
{ {
RootFolder = null; RootFolder = null;
return; return;
} }
RootFolder = new FolderViewModel(folder, null); RootFolder = new FolderViewModel(null, folder, ProfileEditorViewModel);
} }
private DragDropType GetDragDropType(IDropInfo dropInfo) private static DragDropType GetDragDropType(IDropInfo dropInfo)
{ {
var source = dropInfo.Data as ProfileElementViewModel; var source = dropInfo.Data as ProfileElementViewModel;
var target = dropInfo.TargetItem as ProfileElementViewModel; var target = dropInfo.TargetItem as ProfileElementViewModel;