Update settings configuration

There is a non-zero amount of settings that I need to set up for Espresso to work properly. This change is all about updating the view model and its binding to the UI.
This commit is contained in:
Den Delimarsky
2021-04-07 10:38:17 -07:00
parent ee932450df
commit 0e0bae0198
3 changed files with 47 additions and 23 deletions

View File

@@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System; using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.PowerToys.Settings.UI.Library.Helpers; using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces; using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
@@ -15,11 +14,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
private EspressoSettings Settings { get; set; } private EspressoSettings Settings { get; set; }
private string settingsConfigFileFolder = string.Empty;
private Func<string, int> SendConfigMSG { get; } private Func<string, int> SendConfigMSG { get; }
public EspressoViewModel(ISettingsRepository<GeneralSettings> settingsRepository, ISettingsRepository<EspressoSettings> moduleSettingsRepository, Func<string, int> ipcMSGCallBackFunc, string configFileSubfolder = "") public EspressoViewModel(ISettingsRepository<GeneralSettings> settingsRepository, ISettingsRepository<EspressoSettings> moduleSettingsRepository, Func<string, int> ipcMSGCallBackFunc)
{ {
// To obtain the general settings configurations of PowerToys Settings. // To obtain the general settings configurations of PowerToys Settings.
if (settingsRepository == null) if (settingsRepository == null)
@@ -28,7 +25,6 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
} }
GeneralSettingsConfig = settingsRepository.SettingsConfig; GeneralSettingsConfig = settingsRepository.SettingsConfig;
settingsConfigFileFolder = configFileSubfolder;
// To obtain the settings configurations of Fancy zones. // To obtain the settings configurations of Fancy zones.
if (moduleSettingsRepository == null) if (moduleSettingsRepository == null)
@@ -45,7 +41,25 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
// set the callback functions value to hangle outgoing IPC message. // set the callback functions value to hangle outgoing IPC message.
SendConfigMSG = ipcMSGCallBackFunc; SendConfigMSG = ipcMSGCallBackFunc;
_isEnabled = GeneralSettingsConfig.Enabled.Espresso; IsEnabled = GeneralSettingsConfig.Enabled.Espresso;
}
public bool IsEnabled
{
get => _isEnabled;
set
{
if (_isEnabled != value)
{
_isEnabled = value;
OnPropertyChanged(nameof(IsEnabled));
GeneralSettingsConfig.Enabled.Espresso = value;
var outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
SendConfigMSG(outgoing.ToString());
}
}
} }
private bool _isEnabled; private bool _isEnabled;

View File

@@ -1179,4 +1179,7 @@ Win + Shift + O to toggle your video</value>
<data name="Espresso_EnableDisplayKeepAwake.Header" xml:space="preserve"> <data name="Espresso_EnableDisplayKeepAwake.Header" xml:space="preserve">
<value>Keep display on</value> <value>Keep display on</value>
</data> </data>
<data name="Espresso_Behavior_GroupSettings.Text" xml:space="preserve">
<value>Behavior</value>
</data>
</root> </root>

View File

@@ -53,38 +53,45 @@
HorizontalAlignment="Left" HorizontalAlignment="Left"
Margin="0,0,48,0" Margin="0,0,48,0"
MaxWidth="{StaticResource MaxContentWidth}"> MaxWidth="{StaticResource MaxContentWidth}">
<ToggleSwitch x:Uid="Espresso_EnableEspresso" IsOn="True" /> <ToggleSwitch x:Uid="Espresso_EnableEspresso" IsOn="{Binding IsEnabled, Mode=TwoWay}" />
<ToggleSwitch x:Uid="Espresso_EnableDisplayKeepAwake" IsOn="True" />
<!--IsOn="{x:Bind Mode=TwoWay, Path=ViewModel.EnablePowerLauncher}"/>--> <!--IsOn="{x:Bind Mode=TwoWay, Path=ViewModel.EnablePowerLauncher}"/>-->
<!--<TextBlock x:Uid="Shortcuts" <!--<TextBlock x:Uid="Shortcuts"
Style="{StaticResource SettingsGroupTitleStyle}" Style="{StaticResource SettingsGroupTitleStyle}"
Foreground="{x:Bind Mode=OneWay, Path=ViewModel.EnablePowerLauncher, Converter={StaticResource ModuleEnabledToForegroundConverter}}"/>--> Foreground="{x:Bind Mode=OneWay, Path=ViewModel.EnablePowerLauncher, Converter={StaticResource ModuleEnabledToForegroundConverter}}"/>-->
<TextBlock x:Uid="FancyZones_Editor_GroupSettings" <TextBlock x:Uid="Espresso_Behavior_GroupSettings"
Style="{StaticResource SettingsGroupTitleStyle}"/> Style="{StaticResource SettingsGroupTitleStyle}"/>
<ToggleSwitch x:Uid="Espresso_EnableDisplayKeepAwake"
IsEnabled="{Binding IsEnabled}"
IsOn="True" />
<!--Foreground="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabled, Converter={StaticResource ModuleEnabledToForegroundConverter}}"--> <!--Foreground="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabled, Converter={StaticResource ModuleEnabledToForegroundConverter}}"-->
<RadioButton x:Uid="Espresso_IndefiniteKeepAwake">
<RadioButton.Content> <StackPanel Margin="{StaticResource MediumTopMargin}">
<TextBlock TextWrapping="WrapWholeWords" LineHeight="20"> <RadioButton x:Uid="Espresso_IndefiniteKeepAwake"
IsEnabled="{Binding IsEnabled}">
<RadioButton.Content>
<TextBlock TextWrapping="WrapWholeWords" LineHeight="20">
<Run x:Uid="Espresso_IndefiniteKeepAwakeContent"/> <Run x:Uid="Espresso_IndefiniteKeepAwakeContent"/>
<LineBreak/> <LineBreak/>
<Run Foreground="{ThemeResource SystemBaseMediumColor}" <Run Foreground="{ThemeResource SystemBaseMediumColor}"
x:Uid="Espresso_IndefiniteKeepAwakeDescription"/> x:Uid="Espresso_IndefiniteKeepAwakeDescription"/>
</TextBlock> </TextBlock>
</RadioButton.Content> </RadioButton.Content>
</RadioButton> </RadioButton>
<RadioButton x:Uid="Espresso_TemporaryKeepAwake"> <RadioButton x:Uid="Espresso_TemporaryKeepAwake"
<RadioButton.Content> IsEnabled="{Binding IsEnabled}">
<TextBlock TextWrapping="WrapWholeWords" LineHeight="20"> <RadioButton.Content>
<TextBlock TextWrapping="WrapWholeWords" LineHeight="20">
<Run x:Uid="Espresso_TemporaryKeepAwakeContent"/> <Run x:Uid="Espresso_TemporaryKeepAwakeContent"/>
<LineBreak/> <LineBreak/>
<Run Foreground="{ThemeResource SystemBaseMediumColor}" <Run Foreground="{ThemeResource SystemBaseMediumColor}"
x:Uid="Espresso_TemporaryKeepAwakeDescription"/> x:Uid="Espresso_TemporaryKeepAwakeDescription"/>
</TextBlock> </TextBlock>
</RadioButton.Content> </RadioButton.Content>
</RadioButton> </RadioButton>
</StackPanel> </StackPanel>
</StackPanel>
<RelativePanel x:Name="SidePanel" <RelativePanel x:Name="SidePanel"
HorizontalAlignment="Left" HorizontalAlignment="Left"
@@ -136,7 +143,7 @@
NavigateUri="https://medium.com/@Niels9001/a-fluent-color-meter-for-powertoys-20407ededf0c"> NavigateUri="https://medium.com/@Niels9001/a-fluent-color-meter-for-powertoys-20407ededf0c">
<TextBlock Text="Niels Laute's UX concept" TextWrapping="Wrap" /> <TextBlock Text="Niels Laute's UX concept" TextWrapping="Wrap" />
</HyperlinkButton> </HyperlinkButton>
</StackPanel> </StackPanel>
</RelativePanel> </RelativePanel>
</Grid> </Grid>