Skip to content

Commit 8c3ef71

Browse files
committed
Resizeable window: fixes after review
1 parent 2893487 commit 8c3ef71

File tree

8 files changed

+31
-79
lines changed

8 files changed

+31
-79
lines changed

Flow.Launcher/MainWindow.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
PreviewKeyUp="OnKeyUp"
3131
ResizeMode="CanResize"
3232
ShowInTaskbar="False"
33-
SizeChanged="OnSizeChanged"
3433
SizeToContent="Height"
3534
Topmost="True"
3635
Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ public MainWindow(Settings settings, MainViewModel mainVM)
6464

6565
DataObject.AddPastingHandler(QueryTextBox, OnPaste);
6666

67-
this.Loaded += (obj, args) =>
67+
this.Loaded += (_, _) =>
6868
{
6969
var handle = new WindowInteropHelper(this).Handle;
7070
var win = HwndSource.FromHwnd(handle);
71-
win.AddHook(new HwndSourceHook(WndProc));
71+
win.AddHook(WndProc);
7272
};
7373
}
7474

@@ -83,20 +83,12 @@ public MainWindow()
8383
InitializeComponent();
8484
}
8585

86-
private void OnSizeChanged(object sender, SizeChangedEventArgs e)
87-
{
88-
89-
}
90-
9186
private const int WM_ENTERSIZEMOVE = 0x0231;
9287
private const int WM_EXITSIZEMOVE = 0x0232;
93-
public event EventHandler ResizeBegin;
94-
public event EventHandler ResizeEnd;
9588
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
9689
{
9790
if (msg == WM_ENTERSIZEMOVE)
9891
{
99-
OnResizeBegin();
10092
handled = true;
10193
}
10294
if (msg == WM_EXITSIZEMOVE)
@@ -107,11 +99,6 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b
10799
return IntPtr.Zero;
108100
}
109101

110-
private void OnResizeBegin()
111-
{
112-
113-
}
114-
115102
private void OnResizeEnd()
116103
{
117104
int shadowMargin = 0;
@@ -120,14 +107,17 @@ private void OnResizeEnd()
120107
shadowMargin = 32;
121108
}
122109

123-
if (!_settings.KeepMaxResults) {
124-
if (System.Convert.ToInt32((Height - (_settings.WindowHeightSize + 14) - shadowMargin) / _settings.ItemHeightSize) < 1)
110+
if (!_settings.KeepMaxResults)
111+
{
112+
var itemCount = (Height - (_settings.WindowHeightSize + 14) - shadowMargin) / _settings.ItemHeightSize;
113+
114+
if (itemCount < 2)
125115
{
126116
_settings.MaxResultsToShow = 2;
127117
}
128118
else
129119
{
130-
_settings.MaxResultsToShow = System.Convert.ToInt32(Math.Truncate((Height - (_settings.WindowHeightSize + 14) - shadowMargin) / _settings.ItemHeightSize));
120+
_settings.MaxResultsToShow = Convert.ToInt32(Math.Truncate(itemCount));
131121
}
132122
}
133123

@@ -161,7 +151,7 @@ private void OnPaste(object sender, DataObjectPastingEventArgs e)
161151
e.DataObject = data;
162152
}
163153
}
164-
154+
165155
private async void OnClosing(object sender, CancelEventArgs e)
166156
{
167157
_notifyIcon.Visible = false;
@@ -622,11 +612,11 @@ private async void OnDeactivated(object sender, EventArgs e)
622612
{
623613
_settings.WindowLeft = Left;
624614
_settings.WindowTop = Top;
625-
//This condition stops extra hide call when animator is on,
615+
//This condition stops extra hide call when animator is on,
626616
// which causes the toggling to occasional hide instead of show.
627617
if (_viewModel.MainWindowVisibilityStatus)
628618
{
629-
// Need time to initialize the main query window animation.
619+
// Need time to initialize the main query window animation.
630620
// This also stops the mainwindow from flickering occasionally after Settings window is opened
631621
// and always after Settings window is closed.
632622
if (_settings.UseAnimation)
@@ -697,7 +687,7 @@ public Screen SelectedScreen()
697687
}
698688
return screen ?? Screen.AllScreens[0];
699689
}
700-
690+
701691
public double HorizonCenter(Screen screen)
702692
{
703693
var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);

Flow.Launcher/ResultListBox.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@
209209
<!-- a result item height is 52 including margin -->
210210
<DataTemplate.Triggers>
211211
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}, Path=IsSelected}" Value="True">
212-
213212
<Setter TargetName="Bullet" Property="Style" Value="{DynamicResource ItemBulletSelectedStyle}" />
214213
<Setter TargetName="Title" Property="Style" Value="{DynamicResource ItemTitleSelectedStyle}" />
215214
<Setter TargetName="SubTitle" Property="Style" Value="{DynamicResource ItemSubTitleSelectedStyle}" />

Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,6 @@ public bool ShouldUsePinyin
150150
.ToList();
151151

152152
public List<Language> Languages => InternationalizationManager.Instance.LoadAvailableLanguages();
153-
public IEnumerable<int> MaxResultsRange => Enumerable.Range(2, 16);
154-
public bool KeepMaxResults
155-
{
156-
get => Settings.KeepMaxResults;
157-
set => Settings.KeepMaxResults = value;
158-
}
159153

160154
public string AlwaysPreviewToolTip => string.Format(
161155
InternationalizationManager.Instance.GetTranslation("AlwaysPreviewToolTip"),
Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Drawing;
32
using System.Windows;
43
using System.Windows.Controls;
54
using System.Windows.Media;
@@ -32,7 +31,7 @@ private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArg
3231
_viewModel.UpdateColorScheme();
3332
}
3433

35-
private void Reset_Click(object sender, System.Windows.RoutedEventArgs e)
34+
private void Reset_Click(object sender, RoutedEventArgs e)
3635
{
3736
/*The FamilyTypeface should initialize all of its various properties.*/
3837
FamilyTypeface targetTypeface = new FamilyTypeface { Stretch = FontStretches.Normal, Weight = FontWeights.Normal, Style = FontStyles.Normal };
@@ -52,56 +51,31 @@ private void Reset_Click(object sender, System.Windows.RoutedEventArgs e)
5251
WindowHeightValue.Value = 42;
5352
ItemHeightValue.Value = 58;
5453
}
55-
public int SearchFontIndex(string str, ComboBox combo)
56-
{
57-
int index = -1;
58-
string targetFont = str;
5954

55+
private int SearchFontIndex(string targetFont, ComboBox combo)
56+
{
6057
for (int i = 0; i < combo.Items.Count; i++)
6158
{
62-
if (combo.Items[i].ToString() == targetFont)
59+
if (combo.Items[i]?.ToString() == targetFont)
6360
{
64-
index = i;
65-
break;
61+
return i;
6662
}
6763
}
68-
69-
if (index != -1)
70-
{
71-
return index;
72-
}
73-
else
74-
{
75-
// If there no Default Value.
76-
return 0;
77-
}
64+
return 0;
7865
}
79-
public int SearchFontStyleIndex(FamilyTypeface targetTypeface, ComboBox combo)
80-
{
81-
int index = -1;
8266

67+
private int SearchFontStyleIndex(FamilyTypeface targetTypeface, ComboBox combo)
68+
{
8369
for (int i = 0; i < combo.Items.Count; i++)
8470
{
85-
if (combo.Items[i] is FamilyTypeface)
71+
if (combo.Items[i] is FamilyTypeface typefaceItem &&
72+
typefaceItem.Stretch == targetTypeface.Stretch &&
73+
typefaceItem.Weight == targetTypeface.Weight &&
74+
typefaceItem.Style == targetTypeface.Style)
8675
{
87-
FamilyTypeface typefaceItem = (FamilyTypeface)combo.Items[i];
88-
if (typefaceItem.Stretch == targetTypeface.Stretch &&
89-
typefaceItem.Weight == targetTypeface.Weight &&
90-
typefaceItem.Style == targetTypeface.Style)
91-
{
92-
index = i;
93-
break;
94-
}
76+
return i;
9577
}
9678
}
97-
98-
if (index != -1)
99-
{
100-
return index;
101-
}
102-
else
103-
{
104-
return 0;
105-
}
79+
return 0;
10680
}
10781
}

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@
1919
using System.Text;
2020
using System.Threading.Channels;
2121
using ISavable = Flow.Launcher.Plugin.ISavable;
22-
using System.IO;
23-
using System.Collections.Specialized;
2422
using CommunityToolkit.Mvvm.Input;
2523
using System.Globalization;
2624
using System.Windows.Input;
2725
using System.ComponentModel;
28-
using Windows.UI.Core.AnimationMetrics;
2926

3027
namespace Flow.Launcher.ViewModel
3128
{
@@ -455,7 +452,7 @@ private void SelectPrevItem()
455452
{
456453
SelectedResults.SelectPrevResult();
457454
}
458-
455+
459456
}
460457

461458
[RelayCommand]
@@ -482,7 +479,7 @@ public void ToggleGameMode()
482479
{
483480
GameModeStatus = !GameModeStatus;
484481
}
485-
482+
486483
[RelayCommand]
487484
public void CopyAlternative()
488485
{
@@ -760,7 +757,7 @@ public string VerifyOrSetDefaultHotkey(string hotkey, string defaultHotkey)
760757

761758
return hotkey;
762759
}
763-
760+
764761
public string PreviewHotkey => VerifyOrSetDefaultHotkey(Settings.PreviewHotkey, "F1");
765762
public string AutoCompleteHotkey => VerifyOrSetDefaultHotkey(Settings.AutoCompleteHotkey, "Ctrl+Tab");
766763
public string AutoCompleteHotkey2 => VerifyOrSetDefaultHotkey(Settings.AutoCompleteHotkey2, "");

Flow.Launcher/ViewModel/ResultViewModel.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public ResultViewModel(Result result, Settings settings)
2121
{
2222
Settings = settings;
2323

24-
2524
if (result == null)
2625
{
2726
return;

Flow.Launcher/ViewModel/ResultsViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public ResultsViewModel(Settings settings) : this()
4949

5050
#region Properties
5151

52-
public double MaxHeight => MaxResults * _settings.ItemHeightSize!;
52+
public double MaxHeight => MaxResults * _settings.ItemHeightSize;
5353
public double ItemHeightSize
5454
{
5555
get => _settings.ItemHeightSize;
@@ -61,7 +61,7 @@ public double ItemHeightSize
6161
public ResultViewModel SelectedItem { get; set; }
6262
public Thickness Margin { get; set; }
6363
public Visibility Visibility { get; set; } = Visibility.Collapsed;
64-
64+
6565
public ICommand RightClickResultCommand { get; init; }
6666
public ICommand LeftClickResultCommand { get; init; }
6767

0 commit comments

Comments
 (0)