Browse Source

Added drag drop events to layer control

Krzysztof Krysiński 1 year ago
parent
commit
67aa34b5ef

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

@@ -22,7 +22,6 @@ internal partial class FolderControl : UserControl
     }
 
     public static string? FolderControlDataName = typeof(FolderControl).FullName;
-    public static string? LayerControlDataName = typeof(LayerControl).FullName;
 
     public static readonly StyledProperty<LayersManager> ManagerProperty =
         AvaloniaProperty.Register<FolderControl, LayersManager>(nameof(Manager));

+ 5 - 3
src/PixiEditor.AvaloniaUI/Views/Layers/LayerControl.axaml

@@ -41,7 +41,7 @@
                 <RowDefinition Height="10"/>
                 <RowDefinition Height="26"/>
             </Grid.RowDefinitions>
-            <Grid DragDrop.AllowDrop="True" Grid.Row="0" Grid.ColumnSpan="3" Background="Transparent"/>
+            <Grid DragDrop.AllowDrop="True" helpers:DragDropEvents.DragEnter="Grid_DragEnter" helpers:DragDropEvents.Drop="Grid_Drop_Top" helpers:DragDropEvents.DragLeave="Grid_DragLeave" Grid.Row="0" Grid.ColumnSpan="3" Background="Transparent"/>
             <Grid Grid.Row="1" Margin="0,-17,0,0" VerticalAlignment="Center" DragDrop.AllowDrop="False">
                 <Grid.ColumnDefinitions>
                     <ColumnDefinition Width="24"/>
@@ -136,10 +136,12 @@
                             IsVisible="{Binding Layer.LockTransparencyBindable, ElementName=uc}"/>
                     </WrapPanel>
                 </StackPanel>
-                <Grid Margin="0, 0, 0, -2.5" VerticalAlignment="Bottom" Height="10" Grid.Row="2" Grid.Column="0" DragDrop.AllowDrop="True"  Background="Transparent" Name="dropBelowGrid"/>
+                <Grid Margin="0, 0, 0, -2.5" helpers:DragDropEvents.DragEnter="Grid_DragEnter" VerticalAlignment="Bottom" helpers:DragDropEvents.Drop="Grid_Drop_Below"  helpers:DragDropEvents.DragLeave="Grid_DragLeave" Height="10" Grid.Row="2" Grid.Column="0" DragDrop.AllowDrop="True"  Background="Transparent" Name="dropBelowGrid"/>
                 <Grid Margin="0, 0, 0, -2.5" VerticalAlignment="Bottom" Height="10" Grid.Row="2" Grid.Column="1" Background="{Binding ElementName=dropBelowGrid, Path=Background}"/>
 
-                <Grid Margin="0, 0, 0, -2.5" VerticalAlignment="Bottom" Height="10" Grid.Row="2" Grid.Column="2" DragDrop.AllowDrop="True"  Background="Transparent"/>
+                <Grid Margin="0, 0, 0, -2.5" VerticalAlignment="Bottom" Height="10" Grid.Row="2" Grid.Column="2"
+                      helpers:DragDropEvents.DragEnter="Grid_DragEnter" helpers:DragDropEvents.Drop="Grid_Drop_Bottom" helpers:DragDropEvents.DragLeave="Grid_DragLeave"
+                      DragDrop.AllowDrop="True"  Background="Transparent"/>
             </Grid>
         </Grid>
         <Border.ContextMenu>

+ 23 - 22
src/PixiEditor.AvaloniaUI/Views/Layers/LayerControl.axaml.cs

@@ -12,73 +12,75 @@ namespace PixiEditor.AvaloniaUI.Views.Layers;
 #nullable enable
 internal partial class LayerControl : UserControl
 {
-   public static readonly StyledProperty<LayerViewModel> LayerProperty =
+    public static string? LayerControlDataName = typeof(LayerControl).FullName;
+
+    public static readonly StyledProperty<LayerViewModel> LayerProperty =
         AvaloniaProperty.Register<LayerControl, LayerViewModel>(nameof(Layer));
 
-   public LayerViewModel Layer
+    public LayerViewModel Layer
     {
         get => GetValue(LayerProperty);
         set => SetValue(LayerProperty, value);
     }
 
-   private readonly IBrush? highlightColor;
+    private readonly IBrush? highlightColor;
 
-   public static readonly StyledProperty<bool> ControlButtonsVisibleProperty =
+    public static readonly StyledProperty<bool> ControlButtonsVisibleProperty =
         AvaloniaProperty.Register<LayerControl, bool>(nameof(ControlButtonsVisible), false);
 
-   public bool ControlButtonsVisible
+    public bool ControlButtonsVisible
     {
         get => GetValue(ControlButtonsVisibleProperty);
         set => SetValue(ControlButtonsVisibleProperty, value);
     }
 
-   public string LayerColor
+    public string LayerColor
     {
         get => GetValue(LayerColorProperty);
         set => SetValue(LayerColorProperty, value);
     }
 
-   public static readonly StyledProperty<string> LayerColorProperty =
+    public static readonly StyledProperty<string> LayerColorProperty =
         AvaloniaProperty.Register<LayerControl, string>(nameof(LayerColor), "#00000000");
 
-   public static readonly StyledProperty<LayersManager> ManagerProperty =
+    public static readonly StyledProperty<LayersManager> ManagerProperty =
         AvaloniaProperty.Register<LayerControl, LayersManager>(nameof(Manager));
 
-   public LayersManager Manager
+    public LayersManager Manager
     {
         get => GetValue(ManagerProperty);
         set => SetValue(ManagerProperty, value);
     }
 
-   public static readonly StyledProperty<RelayCommand> MoveToBackCommandProperty =
+    public static readonly StyledProperty<RelayCommand> MoveToBackCommandProperty =
         AvaloniaProperty.Register<LayerControl, RelayCommand>(nameof(MoveToBackCommand));
 
-   public RelayCommand MoveToBackCommand
+    public RelayCommand MoveToBackCommand
     {
         get => GetValue(MoveToBackCommandProperty);
         set => SetValue(MoveToBackCommandProperty, value);
     }
 
-   public static readonly StyledProperty<RelayCommand> MoveToFrontCommandProperty =
+    public static readonly StyledProperty<RelayCommand> MoveToFrontCommandProperty =
         AvaloniaProperty.Register<LayerControl, RelayCommand>(nameof(MoveToFrontCommand));
 
-   public RelayCommand MoveToFrontCommand
+    public RelayCommand MoveToFrontCommand
     {
         get => GetValue(MoveToFrontCommandProperty);
         set => SetValue(MoveToFrontCommandProperty, value);
     }
 
 
-   private MouseUpdateController mouseUpdateController;
-    
-   public LayerControl()
+    private MouseUpdateController mouseUpdateController;
+
+    public LayerControl()
     {
         InitializeComponent();
         Loaded += LayerControl_Loaded;
         highlightColor = (Brush?)App.Current.Resources["SoftSelectedLayerColor"];
     }
 
-   private void LayerControl_Loaded(object sender, RoutedEventArgs e)
+    private void LayerControl_Loaded(object sender, RoutedEventArgs e)
     {
         mouseUpdateController = new MouseUpdateController(this, Manager.LayerControl_MouseMove);
     }
@@ -96,7 +98,6 @@ internal partial class LayerControl : UserControl
     private void LayerItem_OnMouseLeave(object sender, PointerEventArgs e)
     {
         ControlButtonsVisible = false;
-
     }
 
     private void Grid_DragEnter(object? sender, DragEventArgs e)
@@ -115,7 +116,7 @@ internal partial class LayerControl : UserControl
 
     public static Guid? ExtractMemberGuid(IDataObject droppedMemberDataObject)
     {
-        object droppedLayer = droppedMemberDataObject.Get(FolderControl.LayerControlDataName);
+        object droppedLayer = droppedMemberDataObject.Get(LayerControlDataName);
         object droppedFolder = droppedMemberDataObject.Get(AvaloniaUI.Views.Layers.FolderControl.FolderControlDataName);
         if (droppedLayer is LayerControl layer)
             return layer.Layer.GuidValue;
@@ -152,18 +153,18 @@ internal partial class LayerControl : UserControl
         HandleDrop(e.Data, StructureMemberPlacement.BelowOutsideFolder);
     }
 
-   private void RenameMenuItem_Click(object sender, RoutedEventArgs e)
+    private void RenameMenuItem_Click(object sender, RoutedEventArgs e)
     {
         editableTextBlock.EnableEditing();
     }
 
-   private void MaskMouseDown(object sender, PointerPressedEventArgs e)
+    private void MaskMouseDown(object sender, PointerPressedEventArgs e)
     {
         if (Layer is not null)
             Layer.ShouldDrawOnMask = true;
     }
 
-   private void LayerMouseDown(object sender, PointerPressedEventArgs e)
+    private void LayerMouseDown(object sender, PointerPressedEventArgs e)
     {
         if (Layer is not null)
             Layer.ShouldDrawOnMask = false;

+ 2 - 1
src/PixiEditor.AvaloniaUI/Views/Layers/LayersManager.axaml

@@ -16,6 +16,7 @@
              xmlns:behaviours="clr-namespace:PixiEditor.AvaloniaUI.Helpers.Behaviours"
              xmlns:ui="clr-namespace:PixiEditor.Helpers.UI"
              xmlns:docVm="clr-namespace:PixiEditor.AvaloniaUI.ViewModels.Document"
+             xmlns:ui1="clr-namespace:PixiEditor.AvaloniaUI.Helpers.UI"
              mc:Ignorable="d"
              d:DesignHeight="450" d:DesignWidth="250" x:Name="layersManager">
     <UserControl.Resources>
@@ -174,7 +175,7 @@
                     </DataTemplate>
                 </TreeView.DataTemplates>
             </TreeView>
-            <Border Name="dropBorder" DragDrop.AllowDrop="True" Background="Transparent" BorderThickness="0, 5, 0, 0"></Border>
+            <Border Name="dropBorder" ui1:DragDropEvents.DragEnter="Grid_DragEnter" ui1:DragDropEvents.DragLeave="Grid_DragLeave" DragDrop.AllowDrop="True" ui1:DragDropEvents.Drop="Grid_Drop" Background="Transparent" BorderThickness="0, 5, 0, 0"></Border>
         </DockPanel>
     </Grid>
 </UserControl>

+ 2 - 3
src/PixiEditor.AvaloniaUI/Views/Layers/LayersManager.axaml.cs

@@ -53,8 +53,7 @@ internal partial class LayersManager : UserControl
         if (e.Source is LayerControl container && isLeftPressed && Equals(e.Pointer.Captured, container))
         {
             DataObject data = new();
-            //TODO: Check what dataformat to use
-            data.Set(DataFormats.Text, container);
+            data.Set(LayerControl.LayerControlDataName, container);
             Dispatcher.UIThread.InvokeAsync(() => DragDrop.DoDragDrop(e, data, DragDropEffects.Move));
         }
     }
@@ -95,7 +94,7 @@ internal partial class LayersManager : UserControl
             isLeftPressed && Equals(e.Pointer.Captured, container))
         {
             DataObject data = new();
-            data.Set(DataFormats.Text, container);
+            data.Set(FolderControl.FolderControlDataName, container);
             Dispatcher.UIThread.InvokeAsync(() => DragDrop.DoDragDrop(e, data, DragDropEffects.Move));
         }
     }