diff --git a/Files/Helpers/UIFilesystemHelpers.cs b/Files/Helpers/UIFilesystemHelpers.cs index bd4f8fa77d22..5fa46ca9c4b9 100644 --- a/Files/Helpers/UIFilesystemHelpers.cs +++ b/Files/Helpers/UIFilesystemHelpers.cs @@ -7,11 +7,164 @@ using System.Threading.Tasks; using Windows.ApplicationModel.DataTransfer; using Windows.Storage; +using System.Collections.Generic; +using Windows.ApplicationModel.AppService; +using Windows.Foundation.Collections; +using System.Linq; namespace Files.Helpers { public static class UIFilesystemHelpers { + public static async void CutItem(IShellPage associatedInstance) + { + DataPackage dataPackage = new DataPackage + { + RequestedOperation = DataPackageOperation.Move + }; + List items = new List(); + FilesystemResult result = (FilesystemResult)false; + + if (associatedInstance.SlimContentPage.IsItemSelected) + { + // First, reset DataGrid Rows that may be in "cut" command mode + associatedInstance.SlimContentPage.ResetItemOpacity(); + + foreach (ListedItem listedItem in associatedInstance.SlimContentPage.SelectedItems) + { + // Dim opacities accordingly + associatedInstance.SlimContentPage.SetItemOpacity(listedItem); + + if (listedItem.PrimaryItemAttribute == StorageItemTypes.File) + { + result = await associatedInstance.FilesystemViewModel.GetFileFromPathAsync(listedItem.ItemPath) + .OnSuccess(t => items.Add(t)); + if (!result) + { + break; + } + } + else + { + result = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(listedItem.ItemPath) + .OnSuccess(t => items.Add(t)); + if (!result) + { + break; + } + } + } + if (result.ErrorCode == FileSystemStatusCode.NotFound) + { + associatedInstance.SlimContentPage.ResetItemOpacity(); + return; + } + else if (result.ErrorCode == FileSystemStatusCode.Unauthorized) + { + // Try again with fulltrust process + if (associatedInstance.ServiceConnection != null) + { + string filePaths = string.Join('|', associatedInstance.SlimContentPage.SelectedItems.Select(x => x.ItemPath)); + AppServiceResponseStatus status = await associatedInstance.ServiceConnection.SendMessageAsync(new ValueSet() + { + { "Arguments", "FileOperation" }, + { "fileop", "Clipboard" }, + { "filepath", filePaths }, + { "operation", (int)DataPackageOperation.Move } + }); + if (status == AppServiceResponseStatus.Success) + { + return; + } + } + associatedInstance.SlimContentPage.ResetItemOpacity(); + return; + } + } + + if (!items.Any()) + { + return; + } + dataPackage.SetStorageItems(items); + try + { + Clipboard.SetContent(dataPackage); + Clipboard.Flush(); + } + catch + { + dataPackage = null; + } + } + + public static async void CopyItem(IShellPage associatedInstance) + { + DataPackage dataPackage = new DataPackage() + { + RequestedOperation = DataPackageOperation.Copy + }; + List items = new List(); + + string copySourcePath = associatedInstance.FilesystemViewModel.WorkingDirectory; + FilesystemResult result = (FilesystemResult)false; + + if (associatedInstance.SlimContentPage.IsItemSelected) + { + foreach (ListedItem listedItem in associatedInstance.SlimContentPage.SelectedItems) + { + if (listedItem.PrimaryItemAttribute == StorageItemTypes.File) + { + result = await associatedInstance.FilesystemViewModel.GetFileFromPathAsync(listedItem.ItemPath) + .OnSuccess(t => items.Add(t)); + if (!result) + { + break; + } + } + else + { + result = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(listedItem.ItemPath) + .OnSuccess(t => items.Add(t)); + if (!result) + { + break; + } + } + } + if (result.ErrorCode == FileSystemStatusCode.Unauthorized) + { + // Try again with fulltrust process + if (associatedInstance.ServiceConnection != null) + { + string filePaths = string.Join('|', associatedInstance.SlimContentPage.SelectedItems.Select(x => x.ItemPath)); + await associatedInstance.ServiceConnection.SendMessageAsync(new ValueSet() + { + { "Arguments", "FileOperation" }, + { "fileop", "Clipboard" }, + { "filepath", filePaths }, + { "operation", (int)DataPackageOperation.Copy } + }); + } + return; + } + } + + if (items?.Count > 0) + { + dataPackage.SetStorageItems(items); + try + { + Clipboard.SetContent(dataPackage); + Clipboard.Flush(); + } + catch + { + dataPackage = null; + } + } + } + public static async Task PasteItemAsync(string destinationPath, IShellPage associatedInstance) { DataPackageView packageView = await FilesystemTasks.Wrap(() => Task.FromResult(Clipboard.GetContent())); diff --git a/Files/Interacts/BaseLayoutCommandImplementationModel.cs b/Files/Interacts/BaseLayoutCommandImplementationModel.cs index b35382be26f8..84623bad2dff 100644 --- a/Files/Interacts/BaseLayoutCommandImplementationModel.cs +++ b/Files/Interacts/BaseLayoutCommandImplementationModel.cs @@ -158,153 +158,14 @@ public virtual void QuickLook(RoutedEventArgs e) QuickLookHelpers.ToggleQuickLook(associatedInstance); } - public virtual async void CopyItem(RoutedEventArgs e) + public virtual void CopyItem(RoutedEventArgs e) { - DataPackage dataPackage = new DataPackage() - { - RequestedOperation = DataPackageOperation.Copy - }; - List items = new List(); - - string copySourcePath = associatedInstance.FilesystemViewModel.WorkingDirectory; - FilesystemResult result = (FilesystemResult)false; - - if (SlimContentPage.IsItemSelected) - { - foreach (ListedItem listedItem in SlimContentPage.SelectedItems) - { - if (listedItem.PrimaryItemAttribute == StorageItemTypes.File) - { - result = await associatedInstance.FilesystemViewModel.GetFileFromPathAsync(listedItem.ItemPath) - .OnSuccess(t => items.Add(t)); - if (!result) - { - break; - } - } - else - { - result = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(listedItem.ItemPath) - .OnSuccess(t => items.Add(t)); - if (!result) - { - break; - } - } - } - if (result.ErrorCode == FileSystemStatusCode.Unauthorized) - { - // Try again with fulltrust process - if (ServiceConnection != null) - { - string filePaths = string.Join('|', SlimContentPage.SelectedItems.Select(x => x.ItemPath)); - await ServiceConnection.SendMessageAsync(new ValueSet() - { - { "Arguments", "FileOperation" }, - { "fileop", "Clipboard" }, - { "filepath", filePaths }, - { "operation", (int)DataPackageOperation.Copy } - }); - } - return; - } - } - - if (items?.Count > 0) - { - dataPackage.SetStorageItems(items); - try - { - Clipboard.SetContent(dataPackage); - Clipboard.Flush(); - } - catch - { - dataPackage = null; - } - } + UIFilesystemHelpers.CopyItem(associatedInstance); } - public virtual async void CutItem(RoutedEventArgs e) + public virtual void CutItem(RoutedEventArgs e) { - DataPackage dataPackage = new DataPackage - { - RequestedOperation = DataPackageOperation.Move - }; - List items = new List(); - FilesystemResult result = (FilesystemResult)false; - - if (SlimContentPage.IsItemSelected) - { - // First, reset DataGrid Rows that may be in "cut" command mode - SlimContentPage.ResetItemOpacity(); - - foreach (ListedItem listedItem in SlimContentPage.SelectedItems) - { - // Dim opacities accordingly - SlimContentPage.SetItemOpacity(listedItem); - - if (listedItem.PrimaryItemAttribute == StorageItemTypes.File) - { - result = await associatedInstance.FilesystemViewModel.GetFileFromPathAsync(listedItem.ItemPath) - .OnSuccess(t => items.Add(t)); - if (!result) - { - break; - } - } - else - { - result = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(listedItem.ItemPath) - .OnSuccess(t => items.Add(t)); - if (!result) - { - break; - } - } - } - if (result.ErrorCode == FileSystemStatusCode.NotFound) - { - SlimContentPage.ResetItemOpacity(); - return; - } - else if (result.ErrorCode == FileSystemStatusCode.Unauthorized) - { - // Try again with fulltrust process - if (ServiceConnection != null) - { - string filePaths = string.Join('|', SlimContentPage.SelectedItems.Select(x => x.ItemPath)); - AppServiceResponseStatus status = await ServiceConnection.SendMessageAsync(new ValueSet() - { - { "Arguments", "FileOperation" }, - { "fileop", "Clipboard" }, - { "filepath", filePaths }, - { "operation", (int)DataPackageOperation.Move } - }); - if (status == AppServiceResponseStatus.Success) - { - return; - } - } - SlimContentPage.ResetItemOpacity(); - return; - } - } - - if (!items.Any()) - { - return; - } - dataPackage.SetStorageItems(items); - try - { - Clipboard.SetContent(dataPackage); - Clipboard.Flush(); - } - catch - { - dataPackage = null; - } + UIFilesystemHelpers.CutItem(associatedInstance); } public virtual async void RestoreItem(RoutedEventArgs e) diff --git a/Files/Views/ModernShellPage.xaml.cs b/Files/Views/ModernShellPage.xaml.cs index ae1d19a34473..74cf65acd60d 100644 --- a/Files/Views/ModernShellPage.xaml.cs +++ b/Files/Views/ModernShellPage.xaml.cs @@ -980,7 +980,7 @@ await FilesystemHelpers.DeleteItemsAsync( case (true, false, false, true, VirtualKey.C): // ctrl + c, copy if (!NavigationToolbar.IsEditModeEnabled && !ContentPage.IsRenamingItem) { - FilePropertiesHelpers.ShowProperties(this); + UIFilesystemHelpers.CopyItem(this); } break; @@ -996,7 +996,7 @@ await FilesystemHelpers.DeleteItemsAsync( case (true, false, false, true, VirtualKey.X): // ctrl + x, cut if (!NavigationToolbar.IsEditModeEnabled && !ContentPage.IsRenamingItem) { - FilePropertiesHelpers.ShowProperties(this); + UIFilesystemHelpers.CutItem(this); } break;