From 15df1a2f1db01dd779bfae7334a26daa2459a5ea Mon Sep 17 00:00:00 2001
From: Den Delimarsky <1389609+dend@users.noreply.github.com>
Date: Sun, 2 May 2021 10:29:50 -0700
Subject: [PATCH] Update settings config.
---
.../ViewModels/EspressoViewModel.cs | 16 +++++++
.../Converters/EspressoModeToBoolConverter.cs | 44 +++++++++++++++++++
.../EspressoModeToReverseBoolConverter.cs | 44 +++++++++++++++++++
.../Microsoft.PowerToys.Settings.UI.csproj | 2 +
.../Views/EspressoPage.xaml | 14 ++++--
5 files changed, 117 insertions(+), 3 deletions(-)
create mode 100644 src/settings-ui/Microsoft.PowerToys.Settings.UI/Converters/EspressoModeToBoolConverter.cs
create mode 100644 src/settings-ui/Microsoft.PowerToys.Settings.UI/Converters/EspressoModeToReverseBoolConverter.cs
diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/ViewModels/EspressoViewModel.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/ViewModels/EspressoViewModel.cs
index 0d4bef052d..599e12bb74 100644
--- a/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/ViewModels/EspressoViewModel.cs
+++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/ViewModels/EspressoViewModel.cs
@@ -63,6 +63,22 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
}
}
+ public EspressoMode Mode
+ {
+ get => _mode;
+ set
+ {
+ if (_mode != value)
+ {
+ _mode = value;
+ OnPropertyChanged(nameof(Mode));
+
+ Settings.Properties.Mode = value;
+ NotifyPropertyChanged();
+ }
+ }
+ }
+
public bool KeepDisplayOn
{
get => _keepDisplayOn;
diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Converters/EspressoModeToBoolConverter.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Converters/EspressoModeToBoolConverter.cs
new file mode 100644
index 0000000000..22bb728e21
--- /dev/null
+++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Converters/EspressoModeToBoolConverter.cs
@@ -0,0 +1,44 @@
+// 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.Library;
+using Windows.UI.Xaml.Data;
+
+namespace Microsoft.PowerToys.Settings.UI.Converters
+{
+ public sealed class EspressoModeToBoolConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, string language)
+ {
+ if (targetType != typeof(bool))
+ {
+ throw new InvalidOperationException("The target type needs to be a boolean.");
+ }
+
+ switch ((EspressoMode)value)
+ {
+ case EspressoMode.INDEFINITE:
+ return true;
+ case EspressoMode.TIMED:
+ return false;
+ }
+
+ return false;
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, string language)
+ {
+ switch ((bool)value)
+ {
+ case true:
+ return EspressoMode.INDEFINITE;
+ case false:
+ return EspressoMode.TIMED;
+ }
+
+ return EspressoMode.INDEFINITE;
+ }
+ }
+}
diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Converters/EspressoModeToReverseBoolConverter.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Converters/EspressoModeToReverseBoolConverter.cs
new file mode 100644
index 0000000000..c9af415458
--- /dev/null
+++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Converters/EspressoModeToReverseBoolConverter.cs
@@ -0,0 +1,44 @@
+// 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.Library;
+using Windows.UI.Xaml.Data;
+
+namespace Microsoft.PowerToys.Settings.UI.Converters
+{
+ public sealed class EspressoModeToReverseBoolConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, string language)
+ {
+ if (targetType != typeof(bool))
+ {
+ throw new InvalidOperationException("The target type needs to be a boolean.");
+ }
+
+ switch ((EspressoMode)value)
+ {
+ case EspressoMode.INDEFINITE:
+ return false;
+ case EspressoMode.TIMED:
+ return true;
+ }
+
+ return false;
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, string language)
+ {
+ switch ((bool)value)
+ {
+ case false:
+ return EspressoMode.INDEFINITE;
+ case true:
+ return EspressoMode.TIMED;
+ }
+
+ return EspressoMode.INDEFINITE;
+ }
+ }
+}
diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Microsoft.PowerToys.Settings.UI.csproj b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Microsoft.PowerToys.Settings.UI.csproj
index 34d706754a..77aa5811fe 100644
--- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Microsoft.PowerToys.Settings.UI.csproj
+++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Microsoft.PowerToys.Settings.UI.csproj
@@ -105,6 +105,8 @@
ShortcutVisualControl.xaml
+
+
Code
diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/EspressoPage.xaml b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/EspressoPage.xaml
index 6db360bcb4..9f69ed35e0 100644
--- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/EspressoPage.xaml
+++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/EspressoPage.xaml
@@ -5,7 +5,8 @@
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"
+ xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
+ xmlns:c="using:Microsoft.PowerToys.Settings.UI.Converters"
xmlns:Custom="using:Microsoft.PowerToys.Settings.UI.Controls"
xmlns:Color="using:Microsoft.PowerToys.Settings.UI.Library.ViewModels" xmlns:Interactivity="using:Microsoft.Xaml.Interactivity" xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
mc:Ignorable="d"
@@ -14,6 +15,11 @@
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
AutomationProperties.LandmarkType="Main">
+
+
+
+
+
@@ -70,7 +76,8 @@
+ IsEnabled="{Binding IsEnabled}"
+ IsChecked="{Binding Mode, Mode=TwoWay, Converter={StaticResource EspressoModeToBoolConverter}}">
@@ -81,7 +88,8 @@
+ IsEnabled="{Binding IsEnabled}"
+ IsChecked="{Binding Mode, Mode=TwoWay, Converter={StaticResource EspressoModeToReverseBoolConverter}}">