Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Dec 12, 2024
1 parent 0145399 commit 94fa1fd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 28 deletions.
4 changes: 2 additions & 2 deletions JL.Core/Mining/Anki/AnkiConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ await File.WriteAllTextAsync(Path.Join(Utils.ConfigPath, "AnkiConfig.json"),
s_ankiConfigDict = await JsonSerializer.DeserializeAsync<Dictionary<MineType, AnkiConfig>>(ankiConfigStream,
Utils.s_jsoIgnoringNullWithEnumConverter).ConfigureAwait(false);
}

return s_ankiConfigDict;
}

catch (Exception ex)
Expand All @@ -76,7 +78,5 @@ await File.WriteAllTextAsync(Path.Join(Utils.ConfigPath, "AnkiConfig.json"),
Utils.Logger.Warning("AnkiConfig.json doesn't exist");
return null;
}

return s_ankiConfigDict;
}
}
54 changes: 30 additions & 24 deletions JL.Windows/GUI/PopupWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public Task LookupOnCharPosition(TextBox textBox, int charPosition, bool enableM
if (enableMiningMode)
{
EnableMiningMode();
DisplayResults(true);
DisplayResults();

if (configManager.AutoHidePopupIfMouseIsNotOverIt)
{
Expand All @@ -265,7 +265,7 @@ public Task LookupOnCharPosition(TextBox textBox, int charPosition, bool enableM

else
{
DisplayResults(false);
DisplayResults();
}

Show();
Expand Down Expand Up @@ -367,7 +367,7 @@ public Task LookupOnSelect(TextBox textBox)
LastLookupResults = lookupResults;

EnableMiningMode();
DisplayResults(true);
DisplayResults();

if (configManager.AutoHidePopupIfMouseIsNotOverIt)
{
Expand Down Expand Up @@ -475,7 +475,7 @@ private void UpdatePosition(double x, double y)
WinApi.MoveWindowToPosition(WindowHandle, x, y);
}

public void DisplayResults(bool generateAllResults)
public void DisplayResults()
{
ConfigManager configManager = ConfigManager.Instance;
CoreConfigManager coreConfigManager = CoreConfigManager.Instance;
Expand All @@ -495,18 +495,23 @@ public void DisplayResults(bool generateAllResults)
bool showAOrthographyInfo = jmdict.Options.AOrthographyInfo!.Value;
double pOrthographyInfoFontSize = jmdict.Options.POrthographyInfoFontSize!.Value;

int resultCount = generateAllResults
? LastLookupResults.Length
: Math.Min(LastLookupResults.Length, ConfigManager.Instance.MaxNumResultsNotInMiningMode);

bool checkForDuplicateCards = MiningMode
&& coreConfigManager.CheckForDuplicateCards
&& !configManager.MineToFileInsteadOfAnki
&& coreConfigManager.AnkiIntegration;

TextBlock[]? duplicateIcons = checkForDuplicateCards
? new TextBlock[LastLookupResults.Length]
: null;
TextBlock[]? duplicateIcons;
int resultCount;
bool checkForDuplicateCards;
if (MiningMode)
{
resultCount = LastLookupResults.Length;
checkForDuplicateCards = coreConfigManager is { CheckForDuplicateCards: true, AnkiIntegration: true } && !configManager.MineToFileInsteadOfAnki;
duplicateIcons = checkForDuplicateCards
? new TextBlock[LastLookupResults.Length]
: null;
}
else
{
resultCount = Math.Min(LastLookupResults.Length, ConfigManager.Instance.MaxNumResultsNotInMiningMode);
checkForDuplicateCards = false;
duplicateIcons = null;
}

StackPanel[] popupItemSource = new StackPanel[resultCount];

Expand All @@ -523,10 +528,12 @@ public void DisplayResults(bool generateAllResults)
}

PopupListView.ItemsSource = popupItemSource;
if (duplicateIcons is not null)

if (checkForDuplicateCards)
{
_ = CheckResultForDuplicates(duplicateIcons);
_ = CheckResultForDuplicates(duplicateIcons!);
}

GenerateDictTypeButtons();
UpdateLayout();
}
Expand Down Expand Up @@ -815,10 +822,10 @@ private StackPanel PrepareResultStackPanel(LookupResult result, int index, int r
// Keep this at the bottom
if (duplicateIcons is not null)
{
TextBlock duplicate = new()
TextBlock duplicateIconTextBlock = new()
{
Text = "⚠",
Name = nameof(duplicate),
Name = nameof(duplicateIconTextBlock),
FontSize = configManager.DictTypeFontSize,
Foreground = configManager.DefinitionsColor,
VerticalAlignment = VerticalAlignment.Top,
Expand All @@ -831,8 +838,8 @@ private StackPanel PrepareResultStackPanel(LookupResult result, int index, int r
Visibility = Visibility.Hidden
};

_ = top.Children.Add(duplicate);
duplicateIcons[index] = duplicate;
_ = top.Children.Add(duplicateIconTextBlock);
duplicateIcons[index] = duplicateIconTextBlock;
}

// bottom
Expand Down Expand Up @@ -1395,6 +1402,7 @@ public async Task HandleHotKey(KeyGesture keyGesture, KeyEventArgs? e)
}

EnableMiningMode();
DisplayResults();

if (configManager.Focusable)
{
Expand All @@ -1403,8 +1411,6 @@ public async Task HandleHotKey(KeyGesture keyGesture, KeyEventArgs? e)

_ = Focus();

DisplayResults(true);

if (configManager.AutoHidePopupIfMouseIsNotOverIt)
{
PopupWindowUtils.SetPopupAutoHideTimer();
Expand Down
5 changes: 3 additions & 2 deletions JL.Windows/Utilities/PopupWindowUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ public static void HidePopups(PopupWindow? rootPopup)
public static void ShowMiningModeResults(PopupWindow popupWindow)
{
popupWindow.EnableMiningMode();
WinApi.BringToFront(popupWindow.WindowHandle);
popupWindow.DisplayResults(true);
popupWindow.DisplayResults();

ConfigManager configManager = ConfigManager.Instance;
if (configManager.Focusable)
Expand All @@ -247,6 +246,8 @@ public static void ShowMiningModeResults(PopupWindow popupWindow)

_ = popupWindow.Focus();

WinApi.BringToFront(popupWindow.WindowHandle);

if (configManager.AutoHidePopupIfMouseIsNotOverIt)
{
SetPopupAutoHideTimer();
Expand Down

0 comments on commit 94fa1fd

Please sign in to comment.