|
6 | 6 | using Microsoft.UI.Xaml.Automation; |
7 | 7 | using Microsoft.UI.Xaml.Automation.Peers; |
8 | 8 | using System.Collections.Specialized; |
| 9 | +using System.IO; |
9 | 10 | using Windows.ApplicationModel.DataTransfer; |
| 11 | +using Windows.Storage; |
10 | 12 |
|
11 | 13 | namespace Files.App.Controls |
12 | 14 | { |
@@ -90,6 +92,7 @@ public void HandleItemChange() |
90 | 92 | HookupItemChangeListener(null, Item); |
91 | 93 | UpdateExpansionState(); |
92 | 94 | ReevaluateSelection(); |
| 95 | + CanDrag = Item?.GetType().GetProperty("Path")?.GetValue(Item) is string path && Path.IsPathRooted(path); |
93 | 96 | } |
94 | 97 |
|
95 | 98 | private void HookupOwners() |
@@ -137,7 +140,35 @@ private void HookupItemChangeListener(ISidebarItemModel? oldItem, ISidebarItemMo |
137 | 140 |
|
138 | 141 | private void SidebarItem_DragStarting(UIElement sender, DragStartingEventArgs args) |
139 | 142 | { |
140 | | - args.Data.SetData(StandardDataFormats.Text, Text?.ToString() ?? string.Empty); |
| 143 | + if (Item?.GetType().GetProperty("Path")?.GetValue(Item) is not string dragPath || !Path.IsPathRooted(dragPath)) |
| 144 | + return; |
| 145 | + |
| 146 | + args.Data.SetData(StandardDataFormats.Text, dragPath); |
| 147 | + args.Data.RequestedOperation = DataPackageOperation.Copy; |
| 148 | + args.Data.SetDataProvider(StandardDataFormats.StorageItems, async request => |
| 149 | + { |
| 150 | + var deferral = request.GetDeferral(); |
| 151 | + try |
| 152 | + { |
| 153 | + if (Directory.Exists(dragPath)) |
| 154 | + { |
| 155 | + var folder = await StorageFolder.GetFolderFromPathAsync(dragPath); |
| 156 | + request.SetData(new IStorageItem[] { folder }); |
| 157 | + } |
| 158 | + else if (File.Exists(dragPath)) |
| 159 | + { |
| 160 | + var file = await StorageFile.GetFileFromPathAsync(dragPath); |
| 161 | + request.SetData(new IStorageItem[] { file }); |
| 162 | + } |
| 163 | + } |
| 164 | + catch |
| 165 | + { |
| 166 | + } |
| 167 | + finally |
| 168 | + { |
| 169 | + deferral.Complete(); |
| 170 | + } |
| 171 | + }); |
141 | 172 | } |
142 | 173 |
|
143 | 174 | private void SetFlyoutOpen(bool isOpen = true) |
|
0 commit comments