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
|
||||
{
|
||||
Interval = new TimeSpan(0, 0, 0, 0, 500),
|
||||
IsEnabled = false
|
||||
};
|
||||
DispatcherTimer timer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 0, 500), IsEnabled = false };
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
|
|
@ -88,6 +84,7 @@ namespace Flow.Launcher
|
|||
private const int WM_EXITSIZEMOVE = 0x0232;
|
||||
private int _initialWidth;
|
||||
private int _initialHeight;
|
||||
|
||||
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
|
||||
{
|
||||
if (msg == WM_ENTERSIZEMOVE)
|
||||
|
|
@ -96,18 +93,22 @@ namespace Flow.Launcher
|
|||
_initialHeight = (int)Height;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
if (msg == WM_EXITSIZEMOVE)
|
||||
{
|
||||
if ( _initialHeight != (int)Height)
|
||||
if (_initialHeight != (int)Height)
|
||||
{
|
||||
OnResizeEnd();
|
||||
}
|
||||
|
||||
if (_initialWidth != (int)Width)
|
||||
{
|
||||
FlowMainWindow.SizeToContent = SizeToContent.Height;
|
||||
}
|
||||
|
||||
handled = true;
|
||||
}
|
||||
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
|
|
@ -132,6 +133,7 @@ namespace Flow.Launcher
|
|||
_settings.MaxResultsToShow = Convert.ToInt32(Math.Truncate(itemCount));
|
||||
}
|
||||
}
|
||||
|
||||
FlowMainWindow.SizeToContent = SizeToContent.Height;
|
||||
_viewModel.MainWindowWidth = Width;
|
||||
}
|
||||
|
|
@ -176,6 +178,7 @@ namespace Flow.Launcher
|
|||
private void OnInitialized(object sender, EventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
private void OnLoaded(object sender, RoutedEventArgs _)
|
||||
{
|
||||
// MouseEventHandler
|
||||
|
|
@ -208,6 +211,7 @@ namespace Flow.Launcher
|
|||
{
|
||||
SoundPlay();
|
||||
}
|
||||
|
||||
UpdatePosition();
|
||||
PreviewReset();
|
||||
Activate();
|
||||
|
|
@ -219,7 +223,8 @@ namespace Flow.Launcher
|
|||
_viewModel.LastQuerySelected = true;
|
||||
}
|
||||
|
||||
if (_viewModel.ProgressBarVisibility == Visibility.Visible && isProgressBarStoryboardPaused)
|
||||
if (_viewModel.ProgressBarVisibility == Visibility.Visible &&
|
||||
isProgressBarStoryboardPaused)
|
||||
{
|
||||
_progressBarStoryboard.Begin(ProgressBar, true);
|
||||
isProgressBarStoryboardPaused = false;
|
||||
|
|
@ -260,9 +265,12 @@ namespace Flow.Launcher
|
|||
MoveQueryTextToEnd();
|
||||
_viewModel.QueryTextCursorMovedToEnd = false;
|
||||
}
|
||||
|
||||
break;
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
|
@ -292,50 +300,58 @@ namespace Flow.Launcher
|
|||
|
||||
private void InitializePosition()
|
||||
{
|
||||
if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation)
|
||||
InitializePositionInner();
|
||||
InitializePositionInner();
|
||||
return;
|
||||
|
||||
void InitializePositionInner()
|
||||
{
|
||||
Top = _settings.WindowTop;
|
||||
Left = _settings.WindowLeft;
|
||||
}
|
||||
else
|
||||
{
|
||||
var screen = SelectedScreen();
|
||||
switch (_settings.SearchWindowAlign)
|
||||
if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation)
|
||||
{
|
||||
case SearchWindowAligns.Center:
|
||||
Left = HorizonCenter(screen);
|
||||
Top = VerticalCenter(screen);
|
||||
break;
|
||||
case SearchWindowAligns.CenterTop:
|
||||
Left = HorizonCenter(screen);
|
||||
Top = 10;
|
||||
break;
|
||||
case SearchWindowAligns.LeftTop:
|
||||
Left = HorizonLeft(screen);
|
||||
Top = 10;
|
||||
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;
|
||||
Top = _settings.WindowTop;
|
||||
Left = _settings.WindowLeft;
|
||||
}
|
||||
else
|
||||
{
|
||||
var screen = SelectedScreen();
|
||||
switch (_settings.SearchWindowAlign)
|
||||
{
|
||||
case SearchWindowAligns.Center:
|
||||
Left = HorizonCenter(screen);
|
||||
Top = VerticalCenter(screen);
|
||||
break;
|
||||
case SearchWindowAligns.CenterTop:
|
||||
Left = HorizonCenter(screen);
|
||||
Top = 10;
|
||||
break;
|
||||
case SearchWindowAligns.LeftTop:
|
||||
Left = HorizonLeft(screen);
|
||||
Top = 10;
|
||||
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()
|
||||
{
|
||||
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[2]).Header = InternationalizationManager.Instance.GetTranslation("PositionReset");
|
||||
((MenuItem)menu.Items[3]).Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings");
|
||||
((MenuItem)menu.Items[4]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit");
|
||||
|
||||
}
|
||||
|
||||
private void InitializeNotifyIcon()
|
||||
|
|
@ -347,50 +363,34 @@ namespace Flow.Launcher
|
|||
Visible = !_settings.HideNotifyIcon
|
||||
};
|
||||
|
||||
var openIcon = new FontIcon
|
||||
{
|
||||
Glyph = "\ue71e"
|
||||
};
|
||||
var openIcon = new FontIcon { Glyph = "\ue71e" };
|
||||
var open = new MenuItem
|
||||
{
|
||||
Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")",
|
||||
Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" +
|
||||
_settings.Hotkey + ")",
|
||||
Icon = openIcon
|
||||
};
|
||||
var gamemodeIcon = new FontIcon
|
||||
{
|
||||
Glyph = "\ue7fc"
|
||||
};
|
||||
var gamemodeIcon = new FontIcon { Glyph = "\ue7fc" };
|
||||
var gamemode = new MenuItem
|
||||
{
|
||||
Header = InternationalizationManager.Instance.GetTranslation("GameMode"),
|
||||
Icon = gamemodeIcon
|
||||
};
|
||||
var positionresetIcon = new FontIcon
|
||||
{
|
||||
Glyph = "\ue73f"
|
||||
Header = InternationalizationManager.Instance.GetTranslation("GameMode"), Icon = gamemodeIcon
|
||||
};
|
||||
var positionresetIcon = new FontIcon { Glyph = "\ue73f" };
|
||||
var positionreset = new MenuItem
|
||||
{
|
||||
Header = InternationalizationManager.Instance.GetTranslation("PositionReset"),
|
||||
Icon = positionresetIcon
|
||||
};
|
||||
var settingsIcon = new FontIcon
|
||||
{
|
||||
Glyph = "\ue713"
|
||||
};
|
||||
var settingsIcon = new FontIcon { Glyph = "\ue713" };
|
||||
var settings = new MenuItem
|
||||
{
|
||||
Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings"),
|
||||
Icon = settingsIcon
|
||||
};
|
||||
var exitIcon = new FontIcon
|
||||
{
|
||||
Glyph = "\ue7e8"
|
||||
};
|
||||
var exitIcon = new FontIcon { Glyph = "\ue7e8" };
|
||||
var exit = new MenuItem
|
||||
{
|
||||
Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"),
|
||||
Icon = exitIcon
|
||||
Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"), Icon = exitIcon
|
||||
};
|
||||
|
||||
open.Click += (o, e) => _viewModel.ToggleFlowLauncher();
|
||||
|
|
@ -423,6 +423,7 @@ namespace Flow.Launcher
|
|||
{
|
||||
_ = SetForegroundWindow(hwndSource.Handle);
|
||||
}
|
||||
|
||||
contextMenu.Focus();
|
||||
break;
|
||||
}
|
||||
|
|
@ -456,8 +457,10 @@ namespace Flow.Launcher
|
|||
|
||||
private void InitProgressbarAnimation()
|
||||
{
|
||||
var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 100, 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)));
|
||||
var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 100,
|
||||
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(da1, new PropertyPath("(Line.X1)"));
|
||||
_progressBarStoryboard.Children.Add(da);
|
||||
|
|
@ -567,6 +570,7 @@ namespace Flow.Launcher
|
|||
{
|
||||
clocksb.Begin(ClockPanel);
|
||||
}
|
||||
|
||||
iconsb.Begin(SearchIcon);
|
||||
windowsb.Begin(FlowMainWindow);
|
||||
}
|
||||
|
|
@ -674,7 +678,7 @@ namespace Flow.Launcher
|
|||
public Screen SelectedScreen()
|
||||
{
|
||||
Screen screen = null;
|
||||
switch(_settings.SearchWindowScreen)
|
||||
switch (_settings.SearchWindowScreen)
|
||||
{
|
||||
case SearchWindowScreens.Cursor:
|
||||
screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
|
||||
|
|
@ -696,6 +700,7 @@ namespace Flow.Launcher
|
|||
screen = Screen.AllScreens[0];
|
||||
break;
|
||||
}
|
||||
|
||||
return screen ?? Screen.AllScreens[0];
|
||||
}
|
||||
|
||||
|
|
@ -765,6 +770,7 @@ namespace Flow.Launcher
|
|||
_viewModel.LoadContextMenuCommand.Execute(null);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
break;
|
||||
case Key.Left:
|
||||
if (!_viewModel.SelectedIsFromQueryResults() && QueryTextBox.CaretIndex == 0)
|
||||
|
|
@ -772,6 +778,7 @@ namespace Flow.Launcher
|
|||
_viewModel.EscCommand.Execute(null);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
break;
|
||||
case Key.Back:
|
||||
if (specialKeyState.CtrlPressed)
|
||||
|
|
@ -790,12 +797,13 @@ namespace Flow.Launcher
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void OnKeyUp(object sender, KeyEventArgs e)
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
public void PreviewReset()
|
||||
{
|
||||
_viewModel.ResetPreview();
|
||||
|
|
|
|||
Loading…
Reference in a new issue