[File locksmith]Add setting to show only in extended context menu (#26711)

* [File Locksmith] Move File Locksmith "What's using this file?" into the extended context menu

* [File Locksmith] Add FileLocksmithExt to directory background context menu

* [File Locksmith]
* Directory background right click crash fixed.
*Settings added.

* [File Locksmith] Remove uncessary things.

* [File Locksmith] Spell check correction
This commit is contained in:
gokcekantarci
2023-06-14 12:06:44 +03:00
committed by GitHub
parent a780e6ae72
commit 293b06d083
13 changed files with 273 additions and 11 deletions

View File

@@ -3,6 +3,8 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Globalization;
using System.Text.Json;
using global::PowerToys.GPOWrapper;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
@@ -14,8 +16,18 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
private GeneralSettings GeneralSettingsConfig { get; set; }
public FileLocksmithViewModel(ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc)
private readonly ISettingsUtils _settingsUtils;
private FileLocksmithSettings Settings { get; set; }
private const string ModuleName = FileLocksmithSettings.ModuleName;
private string _settingsConfigFileFolder = string.Empty;
public FileLocksmithViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
{
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
// To obtain the general settings configurations of PowerToys Settings.
if (settingsRepository == null)
{
@@ -24,10 +36,29 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
GeneralSettingsConfig = settingsRepository.SettingsConfig;
try
{
FileLocksmithLocalProperties localSettings = _settingsUtils.GetSettingsOrDefault<FileLocksmithLocalProperties>(GetSettingsSubPath(), "file-locksmith-settings.json");
Settings = new FileLocksmithSettings(localSettings);
}
catch (Exception)
{
FileLocksmithLocalProperties localSettings = new FileLocksmithLocalProperties();
Settings = new FileLocksmithSettings(localSettings);
_settingsUtils.SaveSettings(localSettings.ToJsonString(), GetSettingsSubPath(), "file-locksmith-settings.json");
}
InitializeEnabledValue();
// set the callback functions value to hangle outgoing IPC message.
SendConfigMSG = ipcMSGCallBackFunc;
_fileLocksmithEnabledOnContextExtendedMenu = Settings.Properties.ExtendedContextMenuOnly.Value;
}
public string GetSettingsSubPath()
{
return _settingsConfigFileFolder + "\\" + ModuleName;
}
private void InitializeEnabledValue()
@@ -67,7 +98,27 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
SendConfigMSG(outgoing.ToString());
// TODO: Implement when this module has properties.
// NotifyPropertyChanged();
NotifySettingsChanged();
}
}
}
public bool EnabledOnContextExtendedMenu
{
get
{
return _fileLocksmithEnabledOnContextExtendedMenu;
}
set
{
if (value != _fileLocksmithEnabledOnContextExtendedMenu)
{
_fileLocksmithEnabledOnContextExtendedMenu = value;
Settings.Properties.ExtendedContextMenuOnly.Value = value;
OnPropertyChanged(nameof(EnabledOnContextExtendedMenu));
NotifySettingsChanged();
}
}
}
@@ -77,11 +128,23 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
get => _enabledStateIsGPOConfigured;
}
private void NotifySettingsChanged()
{
// Using InvariantCulture as this is an IPC message
SendConfigMSG(
string.Format(
CultureInfo.InvariantCulture,
"{{ \"powertoys\": {{ \"{0}\": {1} }} }}",
FileLocksmithSettings.ModuleName,
JsonSerializer.Serialize(Settings)));
}
private Func<string, int> SendConfigMSG { get; }
private GpoRuleConfigured _enabledGpoRuleConfiguration;
private bool _enabledStateIsGPOConfigured;
private bool _isFileLocksmithEnabled;
private bool _fileLocksmithEnabledOnContextExtendedMenu;
public void RefreshEnabledState()
{