Skip to content

Commit

Permalink
Fixed guid thing (custom observable collection impl)
Browse files Browse the repository at this point in the history
  • Loading branch information
flabbet committed Dec 8, 2021
1 parent 0f820de commit 33c7224
Show file tree
Hide file tree
Showing 10 changed files with 794 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Globalization;
using System.Linq;
using System.Windows.Data;
using PixiEditor.Models.DataHolders;

namespace PixiEditor.Helpers.Converters
{
Expand All @@ -24,7 +25,7 @@ public override object Convert(object[] values, Type targetType, object paramete

private ObservableCollection<GuidStructureItem> GetSubGroups(IEnumerable<GuidStructureItem> groups)
{
ObservableCollection<GuidStructureItem> finalGroups = new ObservableCollection<GuidStructureItem>();
WpfObservableRangeCollection<GuidStructureItem> finalGroups = new WpfObservableRangeCollection<GuidStructureItem>();
foreach (var group in groups)
{
finalGroups.AddRange(GetSubGroups(group));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Windows;
using System.Windows.Data;
using PixiEditor.Models.DataHolders;

namespace PixiEditor.Helpers.Converters
{
Expand All @@ -16,11 +17,11 @@ public class LayersToStructuredLayersConverter
private static StructuredLayerTree cachedTree;
private List<Guid> lastLayerGuids = new List<Guid>();
private IList<Layer> lastLayers = new List<Layer>();
private ObservableCollection<GuidStructureItem> lastStructure = new ObservableCollection<GuidStructureItem>();
private WpfObservableRangeCollection<GuidStructureItem> lastStructure = new WpfObservableRangeCollection<GuidStructureItem>();

public override object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values[0] is ObservableCollection<Layer> layers && values[1] is LayerStructure structure)
if (values[0] is WpfObservableRangeCollection<Layer> layers && values[1] is LayerStructure structure)
{
if (cachedTree == null)
{
Expand Down
16 changes: 0 additions & 16 deletions PixiEditor/Helpers/Extensions/ObservableCollectionEx.cs

This file was deleted.

8 changes: 4 additions & 4 deletions PixiEditor/Helpers/Extensions/ParserHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public static Document ToDocument(this SerializableDocument serializableDocument
return document;
}

public static ObservableCollection<Layer> ToLayers(this SerializableDocument document)
public static WpfObservableRangeCollection<Layer> ToLayers(this SerializableDocument document)
{
ObservableCollection<Layer> layers = new();
WpfObservableRangeCollection<Layer> layers = new();
foreach (SerializableLayer slayer in document)
{
layers.Add(slayer.ToLayer());
Expand All @@ -50,9 +50,9 @@ public static Layer ToLayer(this SerializableLayer layer)
};
}

public static ObservableCollection<GuidStructureItem> ToGroups(this SerializableDocument sdocument, Document document)
public static WpfObservableRangeCollection<GuidStructureItem> ToGroups(this SerializableDocument sdocument, Document document)
{
ObservableCollection<GuidStructureItem> groups = new();
WpfObservableRangeCollection<GuidStructureItem> groups = new();

if (sdocument.Groups == null)
{
Expand Down
12 changes: 6 additions & 6 deletions PixiEditor/Models/DataHolders/Document/Document.Layers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public partial class Document
private Guid activeLayerGuid;
private LayerStructure layerStructure;

private ObservableCollection<Layer> layers = new();
private WpfObservableRangeCollection<Layer> layers = new();

public ObservableCollection<Layer> Layers
public WpfObservableRangeCollection<Layer> Layers
{
get => layers;
set
Expand Down Expand Up @@ -407,14 +407,14 @@ public void RemoveActiveLayers()

}

public void AddLayerStructureToUndo(ObservableCollection<GuidStructureItem> oldLayerStructureGroups)
public void AddLayerStructureToUndo(WpfObservableRangeCollection<GuidStructureItem> oldLayerStructureGroups)
{
UndoManager.AddUndoChange(
new Change(
BuildLayerStructureProcess,
new[] { oldLayerStructureGroups },
new object[] { oldLayerStructureGroups },
BuildLayerStructureProcess,
new[] { LayerStructure.CloneGroups() }));
new object[] { LayerStructure.CloneGroups() }));
}

public Layer MergeLayers(Layer[] layersToMerge, bool nameOfLast, int index)
Expand Down Expand Up @@ -516,7 +516,7 @@ private void DisposeLayerBitmaps()

private void BuildLayerStructureProcess(object[] parameters)
{
if (parameters.Length > 0 && parameters[0] is ObservableCollection<GuidStructureItem> groups)
if (parameters.Length > 0 && parameters[0] is WpfObservableRangeCollection<GuidStructureItem> groups)
{
LayerStructure.Groups.CollectionChanged -= Groups_CollectionChanged;
LayerStructure.Groups = LayerStructure.CloneGroups(groups);
Expand Down

0 comments on commit 33c7224

Please sign in to comment.