Skip to content

Commit b497c96

Browse files
committed
Add the “Show images at the bottom instead of the top” dictionary option. Disabling it shows definition images above an entry’s definition instead of below.
1 parent b4a251b commit b497c96

File tree

6 files changed

+61
-11
lines changed

6 files changed

+61
-11
lines changed

JL.Core/Dicts/DictUtils.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ public static class DictUtils
7474
new DictOptions(
7575
new UseDBOption(false),
7676
new NoAllOption(false),
77-
showImages: new ShowImagesOption(true)),
77+
showImages: new ShowImagesOption(true),
78+
showImageAtBottom: new ShowImageAtBottomOption(true)),
7879
autoUpdatable: false,
7980
url: null,
8081
revision: null)
@@ -100,7 +101,8 @@ public static class DictUtils
100101
new DictOptions(
101102
new UseDBOption(false),
102103
new NoAllOption(false),
103-
showImages: new ShowImagesOption(true)),
104+
showImages: new ShowImagesOption(true),
105+
showImageAtBottom: new ShowImageAtBottomOption(true)),
104106
autoUpdatable: false,
105107
url: null,
106108
revision: null)
@@ -1606,13 +1608,18 @@ private static void InitDictOptions(Dict dict)
16061608
else if (dict.Type is DictType.CustomNameDictionary or DictType.ProfileCustomNameDictionary)
16071609
{
16081610
dict.Options.ShowImages = new ShowImagesOption(true);
1611+
dict.Options.ShowImageAtBottom = new ShowImageAtBottomOption(true);
16091612
}
16101613
else
16111614
{
16121615
if (ShowImagesOption.ValidDictTypes.Contains(dict.Type))
16131616
{
16141617
dict.Options.ShowImages ??= new ShowImagesOption(true);
16151618
}
1619+
if (ShowImageAtBottomOption.ValidDictTypes.Contains(dict.Type))
1620+
{
1621+
dict.Options.ShowImageAtBottom ??= new ShowImageAtBottomOption(true);
1622+
}
16161623
if (NewlineBetweenDefinitionsOption.ValidDictTypes.Contains(dict.Type))
16171624
{
16181625
dict.Options.NewlineBetweenDefinitions ??= new NewlineBetweenDefinitionsOption(true);

JL.Core/Dicts/Options/AvailableDictOptions.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,17 @@ public sealed class ShowImagesOption(bool value)
143143
[JsonIgnore]
144144
public static readonly DictType[] ValidDictTypes =
145145
[DictType.NonspecificWordYomichan, DictType.NonspecificNameYomichan, DictType.NonspecificKanjiWithWordSchemaYomichan, DictType.NonspecificYomichan, DictType.NonspecificKanjiYomichan,
146-
DictType.NonspecificNameNazeka, DictType.NonspecificWordNazeka, DictType.NonspecificNazeka, DictType.NonspecificKanjiNazeka];
146+
DictType.NonspecificNameNazeka, DictType.NonspecificWordNazeka, DictType.NonspecificNazeka, DictType.NonspecificKanjiNazeka,
147+
DictType.CustomNameDictionary, DictType.ProfileCustomNameDictionary];
148+
}
149+
150+
public sealed class ShowImageAtBottomOption(bool value)
151+
{
152+
public bool Value { get; set; } = value;
153+
154+
[JsonIgnore]
155+
public static readonly DictType[] ValidDictTypes =
156+
[DictType.NonspecificWordYomichan, DictType.NonspecificNameYomichan, DictType.NonspecificKanjiWithWordSchemaYomichan, DictType.NonspecificYomichan, DictType.NonspecificKanjiYomichan,
157+
DictType.NonspecificNameNazeka, DictType.NonspecificWordNazeka, DictType.NonspecificNazeka, DictType.NonspecificKanjiNazeka,
158+
DictType.CustomNameDictionary, DictType.ProfileCustomNameDictionary];
147159
}

JL.Core/Dicts/Options/DictOptions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public sealed class DictOptions(
2121
AntonymOption? antonym = null,
2222
ShowPitchAccentWithDottedLinesOption? showPitchAccentWithDottedLines = null,
2323
AutoUpdateAfterNDaysOption? autoUpdateAfterNDays = null,
24-
ShowImagesOption? showImages = null)
24+
ShowImagesOption? showImages = null,
25+
ShowImageAtBottomOption? showImageAtBottom = null)
2526
{
2627
public UseDBOption UseDB { get; } = useDB;
2728
public NoAllOption NoAll { get; } = noAll;
@@ -47,4 +48,5 @@ public sealed class DictOptions(
4748
public AutoUpdateAfterNDaysOption? AutoUpdateAfterNDays { get; internal set; } = autoUpdateAfterNDays;
4849

4950
public ShowImagesOption? ShowImages { get; internal set; } = showImages;
51+
public ShowImageAtBottomOption? ShowImageAtBottom { get; internal set; } = showImageAtBottom;
5052
}

JL.Windows/GUI/Options/DictOptionsControl.xaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@
126126
<TextBlock Text="Show images" TextWrapping="Wrap" HorizontalAlignment="Left" Style="{StaticResource TextBlockDefault}" />
127127
</CheckBox>
128128

129+
<CheckBox Name="ShowImageAtBottomCheckBox" Margin="10" Visibility="Collapsed" HorizontalAlignment="Left">
130+
<TextBlock Text="Show images at the bottom instead of the top"
131+
ToolTip="If unchecked, definition images are shown above an entry’s definition instead of below."
132+
Cursor="Help"
133+
TextWrapping="Wrap"
134+
HorizontalAlignment="Left"
135+
Style="{StaticResource TextBlockDefault}" />
136+
</CheckBox>
137+
129138
<CheckBox Name="ShowPitchAccentWithDottedLinesCheckBox" Margin="10" Visibility="Collapsed" HorizontalAlignment="Left">
130139
<TextBlock Text="Show pitch accent with dotted lines"
131140
ToolTip="If unchecked, pitch accent will be shown with solid lines"

JL.Windows/GUI/Options/DictOptionsControl.xaml.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ public DictOptions GetDictOptions(DictType type, bool autoUpdatable)
179179
showImagesOption = new ShowImagesOption(ShowImagesCheckBox.IsChecked.Value);
180180
}
181181

182+
ShowImageAtBottomOption? showImageAtBottomOption = null;
183+
if (ShowImageAtBottomOption.ValidDictTypes.Contains(type))
184+
{
185+
Debug.Assert(ShowImageAtBottomCheckBox.IsChecked is not null);
186+
showImageAtBottomOption = new ShowImageAtBottomOption(ShowImageAtBottomCheckBox.IsChecked.Value);
187+
}
188+
182189
DictOptions options = new(
183190
useDBOption,
184191
noAllOption,
@@ -200,7 +207,8 @@ public DictOptions GetDictOptions(DictType type, bool autoUpdatable)
200207
antonymOption,
201208
showPitchAccentWithDottedLines,
202209
autoUpdateAfterNDaysOption,
203-
showImagesOption);
210+
showImagesOption,
211+
showImageAtBottomOption);
204212

205213
return options;
206214
}
@@ -225,6 +233,7 @@ public void GenerateDictOptionsElements(DictType dictType, DictOptions? dictOpti
225233
OptionUtils.ChangeVisibilityOfCheckBox(UseDBOption.ValidDictTypes.Contains(dictType), UseDBCheckBox, dictOptions?.UseDB.Value ?? true, ref showDictOptions);
226234
OptionUtils.ChangeVisibilityOfCheckBox(ShowPitchAccentWithDottedLinesOption.ValidDictTypes.Contains(dictType), ShowPitchAccentWithDottedLinesCheckBox, dictOptions?.ShowPitchAccentWithDottedLines?.Value ?? true, ref showDictOptions);
227235
OptionUtils.ChangeVisibilityOfCheckBox(ShowImagesOption.ValidDictTypes.Contains(dictType), ShowImagesCheckBox, dictOptions?.ShowImages?.Value ?? true, ref showDictOptions);
236+
OptionUtils.ChangeVisibilityOfCheckBox(ShowImageAtBottomOption.ValidDictTypes.Contains(dictType), ShowImageAtBottomCheckBox, dictOptions?.ShowImageAtBottom?.Value ?? true, ref showDictOptions);
228237
OptionUtils.ChangeVisibilityOfColorButton(PitchAccentMarkerColorOption.ValidDictTypes.Contains(dictType), PitchAccentMarkerColorButton, PitchAccentMarkerColorDockPanel, dictOptions?.PitchAccentMarkerColor?.Value, DictOptionManager.PitchAccentMarkerColor, ref showDictOptions);
229238
OptionUtils.ChangeVisibilityOfColorButton(POrthographyInfoColorOption.ValidDictTypes.Contains(dictType), POrthographyInfoColorButton, POrthographyInfoColorDockPanel, dictOptions?.POrthographyInfoColor?.Value, DictOptionManager.POrthographyInfoColor, ref showDictOptions);
230239
OptionUtils.ChangeVisibilityOfNumericUpDown(POrthographyInfoFontSizeOption.ValidDictTypes.Contains(dictType), POrthographyInfoFontSizeNumericUpDown, POrthographyInfoFontSizeDockPanel, dictOptions?.POrthographyInfoFontSize?.Value ?? 15, ref showDictOptions);

JL.Windows/GUI/Popup/PopupContentGenerator.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,24 @@ private static StackPanel PrepareResultStackPanel(LookupDisplayResult lookupDisp
5555
CreateMiningButton(lookupDisplayResult, top);
5656

5757
StackPanel bottom = new();
58+
59+
bool imagesExist = result.ImagePaths is not null;
60+
Debug.Assert(!imagesExist || (result.Dict.Options.ShowImages is not null && result.Dict.Options.ShowImageAtBottom is not null));
61+
bool showImagesAtBottom = imagesExist && result.Dict.Options.ShowImageAtBottom!.Value;
62+
63+
if (imagesExist && !showImagesAtBottom)
64+
{
65+
CreateImages(lookupDisplayResult, bottom);
66+
}
67+
5868
CreateFormattedDefinition(lookupDisplayResult, bottom);
5969
CreateKanjiText(ownerWindow, result.KanjiLookupResult, bottom);
60-
CreateImages(lookupDisplayResult, bottom);
70+
71+
if (imagesExist && showImagesAtBottom)
72+
{
73+
CreateImages(lookupDisplayResult, bottom);
74+
}
75+
6176
CreateSeparator(lookupDisplayResult.NonLastItem, bottom);
6277

6378
StackPanel stackPanel = new()
@@ -630,11 +645,6 @@ private static void CreateKanjiText(PopupWindow ownerWindow, KanjiLookupResult?
630645
private static void CreateImages(LookupDisplayResult lookupDisplayResult, StackPanel bottom)
631646
{
632647
LookupResult result = lookupDisplayResult.LookupResult;
633-
if (result.ImagePaths is null)
634-
{
635-
return;
636-
}
637-
638648
ShowImagesOption? showImagesOption = result.Dict.Options.ShowImages;
639649
Debug.Assert(showImagesOption is not null);
640650
if (!showImagesOption.Value)
@@ -646,6 +656,7 @@ private static void CreateImages(LookupDisplayResult lookupDisplayResult, StackP
646656
int maxPopupWidth = double.ConvertToIntegerNative<int>(lookupDisplayResult.OwnerWindow.MaxWidth * dpi.DpiScaleX);
647657
int maxPopupHeight = double.ConvertToIntegerNative<int>(lookupDisplayResult.OwnerWindow.MaxHeight * dpi.DpiScaleY);
648658

659+
Debug.Assert(result.ImagePaths is not null);
649660
for (int i = 0; i < result.ImagePaths.Length; i++)
650661
{
651662
string imagePath = Path.GetFullPath(result.ImagePaths[i], AppInfo.ApplicationPath);

0 commit comments

Comments
 (0)