Skip to content

Commit

Permalink
Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Jan 24, 2024
1 parent affc501 commit 5e4ca11
Showing 1 changed file with 27 additions and 54 deletions.
81 changes: 27 additions & 54 deletions JL.Windows/GUI/PopupWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,16 @@ public void DisplayResults(bool generateAllResults, string? text = null)
}
}

private void AddEventHandlersToTextBox(TextBox textBox)
{
textBox.PreviewMouseUp += TextBox_PreviewMouseUp;
textBox.MouseMove += TextBox_MouseMove;
textBox.LostFocus += Unselect;
textBox.PreviewMouseRightButtonUp += TextBox_PreviewMouseRightButtonUp;
textBox.MouseLeave += OnMouseLeave;
textBox.PreviewMouseLeftButtonDown += TextBox_PreviewMouseLeftButtonDown;
}

public StackPanel PrepareResultStackPanel(LookupResult result, int index, int resultsCount, Dict? pitchDict, bool pitchDictIsActive, bool showPOrthographyInfo, bool showROrthographyInfo, bool showAOrthographyInfo, double pOrthographyInfoFontSize)
{
// top
Expand Down Expand Up @@ -579,12 +589,7 @@ public StackPanel PrepareResultStackPanel(LookupResult result, int index, int re
_ = top.Children.Add(readingTextBox);
}

readingTextBox.PreviewMouseUp += TextBox_PreviewMouseUp;
readingTextBox.MouseMove += TextBox_MouseMove;
readingTextBox.LostFocus += Unselect;
readingTextBox.PreviewMouseRightButtonUp += TextBox_PreviewMouseRightButtonUp;
readingTextBox.MouseLeave += OnMouseLeave;
readingTextBox.PreviewMouseLeftButtonDown += TextBox_PreviewMouseLeftButtonDown;
AddEventHandlersToTextBox(readingTextBox);
}

else
Expand Down Expand Up @@ -642,12 +647,8 @@ public StackPanel PrepareResultStackPanel(LookupResult result, int index, int re
VerticalAlignment.Center,
new Thickness(5, 0, 0, 0));

alternativeSpellingsTexBox.PreviewMouseUp += TextBox_PreviewMouseUp;
alternativeSpellingsTexBox.MouseMove += TextBox_MouseMove;
alternativeSpellingsTexBox.LostFocus += Unselect;
alternativeSpellingsTexBox.PreviewMouseRightButtonUp += TextBox_PreviewMouseRightButtonUp;
alternativeSpellingsTexBox.MouseLeave += OnMouseLeave;
alternativeSpellingsTexBox.PreviewMouseLeftButtonDown += TextBox_PreviewMouseLeftButtonDown;
AddEventHandlersToTextBox(alternativeSpellingsTexBox);

_ = top.Children.Add(alternativeSpellingsTexBox);
}
else
Expand Down Expand Up @@ -676,12 +677,8 @@ public StackPanel PrepareResultStackPanel(LookupResult result, int index, int re
VerticalAlignment.Top,
new Thickness(5, 0, 0, 0));

deconjugationProcessTextBox.PreviewMouseUp += TextBox_PreviewMouseUp;
deconjugationProcessTextBox.MouseMove += TextBox_MouseMove;
deconjugationProcessTextBox.LostFocus += Unselect;
deconjugationProcessTextBox.PreviewMouseRightButtonUp += TextBox_PreviewMouseRightButtonUp;
deconjugationProcessTextBox.MouseLeave += OnMouseLeave;
deconjugationProcessTextBox.PreviewMouseLeftButtonDown += TextBox_PreviewMouseLeftButtonDown;
AddEventHandlersToTextBox(deconjugationProcessTextBox);

_ = top.Children.Add(deconjugationProcessTextBox);
}
else
Expand Down Expand Up @@ -740,12 +737,8 @@ public StackPanel PrepareResultStackPanel(LookupResult result, int index, int re
VerticalAlignment.Center,
new Thickness(2));

definitionsTextBox.PreviewMouseUp += TextBox_PreviewMouseUp;
definitionsTextBox.MouseMove += TextBox_MouseMove;
definitionsTextBox.LostFocus += Unselect;
definitionsTextBox.PreviewMouseRightButtonUp += TextBox_PreviewMouseRightButtonUp;
definitionsTextBox.MouseLeave += OnMouseLeave;
definitionsTextBox.PreviewMouseLeftButtonDown += TextBox_PreviewMouseLeftButtonDown;
AddEventHandlersToTextBox(definitionsTextBox);

_ = bottom.Children.Add(definitionsTextBox);
}

Expand Down Expand Up @@ -776,12 +769,8 @@ public StackPanel PrepareResultStackPanel(LookupResult result, int index, int re
VerticalAlignment.Center,
new Thickness(2));

onReadingsTextBox.PreviewMouseUp += TextBox_PreviewMouseUp;
onReadingsTextBox.MouseMove += TextBox_MouseMove;
onReadingsTextBox.LostFocus += Unselect;
onReadingsTextBox.PreviewMouseRightButtonUp += TextBox_PreviewMouseRightButtonUp;
onReadingsTextBox.MouseLeave += OnMouseLeave;
onReadingsTextBox.PreviewMouseLeftButtonDown += TextBox_PreviewMouseLeftButtonDown;
AddEventHandlersToTextBox(onReadingsTextBox);

_ = bottom.Children.Add(onReadingsTextBox);
}

Expand Down Expand Up @@ -811,12 +800,8 @@ public StackPanel PrepareResultStackPanel(LookupResult result, int index, int re
VerticalAlignment.Center,
new Thickness(2));

kunReadingsTextBox.PreviewMouseUp += TextBox_PreviewMouseUp;
kunReadingsTextBox.MouseMove += TextBox_MouseMove;
kunReadingsTextBox.LostFocus += Unselect;
kunReadingsTextBox.PreviewMouseRightButtonUp += TextBox_PreviewMouseRightButtonUp;
kunReadingsTextBox.MouseLeave += OnMouseLeave;
kunReadingsTextBox.PreviewMouseLeftButtonDown += TextBox_PreviewMouseLeftButtonDown;
AddEventHandlersToTextBox(kunReadingsTextBox);

_ = bottom.Children.Add(kunReadingsTextBox);
}

Expand Down Expand Up @@ -846,12 +831,8 @@ public StackPanel PrepareResultStackPanel(LookupResult result, int index, int re
VerticalAlignment.Center,
new Thickness(2));

nanoriReadingsTextBox.PreviewMouseUp += TextBox_PreviewMouseUp;
nanoriReadingsTextBox.MouseMove += TextBox_MouseMove;
nanoriReadingsTextBox.LostFocus += Unselect;
nanoriReadingsTextBox.PreviewMouseRightButtonUp += TextBox_PreviewMouseRightButtonUp;
nanoriReadingsTextBox.MouseLeave += OnMouseLeave;
nanoriReadingsTextBox.PreviewMouseLeftButtonDown += TextBox_PreviewMouseLeftButtonDown;
AddEventHandlersToTextBox(nanoriReadingsTextBox);

_ = bottom.Children.Add(nanoriReadingsTextBox);
}

Expand Down Expand Up @@ -881,12 +862,8 @@ public StackPanel PrepareResultStackPanel(LookupResult result, int index, int re
VerticalAlignment.Center,
new Thickness(2));

radicalNameTextBox.PreviewMouseUp += TextBox_PreviewMouseUp;
radicalNameTextBox.MouseMove += TextBox_MouseMove;
radicalNameTextBox.LostFocus += Unselect;
radicalNameTextBox.PreviewMouseRightButtonUp += TextBox_PreviewMouseRightButtonUp;
radicalNameTextBox.MouseLeave += OnMouseLeave;
radicalNameTextBox.PreviewMouseLeftButtonDown += TextBox_PreviewMouseLeftButtonDown;
AddEventHandlersToTextBox(radicalNameTextBox);

_ = bottom.Children.Add(radicalNameTextBox);
}

Expand Down Expand Up @@ -940,12 +917,8 @@ public StackPanel PrepareResultStackPanel(LookupResult result, int index, int re
VerticalAlignment.Center,
new Thickness(2));

compositionTextBox.PreviewMouseUp += TextBox_PreviewMouseUp;
compositionTextBox.MouseMove += TextBox_MouseMove;
compositionTextBox.LostFocus += Unselect;
compositionTextBox.PreviewMouseRightButtonUp += TextBox_PreviewMouseRightButtonUp;
compositionTextBox.MouseLeave += OnMouseLeave;
compositionTextBox.PreviewMouseLeftButtonDown += TextBox_PreviewMouseLeftButtonDown;
AddEventHandlersToTextBox(compositionTextBox);

_ = bottom.Children.Add(compositionTextBox);
}

Expand Down

0 comments on commit 5e4ca11

Please sign in to comment.