Skip to content

Commit

Permalink
Simplifications from Code Analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
richardbuckle committed Jul 25, 2018
1 parent 8d92d29 commit c2d3179
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions EDDI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,12 @@ public MainWindow(bool fromVA = false)

private List<LanguageDef> GetAvailableLangs()
{
List<LanguageDef> cultures = new List<LanguageDef>();
List<LanguageDef> cultures = new List<LanguageDef>
{

// 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));
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -364,8 +364,10 @@ private void LoadResponders(EDDIConfiguration eddiConfiguration)
private void ConfigureTTS()
{
SpeechServiceConfiguration speechServiceConfiguration = SpeechServiceConfiguration.FromFile();
List<string> speechOptions = new List<string>();
speechOptions.Add("Windows TTS default");
List<string> speechOptions = new List<string>
{
"Windows TTS default"
};
try
{
using (SpeechSynthesizer synth = new SpeechSynthesizer())
Expand All @@ -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)
{
Expand Down Expand Up @@ -754,14 +756,16 @@ private void enableICAOUpdated(object sender, RoutedEventArgs e)
/// </summary>
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();
}
Expand All @@ -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)
Expand Down

0 comments on commit c2d3179

Please sign in to comment.