Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/Files.App.Controls/Sidebar/SidebarItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
using Microsoft.UI.Xaml.Automation;
using Microsoft.UI.Xaml.Automation.Peers;
using System.Collections.Specialized;
using System.IO;
using Windows.ApplicationModel.DataTransfer;
using Windows.Storage;

namespace Files.App.Controls
{
Expand Down Expand Up @@ -90,6 +92,7 @@ public void HandleItemChange()
HookupItemChangeListener(null, Item);
UpdateExpansionState();
ReevaluateSelection();
CanDrag = Item?.GetType().GetProperty("Path")?.GetValue(Item) is string path && Path.IsPathRooted(path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should ask review for any PR atleast about code quality.

This is not trim safe (aot incompat).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can address this when we're ready to enable trimming.

}

private void HookupOwners()
Expand Down Expand Up @@ -137,7 +140,30 @@ private void HookupItemChangeListener(ISidebarItemModel? oldItem, ISidebarItemMo

private void SidebarItem_DragStarting(UIElement sender, DragStartingEventArgs args)
{
args.Data.SetData(StandardDataFormats.Text, Text?.ToString() ?? string.Empty);
if (Item?.GetType().GetProperty("Path")?.GetValue(Item) is not string dragPath || !Path.IsPathRooted(dragPath))
return;

args.Data.SetData(StandardDataFormats.Text, dragPath);
args.Data.RequestedOperation = DataPackageOperation.Move | DataPackageOperation.Copy | DataPackageOperation.Link;
args.Data.SetDataProvider(StandardDataFormats.StorageItems, async request =>
{
var deferral = request.GetDeferral();
try
{
if (Directory.Exists(dragPath))
{
var folder = await StorageFolder.GetFolderFromPathAsync(dragPath);
request.SetData(new IStorageItem[] { folder });
}
}
catch
{
}
finally
{
deferral.Complete();
}
});
}

private void SetFlyoutOpen(bool isOpen = true)
Expand Down
Loading