1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-31 17:53:32 +00:00

Profile import/clone fixes

Fixed importing a default profile not setting the IsDefault flag to false
Fixed duplicating a profile not cloning the layers
This commit is contained in:
SpoinkyNL 2016-07-20 08:19:28 +02:00
parent 11035f7920
commit 20eca5e849
3 changed files with 9 additions and 19 deletions

View File

@ -50,13 +50,7 @@ namespace Artemis.Utilities
if (ReferenceEquals(source, null)) if (ReferenceEquals(source, null))
return default(T); return default(T);
var deserializeSettings = new JsonSerializerSettings return (T)JsonConvert.DeserializeObject(JsonConvert.SerializeObject(source), source.GetType());
{
ObjectCreationHandling = ObjectCreationHandling.Replace,
TypeNameHandling = TypeNameHandling.Auto
};
return (T) JsonConvert.DeserializeObject(JsonConvert.SerializeObject(source), source.GetType(),
deserializeSettings);
} }
public static object GetPropertyValue(object o, string path) public static object GetPropertyValue(object o, string path)

View File

@ -217,20 +217,17 @@ namespace Artemis.ViewModels.Profiles
foreach (var conditionViewModel in LayerConditionVms) foreach (var conditionViewModel in LayerConditionVms)
ProposedLayer.Properties.Conditions.Add(conditionViewModel.LayerConditionModel); 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 not a keyboard, ignore size and position
if (ProposedLayer.LayerType.DrawType != DrawType.Keyboard) if (ProposedLayer.LayerType.DrawType != DrawType.Keyboard)
{ {
ProposedLayer.Properties.Width = currentNoChildren.Properties.Width; ProposedLayer.Properties.Width = Layer.Properties.Width;
ProposedLayer.Properties.Height = currentNoChildren.Properties.Height; ProposedLayer.Properties.Height = Layer.Properties.Height;
ProposedLayer.Properties.X = currentNoChildren.Properties.X; ProposedLayer.Properties.X = Layer.Properties.X;
ProposedLayer.Properties.Y = currentNoChildren.Properties.Y; ProposedLayer.Properties.Y = Layer.Properties.Y;
ProposedLayer.Properties.Contain = currentNoChildren.Properties.Contain; 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); var proposed = JsonConvert.SerializeObject(ProposedLayer, Formatting.Indented);
if (current.Equals(proposed)) if (current.Equals(proposed))

View File

@ -414,8 +414,6 @@ namespace Artemis.ViewModels.Profiles
{ {
var clone = GeneralHelpers.Clone(layer); var clone = GeneralHelpers.Clone(layer);
layer.InsertAfter(clone); layer.InsertAfter(clone);
foreach (var layerModel in layer.Children)
clone.Children.Add(GeneralHelpers.Clone(layerModel));
UpdateLayerList(clone); UpdateLayerList(clone);
} }
@ -642,9 +640,10 @@ namespace Artemis.ViewModels.Profiles
profile.KeyboardSlug = deviceManager.ActiveKeyboard.Slug; profile.KeyboardSlug = deviceManager.ActiveKeyboard.Slug;
profile.Width = deviceManager.ActiveKeyboard.Width; profile.Width = deviceManager.ActiveKeyboard.Width;
profile.Height = deviceManager.ActiveKeyboard.Height; profile.Height = deviceManager.ActiveKeyboard.Height;
profile.IsDefault = false;
} }
profile.IsDefault = false;
// Verify the name // Verify the name
while (ProfileProvider.GetAll().Contains(profile)) while (ProfileProvider.GetAll().Contains(profile))
{ {