11using System ;
22using System . Linq ;
3+ using Avalonia ;
34using Avalonia . Controls ;
45using Avalonia . Input ;
56using Avalonia . Markup . Xaml ;
67using Avalonia . VisualTree ;
78using DynamicData . Binding ;
89using StabilityMatrix . Avalonia . Controls ;
910using StabilityMatrix . Avalonia . ViewModels ;
11+ using StabilityMatrix . Avalonia . ViewModels . CheckpointManager ;
1012using StabilityMatrix . Core . Attributes ;
13+ using StabilityMatrix . Core . Models . FileInterfaces ;
1114using CheckpointFolder = StabilityMatrix . Avalonia . ViewModels . CheckpointManager . CheckpointFolder ;
1215
1316namespace StabilityMatrix . Avalonia . Views ;
@@ -59,12 +62,36 @@ private void InvalidateRepeater()
5962 }
6063 }
6164
62- private static async void OnDrop ( object ? sender , DragEventArgs e )
65+ private async void OnDrop ( object ? sender , DragEventArgs e )
6366 {
6467 var sourceDataContext = ( e . Source as Control ) ? . DataContext ;
65- if ( sourceDataContext is CheckpointFolder folder )
68+ switch ( sourceDataContext )
6669 {
67- await folder . OnDrop ( e ) ;
70+ case CheckpointFolder folder :
71+ {
72+ if ( e . Data . Get ( "Context" ) is not CheckpointFile file )
73+ return ;
74+
75+ var filePath = new FilePath ( file . FilePath ) ;
76+ if ( filePath . Directory ? . FullPath != folder . DirectoryPath )
77+ {
78+ await folder . OnDrop ( e ) ;
79+ }
80+ break ;
81+ }
82+ case CheckpointFile file :
83+ {
84+ if ( e . Data . Get ( "Context" ) is not CheckpointFile dragFile )
85+ return ;
86+
87+ var parentFolder = file . ParentFolder ;
88+ var dragFilePath = new FilePath ( dragFile . FilePath ) ;
89+ if ( dragFilePath . Directory ? . FullPath != parentFolder . DirectoryPath )
90+ {
91+ await parentFolder . OnDrop ( e ) ;
92+ }
93+ break ;
94+ }
6895 }
6996 }
7097
@@ -77,7 +104,7 @@ private static void OnDragExit(object? sender, DragEventArgs e)
77104 }
78105 }
79106
80- private static void OnDragEnter ( object ? sender , DragEventArgs e )
107+ private void OnDragEnter ( object ? sender , DragEventArgs e )
81108 {
82109 // Only allow Copy or Link as Drop Operations.
83110 e . DragEffects &= DragDropEffects . Copy | DragDropEffects . Link ;
@@ -90,10 +117,29 @@ private static void OnDragEnter(object? sender, DragEventArgs e)
90117
91118 // Forward to view model
92119 var sourceDataContext = ( e . Source as Control ) ? . DataContext ;
93- if ( sourceDataContext is CheckpointFolder folder )
120+ switch ( sourceDataContext )
94121 {
95- folder . IsExpanded = true ;
96- folder . IsCurrentDragTarget = true ;
122+ case CheckpointFolder folder :
123+ {
124+ folder . IsExpanded = true ;
125+ if ( e . Data . Get ( "Context" ) is not CheckpointFile file )
126+ return ;
127+
128+ var filePath = new FilePath ( file . FilePath ) ;
129+ folder . IsCurrentDragTarget = filePath . Directory ? . FullPath != folder . DirectoryPath ;
130+ break ;
131+ }
132+ case CheckpointFile file :
133+ {
134+ if ( e . Data . Get ( "Context" ) is not CheckpointFile dragFile )
135+ return ;
136+
137+ var parentFolder = file . ParentFolder ;
138+ var dragFilePath = new FilePath ( dragFile . FilePath ) ;
139+ parentFolder . IsCurrentDragTarget =
140+ dragFilePath . Directory ? . FullPath != parentFolder . DirectoryPath ;
141+ break ;
142+ }
97143 }
98144 }
99145
0 commit comments