// 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 Microsoft.PowerToys.Settings.UI.Lib; using Microsoft.PowerToys.Settings.UI.ViewModels; using Microsoft.UI.Xaml.Controls; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Navigation; namespace Microsoft.PowerToys.Settings.UI.Views { public sealed partial class PowerRenamePage : Page { public PowerRenameViewModel ViewModel { get; } = new PowerRenameViewModel(); private const string POWERTOYNAME = "PowerRename"; public PowerRenamePage() { InitializeComponent(); } /// protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); PowerRenameSettings settings; try { settings = SettingsUtils.GetSettings(POWERTOYNAME); UpdateView(settings); } catch { settings = new PowerRenameSettings(POWERTOYNAME); SettingsUtils.SaveSettings(settings.ToJsonString(), POWERTOYNAME); UpdateView(settings); } } private void UpdateView(PowerRenameSettings settings) { Toggle_PowerRename_Enable.IsOn = settings.properties.MruEnabled.Value; Toggle_PowerRename_EnableOnExtendedContextMenu.IsOn = settings.properties.ShowExtendedMenu.Value; Toggle_PowerRename_MaxDispListNum.Value = settings.properties.MaxMruSize.Value; Toggle_PowerRename_EnableOnContextMenu.IsOn = settings.properties.ShowIconInMenu.Value; Toggle_PowerRename_RestoreFlagsOnLaunch.IsOn = settings.properties.PersistInput.Value; } private void Toggle_PowerRename_Enable_Toggled(object sender, RoutedEventArgs e) { ToggleSwitch swt = sender as ToggleSwitch; if (swt != null) { PowerRenameSettings settings = SettingsUtils.GetSettings(POWERTOYNAME); settings.properties.MruEnabled.Value = swt.IsOn; if (ShellPage.DefaultSndMSGCallback != null) { SndPowerRenameSettings snd = new SndPowerRenameSettings(settings); SndModuleSettings ipcMessage = new SndModuleSettings(snd); ShellPage.DefaultSndMSGCallback(ipcMessage.ToJsonString()); } } } private void Toggle_PowerRename_EnableOnContextMenu_Toggled(object sender, RoutedEventArgs e) { ToggleSwitch swt = sender as ToggleSwitch; if (swt != null) { PowerRenameSettings settings = SettingsUtils.GetSettings(POWERTOYNAME); settings.properties.ShowIconInMenu.Value = swt.IsOn; if (ShellPage.DefaultSndMSGCallback != null) { SndPowerRenameSettings snd = new SndPowerRenameSettings(settings); SndModuleSettings ipcMessage = new SndModuleSettings(snd); ShellPage.DefaultSndMSGCallback(ipcMessage.ToJsonString()); } } } private void Toggle_PowerRename_EnableOnExtendedContextMenu_Toggled(object sender, RoutedEventArgs e) { ToggleSwitch swt = sender as ToggleSwitch; if (swt != null) { PowerRenameSettings settings = SettingsUtils.GetSettings(POWERTOYNAME); settings.properties.ShowExtendedMenu.Value = swt.IsOn; if (ShellPage.DefaultSndMSGCallback != null) { SndPowerRenameSettings snd = new SndPowerRenameSettings(settings); SndModuleSettings ipcMessage = new SndModuleSettings(snd); ShellPage.DefaultSndMSGCallback(ipcMessage.ToJsonString()); } } } private void Toggle_PowerRename_RestoreFlagsOnLaunch_Toggled(object sender, RoutedEventArgs e) { ToggleSwitch swt = sender as ToggleSwitch; if (swt != null) { PowerRenameSettings settings = SettingsUtils.GetSettings(POWERTOYNAME); settings.properties.PersistInput.Value = swt.IsOn; if (ShellPage.DefaultSndMSGCallback != null) { SndPowerRenameSettings snd = new SndPowerRenameSettings(settings); SndModuleSettings ipcMessage = new SndModuleSettings(snd); ShellPage.DefaultSndMSGCallback(ipcMessage.ToJsonString()); } } } private void Toggle_PowerRename_MaxDispListNum_ValueChanged(NumberBox sender, NumberBoxValueChangedEventArgs args) { if (sender != null) { PowerRenameSettings settings = SettingsUtils.GetSettings(POWERTOYNAME); settings.properties.MaxMruSize.Value = Convert.ToInt32(sender.Value); if (ShellPage.DefaultSndMSGCallback != null) { SndPowerRenameSettings snd = new SndPowerRenameSettings(settings); SndModuleSettings ipcMessage = new SndModuleSettings(snd); ShellPage.DefaultSndMSGCallback(ipcMessage.ToJsonString()); } } } } }