Kaynağa Gözat

Now moving folders fully work*

flabbet 4 yıl önce
ebeveyn
işleme
5274d384d9

+ 2 - 0
PixiEditor/Models/Layers/GuidStructureItem.cs

@@ -1,10 +1,12 @@
 using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
+using System.Diagnostics;
 using PixiEditor.Helpers;
 
 namespace PixiEditor.Models.Layers
 {
+    [DebuggerDisplay("{Name} - {FolderGuid}")]
     public class GuidStructureItem : NotifyableObject
     {
         public Guid FolderGuid { get; init; }

+ 22 - 7
PixiEditor/Models/Layers/LayerStructure.cs

@@ -76,14 +76,24 @@ namespace PixiEditor.Models.Layers
             {
                 if (folder.StartLayerGuid != null && folder.EndLayerGuid != null)
                 {
-                    Guid? topBoundLayer = FindBoundLayer(parentFolder, (Guid)folder.StartLayerGuid, false);
-                    Guid? bottomBoundLayer = FindBoundLayer(parentFolder, (Guid)folder.EndLayerGuid, true);
+                    int folderTopIndex = Owner.Layers.IndexOf(Owner.Layers.First(x => x.LayerGuid == folder.EndLayerGuid));
+                    int folderBottomIndex = Owner.Layers.IndexOf(Owner.Layers.First(x => x.LayerGuid == folder.StartLayerGuid));
+
+                    int parentFolderTopIndex = Owner.Layers.IndexOf(Owner.Layers.First(x => x.LayerGuid == parentFolder.EndLayerGuid));
+                    int parentFolderBottomIndex = Owner.Layers.IndexOf(Owner.Layers.First(x => x.LayerGuid == parentFolder.StartLayerGuid));
+
+                    int finalTopIndex = Math.Max(folderTopIndex, parentFolderTopIndex);
+                    int finalBottomIndex = Math.Min(folderBottomIndex, parentFolderBottomIndex);
+
+                    Guid? topBoundLayer = FindBoundLayer((Guid)folder.StartLayerGuid, finalTopIndex, finalBottomIndex, false);
+                    Guid? bottomBoundLayer = FindBoundLayer((Guid)folder.EndLayerGuid, finalTopIndex, finalBottomIndex, true);
 
                     if (topBoundLayer == parentFolder.EndLayerGuid)
                     {
                         parentFolder.EndLayerGuid = folder.EndLayerGuid;
                     }
-                    else if (bottomBoundLayer == parentFolder.StartLayerGuid)
+
+                    if (bottomBoundLayer == parentFolder.StartLayerGuid)
                     {
                         parentFolder.StartLayerGuid = folder.StartLayerGuid;
                     }
@@ -107,15 +117,20 @@ namespace PixiEditor.Models.Layers
             }
         }
 
+        private Guid? FindBoundLayer(Guid layerGuid, int parentFolderTopIndex, int parentFolderBottomIndex, bool above)
+        {
+            return GetNextLayerGuid(
+                   layerGuid,
+                   GetLayersInOrder(new FolderData(parentFolderTopIndex, parentFolderBottomIndex)),
+                   above);
+        }
+
         private Guid? FindBoundLayer(GuidStructureItem parentFolder, Guid layerGuid, bool above)
         {
             int parentFolderTopIndex = Owner.Layers.IndexOf(Owner.Layers.First(x => x.LayerGuid == parentFolder.EndLayerGuid));
             int parentFolderBottomIndex = Owner.Layers.IndexOf(Owner.Layers.First(x => x.LayerGuid == parentFolder.StartLayerGuid));
 
-            return GetNextLayerGuid(
-                    layerGuid,
-                    GetLayersInOrder(new FolderData(parentFolderTopIndex, parentFolderBottomIndex)),
-                    above);
+            return FindBoundLayer(layerGuid, parentFolderTopIndex, parentFolderBottomIndex, above);
         }
 
         private Guid? GetNextLayerGuid(Guid? layer, List<Guid> allLayers, bool above)