From ebeaa2942385204f1abe88ddd7d24702fc94296a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaro=20Mart=C3=ADnez?= Date: Wed, 24 Apr 2024 03:14:23 -0500 Subject: [PATCH] Use SetEnum for setting enums No need to check if enums are enums, use SetEnum directly now! --- RetroBar/Utilities/Settings.cs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/RetroBar/Utilities/Settings.cs b/RetroBar/Utilities/Settings.cs index 0b7e2cfd..4698c049 100644 --- a/RetroBar/Utilities/Settings.cs +++ b/RetroBar/Utilities/Settings.cs @@ -1,4 +1,5 @@ using ManagedShell.AppBar; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; @@ -54,7 +55,18 @@ protected void Set(ref T field, T value, [CallerMemberName] string propertyNa { if (!field.Equals(value)) { - if (typeof(T).IsEnum && System.Convert.ToInt32(value) < 0) + // TODO: Should we log setting change? + + field = value; + OnPropertyChanged(propertyName); + } + } + + protected void SetEnum(ref T field, T value, [CallerMemberName] string propertyName = "") where T : struct, Enum + { + if (!field.Equals(value)) + { + if (Convert.ToInt32(value) < 0) { return; } @@ -178,7 +190,7 @@ public bool UseSoftwareRendering public AppBarEdge Edge { get => _edge; - set => Set(ref _edge, value); + set => SetEnum(ref _edge, value); } private List _quickLaunchOrder = []; @@ -199,7 +211,7 @@ public bool ShowTaskThumbnails public MultiMonOption MultiMonMode { get => _multiMonMode; - set => Set(ref _multiMonMode, value); + set => SetEnum(ref _multiMonMode, value); } private double _taskbarScale = 1.0; @@ -234,7 +246,7 @@ public bool LockTaskbar public InvertIconsOption InvertIconsMode { get => _invertIconsMode; - set => Set(ref _invertIconsMode, value); + set => SetEnum(ref _invertIconsMode, value); } private bool _showTaskBadges = true; @@ -248,7 +260,7 @@ public bool ShowTaskBadges public TaskMiddleClickOption TaskMiddleClickAction { get => _taskMiddleClickAction; - set => Set(ref _taskMiddleClickAction, value); + set => SetEnum(ref _taskMiddleClickAction, value); } private bool _updates = true;