Skip to content

Commit 8436b87

Browse files
committed
Feature: Add drag-and-drop folder support in MainWindow.
1 parent 1f743a4 commit 8436b87

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Code authored by Dean Edis (DeanTheCoder).
2+
// Anyone is free to copy, modify, use, compile, or distribute this software,
3+
// either in source code form or as a compiled binary, for any non-commercial
4+
// purpose.
5+
//
6+
// If you modify the code, please retain this copyright header,
7+
// and consider contributing back to the repository or letting us know
8+
// about your modifications. Your contributions are valued!
9+
//
10+
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND.
11+
using System.Linq;
12+
using Avalonia.Controls;
13+
using Avalonia.Input;
14+
using Avalonia.Platform.Storage;
15+
using CSharp.Core.Extensions;
16+
using CSharp.Core.UI;
17+
18+
namespace CodeIngest.Desktop.Views;
19+
20+
public partial class MainWindow : Window
21+
{
22+
public MainWindow()
23+
{
24+
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());
36+
}
37+
}

0 commit comments

Comments
 (0)