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:
parent
1bb2d4a4f2
commit
602a0e6fee
@ -3,10 +3,11 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Abstract
|
||||
{
|
||||
public abstract class ProfileElement
|
||||
public abstract class ProfileElement : PropertyChangedBase
|
||||
{
|
||||
protected List<ProfileElement> _children;
|
||||
|
||||
@ -55,7 +56,9 @@ namespace Artemis.Core.Models.Profile.Abstract
|
||||
var folders = new List<Folder>();
|
||||
foreach (var childFolder in Children.Where(c => c is Folder).Cast<Folder>())
|
||||
{
|
||||
// Add all folders in this element
|
||||
folders.Add(childFolder);
|
||||
// Add all folders in folders inside this element
|
||||
folders.AddRange(childFolder.GetAllFolders());
|
||||
}
|
||||
|
||||
@ -64,14 +67,16 @@ namespace Artemis.Core.Models.Profile.Abstract
|
||||
|
||||
public List<Layer> GetAllLayers()
|
||||
{
|
||||
var folders = new List<Layer>();
|
||||
foreach (var childLayer in Children.Where(c => c is Layer).Cast<Layer>())
|
||||
{
|
||||
folders.Add(childLayer);
|
||||
folders.AddRange(childLayer.GetAllLayers());
|
||||
}
|
||||
var layers = new List<Layer>();
|
||||
|
||||
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>
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Models.Profile.Abstract;
|
||||
@ -27,6 +26,10 @@ namespace Artemis.Core.Models.Profile
|
||||
|
||||
Profile = profile;
|
||||
Parent = parent;
|
||||
Name = folderEntity.Name;
|
||||
Order = folderEntity.Order;
|
||||
|
||||
// TODO: Load conditions
|
||||
|
||||
// Load child folders
|
||||
foreach (var childFolder in Profile.ProfileEntity.Folders.Where(f => f.ParentId == EntityId))
|
||||
|
||||
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using Artemis.Core.Extensions;
|
||||
using Artemis.Core.Models.Profile.Abstract;
|
||||
using Artemis.Core.Models.Surface;
|
||||
@ -11,7 +10,6 @@ using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Plugins.Interfaces;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using Device = Artemis.Core.Models.Surface.Device;
|
||||
|
||||
namespace Artemis.Core.Models.Profile
|
||||
{
|
||||
@ -35,6 +33,9 @@ namespace Artemis.Core.Models.Profile
|
||||
|
||||
Profile = profile;
|
||||
Parent = parent;
|
||||
Name = layerEntity.Name;
|
||||
Order = layerEntity.Order;
|
||||
|
||||
LayerType = pluginService.GetLayerTypeByGuid(layerEntity.LayerTypeGuid);
|
||||
Leds = new List<DeviceLed>();
|
||||
}
|
||||
@ -129,7 +130,7 @@ namespace Artemis.Core.Models.Profile
|
||||
path.AddRectangles(Leds.Select(l => l.AbsoluteRenderRectangle).ToArray());
|
||||
RenderPath = path;
|
||||
}
|
||||
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Layer - {nameof(Name)}: {Name}, {nameof(Order)}: {Order}";
|
||||
|
||||
@ -140,7 +140,7 @@ namespace Artemis.Core.Models.Profile
|
||||
{
|
||||
Deactivated?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -96,9 +96,11 @@ namespace Artemis.Core.Services.Storage
|
||||
profile.ApplyToEntity();
|
||||
if (includeChildren)
|
||||
{
|
||||
foreach (var profileElement in profile.Children)
|
||||
profileElement.ApplyToEntity();
|
||||
|
||||
foreach (var folder in profile.GetAllFolders())
|
||||
folder.ApplyToEntity();
|
||||
foreach (var layer in profile.GetAllLayers())
|
||||
layer.ApplyToEntity();
|
||||
|
||||
if (_surfaceService.ActiveSurface != null)
|
||||
profile.ApplySurface(_surfaceService.ActiveSurface);
|
||||
}
|
||||
|
||||
@ -6,13 +6,20 @@ namespace Artemis.Storage.Entities.Profile
|
||||
{
|
||||
public class LayerEntity
|
||||
{
|
||||
public LayerEntity()
|
||||
{
|
||||
Leds = new List<LedEntity>();
|
||||
Condition = new List<ProfileConditionEntity>();
|
||||
Elements = new List<LayerElementEntity>();
|
||||
}
|
||||
|
||||
public Guid Id { get; set; }
|
||||
public Guid ParentId { get; set; }
|
||||
public Guid LayerTypeGuid { get; set; }
|
||||
|
||||
public int Order { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
|
||||
public List<LedEntity> Leds { get; set; }
|
||||
public List<ProfileConditionEntity> Condition { get; set; }
|
||||
public List<LayerElementEntity> Elements { get; set; }
|
||||
|
||||
@ -166,7 +166,10 @@
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<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\DisplayConditionViewModel.cs" />
|
||||
<Compile Include="Screens\Module\ProfileEditor\ElementProperties\ElementPropertiesViewModel.cs" />
|
||||
@ -220,6 +223,10 @@
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</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">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.UI.ViewModels.Dialogs;
|
||||
using FluentValidation;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Module.ProfileEditor.Dialogs
|
||||
@ -27,4 +28,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Dialogs
|
||||
Session.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public class ProfileCreateViewModelValidator : AbstractValidator<ProfileCreateViewModel>
|
||||
{
|
||||
public ProfileCreateViewModelValidator()
|
||||
{
|
||||
RuleFor(m => m.ProfileName).NotEmpty().WithMessage("Profile name may not be empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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>
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,13 +1,16 @@
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Stylet;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Module.ProfileEditor
|
||||
{
|
||||
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()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,16 +18,15 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
|
||||
{
|
||||
public class ProfileEditorViewModel : Conductor<ProfileEditorPanelViewModel>.Collection.AllActive
|
||||
{
|
||||
private readonly IDialogService _dialogService;
|
||||
private readonly IProfileService _profileService;
|
||||
|
||||
public ProfileEditorViewModel(ProfileModule module, ICollection<ProfileEditorPanelViewModel> viewModels, IProfileService profileService, IDialogService dialogService)
|
||||
{
|
||||
_profileService = profileService;
|
||||
_dialogService = dialogService;
|
||||
|
||||
DisplayName = "Profile editor";
|
||||
Module = module;
|
||||
DialogService = dialogService;
|
||||
|
||||
DisplayConditionsViewModel = (DisplayConditionsViewModel) viewModels.First(vm => vm is DisplayConditionsViewModel);
|
||||
ElementPropertiesViewModel = (ElementPropertiesViewModel) viewModels.First(vm => vm is ElementPropertiesViewModel);
|
||||
@ -42,6 +41,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
|
||||
}
|
||||
|
||||
public ProfileModule Module { get; }
|
||||
public IDialogService DialogService { get; }
|
||||
public DisplayConditionsViewModel DisplayConditionsViewModel { get; }
|
||||
public ElementPropertiesViewModel ElementPropertiesViewModel { get; }
|
||||
public LayerElementsViewModel LayerElementsViewModel { get; }
|
||||
@ -68,8 +68,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
|
||||
|
||||
foreach (var panelViewModel in Items)
|
||||
{
|
||||
panelViewModel.Profile = profile;
|
||||
panelViewModel.OnProfileChanged();
|
||||
panelViewModel.ProfileEditorViewModel = this;
|
||||
panelViewModel.ActiveProfileChanged();
|
||||
}
|
||||
|
||||
if (oldProfile != null)
|
||||
@ -87,14 +87,14 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
|
||||
|
||||
public async Task AddProfile()
|
||||
{
|
||||
var result = await _dialogService.ShowDialog<ProfileCreateViewModel>();
|
||||
var result = await DialogService.ShowDialog<ProfileCreateViewModel>();
|
||||
if (result is string name)
|
||||
CreateProfile(name);
|
||||
}
|
||||
|
||||
public async Task DeleteActiveProfile()
|
||||
{
|
||||
var result = await _dialogService.ShowConfirmDialog(
|
||||
var result = await DialogService.ShowConfirmDialog(
|
||||
"Delete active profile",
|
||||
"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)
|
||||
Module.ChangeActiveProfile(activeProfile);
|
||||
}
|
||||
|
||||
public void OnProfileUpdated()
|
||||
{
|
||||
_profileService.UpdateProfile(SelectedProfile, true);
|
||||
|
||||
foreach (var panelViewModel in Items)
|
||||
{
|
||||
panelViewModel.ActiveProfileUpdated();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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.UI.Screens.Module.ProfileEditor.Dialogs;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements.Abstract
|
||||
{
|
||||
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>();
|
||||
}
|
||||
|
||||
public FolderViewModel Parent { get; set; }
|
||||
public ProfileEditorViewModel ProfileEditorViewModel { get; set; }
|
||||
|
||||
public ProfileElement ProfileElement { 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.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -12,11 +12,16 @@
|
||||
<StackPanel>
|
||||
<StackPanel.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="Rename" Command="{s:Action Rename}">
|
||||
<MenuItem Header="Rename" Command="{s:Action RenameElement}">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="RenameBox" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Delete" Command="{s:Action DeleteElement}">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="TrashCan" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<Separator />
|
||||
<MenuItem Header="Add new folder" Command="{s:Action AddFolder}">
|
||||
<MenuItem.Icon>
|
||||
|
||||
@ -6,11 +6,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
|
||||
{
|
||||
public class FolderViewModel : ProfileElementViewModel
|
||||
{
|
||||
public FolderViewModel(Folder folder, FolderViewModel parent)
|
||||
public FolderViewModel(FolderViewModel parent, Folder folder, ProfileEditorViewModel profileEditorViewModel) : base(parent, folder, profileEditorViewModel)
|
||||
{
|
||||
Folder = folder;
|
||||
Parent = parent;
|
||||
ProfileElement = folder;
|
||||
UpdateProfileElements();
|
||||
}
|
||||
|
||||
public Folder Folder { get; }
|
||||
@ -19,12 +18,16 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
|
||||
{
|
||||
Folder.AddFolder("New folder");
|
||||
UpdateProfileElements();
|
||||
|
||||
ProfileEditorViewModel.OnProfileUpdated();
|
||||
}
|
||||
|
||||
public void AddLayer()
|
||||
{
|
||||
Folder.AddLayer("New layer");
|
||||
UpdateProfileElements();
|
||||
|
||||
ProfileEditorViewModel.OnProfileUpdated();
|
||||
}
|
||||
|
||||
public void RemoveExistingElement(ProfileElementViewModel element)
|
||||
@ -32,8 +35,6 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
|
||||
Folder.RemoveChild(element.ProfileElement);
|
||||
Children.Remove(element);
|
||||
element.Parent = null;
|
||||
|
||||
UpdateProfileElements();
|
||||
}
|
||||
|
||||
public void AddExistingElement(ProfileElementViewModel element)
|
||||
@ -41,11 +42,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
|
||||
Folder.AddChild(element.ProfileElement);
|
||||
Children.Add(element);
|
||||
element.Parent = this;
|
||||
|
||||
UpdateProfileElements();
|
||||
}
|
||||
|
||||
public override void UpdateProfileElements()
|
||||
public sealed override void UpdateProfileElements()
|
||||
{
|
||||
// Ensure every child element has an up-to-date VM
|
||||
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);
|
||||
if (existing == null)
|
||||
Children.Add(new FolderViewModel(folder, this));
|
||||
Children.Add(new FolderViewModel(this, folder, ProfileEditorViewModel));
|
||||
}
|
||||
else if (profileElement is Layer layer)
|
||||
{
|
||||
existing = Children.FirstOrDefault(p => p is LayerViewModel vm && vm.Layer == layer);
|
||||
if (existing == null)
|
||||
Children.Add(new LayerViewModel(layer, this));
|
||||
Children.Add(new LayerViewModel(this, layer, ProfileEditorViewModel));
|
||||
}
|
||||
|
||||
existing?.UpdateProfileElements();
|
||||
|
||||
@ -12,11 +12,16 @@
|
||||
<StackPanel>
|
||||
<StackPanel.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="Rename" Command="{s:Action Rename}">
|
||||
<MenuItem Header="Rename" Command="{s:Action RenameElement}">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="RenameBox" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Delete" Command="{s:Action DeleteElement}">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="TrashCan" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
</ContextMenu>
|
||||
</StackPanel.ContextMenu>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
|
||||
@ -5,11 +5,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
|
||||
{
|
||||
public class LayerViewModel : ProfileElementViewModel
|
||||
{
|
||||
public LayerViewModel(Layer layer, FolderViewModel parent)
|
||||
public LayerViewModel(FolderViewModel parent, Layer layer, ProfileEditorViewModel profileEditorViewModel) : base(parent, layer, profileEditorViewModel)
|
||||
{
|
||||
Layer = layer;
|
||||
Parent = parent;
|
||||
ProfileElement = layer;
|
||||
}
|
||||
|
||||
public Layer Layer { get; }
|
||||
|
||||
@ -56,6 +56,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
|
||||
target.SetElementBehind(source);
|
||||
break;
|
||||
}
|
||||
|
||||
ProfileEditorViewModel.OnProfileUpdated();
|
||||
}
|
||||
|
||||
public void AddFolder()
|
||||
@ -68,24 +70,24 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
|
||||
RootFolder?.AddLayer();
|
||||
}
|
||||
|
||||
public override void OnProfileChanged()
|
||||
public override void ActiveProfileChanged()
|
||||
{
|
||||
CreateRootFolderViewModel();
|
||||
base.OnProfileChanged();
|
||||
base.ActiveProfileChanged();
|
||||
}
|
||||
|
||||
private void CreateRootFolderViewModel()
|
||||
{
|
||||
if (!(Profile?.Children?.FirstOrDefault() is Folder folder))
|
||||
if (!(ProfileEditorViewModel?.SelectedProfile?.Children?.FirstOrDefault() is Folder folder))
|
||||
{
|
||||
RootFolder = null;
|
||||
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 target = dropInfo.TargetItem as ProfileElementViewModel;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user