Kaynağa Gözat

Fixed remove group crash

flabbet 4 yıl önce
ebeveyn
işleme
198a64e5c9

+ 4 - 0
PixiEditor/Models/DataHolders/Document/Document.Layers.cs

@@ -707,6 +707,10 @@ namespace PixiEditor.Models.DataHolders
 
                 LayerStructure.ExpandParentGroups(layerGroup);
 
+                if (layerGroup?.Parent != null && LayerStructure.GroupContainsOnlyLayer(layer.LayerGuid, layerGroup))
+                {
+                    LayerStructure.PreMoveReassignBounds(new GroupData(layerGroup.Parent.GroupGuid), new GroupData(layerGroup.GroupGuid));
+                }
                 LayerStructure.AssignParent(Layers[index].LayerGuid, null);
                 RemoveGroupsIfEmpty(layer, layerGroup);
 

+ 1 - 1
PixiEditor/Models/Layers/LayerStructure.cs

@@ -284,7 +284,7 @@ namespace PixiEditor.Models.Layers
         /// <param name="group">Group which data should be reassigned.</param>
         public void PostMoveReassignBounds(GroupData parentGroup, GroupData group)
         {
-            PostMoveReassignBounds(GetGroupByGuid(parentGroup.GroupGuid), GetGroupByGuid(group.GroupGuid));
+            PostMoveReassignBounds(GetGroupByGuid(parentGroup?.GroupGuid), GetGroupByGuid(group.GroupGuid));
         }
 
         /// <summary>

+ 8 - 3
PixiEditor/ViewModels/SubViewModels/Main/LayersViewModel.cs

@@ -1,6 +1,7 @@
 using PixiEditor.Helpers;
 using PixiEditor.Models.Controllers;
 using PixiEditor.Models.Layers;
+using PixiEditor.Views;
 using PixiEditor.Views.UserControls;
 using System;
 using System.Linq;
@@ -72,7 +73,7 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
 
         public bool CanDeleteSelected(object parameter)
         {
-            return (parameter is not null and (Layer or LayerGroup)) || (Owner.BitmapManager?.ActiveDocument?.ActiveLayer != null);
+            return (parameter is not null and(Layer or LayerGroup)) || (Owner.BitmapManager?.ActiveDocument?.ActiveLayer != null);
         }
 
         public void DeleteSelected(object parameter)
@@ -81,9 +82,9 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             {
                 DeleteLayer(Owner.BitmapManager.ActiveDocument.Layers.IndexOf(layer));
             }
-            else if (Owner.BitmapManager.ActiveDocument.ActiveLayer != null)
+            else if(parameter is LayerStructureItemContainer container)
             {
-                DeleteLayer(Owner.BitmapManager.ActiveDocument.Layers.IndexOf(Owner.BitmapManager.ActiveDocument.ActiveLayer));
+                DeleteLayer(Owner.BitmapManager.ActiveDocument.Layers.IndexOf(container.Layer));
             }
             else if (parameter is LayerGroup group)
             {
@@ -93,6 +94,10 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             {
                 DeleteGroup(groupControl.GroupGuid);
             }
+            else if (Owner.BitmapManager.ActiveDocument.ActiveLayer != null)
+            {
+                DeleteLayer(Owner.BitmapManager.ActiveDocument.Layers.IndexOf(Owner.BitmapManager.ActiveDocument.ActiveLayer));
+            }
         }
 
         public void DeleteGroup(object parameter)