[Registry Preview] Adds application to Open with list for REG files (#26033)

* 25834

* Asociate Registry Preview with .reg files

* Add setting for making RP default app for .reg files

* Run spellcheck

* Run spellcheck again

* Fix build

---------

Co-authored-by: Stefan Markovic <stefan@janeasystems.com>
This commit is contained in:
Randy
2023-06-10 15:02:53 -07:00
committed by GitHub
parent b6ff97f795
commit eddb617484
13 changed files with 246 additions and 93 deletions

View File

@@ -3502,6 +3502,13 @@ Activate by holding the key for the character you want to add an accent to, then
<data name="RegistryPreview_LaunchButtonControl.Header" xml:space="preserve">
<value>Launch Registry Preview</value>
</data>
<data name="RegistryPreview_DefaultRegApp.Header" xml:space="preserve">
<value>Default app</value>
</data>
<data name="RegistryPreview_DefaultRegApp.Description" xml:space="preserve">
<value>Make Registry Preview default app for opening .reg files</value>
<comment>Registry Preview is app name. Do not localize.</comment>
</data>
<data name="PastePlain_ShortcutWarning.Title" xml:space="preserve">
<value>Using this shortcut may prevent non-text paste actions (e.g. images, files) or built-in paste plain text actions in other applications from functioning.</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;
@@ -17,7 +19,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
public ButtonClickCommand LaunchEventHandler => new ButtonClickCommand(Launch);
public RegistryPreviewViewModel(ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc)
public RegistryPreviewViewModel(ISettingsRepository<GeneralSettings> settingsRepository, ISettingsRepository<RegistryPreviewSettings> registryPreviewSettingsRepository, Func<string, int> ipcMSGCallBackFunc)
{
// To obtain the general settings configurations of PowerToys Settings.
if (settingsRepository == null)
@@ -27,6 +29,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
GeneralSettingsConfig = settingsRepository.SettingsConfig;
_settings = registryPreviewSettingsRepository.SettingsConfig;
InitializeEnabledValue();
// set the callback functions value to hangle outgoing IPC message.
@@ -71,6 +75,21 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
public bool IsRegistryPreviewDefaultRegApp
{
get => _settings.Properties.DefaultRegApp;
set
{
if (_settings.Properties.DefaultRegApp != value)
{
_settings.Properties.DefaultRegApp = value;
OnPropertyChanged(nameof(IsRegistryPreviewDefaultRegApp));
NotifySettingsChanged();
}
}
}
public bool IsEnabledGpoConfigured
{
get => _enabledStateIsGPOConfigured;
@@ -88,11 +107,23 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
private GpoRuleConfigured _enabledGpoRuleConfiguration;
private bool _enabledStateIsGPOConfigured;
private bool _isRegistryPreviewEnabled;
private RegistryPreviewSettings _settings;
public void RefreshEnabledState()
{
InitializeEnabledValue();
OnPropertyChanged(nameof(IsRegistryPreviewEnabled));
}
private void NotifySettingsChanged()
{
// Using InvariantCulture as this is an IPC message
SendConfigMSG(
string.Format(
CultureInfo.InvariantCulture,
"{{ \"powertoys\": {{ \"{0}\": {1} }} }}",
RegistryPreviewSettings.ModuleName,
JsonSerializer.Serialize(_settings)));
}
}
}

View File

@@ -11,11 +11,9 @@
AutomationProperties.LandmarkType="Main"
mc:Ignorable="d">
<controls:SettingsPageControl
x:Uid="RegistryPreview"
ModuleImageSource="ms-appx:///Assets/Modules/RegistryPreview.png">
<controls:SettingsPageControl x:Uid="RegistryPreview" ModuleImageSource="ms-appx:///Assets/Modules/RegistryPreview.png">
<controls:SettingsPageControl.ModuleContent>
<StackPanel Orientation="Vertical" ChildrenTransitions="{StaticResource SettingsCardsAnimations}">
<StackPanel ChildrenTransitions="{StaticResource SettingsCardsAnimations}" Orientation="Vertical">
<labs:SettingsCard
x:Uid="RegistryPreview_Enable_RegistryPreview"
HeaderIcon="{ui:BitmapIcon Source=/Assets/FluentIcons/FluentIconsRegistryPreview.png}"
@@ -40,15 +38,17 @@
HeaderIcon="{ui:FontIcon FontFamily={StaticResource SymbolThemeFontFamily},
Glyph=&#xEA37;}"
IsClickEnabled="True" />
<labs:SettingsCard x:Uid="RegistryPreview_DefaultRegApp" HeaderIcon="{ui:FontIcon FontFamily={StaticResource SymbolThemeFontFamily}, Glyph=&#xE7AC;}">
<ToggleSwitch x:Uid="RegistryPreview_DefaultRegApp_ToggleSwitch" IsOn="{x:Bind Mode=TwoWay, Path=ViewModel.IsRegistryPreviewDefaultRegApp}" />
</labs:SettingsCard>
</controls:SettingsGroup>
</StackPanel>
</controls:SettingsPageControl.ModuleContent>
<controls:SettingsPageControl.PrimaryLinks>
<controls:PageLink
x:Uid="LearnMore_RegistryPreview"
Link="https://aka.ms/PowerToysOverview_RegistryPreview" />
<controls:PageLink x:Uid="LearnMore_RegistryPreview" Link="https://aka.ms/PowerToysOverview_RegistryPreview" />
</controls:SettingsPageControl.PrimaryLinks>
</controls:SettingsPageControl>
</Page>

View File

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