Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Dec 15, 2024
1 parent bca4690 commit dd23c16
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion JL.Windows/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ internal sealed class ConfigManager
#endregion

private static readonly ComboBoxItem[] s_japaneseFonts = WindowsUtils.FindJapaneseFonts();
private static readonly ComboBoxItem[] s_popupJapaneseFonts = WindowsUtils.CloneJapaneseFontComboBoxItems(s_japaneseFonts);
private static readonly ComboBoxItem[] s_popupJapaneseFonts = WindowsUtils.CloneComboBoxItems(s_japaneseFonts);
private SkinType Theme { get; set; } = SkinType.Dark;

private ConfigManager()
Expand Down
6 changes: 5 additions & 1 deletion JL.Windows/GUI/AddAudioSourceWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using JL.Core.Audio;
using JL.Core.Utilities;
using JL.Windows.SpeechSynthesis;
using JL.Windows.Utilities;

namespace JL.Windows.GUI;

Expand Down Expand Up @@ -129,7 +130,10 @@ private void SaveButton_Click(object sender, RoutedEventArgs e)
private void Window_Loaded(object sender, RoutedEventArgs e)
{
AudioSourceTypeComboBox.ItemsSource = s_audioSourceTypes;
TextToSpeechVoicesComboBox.ItemsSource = SpeechSynthesisUtils.InstalledVoices;
if (SpeechSynthesisUtils.InstalledVoices is not null)
{
TextToSpeechVoicesComboBox.ItemsSource = WindowsUtils.CloneComboBoxItems(SpeechSynthesisUtils.InstalledVoices);
}
}

private void InfoButton_Click(object sender, RoutedEventArgs e)
Expand Down
16 changes: 9 additions & 7 deletions JL.Windows/GUI/EditAudioSourceWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using JL.Core.Audio;
using JL.Core.Utilities;
using JL.Windows.SpeechSynthesis;
using JL.Windows.Utilities;

namespace JL.Windows.GUI;

Expand Down Expand Up @@ -45,15 +46,16 @@ public EditAudioSourceWindow(string uri, AudioSource audioSource)

case AudioSourceType.TextToSpeech:
PathType.Text = "Text to Speech Voice";
TextToSpeechVoicesComboBox.ItemsSource = SpeechSynthesisUtils.InstalledVoices;

TextToSpeechVoicesComboBox.SelectedIndex = SpeechSynthesisUtils.InstalledVoices is not null
? Array.FindIndex(SpeechSynthesisUtils.InstalledVoices, iv => iv.Content.ToString() == _uri)
: 0;

if (TextToSpeechVoicesComboBox.SelectedIndex < 0)
if (SpeechSynthesisUtils.InstalledVoices is not null)
{
TextToSpeechVoicesComboBox.SelectedIndex = 0;
TextToSpeechVoicesComboBox.ItemsSource = WindowsUtils.CloneComboBoxItems(SpeechSynthesisUtils.InstalledVoices);
TextToSpeechVoicesComboBox.SelectedIndex = Array.FindIndex(SpeechSynthesisUtils.InstalledVoices, iv => iv.Content.ToString() == _uri);

if (TextToSpeechVoicesComboBox.SelectedIndex < 0)
{
TextToSpeechVoicesComboBox.SelectedIndex = 0;
}
}

TextBlockUri.Visibility = Visibility.Collapsed;
Expand Down
4 changes: 2 additions & 2 deletions JL.Windows/SpeechSynthesis/SpeechSynthesisUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ internal static class SpeechSynthesisUtils
public static string? InstalledVoiceWithHighestPriority { get; private set; }
private static SpeechSynthesizer Synthesizer { get; } = new();

public static ComboBoxItem[]? InstalledVoices { get; } = GetInstalledJapaneseVoiceNames();
public static ComboBoxItem[]? InstalledVoices { get; } = GetInstalledVoiceNames();

private static ComboBoxItem[]? GetInstalledJapaneseVoiceNames()
private static ComboBoxItem[]? GetInstalledVoiceNames()
{
Synthesizer.InjectOneCoreVoices();

Expand Down
10 changes: 5 additions & 5 deletions JL.Windows/Utilities/WindowsUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,16 @@ public static ComboBoxItem[] FindJapaneseFonts()
.ToArray();
}

public static ComboBoxItem[] CloneJapaneseFontComboBoxItems(ComboBoxItem[] japaneseFontsComboBoxItems)
public static ComboBoxItem[] CloneComboBoxItems(ComboBoxItem[] comboBoxItems)
{
ComboBoxItem[] clone = new ComboBoxItem[japaneseFontsComboBoxItems.Length];
for (int i = 0; i < japaneseFontsComboBoxItems.Length; i++)
ComboBoxItem[] clone = new ComboBoxItem[comboBoxItems.Length];
for (int i = 0; i < comboBoxItems.Length; i++)
{
ComboBoxItem comboBoxItem = japaneseFontsComboBoxItems[i];
ComboBoxItem comboBoxItem = comboBoxItems[i];

clone[i] = new ComboBoxItem
{
Content = comboBoxItem.FontFamily.Source,
Content = comboBoxItem.Content,
FontFamily = comboBoxItem.FontFamily
};

Expand Down

0 comments on commit dd23c16

Please sign in to comment.