From 20eca5e8497d8489a6ccc8fd88e7ba20d9d00b31 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Wed, 20 Jul 2016 08:19:28 +0200 Subject: [PATCH] Profile import/clone fixes Fixed importing a default profile not setting the IsDefault flag to false Fixed duplicating a profile not cloning the layers --- Artemis/Artemis/Utilities/GeneralHelpers.cs | 8 +------- .../ViewModels/Profiles/LayerEditorViewModel.cs | 15 ++++++--------- .../ViewModels/Profiles/ProfileEditorViewModel.cs | 5 ++--- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/Artemis/Artemis/Utilities/GeneralHelpers.cs b/Artemis/Artemis/Utilities/GeneralHelpers.cs index 58fb17d1d..29cba4b2a 100644 --- a/Artemis/Artemis/Utilities/GeneralHelpers.cs +++ b/Artemis/Artemis/Utilities/GeneralHelpers.cs @@ -50,13 +50,7 @@ namespace Artemis.Utilities if (ReferenceEquals(source, null)) return default(T); - var deserializeSettings = new JsonSerializerSettings - { - ObjectCreationHandling = ObjectCreationHandling.Replace, - TypeNameHandling = TypeNameHandling.Auto - }; - return (T) JsonConvert.DeserializeObject(JsonConvert.SerializeObject(source), source.GetType(), - deserializeSettings); + return (T)JsonConvert.DeserializeObject(JsonConvert.SerializeObject(source), source.GetType()); } public static object GetPropertyValue(object o, string path) diff --git a/Artemis/Artemis/ViewModels/Profiles/LayerEditorViewModel.cs b/Artemis/Artemis/ViewModels/Profiles/LayerEditorViewModel.cs index 0dfea8c36..b2218c502 100644 --- a/Artemis/Artemis/ViewModels/Profiles/LayerEditorViewModel.cs +++ b/Artemis/Artemis/ViewModels/Profiles/LayerEditorViewModel.cs @@ -217,20 +217,17 @@ namespace Artemis.ViewModels.Profiles foreach (var conditionViewModel in LayerConditionVms) ProposedLayer.Properties.Conditions.Add(conditionViewModel.LayerConditionModel); - // Ignore children on the comparison - var currentNoChildren = GeneralHelpers.Clone(Layer); - currentNoChildren.Children.Clear(); // If not a keyboard, ignore size and position if (ProposedLayer.LayerType.DrawType != DrawType.Keyboard) { - ProposedLayer.Properties.Width = currentNoChildren.Properties.Width; - ProposedLayer.Properties.Height = currentNoChildren.Properties.Height; - ProposedLayer.Properties.X = currentNoChildren.Properties.X; - ProposedLayer.Properties.Y = currentNoChildren.Properties.Y; - ProposedLayer.Properties.Contain = currentNoChildren.Properties.Contain; + ProposedLayer.Properties.Width = Layer.Properties.Width; + ProposedLayer.Properties.Height = Layer.Properties.Height; + ProposedLayer.Properties.X = Layer.Properties.X; + ProposedLayer.Properties.Y = Layer.Properties.Y; + ProposedLayer.Properties.Contain = Layer.Properties.Contain; } - var current = JsonConvert.SerializeObject(currentNoChildren, Formatting.Indented); + var current = JsonConvert.SerializeObject(Layer, Formatting.Indented); var proposed = JsonConvert.SerializeObject(ProposedLayer, Formatting.Indented); if (current.Equals(proposed)) diff --git a/Artemis/Artemis/ViewModels/Profiles/ProfileEditorViewModel.cs b/Artemis/Artemis/ViewModels/Profiles/ProfileEditorViewModel.cs index 3e2929dd5..34a272f6e 100644 --- a/Artemis/Artemis/ViewModels/Profiles/ProfileEditorViewModel.cs +++ b/Artemis/Artemis/ViewModels/Profiles/ProfileEditorViewModel.cs @@ -414,8 +414,6 @@ namespace Artemis.ViewModels.Profiles { var clone = GeneralHelpers.Clone(layer); layer.InsertAfter(clone); - foreach (var layerModel in layer.Children) - clone.Children.Add(GeneralHelpers.Clone(layerModel)); UpdateLayerList(clone); } @@ -642,9 +640,10 @@ namespace Artemis.ViewModels.Profiles profile.KeyboardSlug = deviceManager.ActiveKeyboard.Slug; profile.Width = deviceManager.ActiveKeyboard.Width; profile.Height = deviceManager.ActiveKeyboard.Height; - profile.IsDefault = false; } + profile.IsDefault = false; + // Verify the name while (ProfileProvider.GetAll().Contains(profile)) {