diff --git a/src/Artemis.Core/Models/Profile/ProfileDescriptor.cs b/src/Artemis.Core/Models/Profile/ProfileDescriptor.cs
index 7898eeae2..b59e963c8 100644
--- a/src/Artemis.Core/Models/Profile/ProfileDescriptor.cs
+++ b/src/Artemis.Core/Models/Profile/ProfileDescriptor.cs
@@ -9,12 +9,13 @@ namespace Artemis.Core
///
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;
}
///
@@ -25,26 +26,17 @@ namespace Artemis.Core
///
/// Gets the unique ID of the profile by which it can be loaded from storage
///
- public Guid Id => _profileEntity.Id;
+ public Guid Id { get; }
///
/// Gets the name of the profile
///
- public string Name => _profileEntity.Name;
+ public string Name { get; }
///
/// Gets a boolean indicating whether this was the last active profile
///
- public bool IsLastActiveProfile => _profileEntity.IsActive;
+ public bool IsLastActiveProfile { get; }
- ///
- /// Triggers a property change for all properties linked to the backing profile entity ¯\_(ツ)_/¯
- ///
- public void Update()
- {
- OnPropertyChanged(nameof(Id));
- OnPropertyChanged(nameof(Name));
- OnPropertyChanged(nameof(IsLastActiveProfile));
- }
}
}
\ No newline at end of file
diff --git a/src/Artemis.Core/Services/Storage/Interfaces/IProfileService.cs b/src/Artemis.Core/Services/Storage/Interfaces/IProfileService.cs
index d7a1d9787..bd34ed32b 100644
--- a/src/Artemis.Core/Services/Storage/Interfaces/IProfileService.cs
+++ b/src/Artemis.Core/Services/Storage/Interfaces/IProfileService.cs
@@ -118,7 +118,8 @@ namespace Artemis.Core.Services
///
/// The content of the profile as JSON
/// The module to import the profile in to
+ /// Text to add after the name of the profile (separated by a dash)
///
- ProfileDescriptor ImportProfile(string json, ProfileModule profileModule);
+ ProfileDescriptor ImportProfile(string json, ProfileModule profileModule, string nameAffix = "imported");
}
}
\ No newline at end of file
diff --git a/src/Artemis.Core/Services/Storage/ProfileService.cs b/src/Artemis.Core/Services/Storage/ProfileService.cs
index 098812196..904a6a3a1 100644
--- a/src/Artemis.Core/Services/Storage/ProfileService.cs
+++ b/src/Artemis.Core/Services/Storage/ProfileService.cs
@@ -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(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);
diff --git a/src/Artemis.UI/Screens/ProfileEditor/ProfileEditorViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/ProfileEditorViewModel.cs
index fea7338c5..3812e8c35 100644
--- a/src/Artemis.UI/Screens/ProfileEditor/ProfileEditorViewModel.cs
+++ b/src/Artemis.UI/Screens/ProfileEditor/ProfileEditorViewModel.cs
@@ -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(new Dictionary