1
1
// Copyright (c) 2024 Files Community
2
2
// Licensed under the MIT License. See the LICENSE.
3
3
4
+ using Microsoft . UI . Xaml . Controls ;
5
+ using Windows . Foundation . Metadata ;
6
+
4
7
namespace Files . App . Actions
5
8
{
6
9
internal sealed class RestoreAllRecycleBinAction : BaseUIAction , IAction
7
10
{
11
+ private readonly IWindowsRecycleBinService WindowsRecycleBinService = Ioc . Default . GetRequiredService < IWindowsRecycleBinService > ( ) ;
12
+
8
13
public string Label
9
14
=> "RestoreAllItems" . GetLocalizedResource ( ) ;
10
15
@@ -16,11 +21,65 @@ public RichGlyph Glyph
16
21
17
22
public override bool IsExecutable =>
18
23
UIHelpers . CanShowDialog &&
19
- RecycleBinHelpers . RecycleBinHasItems ( ) ;
24
+ WindowsRecycleBinService . HasItems ( ) ;
20
25
21
26
public async Task ExecuteAsync ( object ? parameter = null )
22
27
{
23
- await RecycleBinHelpers . RestoreRecycleBinAsync ( ) ;
28
+ // TODO: Use AppDialogService
29
+ var confirmationDialog = new ContentDialog ( )
30
+ {
31
+ Title = "ConfirmRestoreBinDialogTitle" . GetLocalizedResource ( ) ,
32
+ Content = "ConfirmRestoreBinDialogContent" . GetLocalizedResource ( ) ,
33
+ PrimaryButtonText = "Yes" . GetLocalizedResource ( ) ,
34
+ SecondaryButtonText = "Cancel" . GetLocalizedResource ( ) ,
35
+ DefaultButton = ContentDialogButton . Primary
36
+ } ;
37
+
38
+ if ( ApiInformation . IsApiContractPresent ( "Windows.Foundation.UniversalApiContract" , 8 ) )
39
+ confirmationDialog . XamlRoot = MainWindow . Instance . Content . XamlRoot ;
40
+
41
+ if ( await confirmationDialog . TryShowAsync ( ) is not ContentDialogResult . Primary )
42
+ return ;
43
+
44
+ //using var sop = new ShellFileOperations { Options = GetDeleteOpFlags(hideUI) };
45
+ //HRESULT hr = HRESULT.S_OK;
46
+
47
+ try
48
+ {
49
+ //foreach (var item in deletedItems)
50
+ //{
51
+ // if (item.Parent != ShellFolderInstance) throw new InvalidOperationException("Unable to restore a ShellItem that is not in the Recycle Bin.");
52
+ // // Manually create a ShellFolder instance to the original location.
53
+ // using var sf = new ShellFolder(Path.GetDirectoryName(item.Name)!);
54
+ // sop.QueueMoveOperation(item, sf, Path.GetFileName(item.Name));
55
+ //}
56
+ //sop.PerformOperations();
57
+ //hr.ThrowIfFailed();
58
+ }
59
+ catch ( Exception )
60
+ {
61
+ var errorDialog = new ContentDialog ( )
62
+ {
63
+ Title = "FailedToRestore" . GetLocalizedResource ( ) ,
64
+ PrimaryButtonText = "OK" . GetLocalizedResource ( ) ,
65
+ } ;
66
+
67
+ if ( ApiInformation . IsApiContractPresent ( "Windows.Foundation.UniversalApiContract" , 8 ) )
68
+ errorDialog . XamlRoot = MainWindow . Instance . Content . XamlRoot ;
69
+
70
+ await errorDialog . TryShowAsync ( ) ;
71
+ }
72
+ finally
73
+ {
74
+ try
75
+ {
76
+ // Call the undocumented function to reset the icon.
77
+ //SHUpdateRecycleBinIcon();
78
+ }
79
+ catch
80
+ {
81
+ }
82
+ }
24
83
}
25
84
}
26
85
}
0 commit comments