Skip to content

Commit da92d45

Browse files
committed
drag on files too
1 parent f0d401b commit da92d45

File tree

4 files changed

+66
-12
lines changed

4 files changed

+66
-12
lines changed

StabilityMatrix.Avalonia/ViewModels/CheckpointManager/CheckpointFile.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public partial class CheckpointFile : ViewModelBase
5555
[ObservableProperty]
5656
private CivitModelType modelType;
5757

58+
[ObservableProperty]
59+
private CheckpointFolder parentFolder;
60+
5861
public string FileName => Path.GetFileName(FilePath);
5962

6063
public ObservableCollection<string> Badges { get; set; } = new();
@@ -220,6 +223,7 @@ private void OpenOnCivitAi()
220223
/// - {filename}.cm-info.json (connected model info)
221224
/// </summary>
222225
public static IEnumerable<CheckpointFile> FromDirectoryIndex(
226+
CheckpointFolder parentFolder,
223227
string directory,
224228
SearchOption searchOption = SearchOption.TopDirectoryOnly
225229
)
@@ -268,6 +272,8 @@ public static IEnumerable<CheckpointFile> FromDirectoryIndex(
268272
checkpointFile.PreviewImagePath = Assets.NoImage.ToString();
269273
}
270274

275+
checkpointFile.ParentFolder = parentFolder;
276+
271277
yield return checkpointFile;
272278
}
273279
}
@@ -329,13 +335,14 @@ var file in Directory.EnumerateFiles(
329335
/// Index with progress reporting.
330336
/// </summary>
331337
public static IEnumerable<CheckpointFile> FromDirectoryIndex(
338+
CheckpointFolder parentFolder,
332339
string directory,
333340
IProgress<ProgressReport> progress,
334341
SearchOption searchOption = SearchOption.TopDirectoryOnly
335342
)
336343
{
337344
var current = 0ul;
338-
foreach (var checkpointFile in FromDirectoryIndex(directory, searchOption))
345+
foreach (var checkpointFile in FromDirectoryIndex(parentFolder, directory, searchOption))
339346
{
340347
current++;
341348
progress.Report(new ProgressReport(current, "Indexing", checkpointFile.FileName));

StabilityMatrix.Avalonia/ViewModels/CheckpointManager/CheckpointFolder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ private IEnumerable<CheckpointFile> GetCheckpointFiles()
575575
return Enumerable.Empty<CheckpointFile>();
576576
}
577577

578-
return CheckpointFile.FromDirectoryIndex(DirectoryPath);
578+
return CheckpointFile.FromDirectoryIndex(this, DirectoryPath);
579579
}
580580

581581
/// <summary>

StabilityMatrix.Avalonia/Views/CheckpointsPage.axaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<!-- Checkpoint File Card -->
4545
<DataTemplate DataType="{x:Type checkpointManager:CheckpointFile}" x:Key="CheckpointFileDataTemplate">
4646
<Border
47-
DragDrop.AllowDrop="False"
47+
DragDrop.AllowDrop="True"
4848
Background="Transparent"
4949
BorderThickness="2"
5050
Margin="4">
@@ -400,10 +400,10 @@
400400
HorizontalAlignment="Right"
401401
Margin="16,0"
402402
Orientation="Horizontal">
403-
<TextBox Margin="16, 16"
403+
<TextBox Margin="8, 16"
404404
Watermark="{x:Static lang:Resources.Action_Search}"
405405
Height="16"
406-
MinWidth="150"
406+
MinWidth="220"
407407
KeyDown="InputElement_OnKeyDown"
408408
Text="{Binding SearchFilter, Mode=TwoWay}">
409409
<TextBox.InnerRightContent>
@@ -459,6 +459,7 @@
459459
Grid.Column="0"
460460
Grid.ColumnSpan="2"
461461
Grid.Row="1"
462+
x:Name="MainScrollViewer"
462463
HorizontalScrollBarVisibility="Disabled"
463464
VerticalScrollBarVisibility="Auto">
464465
<Grid>

StabilityMatrix.Avalonia/Views/CheckpointsPage.axaml.cs

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
using System;
22
using System.Linq;
3+
using Avalonia;
34
using Avalonia.Controls;
45
using Avalonia.Input;
56
using Avalonia.Markup.Xaml;
67
using Avalonia.VisualTree;
78
using DynamicData.Binding;
89
using StabilityMatrix.Avalonia.Controls;
910
using StabilityMatrix.Avalonia.ViewModels;
11+
using StabilityMatrix.Avalonia.ViewModels.CheckpointManager;
1012
using StabilityMatrix.Core.Attributes;
13+
using StabilityMatrix.Core.Models.FileInterfaces;
1114
using CheckpointFolder = StabilityMatrix.Avalonia.ViewModels.CheckpointManager.CheckpointFolder;
1215

1316
namespace 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

Comments
 (0)