Skip to content

Commit 9608101

Browse files
authored
Fix: Fixed drag and drop (#11728)
1 parent 3271055 commit 9608101

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/Files.App/BaseLayout.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,21 @@
2626
using System.Collections.Generic;
2727
using System.ComponentModel;
2828
using System.Diagnostics;
29+
using System.IO;
2930
using System.Linq;
3031
using System.Runtime.CompilerServices;
32+
using System.Runtime.InteropServices.ComTypes;
3133
using System.Threading;
3234
using System.Threading.Tasks;
35+
using Vanara.PInvoke;
3336
using Windows.ApplicationModel.DataTransfer;
3437
using Windows.ApplicationModel.DataTransfer.DragDrop;
3538
using Windows.Foundation;
3639
using Windows.Foundation.Collections;
3740
using Windows.Storage;
3841
using Windows.System;
3942
using static Files.App.Helpers.PathNormalization;
43+
using VA = Vanara.Windows.Shell;
4044
using DispatcherQueueTimer = Microsoft.UI.Dispatching.DispatcherQueueTimer;
4145
using SortDirection = Files.Shared.Enums.SortDirection;
4246

@@ -875,11 +879,27 @@ protected virtual void Page_CharacterReceived(UIElement sender, CharacterReceive
875879
protected void FileList_DragItemsStarting(object sender, DragItemsStartingEventArgs e)
876880
{
877881
SelectedItems!.AddRange(e.Items.OfType<ListedItem>());
882+
878883
try
879884
{
880-
// Only support IStorageItem capable paths
881-
var itemList = e.Items.OfType<ListedItem>().Where(x => !(x.IsHiddenItem && x.IsLinkItem && x.IsRecycleBinItem && x.IsShortcut)).Select(x => VirtualStorageItem.FromListedItem(x));
882-
e.Data.SetStorageItems(itemList, false);
885+
var shellItemList = e.Items.OfType<ListedItem>().Select(x => new VA.ShellItem(x.ItemPath)).ToArray();
886+
if (shellItemList[0].FileSystemPath is not null)
887+
{
888+
var iddo = shellItemList[0].Parent.GetChildrenUIObjects<IDataObject>(HWND.NULL, shellItemList);
889+
shellItemList.ForEach(x => x.Dispose());
890+
var format = System.Windows.Forms.DataFormats.GetFormat("Shell IDList Array");
891+
if (iddo.TryGetData<byte[]>((uint)format.Id, out var data))
892+
{
893+
var mem = new MemoryStream(data).AsRandomAccessStream();
894+
e.Data.SetData(format.Name, mem);
895+
}
896+
}
897+
else
898+
{
899+
// Only support IStorageItem capable paths
900+
var storageItemList = e.Items.OfType<ListedItem>().Where(x => !(x.IsHiddenItem && x.IsLinkItem && x.IsRecycleBinItem && x.IsShortcut)).Select(x => VirtualStorageItem.FromListedItem(x));
901+
e.Data.SetStorageItems(storageItemList, false);
902+
}
883903
}
884904
catch (Exception)
885905
{

0 commit comments

Comments
 (0)