Browse Source

Fixed groups exception

flabbet 3 years ago
parent
commit
34318c0324

+ 2 - 0
PixiEditor/Models/DataHolders/WpfObservableRangeCollection.cs

@@ -11,6 +11,7 @@ namespace PixiEditor.Models.DataHolders
 {
 {
 public class WpfObservableRangeCollection<T> : RangeObservableCollection<T>
 public class WpfObservableRangeCollection<T> : RangeObservableCollection<T>
 {
 {
+        public bool SuppressNotify { get; set; } = false;
   DeferredEventsCollection _deferredEvents;
   DeferredEventsCollection _deferredEvents;
 
 
   public WpfObservableRangeCollection()
   public WpfObservableRangeCollection()
@@ -37,6 +38,7 @@ public class WpfObservableRangeCollection<T> : RangeObservableCollection<T>
   /// </remarks>
   /// </remarks>
   protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   {
   {
+            if (SuppressNotify) return;
     var _deferredEvents = (ICollection<NotifyCollectionChangedEventArgs>) typeof(RangeObservableCollection<T>)
     var _deferredEvents = (ICollection<NotifyCollectionChangedEventArgs>) typeof(RangeObservableCollection<T>)
       .GetField("_deferredEvents", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this);
       .GetField("_deferredEvents", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this);
     if (_deferredEvents != null)
     if (_deferredEvents != null)

+ 4 - 0
PixiEditor/Models/Undo/StorageBasedChange.cs

@@ -260,9 +260,13 @@ namespace PixiEditor.Models.Undo
                 for (int i = 0; i < layers.Length; i++)
                 for (int i = 0; i < layers.Length; i++)
                 {
                 {
                     Layer layer = layers[i];
                     Layer layer = layers[i];
+                    document.Layers.SuppressNotify = true;
                     document.Layers.RemoveAt(data[i].LayerIndex);
                     document.Layers.RemoveAt(data[i].LayerIndex);
+                    document.Layers.SuppressNotify = false;
 
 
                     document.Layers.Insert(data[i].LayerIndex, layer);
                     document.Layers.Insert(data[i].LayerIndex, layer);
+
+
                     if (data[i].IsActive)
                     if (data[i].IsActive)
                     {
                     {
                         document.SetMainActiveLayer(data[i].LayerIndex);
                         document.SetMainActiveLayer(data[i].LayerIndex);

+ 0 - 1
PixiEditor/ViewModels/SubViewModels/Main/LayersViewModel.cs

@@ -180,7 +180,6 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
                 doc.MoveLayerInStructure(doc.Layers[^1].LayerGuid, lastActiveLayerGuid, true);
                 doc.MoveLayerInStructure(doc.Layers[^1].LayerGuid, lastActiveLayerGuid, true);
                 Guid? parent = parameter is Layer or LayerStructureItemContainer ? activeLayerParent?.GroupGuid : activeLayerParent.Parent?.GroupGuid;
                 Guid? parent = parameter is Layer or LayerStructureItemContainer ? activeLayerParent?.GroupGuid : activeLayerParent.Parent?.GroupGuid;
                 doc.LayerStructure.AssignParent(doc.ActiveLayerGuid, parent);
                 doc.LayerStructure.AssignParent(doc.ActiveLayerGuid, parent);
-                doc.UndoManager.UndoStack.Pop();
             }
             }
             if (control != null)
             if (control != null)
             {
             {