Skip to content

Commit e9b4780

Browse files
committed
Allows mining by pressing the primary spelling, again. When clicking the Primary Spelling text box, the behavior of the "Lookup button" and "Enable mining mode" button will take precedence over this action.
Fixes #114
1 parent aaf0b54 commit e9b4780

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

JL.Windows/GUI/PopupWindow.xaml.cs

+39-2
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ private void DisplayResults()
565565
UpdateLayout();
566566
}
567567

568-
private void AddEventHandlersToTextBox(FrameworkElement textBox)
568+
private void AddEventHandlersToTextBox(TextBox textBox)
569569
{
570570
textBox.PreviewMouseUp += TextBox_PreviewMouseUp;
571571
textBox.MouseMove += TextBox_MouseMove;
@@ -585,6 +585,16 @@ private void AddEventHandlersToDefinitionsTextBox(TextBox textBox)
585585
textBox.PreviewMouseLeftButtonDown += DefinitionsTextBox_PreviewMouseLeftButtonDown;
586586
}
587587

588+
private void AddEventHandlersToPrimarySpellingTextBox(FrameworkElement textBox)
589+
{
590+
textBox.PreviewMouseUp += PrimarySpellingTextBox_PreviewMouseUp;
591+
textBox.MouseMove += TextBox_MouseMove;
592+
textBox.LostFocus += Unselect;
593+
textBox.PreviewMouseRightButtonUp += TextBox_PreviewMouseRightButtonUp;
594+
textBox.MouseLeave += OnMouseLeave;
595+
textBox.PreviewMouseLeftButtonDown += TextBox_PreviewMouseLeftButtonDown;
596+
}
597+
588598
private StackPanel PrepareResultStackPanel(LookupResult result, int index, int resultCount, bool showPOrthographyInfo, bool showROrthographyInfo, bool showAOrthographyInfo, double pOrthographyInfoFontSize, Button[]? miningButtons)
589599
{
590600
// top
@@ -606,7 +616,7 @@ private StackPanel PrepareResultStackPanel(LookupResult result, int index, int r
606616
new Thickness(2, 0, 0, 0),
607617
PopupContextMenu);
608618

609-
AddEventHandlersToTextBox(primarySpellingFrameworkElement);
619+
AddEventHandlersToPrimarySpellingTextBox(primarySpellingFrameworkElement);
610620
}
611621
else
612622
{
@@ -1868,6 +1878,33 @@ private async void TextBox_PreviewMouseUp(object sender, MouseButtonEventArgs e)
18681878
await HandleTextBoxMouseUp(textBox).ConfigureAwait(false);
18691879
}
18701880

1881+
// ReSharper disable once AsyncVoidMethod
1882+
private async void PrimarySpellingTextBox_PreviewMouseUp(object sender, MouseButtonEventArgs e)
1883+
{
1884+
TextBox textBox = (TextBox)sender;
1885+
_lastInteractedTextBox = textBox;
1886+
LastSelectedText = _lastInteractedTextBox.SelectedText;
1887+
1888+
ConfigManager configManager = ConfigManager.Instance;
1889+
if (configManager.InactiveLookupMode
1890+
|| (configManager.RequireLookupKeyPress && !configManager.LookupKeyKeyGesture.IsPressed())
1891+
|| ((!configManager.LookupOnSelectOnly || e.ChangedButton is not MouseButton.Left)
1892+
&& (!configManager.LookupOnMouseClickOnly || e.ChangedButton != configManager.LookupOnClickMouseButton)))
1893+
{
1894+
if ((configManager.LookupOnMouseClickOnly
1895+
|| configManager.LookupOnSelectOnly
1896+
|| e.ChangedButton != configManager.MiningModeMouseButton)
1897+
&& (e.ChangedButton == configManager.MinePrimarySpellingMouseButton))
1898+
{
1899+
await HandleMining(true).ConfigureAwait(false);
1900+
}
1901+
}
1902+
else
1903+
{
1904+
await HandleTextBoxMouseUp(textBox).ConfigureAwait(false);
1905+
}
1906+
}
1907+
18711908
private Task HandleTextBoxMouseUp(TextBox textBox)
18721909
{
18731910
ChildPopupWindow ??= new PopupWindow

JL.Windows/GUI/PreferencesWindow.xaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,9 @@
888888
Style="{StaticResource TextBlockDefault}"
889889
TextWrapping="Wrap" VerticalAlignment="Center"
890890
Cursor="Help"
891-
ToolTip="Sets the value of the "Selected Spelling" field to the primary spelling and mines the term"/>
891+
ToolTip="Sets the value of the "Selected Spelling" field to the primary spelling and mines the term.
892+

Can be used to mine the term by clicking either the ➕ button or the Primary Spelling text box.
893+

When clicking the Primary Spelling text box, the "Lookup button" and "'Enable mining mode' button" will take precedence over this action."/>
892894
<ComboBox x:Name="MinePrimarySpellingMouseButtonComboBox" HorizontalAlignment="Right"
893895
SelectedValuePath="Tag" Width="250">
894896
<ComboBoxItem Content="Left button" Tag="Left" />

0 commit comments

Comments
 (0)