Skip to content

Commit 11e55ce

Browse files
committed
WIP: Open flyout when dropping from Shelf
1 parent 453aacd commit 11e55ce

File tree

1 file changed

+97
-65
lines changed

1 file changed

+97
-65
lines changed

src/Files.App/ViewModels/Layouts/BaseLayoutViewModel.cs

Lines changed: 97 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Windows.ApplicationModel.DataTransfer.DragDrop;
1212
using Windows.Storage;
1313
using Windows.System;
14+
using Microsoft.UI.Xaml.Controls;
1415

1516
namespace Files.App.ViewModels.Layouts
1617
{
@@ -100,17 +101,22 @@ public async Task DragOverAsync(DragEventArgs e)
100101
return;
101102
}
102103

103-
if (FilesystemHelpers.HasDraggedStorageItems(e.DataView))
104+
if (!FilesystemHelpers.HasDraggedStorageItems(e.DataView))
104105
{
105-
e.Handled = true;
106-
107-
var draggedItems = await FilesystemHelpers.GetDraggedStorageItems(e.DataView);
108-
109-
var pwd = _associatedInstance.ShellViewModel.WorkingDirectory.TrimPath();
110-
var folderName = Path.IsPathRooted(pwd) && Path.GetPathRoot(pwd) == pwd ? Path.GetPathRoot(pwd) : Path.GetFileName(pwd);
106+
deferral.Complete();
107+
return;
108+
}
109+
110+
e.Handled = true;
111+
var draggedItems = await FilesystemHelpers.GetDraggedStorageItems(e.DataView);
112+
var pwd = _associatedInstance.ShellViewModel.WorkingDirectory.TrimPath();
113+
var folderName = Path.IsPathRooted(pwd) && Path.GetPathRoot(pwd) == pwd ? Path.GetPathRoot(pwd) : Path.GetFileName(pwd);
111114

115+
try
116+
{
112117
// As long as one file doesn't already belong to this folder
113-
if (_associatedInstance.InstanceViewModel.IsPageTypeSearchResults || draggedItems.Any() && draggedItems.AreItemsAlreadyInFolder(_associatedInstance.ShellViewModel.WorkingDirectory))
118+
if (_associatedInstance.InstanceViewModel.IsPageTypeSearchResults || draggedItems.Any() &&
119+
draggedItems.AreItemsAlreadyInFolder(_associatedInstance.ShellViewModel.WorkingDirectory))
114120
{
115121
e.AcceptedOperation = DataPackageOperation.None;
116122
}
@@ -120,80 +126,106 @@ public async Task DragOverAsync(DragEventArgs e)
120126
}
121127
else
122128
{
123-
try
129+
e.DragUIOverride.IsCaptionVisible = true;
130+
if (e.DataView.Properties.TryGetValue("Files_ActionBinder", out var actionBinder) && actionBinder is "Files_ShelfBinder")
124131
{
125-
e.DragUIOverride.IsCaptionVisible = true;
126-
if (pwd.StartsWith(Constants.UserEnvironmentPaths.RecycleBinPath, StringComparison.Ordinal))
127-
{
128-
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalizedResource(), folderName);
129-
// Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
130-
e.AcceptedOperation = DataPackageOperation.Move | DataPackageOperation.Copy;
131-
}
132-
else if (e.Modifiers.HasFlag(DragDropModifiers.Alt) || e.Modifiers.HasFlag(DragDropModifiers.Control | DragDropModifiers.Shift))
133-
{
134-
e.DragUIOverride.Caption = string.Format("LinkToFolderCaptionText".GetLocalizedResource(), folderName);
135-
e.AcceptedOperation = DataPackageOperation.Link;
136-
}
137-
else if (e.Modifiers.HasFlag(DragDropModifiers.Control))
138-
{
139-
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalizedResource(), folderName);
140-
e.AcceptedOperation = DataPackageOperation.Copy;
141-
}
142-
else if (e.Modifiers.HasFlag(DragDropModifiers.Shift))
143-
{
144-
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalizedResource(), folderName);
145-
// Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
146-
e.AcceptedOperation = DataPackageOperation.Move | DataPackageOperation.Copy;
147-
}
148-
else if (draggedItems.Any(x =>
149-
x.Item is ZipStorageFile ||
150-
x.Item is ZipStorageFolder) ||
151-
ZipStorageFolder.IsZipPath(pwd))
152-
{
153-
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalizedResource(), folderName);
154-
e.AcceptedOperation = DataPackageOperation.Copy;
155-
}
156-
else if (draggedItems.AreItemsInSameDrive(_associatedInstance.ShellViewModel.WorkingDirectory))
157-
{
158-
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalizedResource(), folderName);
159-
// Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
160-
e.AcceptedOperation = DataPackageOperation.Move | DataPackageOperation.Copy;
161-
}
162-
else
163-
{
164-
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalizedResource(), folderName);
165-
e.AcceptedOperation = DataPackageOperation.Copy;
166-
}
132+
e.DragUIOverride.Caption = string.Format("LinkToFolderCaptionText".GetLocalizedResource(), folderName);
133+
e.AcceptedOperation = DataPackageOperation.Link;
134+
}
135+
else if (pwd.StartsWith(Constants.UserEnvironmentPaths.RecycleBinPath, StringComparison.Ordinal))
136+
{
137+
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalizedResource(), folderName);
167138

168-
_itemManipulationModel.ClearSelection();
139+
// Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
140+
e.AcceptedOperation = DataPackageOperation.Move | DataPackageOperation.Copy;
169141
}
170-
catch (COMException ex) when (ex.Message.Contains("RPC server is unavailable"))
142+
else if (e.Modifiers.HasFlag(DragDropModifiers.Alt) || e.Modifiers.HasFlag(DragDropModifiers.Control | DragDropModifiers.Shift))
171143
{
172-
Logger?.LogDebug(ex, ex.Message);
144+
e.DragUIOverride.Caption = string.Format("LinkToFolderCaptionText".GetLocalizedResource(), folderName);
145+
e.AcceptedOperation = DataPackageOperation.Link;
173146
}
147+
else if (e.Modifiers.HasFlag(DragDropModifiers.Control))
148+
{
149+
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalizedResource(), folderName);
150+
e.AcceptedOperation = DataPackageOperation.Copy;
151+
}
152+
else if (e.Modifiers.HasFlag(DragDropModifiers.Shift))
153+
{
154+
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalizedResource(), folderName);
155+
156+
// Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
157+
e.AcceptedOperation = DataPackageOperation.Move | DataPackageOperation.Copy;
158+
}
159+
else if (draggedItems.Any(x =>
160+
x.Item is ZipStorageFile ||
161+
x.Item is ZipStorageFolder) ||
162+
ZipStorageFolder.IsZipPath(pwd))
163+
{
164+
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalizedResource(), folderName);
165+
e.AcceptedOperation = DataPackageOperation.Copy;
166+
}
167+
else if (draggedItems.AreItemsInSameDrive(_associatedInstance.ShellViewModel.WorkingDirectory))
168+
{
169+
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalizedResource(), folderName);
170+
171+
// Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
172+
e.AcceptedOperation = DataPackageOperation.Move | DataPackageOperation.Copy;
173+
}
174+
else
175+
{
176+
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalizedResource(), folderName);
177+
e.AcceptedOperation = DataPackageOperation.Copy;
178+
}
179+
180+
_itemManipulationModel.ClearSelection();
174181
}
175182
}
176-
177-
deferral.Complete();
183+
catch (COMException ex) when (ex.Message.Contains("RPC server is unavailable"))
184+
{
185+
Logger?.LogDebug(ex, ex.Message);
186+
}
187+
finally
188+
{
189+
deferral.Complete();
190+
}
178191
}
179192

180193
public async Task DropAsync(DragEventArgs e)
181194
{
182195
e.Handled = true;
196+
var deferral = e.GetDeferral();
183197

184-
if (FilesystemHelpers.HasDraggedStorageItems(e.DataView))
198+
try
185199
{
186-
var deferral = e.GetDeferral();
200+
if (!FilesystemHelpers.HasDraggedStorageItems(e.DataView))
201+
return;
187202

188-
try
189-
{
190-
await _associatedInstance.FilesystemHelpers.PerformOperationTypeAsync(e.AcceptedOperation, e.DataView, _associatedInstance.ShellViewModel.WorkingDirectory, false, true);
191-
await _associatedInstance.RefreshIfNoWatcherExistsAsync();
192-
}
193-
finally
203+
if (e.DataView.Properties.TryGetValue("Files_ActionBinder", out var actionBinder) && actionBinder is "Files_ShelfBinder")
194204
{
195-
deferral.Complete();
205+
if (e.OriginalSource is not UIElement uiElement)
206+
return;
207+
208+
var pwd = _associatedInstance.ShellViewModel.WorkingDirectory.TrimPath();
209+
var folderName = Path.IsPathRooted(pwd) && Path.GetPathRoot(pwd) == pwd ? Path.GetPathRoot(pwd) : Path.GetFileName(pwd);
210+
var menuFlyout = new MenuFlyout()
211+
{
212+
Items =
213+
{
214+
new MenuFlyoutItem() { Text = string.Format("CopyToFolderCaptionText".GetLocalizedResource(), folderName) },
215+
new MenuFlyoutItem() { Text = string.Format("MoveToFolderCaptionText".GetLocalizedResource(), folderName) },
216+
}
217+
};
218+
219+
menuFlyout.ShowAt(uiElement, e.GetPosition(uiElement));
220+
return;
196221
}
222+
223+
await _associatedInstance.FilesystemHelpers.PerformOperationTypeAsync(e.AcceptedOperation, e.DataView, _associatedInstance.ShellViewModel.WorkingDirectory, false, true);
224+
await _associatedInstance.RefreshIfNoWatcherExistsAsync();
225+
}
226+
finally
227+
{
228+
deferral.Complete();
197229
}
198230
}
199231

0 commit comments

Comments
 (0)