Skip to content

Commit ffb6a53

Browse files
yaira2hishitetsu
andauthored
Feature: Added "Edit in notepad" action to the right click context menu (#15435)
Co-authored-by: hishitetsu <66369541+hishitetsu@users.noreply.github.com>
1 parent c101ce2 commit ffb6a53

File tree

6 files changed

+23
-5
lines changed

6 files changed

+23
-5
lines changed

src/Files.App/Actions/Content/Run/RunAsAdminAction.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public override RichGlyph Glyph
2020

2121
public override bool IsExecutable =>
2222
ContentPageContext.SelectedItem is not null &&
23+
ContentPageContext.PageType != ContentPageTypes.RecycleBin &&
24+
ContentPageContext.PageType != ContentPageTypes.ZipFolder &&
2325
(FileExtensionHelpers.IsExecutableFile(ContentPageContext.SelectedItem.FileExtension) ||
2426
(ContentPageContext.SelectedItem is ShortcutItem shortcut &&
2527
shortcut.IsExecutable));

src/Files.App/Actions/Content/Run/RunAsAnotherUserAction.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public override RichGlyph Glyph
1919

2020
public override bool IsExecutable =>
2121
ContentPageContext.SelectedItem is not null &&
22+
ContentPageContext.PageType != ContentPageTypes.RecycleBin &&
23+
ContentPageContext.PageType != ContentPageTypes.ZipFolder &&
2224
!FileExtensionHelpers.IsAhkFile(ContentPageContext.SelectedItem.FileExtension) &&
2325
(FileExtensionHelpers.IsExecutableFile(ContentPageContext.SelectedItem.FileExtension) ||
2426
(ContentPageContext.SelectedItem is ShortcutItem shortcut &&

src/Files.App/Actions/FileSystem/CreateFolderWithSelectionAction.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public RichGlyph Glyph
1818

1919
public bool IsExecutable =>
2020
context.ShellPage is not null &&
21+
context.PageType != ContentPageTypes.RecycleBin &&
22+
context.PageType != ContentPageTypes.ZipFolder &&
2123
context.HasSelection;
2224

2325
public CreateFolderWithSelectionAction()

src/Files.App/Actions/Open/EditInNotepadAction.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ public RichGlyph Glyph
1919
=> new("\uE70F");
2020

2121
public bool IsExecutable =>
22-
context.SelectedItem is not null &&
23-
FileExtensionHelpers.IsBatchFile(context.SelectedItem.FileExtension);
22+
context.SelectedItems.Any() &&
23+
context.PageType != ContentPageTypes.RecycleBin &&
24+
context.PageType != ContentPageTypes.ZipFolder &&
25+
context.SelectedItems.All(x => FileExtensionHelpers.IsBatchFile(x.FileExtension) || FileExtensionHelpers.IsAhkFile(x.FileExtension) || FileExtensionHelpers.IsCmdFile(x.FileExtension));
2426

2527
public EditInNotepadAction()
2628
{
@@ -31,8 +33,7 @@ public EditInNotepadAction()
3133

3234
public Task ExecuteAsync(object? parameter = null)
3335
{
34-
return Win32Helper.RunPowershellCommandAsync($"notepad '{context.ShellPage?.SlimContentPage?.SelectedItem?.ItemPath}\'", false);
35-
36+
return Task.WhenAll(context.SelectedItems.Select(item => Win32Helper.RunPowershellCommandAsync($"notepad '{item.ItemPath}\'", false)));
3637
}
3738

3839
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
@@ -45,4 +46,4 @@ private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
4546
}
4647
}
4748
}
48-
}
49+
}

src/Files.App/Data/Factories/ContentPageContextFlyoutFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
589589
ShowInRecycleBin = true,
590590
ShowInSearchPage = true,
591591
},
592+
new ContextMenuFlyoutItemViewModelBuilder(Commands.EditInNotepad).Build(),
592593
new ContextMenuFlyoutItemViewModel()
593594
{
594595
Text = "Loading".GetLocalizedResource(),

src/Files.Shared/Helpers/FileExtensionHelpers.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,16 @@ public static bool IsAhkFile(string? filePathToCheck)
173173
return HasExtension(filePathToCheck, ".ahk");
174174
}
175175

176+
/// <summary>
177+
/// Check if the file path is a cmd file.
178+
/// </summary>
179+
/// <param name="filePathToCheck">The file path to check.</param>
180+
/// <returns><c>true</c> if the filePathToCheck is a cmd file; otherwise, <c>false</c>.</returns>
181+
public static bool IsCmdFile(string? filePathToCheck)
182+
{
183+
return HasExtension(filePathToCheck, ".cmd");
184+
}
185+
176186
/// <summary>
177187
/// Check if the file path is an msi installer file.
178188
/// </summary>

0 commit comments

Comments
 (0)