Skip to content

Commit 1a85fca

Browse files
committed
use local function to make things slightly less ugly
1 parent 9031b2f commit 1a85fca

File tree

1 file changed

+77
-68
lines changed

1 file changed

+77
-68
lines changed

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 77 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,7 @@ public MainWindow(Settings settings, MainViewModel mainVM)
7373
};
7474
}
7575

76-
DispatcherTimer timer = new DispatcherTimer
77-
{
78-
Interval = new TimeSpan(0, 0, 0, 0, 500),
79-
IsEnabled = false
80-
};
76+
DispatcherTimer timer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 0, 500), IsEnabled = false };
8177

8278
public MainWindow()
8379
{
@@ -88,6 +84,7 @@ public MainWindow()
8884
private const int WM_EXITSIZEMOVE = 0x0232;
8985
private int _initialWidth;
9086
private int _initialHeight;
87+
9188
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
9289
{
9390
if (msg == WM_ENTERSIZEMOVE)
@@ -96,18 +93,22 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b
9693
_initialHeight = (int)Height;
9794
handled = true;
9895
}
96+
9997
if (msg == WM_EXITSIZEMOVE)
10098
{
101-
if ( _initialHeight != (int)Height)
99+
if (_initialHeight != (int)Height)
102100
{
103101
OnResizeEnd();
104102
}
103+
105104
if (_initialWidth != (int)Width)
106105
{
107106
FlowMainWindow.SizeToContent = SizeToContent.Height;
108107
}
108+
109109
handled = true;
110110
}
111+
111112
return IntPtr.Zero;
112113
}
113114

@@ -132,6 +133,7 @@ private void OnResizeEnd()
132133
_settings.MaxResultsToShow = Convert.ToInt32(Math.Truncate(itemCount));
133134
}
134135
}
136+
135137
FlowMainWindow.SizeToContent = SizeToContent.Height;
136138
_viewModel.MainWindowWidth = Width;
137139
}
@@ -176,6 +178,7 @@ private async void OnClosing(object sender, CancelEventArgs e)
176178
private void OnInitialized(object sender, EventArgs e)
177179
{
178180
}
181+
179182
private void OnLoaded(object sender, RoutedEventArgs _)
180183
{
181184
// MouseEventHandler
@@ -208,6 +211,7 @@ private void OnLoaded(object sender, RoutedEventArgs _)
208211
{
209212
SoundPlay();
210213
}
214+
211215
UpdatePosition();
212216
PreviewReset();
213217
Activate();
@@ -219,7 +223,8 @@ private void OnLoaded(object sender, RoutedEventArgs _)
219223
_viewModel.LastQuerySelected = true;
220224
}
221225

222-
if (_viewModel.ProgressBarVisibility == Visibility.Visible && isProgressBarStoryboardPaused)
226+
if (_viewModel.ProgressBarVisibility == Visibility.Visible &&
227+
isProgressBarStoryboardPaused)
223228
{
224229
_progressBarStoryboard.Begin(ProgressBar, true);
225230
isProgressBarStoryboardPaused = false;
@@ -260,9 +265,12 @@ private void OnLoaded(object sender, RoutedEventArgs _)
260265
MoveQueryTextToEnd();
261266
_viewModel.QueryTextCursorMovedToEnd = false;
262267
}
268+
263269
break;
264270
case nameof(MainViewModel.GameModeStatus):
265-
_notifyIcon.Icon = _viewModel.GameModeStatus ? Properties.Resources.gamemode : Properties.Resources.app;
271+
_notifyIcon.Icon = _viewModel.GameModeStatus
272+
? Properties.Resources.gamemode
273+
: Properties.Resources.app;
266274
break;
267275
}
268276
};
@@ -292,50 +300,58 @@ private void OnLoaded(object sender, RoutedEventArgs _)
292300

293301
private void InitializePosition()
294302
{
295-
if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation)
296-
{
297-
Top = _settings.WindowTop;
298-
Left = _settings.WindowLeft;
299-
}
300-
else
303+
InitializePositionInner();
304+
InitializePositionInner();
305+
return;
306+
307+
void InitializePositionInner()
301308
{
302-
var screen = SelectedScreen();
303-
switch (_settings.SearchWindowAlign)
309+
if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation)
304310
{
305-
case SearchWindowAligns.Center:
306-
Left = HorizonCenter(screen);
307-
Top = VerticalCenter(screen);
308-
break;
309-
case SearchWindowAligns.CenterTop:
310-
Left = HorizonCenter(screen);
311-
Top = 10;
312-
break;
313-
case SearchWindowAligns.LeftTop:
314-
Left = HorizonLeft(screen);
315-
Top = 10;
316-
break;
317-
case SearchWindowAligns.RightTop:
318-
Left = HorizonRight(screen);
319-
Top = 10;
320-
break;
321-
case SearchWindowAligns.Custom:
322-
Left = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X + _settings.CustomWindowLeft, 0).X;
323-
Top = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y + _settings.CustomWindowTop).Y;
324-
break;
311+
Top = _settings.WindowTop;
312+
Left = _settings.WindowLeft;
313+
}
314+
else
315+
{
316+
var screen = SelectedScreen();
317+
switch (_settings.SearchWindowAlign)
318+
{
319+
case SearchWindowAligns.Center:
320+
Left = HorizonCenter(screen);
321+
Top = VerticalCenter(screen);
322+
break;
323+
case SearchWindowAligns.CenterTop:
324+
Left = HorizonCenter(screen);
325+
Top = 10;
326+
break;
327+
case SearchWindowAligns.LeftTop:
328+
Left = HorizonLeft(screen);
329+
Top = 10;
330+
break;
331+
case SearchWindowAligns.RightTop:
332+
Left = HorizonRight(screen);
333+
Top = 10;
334+
break;
335+
case SearchWindowAligns.Custom:
336+
Left = WindowsInteropHelper.TransformPixelsToDIP(this,
337+
screen.WorkingArea.X + _settings.CustomWindowLeft, 0).X;
338+
Top = WindowsInteropHelper.TransformPixelsToDIP(this, 0,
339+
screen.WorkingArea.Y + _settings.CustomWindowTop).Y;
340+
break;
341+
}
325342
}
326343
}
327-
328344
}
329345

330346
private void UpdateNotifyIconText()
331347
{
332348
var menu = contextMenu;
333-
((MenuItem)menu.Items[0]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")";
349+
((MenuItem)menu.Items[0]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") +
350+
" (" + _settings.Hotkey + ")";
334351
((MenuItem)menu.Items[1]).Header = InternationalizationManager.Instance.GetTranslation("GameMode");
335352
((MenuItem)menu.Items[2]).Header = InternationalizationManager.Instance.GetTranslation("PositionReset");
336353
((MenuItem)menu.Items[3]).Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings");
337354
((MenuItem)menu.Items[4]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit");
338-
339355
}
340356

341357
private void InitializeNotifyIcon()
@@ -347,50 +363,34 @@ private void InitializeNotifyIcon()
347363
Visible = !_settings.HideNotifyIcon
348364
};
349365

350-
var openIcon = new FontIcon
351-
{
352-
Glyph = "\ue71e"
353-
};
366+
var openIcon = new FontIcon { Glyph = "\ue71e" };
354367
var open = new MenuItem
355368
{
356-
Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")",
369+
Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" +
370+
_settings.Hotkey + ")",
357371
Icon = openIcon
358372
};
359-
var gamemodeIcon = new FontIcon
360-
{
361-
Glyph = "\ue7fc"
362-
};
373+
var gamemodeIcon = new FontIcon { Glyph = "\ue7fc" };
363374
var gamemode = new MenuItem
364375
{
365-
Header = InternationalizationManager.Instance.GetTranslation("GameMode"),
366-
Icon = gamemodeIcon
367-
};
368-
var positionresetIcon = new FontIcon
369-
{
370-
Glyph = "\ue73f"
376+
Header = InternationalizationManager.Instance.GetTranslation("GameMode"), Icon = gamemodeIcon
371377
};
378+
var positionresetIcon = new FontIcon { Glyph = "\ue73f" };
372379
var positionreset = new MenuItem
373380
{
374381
Header = InternationalizationManager.Instance.GetTranslation("PositionReset"),
375382
Icon = positionresetIcon
376383
};
377-
var settingsIcon = new FontIcon
378-
{
379-
Glyph = "\ue713"
380-
};
384+
var settingsIcon = new FontIcon { Glyph = "\ue713" };
381385
var settings = new MenuItem
382386
{
383387
Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings"),
384388
Icon = settingsIcon
385389
};
386-
var exitIcon = new FontIcon
387-
{
388-
Glyph = "\ue7e8"
389-
};
390+
var exitIcon = new FontIcon { Glyph = "\ue7e8" };
390391
var exit = new MenuItem
391392
{
392-
Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"),
393-
Icon = exitIcon
393+
Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"), Icon = exitIcon
394394
};
395395

396396
open.Click += (o, e) => _viewModel.ToggleFlowLauncher();
@@ -423,6 +423,7 @@ private void InitializeNotifyIcon()
423423
{
424424
_ = SetForegroundWindow(hwndSource.Handle);
425425
}
426+
426427
contextMenu.Focus();
427428
break;
428429
}
@@ -456,8 +457,10 @@ private async void PositionReset()
456457

457458
private void InitProgressbarAnimation()
458459
{
459-
var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 100, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
460-
var da1 = new DoubleAnimation(ProgressBar.X1, ActualWidth + 0, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
460+
var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 100,
461+
new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
462+
var da1 = new DoubleAnimation(ProgressBar.X1, ActualWidth + 0,
463+
new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
461464
Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X2)"));
462465
Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X1)"));
463466
_progressBarStoryboard.Children.Add(da);
@@ -567,6 +570,7 @@ public void WindowAnimator()
567570
{
568571
clocksb.Begin(ClockPanel);
569572
}
573+
570574
iconsb.Begin(SearchIcon);
571575
windowsb.Begin(FlowMainWindow);
572576
}
@@ -674,7 +678,7 @@ public void HideStartup()
674678
public Screen SelectedScreen()
675679
{
676680
Screen screen = null;
677-
switch(_settings.SearchWindowScreen)
681+
switch (_settings.SearchWindowScreen)
678682
{
679683
case SearchWindowScreens.Cursor:
680684
screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
@@ -696,6 +700,7 @@ public Screen SelectedScreen()
696700
screen = Screen.AllScreens[0];
697701
break;
698702
}
703+
699704
return screen ?? Screen.AllScreens[0];
700705
}
701706

@@ -765,13 +770,15 @@ private void OnKeyDown(object sender, KeyEventArgs e)
765770
_viewModel.LoadContextMenuCommand.Execute(null);
766771
e.Handled = true;
767772
}
773+
768774
break;
769775
case Key.Left:
770776
if (!_viewModel.SelectedIsFromQueryResults() && QueryTextBox.CaretIndex == 0)
771777
{
772778
_viewModel.EscCommand.Execute(null);
773779
e.Handled = true;
774780
}
781+
775782
break;
776783
case Key.Back:
777784
if (specialKeyState.CtrlPressed)
@@ -790,12 +797,13 @@ private void OnKeyDown(object sender, KeyEventArgs e)
790797
}
791798
}
792799
}
800+
793801
break;
794802
default:
795803
break;
796-
797804
}
798805
}
806+
799807
private void OnKeyUp(object sender, KeyEventArgs e)
800808
{
801809
if (e.Key == Key.Up || e.Key == Key.Down)
@@ -811,6 +819,7 @@ private void MainPreviewMouseMove(object sender, System.Windows.Input.MouseEvent
811819
e.Handled = true; // Ignore Mouse Hover when press Arrowkeys
812820
}
813821
}
822+
814823
public void PreviewReset()
815824
{
816825
_viewModel.ResetPreview();

0 commit comments

Comments
 (0)