Skip to content

Commit 6759125

Browse files
committed
Minor
1 parent 42b4fd3 commit 6759125

File tree

5 files changed

+83
-11
lines changed

5 files changed

+83
-11
lines changed

JL.Core/Deconjugation/Rule.cs

+73-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace JL.Core.Deconjugation;
55

66
[method: JsonConstructor]
7-
internal readonly struct Rule(string type, string[] decEnd, string[] conEnd, string detail, string? contextRule = null, string[]? decTag = null, string[]? conTag = null)
7+
internal readonly struct Rule(string type, string[] decEnd, string[] conEnd, string detail, string? contextRule = null, string[]? decTag = null, string[]? conTag = null) : IEquatable<Rule>
88
{
99
[JsonPropertyName("type")] public string Type { get; } = type.GetPooledString();
1010
[JsonPropertyName("dec_end")] public string[] DecEnd { get; } = decEnd;
@@ -13,4 +13,76 @@ internal readonly struct Rule(string type, string[] decEnd, string[] conEnd, str
1313
[JsonPropertyName("contextrule")] public string? ContextRule { get; } = contextRule?.GetPooledString();
1414
[JsonPropertyName("dec_tag")] public string[]? DecTag { get; } = decTag;
1515
[JsonPropertyName("con_tag")] public string[]? ConTag { get; } = conTag;
16+
17+
public override int GetHashCode()
18+
{
19+
unchecked
20+
{
21+
int hash = (17 * 37) + Type.GetHashCode(StringComparison.Ordinal);
22+
hash = (hash * 37) + Detail.GetHashCode(StringComparison.Ordinal);
23+
hash = (hash * 37) + ContextRule?.GetHashCode(StringComparison.Ordinal) ?? 37;
24+
25+
foreach (string decEnd in DecEnd)
26+
{
27+
hash = (hash * 37) + decEnd.GetHashCode(StringComparison.Ordinal);
28+
}
29+
30+
foreach (string conEnd in ConEnd)
31+
{
32+
hash = (hash * 37) + conEnd.GetHashCode(StringComparison.Ordinal);
33+
}
34+
35+
if (DecTag is not null)
36+
{
37+
foreach (string decTag in DecTag)
38+
{
39+
hash = (hash * 37) + decTag.GetHashCode(StringComparison.Ordinal);
40+
}
41+
}
42+
else
43+
{
44+
hash *= 37;
45+
}
46+
47+
if (ConTag is not null)
48+
{
49+
foreach (string conTag in ConTag)
50+
{
51+
hash = (hash * 37) + conTag.GetHashCode(StringComparison.Ordinal);
52+
}
53+
}
54+
else
55+
{
56+
hash *= 37;
57+
}
58+
59+
return hash;
60+
}
61+
}
62+
63+
public override bool Equals(object? obj)
64+
{
65+
return obj is Rule rule
66+
&& Type == rule.Type
67+
&& Detail == rule.Detail
68+
&& ContextRule == rule.ContextRule
69+
&& DecEnd.SequenceEqual(rule.DecEnd)
70+
&& ConEnd.SequenceEqual(rule.ConEnd)
71+
&& (rule.DecTag is not null ? (DecTag?.SequenceEqual(rule.DecTag) ?? false) : DecTag is null)
72+
&& (rule.ConTag is not null ? (ConTag?.SequenceEqual(rule.ConTag) ?? false) : ConTag is null);
73+
}
74+
75+
public bool Equals(Rule other)
76+
{
77+
return Type == other.Type
78+
&& Detail == other.Detail
79+
&& ContextRule == other.ContextRule
80+
&& DecEnd.SequenceEqual(other.DecEnd)
81+
&& ConEnd.SequenceEqual(other.ConEnd)
82+
&& (other.DecTag is not null ? (DecTag?.SequenceEqual(other.DecTag) ?? false) : DecTag is null)
83+
&& (other.ConTag is not null ? (ConTag?.SequenceEqual(other.ConTag) ?? false) : ConTag is null);
84+
}
85+
86+
public static bool operator ==(Rule left, Rule right) => left.Equals(right);
87+
public static bool operator !=(Rule left, Rule right) => !left.Equals(right);
1688
}

JL.Windows/GUI/PopupWindow.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1892,7 +1892,7 @@ private async void PrimarySpellingTextBox_PreviewMouseUp(object sender, MouseBut
18921892
if ((configManager.LookupOnMouseClickOnly
18931893
|| configManager.LookupOnSelectOnly
18941894
|| e.ChangedButton != configManager.MiningModeMouseButton)
1895-
&& e.ChangedButton == configManager.MinePrimarySpellingMouseButton)
1895+
&& (e.ChangedButton == configManager.MinePrimarySpellingMouseButton))
18961896
{
18971897
await HandleMining(true).ConfigureAwait(false);
18981898
}

JL.Windows/Utilities/MagpieUtils.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ public static void UnmarkWindowAsMagpieToolWindow(nint windowHandle)
2727
WinApi.RemoveProp(windowHandle, "Magpie.ToolWindow");
2828
}
2929

30-
public static double GetMagpieWindowLeftEdgePosition(nint windowHandle)
30+
public static double GetMagpieWindowLeftEdgePositionFromMagpie(nint windowHandle)
3131
{
3232
return WinApi.GetProp(windowHandle, "Magpie.DestLeft");
3333
}
3434

35-
public static double GetMagpieWindowRightEdgePosition(nint windowHandle)
35+
public static double GetMagpieWindowRightEdgePositionFromMagpie(nint windowHandle)
3636
{
3737
return WinApi.GetProp(windowHandle, "Magpie.DestRight");
3838
}
3939

40-
public static double GetMagpieWindowTopEdgePosition(nint windowHandle)
40+
public static double GetMagpieWindowTopEdgePositionFromMagpie(nint windowHandle)
4141
{
4242
return WinApi.GetProp(windowHandle, "Magpie.DestTop");
4343
}
4444

45-
public static double GetMagpieWindowBottomEdgePosition(nint windowHandle)
45+
public static double GetMagpieWindowBottomEdgePositionFromMagpie(nint windowHandle)
4646
{
4747
return WinApi.GetProp(windowHandle, "Magpie.DestBottom");
4848
}

JL.Windows/Utilities/WindowsUtils.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ public static Size MeasureTextSize(string text, double fontSize)
489489

490490
public static void ShowColorPicker(Button button)
491491
{
492-
ColorPicker picker = SingleOpenHelper.CreateControl<ColorPicker>();
492+
using ColorPicker picker = SingleOpenHelper.CreateControl<ColorPicker>();
493493
HandyControl.Controls.PopupWindow window = new()
494494
{
495495
PopupElement = picker,

JL.Windows/WinApi.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,10 @@ private nint WndProc(nint hwnd, int msg, nint wParam, nint lParam, ref bool hand
345345
MagpieUtils.IsMagpieScaling = wParam is 1;
346346
if (MagpieUtils.IsMagpieScaling)
347347
{
348-
MagpieUtils.MagpieWindowTopEdgePosition = MagpieUtils.GetMagpieWindowTopEdgePosition(lParam);
349-
MagpieUtils.MagpieWindowBottomEdgePosition = MagpieUtils.GetMagpieWindowBottomEdgePosition(lParam);
350-
MagpieUtils.MagpieWindowLeftEdgePosition = MagpieUtils.GetMagpieWindowLeftEdgePosition(lParam);
351-
MagpieUtils.MagpieWindowRightEdgePosition = MagpieUtils.GetMagpieWindowRightEdgePosition(lParam);
348+
MagpieUtils.MagpieWindowTopEdgePosition = MagpieUtils.GetMagpieWindowTopEdgePositionFromMagpie(lParam);
349+
MagpieUtils.MagpieWindowBottomEdgePosition = MagpieUtils.GetMagpieWindowBottomEdgePositionFromMagpie(lParam);
350+
MagpieUtils.MagpieWindowLeftEdgePosition = MagpieUtils.GetMagpieWindowLeftEdgePositionFromMagpie(lParam);
351+
MagpieUtils.MagpieWindowRightEdgePosition = MagpieUtils.GetMagpieWindowRightEdgePositionFromMagpie(lParam);
352352
// MagpieUtils.SourceWindowHandle = MagpieUtils.GetSourceWindowHande(lParam);
353353
MagpieUtils.DpiAwareMagpieWindowWidth = (MagpieUtils.MagpieWindowRightEdgePosition - MagpieUtils.MagpieWindowLeftEdgePosition) / WindowsUtils.Dpi.DpiScaleX;
354354
MainWindow.Instance.BringToFront();

0 commit comments

Comments
 (0)