From c2d31797633367b5b310bb0ee87b4db7d7daf808 Mon Sep 17 00:00:00 2001 From: Richard Buckle Date: Wed, 25 Jul 2018 21:49:02 +0100 Subject: [PATCH] Simplifications from Code Analysis --- EDDI/MainWindow.xaml.cs | 44 ++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/EDDI/MainWindow.xaml.cs b/EDDI/MainWindow.xaml.cs index 974d4081f8..3a82d0e5d0 100644 --- a/EDDI/MainWindow.xaml.cs +++ b/EDDI/MainWindow.xaml.cs @@ -255,10 +255,12 @@ public MainWindow(bool fromVA = false) private List GetAvailableLangs() { - List cultures = new List(); + List cultures = new List + { - // Add the "Automatic" culture, we are using the InvariantCulture name "" to mean user's culture - cultures.Add(new LanguageDef(CultureInfo.InvariantCulture, Properties.EddiResources.system_language)); + // Add the "Automatic" culture, we are using the InvariantCulture name "" to mean user's culture + new LanguageDef(CultureInfo.InvariantCulture, Properties.EddiResources.system_language) + }; CultureInfo neutralInfo = new CultureInfo("en"); // Add our "neutral" language "en". cultures.Add(new LanguageDef(neutralInfo)); @@ -301,8 +303,7 @@ private void LoadMonitors(EDDIConfiguration eddiConfiguration) PluginSkeleton skeleton = new PluginSkeleton(monitor.MonitorName()); skeleton.plugindescription.Text = monitor.MonitorDescription(); - bool enabled; - if (eddiConfiguration.Plugins.TryGetValue(monitor.MonitorName(), out enabled)) + if (eddiConfiguration.Plugins.TryGetValue(monitor.MonitorName(), out bool enabled)) { skeleton.pluginenabled.IsChecked = enabled; } @@ -335,8 +336,7 @@ private void LoadResponders(EDDIConfiguration eddiConfiguration) PluginSkeleton skeleton = new PluginSkeleton(responder.ResponderName()); skeleton.plugindescription.Text = responder.ResponderDescription(); - bool enabled; - if (eddiConfiguration.Plugins.TryGetValue(responder.ResponderName(), out enabled)) + if (eddiConfiguration.Plugins.TryGetValue(responder.ResponderName(), out bool enabled)) { skeleton.pluginenabled.IsChecked = enabled; } @@ -364,8 +364,10 @@ private void LoadResponders(EDDIConfiguration eddiConfiguration) private void ConfigureTTS() { SpeechServiceConfiguration speechServiceConfiguration = SpeechServiceConfiguration.FromFile(); - List speechOptions = new List(); - speechOptions.Add("Windows TTS default"); + List speechOptions = new List + { + "Windows TTS default" + }; try { using (SpeechSynthesizer synth = new SpeechSynthesizer()) @@ -380,7 +382,7 @@ private void ConfigureTTS() } ttsVoiceDropDown.ItemsSource = speechOptions; - ttsVoiceDropDown.Text = speechServiceConfiguration.StandardVoice == null ? "Windows TTS default" : speechServiceConfiguration.StandardVoice; + ttsVoiceDropDown.Text = speechServiceConfiguration.StandardVoice ?? "Windows TTS default"; } catch (Exception e) { @@ -754,14 +756,16 @@ private void enableICAOUpdated(object sender, RoutedEventArgs e) /// private void ttsUpdated() { - SpeechServiceConfiguration speechConfiguration = new SpeechServiceConfiguration(); - speechConfiguration.StandardVoice = ttsVoiceDropDown.SelectedValue == null || ttsVoiceDropDown.SelectedValue.ToString() == "Windows TTS default" ? null : ttsVoiceDropDown.SelectedValue.ToString(); - speechConfiguration.Volume = (int)ttsVolumeSlider.Value; - speechConfiguration.Rate = (int)ttsRateSlider.Value; - speechConfiguration.EffectsLevel = (int)ttsEffectsLevelSlider.Value; - speechConfiguration.DistortOnDamage = ttsDistortCheckbox.IsChecked.Value; - speechConfiguration.DisableSsml = disableSsmlCheckbox.IsChecked.Value; - speechConfiguration.EnableIcao = enableIcaoCheckbox.IsChecked.Value; + SpeechServiceConfiguration speechConfiguration = new SpeechServiceConfiguration + { + StandardVoice = ttsVoiceDropDown.SelectedValue == null || ttsVoiceDropDown.SelectedValue.ToString() == "Windows TTS default" ? null : ttsVoiceDropDown.SelectedValue.ToString(), + Volume = (int)ttsVolumeSlider.Value, + Rate = (int)ttsRateSlider.Value, + EffectsLevel = (int)ttsEffectsLevelSlider.Value, + DistortOnDamage = ttsDistortCheckbox.IsChecked.Value, + DisableSsml = disableSsmlCheckbox.IsChecked.Value, + EnableIcao = enableIcaoCheckbox.IsChecked.Value + }; speechConfiguration.ToFile(); SpeechService.Instance.ReloadConfiguration(); } @@ -774,9 +778,13 @@ private void ttsUpdated() public void OnVaWindowStateChange(WindowState state, bool minimizeCheck) { if (minimizeCheck && WindowState == WindowState.Minimized) + { WindowState = WindowState.Normal; + } else if (!minimizeCheck && WindowState != state) + { WindowState = state; + } } protected override void OnClosing(CancelEventArgs e)