Skip to content

Commit

Permalink
Fix: Fixed ArgumentException when trying to create DataPackageView
Browse files Browse the repository at this point in the history
  • Loading branch information
yaira2 committed Feb 4, 2024
1 parent 5c64de1 commit c057904
Showing 1 changed file with 65 additions and 62 deletions.
127 changes: 65 additions & 62 deletions src/Files.App/ViewModels/Layouts/BaseLayoutViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,81 +85,84 @@ private void PointerWheelChanged(PointerRoutedEventArgs e)

public async Task DragOverAsync(DragEventArgs e)
{
var deferral = e.GetDeferral();
DragOperationDeferral? deferral = null;

if (_associatedInstance.InstanceViewModel.IsPageTypeSearchResults)
try
{
e.AcceptedOperation = DataPackageOperation.None;
deferral.Complete();
deferral = e.GetDeferral();

return;
}
if (_associatedInstance.InstanceViewModel.IsPageTypeSearchResults)
{
e.AcceptedOperation = DataPackageOperation.None;
deferral.Complete();

_itemManipulationModel.ClearSelection();
return;
}

if (FilesystemHelpers.HasDraggedStorageItems(e.DataView))
{
e.Handled = true;
_itemManipulationModel.ClearSelection();

var draggedItems = await FilesystemHelpers.GetDraggedStorageItems(e.DataView);
if (FilesystemHelpers.HasDraggedStorageItems(e.DataView))
{
e.Handled = true;

var pwd = _associatedInstance.FilesystemViewModel.WorkingDirectory.TrimPath();
var folderName = Path.IsPathRooted(pwd) && Path.GetPathRoot(pwd) == pwd ? Path.GetPathRoot(pwd) : Path.GetFileName(pwd);
var draggedItems = await FilesystemHelpers.GetDraggedStorageItems(e.DataView);

// As long as one file doesn't already belong to this folder
if (_associatedInstance.InstanceViewModel.IsPageTypeSearchResults || draggedItems.Any() && draggedItems.AreItemsAlreadyInFolder(_associatedInstance.FilesystemViewModel.WorkingDirectory))
{
e.AcceptedOperation = DataPackageOperation.None;
}
else if (!draggedItems.Any())
{
e.AcceptedOperation = DataPackageOperation.None;
}
else
{
e.DragUIOverride.IsCaptionVisible = true;
if (pwd.StartsWith(Constants.UserEnvironmentPaths.RecycleBinPath, StringComparison.Ordinal))
{
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalizedResource(), folderName);
e.AcceptedOperation = DataPackageOperation.Move;
}
else if (e.Modifiers.HasFlag(DragDropModifiers.Alt) || e.Modifiers.HasFlag(DragDropModifiers.Control | DragDropModifiers.Shift))
{
e.DragUIOverride.Caption = string.Format("LinkToFolderCaptionText".GetLocalizedResource(), folderName);
e.AcceptedOperation = DataPackageOperation.Link;
}
else if (e.Modifiers.HasFlag(DragDropModifiers.Control))
{
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalizedResource(), folderName);
e.AcceptedOperation = DataPackageOperation.Copy;
}
else if (e.Modifiers.HasFlag(DragDropModifiers.Shift))
{
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalizedResource(), folderName);
e.AcceptedOperation = DataPackageOperation.Move;
}
else if (draggedItems.Any(x =>
x.Item is ZipStorageFile ||
x.Item is ZipStorageFolder) ||
ZipStorageFolder.IsZipPath(pwd))
{
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalizedResource(), folderName);
e.AcceptedOperation = DataPackageOperation.Copy;
}
else if (draggedItems.AreItemsInSameDrive(_associatedInstance.FilesystemViewModel.WorkingDirectory))
{
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalizedResource(), folderName);
e.AcceptedOperation = DataPackageOperation.Move;
}
var pwd = _associatedInstance.FilesystemViewModel.WorkingDirectory.TrimPath();
var folderName = Path.IsPathRooted(pwd) && Path.GetPathRoot(pwd) == pwd ? Path.GetPathRoot(pwd) : Path.GetFileName(pwd);

// As long as one file doesn't already belong to this folder
if (_associatedInstance.InstanceViewModel.IsPageTypeSearchResults || draggedItems.Any() && draggedItems.AreItemsAlreadyInFolder(_associatedInstance.FilesystemViewModel.WorkingDirectory))
e.AcceptedOperation = DataPackageOperation.None;
else if (!draggedItems.Any())
e.AcceptedOperation = DataPackageOperation.None;
else
{
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalizedResource(), folderName);
e.AcceptedOperation = DataPackageOperation.Copy;
e.DragUIOverride.IsCaptionVisible = true;
if (pwd is not null && pwd.StartsWith(Constants.UserEnvironmentPaths.RecycleBinPath, StringComparison.Ordinal))
{
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalizedResource(), folderName);
e.AcceptedOperation = DataPackageOperation.Move;
}
else if (e.Modifiers.HasFlag(DragDropModifiers.Alt) || e.Modifiers.HasFlag(DragDropModifiers.Control | DragDropModifiers.Shift))
{
e.DragUIOverride.Caption = string.Format("LinkToFolderCaptionText".GetLocalizedResource(), folderName);
e.AcceptedOperation = DataPackageOperation.Link;
}
else if (e.Modifiers.HasFlag(DragDropModifiers.Control))
{
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalizedResource(), folderName);
e.AcceptedOperation = DataPackageOperation.Copy;
}
else if (e.Modifiers.HasFlag(DragDropModifiers.Shift))
{
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalizedResource(), folderName);
e.AcceptedOperation = DataPackageOperation.Move;
}
else if (draggedItems.Any(x =>
x.Item is ZipStorageFile ||
x.Item is ZipStorageFolder) ||
ZipStorageFolder.IsZipPath(pwd))
{
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalizedResource(), folderName);
e.AcceptedOperation = DataPackageOperation.Copy;
}
else if (draggedItems.AreItemsInSameDrive(_associatedInstance.FilesystemViewModel.WorkingDirectory))
{
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalizedResource(), folderName);
e.AcceptedOperation = DataPackageOperation.Move;
}
else
{
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalizedResource(), folderName);
e.AcceptedOperation = DataPackageOperation.Copy;
}
}
}
}

deferral.Complete();
finally
{
deferral?.Complete();
}
}

public async Task DropAsync(DragEventArgs e)
Expand Down

0 comments on commit c057904

Please sign in to comment.