Skip to content

Commit 501e3d1

Browse files
committed
Feature: Add drag-and-drop support for setting the root folder.
1 parent 0c7c633 commit 501e3d1

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

CodeIngest.Desktop/MainWindow.axaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
</Style>
3333
</Grid.Styles>
3434

35-
<Border BorderThickness="1" Margin="8">
36-
<ui:FolderTree Root="{Binding Root}" Margin="8"/>
35+
<Border BorderThickness="1" Margin="8" DragDrop.AllowDrop="True">
36+
<ui:FolderTree Root="{Binding Root}" Margin="8" />
3737
</Border>
3838

3939
<StackPanel Grid.Column="1" Margin="0,8,8,8">

CodeIngest.Desktop/MainWindow.axaml.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
// about your modifications. Your contributions are valued!
99
//
1010
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND.
11+
using System.Linq;
1112
using Avalonia.Controls;
13+
using Avalonia.Input;
14+
using Avalonia.Platform.Storage;
15+
using CSharp.Core.Extensions;
16+
using CSharp.Core.UI;
1217

1318
namespace CodeIngest.Desktop;
1419

@@ -17,5 +22,16 @@ public partial class MainWindow : Window
1722
public MainWindow()
1823
{
1924
InitializeComponent();
25+
26+
AddHandler(DragDrop.DropEvent, OnDrop);
27+
}
28+
29+
private void OnDrop(object sender, DragEventArgs e)
30+
{
31+
if (e.Data.GetFiles()?.FirstOrDefault() is not IStorageFolder folder)
32+
return;
33+
if (DataContext == null)
34+
return;
35+
((MainViewModel)DataContext).Root = new FolderTreeRoot(folder.ToDirectoryInfo());
2036
}
2137
}

0 commit comments

Comments
 (0)