ソースを参照

Now new layer is created above selected item, no matter collapse state

flabbet 4 年 前
コミット
5b112a0a77
1 ファイル変更4 行追加11 行削除
  1. 4 11
      PixiEditor/ViewModels/SubViewModels/Main/LayersViewModel.cs

+ 4 - 11
PixiEditor/ViewModels/SubViewModels/Main/LayersViewModel.cs

@@ -151,13 +151,9 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
         public void NewLayer(object parameter)
         {
             GuidStructureItem control = GetGroupFromParameter(parameter);
-            bool isCollapsed = false;
-            if (control != null)
-            {
-                isCollapsed = !control.IsExpanded;
-            }
             var doc = Owner.BitmapManager.ActiveDocument;
             var activeLayerParent = doc.LayerStructure.GetGroupByLayer(doc.ActiveLayerGuid);
+
             Guid lastActiveLayerGuid = doc.ActiveLayerGuid;
 
             doc.AddNewLayer($"New Layer {Owner.BitmapManager.ActiveDocument.Layers.Count}");
@@ -165,16 +161,13 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             if (doc.Layers.Count > 1)
             {
                 doc.MoveLayerInStructure(doc.Layers[^1].LayerGuid, lastActiveLayerGuid, true);
-                if (isCollapsed)
-                {
-                    doc.LayerStructure.AssignParent(doc.ActiveLayerGuid, control.Parent?.GroupGuid);
-                }
-
+                Guid? parent = parameter is Layer or LayerStructureItemContainer ? activeLayerParent?.GroupGuid : activeLayerParent.Parent?.GroupGuid;
+                doc.LayerStructure.AssignParent(doc.ActiveLayerGuid, parent);
                 doc.UndoManager.UndoStack.Pop();
             }
             if (control != null)
             {
-                control.IsExpanded = !isCollapsed;
+                control.IsExpanded = true;
                 doc.RaisePropertyChange(nameof(doc.LayerStructure));
             }
         }