Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Oct 8, 2023
1 parent 2c15389 commit d723999
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 29 deletions.
2 changes: 1 addition & 1 deletion JL.Core.Tests/LookupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void ClassInit()
)));

Dict dict = DictUtils.Dicts["JMdict"];
DictUtils.BuiltInDictTypeToDict[DictType.JMdict] = dict;
DictUtils.SingleDictTypeDicts[DictType.JMdict] = dict;
JmdictLoader.Load(dict).Wait();

FreqUtils.FreqDicts = FreqUtils.s_builtInFreqs;
Expand Down
21 changes: 13 additions & 8 deletions JL.Core/Dicts/DictUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static class DictUtils
}
};

public static readonly Dictionary<DictType, Dict> BuiltInDictTypeToDict = new(7);
public static readonly Dictionary<DictType, Dict> SingleDictTypeDicts = new(8);

public static readonly Dictionary<string, string> JmdictEntities = new(254)
{
Expand Down Expand Up @@ -803,6 +803,7 @@ dict.Type is DictType.CustomNameDictionary
Utils.Frontend.Alert(AlertLevel.Error, string.Create(CultureInfo.InvariantCulture, $"Couldn't import {dict.Name}"));
Utils.Logger.Error(ex, "Couldn't import {DictType}", dict.Type);
_ = Dicts.Remove(dict.Name);
_ = SingleDictTypeDicts.Remove(DictType.PitchAccentYomichan);
dictRemoved = true;
}
}));
Expand Down Expand Up @@ -993,32 +994,36 @@ internal static async Task DeserializeDicts()
{
case DictType.ProfileCustomNameDictionary:
dict.Path = ProfileUtils.GetProfileCustomNameDictPath(ProfileUtils.CurrentProfile);
BuiltInDictTypeToDict.Add(dict.Type, dict);
SingleDictTypeDicts[dict.Type] = dict;
break;

case DictType.ProfileCustomWordDictionary:
dict.Path = ProfileUtils.GetProfileCustomWordDictPath(ProfileUtils.CurrentProfile);
BuiltInDictTypeToDict.Add(dict.Type, dict);
SingleDictTypeDicts[dict.Type] = dict;
break;

case DictType.CustomNameDictionary:
BuiltInDictTypeToDict.Add(dict.Type, dict);
SingleDictTypeDicts[dict.Type] = dict;
break;

case DictType.CustomWordDictionary:
BuiltInDictTypeToDict.Add(dict.Type, dict);
SingleDictTypeDicts[dict.Type] = dict;
break;

case DictType.JMdict:
BuiltInDictTypeToDict.Add(dict.Type, dict);
SingleDictTypeDicts[dict.Type] = dict;
break;

case DictType.Kanjidic:
BuiltInDictTypeToDict.Add(dict.Type, dict);
SingleDictTypeDicts[dict.Type] = dict;
break;

case DictType.JMnedict:
BuiltInDictTypeToDict.Add(dict.Type, dict);
SingleDictTypeDicts[dict.Type] = dict;
break;

case DictType.PitchAccentYomichan:
SingleDictTypeDicts[dict.Type] = dict;
break;
}

Expand Down
6 changes: 3 additions & 3 deletions JL.Core/Dicts/EDICT/ResourceUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static async Task UpdateJmdict()
{
DictUtils.UpdatingJmdict = true;

Dict dict = DictUtils.BuiltInDictTypeToDict[DictType.JMdict];
Dict dict = DictUtils.SingleDictTypeDicts[DictType.JMdict];
bool downloaded = await UpdateResource(dict.Path,
DictUtils.s_jmdictUrl,
DictType.JMdict.ToString(), true, false)
Expand Down Expand Up @@ -141,7 +141,7 @@ public static async Task UpdateJmnedict()
{
DictUtils.UpdatingJmnedict = true;

Dict dict = DictUtils.BuiltInDictTypeToDict[DictType.JMnedict];
Dict dict = DictUtils.SingleDictTypeDicts[DictType.JMnedict];
bool downloaded = await UpdateResource(dict.Path,
DictUtils.s_jmnedictUrl,
DictType.JMnedict.ToString(), true, false)
Expand Down Expand Up @@ -170,7 +170,7 @@ public static async Task UpdateKanjidic()
{
DictUtils.UpdatingKanjidic = true;

Dict dict = DictUtils.BuiltInDictTypeToDict[DictType.Kanjidic];
Dict dict = DictUtils.SingleDictTypeDicts[DictType.Kanjidic];
bool downloaded = await UpdateResource(dict.Path,
DictUtils.s_kanjidicUrl,
DictType.Kanjidic.ToString(), true, false)
Expand Down
2 changes: 1 addition & 1 deletion JL.Core/Lookup/LookupUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ private static Dictionary<string, IntermediaryResult> GetKanjiResults(string tex
private static ConcurrentQueue<LookupResult> BuildJmdictResult(
Dictionary<string, IntermediaryResult> jmdictResults)
{
Dict dict = DictUtils.BuiltInDictTypeToDict[DictType.JMdict];
Dict dict = DictUtils.SingleDictTypeDicts[DictType.JMdict];
bool showROrthographyInfo = dict.Options?.ROrthographyInfo?.Value ?? true;
bool showAOrthographyInfo = dict.Options?.AOrthographyInfo?.Value ?? true;

Expand Down
4 changes: 2 additions & 2 deletions JL.Core/WordClass/JmdictWordClassUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static async Task Serialize()
"v5n", "v5r", "v5r-i", "v5s", "v5t", "v5u", "v5u-s", "vk", "vs-c", "vs-i", "vs-s", "vz"
};

Dict dict = DictUtils.BuiltInDictTypeToDict[DictType.JMdict];
Dict dict = DictUtils.SingleDictTypeDicts[DictType.JMdict];
foreach (IList<IDictRecord> jmdictRecordList in dict.Contents.Values.ToList())
{
int jmdictRecordListCount = jmdictRecordList.Count;
Expand Down Expand Up @@ -126,7 +126,7 @@ internal static async Task Initialize()
{
if (!File.Exists(Path.Join(Utils.ResourcesPath, "PoS.json")))
{
Dict dict = DictUtils.BuiltInDictTypeToDict[DictType.JMdict];
Dict dict = DictUtils.SingleDictTypeDicts[DictType.JMdict];
if (dict.Active)
{
await Serialize().ConfigureAwait(false);
Expand Down
15 changes: 6 additions & 9 deletions JL.Windows/DictOptionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ internal static class DictOptionManager

public static void ApplyDictOptions()
{
if (DictUtils.BuiltInDictTypeToDict.TryGetValue(DictType.JMdict, out Dict? jmdict))
if (DictUtils.SingleDictTypeDicts.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
Expand All @@ -24,13 +24,10 @@ public static void ApplyDictOptions()
POrthographyInfoColor.Freeze();
}

Dict? pitchAccentDict = DictUtils.Dicts.Values.FirstOrDefault(static dict => dict.Type is DictType.PitchAccentYomichan);
if (pitchAccentDict is not null)
if (DictUtils.SingleDictTypeDicts.TryGetValue(DictType.PitchAccentYomichan, out Dict? pitchAccentDict))
{
if (pitchAccentDict.Options?.PitchAccentMarkerColor is not null)
{
PitchAccentMarkerColor = WindowsUtils.FrozenBrushFromHex(pitchAccentDict.Options.PitchAccentMarkerColor.Value.Value)!;
}
PitchAccentMarkerColor = WindowsUtils.FrozenBrushFromHex(pitchAccentDict.Options?.PitchAccentMarkerColor?.Value
?? Brushes.DeepSkyBlue.ToString(CultureInfo.InvariantCulture))!;
}

else
Expand Down
9 changes: 7 additions & 2 deletions JL.Windows/GUI/AddDictionaryWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,13 @@ private void SaveButton_Click(object sender, RoutedEventArgs e)

DictOptions options = new(newlineOption, examplesOption, noAllOption, pitchAccentMarkerColorOption);

DictUtils.Dicts.Add(name,
new Dict(type, name, path, true, DictUtils.Dicts.Count + 1, 0, options));
Dict dict = new(type, name, path, true, DictUtils.Dicts.Count + 1, 0, options);
DictUtils.Dicts.Add(name, dict);

if (dict.Type is DictType.PitchAccentYomichan)
{
DictUtils.SingleDictTypeDicts[DictType.PitchAccentYomichan] = dict;
}

Close();
}
Expand Down
5 changes: 5 additions & 0 deletions JL.Windows/GUI/ManageDictionariesWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ and not DictType.Kanjidic
dict.Contents.TrimExcess();
_ = DictUtils.Dicts.Remove(dict.Name);

if (dict.Type is DictType.PitchAccentYomichan)
{
_ = DictUtils.SingleDictTypeDicts.Remove(DictType.PitchAccentYomichan);
}

int priorityOfDeletedDict = dict.Priority;

foreach (Dict d in DictUtils.Dicts.Values)
Expand Down
2 changes: 1 addition & 1 deletion JL.Windows/GUI/PopupWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ public StackPanel MakeResultStackPanel(LookupResult result, int index, int resul
};
primarySpellingTextBlock.PreviewMouseUp += PrimarySpelling_PreviewMouseUp; // for mining

Dict? pitchDict = DictUtils.Dicts.Values.FirstOrDefault(static dict => dict.Type is DictType.PitchAccentYomichan);
_ = DictUtils.SingleDictTypeDicts.TryGetValue(DictType.PitchAccentYomichan, out Dict? pitchDict);
bool pitchDictIsActive = pitchDict?.Active ?? false;

if (result.Readings is null && pitchDictIsActive)
Expand Down
4 changes: 2 additions & 2 deletions JL.Windows/GUI/PreferencesWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public PreferencesWindow()
{
InitializeComponent();
_profileName = ProfileUtils.CurrentProfile;
_profileNamesDict = DictUtils.BuiltInDictTypeToDict[DictType.ProfileCustomNameDictionary];
_profileWordsDict = DictUtils.BuiltInDictTypeToDict[DictType.ProfileCustomWordDictionary];
_profileNamesDict = DictUtils.SingleDictTypeDicts[DictType.ProfileCustomNameDictionary];
_profileWordsDict = DictUtils.SingleDictTypeDicts[DictType.ProfileCustomWordDictionary];
}

public static bool IsItVisible()
Expand Down

0 comments on commit d723999

Please sign in to comment.