From 89b44f5126a5f7cba5bac75326b8bb0fa67cbfff Mon Sep 17 00:00:00 2001 From: Lavius Motileng <58791731+laviusmotileng-ms@users.noreply.github.com> Date: Thu, 2 Apr 2020 06:08:56 -0700 Subject: [PATCH] User/lamotile/add powerrename settings (#1813) * added powerrename settings * removed pop-up message * removed unused files * revrted changes to old settings * updated solution file * added ToJsonString() method * added JSON property for the powertoy name --- PowerToys.sln | 11 ++ .../BasePTModuleSettings.cs | 18 +++ .../GeneralSettings.cs | 4 +- .../IPowerToySettings.cs | 13 ++ .../PowerPreviewSettings.cs | 54 ++++---- .../PowerRenameSettings.cs | 67 ++++++++++ .../Property.cs | 27 ++++ .../SettingsUtils.cs | 6 +- .../SndModuleSettings.cs | 18 +-- .../Views/GeneralPage.xaml.cs | 26 ++-- .../Views/PowerPreviewPage.xaml.cs | 15 ++- .../Views/PowerRenamePage.xaml | 51 +++---- .../Views/PowerRenamePage.xaml.cs | 124 +++++++++++++++++- src/core/Test/Program.cs | 21 --- src/core/Test/Test.csproj | 12 -- src/modules/powerrename/dll/dllmain.cpp | 4 +- 16 files changed, 346 insertions(+), 125 deletions(-) create mode 100644 src/core/Microsoft.PowerToys.Settings.UI.Lib/BasePTModuleSettings.cs create mode 100644 src/core/Microsoft.PowerToys.Settings.UI.Lib/IPowerToySettings.cs create mode 100644 src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerRenameSettings.cs create mode 100644 src/core/Microsoft.PowerToys.Settings.UI.Lib/Property.cs delete mode 100644 src/core/Test/Program.cs delete mode 100644 src/core/Test/Test.csproj diff --git a/PowerToys.sln b/PowerToys.sln index 77c12b0a80..3eb736187b 100644 --- a/PowerToys.sln +++ b/PowerToys.sln @@ -194,6 +194,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.PowerToys.Settings.UI.Lib", "src\core\Microsoft.PowerToys.Settings.UI.Lib\Microsoft.PowerToys.Settings.UI.Lib.csproj", "{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test", "src\core\Test\Test.csproj", "{C266BF3A-B9B8-4047-8ADD-E22A6AE1DFFC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM = Debug|ARM @@ -650,6 +652,14 @@ Global {B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|Any CPU.Build.0 = Release|Any CPU {B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x64.ActiveCfg = Release|Any CPU {B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x64.Build.0 = Release|Any CPU + {C266BF3A-B9B8-4047-8ADD-E22A6AE1DFFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C266BF3A-B9B8-4047-8ADD-E22A6AE1DFFC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C266BF3A-B9B8-4047-8ADD-E22A6AE1DFFC}.Debug|x64.ActiveCfg = Debug|Any CPU + {C266BF3A-B9B8-4047-8ADD-E22A6AE1DFFC}.Debug|x64.Build.0 = Debug|Any CPU + {C266BF3A-B9B8-4047-8ADD-E22A6AE1DFFC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C266BF3A-B9B8-4047-8ADD-E22A6AE1DFFC}.Release|Any CPU.Build.0 = Release|Any CPU + {C266BF3A-B9B8-4047-8ADD-E22A6AE1DFFC}.Release|x64.ActiveCfg = Release|Any CPU + {C266BF3A-B9B8-4047-8ADD-E22A6AE1DFFC}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -699,6 +709,7 @@ Global {4EB9C181-96E2-4587-AB98-2DB84C1A2310} = {C3081D9A-1586-441A-B5F4-ED815B3719C1} {C073B057-B157-40F0-8678-1DCD119D841C} = {C3081D9A-1586-441A-B5F4-ED815B3719C1} {B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A} = {C3081D9A-1586-441A-B5F4-ED815B3719C1} + {C266BF3A-B9B8-4047-8ADD-E22A6AE1DFFC} = {C3081D9A-1586-441A-B5F4-ED815B3719C1} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0} diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/BasePTModuleSettings.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/BasePTModuleSettings.cs new file mode 100644 index 0000000000..8f30f29c98 --- /dev/null +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/BasePTModuleSettings.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.Json; + +namespace Microsoft.PowerToys.Settings.UI.Lib +{ + public abstract class BasePTModuleSettings + { + public string name { get; set; } + public string version { get; set; } + + public virtual string ToJsonString() + { + return JsonSerializer.Serialize(this); + } + } +} diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/GeneralSettings.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/GeneralSettings.cs index f66079f577..3c59afc9dd 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/GeneralSettings.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/GeneralSettings.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; using System.Text.Json; using System.Text.Json.Serialization; -namespace Microsoft.PowerToys.Settings.UI.ViewModels +namespace Microsoft.PowerToys.Settings.UI.Lib { public class GeneralSettings { @@ -30,7 +30,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels this.powertoys_version = "v0.15.3"; } - public override string ToString() + public string ToJsonString() { return JsonSerializer.Serialize(this); } diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/IPowerToySettings.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/IPowerToySettings.cs new file mode 100644 index 0000000000..450a186e0a --- /dev/null +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/IPowerToySettings.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Microsoft.PowerToys.Settings.UI.Lib +{ + public interface IPowerToySettings + { + string name { get; set; } + string version { get; set; } + string ToJsonString(); + } +} diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerPreviewSettings.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerPreviewSettings.cs index 3552260b22..62ee6298cb 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerPreviewSettings.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerPreviewSettings.cs @@ -2,70 +2,62 @@ using System.Collections.Generic; using System.Text; using System.Text.Json; +using System.Text.Json.Serialization; namespace Microsoft.PowerToys.Settings.UI.Lib { - /// - /// This class models the settings for the PowerPreview class. - /// Eaxmple JSON: - /// { - /// "name": "File Explorer Preview", - /// "properties": { - /// "IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL": { "value": true }, - /// "PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID": { "value": true } - /// }, - /// "version": "1.0" - /// } - - /// - public class PowerPreviewSettings + public class PowerPreviewSettings : BasePTModuleSettings { - public string name { get; set; } - public Properties properties { get; set; } - public string version { get; set; } + public PowerPreviewProperties properties { get; set; } public PowerPreviewSettings() { - this.properties = new Properties(); + this.properties = new PowerPreviewProperties(); this.version = "1"; this.name = "_unset_"; } public PowerPreviewSettings(string ptName) { - this.properties = new Properties(); + this.properties = new PowerPreviewProperties(); this.version = "1"; this.name = ptName; } - public override string ToString() + public override string ToJsonString() { - return "{\"" + this.name + "\":" + JsonSerializer.Serialize(this) + "}"; + return JsonSerializer.Serialize(this); } } - public class Property + public class PowerPreviewProperties { - public bool value { get; set; } - + public BoolProperty IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL { get; set; } + public BoolProperty PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID { get; set; } + + public PowerPreviewProperties() + { + this.IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL = new BoolProperty(); + this.PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID = new BoolProperty(); + } + public override string ToString() { return JsonSerializer.Serialize(this); } } - public class Properties + public class SndPowerPreviewSettings { - public Property IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL { get; set; } - public Property PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID { get; set; } + [JsonPropertyName("File Explorer Preview")] + public PowerPreviewSettings File_Explorer_Preview { get; set; } - public Properties() + public SndPowerPreviewSettings(PowerPreviewSettings settings) { - this.IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL = new Property(); - this.PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID = new Property(); + this.File_Explorer_Preview = settings; } - public override string ToString() + public string ToJsonString() { return JsonSerializer.Serialize(this); } diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerRenameSettings.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerRenameSettings.cs new file mode 100644 index 0000000000..575a11f8bb --- /dev/null +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerRenameSettings.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Microsoft.PowerToys.Settings.UI.Lib +{ + public class PowerRenameSettings : BasePTModuleSettings + { + public PowerRenameProperties properties { get; set; } + + public PowerRenameSettings() + { + this.properties = new PowerRenameProperties(); + this.version = "1"; + this.name = "_unset_"; + } + + public PowerRenameSettings(string ptName) + { + this.properties = new PowerRenameProperties(); + this.version = "1"; + this.name = ptName; + } + + public override string ToJsonString() + { + return JsonSerializer.Serialize(this); + } + } + + public class PowerRenameProperties + { + public PowerRenameProperties() + { + this.bool_persist_input = new BoolProperty(); + this.bool_mru_enabled = new BoolProperty(); + this.int_max_mru_size = new IntProperty(); + this.bool_show_icon_on_menu = new BoolProperty(); + this.bool_show_extended_menu = new BoolProperty(); + } + + public BoolProperty bool_persist_input { get; set; } + public BoolProperty bool_mru_enabled { get; set; } + public IntProperty int_max_mru_size { get; set; } + public BoolProperty bool_show_icon_on_menu { get; set; } + public BoolProperty bool_show_extended_menu { get; set; } + } + + public class SndPowerRenameSettings + { + [JsonPropertyName("PowerRename")] + public PowerRenameSettings PowerRename { get; set; } + + public SndPowerRenameSettings(PowerRenameSettings settings) + { + this.PowerRename = settings; + } + + public string ToJsonString() + { + return JsonSerializer.Serialize(this); + } + } +} + diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/Property.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/Property.cs new file mode 100644 index 0000000000..5423a59d0f --- /dev/null +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/Property.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.Json; + +namespace Microsoft.PowerToys.Settings.UI.Lib +{ + public class BoolProperty + { + public bool value { get; set; } + + public override string ToString() + { + return JsonSerializer.Serialize(this); + } + } + + public class IntProperty + { + public int value { get; set; } + + public override string ToString() + { + return JsonSerializer.Serialize(this); + } + } +} diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/SettingsUtils.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/SettingsUtils.cs index 5cdf1aa1f4..db8c406033 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/SettingsUtils.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/SettingsUtils.cs @@ -39,13 +39,13 @@ namespace Microsoft.PowerToys.Settings.UI.Lib /// Save settings to a json file. /// /// dynamic json settings object. - public static void SaveSettings(T settings, string powertoy) + public static void SaveSettings(string jsonSettings, string powertoy) { - if(settings != null) + if(jsonSettings != null) { System.IO.File.WriteAllText( SettingsUtils.GetSettingsPath(powertoy), - settings.ToString()); + jsonSettings.ToString()); } } } diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndModuleSettings.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndModuleSettings.cs index a2e2c21037..a864f2fd15 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndModuleSettings.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndModuleSettings.cs @@ -5,24 +5,18 @@ using System.Text.Json; namespace Microsoft.PowerToys.Settings.UI.Lib { - /// - /// PowerToys runner expects a json text that contains one of the following attributes: refresh, general and powertoys. - /// The one for general settings is placed in the General settings model. This class represents the json text that starts with the "powertoys" attribute. - /// this will tell the runner that we are sending settings for a powertoy module and not for general settings. - /// - /// M stands for the Model of PT Module Settings to be sent. - public class SndModuleSettings + public class SndModuleSettings { - public M powertoys { get; set; } + public S powertoys { get; set; } - public SndModuleSettings(M ptModuleSettings) + public SndModuleSettings(S settings) { - this.powertoys = ptModuleSettings; + this.powertoys = settings; } - public override string ToString() + public string ToJsonString() { - return "{\"powertoys\":" + this.powertoys.ToString() + "}"; + return JsonSerializer.Serialize(this); } } } diff --git a/src/core/Microsoft.PowerToys.Settings.UI/Views/GeneralPage.xaml.cs b/src/core/Microsoft.PowerToys.Settings.UI/Views/GeneralPage.xaml.cs index 80d3c3c70c..1ed647922a 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/Views/GeneralPage.xaml.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI/Views/GeneralPage.xaml.cs @@ -32,7 +32,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views { this.InitializeComponent(); } - + /// protected override void OnNavigatedTo(NavigationEventArgs e) { @@ -52,7 +52,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views { // create settings file if one is not found. settings = new GeneralSettings(); - SettingsUtils.SaveSettings(settings, string.Empty); + SettingsUtils.SaveSettings(settings.ToJsonString(), string.Empty); // load and apply theme settings this.ReLoadTheme(settings.theme); @@ -103,7 +103,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views break; } - SettingsUtils.SaveSettings(settings, string.Empty); + SettingsUtils.SaveSettings(settings.ToJsonString(), string.Empty); OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(settings); if (ShellPage.Default_SndMSG_Callback != null) @@ -129,16 +129,16 @@ namespace Microsoft.PowerToys.Settings.UI.Views { RadioButton rb = sender as RadioButton; - //if (rb != null) - //{ - // string themeName = rb.Tag.ToString(); - // this.ReLoadTheme(themeName); + if (rb != null) + { + string themeName = rb.Tag.ToString(); + this.ReLoadTheme(themeName); - // // update and save settings to file. - // GeneralSettings settings = SettingsUtils.GetSettings(string.Empty); - // settings.theme = themeName; - // SettingsUtils.SaveSettings(settings, string.Empty); - //} + // update and save settings to file. + GeneralSettings settings = SettingsUtils.GetSettings(string.Empty); + settings.theme = themeName; + SettingsUtils.SaveSettings(settings.ToJsonString(), string.Empty); + } } private async void CheckForUpdates_Click(object sender, RoutedEventArgs e) @@ -146,4 +146,4 @@ namespace Microsoft.PowerToys.Settings.UI.Views await Launcher.LaunchUriAsync(new Uri("https://github.com/microsoft/PowerToys/releases")); } } -} \ No newline at end of file +} diff --git a/src/core/Microsoft.PowerToys.Settings.UI/Views/PowerPreviewPage.xaml.cs b/src/core/Microsoft.PowerToys.Settings.UI/Views/PowerPreviewPage.xaml.cs index a318762fb1..78fedba12a 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/Views/PowerPreviewPage.xaml.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI/Views/PowerPreviewPage.xaml.cs @@ -46,7 +46,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views catch(Exception exp) { settings = new PowerPreviewSettings(POWERTOY_NAME); - SettingsUtils.SaveSettings(settings, POWERTOY_NAME); + SettingsUtils.SaveSettings(settings.ToJsonString(), POWERTOY_NAME); ToggleSwitch_Preview_SVG.IsOn = settings.properties.IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL.value; ToggleSwitch_Preview_MD.IsOn = settings.properties.PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID.value; } @@ -61,11 +61,11 @@ namespace Microsoft.PowerToys.Settings.UI.Views PowerPreviewSettings settings = SettingsUtils.GetSettings(POWERTOY_NAME); settings.properties.IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL.value = swt.IsOn; - SndModuleSettings moduleSettings = new SndModuleSettings(settings); - if (ShellPage.Default_SndMSG_Callback != null) { - ShellPage.Default_SndMSG_Callback(moduleSettings.ToString()); + SndPowerPreviewSettings snd = new SndPowerPreviewSettings(settings); + SndModuleSettings ipcMessage = new SndModuleSettings(snd); + ShellPage.Default_SndMSG_Callback(ipcMessage.ToJsonString()); } } } @@ -79,13 +79,14 @@ namespace Microsoft.PowerToys.Settings.UI.Views PowerPreviewSettings settings = SettingsUtils.GetSettings(POWERTOY_NAME); settings.properties.PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID.value = swt.IsOn; - SndModuleSettings moduleSettings = new SndModuleSettings(settings); - if (ShellPage.Default_SndMSG_Callback != null) { - ShellPage.Default_SndMSG_Callback(moduleSettings.ToString()); + SndPowerPreviewSettings snd = new SndPowerPreviewSettings(settings); + SndModuleSettings ipcMessage = new SndModuleSettings(snd); + ShellPage.Default_SndMSG_Callback(ipcMessage.ToJsonString()); } } } + } } diff --git a/src/core/Microsoft.PowerToys.Settings.UI/Views/PowerRenamePage.xaml b/src/core/Microsoft.PowerToys.Settings.UI/Views/PowerRenamePage.xaml index e69d233a84..3d63560595 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/Views/PowerRenamePage.xaml +++ b/src/core/Microsoft.PowerToys.Settings.UI/Views/PowerRenamePage.xaml @@ -2,7 +2,6 @@ x:Class="Microsoft.PowerToys.Settings.UI.Views.PowerRenamePage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:local="using:Microsoft.PowerToys.Settings.UI.Views" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:muxc="using:Microsoft.UI.Xaml.Controls" @@ -44,37 +43,43 @@ - + - + - + - + - + - - - + Margin="{StaticResource SmallTopMargin}" + ValueChanged="Toggle_PowerRename_MaxDispListNum_ValueChanged" + /> @@ -91,12 +96,14 @@ + \ No newline at end of file diff --git a/src/core/Microsoft.PowerToys.Settings.UI/Views/PowerRenamePage.xaml.cs b/src/core/Microsoft.PowerToys.Settings.UI/Views/PowerRenamePage.xaml.cs index 50ae295eb1..56a3041d98 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/Views/PowerRenamePage.xaml.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI/Views/PowerRenamePage.xaml.cs @@ -1,11 +1,15 @@ -using Microsoft.PowerToys.Settings.UI.ViewModels; +using Microsoft.PowerToys.Settings.UI.Lib; +using Microsoft.PowerToys.Settings.UI.ViewModels; +using Microsoft.UI.Xaml.Controls; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; +using System.ServiceModel.Channels; using Windows.Foundation; using Windows.Foundation.Collections; +using Windows.UI.Popups; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; @@ -19,10 +23,128 @@ namespace Microsoft.PowerToys.Settings.UI.Views public sealed partial class PowerRenamePage : Page { public PowerRenameViewModel ViewModel { get; } = new PowerRenameViewModel(); + private const string POWERTOY_NAME = "PowerRename"; public PowerRenamePage() { this.InitializeComponent(); } + + /// + protected override void OnNavigatedTo(NavigationEventArgs e) + { + base.OnNavigatedTo(e); + PowerRenameSettings settings; + try + { + settings = SettingsUtils.GetSettings(POWERTOY_NAME); + UpdateView(settings); + } + catch (Exception exp) + { + settings = new PowerRenameSettings(POWERTOY_NAME); + SettingsUtils.SaveSettings(settings.ToJsonString(), POWERTOY_NAME); + UpdateView(settings); + } + } + + + private void UpdateView(PowerRenameSettings settings) + { + this.Toggle_PowerRename_Enable.IsOn = settings.properties.bool_mru_enabled.value; + this.Toggle_PowerRename_EnableOnExtendedContextMenu.IsOn = settings.properties.bool_show_extended_menu.value; + this.Toggle_PowerRename_MaxDispListNum.Value = settings.properties.int_max_mru_size.value; + this.Toggle_PowerRename_EnableOnContextMenu.IsOn = settings.properties.bool_show_icon_on_menu.value; + this.Toggle_PowerRename_RestoreFlagsOnLaunch.IsOn = settings.properties.bool_persist_input.value; + } + + private void Toggle_PowerRename_Enable_Toggled(object sender, RoutedEventArgs e) + { + ToggleSwitch swt = sender as ToggleSwitch; + + if (swt != null) + { + PowerRenameSettings settings = SettingsUtils.GetSettings(POWERTOY_NAME); + settings.properties.bool_mru_enabled.value = swt.IsOn; + + if (ShellPage.Default_SndMSG_Callback != null) + { + SndPowerRenameSettings snd = new SndPowerRenameSettings(settings); + SndModuleSettings ipcMessage = new SndModuleSettings(snd); + ShellPage.Default_SndMSG_Callback(ipcMessage.ToJsonString()); + } + } + } + + private void Toggle_PowerRename_EnableOnContextMenu_Toggled(object sender, RoutedEventArgs e) + { + ToggleSwitch swt = sender as ToggleSwitch; + + if (swt != null) + { + PowerRenameSettings settings = SettingsUtils.GetSettings(POWERTOY_NAME); + settings.properties.bool_show_icon_on_menu.value = swt.IsOn; + + if (ShellPage.Default_SndMSG_Callback != null) + { + SndPowerRenameSettings snd = new SndPowerRenameSettings(settings); + SndModuleSettings ipcMessage = new SndModuleSettings(snd); + ShellPage.Default_SndMSG_Callback(ipcMessage.ToJsonString()); + } + } + } + + private void Toggle_PowerRename_EnableOnExtendedContextMenu_Toggled(object sender, RoutedEventArgs e) + { + ToggleSwitch swt = sender as ToggleSwitch; + + if (swt != null) + { + PowerRenameSettings settings = SettingsUtils.GetSettings(POWERTOY_NAME); + settings.properties.bool_show_extended_menu.value = swt.IsOn; + + if (ShellPage.Default_SndMSG_Callback != null) + { + SndPowerRenameSettings snd = new SndPowerRenameSettings(settings); + SndModuleSettings ipcMessage = new SndModuleSettings(snd); + ShellPage.Default_SndMSG_Callback(ipcMessage.ToJsonString()); + } + } + } + + private void Toggle_PowerRename_RestoreFlagsOnLaunch_Toggled(object sender, RoutedEventArgs e) + { + ToggleSwitch swt = sender as ToggleSwitch; + + if (swt != null) + { + PowerRenameSettings settings = SettingsUtils.GetSettings(POWERTOY_NAME); + settings.properties.bool_persist_input.value = swt.IsOn; + + if (ShellPage.Default_SndMSG_Callback != null) + { + SndPowerRenameSettings snd = new SndPowerRenameSettings(settings); + SndModuleSettings ipcMessage = new SndModuleSettings(snd); + ShellPage.Default_SndMSG_Callback(ipcMessage.ToJsonString()); + } + } + } + + private void Toggle_PowerRename_MaxDispListNum_ValueChanged(NumberBox sender, NumberBoxValueChangedEventArgs args) + { + if (sender != null) + { + PowerRenameSettings settings = SettingsUtils.GetSettings(POWERTOY_NAME); + settings.properties.int_max_mru_size.value = Convert.ToInt32(sender.Value); + + if (ShellPage.Default_SndMSG_Callback != null) + { + SndPowerRenameSettings snd = new SndPowerRenameSettings(settings); + SndModuleSettings ipcMessage = new SndModuleSettings(snd); + ShellPage.Default_SndMSG_Callback(ipcMessage.ToJsonString()); + } + } + } } } + diff --git a/src/core/Test/Program.cs b/src/core/Test/Program.cs deleted file mode 100644 index 6b6e9fb5aa..0000000000 --- a/src/core/Test/Program.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Microsoft.PowerToys.Settings.UI.Lib; -using Microsoft.PowerToys.Settings.UI.ViewModels; -using System; -using System.IO; -using System.Text.Json; - -namespace Test -{ - class Program - { - static void Main(string[] args) - { - PowerPreviewSettings pvst = new PowerPreviewSettings(); - pvst.name = "File Explorer"; - - SndModuleSettings snd = new SndModuleSettings(pvst); - - Console.WriteLine(snd.ToString()); - } - } -} diff --git a/src/core/Test/Test.csproj b/src/core/Test/Test.csproj deleted file mode 100644 index 13924ab281..0000000000 --- a/src/core/Test/Test.csproj +++ /dev/null @@ -1,12 +0,0 @@ - - - - Exe - netcoreapp3.1 - - - - - - - diff --git a/src/modules/powerrename/dll/dllmain.cpp b/src/modules/powerrename/dll/dllmain.cpp index 8ab55ce2fa..e6d5ee748d 100644 --- a/src/modules/powerrename/dll/dllmain.cpp +++ b/src/modules/powerrename/dll/dllmain.cpp @@ -250,7 +250,9 @@ public: CSettings::SetMaxMRUSize(values.get_int_value(L"int_max_mru_size").value()); CSettings::SetShowIconOnMenu(values.get_bool_value(L"bool_show_icon_on_menu").value()); CSettings::SetExtendedContextMenuOnly(values.get_bool_value(L"bool_show_extended_menu").value()); - + + values.save_to_settings_file(); + Trace::SettingsChanged(); } catch (std::exception)