5
5
using JL . Core . Lookup ;
6
6
using JL . Core . Mining ;
7
7
using JL . Windows . Utilities ;
8
- using Rectangle = System . Drawing . Rectangle ;
9
8
10
9
namespace JL . Windows . GUI ;
11
10
@@ -18,24 +17,20 @@ internal sealed partial class MiningSelectionWindow
18
17
private readonly LookupResult [ ] _lookupResults ;
19
18
private readonly int _currentLookupResultIndex ;
20
19
private readonly string _currentSourceText ;
21
- private readonly string ? _formattedDefinitions ;
22
- private readonly string ? _selectedDefinitions ;
23
20
private readonly int _currentSourceTextCharPosition ;
24
21
25
22
private nint _windowHandle ;
26
23
27
24
private static MiningSelectionWindow ? s_instance ;
28
25
29
- private MiningSelectionWindow ( PopupWindow owner , LookupResult [ ] lookupResults , int currentLookupResultIndex , string currentSourceText , string ? formattedDefinitions , string ? selectedDefinitions , int currentSourceTextCharPosition )
26
+ private MiningSelectionWindow ( PopupWindow owner , LookupResult [ ] lookupResults , int currentLookupResultIndex , string currentSourceText , int currentSourceTextCharPosition )
30
27
{
31
28
InitializeComponent ( ) ;
32
29
Owner = owner ;
33
30
_popupWindow = owner ;
34
31
_lookupResults = lookupResults ;
35
32
_currentLookupResultIndex = currentLookupResultIndex ;
36
33
_currentSourceText = currentSourceText ;
37
- _formattedDefinitions = formattedDefinitions ;
38
- _selectedDefinitions = selectedDefinitions ;
39
34
_currentSourceTextCharPosition = currentSourceTextCharPosition ;
40
35
}
41
36
@@ -44,9 +39,9 @@ public static bool IsItVisible()
44
39
return s_instance ? . IsVisible ?? false ;
45
40
}
46
41
47
- internal static void Show ( PopupWindow owner , LookupResult [ ] lookupResults , int currentLookupResultIndex , string currentSourceText , string ? formattedDefinitions , string ? selectedDefinitions , int currentSourceTextCharPosition )
42
+ internal static void Show ( PopupWindow owner , LookupResult [ ] lookupResults , int currentLookupResultIndex , string currentSourceText , int currentSourceTextCharPosition )
48
43
{
49
- MiningSelectionWindow currentInstance = s_instance ??= new MiningSelectionWindow ( owner , lookupResults , currentLookupResultIndex , currentSourceText , formattedDefinitions , selectedDefinitions , currentSourceTextCharPosition ) ;
44
+ MiningSelectionWindow currentInstance = s_instance ??= new MiningSelectionWindow ( owner , lookupResults , currentLookupResultIndex , currentSourceText , currentSourceTextCharPosition ) ;
50
45
ConfigManager configManager = ConfigManager . Instance ;
51
46
52
47
ListViewItem [ ] listViewItem ;
@@ -73,7 +68,7 @@ internal static void Show(PopupWindow owner, LookupResult[] lookupResults, int c
73
68
currentInstance . FontFamily = configManager . PopupFont ;
74
69
currentInstance . Owner = owner ;
75
70
currentInstance . Show ( ) ;
76
- currentInstance . UpdatePosition ( WinApi . GetMousePosition ( ) ) ;
71
+ WindowsUtils . UpdatePositionForSelectionWindows ( currentInstance , currentInstance . _windowHandle , WinApi . GetMousePosition ( ) ) ;
77
72
78
73
if ( configManager . Focusable )
79
74
{
@@ -105,81 +100,22 @@ protected override void OnActivated(EventArgs e)
105
100
// ReSharper disable once AsyncVoidMethod
106
101
private async void MiningListView_PreviewMouseUp ( object sender , MouseButtonEventArgs e )
107
102
{
103
+ TextBox ? definitionsTextBox = _popupWindow . GetDefinitionTextBox ( _currentLookupResultIndex ) ;
104
+ string ? formattedDefinitions = definitionsTextBox ? . Text ;
105
+ string ? selectedDefinitions = PopupWindowUtils . GetSelectedDefinitions ( definitionsTextBox ) ;
106
+
108
107
string selectedSpelling = ( string ) ( ( ListViewItem ) sender ) . Content ;
109
108
_popupWindow . HidePopup ( ) ;
110
109
111
110
ConfigManager configManager = ConfigManager . Instance ;
112
111
if ( configManager . MineToFileInsteadOfAnki )
113
112
{
114
- await MiningUtils . MineToFile ( _lookupResults , _currentLookupResultIndex , _currentSourceText , _formattedDefinitions , _selectedDefinitions , _currentSourceTextCharPosition , selectedSpelling ) . ConfigureAwait ( false ) ;
115
- }
116
- else
117
- {
118
- await MiningUtils . Mine ( _lookupResults , _currentLookupResultIndex , _currentSourceText , _formattedDefinitions , _selectedDefinitions , _currentSourceTextCharPosition , selectedSpelling ) . ConfigureAwait ( false ) ;
119
- }
120
- }
121
-
122
- private void UpdatePosition ( Point cursorPosition )
123
- {
124
- double mouseX = cursorPosition . X ;
125
- double mouseY = cursorPosition . Y ;
126
-
127
- DpiScale dpi = WindowsUtils . Dpi ;
128
- double currentWidth = ActualWidth * dpi . DpiScaleX ;
129
- double currentHeight = ActualHeight * dpi . DpiScaleY ;
130
-
131
- double dpiAwareXOffSet = 5 * dpi . DpiScaleX ;
132
- double dpiAwareYOffset = 15 * dpi . DpiScaleY ;
133
-
134
- Rectangle bounds = WindowsUtils . ActiveScreen . Bounds ;
135
- bool needsFlipX = mouseX + currentWidth > bounds . Right ;
136
- bool needsFlipY = mouseY + currentHeight > bounds . Bottom ;
137
-
138
- double newLeft ;
139
- double newTop ;
140
-
141
- if ( needsFlipX )
142
- {
143
- // flip Leftwards while preventing -OOB
144
- newLeft = mouseX - currentWidth - dpiAwareXOffSet ;
145
- if ( newLeft < bounds . X )
146
- {
147
- newLeft = bounds . X ;
148
- }
113
+ await MiningUtils . MineToFile ( _lookupResults , _currentLookupResultIndex , _currentSourceText , formattedDefinitions , selectedDefinitions , _currentSourceTextCharPosition , selectedSpelling ) . ConfigureAwait ( false ) ;
149
114
}
150
115
else
151
116
{
152
- // no flip
153
- newLeft = mouseX - dpiAwareXOffSet ;
117
+ await MiningUtils . Mine ( _lookupResults , _currentLookupResultIndex , _currentSourceText , formattedDefinitions , selectedDefinitions , _currentSourceTextCharPosition , selectedSpelling ) . ConfigureAwait ( false ) ;
154
118
}
155
-
156
- if ( needsFlipY )
157
- {
158
- // flip Upwards while preventing -OOB
159
- newTop = mouseY - ( currentHeight + dpiAwareYOffset ) ;
160
- if ( newTop < bounds . Y )
161
- {
162
- newTop = bounds . Y ;
163
- }
164
- }
165
- else
166
- {
167
- // no flip
168
- newTop = mouseY + dpiAwareYOffset ;
169
- }
170
-
171
- // stick to edges if +OOB
172
- if ( newLeft + currentWidth > bounds . Right )
173
- {
174
- newLeft = bounds . Right - currentWidth ;
175
- }
176
-
177
- if ( newTop + currentHeight > bounds . Bottom )
178
- {
179
- newTop = bounds . Bottom - currentHeight ;
180
- }
181
-
182
- WinApi . MoveWindowToPosition ( _windowHandle , newLeft , newTop ) ;
183
119
}
184
120
185
121
public static void CloseWindow ( )
0 commit comments