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

Profile import - Fixed and streamlined functionality

This commit is contained in:
SpoinkyNL 2020-09-25 21:32:53 +02:00
parent a5455c26d6
commit 8294cc306a
4 changed files with 24 additions and 5 deletions

View File

@ -236,7 +236,8 @@ namespace Artemis.Core.Services
var profileEntity = JsonConvert.DeserializeObject<ProfileEntity>(json, ExportSettings);
// Assign a new GUID to make sure it is unique in case of a previous import of the same content
profileEntity.Id = Guid.NewGuid();
profileEntity.UpdateGuid(Guid.NewGuid());
profileEntity.Name = $"{profileEntity.Name} - Imported";
_profileRepository.Add(profileEntity);
return new ProfileDescriptor(profileModule, profileEntity);

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace Artemis.Storage.Entities.Profile
{
@ -19,5 +20,15 @@ namespace Artemis.Storage.Entities.Profile
public List<FolderEntity> Folders { get; set; }
public List<LayerEntity> Layers { get; set; }
public void UpdateGuid(Guid guid)
{
var oldGuid = Id;
Id = guid;
var rootFolder = Folders.FirstOrDefault(f => f.ParentId == oldGuid);
if (rootFolder != null)
rootFolder.ParentId = Id;
}
}
}

View File

@ -32,9 +32,9 @@ namespace Artemis.UI.Screens.ProfileEditor.Dialogs
public void Accept()
{
_profileService.ImportProfile(Document.Text, ProfileModule);
var descriptor = _profileService.ImportProfile(Document.Text, ProfileModule);
_mainMessageQueue.Enqueue("Profile imported.");
Session.Close();
Session.Close(descriptor);
}
public void Cancel()

View File

@ -6,6 +6,7 @@ using System.Windows;
using Artemis.Core;
using Artemis.Core.Modules;
using Artemis.Core.Services;
using Artemis.UI.Extensions;
using Artemis.UI.Screens.ProfileEditor.Dialogs;
using Artemis.UI.Screens.ProfileEditor.DisplayConditions;
using Artemis.UI.Screens.ProfileEditor.LayerProperties;
@ -58,7 +59,7 @@ namespace Artemis.UI.Screens.ProfileEditor
DialogService = dialogService;
Profiles = new BindableCollection<ProfileDescriptor>();
// Populate the panels
ProfileViewModel = profileViewModel;
ProfileTreeViewModel = profileTreeViewModel;
@ -190,10 +191,16 @@ namespace Artemis.UI.Screens.ProfileEditor
public async Task ImportProfile()
{
await DialogService.ShowDialog<ProfileImportViewModel>(new Dictionary<string, object>
var result = await DialogService.ShowDialog<ProfileImportViewModel>(new Dictionary<string, object>
{
{"profileModule", Module}
});
if (result != null && result is ProfileDescriptor descriptor)
{
Profiles.Add(descriptor);
Profiles.Sort(p => p.Name);
}
}
public void Undo()