Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Jul 20, 2024
1 parent fc7386e commit 3b83356
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 177 deletions.
5 changes: 1 addition & 4 deletions JL.Core/Dicts/EPWING/Yomichan/EpwingYomichanLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ public static async Task Load(Dict dict)
return;
}

List<string> jsonFiles = Directory.EnumerateFiles(fullPath, "*_bank_*.json", SearchOption.TopDirectoryOnly)
.Where(static s => s.Contains("term", StringComparison.Ordinal) || s.Contains("kanji", StringComparison.Ordinal))
.ToList();

IEnumerable<string> jsonFiles = Directory.EnumerateFiles(fullPath, "*_bank_*.json", SearchOption.TopDirectoryOnly);
foreach (string jsonFile in jsonFiles)
{
List<List<JsonElement>>? jsonElementLists;
Expand Down
3 changes: 1 addition & 2 deletions JL.Core/Dicts/KanjiDict/YomichanKanjiLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public static async Task Load(Dict dict)
return;
}

List<string> jsonFiles = Directory.EnumerateFiles(fullPath, "kanji_bank_*.json", SearchOption.TopDirectoryOnly).ToList();

IEnumerable<string> jsonFiles = Directory.EnumerateFiles(fullPath, "kanji_bank_*.json", SearchOption.TopDirectoryOnly);
foreach (string jsonFile in jsonFiles)
{
List<List<JsonElement>>? jsonObjects;
Expand Down
3 changes: 1 addition & 2 deletions JL.Core/Dicts/PitchAccent/YomichanPitchAccentLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public static async Task Load(Dict dict)

IDictionary<string, IList<IDictRecord>> pitchDict = dict.Contents;

string[] jsonFiles = Directory.GetFiles(fullPath, "term*bank_*.json");

IEnumerable<string> jsonFiles = Directory.EnumerateFiles(fullPath, "term*bank_*.json", SearchOption.TopDirectoryOnly);
foreach (string jsonFile in jsonFiles)
{
List<List<JsonElement>>? jsonObjects;
Expand Down
5 changes: 1 addition & 4 deletions JL.Core/Freqs/FrequencyYomichan/FrequencyYomichanLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ public static async Task Load(Freq freq)
return;
}

List<string> jsonFiles = Directory.EnumerateFiles(fullPath, "*_bank_*.json", SearchOption.TopDirectoryOnly)
.Where(static s => s.Contains("term", StringComparison.Ordinal) || s.Contains("kanji", StringComparison.Ordinal))
.ToList();

IEnumerable<string> jsonFiles = Directory.EnumerateFiles(fullPath, "*_bank_*.json", SearchOption.TopDirectoryOnly);
foreach (string jsonFile in jsonFiles)
{
List<List<JsonElement>>? frequencyJson;
Expand Down
61 changes: 35 additions & 26 deletions JL.Windows/GUI/AddDictionaryWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
Expand Down Expand Up @@ -32,17 +33,15 @@ private void CancelButton_Click(object sender, RoutedEventArgs e)

private void SaveButton_Click(object sender, RoutedEventArgs e)
{
bool isValid = true;
ComboBoxDictType.ClearValue(BorderBrushProperty);
TextBlockPath.ClearValue(BorderBrushProperty);
NameTextBox.ClearValue(BorderBrushProperty);

string? typeString = ComboBoxDictType.SelectionBoxItem.ToString();
if (string.IsNullOrEmpty(typeString))
{
ComboBoxDictType.BorderBrush = Brushes.Red;
isValid = false;
}
else if (ComboBoxDictType.BorderBrush == Brushes.Red)
{
ComboBoxDictType.ClearValue(BorderBrushProperty);
return;
}

string path = TextBlockPath.Text;
Expand All @@ -53,11 +52,7 @@ private void SaveButton_Click(object sender, RoutedEventArgs e)
|| DictUtils.Dicts.Values.Any(dict => dict.Path == path))
{
TextBlockPath.BorderBrush = Brushes.Red;
isValid = false;
}
else if (TextBlockPath.BorderBrush == Brushes.Red)
{
TextBlockPath.ClearValue(BorderBrushProperty);
return;
}

string name = NameTextBox.Text;
Expand All @@ -67,28 +62,42 @@ private void SaveButton_Click(object sender, RoutedEventArgs e)
|| DictUtils.Dicts.ContainsKey(name))
{
NameTextBox.BorderBrush = Brushes.Red;
isValid = false;
}
else if (NameTextBox.BorderBrush == Brushes.Red)
{
NameTextBox.ClearValue(BorderBrushProperty);
return;
}

if (isValid)
DictType type = typeString!.GetEnum<DictType>();
if (DictUtils.YomichanDictTypes.Contains(type))
{
DictType type = typeString!.GetEnum<DictType>();

DictOptions options = _dictOptionsControl.GetDictOptions(type);
Dict dict = new(type, name, path, true, DictUtils.Dicts.Count + 1, 0, false, options);
DictUtils.Dicts.Add(name, dict);

if (dict.Type is DictType.PitchAccentYomichan)
if (type is DictType.NonspecificKanjiYomichan)
{
DictUtils.SingleDictTypeDicts[DictType.PitchAccentYomichan] = dict;
bool validPath = Directory.EnumerateFiles(fullPath, "kanji_bank_*.json", SearchOption.TopDirectoryOnly).Any();
if (!validPath)
{
TextBlockPath.BorderBrush = Brushes.Red;
return;
}
}
else
{
bool validPath = Directory.EnumerateFiles(fullPath, "*_bank_*.json", SearchOption.TopDirectoryOnly).Any();
if (!validPath)
{
TextBlockPath.BorderBrush = Brushes.Red;
return;
}
}
}

DictOptions options = _dictOptionsControl.GetDictOptions(type);
Dict dict = new(type, name, path, true, DictUtils.Dicts.Count + 1, 0, false, options);
DictUtils.Dicts.Add(name, dict);

Close();
if (dict.Type is DictType.PitchAccentYomichan)
{
DictUtils.SingleDictTypeDicts[DictType.PitchAccentYomichan] = dict;
}

Close();
}

private void BrowseForDictionaryFile(string filter)
Expand Down
42 changes: 19 additions & 23 deletions JL.Windows/GUI/AddFrequencyWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,15 @@ private void CancelButton_Click(object sender, RoutedEventArgs e)

private void SaveButton_Click(object sender, RoutedEventArgs e)
{
bool isValid = true;
FreqTypeComboBox.ClearValue(BorderBrushProperty);
TextBlockPath.ClearValue(BorderBrushProperty);
NameTextBox.ClearValue(BorderBrushProperty);

string? typeString = FreqTypeComboBox.SelectionBoxItem.ToString();
if (string.IsNullOrEmpty(typeString))
{
FreqTypeComboBox.BorderBrush = Brushes.Red;
isValid = false;
}
else if (FreqTypeComboBox.BorderBrush == Brushes.Red)
{
FreqTypeComboBox.ClearValue(BorderBrushProperty);
return;
}

string path = TextBlockPath.Text;
Expand All @@ -51,11 +49,7 @@ private void SaveButton_Click(object sender, RoutedEventArgs e)
|| FreqUtils.FreqDicts.Values.Any(freq => freq.Path == path))
{
TextBlockPath.BorderBrush = Brushes.Red;
isValid = false;
}
else if (TextBlockPath.BorderBrush == Brushes.Red)
{
TextBlockPath.ClearValue(BorderBrushProperty);
return;
}

string name = NameTextBox.Text;
Expand All @@ -65,24 +59,26 @@ private void SaveButton_Click(object sender, RoutedEventArgs e)
|| FreqUtils.FreqDicts.ContainsKey(name))
{
NameTextBox.BorderBrush = Brushes.Red;
isValid = false;
}
else if (NameTextBox.BorderBrush == Brushes.Red)
{
NameTextBox.ClearValue(BorderBrushProperty);
return;
}

if (isValid)
FreqType type = typeString!.GetEnum<FreqType>();
if (type is FreqType.Yomichan or FreqType.YomichanKanji)
{
FreqType type = typeString!.GetEnum<FreqType>();
bool validPath = Directory.EnumerateFiles(fullPath, "*_bank_*.json", SearchOption.TopDirectoryOnly).Any();
if (!validPath)
{
TextBlockPath.BorderBrush = Brushes.Red;
return;
}
}

FreqOptions options = _freqOptionsControl.GetFreqOptions(type);
FreqOptions options = _freqOptionsControl.GetFreqOptions(type);

FreqUtils.FreqDicts.Add(name,
new Freq(type, name, path, true, FreqUtils.FreqDicts.Count + 1, 0, 0, false, options));
FreqUtils.FreqDicts.Add(name,
new Freq(type, name, path, true, FreqUtils.FreqDicts.Count + 1, 0, 0, false, options));

Close();
}
Close();
}

private void BrowseForFrequencyFile(string filter)
Expand Down
Loading

0 comments on commit 3b83356

Please sign in to comment.