Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Dec 8, 2024
1 parent a8320d5 commit 5c6e434
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
7 changes: 5 additions & 2 deletions JL.Core/Lookup/LookupUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<LookupResult> lookupResults = [];

Expand Down
13 changes: 8 additions & 5 deletions JL.Core/Mining/MiningUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions JL.Windows/GUI/PopupWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 4 additions & 10 deletions JL.Windows/GUI/PreferencesWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<JLField>(), OtherMiningSetupStackPanelFields);
Expand Down

0 comments on commit 5c6e434

Please sign in to comment.