mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
use local function to make things slightly less ugly
This commit is contained in:
parent
9031b2ffee
commit
1a85fca430
1 changed files with 77 additions and 68 deletions
|
|
@ -73,11 +73,7 @@ namespace Flow.Launcher
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
DispatcherTimer timer = new DispatcherTimer
|
DispatcherTimer timer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 0, 500), IsEnabled = false };
|
||||||
{
|
|
||||||
Interval = new TimeSpan(0, 0, 0, 0, 500),
|
|
||||||
IsEnabled = false
|
|
||||||
};
|
|
||||||
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
|
|
@ -88,6 +84,7 @@ namespace Flow.Launcher
|
||||||
private const int WM_EXITSIZEMOVE = 0x0232;
|
private const int WM_EXITSIZEMOVE = 0x0232;
|
||||||
private int _initialWidth;
|
private int _initialWidth;
|
||||||
private int _initialHeight;
|
private int _initialHeight;
|
||||||
|
|
||||||
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
|
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
|
||||||
{
|
{
|
||||||
if (msg == WM_ENTERSIZEMOVE)
|
if (msg == WM_ENTERSIZEMOVE)
|
||||||
|
|
@ -96,18 +93,22 @@ namespace Flow.Launcher
|
||||||
_initialHeight = (int)Height;
|
_initialHeight = (int)Height;
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg == WM_EXITSIZEMOVE)
|
if (msg == WM_EXITSIZEMOVE)
|
||||||
{
|
{
|
||||||
if ( _initialHeight != (int)Height)
|
if (_initialHeight != (int)Height)
|
||||||
{
|
{
|
||||||
OnResizeEnd();
|
OnResizeEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_initialWidth != (int)Width)
|
if (_initialWidth != (int)Width)
|
||||||
{
|
{
|
||||||
FlowMainWindow.SizeToContent = SizeToContent.Height;
|
FlowMainWindow.SizeToContent = SizeToContent.Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return IntPtr.Zero;
|
return IntPtr.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -132,6 +133,7 @@ namespace Flow.Launcher
|
||||||
_settings.MaxResultsToShow = Convert.ToInt32(Math.Truncate(itemCount));
|
_settings.MaxResultsToShow = Convert.ToInt32(Math.Truncate(itemCount));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FlowMainWindow.SizeToContent = SizeToContent.Height;
|
FlowMainWindow.SizeToContent = SizeToContent.Height;
|
||||||
_viewModel.MainWindowWidth = Width;
|
_viewModel.MainWindowWidth = Width;
|
||||||
}
|
}
|
||||||
|
|
@ -176,6 +178,7 @@ namespace Flow.Launcher
|
||||||
private void OnInitialized(object sender, EventArgs e)
|
private void OnInitialized(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnLoaded(object sender, RoutedEventArgs _)
|
private void OnLoaded(object sender, RoutedEventArgs _)
|
||||||
{
|
{
|
||||||
// MouseEventHandler
|
// MouseEventHandler
|
||||||
|
|
@ -208,6 +211,7 @@ namespace Flow.Launcher
|
||||||
{
|
{
|
||||||
SoundPlay();
|
SoundPlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdatePosition();
|
UpdatePosition();
|
||||||
PreviewReset();
|
PreviewReset();
|
||||||
Activate();
|
Activate();
|
||||||
|
|
@ -219,7 +223,8 @@ namespace Flow.Launcher
|
||||||
_viewModel.LastQuerySelected = true;
|
_viewModel.LastQuerySelected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_viewModel.ProgressBarVisibility == Visibility.Visible && isProgressBarStoryboardPaused)
|
if (_viewModel.ProgressBarVisibility == Visibility.Visible &&
|
||||||
|
isProgressBarStoryboardPaused)
|
||||||
{
|
{
|
||||||
_progressBarStoryboard.Begin(ProgressBar, true);
|
_progressBarStoryboard.Begin(ProgressBar, true);
|
||||||
isProgressBarStoryboardPaused = false;
|
isProgressBarStoryboardPaused = false;
|
||||||
|
|
@ -260,9 +265,12 @@ namespace Flow.Launcher
|
||||||
MoveQueryTextToEnd();
|
MoveQueryTextToEnd();
|
||||||
_viewModel.QueryTextCursorMovedToEnd = false;
|
_viewModel.QueryTextCursorMovedToEnd = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case nameof(MainViewModel.GameModeStatus):
|
case nameof(MainViewModel.GameModeStatus):
|
||||||
_notifyIcon.Icon = _viewModel.GameModeStatus ? Properties.Resources.gamemode : Properties.Resources.app;
|
_notifyIcon.Icon = _viewModel.GameModeStatus
|
||||||
|
? Properties.Resources.gamemode
|
||||||
|
: Properties.Resources.app;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -292,50 +300,58 @@ namespace Flow.Launcher
|
||||||
|
|
||||||
private void InitializePosition()
|
private void InitializePosition()
|
||||||
{
|
{
|
||||||
if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation)
|
InitializePositionInner();
|
||||||
|
InitializePositionInner();
|
||||||
|
return;
|
||||||
|
|
||||||
|
void InitializePositionInner()
|
||||||
{
|
{
|
||||||
Top = _settings.WindowTop;
|
if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation)
|
||||||
Left = _settings.WindowLeft;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var screen = SelectedScreen();
|
|
||||||
switch (_settings.SearchWindowAlign)
|
|
||||||
{
|
{
|
||||||
case SearchWindowAligns.Center:
|
Top = _settings.WindowTop;
|
||||||
Left = HorizonCenter(screen);
|
Left = _settings.WindowLeft;
|
||||||
Top = VerticalCenter(screen);
|
}
|
||||||
break;
|
else
|
||||||
case SearchWindowAligns.CenterTop:
|
{
|
||||||
Left = HorizonCenter(screen);
|
var screen = SelectedScreen();
|
||||||
Top = 10;
|
switch (_settings.SearchWindowAlign)
|
||||||
break;
|
{
|
||||||
case SearchWindowAligns.LeftTop:
|
case SearchWindowAligns.Center:
|
||||||
Left = HorizonLeft(screen);
|
Left = HorizonCenter(screen);
|
||||||
Top = 10;
|
Top = VerticalCenter(screen);
|
||||||
break;
|
break;
|
||||||
case SearchWindowAligns.RightTop:
|
case SearchWindowAligns.CenterTop:
|
||||||
Left = HorizonRight(screen);
|
Left = HorizonCenter(screen);
|
||||||
Top = 10;
|
Top = 10;
|
||||||
break;
|
break;
|
||||||
case SearchWindowAligns.Custom:
|
case SearchWindowAligns.LeftTop:
|
||||||
Left = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X + _settings.CustomWindowLeft, 0).X;
|
Left = HorizonLeft(screen);
|
||||||
Top = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y + _settings.CustomWindowTop).Y;
|
Top = 10;
|
||||||
break;
|
break;
|
||||||
|
case SearchWindowAligns.RightTop:
|
||||||
|
Left = HorizonRight(screen);
|
||||||
|
Top = 10;
|
||||||
|
break;
|
||||||
|
case SearchWindowAligns.Custom:
|
||||||
|
Left = WindowsInteropHelper.TransformPixelsToDIP(this,
|
||||||
|
screen.WorkingArea.X + _settings.CustomWindowLeft, 0).X;
|
||||||
|
Top = WindowsInteropHelper.TransformPixelsToDIP(this, 0,
|
||||||
|
screen.WorkingArea.Y + _settings.CustomWindowTop).Y;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateNotifyIconText()
|
private void UpdateNotifyIconText()
|
||||||
{
|
{
|
||||||
var menu = contextMenu;
|
var menu = contextMenu;
|
||||||
((MenuItem)menu.Items[0]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")";
|
((MenuItem)menu.Items[0]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") +
|
||||||
|
" (" + _settings.Hotkey + ")";
|
||||||
((MenuItem)menu.Items[1]).Header = InternationalizationManager.Instance.GetTranslation("GameMode");
|
((MenuItem)menu.Items[1]).Header = InternationalizationManager.Instance.GetTranslation("GameMode");
|
||||||
((MenuItem)menu.Items[2]).Header = InternationalizationManager.Instance.GetTranslation("PositionReset");
|
((MenuItem)menu.Items[2]).Header = InternationalizationManager.Instance.GetTranslation("PositionReset");
|
||||||
((MenuItem)menu.Items[3]).Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings");
|
((MenuItem)menu.Items[3]).Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings");
|
||||||
((MenuItem)menu.Items[4]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit");
|
((MenuItem)menu.Items[4]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitializeNotifyIcon()
|
private void InitializeNotifyIcon()
|
||||||
|
|
@ -347,50 +363,34 @@ namespace Flow.Launcher
|
||||||
Visible = !_settings.HideNotifyIcon
|
Visible = !_settings.HideNotifyIcon
|
||||||
};
|
};
|
||||||
|
|
||||||
var openIcon = new FontIcon
|
var openIcon = new FontIcon { Glyph = "\ue71e" };
|
||||||
{
|
|
||||||
Glyph = "\ue71e"
|
|
||||||
};
|
|
||||||
var open = new MenuItem
|
var open = new MenuItem
|
||||||
{
|
{
|
||||||
Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")",
|
Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" +
|
||||||
|
_settings.Hotkey + ")",
|
||||||
Icon = openIcon
|
Icon = openIcon
|
||||||
};
|
};
|
||||||
var gamemodeIcon = new FontIcon
|
var gamemodeIcon = new FontIcon { Glyph = "\ue7fc" };
|
||||||
{
|
|
||||||
Glyph = "\ue7fc"
|
|
||||||
};
|
|
||||||
var gamemode = new MenuItem
|
var gamemode = new MenuItem
|
||||||
{
|
{
|
||||||
Header = InternationalizationManager.Instance.GetTranslation("GameMode"),
|
Header = InternationalizationManager.Instance.GetTranslation("GameMode"), Icon = gamemodeIcon
|
||||||
Icon = gamemodeIcon
|
|
||||||
};
|
|
||||||
var positionresetIcon = new FontIcon
|
|
||||||
{
|
|
||||||
Glyph = "\ue73f"
|
|
||||||
};
|
};
|
||||||
|
var positionresetIcon = new FontIcon { Glyph = "\ue73f" };
|
||||||
var positionreset = new MenuItem
|
var positionreset = new MenuItem
|
||||||
{
|
{
|
||||||
Header = InternationalizationManager.Instance.GetTranslation("PositionReset"),
|
Header = InternationalizationManager.Instance.GetTranslation("PositionReset"),
|
||||||
Icon = positionresetIcon
|
Icon = positionresetIcon
|
||||||
};
|
};
|
||||||
var settingsIcon = new FontIcon
|
var settingsIcon = new FontIcon { Glyph = "\ue713" };
|
||||||
{
|
|
||||||
Glyph = "\ue713"
|
|
||||||
};
|
|
||||||
var settings = new MenuItem
|
var settings = new MenuItem
|
||||||
{
|
{
|
||||||
Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings"),
|
Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings"),
|
||||||
Icon = settingsIcon
|
Icon = settingsIcon
|
||||||
};
|
};
|
||||||
var exitIcon = new FontIcon
|
var exitIcon = new FontIcon { Glyph = "\ue7e8" };
|
||||||
{
|
|
||||||
Glyph = "\ue7e8"
|
|
||||||
};
|
|
||||||
var exit = new MenuItem
|
var exit = new MenuItem
|
||||||
{
|
{
|
||||||
Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"),
|
Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"), Icon = exitIcon
|
||||||
Icon = exitIcon
|
|
||||||
};
|
};
|
||||||
|
|
||||||
open.Click += (o, e) => _viewModel.ToggleFlowLauncher();
|
open.Click += (o, e) => _viewModel.ToggleFlowLauncher();
|
||||||
|
|
@ -423,6 +423,7 @@ namespace Flow.Launcher
|
||||||
{
|
{
|
||||||
_ = SetForegroundWindow(hwndSource.Handle);
|
_ = SetForegroundWindow(hwndSource.Handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
contextMenu.Focus();
|
contextMenu.Focus();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -456,8 +457,10 @@ namespace Flow.Launcher
|
||||||
|
|
||||||
private void InitProgressbarAnimation()
|
private void InitProgressbarAnimation()
|
||||||
{
|
{
|
||||||
var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 100, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
|
var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 100,
|
||||||
var da1 = new DoubleAnimation(ProgressBar.X1, ActualWidth + 0, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
|
new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
|
||||||
|
var da1 = new DoubleAnimation(ProgressBar.X1, ActualWidth + 0,
|
||||||
|
new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
|
||||||
Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X2)"));
|
Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X2)"));
|
||||||
Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X1)"));
|
Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X1)"));
|
||||||
_progressBarStoryboard.Children.Add(da);
|
_progressBarStoryboard.Children.Add(da);
|
||||||
|
|
@ -567,6 +570,7 @@ namespace Flow.Launcher
|
||||||
{
|
{
|
||||||
clocksb.Begin(ClockPanel);
|
clocksb.Begin(ClockPanel);
|
||||||
}
|
}
|
||||||
|
|
||||||
iconsb.Begin(SearchIcon);
|
iconsb.Begin(SearchIcon);
|
||||||
windowsb.Begin(FlowMainWindow);
|
windowsb.Begin(FlowMainWindow);
|
||||||
}
|
}
|
||||||
|
|
@ -674,7 +678,7 @@ namespace Flow.Launcher
|
||||||
public Screen SelectedScreen()
|
public Screen SelectedScreen()
|
||||||
{
|
{
|
||||||
Screen screen = null;
|
Screen screen = null;
|
||||||
switch(_settings.SearchWindowScreen)
|
switch (_settings.SearchWindowScreen)
|
||||||
{
|
{
|
||||||
case SearchWindowScreens.Cursor:
|
case SearchWindowScreens.Cursor:
|
||||||
screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
|
screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
|
||||||
|
|
@ -696,6 +700,7 @@ namespace Flow.Launcher
|
||||||
screen = Screen.AllScreens[0];
|
screen = Screen.AllScreens[0];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return screen ?? Screen.AllScreens[0];
|
return screen ?? Screen.AllScreens[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -765,6 +770,7 @@ namespace Flow.Launcher
|
||||||
_viewModel.LoadContextMenuCommand.Execute(null);
|
_viewModel.LoadContextMenuCommand.Execute(null);
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case Key.Left:
|
case Key.Left:
|
||||||
if (!_viewModel.SelectedIsFromQueryResults() && QueryTextBox.CaretIndex == 0)
|
if (!_viewModel.SelectedIsFromQueryResults() && QueryTextBox.CaretIndex == 0)
|
||||||
|
|
@ -772,6 +778,7 @@ namespace Flow.Launcher
|
||||||
_viewModel.EscCommand.Execute(null);
|
_viewModel.EscCommand.Execute(null);
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case Key.Back:
|
case Key.Back:
|
||||||
if (specialKeyState.CtrlPressed)
|
if (specialKeyState.CtrlPressed)
|
||||||
|
|
@ -790,12 +797,13 @@ namespace Flow.Launcher
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnKeyUp(object sender, KeyEventArgs e)
|
private void OnKeyUp(object sender, KeyEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Key == Key.Up || e.Key == Key.Down)
|
if (e.Key == Key.Up || e.Key == Key.Down)
|
||||||
|
|
@ -811,6 +819,7 @@ namespace Flow.Launcher
|
||||||
e.Handled = true; // Ignore Mouse Hover when press Arrowkeys
|
e.Handled = true; // Ignore Mouse Hover when press Arrowkeys
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PreviewReset()
|
public void PreviewReset()
|
||||||
{
|
{
|
||||||
_viewModel.ResetPreview();
|
_viewModel.ResetPreview();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue