|
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Collections.ObjectModel;
|
|
using System.Globalization;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
|
+using System.Windows;
|
|
using System.Windows.Data;
|
|
using System.Windows.Data;
|
|
|
|
|
|
namespace PixiEditor.Helpers.Converters
|
|
namespace PixiEditor.Helpers.Converters
|
|
@@ -12,7 +13,8 @@ namespace PixiEditor.Helpers.Converters
|
|
public class LayersToStructuredLayersConverter : IMultiValueConverter
|
|
public class LayersToStructuredLayersConverter : IMultiValueConverter
|
|
{
|
|
{
|
|
private static StructuredLayerTree cachedTree;
|
|
private static StructuredLayerTree cachedTree;
|
|
- private List<Guid> lastLayers = new List<Guid>();
|
|
|
|
|
|
+ private List<Guid> lastLayerGuids = new List<Guid>();
|
|
|
|
+ private IList<Layer> lastLayers = new List<Layer>();
|
|
private ObservableCollection<GuidStructureItem> lastStructure = new ObservableCollection<GuidStructureItem>();
|
|
private ObservableCollection<GuidStructureItem> lastStructure = new ObservableCollection<GuidStructureItem>();
|
|
|
|
|
|
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
|
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
|
@@ -24,18 +26,21 @@ namespace PixiEditor.Helpers.Converters
|
|
cachedTree = new StructuredLayerTree(layers, structure);
|
|
cachedTree = new StructuredLayerTree(layers, structure);
|
|
}
|
|
}
|
|
|
|
|
|
- if (TryFindStructureDifferences(structure) || lastLayers.Count != layers.Count || LayerOrderIsDifferent(layers))
|
|
|
|
|
|
+ if (TryFindStructureDifferences(structure) ||
|
|
|
|
+ lastLayerGuids.Count != layers.Count ||
|
|
|
|
+ LayerOrderIsDifferent(layers) ||
|
|
|
|
+ LayersAreDifferentObjects(layers, lastLayers))
|
|
{
|
|
{
|
|
cachedTree = new StructuredLayerTree(layers, structure);
|
|
cachedTree = new StructuredLayerTree(layers, structure);
|
|
-
|
|
|
|
- lastLayers = layers.Select(x => x.LayerGuid).ToList();
|
|
|
|
|
|
+ lastLayers = layers;
|
|
|
|
+ lastLayerGuids = layers.Select(x => x.LayerGuid).ToList();
|
|
lastStructure = structure.CloneGroups();
|
|
lastStructure = structure.CloneGroups();
|
|
}
|
|
}
|
|
|
|
|
|
return cachedTree.RootDirectoryItems;
|
|
return cachedTree.RootDirectoryItems;
|
|
}
|
|
}
|
|
|
|
|
|
- return new StructuredLayerTree(null, null);
|
|
|
|
|
|
+ return DependencyProperty.UnsetValue;
|
|
}
|
|
}
|
|
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
|
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
|
{
|
|
{
|
|
@@ -44,7 +49,21 @@ namespace PixiEditor.Helpers.Converters
|
|
private bool LayerOrderIsDifferent(IList<Layer> layers)
|
|
private bool LayerOrderIsDifferent(IList<Layer> layers)
|
|
{
|
|
{
|
|
var guids = layers.Select(x => x.LayerGuid).ToArray();
|
|
var guids = layers.Select(x => x.LayerGuid).ToArray();
|
|
- return !guids.SequenceEqual(lastLayers);
|
|
|
|
|
|
+ return !guids.SequenceEqual(lastLayerGuids);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// This should trigger if you open and close the same files twice.
|
|
|
|
+ /// Even though the layers are technically the same, having two different objects screws things up down the line.
|
|
|
|
+ /// </summary>
|
|
|
|
+ private bool LayersAreDifferentObjects(IList<Layer> layers, IList<Layer> lastLayers)
|
|
|
|
+ {
|
|
|
|
+ for (int i = 0; i < layers.Count; i++)
|
|
|
|
+ {
|
|
|
|
+ if (layers[i] != lastLayers[i])
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
private bool TryFindStructureDifferences(LayerStructure structure)
|
|
private bool TryFindStructureDifferences(LayerStructure structure)
|
|
{
|
|
{
|