diff --git a/JL.Core/Lookup/LookupUtils.cs b/JL.Core/Lookup/LookupUtils.cs index 0fc4361d..5b4b086c 100644 --- a/JL.Core/Lookup/LookupUtils.cs +++ b/JL.Core/Lookup/LookupUtils.cs @@ -1158,24 +1158,21 @@ private static List BuildJmnedictResult( private static List BuildKanjidicResult(IDictionary kanjiResults, bool useDBForPitchDict, Dict? pitchDict, List kanjiFreqs) { - KeyValuePair dictResult = kanjiResults.First(); + (string kanji, IntermediaryResult intermediaryResult) = kanjiResults.First(); Dictionary>? pitchAccentDict = useDBForPitchDict - ? YomichanPitchAccentDBManager.GetRecordsFromDB(pitchDict!.Name, dictResult.Key) + ? YomichanPitchAccentDBManager.GetRecordsFromDB(pitchDict!.Name, kanji) : null; - List> iResult = dictResult.Value.Results; - KanjidicRecord kanjiRecord = (KanjidicRecord)iResult[0][0]; + KanjidicRecord kanjiRecord = (KanjidicRecord)intermediaryResult.Results[0][0]; string[]? allReadings = Utils.ConcatNullableArrays(kanjiRecord.OnReadings, kanjiRecord.KunReadings, kanjiRecord.NanoriReadings); - IntermediaryResult intermediaryResult = kanjiResults.First().Value; - - _ = DictUtils.KanjiCompositionDict.TryGetValue(dictResult.Key, out string? kanjiComposition); + _ = DictUtils.KanjiCompositionDict.TryGetValue(kanji, out string? kanjiComposition); LookupResult result = new ( - primarySpelling: dictResult.Key, + primarySpelling: kanji, readings: allReadings, onReadings: kanjiRecord.OnReadings, kunReadings: kanjiRecord.KunReadings, @@ -1184,7 +1181,7 @@ private static List BuildKanjidicResult(IDictionary pitchAccent = pitchAccents[i]; - _ = expressionsWithPitchAccentBuilder.Append(GetExpressionWithPitchAccent(pitchAccent.Key, pitchAccent.Value)); + (string expression, byte position) = pitchAccents[i]; + _ = expressionsWithPitchAccentBuilder.Append(GetExpressionWithPitchAccent(expression, position)); if (i + 1 != pitchAccentCount) { @@ -305,8 +305,8 @@ public static class MiningUtils int pitchAccentCount = pitchAccents.Count; for (int i = 0; i < pitchAccentCount; i++) { - KeyValuePair pitchAccent = pitchAccents[i]; - _ = numericPitchAccentBuilder.Append(CultureInfo.InvariantCulture, $"{pitchAccent.Key}: {pitchAccent.Value}"); + (string expression, byte position) = pitchAccents[i]; + _ = numericPitchAccentBuilder.Append(CultureInfo.InvariantCulture, $"{expression}: {position}"); if (i + 1 != pitchAccentCount) { @@ -327,11 +327,11 @@ public static class MiningUtils List>? pitchAccents = GetPitchAccents(lookupResult.PitchAccentDict ?? pitchDict.Contents, lookupResult); if (pitchAccents is not null) { - KeyValuePair firstPitchAccentKeyValuePair = pitchAccents[0]; - if ((lookupResult.Readings is not null && firstPitchAccentKeyValuePair.Key == lookupResult.Readings[0]) - || (lookupResult.Readings is null && firstPitchAccentKeyValuePair.Key == lookupResult.PrimarySpelling)) + (string expression, byte position) = pitchAccents[0]; + if ((lookupResult.Readings is not null && expression == lookupResult.Readings[0]) + || (lookupResult.Readings is null && expression == lookupResult.PrimarySpelling)) { - return string.Create(CultureInfo.InvariantCulture, $"{PitchAccentStyle}\n\n{GetExpressionWithPitchAccent(firstPitchAccentKeyValuePair.Key, firstPitchAccentKeyValuePair.Value)}"); + return string.Create(CultureInfo.InvariantCulture, $"{PitchAccentStyle}\n\n{GetExpressionWithPitchAccent(expression, position)}"); } } } @@ -345,11 +345,11 @@ public static class MiningUtils List>? pitchAccents = GetPitchAccents(lookupResult.PitchAccentDict ?? pitchDict.Contents, lookupResult); if (pitchAccents is not null) { - KeyValuePair firstPitchAccentKeyValuePair = pitchAccents[0]; - if ((lookupResult.Readings is not null && firstPitchAccentKeyValuePair.Key == lookupResult.Readings[0]) - || (lookupResult.Readings is null && firstPitchAccentKeyValuePair.Key == lookupResult.PrimarySpelling)) + (string expression, byte position) = pitchAccents[0]; + if ((lookupResult.Readings is not null && expression == lookupResult.Readings[0]) + || (lookupResult.Readings is null && expression == lookupResult.PrimarySpelling)) { - return string.Create(CultureInfo.InvariantCulture, $"{firstPitchAccentKeyValuePair.Key}: {firstPitchAccentKeyValuePair.Value}"); + return string.Create(CultureInfo.InvariantCulture, $"{expression}: {position}"); } } } @@ -539,9 +539,9 @@ private static Dictionary GetMiningParameters(LookupResult look int pitchAccentCount = pitchAccents.Count; for (int i = 0; i < pitchAccentCount; i++) { - KeyValuePair pitchAccent = pitchAccents[i]; - _ = numericPitchAccentBuilder.Append(CultureInfo.InvariantCulture, $"{pitchAccent.Key}: {pitchAccent.Value}"); - _ = expressionsWithPitchAccentBuilder.Append(GetExpressionWithPitchAccent(pitchAccent.Key, pitchAccent.Value)); + (string expression, byte position) = pitchAccents[i]; + _ = numericPitchAccentBuilder.Append(CultureInfo.InvariantCulture, $"{expression}: {position}"); + _ = expressionsWithPitchAccentBuilder.Append(GetExpressionWithPitchAccent(expression, position)); if (i + 1 != pitchAccentCount) { @@ -553,12 +553,12 @@ private static Dictionary GetMiningParameters(LookupResult look miningParams[JLField.NumericPitchAccents] = numericPitchAccentBuilder.ToString(); miningParams[JLField.PitchAccents] = expressionsWithPitchAccentBuilder.ToString(); - KeyValuePair firstPitchAccentKeyValuePair = pitchAccents[0]; - if ((lookupResult.Readings is not null && firstPitchAccentKeyValuePair.Key == lookupResult.Readings[0]) - || (lookupResult.Readings is null && firstPitchAccentKeyValuePair.Key == lookupResult.PrimarySpelling)) + (string firstExpression, byte firstPosition) = pitchAccents[0]; + if ((lookupResult.Readings is not null && firstExpression == lookupResult.Readings[0]) + || (lookupResult.Readings is null && firstExpression == lookupResult.PrimarySpelling)) { - miningParams[JLField.PitchAccentForFirstReading] = string.Create(CultureInfo.InvariantCulture, $"{PitchAccentStyle}\n\n{GetExpressionWithPitchAccent(firstPitchAccentKeyValuePair.Key, firstPitchAccentKeyValuePair.Value)}"); - miningParams[JLField.NumericPitchAccentForFirstReading] = string.Create(CultureInfo.InvariantCulture, $"{firstPitchAccentKeyValuePair.Key}: {firstPitchAccentKeyValuePair.Value}"); + miningParams[JLField.PitchAccentForFirstReading] = string.Create(CultureInfo.InvariantCulture, $"{PitchAccentStyle}\n\n{GetExpressionWithPitchAccent(firstExpression, firstPosition)}"); + miningParams[JLField.NumericPitchAccentForFirstReading] = string.Create(CultureInfo.InvariantCulture, $"{firstExpression}: {firstPosition}"); } } } diff --git a/JL.Windows/GUI/ManageDictionariesWindow.xaml.cs b/JL.Windows/GUI/ManageDictionariesWindow.xaml.cs index 9677951a..c9de77d7 100644 --- a/JL.Windows/GUI/ManageDictionariesWindow.xaml.cs +++ b/JL.Windows/GUI/ManageDictionariesWindow.xaml.cs @@ -430,9 +430,9 @@ private static string EntityDictToString(Dictionary entityDict) StringBuilder sb = new(); IOrderedEnumerable> sortedJmdictEntities = entityDict.OrderBy(static e => e.Key, StringComparer.InvariantCulture); - foreach (KeyValuePair entity in sortedJmdictEntities) + foreach ((string name, string description) in sortedJmdictEntities) { - _ = sb.Append(CultureInfo.InvariantCulture, $"{entity.Key}: {entity.Value}\n"); + _ = sb.Append(CultureInfo.InvariantCulture, $"{name}: {description}\n"); } return sb.ToString(0, sb.Length - 1); diff --git a/JL.Windows/WinApi.cs b/JL.Windows/WinApi.cs index e9af81d4..72ab1ed0 100644 --- a/JL.Windows/WinApi.cs +++ b/JL.Windows/WinApi.cs @@ -208,9 +208,9 @@ public static void AddHotKeyToGlobalKeyGestureDict(string hotkeyName, KeyGesture public static void RegisterAllGlobalHotKeys(nint windowHandle) { - foreach (KeyValuePair keyValuePair in KeyGestureUtils.GlobalKeyGestureDict) + foreach ((int id, KeyGesture keyGesture) in KeyGestureUtils.GlobalKeyGestureDict) { - _ = RegisterHotKey(windowHandle, keyValuePair.Key, (uint)keyValuePair.Value.Modifiers | MOD_NOREPEAT, (uint)KeyInterop.VirtualKeyFromKey(keyValuePair.Value.Key)); + _ = RegisterHotKey(windowHandle, id, (uint)keyGesture.Modifiers | MOD_NOREPEAT, (uint)KeyInterop.VirtualKeyFromKey(keyGesture.Key)); } }