Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Dec 22, 2024
1 parent 3fdfa02 commit 73c8def
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion JL.Core/Dicts/EPWING/Yomichan/EpwingYomichanLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static async Task Load(Dict dict)
}

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

bool nonKanjiDict = dict.Type is not DictType.NonspecificKanjiWithWordSchemaYomichan;
bool nonNameDict = dict.Type is not DictType.NonspecificNameYomichan;
Expand Down
2 changes: 1 addition & 1 deletion JL.Core/Freqs/FrequencyYomichan/FrequencyYomichanLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static async Task Load(Freq freq)
}

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

foreach (string jsonFile in jsonFiles)
{
Expand Down
3 changes: 3 additions & 0 deletions JL.Core/Utilities/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Buffers;
using System.Collections.Frozen;
using System.Globalization;
using System.Security.Cryptography;
Expand Down Expand Up @@ -249,4 +250,6 @@ public static string GetPath(string path)

return concatArray;
}

public static readonly SearchValues<string> ValidYomichanFileSuffixes = SearchValues.Create(["term", "kanji"], StringComparison.Ordinal);
}
2 changes: 1 addition & 1 deletion JL.Windows/GUI/AddDictionaryWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void SaveButton_Click(object sender, RoutedEventArgs e)
else
{
bool validPath = Directory.EnumerateFiles(fullPath, "*_bank_*.json", SearchOption.TopDirectoryOnly)
.Any(static s => s.Contains("term", StringComparison.Ordinal) || s.Contains("kanji", StringComparison.Ordinal));
.Any(static s => Utils.ValidYomichanFileSuffixes.Contains(s));

if (!validPath)
{
Expand Down
2 changes: 1 addition & 1 deletion JL.Windows/GUI/AddFrequencyWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private void SaveButton_Click(object sender, RoutedEventArgs e)
if (type is FreqType.Yomichan or FreqType.YomichanKanji)
{
bool validPath = Directory.EnumerateFiles(fullPath, "*_bank_*.json", SearchOption.TopDirectoryOnly)
.Any(static s => s.Contains("term", StringComparison.Ordinal) || s.Contains("kanji", StringComparison.Ordinal));
.Any(static s => Utils.ValidYomichanFileSuffixes.Contains(s));

if (!validPath)
{
Expand Down
2 changes: 1 addition & 1 deletion JL.Windows/GUI/EditDictionaryWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void SaveButton_Click(object sender, RoutedEventArgs e)
else
{
bool validPath = Directory.EnumerateFiles(fullPath, "*_bank_*.json", SearchOption.TopDirectoryOnly)
.Any(static s => s.Contains("term", StringComparison.Ordinal) || s.Contains("kanji", StringComparison.Ordinal));
.Any(static s => Utils.ValidYomichanFileSuffixes.Contains(s));

if (!validPath)
{
Expand Down
2 changes: 1 addition & 1 deletion JL.Windows/GUI/EditFrequencyWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private void SaveButton_Click(object sender, RoutedEventArgs e)
if (_freq.Type is FreqType.Yomichan or FreqType.YomichanKanji)
{
bool hasValidFiles = Directory.EnumerateFiles(fullPath, "*_bank_*.json", SearchOption.TopDirectoryOnly)
.Any(static s => s.Contains("term", StringComparison.Ordinal) || s.Contains("kanji", StringComparison.Ordinal));
.Any(static s => Utils.ValidYomichanFileSuffixes.Contains(s));

if (!hasValidFiles)
{
Expand Down
7 changes: 4 additions & 3 deletions JL.Windows/Utilities/KeyGestureUtils.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Buffers;
using System.Collections.Frozen;
using System.Text;
using System.Windows.Controls;
Expand All @@ -10,6 +11,8 @@ namespace JL.Windows.Utilities;

internal static class KeyGestureUtils
{
private static readonly SearchValues<string> s_validModifiers = SearchValues.Create(["Ctrl", "Alt", "Shift"], StringComparison.Ordinal);

public static readonly OrderedDictionary<string, KeyGesture> GlobalKeyGestureNameToKeyGestureDict = [];

public static readonly KeyGesture AltF4KeyGesture = new(Key.F4, ModifierKeys.Alt);
Expand Down Expand Up @@ -174,9 +177,7 @@ public static KeyGesture GetKeyGestureFromConfig(SqliteConnection connection, st
{
KeyGestureConverter keyGestureConverter = new();

string keyGestureString = rawKeyGesture.Contains("Ctrl", StringComparison.Ordinal)
|| rawKeyGesture.Contains("Alt", StringComparison.Ordinal)
|| rawKeyGesture.Contains("Shift", StringComparison.Ordinal)
string keyGestureString = s_validModifiers.Contains(rawKeyGesture)
? rawKeyGesture
: $"Win+{rawKeyGesture}";

Expand Down

0 comments on commit 73c8def

Please sign in to comment.