Resizeable window: fixes after review

This commit is contained in:
Yusyuriv 2024-05-27 13:09:22 +06:00
parent 2893487195
commit 8c3ef711a0
No known key found for this signature in database
GPG key ID: A91C52E6F73148E0
8 changed files with 31 additions and 79 deletions

View file

@ -30,7 +30,6 @@
PreviewKeyUp="OnKeyUp"
ResizeMode="CanResize"
ShowInTaskbar="False"
SizeChanged="OnSizeChanged"
SizeToContent="Height"
Topmost="True"
Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"

View file

@ -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);

View file

@ -209,7 +209,6 @@
<!-- a result item height is 52 including margin -->
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}, Path=IsSelected}" Value="True">
<Setter TargetName="Bullet" Property="Style" Value="{DynamicResource ItemBulletSelectedStyle}" />
<Setter TargetName="Title" Property="Style" Value="{DynamicResource ItemTitleSelectedStyle}" />
<Setter TargetName="SubTitle" Property="Style" Value="{DynamicResource ItemSubTitleSelectedStyle}" />

View file

@ -150,12 +150,6 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
.ToList();
public List<Language> Languages => InternationalizationManager.Instance.LoadAvailableLanguages();
public IEnumerable<int> MaxResultsRange => Enumerable.Range(2, 16);
public bool KeepMaxResults
{
get => Settings.KeepMaxResults;
set => Settings.KeepMaxResults = value;
}
public string AlwaysPreviewToolTip => string.Format(
InternationalizationManager.Instance.GetTranslation("AlwaysPreviewToolTip"),

View file

@ -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;
}
}

View file

@ -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, "");

View file

@ -21,7 +21,6 @@ namespace Flow.Launcher.ViewModel
{
Settings = settings;
if (result == null)
{
return;

View file

@ -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; }