Browse Source

Fixed insta dropping folders to bottom

Krzysztof Krysiński 1 month ago
parent
commit
fec413e5cf

+ 6 - 3
src/PixiEditor/Views/Layers/FolderControl.axaml

@@ -41,10 +41,10 @@
                 <RowDefinition Height="10" />
             </Grid.RowDefinitions>
             <Grid DragDrop.AllowDrop="True" IsVisible="False" Name="TopDropGrid" Grid.Row="0" Grid.ColumnSpan="3"
-                  Background="Transparent" Panel.ZIndex="3" />
+                  Background="Transparent" Panel.ZIndex="5" />
             <Grid IsVisible="False" Margin="20, 0, 0,0" x:Name="middleDropGrid" Grid.Row="1" DragDrop.AllowDrop="True"
-                  Panel.ZIndex="2" Background="Transparent" />
-            <Grid x:Name="centerGrid" Grid.Row="0" Grid.RowSpan="3" Background="Transparent">
+                  Panel.ZIndex="5" Background="Transparent" />
+            <Grid x:Name="centerGrid" ZIndex="3" Grid.Row="0" DragDrop.AllowDrop="True" Grid.RowSpan="3" Background="Transparent">
                 <Grid.ColumnDefinitions>
                     <ColumnDefinition Width="24" />
                     <ColumnDefinition Width="*" />
@@ -141,8 +141,11 @@
                 Grid.Row="2"
                 Name="BottomDropGrid"
                 IsVisible="False"
+                Panel.ZIndex="5"
                 DragDrop.AllowDrop="True"
                 Grid.ColumnSpan="2" Background="Transparent" />
+            <Panel Grid.Row="0" Grid.Column="0" Grid.RowSpan="3" Name="BackgroundGrid" 
+                   Background="Transparent" DragDrop.AllowDrop="True"/>
         </Grid>
         <Border.ContextMenu>
             <ContextMenu>

+ 16 - 1
src/PixiEditor/Views/Layers/FolderControl.axaml.cs

@@ -3,6 +3,7 @@ using Avalonia.Controls;
 using Avalonia.Input;
 using Avalonia.Interactivity;
 using Avalonia.Media;
+using Avalonia.Threading;
 using PixiEditor.Models.Controllers.InputDevice;
 using PixiEditor.Models.Layers;
 using PixiEditor.ViewModels.Document;
@@ -61,6 +62,9 @@ internal partial class FolderControl : UserControl
         middleDropGrid.AddHandler(DragDrop.DragLeaveEvent, Grid_CenterLeave);
         middleDropGrid.AddHandler(DragDrop.DropEvent, Grid_Drop_Center);
 
+        BackgroundGrid.AddHandler(DragDrop.DropEvent, BackgroundGrid_Drop);
+        centerGrid.AddHandler(DragDrop.DropEvent, BackgroundGrid_Drop);
+
         DisableDropPanels();
     }
 
@@ -71,6 +75,16 @@ internal partial class FolderControl : UserControl
         BottomDropGrid.IsVisible = false;
     }
 
+
+    private void BackgroundGrid_Drop(object sender, DragEventArgs e)
+    {
+        Guid[]? droppedGuids = LayerControl.ExtractMemberGuids(e.Data);
+        if (droppedGuids != null && droppedGuids.Contains(Folder.Id))
+        {
+            e.Handled = true;
+        }
+    }
+
     private void OnUnloaded(object? sender, RoutedEventArgs e)
     {
         mouseUpdateController?.Dispose();
@@ -111,7 +125,8 @@ internal partial class FolderControl : UserControl
             return false;
 
         var document = Folder.Document;
-        if (placement is StructureMemberPlacement.Below or StructureMemberPlacement.BelowOutsideFolder or StructureMemberPlacement.Inside)
+        if (placement is StructureMemberPlacement.Below or StructureMemberPlacement.BelowOutsideFolder
+            or StructureMemberPlacement.Inside)
         {
             droppedGuids = droppedGuids.Reverse().ToArray();
         }