From b8fb5876d3a3f1e8de1da08acd1e875e2827b57a Mon Sep 17 00:00:00 2001 From: Lamparter <71598437+Lamparter@users.noreply.github.com> Date: Sat, 18 Jan 2025 15:03:28 +0000 Subject: [PATCH 1/6] Add support for dragging recent files --- .../Widgets/RecentFilesWidget.xaml | 3 ++ .../Widgets/RecentFilesWidget.xaml.cs | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml b/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml index 2ac55b06b518..872d42a5c607 100644 --- a/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml +++ b/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml @@ -37,6 +37,9 @@ x:Name="RecentFilesListView" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" + AllowDrop="True" + CanDragItems="True" + DragItemsStarting="RecentFilesListView_DragItemsStarting" IsItemClickEnabled="True" IsRightTapEnabled="True" ItemClick="RecentFilesListView_ItemClick" diff --git a/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs b/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs index 47a634bb18c8..aa84f27d4b78 100644 --- a/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs +++ b/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs @@ -3,6 +3,8 @@ using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Input; +using Windows.ApplicationModel.DataTransfer; +using Windows.Storage; namespace Files.App.UserControls.Widgets { @@ -30,5 +32,37 @@ private void RecentFilesListView_RightTapped(object sender, RightTappedRoutedEve { ViewModel.BuildItemContextMenu(e.OriginalSource, e); } + + private async void RecentFilesListView_DragItemsStarting(object sender, DragItemsStartingEventArgs e) + { + var items = e.Items.OfType().ToList(); + if (items.Count > 0) + { + var storageItems = new List(); + foreach (var item in items) + { + try + { + var file = await StorageFile.GetFileFromPathAsync(item.Path); + if (file != null) + storageItems.Add(file); + } + catch + { + e.Cancel = true; + } + } + + if (storageItems.Count > 0) + { + // Create a new data package and set the storage items + DataPackage dataPackage = new DataPackage(); + dataPackage.SetStorageItems(storageItems); + e.Data.SetDataProvider(StandardDataFormats.StorageItems, request => request.SetData(storageItems)); + + e.Data.RequestedOperation = DataPackageOperation.Move | DataPackageOperation.Copy | DataPackageOperation.Link; + } + } + } } } From ec2b9f08f8ae3e9adfa02c36a0f2ebddbcc19b2b Mon Sep 17 00:00:00 2001 From: Lamparter <71598437+Lamparter@users.noreply.github.com> Date: Sat, 18 Jan 2025 15:03:36 +0000 Subject: [PATCH 2/6] Reword comment --- src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs b/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs index aa84f27d4b78..9b19b420a658 100644 --- a/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs +++ b/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs @@ -9,7 +9,7 @@ namespace Files.App.UserControls.Widgets { /// - /// Represents group of control displays a list of recent folders with . + /// Represents a control that displays a list of recent folders with . /// public sealed partial class RecentFilesWidget : UserControl { From 60782f8d8e3dc9117475a307a8fafa43af494a63 Mon Sep 17 00:00:00 2001 From: Lamparter <71598437+Lamparter@users.noreply.github.com> Date: Sun, 19 Jan 2025 09:33:54 +0000 Subject: [PATCH 3/6] Remove `AllowDrop` property --- src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml b/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml index 872d42a5c607..ce7392e4f61b 100644 --- a/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml +++ b/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml @@ -37,7 +37,6 @@ x:Name="RecentFilesListView" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" - AllowDrop="True" CanDragItems="True" DragItemsStarting="RecentFilesListView_DragItemsStarting" IsItemClickEnabled="True" From 49d6e9d2026558ddfa43f0a5b8c43792b9a23f35 Mon Sep 17 00:00:00 2001 From: Lamparter <71598437+Lamparter@users.noreply.github.com> Date: Sun, 19 Jan 2025 16:00:44 +0000 Subject: [PATCH 4/6] Reword comment Co-authored-by: Yair <39923744+yaira2@users.noreply.github.com> Signed-off-by: Lamparter <71598437+Lamparter@users.noreply.github.com> --- src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs b/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs index 9b19b420a658..22b49aebe645 100644 --- a/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs +++ b/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs @@ -9,7 +9,7 @@ namespace Files.App.UserControls.Widgets { /// - /// Represents a control that displays a list of recent folders with . + /// Represents a control that displays a list of recent files with . /// public sealed partial class RecentFilesWidget : UserControl { From 2a7eedabee69149f2ce9884b319fe0f883a56e08 Mon Sep 17 00:00:00 2001 From: Lamparter <71598437+Lamparter@users.noreply.github.com> Date: Sun, 19 Jan 2025 16:16:07 +0000 Subject: [PATCH 5/6] Remove items = 0 check --- .../Widgets/RecentFilesWidget.xaml.cs | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs b/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs index 22b49aebe645..74099f056c98 100644 --- a/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs +++ b/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs @@ -36,33 +36,31 @@ private void RecentFilesListView_RightTapped(object sender, RightTappedRoutedEve private async void RecentFilesListView_DragItemsStarting(object sender, DragItemsStartingEventArgs e) { var items = e.Items.OfType().ToList(); - if (items.Count > 0) + var storageItems = new List(); + + foreach (var item in items) { - var storageItems = new List(); - foreach (var item in items) + try { - try - { - var file = await StorageFile.GetFileFromPathAsync(item.Path); - if (file != null) - storageItems.Add(file); - } - catch - { - e.Cancel = true; - } + var file = await StorageFile.GetFileFromPathAsync(item.Path); + if (file != null) + storageItems.Add(file); } - - if (storageItems.Count > 0) + catch { - // Create a new data package and set the storage items - DataPackage dataPackage = new DataPackage(); - dataPackage.SetStorageItems(storageItems); - e.Data.SetDataProvider(StandardDataFormats.StorageItems, request => request.SetData(storageItems)); - - e.Data.RequestedOperation = DataPackageOperation.Move | DataPackageOperation.Copy | DataPackageOperation.Link; + e.Cancel = true; } } + + if (storageItems.Count > 0) + { + // Create a new data package and set the storage items + DataPackage dataPackage = new DataPackage(); + dataPackage.SetStorageItems(storageItems); + e.Data.SetDataProvider(StandardDataFormats.StorageItems, request => request.SetData(storageItems)); + + e.Data.RequestedOperation = DataPackageOperation.Move | DataPackageOperation.Copy | DataPackageOperation.Link; + } } } } From c69a10c1f243b1e51a912198b536277b3b31a73c Mon Sep 17 00:00:00 2001 From: Lamparter <71598437+Lamparter@users.noreply.github.com> Date: Mon, 20 Jan 2025 07:54:58 +0000 Subject: [PATCH 6/6] Convert foreach block into Linq expression --- .../Widgets/RecentFilesWidget.xaml.cs | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs b/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs index 74099f056c98..e9bba29b081f 100644 --- a/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs +++ b/src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs @@ -35,21 +35,18 @@ private void RecentFilesListView_RightTapped(object sender, RightTappedRoutedEve private async void RecentFilesListView_DragItemsStarting(object sender, DragItemsStartingEventArgs e) { - var items = e.Items.OfType().ToList(); + var item = e.Items.OfType().First(); var storageItems = new List(); - foreach (var item in items) + try { - try - { - var file = await StorageFile.GetFileFromPathAsync(item.Path); - if (file != null) - storageItems.Add(file); - } - catch - { - e.Cancel = true; - } + var file = await StorageFile.GetFileFromPathAsync(item.Path); + if (file != null) + storageItems.Add(file); + } + catch + { + e.Cancel = true; } if (storageItems.Count > 0)