-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
RunWithPowershellAction.cs
48 lines (38 loc) · 1.27 KB
/
RunWithPowershellAction.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
48
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.
using Files.Shared.Helpers;
namespace Files.App.Actions
{
internal sealed class RunWithPowershellAction : ObservableObject, IAction
{
private readonly IContentPageContext context;
public string Label
=> "RunWithPowerShell".GetLocalizedResource();
public string Description
=> "RunWithPowershellDescription".GetLocalizedResource();
public RichGlyph Glyph
=> new("\uE756");
public bool IsExecutable =>
context.SelectedItem is not null &&
FileExtensionHelpers.IsPowerShellFile(context.SelectedItem.FileExtension);
public RunWithPowershellAction()
{
context = Ioc.Default.GetRequiredService<IContentPageContext>();
context.PropertyChanged += Context_PropertyChanged;
}
public Task ExecuteAsync(object? parameter = null)
{
return Win32Helper.RunPowershellCommandAsync($"{context.ShellPage?.SlimContentPage?.SelectedItem?.ItemPath}", PowerShellExecutionOptions.None);
}
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IContentPageContext.SelectedItems):
case nameof(IContentPageContext.Folder):
OnPropertyChanged(nameof(IsExecutable));
break;
}
}
}
}