|
| 1 | +using CommunityToolkit.Mvvm.ComponentModel; |
| 2 | +using CommunityToolkit.Mvvm.DependencyInjection; |
| 3 | +using Files.App.Commands; |
| 4 | +using Files.App.Contexts; |
| 5 | +using Files.App.Extensions; |
| 6 | +using Files.App.Helpers; |
| 7 | +using Files.App.Shell; |
| 8 | +using Files.Backend.Helpers; |
| 9 | +using System.Threading.Tasks; |
| 10 | + |
| 11 | +namespace Files.App.Actions |
| 12 | +{ |
| 13 | + internal class RunWithPowershellAction : ObservableObject, IAction |
| 14 | + { |
| 15 | + private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>(); |
| 16 | + |
| 17 | + public bool IsExecutable => context.SelectedItem is not null && |
| 18 | + FileExtensionHelpers.IsPowerShellFile(context.SelectedItem.FileExtension); |
| 19 | + |
| 20 | + public string Label => "RunWithPowerShell".GetLocalizedResource(); |
| 21 | + |
| 22 | + public string Description => "TODO: Need to be described."; |
| 23 | + |
| 24 | + public RichGlyph Glyph => new("\uE756"); |
| 25 | + |
| 26 | + public RunWithPowershellAction() |
| 27 | + { |
| 28 | + context.PropertyChanged += Context_PropertyChanged; |
| 29 | + } |
| 30 | + |
| 31 | + public async Task ExecuteAsync() |
| 32 | + { |
| 33 | + Win32API.RunPowershellCommand($"{context.ShellPage?.SlimContentPage?.SelectedItem.ItemPath}", false); |
| 34 | + } |
| 35 | + |
| 36 | + private void Context_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) |
| 37 | + { |
| 38 | + switch (e.PropertyName) |
| 39 | + { |
| 40 | + case nameof(IContentPageContext.SelectedItems): |
| 41 | + case nameof(IContentPageContext.Folder): |
| 42 | + OnPropertyChanged(nameof(IsExecutable)); |
| 43 | + break; |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | +} |
0 commit comments