From 5c6e434c08fee99c588892f3b0e87a970524799e Mon Sep 17 00:00:00 2001 From: rampaa Date: Sun, 8 Dec 2024 16:40:38 +0300 Subject: [PATCH] Minor --- JL.Core/Lookup/LookupUtils.cs | 7 +++++-- JL.Core/Mining/MiningUtils.cs | 13 ++++++++----- JL.Windows/GUI/PopupWindow.xaml.cs | 8 ++++++-- JL.Windows/GUI/PreferencesWindow.xaml.cs | 14 ++++---------- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/JL.Core/Lookup/LookupUtils.cs b/JL.Core/Lookup/LookupUtils.cs index b0da7f8d..0fc4361d 100644 --- a/JL.Core/Lookup/LookupUtils.cs +++ b/JL.Core/Lookup/LookupUtils.cs @@ -36,8 +36,11 @@ public static class LookupUtils s_lastLookupTime = preciseTimeNow; - Dict? pitchDict = DictUtils.SingleDictTypeDicts.GetValueOrDefault(DictType.PitchAccentYomichan); - bool useDBForPitchDict = pitchDict is { Active: true, Options.UseDB.Value: true, Ready: true }; + bool useDBForPitchDict = false; + if (DictUtils.SingleDictTypeDicts.TryGetValue(DictType.PitchAccentYomichan, out Dict? pitchDict)) + { + useDBForPitchDict = pitchDict is { Active: true, Options.UseDB.Value: true, Ready: true }; + } ConcurrentBag lookupResults = []; diff --git a/JL.Core/Mining/MiningUtils.cs b/JL.Core/Mining/MiningUtils.cs index d67fdb3c..ad984cbb 100644 --- a/JL.Core/Mining/MiningUtils.cs +++ b/JL.Core/Mining/MiningUtils.cs @@ -423,12 +423,15 @@ public static async Task MineToFile(LookupResult lookupResult, string currentTex continue; } - string? jlFieldContent = miningParameters.GetValueOrDefault(jlField)?.ReplaceLineEndings("\\n").Replace("\t", " ", StringComparison.Ordinal).Trim(); - if (!string.IsNullOrEmpty(jlFieldContent)) + if (miningParameters.TryGetValue(jlField, out string? value)) { - _ = lineToMine.Append(CultureInfo.InvariantCulture, $"{jlField.GetDescription()}: ") - .Append(jlFieldContent) - .Append(i < jlFields.Length - 1 ? '\t' : '\n'); + string? jlFieldContent = value.ReplaceLineEndings("\\n").Replace("\t", " ", StringComparison.Ordinal).Trim(); + if (!string.IsNullOrEmpty(jlFieldContent)) + { + _ = lineToMine.Append(CultureInfo.InvariantCulture, $"{jlField.GetDescription()}: ") + .Append(jlFieldContent) + .Append(i < jlFields.Length - 1 ? '\t' : '\n'); + } } } diff --git a/JL.Windows/GUI/PopupWindow.xaml.cs b/JL.Windows/GUI/PopupWindow.xaml.cs index c9adac33..7ea9fa15 100644 --- a/JL.Windows/GUI/PopupWindow.xaml.cs +++ b/JL.Windows/GUI/PopupWindow.xaml.cs @@ -481,8 +481,12 @@ public void DisplayResults(bool generateAllResults) PopupListView.Items.Filter = PopupWindowUtils.NoAllDictFilter; - Dict? pitchDict = DictUtils.SingleDictTypeDicts.GetValueOrDefault(DictType.PitchAccentYomichan); - bool pitchDictIsActive = pitchDict?.Active ?? false; + bool pitchDictIsActive = false; + if (DictUtils.SingleDictTypeDicts.TryGetValue(DictType.PitchAccentYomichan, out Dict? pitchDict)) + { + pitchDictIsActive = pitchDict.Active; + } + Dict jmdict = DictUtils.SingleDictTypeDicts[DictType.JMdict]; bool showPOrthographyInfo = jmdict.Options.POrthographyInfo!.Value; bool showROrthographyInfo = jmdict.Options.ROrthographyInfo!.Value; diff --git a/JL.Windows/GUI/PreferencesWindow.xaml.cs b/JL.Windows/GUI/PreferencesWindow.xaml.cs index db0fd328..d01372c0 100644 --- a/JL.Windows/GUI/PreferencesWindow.xaml.cs +++ b/JL.Windows/GUI/PreferencesWindow.xaml.cs @@ -250,31 +250,25 @@ private async Task SetPreviousMiningConfig() return; } - AnkiConfig? wordAnkiConfig = ankiConfigDict.GetValueOrDefault(MineType.Word); - AnkiConfig? kanjiAnkiConfig = ankiConfigDict.GetValueOrDefault(MineType.Kanji); - AnkiConfig? nameAnkiConfig = ankiConfigDict.GetValueOrDefault(MineType.Name); - AnkiConfig? otherAnkiConfig = ankiConfigDict.GetValueOrDefault(MineType.Other); - - - if (wordAnkiConfig is not null) + if (ankiConfigDict.TryGetValue(MineType.Word, out AnkiConfig? wordAnkiConfig)) { SetPreviousMiningConfig(WordMiningSetupComboBoxDeckNames, WordMiningSetupComboBoxModelNames, WordTagsTextBox, wordAnkiConfig); CreateFieldElements(wordAnkiConfig.Fields, JLFieldUtils.JLFieldsForWordDicts, WordMiningSetupStackPanelFields); } - if (kanjiAnkiConfig is not null) + if (ankiConfigDict.TryGetValue(MineType.Kanji, out AnkiConfig? kanjiAnkiConfig)) { SetPreviousMiningConfig(KanjiMiningSetupComboBoxDeckNames, KanjiMiningSetupComboBoxModelNames, KanjiTagsTextBox, kanjiAnkiConfig); CreateFieldElements(kanjiAnkiConfig.Fields, JLFieldUtils.JLFieldsForKanjiDicts, KanjiMiningSetupStackPanelFields); } - if (nameAnkiConfig is not null) + if (ankiConfigDict.TryGetValue(MineType.Name, out AnkiConfig? nameAnkiConfig)) { SetPreviousMiningConfig(NameMiningSetupComboBoxDeckNames, NameMiningSetupComboBoxModelNames, NameTagsTextBox, nameAnkiConfig); CreateFieldElements(nameAnkiConfig.Fields, JLFieldUtils.JLFieldsForNameDicts, NameMiningSetupStackPanelFields); } - if (otherAnkiConfig is not null) + if (ankiConfigDict.TryGetValue(MineType.Other, out AnkiConfig? otherAnkiConfig)) { SetPreviousMiningConfig(OtherMiningSetupComboBoxDeckNames, OtherMiningSetupComboBoxModelNames, OtherTagsTextBox, otherAnkiConfig); CreateFieldElements(otherAnkiConfig.Fields, Enum.GetValues(), OtherMiningSetupStackPanelFields);