From 09a2e4f479e588bb2c5b6c168d175469fec12668 Mon Sep 17 00:00:00 2001 From: rampaa Date: Sat, 30 Sep 2023 16:12:35 +0300 Subject: [PATCH] Minor optimizations --- JL.Core.Tests/LookupTests.cs | 7 +- JL.Core/Anki/Mining.cs | 3 +- .../Dicts/CustomNameDict/CustomNameLoader.cs | 7 +- .../Dicts/CustomWordDict/CustomWordLoader.cs | 6 +- .../Dicts/CustomWordDict/CustomWordRecord.cs | 4 +- JL.Core/Dicts/DictUtils.cs | 38 +++++- .../Dicts/EDICT/JMdict/JmdictRecordBuilder.cs | 6 +- .../EDICT/JMnedict/JmnedictRecordBuilder.cs | 2 +- .../Dicts/EDICT/KANJIDIC/KanjidicLoader.cs | 9 +- JL.Core/Dicts/EDICT/ResourceUpdater.cs | 6 +- .../EPWING/EpwingNazeka/EpwingNazekaLoader.cs | 5 +- .../EpwingYomichan/EpwingYomichanLoader.cs | 4 +- .../EpwingYomichan/EpwingYomichanRecord.cs | 2 +- .../YomichanKanji/YomichanKanjiLoader.cs | 2 +- .../YomichanKanji/YomichanKanjiRecord.cs | 2 +- .../FrequencyNazeka/FrequencyNazekaLoader.cs | 8 +- .../FrequencyYomichanLoader.cs | 6 +- JL.Core/Lookup/LookupResult.cs | 4 +- JL.Core/Lookup/LookupUtils.cs | 127 +++++++++--------- JL.Core/PitchAccent/PitchAccentRecord.cs | 2 +- JL.Core/Utilities/Utils.cs | 33 +++++ JL.Core/WordClass/JmdictWordClassUtils.cs | 19 ++- JL.Windows/DictOptionManager.cs | 7 +- JL.Windows/GUI/AddDictionaryWindow.xaml.cs | 2 +- JL.Windows/GUI/MainWindow.xaml.cs | 6 +- JL.Windows/GUI/PopupWindow.xaml.cs | 35 ++--- JL.Windows/GUI/PreferencesWindow.xaml.cs | 16 +-- JL.Windows/Utilities/ExtensionMethods.cs | 42 +++--- JL.Windows/Utilities/PopupWindowUtils.cs | 22 +-- JL.Windows/Utilities/WindowsUtils.cs | 2 +- 30 files changed, 238 insertions(+), 196 deletions(-) diff --git a/JL.Core.Tests/LookupTests.cs b/JL.Core.Tests/LookupTests.cs index 7c42c9a3..345f1112 100644 --- a/JL.Core.Tests/LookupTests.cs +++ b/JL.Core.Tests/LookupTests.cs @@ -39,7 +39,10 @@ public void ClassInit() antonym: new AntonymOption(false) ))); - JmdictLoader.Load(DictUtils.Dicts.Values.First(static dict => dict.Type is DictType.JMdict)).Wait(); + Dict dict = DictUtils.Dicts["JMdict"]; + DictUtils.BuiltInDictTypeToDict[DictType.JMdict] = dict; + JmdictLoader.Load(dict).Wait(); + FreqUtils.FreqDicts = FreqUtils.s_builtInFreqs; FreqUtils.LoadFrequencies().Wait(); DeconjugatorUtils.DeserializeRules().Wait(); @@ -59,7 +62,7 @@ public void LookupText_始まる() frequencies: new List { new("VN (Nazeka)", 759) }, primarySpelling: "始まる", deconjugatedMatchedText: "始まる", - readings: new List { "はじまる" }, + readings: new[] { "はじまる" }, formattedDefinitions: "(v5r, vi) (1) to begin; to start; to commence (v5r, vi) (2) to happen (again); to begin (anew) (v5r, vi) (3) to date (from); to originate (in)", edictId: 1307500, alternativeSpellingsOrthographyInfoList: new List(), diff --git a/JL.Core/Anki/Mining.cs b/JL.Core/Anki/Mining.cs index 6f828c3c..77d35e54 100644 --- a/JL.Core/Anki/Mining.cs +++ b/JL.Core/Anki/Mining.cs @@ -159,8 +159,7 @@ public static async Task Mine(Dictionary miningParams) /// Value is the actual content of a mining field (e.g. if the field name is LocalTime, then it should contain the current time)
/// UserField is the name of the user's field in Anki (e.g. Expression)
/// - private static Dictionary ConvertFields(Dictionary userFields, - IReadOnlyDictionary miningParams) + private static Dictionary ConvertFields(Dictionary userFields, Dictionary miningParams) { Dictionary dict = new(); foreach ((string key, JLField value) in userFields) diff --git a/JL.Core/Dicts/CustomNameDict/CustomNameLoader.cs b/JL.Core/Dicts/CustomNameDict/CustomNameLoader.cs index 8ea6e420..c4e536be 100644 --- a/JL.Core/Dicts/CustomNameDict/CustomNameLoader.cs +++ b/JL.Core/Dicts/CustomNameDict/CustomNameLoader.cs @@ -42,7 +42,9 @@ internal static void Load(Dict dict, CancellationToken cancellationToken) public static void AddToDictionary(string spelling, string? reading, string nameType, Dictionary> customNameDictionary) { CustomNameRecord newNameRecord = new(spelling, reading, nameType); - if (customNameDictionary.TryGetValue(JapaneseUtils.KatakanaToHiragana(spelling), out IList? entry)) + + string spellingInHiragana = JapaneseUtils.KatakanaToHiragana(spelling); + if (customNameDictionary.TryGetValue(spellingInHiragana, out IList? entry)) { if (!entry.Contains(newNameRecord)) { @@ -52,8 +54,7 @@ public static void AddToDictionary(string spelling, string? reading, string name else { - customNameDictionary.Add(JapaneseUtils.KatakanaToHiragana(spelling), - new List { newNameRecord }); + customNameDictionary[spellingInHiragana] = new List { newNameRecord }; } } } diff --git a/JL.Core/Dicts/CustomWordDict/CustomWordLoader.cs b/JL.Core/Dicts/CustomWordDict/CustomWordLoader.cs index 67ba1869..9c43002c 100644 --- a/JL.Core/Dicts/CustomWordDict/CustomWordLoader.cs +++ b/JL.Core/Dicts/CustomWordDict/CustomWordLoader.cs @@ -126,7 +126,8 @@ public static void AddToDictionary(string[] spellings, string[]? readings, strin private static bool AddRecordToDictionary(string spelling, CustomWordRecord record, Dictionary> dictionary) { - if (dictionary.TryGetValue(JapaneseUtils.KatakanaToHiragana(spelling), out IList? result)) + string spellingInHiragana = JapaneseUtils.KatakanaToHiragana(spelling); + if (dictionary.TryGetValue(spellingInHiragana, out IList? result)) { if (result.Contains(record)) { @@ -137,8 +138,7 @@ private static bool AddRecordToDictionary(string spelling, CustomWordRecord reco } else { - dictionary.Add(JapaneseUtils.KatakanaToHiragana(spelling), - new List { record }); + dictionary[spellingInHiragana] = new List { record }; } return true; diff --git a/JL.Core/Dicts/CustomWordDict/CustomWordRecord.cs b/JL.Core/Dicts/CustomWordDict/CustomWordRecord.cs index 6f7ba5d4..e197394a 100644 --- a/JL.Core/Dicts/CustomWordDict/CustomWordRecord.cs +++ b/JL.Core/Dicts/CustomWordDict/CustomWordRecord.cs @@ -168,8 +168,8 @@ public override bool Equals(object? obj) CustomWordRecord customWordRecordObj = (CustomWordRecord)obj; return PrimarySpelling == customWordRecordObj.PrimarySpelling - && (customWordRecordObj.AlternativeSpellings?.SequenceEqual(AlternativeSpellings ?? Enumerable.Empty()) ?? AlternativeSpellings is null) - && (customWordRecordObj.Readings?.SequenceEqual(Readings ?? Enumerable.Empty()) ?? Readings is null) + && (customWordRecordObj.AlternativeSpellings?.SequenceEqual(AlternativeSpellings ?? Array.Empty()) ?? AlternativeSpellings is null) + && (customWordRecordObj.Readings?.SequenceEqual(Readings ?? Array.Empty()) ?? Readings is null) && customWordRecordObj.Definitions.SequenceEqual(Definitions) && customWordRecordObj.WordClasses.SequenceEqual(WordClasses); } diff --git a/JL.Core/Dicts/DictUtils.cs b/JL.Core/Dicts/DictUtils.cs index 0f9544e7..d254bec4 100644 --- a/JL.Core/Dicts/DictUtils.cs +++ b/JL.Core/Dicts/DictUtils.cs @@ -102,6 +102,8 @@ public static class DictUtils } }; + public static readonly Dictionary BuiltInDictTypeToDict = new(7); + public static readonly Dictionary JmdictEntities = new(254) { { "bra", "Brazilian" }, @@ -987,13 +989,37 @@ internal static async Task DeserializeDicts() dict.Priority = priority; ++priority; - if (dict.Type is DictType.ProfileCustomNameDictionary) - { - dict.Path = ProfileUtils.GetProfileCustomNameDictPath(ProfileUtils.CurrentProfile); - } - else if (dict.Type is DictType.ProfileCustomWordDictionary) + switch (dict.Type) { - dict.Path = ProfileUtils.GetProfileCustomWordDictPath(ProfileUtils.CurrentProfile); + case DictType.ProfileCustomNameDictionary: + dict.Path = ProfileUtils.GetProfileCustomNameDictPath(ProfileUtils.CurrentProfile); + BuiltInDictTypeToDict.Add(dict.Type, dict); + break; + + case DictType.ProfileCustomWordDictionary: + dict.Path = ProfileUtils.GetProfileCustomWordDictPath(ProfileUtils.CurrentProfile); + BuiltInDictTypeToDict.Add(dict.Type, dict); + break; + + case DictType.CustomNameDictionary: + BuiltInDictTypeToDict.Add(dict.Type, dict); + break; + + case DictType.CustomWordDictionary: + BuiltInDictTypeToDict.Add(dict.Type, dict); + break; + + case DictType.JMdict: + BuiltInDictTypeToDict.Add(dict.Type, dict); + break; + + case DictType.Kanjidic: + BuiltInDictTypeToDict.Add(dict.Type, dict); + break; + + case DictType.JMnedict: + BuiltInDictTypeToDict.Add(dict.Type, dict); + break; } dict.Path = Utils.GetPath(dict.Path); diff --git a/JL.Core/Dicts/EDICT/JMdict/JmdictRecordBuilder.cs b/JL.Core/Dicts/EDICT/JMdict/JmdictRecordBuilder.cs index 593868a6..d4660c16 100644 --- a/JL.Core/Dicts/EDICT/JMdict/JmdictRecordBuilder.cs +++ b/JL.Core/Dicts/EDICT/JMdict/JmdictRecordBuilder.cs @@ -227,9 +227,7 @@ public static void AddToDictionary(JmdictEntry entry, Dictionary 0) + if (i is 0 && allSpellingsWithoutSearchOnlyForms.Count is 0) { for (int j = 0; j < entry.KanjiElements.Count; j++) { @@ -246,7 +244,7 @@ public static void AddToDictionary(JmdictEntry entry, Dictionary { jmdictRecord }); + jmdictDictionary[key] = new List { jmdictRecord }; } } } diff --git a/JL.Core/Dicts/EDICT/JMnedict/JmnedictRecordBuilder.cs b/JL.Core/Dicts/EDICT/JMnedict/JmnedictRecordBuilder.cs index b2e87cef..14439da9 100644 --- a/JL.Core/Dicts/EDICT/JMnedict/JmnedictRecordBuilder.cs +++ b/JL.Core/Dicts/EDICT/JMnedict/JmnedictRecordBuilder.cs @@ -78,7 +78,7 @@ public static void AddToDictionary(JmnedictEntry entry, Dictionary { jmnedictRecord }); + jmnedictDictionary[key] = new List { jmnedictRecord }; } } } diff --git a/JL.Core/Dicts/EDICT/KANJIDIC/KanjidicLoader.cs b/JL.Core/Dicts/EDICT/KANJIDIC/KanjidicLoader.cs index e18fc150..170cecc5 100644 --- a/JL.Core/Dicts/EDICT/KANJIDIC/KanjidicLoader.cs +++ b/JL.Core/Dicts/EDICT/KANJIDIC/KanjidicLoader.cs @@ -25,11 +25,6 @@ public static async Task Load(Dict dict) } } - foreach ((string key, IList recordList) in dict.Contents) - { - dict.Contents[key] = recordList.ToArray(); - } - dict.Contents.TrimExcess(); } @@ -55,7 +50,7 @@ public static async Task Load(Dict dict) private static async Task ReadCharacter(XmlReader xmlReader, Dictionary> kanjidicDictionary) { - string key = await xmlReader.ReadElementContentAsStringAsync().ConfigureAwait(false); + string key = (await xmlReader.ReadElementContentAsStringAsync().ConfigureAwait(false)).GetPooledString(); int grade = -1; int strokeCount = 0; @@ -142,6 +137,6 @@ private static async Task ReadCharacter(XmlReader xmlReader, Dictionary { entry }); + kanjidicDictionary[key] = new IDictRecord[] { entry }; } } diff --git a/JL.Core/Dicts/EDICT/ResourceUpdater.cs b/JL.Core/Dicts/EDICT/ResourceUpdater.cs index d0540553..3c7df073 100644 --- a/JL.Core/Dicts/EDICT/ResourceUpdater.cs +++ b/JL.Core/Dicts/EDICT/ResourceUpdater.cs @@ -106,7 +106,7 @@ public static async Task UpdateJmdict() { DictUtils.UpdatingJmdict = true; - Dict dict = DictUtils.Dicts.Values.First(static dict => dict.Type is DictType.JMdict); + Dict dict = DictUtils.BuiltInDictTypeToDict[DictType.JMdict]; bool downloaded = await UpdateResource(dict.Path, DictUtils.s_jmdictUrl, DictType.JMdict.ToString(), true, false) @@ -141,7 +141,7 @@ public static async Task UpdateJmnedict() { DictUtils.UpdatingJmnedict = true; - Dict dict = DictUtils.Dicts.Values.First(static dict => dict.Type is DictType.JMnedict); + Dict dict = DictUtils.BuiltInDictTypeToDict[DictType.JMnedict]; bool downloaded = await UpdateResource(dict.Path, DictUtils.s_jmnedictUrl, DictType.JMnedict.ToString(), true, false) @@ -170,7 +170,7 @@ public static async Task UpdateKanjidic() { DictUtils.UpdatingKanjidic = true; - Dict dict = DictUtils.Dicts.Values.First(static dict => dict.Type is DictType.Kanjidic); + Dict dict = DictUtils.BuiltInDictTypeToDict[DictType.Kanjidic]; bool downloaded = await UpdateResource(dict.Path, DictUtils.s_kanjidicUrl, DictType.Kanjidic.ToString(), true, false) diff --git a/JL.Core/Dicts/EPWING/EpwingNazeka/EpwingNazekaLoader.cs b/JL.Core/Dicts/EPWING/EpwingNazeka/EpwingNazekaLoader.cs index 34355f92..586fbe08 100644 --- a/JL.Core/Dicts/EPWING/EpwingNazeka/EpwingNazekaLoader.cs +++ b/JL.Core/Dicts/EPWING/EpwingNazeka/EpwingNazekaLoader.cs @@ -125,13 +125,14 @@ public static async Task Load(Dict dict) private static void AddRecordToDictionary(string key, EpwingNazekaRecord record, Dictionary> dictionary) { - if (dictionary.TryGetValue(JapaneseUtils.KatakanaToHiragana(key).GetPooledString(), out IList? result)) + string keyInHiragana = JapaneseUtils.KatakanaToHiragana(key).GetPooledString(); + if (dictionary.TryGetValue(keyInHiragana, out IList? result)) { result.Add(record); } else { - dictionary.Add(key, new List { record }); + dictionary[keyInHiragana] = new List { record }; } } } diff --git a/JL.Core/Dicts/EPWING/EpwingYomichan/EpwingYomichanLoader.cs b/JL.Core/Dicts/EPWING/EpwingYomichan/EpwingYomichanLoader.cs index 2bd80e57..301f628a 100644 --- a/JL.Core/Dicts/EPWING/EpwingYomichan/EpwingYomichanLoader.cs +++ b/JL.Core/Dicts/EPWING/EpwingYomichan/EpwingYomichanLoader.cs @@ -63,7 +63,7 @@ private static void AddToDictionary(IEpwingRecord yomichanRecord, Dict dict) } else { - dict.Contents.Add(hiraganaExpression, new List { yomichanRecord }); + dict.Contents[hiraganaExpression] = new List { yomichanRecord }; } if (dict.Type is not DictType.NonspecificNameYomichan && !string.IsNullOrEmpty(yomichanRecord.Reading)) @@ -76,7 +76,7 @@ private static void AddToDictionary(IEpwingRecord yomichanRecord, Dict dict) } else { - dict.Contents.Add(hiraganaReading, new List { yomichanRecord }); + dict.Contents[hiraganaReading] = new List { yomichanRecord }; } } } diff --git a/JL.Core/Dicts/EPWING/EpwingYomichan/EpwingYomichanRecord.cs b/JL.Core/Dicts/EPWING/EpwingYomichan/EpwingYomichanRecord.cs index 1bc237b9..aff43080 100644 --- a/JL.Core/Dicts/EPWING/EpwingYomichan/EpwingYomichanRecord.cs +++ b/JL.Core/Dicts/EPWING/EpwingYomichan/EpwingYomichanRecord.cs @@ -18,7 +18,7 @@ internal sealed class EpwingYomichanRecord : IEpwingRecord, IGetFrequency //public int Sequence { get; init; } //public string TermTags { get; init; } - public EpwingYomichanRecord(IReadOnlyList jsonElement) + public EpwingYomichanRecord(List jsonElement) { PrimarySpelling = jsonElement[0].ToString().GetPooledString(); Reading = jsonElement[1].ToString(); diff --git a/JL.Core/Dicts/YomichanKanji/YomichanKanjiLoader.cs b/JL.Core/Dicts/YomichanKanji/YomichanKanjiLoader.cs index 8c212fd1..13648f3f 100644 --- a/JL.Core/Dicts/YomichanKanji/YomichanKanjiLoader.cs +++ b/JL.Core/Dicts/YomichanKanji/YomichanKanjiLoader.cs @@ -43,7 +43,7 @@ public static async Task Load(Dict dict) } else { - dict.Contents.Add(kanji, new List { yomichanKanjiRecord }); + dict.Contents[kanji] = new List { yomichanKanjiRecord }; } } } diff --git a/JL.Core/Dicts/YomichanKanji/YomichanKanjiRecord.cs b/JL.Core/Dicts/YomichanKanji/YomichanKanjiRecord.cs index 3331a60d..572ff748 100644 --- a/JL.Core/Dicts/YomichanKanji/YomichanKanjiRecord.cs +++ b/JL.Core/Dicts/YomichanKanji/YomichanKanjiRecord.cs @@ -14,7 +14,7 @@ internal sealed class YomichanKanjiRecord : IDictRecord private string[]? Definitions { get; } private string[]? Stats { get; } - public YomichanKanjiRecord(IReadOnlyList jsonElement) + public YomichanKanjiRecord(List jsonElement) { OnReadings = jsonElement[1].ToString().Split(' ', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); if (OnReadings.Length is 0) diff --git a/JL.Core/Freqs/FrequencyNazeka/FrequencyNazekaLoader.cs b/JL.Core/Freqs/FrequencyNazeka/FrequencyNazekaLoader.cs index c50d6f12..c5a0a912 100644 --- a/JL.Core/Freqs/FrequencyNazeka/FrequencyNazekaLoader.cs +++ b/JL.Core/Freqs/FrequencyNazeka/FrequencyNazekaLoader.cs @@ -37,15 +37,12 @@ public static async Task Load(Freq freq) { readingFreqResult.Add(new FrequencyRecord(exactSpelling, frequencyRank)); } - else { - freqDict.Add(reading.GetPooledString(), - new List { new(exactSpelling, frequencyRank) }); + freqDict[reading.GetPooledString()] = new List { new(exactSpelling, frequencyRank) }; } string exactSpellingInHiragana = JapaneseUtils.KatakanaToHiragana(exactSpelling).GetPooledString(); - if (exactSpellingInHiragana != reading) { if (freqDict.TryGetValue(exactSpellingInHiragana, out IList? exactSpellingFreqResult)) @@ -55,8 +52,7 @@ public static async Task Load(Freq freq) else { - freqDict.Add(exactSpellingInHiragana, - new List { new(reading, frequencyRank) }); + freqDict[exactSpellingInHiragana] = new List { new(reading, frequencyRank) }; } } } diff --git a/JL.Core/Freqs/FrequencyYomichan/FrequencyYomichanLoader.cs b/JL.Core/Freqs/FrequencyYomichan/FrequencyYomichanLoader.cs index 3767ab1f..95364889 100644 --- a/JL.Core/Freqs/FrequencyYomichan/FrequencyYomichanLoader.cs +++ b/JL.Core/Freqs/FrequencyYomichan/FrequencyYomichanLoader.cs @@ -78,7 +78,7 @@ public static async Task Load(Freq freq) else { - freqDict.Add(spellingInHiragana, new List { new(spelling, frequency) }); + freqDict[spellingInHiragana] = new List { new(spelling, frequency) }; } } @@ -92,7 +92,7 @@ public static async Task Load(Freq freq) else { - freqDict.Add(readingInHiragana, new List { new(spelling, frequency) }); + freqDict[readingInHiragana] = new List { new(spelling, frequency) }; } if (reading != spelling) @@ -104,7 +104,7 @@ public static async Task Load(Freq freq) else { - freqDict.Add(spellingInHiragana, new List { new(reading, frequency) }); + freqDict[spellingInHiragana] = new List { new(reading, frequency) }; } } } diff --git a/JL.Core/Lookup/LookupResult.cs b/JL.Core/Lookup/LookupResult.cs index 32fb1b94..486c02d3 100644 --- a/JL.Core/Lookup/LookupResult.cs +++ b/JL.Core/Lookup/LookupResult.cs @@ -11,7 +11,7 @@ public sealed class LookupResult public Dict Dict { get; } public string PrimarySpelling { get; init; } - public IList? Readings { get; init; } + public string[]? Readings { get; init; } public string? FormattedDefinitions { get; init; } public int EdictId { get; init; } public string[]? AlternativeSpellings { get; init; } @@ -34,7 +34,7 @@ internal LookupResult( string matchedText, string deconjugatedMatchedText, Dict dict, - IList? readings, + string[]? readings, List? frequencies = null, string[]? alternativeSpellings = null, string[]? primarySpellingOrthographyInfoList = null, diff --git a/JL.Core/Lookup/LookupUtils.cs b/JL.Core/Lookup/LookupUtils.cs index 862abfa9..d497b96e 100644 --- a/JL.Core/Lookup/LookupUtils.cs +++ b/JL.Core/Lookup/LookupUtils.cs @@ -256,14 +256,17 @@ public static class LookupUtils : null; } - private static List SortLookupResults(IReadOnlyCollection lookupResults) + private static List SortLookupResults(List lookupResults) { return lookupResults .OrderByDescending(static lookupResult => lookupResult.MatchedText.Length) .ThenByDescending(static lookupResult => lookupResult.PrimarySpelling == lookupResult.MatchedText) .ThenBy(static lookupResult => { - int index = lookupResult.Readings?.IndexOf(lookupResult.MatchedText) ?? -1; + int index = lookupResult.Readings is not null + ? Array.IndexOf(lookupResult.Readings, lookupResult.MatchedText) + : -1; + if (index is -1) { return 3; @@ -289,7 +292,10 @@ private static List SortLookupResults(IReadOnlyCollection lookupResult.Frequencies?.Count > 0 ? lookupResult.Frequencies[0].Freq : int.MaxValue) .ThenBy(static lookupResult => { - int index = lookupResult.Readings?.IndexOf(lookupResult.MatchedText) ?? -1; + int index = lookupResult.Readings is not null + ? Array.IndexOf(lookupResult.Readings, lookupResult.MatchedText) + : -1; + return index is not -1 ? index : int.MaxValue; @@ -515,8 +521,8 @@ private static (bool tryLongVowelConversion, int succAttempt) GetWordResultsHelp return (tryLongVowelConversion, succAttempt); } - private static Dictionary GetWordResults(IReadOnlyList textList, - IReadOnlyList textInHiraganaList, IReadOnlyList> deconjugationResultsList, Dict dict) + private static Dictionary GetWordResults(List textList, + List textInHiraganaList, List> deconjugationResultsList, Dict dict) { Dictionary results = new(); @@ -543,8 +549,7 @@ private static Dictionary GetWordResults(IReadOnlyLi return results; } - private static Dictionary GetNameResults(IReadOnlyList textList, - IReadOnlyList textInHiraganaList, Dict dict) + private static Dictionary GetNameResults(List textList, List textInHiraganaList, Dict dict) { Dictionary nameResults = new(); @@ -579,6 +584,10 @@ private static Dictionary GetKanjiResults(string tex private static ConcurrentQueue BuildJmdictResult( Dictionary jmdictResults) { + Dict dict = DictUtils.BuiltInDictTypeToDict[DictType.JMdict]; + bool showROrthographyInfo = dict.Options?.ROrthographyInfo?.Value ?? true; + bool showAOrthographyInfo = dict.Options?.AOrthographyInfo?.Value ?? true; + ConcurrentQueue results = new(); _ = Parallel.ForEach(jmdictResults.Values.ToList(), wordResult => @@ -586,55 +595,64 @@ private static ConcurrentQueue BuildJmdictResult( int resultsListCount = wordResult.Results.Count; for (int i = 0; i < resultsListCount; i++) { - int resultCount = wordResult.Results[i].Count; + List? rOrthographyInfoList = null; + int resultCount = wordResult.Results[i].Count; for (int j = 0; j < resultCount; j++) { JmdictRecord jMDictResult = (JmdictRecord)wordResult.Results[i][j]; string[]?[]? rLists = jMDictResult.ReadingsOrthographyInfo; - string[]?[]? aLists = jMDictResult.AlternativeSpellingsOrthographyInfo; - List rOrthographyInfoList = new(); - List aOrthographyInfoList = new(); - - for (int k = 0; k < rLists?.Length; k++) + if (showROrthographyInfo) { - StringBuilder formattedROrthographyInfo = new(); + rOrthographyInfoList = new List(); - string[]? rList = rLists[k]; - if (rList?.Length > 0) + for (int k = 0; k < rLists?.Length; k++) { - for (int l = 0; l < rList.Length; l++) + StringBuilder formattedROrthographyInfo = new(); + + string[]? rList = rLists[k]; + if (rList?.Length > 0) { - _ = formattedROrthographyInfo.Append(CultureInfo.InvariantCulture, $"{rList[l]}, "); - } + for (int l = 0; l < rList.Length; l++) + { + _ = formattedROrthographyInfo.Append(CultureInfo.InvariantCulture, $"{rList[l]}, "); + } - rOrthographyInfoList.Add(formattedROrthographyInfo.Remove(formattedROrthographyInfo.Length - 2, 2).ToString()); - } - else - { - rOrthographyInfoList.Add(null); + rOrthographyInfoList.Add(formattedROrthographyInfo.Remove(formattedROrthographyInfo.Length - 2, 2).ToString()); + } + else + { + rOrthographyInfoList.Add(null); + } } } - for (int k = 0; k < aLists?.Length; k++) + string[]?[]? aLists = jMDictResult.AlternativeSpellingsOrthographyInfo; + List? aOrthographyInfoList = null; + if (showAOrthographyInfo) { - StringBuilder formattedAOrthographyInfo = new(); + aOrthographyInfoList = new List(); - string[]? aList = aLists[k]; - if (aList?.Length > 0) + for (int k = 0; k < aLists?.Length; k++) { - for (int l = 0; l < aList.Length; l++) + StringBuilder formattedAOrthographyInfo = new(); + + string[]? aList = aLists[k]; + if (aList?.Length > 0) { - _ = formattedAOrthographyInfo.Append(CultureInfo.InvariantCulture, $"{aList[l]}, "); - } + for (int l = 0; l < aList.Length; l++) + { + _ = formattedAOrthographyInfo.Append(CultureInfo.InvariantCulture, $"{aList[l]}, "); + } - aOrthographyInfoList.Add(formattedAOrthographyInfo.Remove(formattedAOrthographyInfo.Length - 2, 2).ToString()); - } + aOrthographyInfoList.Add(formattedAOrthographyInfo.Remove(formattedAOrthographyInfo.Length - 2, 2).ToString()); + } - else - { - aOrthographyInfoList.Add(null); + else + { + aOrthographyInfoList.Add(null); + } } } @@ -713,22 +731,7 @@ private static List BuildKanjidicResult(Dictionary> iResult = dictResult.Value.Results; KanjidicRecord kanjiRecord = (KanjidicRecord)iResult[0][0]; - List allReadings = new(); - - if (kanjiRecord.OnReadings is not null) - { - allReadings.AddRange(kanjiRecord.OnReadings); - } - - if (kanjiRecord.KunReadings is not null) - { - allReadings.AddRange(kanjiRecord.KunReadings); - } - - if (kanjiRecord.NanoriReadings is not null) - { - allReadings.AddRange(kanjiRecord.NanoriReadings); - } + string[]? allReadings = Utils.ConcatNullableArrays(kanjiRecord.OnReadings, kanjiRecord.KunReadings, kanjiRecord.NanoriReadings); IntermediaryResult intermediaryResult = kanjiResults.First().Value; @@ -769,17 +772,7 @@ private static ConcurrentQueue BuildYomichanKanjiResult( { YomichanKanjiRecord yomichanKanjiDictResult = (YomichanKanjiRecord)kanjiResult.Value.Results[i][j]; - List allReadings = new(); - - if (yomichanKanjiDictResult.OnReadings is not null) - { - allReadings.AddRange(yomichanKanjiDictResult.OnReadings); - } - - if (yomichanKanjiDictResult.KunReadings is not null) - { - allReadings.AddRange(yomichanKanjiDictResult.KunReadings); - } + string[]? allReadings = Utils.ConcatNullableArrays(yomichanKanjiDictResult.OnReadings, yomichanKanjiDictResult.KunReadings); LookupResult result = new ( @@ -827,7 +820,7 @@ private static ConcurrentQueue BuildEpwingYomichanResult( frequencies: GetWordFrequencies(epwingResult), dict: wordResult.Dict, readings: epwingResult.Reading is not null - ? new List { epwingResult.Reading } + ? new[] { epwingResult.Reading } : null, formattedDefinitions: epwingResult.BuildFormattedDefinition(wordResult.Dict.Options) ); @@ -865,7 +858,7 @@ private static ConcurrentQueue BuildEpwingNazekaResult( frequencies: GetWordFrequencies(epwingResult), dict: wordResult.Dict, readings: epwingResult.Reading is not null - ? new List { epwingResult.Reading } + ? new[] { epwingResult.Reading } : null, formattedDefinitions: epwingResult.BuildFormattedDefinition(wordResult.Dict.Options) ); @@ -952,7 +945,7 @@ private static ConcurrentQueue BuildCustomNameResult( frequencies: new List { new(customNameResult.Value.Dict.Name, -freq) }, dict: customNameResult.Value.Dict, readings: customNameDictResult.Reading is not null - ? new List { customNameDictResult.Reading } + ? new[] { customNameDictResult.Reading } : null, formattedDefinitions: customNameDictResult.BuildFormattedDefinition() ); @@ -1016,7 +1009,7 @@ private static List GetKanjidicFrequencies(string kanji, return freqsList; } - private static string? ProcessProcess(IReadOnlyList>? processList) + private static string? ProcessProcess(List>? processList) { StringBuilder deconjugation = new(); bool first = true; diff --git a/JL.Core/PitchAccent/PitchAccentRecord.cs b/JL.Core/PitchAccent/PitchAccentRecord.cs index fa1d2f2b..bd7b5b4a 100644 --- a/JL.Core/PitchAccent/PitchAccentRecord.cs +++ b/JL.Core/PitchAccent/PitchAccentRecord.cs @@ -13,7 +13,7 @@ public sealed class PitchAccentRecord : IDictRecord private static readonly Regex s_positionRegex = new("@\"(\\[|[)(\\d)(]|\\])", RegexOptions.Compiled); - internal PitchAccentRecord(IReadOnlyList jsonObject) + internal PitchAccentRecord(List jsonObject) { Spelling = jsonObject[0].ToString().GetPooledString(); diff --git a/JL.Core/Utilities/Utils.cs b/JL.Core/Utilities/Utils.cs index 78e22a9f..aba48178 100644 --- a/JL.Core/Utilities/Utils.cs +++ b/JL.Core/Utilities/Utils.cs @@ -181,4 +181,37 @@ public static string GetPath(string path) string relativePath = Path.GetRelativePath(ApplicationPath, fullPath); return relativePath.StartsWith('.') ? fullPath : relativePath; } + + internal static T[]? ConcatNullableArrays(params T[]?[] arrays) + { + int position = 0; + int length = 0; + + for (int i = 0; i < arrays.Length; i++) + { + T[]? array = arrays[i]; + if (array is not null) + { + length += array.Length; + } + } + + if (length is 0) + { + return null; + } + + T[] concatArray = new T[length]; + for (int i = 0; i < arrays.Length; i++) + { + T[]? array = arrays[i]; + if (array is not null) + { + Array.Copy(array, 0, concatArray, position, array.Length); + position += array.Length; + } + } + + return concatArray; + } } diff --git a/JL.Core/WordClass/JmdictWordClassUtils.cs b/JL.Core/WordClass/JmdictWordClassUtils.cs index 6fb37dd9..0be15b24 100644 --- a/JL.Core/WordClass/JmdictWordClassUtils.cs +++ b/JL.Core/WordClass/JmdictWordClassUtils.cs @@ -32,15 +32,13 @@ public static async Task Load() for (int j = 0; j < jmdictWordClass.Readings.Length; j++) { string readingInHiragana = JapaneseUtils.KatakanaToHiragana(jmdictWordClass.Readings[j]).GetPooledString(); - if (DictUtils.WordClassDictionary.TryGetValue(readingInHiragana, out IList? result)) { result.Add(jmdictWordClass); } - else { - DictUtils.WordClassDictionary.Add(readingInHiragana, new List { jmdictWordClass }); + DictUtils.WordClassDictionary[readingInHiragana] = new List { jmdictWordClass }; } } } @@ -65,7 +63,8 @@ public static async Task Serialize() "v5n", "v5r", "v5r-i", "v5s", "v5t", "v5u", "v5u-s", "vk", "vs-c", "vs-i", "vs-s", "vz" }; - foreach (IList jmdictRecordList in DictUtils.Dicts.Values.First(static dict => dict.Type is DictType.JMdict).Contents.Values.ToList()) + Dict dict = DictUtils.BuiltInDictTypeToDict[DictType.JMdict]; + foreach (IList jmdictRecordList in dict.Contents.Values.ToList()) { int jmdictRecordListCount = jmdictRecordList.Count; for (int i = 0; i < jmdictRecordListCount; i++) @@ -82,7 +81,7 @@ public static async Task Serialize() if (jmdictWordClassDictionary.TryGetValue(value.PrimarySpelling, out List? psr)) { if (!psr.Any(r => - r.Readings?.SequenceEqual(value.Readings ?? Enumerable.Empty()) ?? + r.Readings?.SequenceEqual(value.Readings ?? Array.Empty()) ?? (value.Readings is null && r.Spelling == value.PrimarySpelling))) { psr.Add(new JmdictWordClass(value.PrimarySpelling, value.Readings, wordClasses)); @@ -91,8 +90,7 @@ public static async Task Serialize() else { - jmdictWordClassDictionary.Add(value.PrimarySpelling, - new List { new(value.PrimarySpelling, value.Readings, wordClasses) }); + jmdictWordClassDictionary[value.PrimarySpelling] = new List { new(value.PrimarySpelling, value.Readings, wordClasses) }; } if (value.AlternativeSpellings is not null) @@ -104,7 +102,7 @@ public static async Task Serialize() if (jmdictWordClassDictionary.TryGetValue(spelling, out List? asr)) { if (!asr.Any(r => - r.Readings?.SequenceEqual(value.Readings ?? Enumerable.Empty()) ?? + r.Readings?.SequenceEqual(value.Readings ?? Array.Empty()) ?? (value.Readings is null && r.Spelling == spelling))) { asr.Add(new JmdictWordClass(spelling, value.Readings, wordClasses)); @@ -113,8 +111,7 @@ public static async Task Serialize() else { - jmdictWordClassDictionary.Add(spelling, - new List { new(spelling, value.Readings, wordClasses) }); + jmdictWordClassDictionary[spelling] = new List { new(spelling, value.Readings, wordClasses) }; } } } @@ -127,9 +124,9 @@ await File.WriteAllTextAsync(Path.Join(Utils.ResourcesPath, "PoS.json"), internal static async Task Initialize() { - Dict dict = DictUtils.Dicts.Values.First(static dict => dict.Type is DictType.JMdict); if (!File.Exists(Path.Join(Utils.ResourcesPath, "PoS.json"))) { + Dict dict = DictUtils.BuiltInDictTypeToDict[DictType.JMdict]; if (dict.Active) { await Serialize().ConfigureAwait(false); diff --git a/JL.Windows/DictOptionManager.cs b/JL.Windows/DictOptionManager.cs index 0c0dcf13..a1651f9f 100644 --- a/JL.Windows/DictOptionManager.cs +++ b/JL.Windows/DictOptionManager.cs @@ -12,11 +12,10 @@ internal static class DictOptionManager public static void ApplyDictOptions() { - Dict? jmdict = DictUtils.Dicts.Values.FirstOrDefault(static dict => dict.Type is DictType.JMdict); - if (jmdict is not null) + if (DictUtils.BuiltInDictTypeToDict.TryGetValue(DictType.JMdict, out Dict? jmdict)) { - POrthographyInfoColor = WindowsUtils.FrozenBrushFromHex(jmdict.Options?.POrthographyInfoColor?.Value - ?? ConfigManager.PrimarySpellingColor.ToString(CultureInfo.InvariantCulture))!; + POrthographyInfoColor = WindowsUtils.FrozenBrushFromHex( + jmdict.Options?.POrthographyInfoColor?.Value ?? ConfigManager.PrimarySpellingColor.ToString(CultureInfo.InvariantCulture))!; } else diff --git a/JL.Windows/GUI/AddDictionaryWindow.xaml.cs b/JL.Windows/GUI/AddDictionaryWindow.xaml.cs index 43548c56..448d81a5 100644 --- a/JL.Windows/GUI/AddDictionaryWindow.xaml.cs +++ b/JL.Windows/GUI/AddDictionaryWindow.xaml.cs @@ -141,7 +141,7 @@ private void RadioButtonNazekaEpwingConverter_OnClick(object sender, RoutedEvent FillDictTypesCombobox(DictUtils.NazekaDictTypes); } - private void FillDictTypesCombobox(IEnumerable types) + private void FillDictTypesCombobox(DictType[] types) { IEnumerable loadedDictTypes = DictUtils.Dicts.Values.Select(static dict => dict.Type); IEnumerable validTypes = types.Except(loadedDictTypes.Except(DictUtils.NonspecificDictTypes)); diff --git a/JL.Windows/GUI/MainWindow.xaml.cs b/JL.Windows/GUI/MainWindow.xaml.cs index 025f4457..9e184da5 100644 --- a/JL.Windows/GUI/MainWindow.xaml.cs +++ b/JL.Windows/GUI/MainWindow.xaml.cs @@ -887,9 +887,9 @@ private void ShowAddNameWindow() if (text is not null && FirstPopupWindow.LastSelectedText is not null && text == FirstPopupWindow.LastSelectedText) { - IList? readingList = FirstPopupWindow.LastLookupResults[0].Readings; - reading = readingList is { Count: 1 } - ? readingList[0] + string[]? readings = FirstPopupWindow.LastLookupResults[0].Readings; + reading = readings is { Length: 1 } + ? readings[0] : ""; } diff --git a/JL.Windows/GUI/PopupWindow.xaml.cs b/JL.Windows/GUI/PopupWindow.xaml.cs index ef75ea7a..7d008166 100644 --- a/JL.Windows/GUI/PopupWindow.xaml.cs +++ b/JL.Windows/GUI/PopupWindow.xaml.cs @@ -61,6 +61,8 @@ internal sealed partial class PopupWindow : Window public static LRUCache StackPanelCache { get; } = new( Utils.CacheSize, Utils.CacheSize / 8); + private ScrollViewer? _popupListViewScrollViewer; + public PopupWindow() { InitializeComponent(); @@ -71,6 +73,7 @@ protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); WindowHandle = new WindowInteropHelper(this).Handle; + _popupListViewScrollViewer = PopupListView.GetChildOfType(); } protected override void OnActivated(EventArgs e) @@ -1312,16 +1315,16 @@ private async void PrimarySpelling_PreviewMouseUp(object sender, MouseButtonEven private void ShowAddNameWindow() { string text; - string readings = ""; + string reading = ""; if (ChildPopupWindow?._lastTextBox?.SelectionLength > 0) { text = ChildPopupWindow._lastTextBox.SelectedText; if (text == ChildPopupWindow.LastSelectedText) { - IList? readingList = ChildPopupWindow.LastLookupResults[0].Readings; - readings = readingList is { Count: 1 } - ? readingList[0] + string[]? readings = ChildPopupWindow.LastLookupResults[0].Readings; + reading = readings is { Length: 1 } + ? readings[0] : ""; } } @@ -1330,18 +1333,18 @@ private void ShowAddNameWindow() int index = MiningMode ? _listBoxIndex : 0; text = LastLookupResults[index].PrimarySpelling; - IList? readingList = LastLookupResults[index].Readings; - readings = readingList is { Count: 1 } - ? readingList[0] + string[]? readings = LastLookupResults[index].Readings; + reading = readings is { Length: 1 } + ? readings[0] : ""; } - if (readings == text) + if (reading == text) { - readings = ""; + reading = ""; } - WindowsUtils.ShowAddNameWindow(text, readings); + WindowsUtils.ShowAddNameWindow(text, reading); } private async void Window_KeyDown(object sender, KeyEventArgs e) @@ -1962,12 +1965,6 @@ private void Window_PreviewMouseDown(object sender, MouseButtonEventArgs e) public void HidePopup() { - if (PopupListView.Items.Count > 0) - { - PopupListView.ScrollIntoView(PopupListView.Items.GetItemAt(0)); - PopupListView.UpdateLayout(); - } - MainWindow mainWindow = MainWindow.Instance; bool isFirstPopup = Owner == mainWindow; @@ -1987,6 +1984,12 @@ public void HidePopup() ItemsControlButtons.Visibility = Visibility.Collapsed; ItemsControlButtons.ItemsSource = null; + if (_popupListViewScrollViewer is not null) + { + _popupListViewScrollViewer.ScrollToTop(); + PopupListView.UpdateLayout(); + } + PopupListView.ItemsSource = null; LastText = ""; PopupAutoHideTimer.Stop(); diff --git a/JL.Windows/GUI/PreferencesWindow.xaml.cs b/JL.Windows/GUI/PreferencesWindow.xaml.cs index eb589253..8aa58c85 100644 --- a/JL.Windows/GUI/PreferencesWindow.xaml.cs +++ b/JL.Windows/GUI/PreferencesWindow.xaml.cs @@ -35,8 +35,8 @@ public PreferencesWindow() { InitializeComponent(); _profileName = ProfileUtils.CurrentProfile; - _profileNamesDict = DictUtils.Dicts.Values.First(static dict => dict.Type is DictType.ProfileCustomNameDictionary); - _profileWordsDict = DictUtils.Dicts.Values.First(static dict => dict.Type is DictType.ProfileCustomWordDictionary); + _profileNamesDict = DictUtils.BuiltInDictTypeToDict[DictType.ProfileCustomNameDictionary]; + _profileWordsDict = DictUtils.BuiltInDictTypeToDict[DictType.ProfileCustomWordDictionary]; } public static bool IsItVisible() @@ -203,15 +203,15 @@ private async Task SetPreviousMiningConfig() if (otherAnkiConfig is not null) { SetPreviousMiningConfig(OtherMiningSetupComboBoxDeckNames, OtherMiningSetupComboBoxModelNames, OtherTagsTextBox, otherAnkiConfig); - CreateFieldElements(otherAnkiConfig.Fields, Enum.GetValues().ToList(), OtherMiningSetupStackPanelFields); + CreateFieldElements(otherAnkiConfig.Fields, Enum.GetValues(), OtherMiningSetupStackPanelFields); } } private static void SetPreviousMiningConfig(Selector deckNamesSelector, Selector modelNamesComboBox, TextBox tagTextBox, AnkiConfig ankiConfig) { - deckNamesSelector.ItemsSource = new List { ankiConfig.DeckName }; + deckNamesSelector.ItemsSource = new[] { ankiConfig.DeckName }; deckNamesSelector.SelectedItem = ankiConfig.DeckName; - modelNamesComboBox.ItemsSource = new List { ankiConfig.ModelName }; + modelNamesComboBox.ItemsSource = new[] { ankiConfig.ModelName }; modelNamesComboBox.SelectedItem = ankiConfig.ModelName; tagTextBox.Text = string.Join(", ", ankiConfig.Tags); } @@ -256,7 +256,7 @@ private async void MiningSetupButtonRefresh_Click(object sender, RoutedEventArgs await PopulateDeckAndModelNames().ConfigureAwait(false); } - private static async Task GetFields(ComboBox modelNamesComboBox, Panel miningPanel, IEnumerable fieldList) + private static async Task GetFields(ComboBox modelNamesComboBox, Panel miningPanel, JLField[] fieldList) { string modelName = modelNamesComboBox.SelectionBoxItem.ToString()!; @@ -297,7 +297,7 @@ private async void OtherMiningSetupButtonGetFields_Click(object sender, RoutedEv await GetFields(OtherMiningSetupComboBoxModelNames, OtherMiningSetupStackPanelFields, JLFieldUtils.JLFieldsForWordDicts).ConfigureAwait(false); } - private static void CreateFieldElements(Dictionary fields, IEnumerable fieldList, Panel fieldPanel) + private static void CreateFieldElements(Dictionary fields, JLField[] fieldList, Panel fieldPanel) { fieldPanel.Children.Clear(); @@ -320,7 +320,7 @@ private static void CreateFieldElements(Dictionary fields, IEnu } } - private static AnkiConfig? GetAnkiConfigFromPreferences(Selector deckNamesSelector, Selector modelNamesSelector, Panel miningPanel, TextBox tagsTextBox, IReadOnlyCollection jlFieldList, MineType mineType) + private static AnkiConfig? GetAnkiConfigFromPreferences(Selector deckNamesSelector, Selector modelNamesSelector, Panel miningPanel, TextBox tagsTextBox, JLField[] jlFieldList, MineType mineType) { if (deckNamesSelector.SelectedItem is null || modelNamesSelector.SelectedItem is null) diff --git a/JL.Windows/Utilities/ExtensionMethods.cs b/JL.Windows/Utilities/ExtensionMethods.cs index e2241ee6..5c75986f 100644 --- a/JL.Windows/Utilities/ExtensionMethods.cs +++ b/JL.Windows/Utilities/ExtensionMethods.cs @@ -1,4 +1,6 @@ using System.Configuration; +using System.Windows; +using System.Windows.Media; namespace JL.Windows.Utilities; internal static class ExtensionMethods @@ -8,28 +10,24 @@ internal static class ExtensionMethods return configurationCollection[key]?.Value ?? null; } - //public static T? GetChildOfType(this DependencyObject dependencyObject) where T : DependencyObject - //{ - // for (int i = 0; i < VisualTreeHelper.GetChildrenCount(dependencyObject); i++) - // { - // DependencyObject child = VisualTreeHelper.GetChild(dependencyObject, i); - - // if (child is T result) - // { - // return result; - // } - - // if (child is not null) - // { - // T? grandChild = GetChildOfType(child); + public static T? GetChildOfType(this DependencyObject dependencyObject) where T : DependencyObject + { + int childrenCount = VisualTreeHelper.GetChildrenCount(dependencyObject); + for (int i = 0; i < childrenCount; i++) + { + DependencyObject child = VisualTreeHelper.GetChild(dependencyObject, i); + if (child is T result) + { + return result; + } - // if (grandChild is not null) - // { - // return grandChild; - // } - // } - // } + T? grandChild = GetChildOfType(child); + if (grandChild is not null) + { + return grandChild; + } + } - // return null; - //} + return null; + } } diff --git a/JL.Windows/Utilities/PopupWindowUtils.cs b/JL.Windows/Utilities/PopupWindowUtils.cs index 69471ee6..5bb5071c 100644 --- a/JL.Windows/Utilities/PopupWindowUtils.cs +++ b/JL.Windows/Utilities/PopupWindowUtils.cs @@ -58,11 +58,11 @@ public static string GradeToText(int grade) return null; } - public static string ReadingsToText(IList readings, IReadOnlyList rOrthographyInfoList) + public static string ReadingsToText(string[] readings, List rOrthographyInfoList) { StringBuilder sb = new(); - for (int index = 0; index < readings.Count; index++) + for (int index = 0; index < readings.Length; index++) { _ = sb.Append(readings[index]); @@ -74,7 +74,7 @@ public static string ReadingsToText(IList readings, IReadOnlyList readings, IReadOnlyList alternativeSpellings, IReadOnlyList aOrthographyInfoList) + public static string AlternativeSpellingsToText(string[] alternativeSpellings, List aOrthographyInfoList) { StringBuilder sb = new(); _ = sb.Append('('); - for (int index = 0; index < alternativeSpellings.Count; index++) + for (int index = 0; index < alternativeSpellings.Length; index++) { _ = sb.Append(alternativeSpellings[index]); @@ -101,7 +101,7 @@ public static string AlternativeSpellingsToText(IReadOnlyList alternativ } } - if (index != alternativeSpellings.Count - 1) + if (index != alternativeSpellings.Length - 1) { _ = sb.Append(", "); } @@ -112,22 +112,22 @@ public static string AlternativeSpellingsToText(IReadOnlyList alternativ return sb.ToString(); } - public static Grid CreatePitchAccentGrid(string primarySpelling, IReadOnlyList? alternativeSpellings, - IList? readings, string[] splitReadingsWithRInfo, double leftMargin, Dict dict) + public static Grid CreatePitchAccentGrid(string primarySpelling, string[]? alternativeSpellings, + string[]? readings, string[] splitReadingsWithRInfo, double leftMargin, Dict dict) { Grid pitchAccentGrid = new(); - bool hasReading = readings?.Count > 0; + bool hasReading = readings?.Length > 0; int fontSize = hasReading ? ConfigManager.ReadingsFontSize : ConfigManager.PrimarySpellingFontSize; - IList expressions = hasReading ? readings! : new List { primarySpelling }; + string[] expressions = hasReading ? readings! : new[] { primarySpelling }; double horizontalOffsetForReading = leftMargin; - for (int i = 0; i < expressions.Count; i++) + for (int i = 0; i < expressions.Length; i++) { string normalizedExpression = JapaneseUtils.KatakanaToHiragana(expressions[i]); List combinedFormList = JapaneseUtils.CreateCombinedForm(expressions[i]); diff --git a/JL.Windows/Utilities/WindowsUtils.cs b/JL.Windows/Utilities/WindowsUtils.cs index 567c4ac1..5448c232 100644 --- a/JL.Windows/Utilities/WindowsUtils.cs +++ b/JL.Windows/Utilities/WindowsUtils.cs @@ -48,7 +48,7 @@ internal static class WindowsUtils public static double DpiAwareFixedPopupXPosition { get; set; } = ConfigManager.FixedPopupXPosition / Dpi.DpiScaleX; public static double DpiAwareFixedPopupYPosition { get; set; } = ConfigManager.FixedPopupYPosition / Dpi.DpiScaleY; - public static IEnumerable FindJapaneseFonts() + public static List FindJapaneseFonts() { List japaneseFonts = new();