Skip to content

Commit

Permalink
Use SetEnum for setting enums
Browse files Browse the repository at this point in the history
No need to check if enums are enums, use SetEnum directly now!
  • Loading branch information
xoascf committed Apr 24, 2024
1 parent e809aa1 commit ebeaa29
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions RetroBar/Utilities/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ManagedShell.AppBar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -54,7 +55,18 @@ protected void Set<T>(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<T>(ref T field, T value, [CallerMemberName] string propertyName = "") where T : struct, Enum
{
if (!field.Equals(value))
{
if (Convert.ToInt32(value) < 0)
{
return;
}
Expand Down Expand Up @@ -178,7 +190,7 @@ public bool UseSoftwareRendering
public AppBarEdge Edge
{
get => _edge;
set => Set(ref _edge, value);
set => SetEnum(ref _edge, value);
}

private List<string> _quickLaunchOrder = [];
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit ebeaa29

Please sign in to comment.