Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Fixed drag and drop #11728

Merged
merged 1 commit into from
Mar 15, 2023
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
26 changes: 23 additions & 3 deletions src/Files.App/BaseLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices.ComTypes;
using System.Threading;
using System.Threading.Tasks;
using Vanara.PInvoke;
using Windows.ApplicationModel.DataTransfer;
using Windows.ApplicationModel.DataTransfer.DragDrop;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.System;
using static Files.App.Helpers.PathNormalization;
using VA = Vanara.Windows.Shell;
using DispatcherQueueTimer = Microsoft.UI.Dispatching.DispatcherQueueTimer;
using SortDirection = Files.Shared.Enums.SortDirection;

Expand Down Expand Up @@ -875,11 +879,27 @@ protected virtual void Page_CharacterReceived(UIElement sender, CharacterReceive
protected void FileList_DragItemsStarting(object sender, DragItemsStartingEventArgs e)
{
SelectedItems!.AddRange(e.Items.OfType<ListedItem>());

try
{
// Only support IStorageItem capable paths
var itemList = e.Items.OfType<ListedItem>().Where(x => !(x.IsHiddenItem && x.IsLinkItem && x.IsRecycleBinItem && x.IsShortcut)).Select(x => VirtualStorageItem.FromListedItem(x));
e.Data.SetStorageItems(itemList, false);
var shellItemList = e.Items.OfType<ListedItem>().Select(x => new VA.ShellItem(x.ItemPath)).ToArray();
if (shellItemList[0].FileSystemPath is not null)
{
var iddo = shellItemList[0].Parent.GetChildrenUIObjects<IDataObject>(HWND.NULL, shellItemList);
shellItemList.ForEach(x => x.Dispose());
var format = System.Windows.Forms.DataFormats.GetFormat("Shell IDList Array");
if (iddo.TryGetData<byte[]>((uint)format.Id, out var data))
{
var mem = new MemoryStream(data).AsRandomAccessStream();
e.Data.SetData(format.Name, mem);
}
}
else
{
// Only support IStorageItem capable paths
var storageItemList = e.Items.OfType<ListedItem>().Where(x => !(x.IsHiddenItem && x.IsLinkItem && x.IsRecycleBinItem && x.IsShortcut)).Select(x => VirtualStorageItem.FromListedItem(x));
e.Data.SetStorageItems(storageItemList, false);
}
}
catch (Exception)
{
Expand Down