Skip to content

Commit f8b3fb0

Browse files
authored
Fix: Fixed issues with drag & drop from Files to other apps (#10949)
1 parent e1c4c3b commit f8b3fb0

File tree

2 files changed

+19
-143
lines changed

2 files changed

+19
-143
lines changed

src/Files.App/BaseLayout.cs

Lines changed: 19 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

4246
namespace Files.App
@@ -751,11 +755,23 @@ protected virtual void Page_CharacterReceived(UIElement sender, CharacterReceive
751755
protected void FileList_DragItemsStarting(object sender, DragItemsStartingEventArgs e)
752756
{
753757
SelectedItems!.AddRange(e.Items.OfType<ListedItem>());
758+
754759
try
755760
{
756-
// Only support IStorageItem capable paths
757-
var itemList = e.Items.OfType<ListedItem>().Where(x => !(x.IsHiddenItem && x.IsLinkItem && x.IsRecycleBinItem && x.IsShortcut)).Select(x => VirtualStorageItem.FromListedItem(x));
758-
e.Data.SetStorageItems(itemList, false);
761+
var itemList = e.Items.OfType<ListedItem>().Select(x => new VA.ShellItem(x.ItemPath)).ToArray();
762+
var iddo = itemList[0].Parent.GetChildrenUIObjects<IDataObject>(HWND.NULL, itemList);
763+
itemList.ForEach(x => x.Dispose());
764+
var wfdo = new System.Windows.Forms.DataObject(iddo);
765+
var formats = wfdo.GetFormats(false);
766+
foreach (var format in formats)
767+
{
768+
var clipFrmtId = (uint)System.Windows.Forms.DataFormats.GetFormat(format).Id;
769+
if (iddo.TryGetData<byte[]>(clipFrmtId, out var data))
770+
{
771+
var mem = new MemoryStream(data).AsRandomAccessStream();
772+
e.Data.SetData(format, mem);
773+
}
774+
}
759775
}
760776
catch (Exception)
761777
{

src/Files.App/Filesystem/StorageItems/VirtualStorageItem.cs

Lines changed: 0 additions & 140 deletions
This file was deleted.

0 commit comments

Comments
 (0)