Switch case

This commit is contained in:
Niels Laute
2021-08-11 14:17:47 +02:00
parent ba4aa3c33d
commit 9865b48366
4 changed files with 45 additions and 134 deletions

View File

@@ -265,65 +265,27 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
{ {
if (_themeIndex != value) if (_themeIndex != value)
{ {
if (value == 0) switch (value)
{ {
// set theme to dark. case 0: GeneralSettingsConfig.Theme = "dark"; break;
GeneralSettingsConfig.Theme = "dark"; case 1: GeneralSettingsConfig.Theme = "light"; break;
_themeIndex = value; case 2: GeneralSettingsConfig.Theme = "system"; break;
try
{
UpdateUIThemeCallBack(GeneralSettingsConfig.Theme);
}
#pragma warning disable CA1031 // Do not catch general exception types
catch (Exception e)
#pragma warning restore CA1031 // Do not catch general exception types
{
Logger.LogError("Exception encountered when changing Settings theme", e);
}
NotifyPropertyChanged();
} }
if (value == 1) _themeIndex = value;
try
{ {
// set theme to light. UpdateUIThemeCallBack(GeneralSettingsConfig.Theme);
GeneralSettingsConfig.Theme = "light"; }
_themeIndex = value;
try
{
UpdateUIThemeCallBack(GeneralSettingsConfig.Theme);
}
#pragma warning disable CA1031 // Do not catch general exception types #pragma warning disable CA1031 // Do not catch general exception types
catch (Exception e) catch (Exception e)
#pragma warning restore CA1031 // Do not catch general exception types #pragma warning restore CA1031 // Do not catch general exception types
{ {
Logger.LogError("Exception encountered when changing Settings theme", e); Logger.LogError("Exception encountered when changing Settings theme", e);
}
NotifyPropertyChanged();
} }
if (value == 2) NotifyPropertyChanged();
{
// set theme to system default.
GeneralSettingsConfig.Theme = "system";
_themeIndex = value;
try
{
UpdateUIThemeCallBack(GeneralSettingsConfig.Theme);
}
#pragma warning disable CA1031 // Do not catch general exception types
catch (Exception e)
#pragma warning restore CA1031 // Do not catch general exception types
{
Logger.LogError("Exception encountered when changing Settings theme", e);
}
NotifyPropertyChanged();
}
} }
} }
} }

View File

@@ -197,32 +197,15 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
set set
{ {
if (_themeIndex != value) switch (value)
{ {
if (value == 0) case 0: settings.Properties.Theme = Theme.Dark; break;
{ case 1: settings.Properties.Theme = Theme.Light; break;
// set theme to dark. case 2: settings.Properties.Theme = Theme.System; break;
settings.Properties.Theme = Theme.Dark;
_themeIndex = value;
UpdateSettings();
}
if (value == 1)
{
// set theme to light.
settings.Properties.Theme = Theme.Light;
_themeIndex = value;
UpdateSettings();
}
if (value == 2)
{
// set theme to system default.
settings.Properties.Theme = Theme.System;
_themeIndex = value;
UpdateSettings();
}
} }
_themeIndex = value;
UpdateSettings();
} }
} }
@@ -237,23 +220,15 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
{ {
if (_monitorPositionIndex != value) if (_monitorPositionIndex != value)
{ {
if (value == 0) switch (value)
{ {
settings.Properties.Position = StartupPosition.Cursor; case 0: settings.Properties.Position = StartupPosition.Cursor; break;
UpdateSettings(); case 1: settings.Properties.Position = StartupPosition.PrimaryMonitor; break;
case 2: settings.Properties.Position = StartupPosition.Focus; break;
} }
if (value == 1) _monitorPositionIndex = value;
{ UpdateSettings();
settings.Properties.Position = StartupPosition.PrimaryMonitor;
UpdateSettings();
}
if (value == 2)
{
settings.Properties.Position = StartupPosition.Focus;
UpdateSettings();
}
} }
} }
} }

View File

@@ -56,21 +56,11 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
_opacity = Settings.Properties.OverlayOpacity.Value; _opacity = Settings.Properties.OverlayOpacity.Value;
_disabledApps = Settings.Properties.DisabledApps.Value; _disabledApps = Settings.Properties.DisabledApps.Value;
string theme = Settings.Properties.Theme.Value; switch (Settings.Properties.Theme.Value)
if (theme == "dark")
{ {
_themeIndex = 0; case "dark": _themeIndex = 0; break;
} case "light": _themeIndex = 1; break;
case "system": _themeIndex = 2; break;
if (theme == "light")
{
_themeIndex = 1;
}
if (theme == "system")
{
_themeIndex = 2;
} }
} }
@@ -130,29 +120,15 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
{ {
if (_themeIndex != value) if (_themeIndex != value)
{ {
if (value == 0) switch (value)
{ {
// set theme to dark. case 0: Settings.Properties.Theme.Value = "dark"; break;
Settings.Properties.Theme.Value = "dark"; case 1: Settings.Properties.Theme.Value = "light"; break;
_themeIndex = value; case 2: Settings.Properties.Theme.Value = "system"; break;
NotifyPropertyChanged();
} }
if (value == 1) _themeIndex = value;
{ NotifyPropertyChanged();
// set theme to light.
Settings.Properties.Theme.Value = "light";
_themeIndex = value;
NotifyPropertyChanged();
}
if (value == 2)
{
// set theme to system default.
Settings.Properties.Theme.Value = "system";
_themeIndex = value;
NotifyPropertyChanged();
}
} }
} }
} }

View File

@@ -272,7 +272,7 @@ Disabling this module or closing PowerToys will unmute the microphone and camera
<value>Remap a key</value> <value>Remap a key</value>
<comment>Keyboard Manager remap keyboard button content</comment> <comment>Keyboard Manager remap keyboard button content</comment>
</data> </data>
<data name="KeyboardManager_Keys.Header" xml:space="preserve"> <data name="KeyboardManager_Keys.Header" xml:space="preserve">
<value>Keys</value> <value>Keys</value>
<comment>Keyboard Manager remap keyboard header</comment> <comment>Keyboard Manager remap keyboard header</comment>
</data> </data>
@@ -280,7 +280,7 @@ Disabling this module or closing PowerToys will unmute the microphone and camera
<value>Remap a shortcut</value> <value>Remap a shortcut</value>
<comment>Keyboard Manager remap shortcuts button</comment> <comment>Keyboard Manager remap shortcuts button</comment>
</data> </data>
<data name="KeyboardManager_Shortcuts.Header" xml:space="preserve"> <data name="KeyboardManager_Shortcuts.Header" xml:space="preserve">
<value>Shortcuts</value> <value>Shortcuts</value>
<comment>Keyboard Manager remap keyboard header</comment> <comment>Keyboard Manager remap keyboard header</comment>
</data> </data>
@@ -413,7 +413,7 @@ Disabling this module or closing PowerToys will unmute the microphone and camera
<value>Excluded apps</value> <value>Excluded apps</value>
</data> </data>
<data name="FancyZones_ExcludeApps.Description" xml:space="preserve"> <data name="FancyZones_ExcludeApps.Description" xml:space="preserve">
<value>Excludes an application from snappting to zones and will only react to Windows Snap. Add one application name per line.</value> <value>Excludes an application from snapping to zones and will only react to Windows Snap. Add one application name per line.</value>
</data> </data>
<data name="FancyZones_HighlightOpacity.Header" xml:space="preserve"> <data name="FancyZones_HighlightOpacity.Header" xml:space="preserve">
<value>Zone opacity</value> <value>Zone opacity</value>
@@ -950,7 +950,7 @@ Made with 💗 by Microsoft and the PowerToys community.</value>
<data name="ColorFormats.Header" xml:space="preserve"> <data name="ColorFormats.Header" xml:space="preserve">
<value>Picker behavior</value> <value>Picker behavior</value>
</data> </data>
<data name="ColorPicker_CopiedColorRepresentation.Description" xml:space="preserve"> <data name="ColorPicker_CopiedColorRepresentation.Description" xml:space="preserve">
<value>This format will be copied to your clipboard</value> <value>This format will be copied to your clipboard</value>
</data> </data>
<data name="KBM_KeysCannotBeRemapped.Text" xml:space="preserve"> <data name="KBM_KeysCannotBeRemapped.Text" xml:space="preserve">
@@ -969,9 +969,8 @@ Made with 💗 by Microsoft and the PowerToys community.</value>
</data> </data>
<data name="FancyZones_Windows.Header" xml:space="preserve"> <data name="FancyZones_Windows.Header" xml:space="preserve">
<value>Windows</value> <value>Windows</value>
<comment>refers to a set of windows, not the product name</comment> <comment>refers to a set of windows, not the product name</comment>
</data> </data>
<data name="PowerRename_BehaviorHeader.Header" xml:space="preserve"> <data name="PowerRename_BehaviorHeader.Header" xml:space="preserve">
<value>Behavior</value> <value>Behavior</value>
</data> </data>
@@ -999,16 +998,16 @@ Made with 💗 by Microsoft and the PowerToys community.</value>
<data name="ColorPicker_ColorFormats.Header" xml:space="preserve"> <data name="ColorPicker_ColorFormats.Header" xml:space="preserve">
<value>Color formats</value> <value>Color formats</value>
</data> </data>
<data name="ColorPicker_ColorFormats.Description" xml:space="preserve"> <data name="ColorPicker_ColorFormats.Description" xml:space="preserve">
<value>Select which color formats (and in what order) should show up in the editor</value> <value>Select which color formats (and in what order) should show up in the editor</value>
</data> </data>
<data name="MoveUp.Text" xml:space="preserve"> <data name="MoveUp.Text" xml:space="preserve">
<value>Move up</value> <value>Move up</value>
</data> </data>
<data name="MoveDown.Text" xml:space="preserve"> <data name="MoveDown.Text" xml:space="preserve">
<value>Move down</value> <value>Move down</value>
</data> </data>
<data name="ColorPicker_ShowColorName.Content" xml:space="preserve"> <data name="ColorPicker_ShowColorName.Content" xml:space="preserve">
<value>Show color name when color picking</value> <value>Show color name when color picking</value>
</data> </data>
<data name="ImageResizer_DefaultSize_Large" xml:space="preserve"> <data name="ImageResizer_DefaultSize_Large" xml:space="preserve">
@@ -1129,7 +1128,6 @@ Made with 💗 by Microsoft and the PowerToys community.</value>
<data name="FancyZones_QuickLayoutSwitch.Description" xml:space="preserve"> <data name="FancyZones_QuickLayoutSwitch.Description" xml:space="preserve">
<value>You can configure layout-specific shortcuts in the editor</value> <value>You can configure layout-specific shortcuts in the editor</value>
</data> </data>
<data name="FancyZones_QuickLayoutSwitch_GroupSettings.Text" xml:space="preserve"> <data name="FancyZones_QuickLayoutSwitch_GroupSettings.Text" xml:space="preserve">
<value>Quick layout switch</value> <value>Quick layout switch</value>
</data> </data>