1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 21:38:38 +00:00

Profile editor - Added profile duplicate

This commit is contained in:
SpoinkyNL 2020-12-17 21:34:41 +01:00
parent e61a031485
commit 15759c9289
4 changed files with 26 additions and 19 deletions

View File

@ -9,12 +9,13 @@ namespace Artemis.Core
/// </summary>
public class ProfileDescriptor : CorePropertyChanged
{
private readonly ProfileEntity _profileEntity;
internal ProfileDescriptor(ProfileModule profileModule, ProfileEntity profileEntity)
{
_profileEntity = profileEntity;
ProfileModule = profileModule;
Id = profileEntity.Id;
Name = profileEntity.Name;
IsLastActiveProfile = profileEntity.IsActive;
}
/// <summary>
@ -25,26 +26,17 @@ namespace Artemis.Core
/// <summary>
/// Gets the unique ID of the profile by which it can be loaded from storage
/// </summary>
public Guid Id => _profileEntity.Id;
public Guid Id { get; }
/// <summary>
/// Gets the name of the profile
/// </summary>
public string Name => _profileEntity.Name;
public string Name { get; }
/// <summary>
/// Gets a boolean indicating whether this was the last active profile
/// </summary>
public bool IsLastActiveProfile => _profileEntity.IsActive;
public bool IsLastActiveProfile { get; }
/// <summary>
/// Triggers a property change for all properties linked to the backing profile entity ¯\_(ツ)_/¯
/// </summary>
public void Update()
{
OnPropertyChanged(nameof(Id));
OnPropertyChanged(nameof(Name));
OnPropertyChanged(nameof(IsLastActiveProfile));
}
}
}

View File

@ -118,7 +118,8 @@ namespace Artemis.Core.Services
/// </summary>
/// <param name="json">The content of the profile as JSON</param>
/// <param name="profileModule">The module to import the profile in to</param>
/// <param name="nameAffix">Text to add after the name of the profile (separated by a dash)</param>
/// <returns></returns>
ProfileDescriptor ImportProfile(string json, ProfileModule profileModule);
ProfileDescriptor ImportProfile(string json, ProfileModule profileModule, string nameAffix = "imported");
}
}

View File

@ -280,7 +280,7 @@ namespace Artemis.Core.Services
return JsonConvert.SerializeObject(profileEntity, ExportSettings);
}
public ProfileDescriptor ImportProfile(string json, ProfileModule profileModule)
public ProfileDescriptor ImportProfile(string json, ProfileModule profileModule, string nameAffix)
{
ProfileEntity? profileEntity = JsonConvert.DeserializeObject<ProfileEntity>(json, ExportSettings);
if (profileEntity == null)
@ -288,7 +288,7 @@ namespace Artemis.Core.Services
// Assign a new GUID to make sure it is unique in case of a previous import of the same content
profileEntity.UpdateGuid(Guid.NewGuid());
profileEntity.Name = $"{profileEntity.Name} - Imported";
profileEntity.Name = $"{profileEntity.Name} - {nameAffix}";
_profileRepository.Add(profileEntity);
return new ProfileDescriptor(profileModule, profileEntity);

View File

@ -15,6 +15,7 @@ using Artemis.UI.Screens.ProfileEditor.ProfileTree;
using Artemis.UI.Screens.ProfileEditor.Visualization;
using Artemis.UI.Shared.Services;
using MaterialDesignThemes.Wpf;
using Newtonsoft.Json;
using Stylet;
namespace Artemis.UI.Screens.ProfileEditor
@ -193,10 +194,23 @@ namespace Artemis.UI.Screens.ProfileEditor
{
profile.Name = name;
_profileEditorService.UpdateSelectedProfile();
SelectedProfile.Update();
// The descriptors are immutable and need to be reloaded to reflect the name change
LoadProfiles();
SelectedProfile = Profiles.FirstOrDefault(p => p.Id == _profileEditorService.SelectedProfile.EntityId) ?? Profiles.FirstOrDefault();
}
}
public void DuplicateActiveProfile()
{
string encoded = _profileService.ExportProfile(SelectedProfile);
ProfileDescriptor copy = _profileService.ImportProfile(encoded, Module, "copy");
Profiles.Add(copy);
Profiles.Sort(p => p.Name);
SelectedProfile = copy;
}
public async Task ExportActiveProfile()
{
await DialogService.ShowDialog<ProfileExportViewModel>(new Dictionary<string, object>