[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

@@ -0,0 +1,37 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class FileLocksmithLocalProperties : ISettingsConfig
{
public FileLocksmithLocalProperties()
{
ExtendedContextMenuOnly = false;
}
public bool ExtendedContextMenuOnly { get; set; }
public string ToJsonString()
{
return JsonSerializer.Serialize(this);
}
// This function is required to implement the ISettingsConfig interface and obtain the settings configurations.
public string GetModuleName()
{
string moduleName = FileLocksmithSettings.ModuleName;
return moduleName;
}
// This can be utilized in the future if the settings.json file is to be modified/deleted.
public bool UpgradeSettingsConfiguration()
{
return false;
}
}
}

View File

@@ -0,0 +1,22 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class FileLocksmithProperties
{
public FileLocksmithProperties()
{
ExtendedContextMenuOnly = new BoolProperty(false);
}
[JsonPropertyName("bool_show_extended_menu")]
public BoolProperty ExtendedContextMenuOnly { get; set; }
public override string ToString() => JsonSerializer.Serialize(this);
}
}

View File

@@ -0,0 +1,49 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class FileLocksmithSettings : BasePTModuleSettings, ISettingsConfig
{
public const string ModuleName = "File Locksmith";
public const string ModuleVersion = "1";
[JsonPropertyName("properties")]
public FileLocksmithProperties Properties { get; set; }
public FileLocksmithSettings()
{
Name = ModuleName;
Version = ModuleVersion;
Properties = new FileLocksmithProperties();
}
public FileLocksmithSettings(FileLocksmithLocalProperties localProperties)
{
if (localProperties == null)
{
throw new ArgumentNullException(nameof(localProperties));
}
Properties = new FileLocksmithProperties();
Properties.ExtendedContextMenuOnly.Value = localProperties.ExtendedContextMenuOnly;
Version = "1";
Name = ModuleName;
}
public string GetModuleName()
{
return Name;
}
public bool UpgradeSettingsConfiguration()
{
return false;
}
}
}

View File

@@ -3309,6 +3309,19 @@ Activate by holding the key for the character you want to add an accent to, then
<value>Enable File Locksmith</value>
<comment>File Locksmith is the name of the utility</comment>
</data>
<data name="FileLocksmith_Toggle_StandardContextMenu.Content" xml:space="preserve">
<value>Default and extended context menu</value>
</data>
<data name="FileLocksmith_Toggle_ExtendedContextMenu.Content" xml:space="preserve">
<value>Extended context menu only</value>
</data>
<data name="FileLocksmith_Toggle_ContextMenu.Header" xml:space="preserve">
<value>Show File Locksmith in</value>
</data>
<data name="FileLocksmith_ShellIntegration.Header" xml:space="preserve">
<value>Shell integration</value>
<comment>This refers to directly integrating in with Windows</comment>
</data>
<data name="GPO_IsSettingForced.Title" xml:space="preserve">
<value>The system administrator is forcing this setting.</value>
</data>

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()
{

View File

@@ -30,6 +30,20 @@
IsTabStop="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabledGpoConfigured}"
Severity="Informational" />
<controls:SettingsGroup
x:Uid="FileLocksmith_ShellIntegration"
IsEnabled="{x:Bind Mode=OneWay, Path=ViewModel.IsFileLocksmithEnabled}">
<labs:SettingsExpander
x:Uid="FileLocksmith_Toggle_ContextMenu"
IsExpanded="True">
<ComboBox
MinWidth="{StaticResource SettingActionControlMinWidth}"
SelectedIndex="{x:Bind Mode=TwoWay, Path=ViewModel.EnabledOnContextExtendedMenu, Converter={StaticResource BoolToComboBoxIndexConverter}}">
<ComboBoxItem x:Uid="FileLocksmith_Toggle_StandardContextMenu" />
<ComboBoxItem x:Uid="FileLocksmith_Toggle_ExtendedContextMenu" />
</ComboBox>
</labs:SettingsExpander>
</controls:SettingsGroup>
</StackPanel>
</controls:SettingsPageControl.ModuleContent>
<controls:SettingsPageControl.PrimaryLinks>

View File

@@ -16,7 +16,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
public FileLocksmithPage()
{
var settingsUtils = new SettingsUtils();
ViewModel = new FileLocksmithViewModel(SettingsRepository<GeneralSettings>.GetInstance(settingsUtils), ShellPage.SendDefaultIPCMessage);
ViewModel = new FileLocksmithViewModel(settingsUtils, SettingsRepository<GeneralSettings>.GetInstance(settingsUtils), ShellPage.SendDefaultIPCMessage);
DataContext = ViewModel;
InitializeComponent();
}