Skip to content

Commit 2dff0b6

Browse files
committed
Open settings file action and menu item
1 parent 2f99a52 commit 2dff0b6

File tree

9 files changed

+52
-15
lines changed

9 files changed

+52
-15
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
using Windows.Storage;
5+
using Windows.System;
6+
7+
namespace Files.App.Actions
8+
{
9+
internal sealed partial class OpenSettingsFileAction : IAction
10+
{
11+
public string Label
12+
=> Strings.EditSettingsFile.GetLocalizedResource();
13+
14+
public string Description
15+
=> Strings.EditSettingsFileDescription.GetLocalizedResource();
16+
17+
public HotKey HotKey
18+
=> new(Keys.OemComma, KeyModifiers.CtrlShift);
19+
20+
public RichGlyph Glyph
21+
=> new("\uE8DA");
22+
23+
public async Task ExecuteAsync(object? parameter = null)
24+
{
25+
await SafetyExtensions.IgnoreExceptions(async () =>
26+
{
27+
var settingsJsonFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appdata:///local/settings/user_settings.json"));
28+
if (!await Launcher.LaunchFileAsync(settingsJsonFile))
29+
await ContextMenu.InvokeVerb("open", settingsJsonFile.Path);
30+
});
31+
}
32+
}
33+
}

src/Files.App/Data/Commands/Manager/CommandCodes.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public enum CommandCodes
118118
OpenReleaseNotes,
119119
OpenClassicProperties,
120120
OpenSettings,
121+
OpenSettingsFile,
121122
OpenStorageSense,
122123
OpenStorageSenseFromHome,
123124
OpenStorageSenseFromSidebar,

src/Files.App/Data/Commands/Manager/CommandManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public IRichCommand this[HotKey hotKey]
122122
public IRichCommand OpenStorageSenseFromHome => commands[CommandCodes.OpenStorageSenseFromHome];
123123
public IRichCommand OpenStorageSenseFromSidebar => commands[CommandCodes.OpenStorageSenseFromSidebar];
124124
public IRichCommand OpenSettings => commands[CommandCodes.OpenSettings];
125+
public IRichCommand OpenSettingsFile => commands[CommandCodes.OpenSettingsFile];
125126
public IRichCommand OpenTerminal => commands[CommandCodes.OpenTerminal];
126127
public IRichCommand OpenTerminalAsAdmin => commands[CommandCodes.OpenTerminalAsAdmin];
127128
public IRichCommand OpenTerminalFromSidebar => commands[CommandCodes.OpenTerminalFromSidebar];
@@ -327,6 +328,7 @@ public IEnumerator<IRichCommand> GetEnumerator() =>
327328
[CommandCodes.OpenStorageSenseFromHome] = new OpenStorageSenseFromHomeAction(),
328329
[CommandCodes.OpenStorageSenseFromSidebar] = new OpenStorageSenseFromSidebarAction(),
329330
[CommandCodes.OpenSettings] = new OpenSettingsAction(),
331+
[CommandCodes.OpenSettingsFile] = new OpenSettingsFileAction(),
330332
[CommandCodes.OpenTerminal] = new OpenTerminalAction(),
331333
[CommandCodes.OpenTerminalAsAdmin] = new OpenTerminalAsAdminAction(),
332334
[CommandCodes.OpenTerminalFromSidebar] = new OpenTerminalFromSidebarAction(),

src/Files.App/Data/Commands/Manager/ICommandManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
110110
IRichCommand OpenStorageSenseFromHome { get; }
111111
IRichCommand OpenStorageSenseFromSidebar { get; }
112112
IRichCommand OpenSettings { get; }
113+
IRichCommand OpenSettingsFile { get; }
113114
IRichCommand OpenTerminal { get; }
114115
IRichCommand OpenTerminalAsAdmin { get; }
115116
IRichCommand OpenTerminalFromSidebar { get; }

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,6 +2195,9 @@
21952195
<data name="EditSettingsFile" xml:space="preserve">
21962196
<value>Edit settings file</value>
21972197
</data>
2198+
<data name="EditSettingsFileDescription" xml:space="preserve">
2199+
<value>Open settings file in your default editor</value>
2200+
</data>
21982201
<data name="WhatsNew" xml:space="preserve">
21992202
<value>What's new</value>
22002203
</data>

src/Files.App/ViewModels/Settings/AdvancedViewModel.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ public sealed partial class AdvancedViewModel : ObservableObject
1919
{
2020
private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService<IUserSettingsService>();
2121
private ICommonDialogService CommonDialogService { get; } = Ioc.Default.GetRequiredService<ICommonDialogService>();
22+
public ICommandManager Commands { get; } = Ioc.Default.GetRequiredService<ICommandManager>();
2223

2324
private readonly IFileTagsSettingsService fileTagsSettingsService = Ioc.Default.GetRequiredService<IFileTagsSettingsService>();
2425

2526
public ICommand SetAsDefaultExplorerCommand { get; }
2627
public ICommand SetAsOpenFileDialogCommand { get; }
2728
public ICommand ExportSettingsCommand { get; }
2829
public ICommand ImportSettingsCommand { get; }
29-
public ICommand OpenSettingsJsonCommand { get; }
3030
public AsyncRelayCommand OpenFilesOnWindowsStartupCommand { get; }
3131

3232

@@ -39,22 +39,11 @@ public AdvancedViewModel()
3939
SetAsOpenFileDialogCommand = new AsyncRelayCommand(SetAsOpenFileDialogAsync);
4040
ExportSettingsCommand = new AsyncRelayCommand(ExportSettingsAsync);
4141
ImportSettingsCommand = new AsyncRelayCommand(ImportSettingsAsync);
42-
OpenSettingsJsonCommand = new AsyncRelayCommand(OpenSettingsJsonAsync);
4342
OpenFilesOnWindowsStartupCommand = new AsyncRelayCommand(OpenFilesOnWindowsStartupAsync);
4443

4544
_ = DetectOpenFilesAtStartupAsync();
4645
}
4746

48-
private async Task OpenSettingsJsonAsync()
49-
{
50-
await SafetyExtensions.IgnoreExceptions(async () =>
51-
{
52-
var settingsJsonFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appdata:///local/settings/user_settings.json"));
53-
if (!await Launcher.LaunchFileAsync(settingsJsonFile))
54-
await ContextMenu.InvokeVerb("open", settingsJsonFile.Path);
55-
});
56-
}
57-
5847
private async Task SetAsDefaultExplorerAsync()
5948
{
6049
// Make sure IsSetAsDefaultFileManager is updated

src/Files.App/Views/MainPage.xaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,15 @@
308308
Margin="12,0,0,0"
309309
Text="{x:Bind Commands.OpenSettings.Label, Mode=OneWay}" />
310310
</Grid>
311+
312+
<Button.ContextFlyout>
313+
<MenuFlyout>
314+
<MenuFlyoutItem
315+
Command="{x:Bind Commands.OpenSettingsFile, Mode=OneWay}"
316+
Icon="{x:Bind Commands.OpenSettingsFile.FontIcon, Mode=OneWay}"
317+
Text="{x:Bind Commands.OpenSettingsFile.Label, Mode=OneWay}" />
318+
</MenuFlyout>
319+
</Button.ContextFlyout>
311320
</Button>
312321
</StackPanel>
313322
</controls:SidebarView.Footer>

src/Files.App/Views/MainPage.xaml.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public sealed partial class MainPage : Page
2828
private IGeneralSettingsService generalSettingsService { get; } = Ioc.Default.GetRequiredService<IGeneralSettingsService>();
2929
public IUserSettingsService UserSettingsService { get; }
3030
private readonly IWindowContext WindowContext = Ioc.Default.GetRequiredService<IWindowContext>();
31-
public ICommandManager Commands { get; }
31+
public ICommandManager Commands { get; } = Ioc.Default.GetRequiredService<ICommandManager>();
3232
public SidebarViewModel SidebarAdaptiveViewModel { get; }
3333
public MainPageViewModel ViewModel { get; }
3434

@@ -42,7 +42,6 @@ public MainPage()
4242

4343
// Dependency Injection
4444
UserSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
45-
Commands = Ioc.Default.GetRequiredService<ICommandManager>();
4645
SidebarAdaptiveViewModel = Ioc.Default.GetRequiredService<SidebarViewModel>();
4746
SidebarAdaptiveViewModel.PaneFlyout = (MenuFlyout)Resources["SidebarContextMenu"];
4847
ViewModel = Ioc.Default.GetRequiredService<MainPageViewModel>();

src/Files.App/Views/Settings/AdvancedPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363

6464
<!-- Edit Settings File -->
6565
<wctcontrols:SettingsCard
66-
Command="{x:Bind ViewModel.OpenSettingsJsonCommand}"
66+
Command="{x:Bind ViewModel.Commands.OpenSettingsFile, Mode=OneWay}"
6767
Header="{helpers:ResourceString Name=EditSettingsFile}"
6868
IsClickEnabled="True">
6969
<wctcontrols:SettingsCard.HeaderIcon>

0 commit comments

Comments
 (0)