Skip to content

Commit 20e2603

Browse files
committed
Fixed copying and cutting shortcuts
1 parent 2159b62 commit 20e2603

File tree

3 files changed

+158
-145
lines changed

3 files changed

+158
-145
lines changed

Files/Helpers/UIFilesystemHelpers.cs

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,163 @@
77
using System.Threading.Tasks;
88
using Windows.ApplicationModel.DataTransfer;
99
using Windows.Storage;
10+
using System.Collections.Generic;
11+
using Windows.ApplicationModel.AppService;
12+
using Windows.Foundation.Collections;
1013

1114
namespace Files.Helpers
1215
{
1316
public static class UIFilesystemHelpers
1417
{
18+
public static async void CutItem(IShellPage associatedInstance)
19+
{
20+
DataPackage dataPackage = new DataPackage
21+
{
22+
RequestedOperation = DataPackageOperation.Move
23+
};
24+
List<IStorageItem> items = new List<IStorageItem>();
25+
FilesystemResult result = (FilesystemResult)false;
26+
27+
if (associatedInstance.SlimContentPage.IsItemSelected)
28+
{
29+
// First, reset DataGrid Rows that may be in "cut" command mode
30+
associatedInstance.SlimContentPage.ResetItemOpacity();
31+
32+
foreach (ListedItem listedItem in associatedInstance.SlimContentPage.SelectedItems)
33+
{
34+
// Dim opacities accordingly
35+
associatedInstance.SlimContentPage.SetItemOpacity(listedItem);
36+
37+
if (listedItem.PrimaryItemAttribute == StorageItemTypes.File)
38+
{
39+
result = await associatedInstance.FilesystemViewModel.GetFileFromPathAsync(listedItem.ItemPath)
40+
.OnSuccess(t => items.Add(t));
41+
if (!result)
42+
{
43+
break;
44+
}
45+
}
46+
else
47+
{
48+
result = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(listedItem.ItemPath)
49+
.OnSuccess(t => items.Add(t));
50+
if (!result)
51+
{
52+
break;
53+
}
54+
}
55+
}
56+
if (result.ErrorCode == FileSystemStatusCode.NotFound)
57+
{
58+
associatedInstance.SlimContentPage.ResetItemOpacity();
59+
return;
60+
}
61+
else if (result.ErrorCode == FileSystemStatusCode.Unauthorized)
62+
{
63+
// Try again with fulltrust process
64+
if (associatedInstance.ServiceConnection != null)
65+
{
66+
string filePaths = string.Join('|', SlimContentPage.SelectedItems.Select(x => x.ItemPath));
67+
AppServiceResponseStatus status = await ServiceConnection.SendMessageAsync(new ValueSet()
68+
{
69+
{ "Arguments", "FileOperation" },
70+
{ "fileop", "Clipboard" },
71+
{ "filepath", filePaths },
72+
{ "operation", (int)DataPackageOperation.Move }
73+
});
74+
if (status == AppServiceResponseStatus.Success)
75+
{
76+
return;
77+
}
78+
}
79+
associatedInstance.SlimContentPage.ResetItemOpacity();
80+
return;
81+
}
82+
}
83+
84+
if (!items.Any())
85+
{
86+
return;
87+
}
88+
dataPackage.SetStorageItems(items);
89+
try
90+
{
91+
Clipboard.SetContent(dataPackage);
92+
Clipboard.Flush();
93+
}
94+
catch
95+
{
96+
dataPackage = null;
97+
}
98+
}
99+
100+
public static async void CopyItem(IShellPage associatedInstance)
101+
{
102+
DataPackage dataPackage = new DataPackage()
103+
{
104+
RequestedOperation = DataPackageOperation.Copy
105+
};
106+
List<IStorageItem> items = new List<IStorageItem>();
107+
108+
string copySourcePath = associatedInstance.FilesystemViewModel.WorkingDirectory;
109+
FilesystemResult result = (FilesystemResult)false;
110+
111+
if (associatedInstance.SlimContentPage.IsItemSelected)
112+
{
113+
foreach (ListedItem listedItem in associatedInstance.SlimContentPage.SelectedItems)
114+
{
115+
if (listedItem.PrimaryItemAttribute == StorageItemTypes.File)
116+
{
117+
result = await associatedInstance.FilesystemViewModel.GetFileFromPathAsync(listedItem.ItemPath)
118+
.OnSuccess(t => items.Add(t));
119+
if (!result)
120+
{
121+
break;
122+
}
123+
}
124+
else
125+
{
126+
result = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(listedItem.ItemPath)
127+
.OnSuccess(t => items.Add(t));
128+
if (!result)
129+
{
130+
break;
131+
}
132+
}
133+
}
134+
if (result.ErrorCode == FileSystemStatusCode.Unauthorized)
135+
{
136+
// Try again with fulltrust process
137+
if (associatedInstance.ServiceConnection != null)
138+
{
139+
string filePaths = string.Join('|', associatedInstance.SlimContentPage.SelectedItems.Select(x => x.ItemPath));
140+
await associatedInstance.ServiceConnection.SendMessageAsync(new ValueSet()
141+
{
142+
{ "Arguments", "FileOperation" },
143+
{ "fileop", "Clipboard" },
144+
{ "filepath", filePaths },
145+
{ "operation", (int)DataPackageOperation.Copy }
146+
});
147+
}
148+
return;
149+
}
150+
}
151+
152+
if (items?.Count > 0)
153+
{
154+
dataPackage.SetStorageItems(items);
155+
try
156+
{
157+
Clipboard.SetContent(dataPackage);
158+
Clipboard.Flush();
159+
}
160+
catch
161+
{
162+
dataPackage = null;
163+
}
164+
}
165+
}
166+
15167
public static async Task PasteItemAsync(string destinationPath, IShellPage associatedInstance)
16168
{
17169
DataPackageView packageView = await FilesystemTasks.Wrap(() => Task.FromResult(Clipboard.GetContent()));

Files/Interacts/BaseLayoutCommandImplementationModel.cs

Lines changed: 4 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -158,153 +158,14 @@ public virtual void QuickLook(RoutedEventArgs e)
158158
QuickLookHelpers.ToggleQuickLook(associatedInstance);
159159
}
160160

161-
public virtual async void CopyItem(RoutedEventArgs e)
161+
public virtual void CopyItem(RoutedEventArgs e)
162162
{
163-
DataPackage dataPackage = new DataPackage()
164-
{
165-
RequestedOperation = DataPackageOperation.Copy
166-
};
167-
List<IStorageItem> items = new List<IStorageItem>();
168-
169-
string copySourcePath = associatedInstance.FilesystemViewModel.WorkingDirectory;
170-
FilesystemResult result = (FilesystemResult)false;
171-
172-
if (SlimContentPage.IsItemSelected)
173-
{
174-
foreach (ListedItem listedItem in SlimContentPage.SelectedItems)
175-
{
176-
if (listedItem.PrimaryItemAttribute == StorageItemTypes.File)
177-
{
178-
result = await associatedInstance.FilesystemViewModel.GetFileFromPathAsync(listedItem.ItemPath)
179-
.OnSuccess(t => items.Add(t));
180-
if (!result)
181-
{
182-
break;
183-
}
184-
}
185-
else
186-
{
187-
result = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(listedItem.ItemPath)
188-
.OnSuccess(t => items.Add(t));
189-
if (!result)
190-
{
191-
break;
192-
}
193-
}
194-
}
195-
if (result.ErrorCode == FileSystemStatusCode.Unauthorized)
196-
{
197-
// Try again with fulltrust process
198-
if (ServiceConnection != null)
199-
{
200-
string filePaths = string.Join('|', SlimContentPage.SelectedItems.Select(x => x.ItemPath));
201-
await ServiceConnection.SendMessageAsync(new ValueSet()
202-
{
203-
{ "Arguments", "FileOperation" },
204-
{ "fileop", "Clipboard" },
205-
{ "filepath", filePaths },
206-
{ "operation", (int)DataPackageOperation.Copy }
207-
});
208-
}
209-
return;
210-
}
211-
}
212-
213-
if (items?.Count > 0)
214-
{
215-
dataPackage.SetStorageItems(items);
216-
try
217-
{
218-
Clipboard.SetContent(dataPackage);
219-
Clipboard.Flush();
220-
}
221-
catch
222-
{
223-
dataPackage = null;
224-
}
225-
}
163+
UIFilesystemHelpers.CopyItem(associatedInstance);
226164
}
227165

228-
public virtual async void CutItem(RoutedEventArgs e)
166+
public virtual void CutItem(RoutedEventArgs e)
229167
{
230-
DataPackage dataPackage = new DataPackage
231-
{
232-
RequestedOperation = DataPackageOperation.Move
233-
};
234-
List<IStorageItem> items = new List<IStorageItem>();
235-
FilesystemResult result = (FilesystemResult)false;
236-
237-
if (SlimContentPage.IsItemSelected)
238-
{
239-
// First, reset DataGrid Rows that may be in "cut" command mode
240-
SlimContentPage.ResetItemOpacity();
241-
242-
foreach (ListedItem listedItem in SlimContentPage.SelectedItems)
243-
{
244-
// Dim opacities accordingly
245-
SlimContentPage.SetItemOpacity(listedItem);
246-
247-
if (listedItem.PrimaryItemAttribute == StorageItemTypes.File)
248-
{
249-
result = await associatedInstance.FilesystemViewModel.GetFileFromPathAsync(listedItem.ItemPath)
250-
.OnSuccess(t => items.Add(t));
251-
if (!result)
252-
{
253-
break;
254-
}
255-
}
256-
else
257-
{
258-
result = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(listedItem.ItemPath)
259-
.OnSuccess(t => items.Add(t));
260-
if (!result)
261-
{
262-
break;
263-
}
264-
}
265-
}
266-
if (result.ErrorCode == FileSystemStatusCode.NotFound)
267-
{
268-
SlimContentPage.ResetItemOpacity();
269-
return;
270-
}
271-
else if (result.ErrorCode == FileSystemStatusCode.Unauthorized)
272-
{
273-
// Try again with fulltrust process
274-
if (ServiceConnection != null)
275-
{
276-
string filePaths = string.Join('|', SlimContentPage.SelectedItems.Select(x => x.ItemPath));
277-
AppServiceResponseStatus status = await ServiceConnection.SendMessageAsync(new ValueSet()
278-
{
279-
{ "Arguments", "FileOperation" },
280-
{ "fileop", "Clipboard" },
281-
{ "filepath", filePaths },
282-
{ "operation", (int)DataPackageOperation.Move }
283-
});
284-
if (status == AppServiceResponseStatus.Success)
285-
{
286-
return;
287-
}
288-
}
289-
SlimContentPage.ResetItemOpacity();
290-
return;
291-
}
292-
}
293-
294-
if (!items.Any())
295-
{
296-
return;
297-
}
298-
dataPackage.SetStorageItems(items);
299-
try
300-
{
301-
Clipboard.SetContent(dataPackage);
302-
Clipboard.Flush();
303-
}
304-
catch
305-
{
306-
dataPackage = null;
307-
}
168+
UIFilesystemHelpers.CutItem(associatedInstance);
308169
}
309170

310171
public virtual async void RestoreItem(RoutedEventArgs e)

Files/Views/ModernShellPage.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ await FilesystemHelpers.DeleteItemsAsync(
980980
case (true, false, false, true, VirtualKey.C): // ctrl + c, copy
981981
if (!NavigationToolbar.IsEditModeEnabled && !ContentPage.IsRenamingItem)
982982
{
983-
FilePropertiesHelpers.ShowProperties(this);
983+
UIFilesystemHelpers.CopyItem(this);
984984
}
985985

986986
break;
@@ -996,7 +996,7 @@ await FilesystemHelpers.DeleteItemsAsync(
996996
case (true, false, false, true, VirtualKey.X): // ctrl + x, cut
997997
if (!NavigationToolbar.IsEditModeEnabled && !ContentPage.IsRenamingItem)
998998
{
999-
FilePropertiesHelpers.ShowProperties(this);
999+
UIFilesystemHelpers.CutItem(this);
10001000
}
10011001

10021002
break;

0 commit comments

Comments
 (0)