Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/Files.App/Actions/Open/OpenSettingsFileAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Files Community
// Licensed under the MIT License.

using Windows.Storage;
using Windows.System;

namespace Files.App.Actions
{
internal sealed partial class OpenSettingsFileAction : IAction
{
public string Label
=> Strings.EditSettingsFile.GetLocalizedResource();

public string Description
=> Strings.EditSettingsFileDescription.GetLocalizedResource();

public HotKey HotKey
=> new(Keys.OemComma, KeyModifiers.CtrlShift);

public RichGlyph Glyph
=> new("\uE8DA");

public async Task ExecuteAsync(object? parameter = null)
{
await SafetyExtensions.IgnoreExceptions(async () =>
{
var settingsJsonFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appdata:///local/settings/user_settings.json"));
if (!await Launcher.LaunchFileAsync(settingsJsonFile))
await ContextMenu.InvokeVerb("open", settingsJsonFile.Path);
});
}
}
}
1 change: 1 addition & 0 deletions src/Files.App/Data/Commands/Manager/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public enum CommandCodes
OpenReleaseNotes,
OpenClassicProperties,
OpenSettings,
OpenSettingsFile,
OpenStorageSense,
OpenStorageSenseFromHome,
OpenStorageSenseFromSidebar,
Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Data/Commands/Manager/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public IRichCommand this[HotKey hotKey]
public IRichCommand OpenStorageSenseFromHome => commands[CommandCodes.OpenStorageSenseFromHome];
public IRichCommand OpenStorageSenseFromSidebar => commands[CommandCodes.OpenStorageSenseFromSidebar];
public IRichCommand OpenSettings => commands[CommandCodes.OpenSettings];
public IRichCommand OpenSettingsFile => commands[CommandCodes.OpenSettingsFile];
public IRichCommand OpenTerminal => commands[CommandCodes.OpenTerminal];
public IRichCommand OpenTerminalAsAdmin => commands[CommandCodes.OpenTerminalAsAdmin];
public IRichCommand OpenTerminalFromSidebar => commands[CommandCodes.OpenTerminalFromSidebar];
Expand Down Expand Up @@ -327,6 +328,7 @@ public IEnumerator<IRichCommand> GetEnumerator() =>
[CommandCodes.OpenStorageSenseFromHome] = new OpenStorageSenseFromHomeAction(),
[CommandCodes.OpenStorageSenseFromSidebar] = new OpenStorageSenseFromSidebarAction(),
[CommandCodes.OpenSettings] = new OpenSettingsAction(),
[CommandCodes.OpenSettingsFile] = new OpenSettingsFileAction(),
[CommandCodes.OpenTerminal] = new OpenTerminalAction(),
[CommandCodes.OpenTerminalAsAdmin] = new OpenTerminalAsAdminAction(),
[CommandCodes.OpenTerminalFromSidebar] = new OpenTerminalFromSidebarAction(),
Expand Down
1 change: 1 addition & 0 deletions src/Files.App/Data/Commands/Manager/ICommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
IRichCommand OpenStorageSenseFromHome { get; }
IRichCommand OpenStorageSenseFromSidebar { get; }
IRichCommand OpenSettings { get; }
IRichCommand OpenSettingsFile { get; }
IRichCommand OpenTerminal { get; }
IRichCommand OpenTerminalAsAdmin { get; }
IRichCommand OpenTerminalFromSidebar { get; }
Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -2195,6 +2195,9 @@
<data name="EditSettingsFile" xml:space="preserve">
<value>Edit settings file</value>
</data>
<data name="EditSettingsFileDescription" xml:space="preserve">
<value>Open settings file in your default editor</value>
</data>
<data name="WhatsNew" xml:space="preserve">
<value>What's new</value>
</data>
Expand Down
13 changes: 1 addition & 12 deletions src/Files.App/ViewModels/Settings/AdvancedViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ public sealed partial class AdvancedViewModel : ObservableObject
{
private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService<IUserSettingsService>();
private ICommonDialogService CommonDialogService { get; } = Ioc.Default.GetRequiredService<ICommonDialogService>();
public ICommandManager Commands { get; } = Ioc.Default.GetRequiredService<ICommandManager>();

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

public ICommand SetAsDefaultExplorerCommand { get; }
public ICommand SetAsOpenFileDialogCommand { get; }
public ICommand ExportSettingsCommand { get; }
public ICommand ImportSettingsCommand { get; }
public ICommand OpenSettingsJsonCommand { get; }
public AsyncRelayCommand OpenFilesOnWindowsStartupCommand { get; }


Expand All @@ -39,22 +39,11 @@ public AdvancedViewModel()
SetAsOpenFileDialogCommand = new AsyncRelayCommand(SetAsOpenFileDialogAsync);
ExportSettingsCommand = new AsyncRelayCommand(ExportSettingsAsync);
ImportSettingsCommand = new AsyncRelayCommand(ImportSettingsAsync);
OpenSettingsJsonCommand = new AsyncRelayCommand(OpenSettingsJsonAsync);
OpenFilesOnWindowsStartupCommand = new AsyncRelayCommand(OpenFilesOnWindowsStartupAsync);

_ = DetectOpenFilesAtStartupAsync();
}

private async Task OpenSettingsJsonAsync()
{
await SafetyExtensions.IgnoreExceptions(async () =>
{
var settingsJsonFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appdata:///local/settings/user_settings.json"));
if (!await Launcher.LaunchFileAsync(settingsJsonFile))
await ContextMenu.InvokeVerb("open", settingsJsonFile.Path);
});
}

private async Task SetAsDefaultExplorerAsync()
{
// Make sure IsSetAsDefaultFileManager is updated
Expand Down
12 changes: 10 additions & 2 deletions src/Files.App/Views/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,7 @@
Background="Transparent"
BorderThickness="0"
Command="{x:Bind Commands.OpenSettings, Mode=OneWay}"
ToolTipService.Placement="Bottom"
ToolTipService.ToolTip="{x:Bind Commands.OpenSettings.LabelWithHotKey, Mode=OneWay}">
ToolTipService.Placement="Bottom">
<Button.Resources>
<SolidColorBrush x:Key="ButtonBackgroundPointerOver" Color="{ThemeResource SubtleFillColorSecondary}" />
<SolidColorBrush x:Key="ButtonForegroundDisabled" Color="{ThemeResource TextFillColorPrimary}" />
Expand All @@ -308,6 +307,15 @@
Margin="12,0,0,0"
Text="{x:Bind Commands.OpenSettings.Label, Mode=OneWay}" />
</Grid>

<Button.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem
Command="{x:Bind Commands.OpenSettingsFile, Mode=OneWay}"
Icon="{x:Bind Commands.OpenSettingsFile.FontIcon, Mode=OneWay}"
Text="{x:Bind Commands.OpenSettingsFile.Label, Mode=OneWay}" />
</MenuFlyout>
</Button.ContextFlyout>
</Button>
</StackPanel>
</controls:SidebarView.Footer>
Expand Down
3 changes: 1 addition & 2 deletions src/Files.App/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public sealed partial class MainPage : Page
private IGeneralSettingsService generalSettingsService { get; } = Ioc.Default.GetRequiredService<IGeneralSettingsService>();
public IUserSettingsService UserSettingsService { get; }
private readonly IWindowContext WindowContext = Ioc.Default.GetRequiredService<IWindowContext>();
public ICommandManager Commands { get; }
public ICommandManager Commands { get; } = Ioc.Default.GetRequiredService<ICommandManager>();
public SidebarViewModel SidebarAdaptiveViewModel { get; }
public MainPageViewModel ViewModel { get; }

Expand All @@ -42,7 +42,6 @@ public MainPage()

// Dependency Injection
UserSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
Commands = Ioc.Default.GetRequiredService<ICommandManager>();
SidebarAdaptiveViewModel = Ioc.Default.GetRequiredService<SidebarViewModel>();
SidebarAdaptiveViewModel.PaneFlyout = (MenuFlyout)Resources["SidebarContextMenu"];
ViewModel = Ioc.Default.GetRequiredService<MainPageViewModel>();
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Views/Settings/AdvancedPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

<!-- Edit Settings File -->
<wctcontrols:SettingsCard
Command="{x:Bind ViewModel.OpenSettingsJsonCommand}"
Command="{x:Bind ViewModel.Commands.OpenSettingsFile, Mode=OneWay}"
Header="{helpers:ResourceString Name=EditSettingsFile}"
IsClickEnabled="True">
<wctcontrols:SettingsCard.HeaderIcon>
Expand Down
Loading