From 8c3ef711a05ce8adaa20d98f77db266bbc133838 Mon Sep 17 00:00:00 2001 From: Yusyuriv Date: Mon, 27 May 2024 13:09:22 +0600 Subject: [PATCH] Resizeable window: fixes after review --- Flow.Launcher/MainWindow.xaml | 1 - Flow.Launcher/MainWindow.xaml.cs | 34 +++++------- Flow.Launcher/ResultListBox.xaml | 1 - .../SettingsPaneGeneralViewModel.cs | 6 --- .../Views/SettingsPaneTheme.xaml.cs | 54 +++++-------------- Flow.Launcher/ViewModel/MainViewModel.cs | 9 ++-- Flow.Launcher/ViewModel/ResultViewModel.cs | 1 - Flow.Launcher/ViewModel/ResultsViewModel.cs | 4 +- 8 files changed, 31 insertions(+), 79 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index 139789ea6..788c3c597 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -30,7 +30,6 @@ PreviewKeyUp="OnKeyUp" ResizeMode="CanResize" ShowInTaskbar="False" - SizeChanged="OnSizeChanged" SizeToContent="Height" Topmost="True" Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 6b77ae569..c333c4e85 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -64,11 +64,11 @@ namespace Flow.Launcher DataObject.AddPastingHandler(QueryTextBox, OnPaste); - this.Loaded += (obj, args) => + this.Loaded += (_, _) => { var handle = new WindowInteropHelper(this).Handle; var win = HwndSource.FromHwnd(handle); - win.AddHook(new HwndSourceHook(WndProc)); + win.AddHook(WndProc); }; } @@ -83,20 +83,12 @@ namespace Flow.Launcher InitializeComponent(); } - private void OnSizeChanged(object sender, SizeChangedEventArgs e) - { - - } - private const int WM_ENTERSIZEMOVE = 0x0231; private const int WM_EXITSIZEMOVE = 0x0232; - public event EventHandler ResizeBegin; - public event EventHandler ResizeEnd; private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg == WM_ENTERSIZEMOVE) { - OnResizeBegin(); handled = true; } if (msg == WM_EXITSIZEMOVE) @@ -107,11 +99,6 @@ namespace Flow.Launcher return IntPtr.Zero; } - private void OnResizeBegin() - { - - } - private void OnResizeEnd() { int shadowMargin = 0; @@ -120,14 +107,17 @@ namespace Flow.Launcher shadowMargin = 32; } - if (!_settings.KeepMaxResults) { - if (System.Convert.ToInt32((Height - (_settings.WindowHeightSize + 14) - shadowMargin) / _settings.ItemHeightSize) < 1) + if (!_settings.KeepMaxResults) + { + var itemCount = (Height - (_settings.WindowHeightSize + 14) - shadowMargin) / _settings.ItemHeightSize; + + if (itemCount < 2) { _settings.MaxResultsToShow = 2; } else { - _settings.MaxResultsToShow = System.Convert.ToInt32(Math.Truncate((Height - (_settings.WindowHeightSize + 14) - shadowMargin) / _settings.ItemHeightSize)); + _settings.MaxResultsToShow = Convert.ToInt32(Math.Truncate(itemCount)); } } @@ -161,7 +151,7 @@ namespace Flow.Launcher e.DataObject = data; } } - + private async void OnClosing(object sender, CancelEventArgs e) { _notifyIcon.Visible = false; @@ -622,11 +612,11 @@ namespace Flow.Launcher { _settings.WindowLeft = Left; _settings.WindowTop = Top; - //This condition stops extra hide call when animator is on, + //This condition stops extra hide call when animator is on, // which causes the toggling to occasional hide instead of show. if (_viewModel.MainWindowVisibilityStatus) { - // Need time to initialize the main query window animation. + // Need time to initialize the main query window animation. // This also stops the mainwindow from flickering occasionally after Settings window is opened // and always after Settings window is closed. if (_settings.UseAnimation) @@ -697,7 +687,7 @@ namespace Flow.Launcher } return screen ?? Screen.AllScreens[0]; } - + public double HorizonCenter(Screen screen) { var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0); diff --git a/Flow.Launcher/ResultListBox.xaml b/Flow.Launcher/ResultListBox.xaml index 7dc036afb..38202fcf3 100644 --- a/Flow.Launcher/ResultListBox.xaml +++ b/Flow.Launcher/ResultListBox.xaml @@ -209,7 +209,6 @@ - diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs index cb231d4f5..7afb2d995 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs @@ -150,12 +150,6 @@ public partial class SettingsPaneGeneralViewModel : BaseModel .ToList(); public List Languages => InternationalizationManager.Instance.LoadAvailableLanguages(); - public IEnumerable MaxResultsRange => Enumerable.Range(2, 16); - public bool KeepMaxResults - { - get => Settings.KeepMaxResults; - set => Settings.KeepMaxResults = value; - } public string AlwaysPreviewToolTip => string.Format( InternationalizationManager.Instance.GetTranslation("AlwaysPreviewToolTip"), diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs index cfc59a589..7d412296f 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs @@ -1,5 +1,4 @@ using System; -using System.Drawing; using System.Windows; using System.Windows.Controls; using System.Windows.Media; @@ -32,7 +31,7 @@ public partial class SettingsPaneTheme : Page _viewModel.UpdateColorScheme(); } - private void Reset_Click(object sender, System.Windows.RoutedEventArgs e) + private void Reset_Click(object sender, RoutedEventArgs e) { /*The FamilyTypeface should initialize all of its various properties.*/ FamilyTypeface targetTypeface = new FamilyTypeface { Stretch = FontStretches.Normal, Weight = FontWeights.Normal, Style = FontStyles.Normal }; @@ -52,56 +51,31 @@ public partial class SettingsPaneTheme : Page WindowHeightValue.Value = 42; ItemHeightValue.Value = 58; } - public int SearchFontIndex(string str, ComboBox combo) - { - int index = -1; - string targetFont = str; + private int SearchFontIndex(string targetFont, ComboBox combo) + { for (int i = 0; i < combo.Items.Count; i++) { - if (combo.Items[i].ToString() == targetFont) + if (combo.Items[i]?.ToString() == targetFont) { - index = i; - break; + return i; } } - - if (index != -1) - { - return index; - } - else - { - // If there no Default Value. - return 0; - } + return 0; } - public int SearchFontStyleIndex(FamilyTypeface targetTypeface, ComboBox combo) - { - int index = -1; + private int SearchFontStyleIndex(FamilyTypeface targetTypeface, ComboBox combo) + { for (int i = 0; i < combo.Items.Count; i++) { - if (combo.Items[i] is FamilyTypeface) + if (combo.Items[i] is FamilyTypeface typefaceItem && + typefaceItem.Stretch == targetTypeface.Stretch && + typefaceItem.Weight == targetTypeface.Weight && + typefaceItem.Style == targetTypeface.Style) { - FamilyTypeface typefaceItem = (FamilyTypeface)combo.Items[i]; - if (typefaceItem.Stretch == targetTypeface.Stretch && - typefaceItem.Weight == targetTypeface.Weight && - typefaceItem.Style == targetTypeface.Style) - { - index = i; - break; - } + return i; } } - - if (index != -1) - { - return index; - } - else - { - return 0; - } + return 0; } } diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index ad6b91510..291dd9a97 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -19,13 +19,10 @@ using Microsoft.VisualStudio.Threading; using System.Text; using System.Threading.Channels; using ISavable = Flow.Launcher.Plugin.ISavable; -using System.IO; -using System.Collections.Specialized; using CommunityToolkit.Mvvm.Input; using System.Globalization; using System.Windows.Input; using System.ComponentModel; -using Windows.UI.Core.AnimationMetrics; namespace Flow.Launcher.ViewModel { @@ -455,7 +452,7 @@ namespace Flow.Launcher.ViewModel { SelectedResults.SelectPrevResult(); } - + } [RelayCommand] @@ -482,7 +479,7 @@ namespace Flow.Launcher.ViewModel { GameModeStatus = !GameModeStatus; } - + [RelayCommand] public void CopyAlternative() { @@ -760,7 +757,7 @@ namespace Flow.Launcher.ViewModel return hotkey; } - + public string PreviewHotkey => VerifyOrSetDefaultHotkey(Settings.PreviewHotkey, "F1"); public string AutoCompleteHotkey => VerifyOrSetDefaultHotkey(Settings.AutoCompleteHotkey, "Ctrl+Tab"); public string AutoCompleteHotkey2 => VerifyOrSetDefaultHotkey(Settings.AutoCompleteHotkey2, ""); diff --git a/Flow.Launcher/ViewModel/ResultViewModel.cs b/Flow.Launcher/ViewModel/ResultViewModel.cs index 7e45d95c4..5130e7eba 100644 --- a/Flow.Launcher/ViewModel/ResultViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultViewModel.cs @@ -21,7 +21,6 @@ namespace Flow.Launcher.ViewModel { Settings = settings; - if (result == null) { return; diff --git a/Flow.Launcher/ViewModel/ResultsViewModel.cs b/Flow.Launcher/ViewModel/ResultsViewModel.cs index 826dbe4cd..68e59009f 100644 --- a/Flow.Launcher/ViewModel/ResultsViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultsViewModel.cs @@ -49,7 +49,7 @@ namespace Flow.Launcher.ViewModel #region Properties - public double MaxHeight => MaxResults * _settings.ItemHeightSize!; + public double MaxHeight => MaxResults * _settings.ItemHeightSize; public double ItemHeightSize { get => _settings.ItemHeightSize; @@ -61,7 +61,7 @@ namespace Flow.Launcher.ViewModel public ResultViewModel SelectedItem { get; set; } public Thickness Margin { get; set; } public Visibility Visibility { get; set; } = Visibility.Collapsed; - + public ICommand RightClickResultCommand { get; init; } public ICommand LeftClickResultCommand { get; init; }