-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
BaseCompressArchiveAction.cs
47 lines (38 loc) · 1.2 KB
/
BaseCompressArchiveAction.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.
namespace Files.App.Actions
{
internal abstract class BaseCompressArchiveAction : BaseUIAction, IAction
{
protected readonly IContentPageContext context;
public abstract string Label { get; }
public abstract string Description { get; }
public override bool IsExecutable =>
IsContextPageTypeAdaptedToCommand() &&
CompressHelper.CanCompress(context.SelectedItems) &&
UIHelpers.CanShowDialog;
public BaseCompressArchiveAction()
{
context = Ioc.Default.GetRequiredService<IContentPageContext>();
context.PropertyChanged += Context_PropertyChanged;
}
public abstract Task ExecuteAsync();
private bool IsContextPageTypeAdaptedToCommand()
{
return
context.PageType != ContentPageTypes.RecycleBin &&
context.PageType != ContentPageTypes.ZipFolder &&
context.PageType != ContentPageTypes.None;
}
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IContentPageContext.SelectedItems):
if (IsContextPageTypeAdaptedToCommand())
OnPropertyChanged(nameof(IsExecutable));
break;
}
}
}
}