mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
[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:
@@ -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>
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user