From b87237fd6cdb3d30dbc6698a98309e9d3ea04516 Mon Sep 17 00:00:00 2001 From: DB p Date: Tue, 28 May 2024 16:27:25 +0900 Subject: [PATCH 1/4] - Fix Window Width Save - Removed Unused code - Adjust MinWidth --- Flow.Launcher/MainWindow.xaml | 3 ++- Flow.Launcher/MainWindow.xaml.cs | 11 +++++++++-- .../ViewModels/SettingsPaneThemeViewModel.cs | 6 ------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index 788c3c597c2..c3753f53f89 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -13,7 +13,7 @@ Name="FlowMainWindow" Title="Flow Launcher" Width="{Binding MainWindowWidth, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" - MinWidth="430" + MinWidth="400" MinHeight="30" d:DataContext="{d:DesignInstance Type=vm:MainViewModel}" AllowDrop="True" @@ -30,6 +30,7 @@ PreviewKeyUp="OnKeyUp" ResizeMode="CanResize" ShowInTaskbar="False" + SizeChanged="Window_SizeChanged" 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 c333c4e8506..0a63b180839 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -45,6 +45,7 @@ public partial class MainWindow private MainViewModel _viewModel; private bool _animating; private bool isArrowKeyPressed = false; + private double WindowWidthForSave; private MediaPlayer animationSoundWMP; private SoundPlayer animationSoundWPF; @@ -120,8 +121,6 @@ private void OnResizeEnd() _settings.MaxResultsToShow = Convert.ToInt32(Math.Truncate(itemCount)); } } - - _viewModel.MainWindowWidth = Width; FlowMainWindow.SizeToContent = SizeToContent.Height; } @@ -155,6 +154,9 @@ private void OnPaste(object sender, DataObjectPastingEventArgs e) private async void OnClosing(object sender, CancelEventArgs e) { _notifyIcon.Visible = false; + /* In this timing, window alreayd closed and it effect to window size. So at this point, whenever the window changes, + we recall the width we've stored as a variable and specify it in the settings. This way, the existing window size will be recalled on the next run.*/ + _settings.WindowSize = WindowWidthForSave; App.API.SaveAppAllSettings(); e.Cancel = true; await PluginManager.DisposePluginsAsync(); @@ -832,5 +834,10 @@ private void QueryTextBox_KeyUp(object sender, KeyEventArgs e) be.UpdateSource(); } } + + private void Window_SizeChanged(object sender, SizeChangedEventArgs e) + { + WindowWidthForSave = Width; + } } } diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs index 667d0b72678..5046a475481 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs @@ -173,12 +173,6 @@ public bool KeepMaxResults public string DateText => DateTime.Now.ToString(DateFormat, CultureInfo.CurrentCulture); - public double WindowWidthSize - { - get => Settings.WindowSize; - set => Settings.WindowSize = value; - } - public bool UseGlyphIcons { get => Settings.UseGlyphIcons; From 52d142cb16d57cedd73380f50914c10bf6aee86c Mon Sep 17 00:00:00 2001 From: Yusyuriv Date: Tue, 28 May 2024 13:54:30 +0600 Subject: [PATCH 2/4] One-time binding for main window width --- Flow.Launcher/MainWindow.xaml | 3 +-- Flow.Launcher/MainWindow.xaml.cs | 11 ++--------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index c3753f53f89..70aed0d191a 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -12,7 +12,7 @@ xmlns:vm="clr-namespace:Flow.Launcher.ViewModel" Name="FlowMainWindow" Title="Flow Launcher" - Width="{Binding MainWindowWidth, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" + Width="{Binding MainWindowWidth, Mode=OneTime}" MinWidth="400" MinHeight="30" d:DataContext="{d:DesignInstance Type=vm:MainViewModel}" @@ -30,7 +30,6 @@ PreviewKeyUp="OnKeyUp" ResizeMode="CanResize" ShowInTaskbar="False" - SizeChanged="Window_SizeChanged" 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 0a63b180839..c333c4e8506 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -45,7 +45,6 @@ public partial class MainWindow private MainViewModel _viewModel; private bool _animating; private bool isArrowKeyPressed = false; - private double WindowWidthForSave; private MediaPlayer animationSoundWMP; private SoundPlayer animationSoundWPF; @@ -121,6 +120,8 @@ private void OnResizeEnd() _settings.MaxResultsToShow = Convert.ToInt32(Math.Truncate(itemCount)); } } + + _viewModel.MainWindowWidth = Width; FlowMainWindow.SizeToContent = SizeToContent.Height; } @@ -154,9 +155,6 @@ private void OnPaste(object sender, DataObjectPastingEventArgs e) private async void OnClosing(object sender, CancelEventArgs e) { _notifyIcon.Visible = false; - /* In this timing, window alreayd closed and it effect to window size. So at this point, whenever the window changes, - we recall the width we've stored as a variable and specify it in the settings. This way, the existing window size will be recalled on the next run.*/ - _settings.WindowSize = WindowWidthForSave; App.API.SaveAppAllSettings(); e.Cancel = true; await PluginManager.DisposePluginsAsync(); @@ -834,10 +832,5 @@ private void QueryTextBox_KeyUp(object sender, KeyEventArgs e) be.UpdateSource(); } } - - private void Window_SizeChanged(object sender, SizeChangedEventArgs e) - { - WindowWidthForSave = Width; - } } } From f62561fe53ef58f344074aa1d3dda2b7eac4969d Mon Sep 17 00:00:00 2001 From: Yusyuriv Date: Tue, 28 May 2024 14:44:28 +0600 Subject: [PATCH 3/4] Don't save new window width if the window is hidden --- Flow.Launcher/MainWindow.xaml | 2 +- Flow.Launcher/ViewModel/MainViewModel.cs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index 70aed0d191a..adb0b7b5dbb 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -12,7 +12,7 @@ xmlns:vm="clr-namespace:Flow.Launcher.ViewModel" Name="FlowMainWindow" Title="Flow Launcher" - Width="{Binding MainWindowWidth, Mode=OneTime}" + Width="{Binding MainWindowWidth, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MinWidth="400" MinHeight="30" d:DataContext="{d:DesignInstance Type=vm:MainViewModel}" diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 291dd9a973e..8e8337fec26 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -706,7 +706,11 @@ private ResultsViewModel SelectedResults public double MainWindowWidth { get => Settings.WindowSize; - set => Settings.WindowSize = value; + set + { + if (!MainWindowVisibilityStatus) return; + Settings.WindowSize = value; + } } public double MainWindowHeight From 96f4153ed278e1e8cfd659df203303bcd53a54c0 Mon Sep 17 00:00:00 2001 From: Yusyuriv Date: Tue, 28 May 2024 14:46:28 +0600 Subject: [PATCH 4/4] Correctly notify windows size change, use window left position for main window --- Flow.Launcher/MainWindow.xaml | 1 + Flow.Launcher/ViewModel/MainViewModel.cs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index adb0b7b5dbb..2b10f79b3a5 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -23,6 +23,7 @@ Deactivated="OnDeactivated" Icon="Images/app.png" Initialized="OnInitialized" + Left="{Binding Settings.WindowLeft, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Loaded="OnLoaded" LocationChanged="OnLocationChanged" Opacity="{Binding MainWindowOpacity, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 8e8337fec26..dcca3fb1a5c 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -538,7 +538,7 @@ private void IncreaseWidth() { Settings.WindowSize += 100; Settings.WindowLeft -= 50; - OnPropertyChanged(); + OnPropertyChanged(nameof(MainWindowWidth)); } [RelayCommand] @@ -554,7 +554,7 @@ private void DecreaseWidth() Settings.WindowSize -= 100; } - OnPropertyChanged(); + OnPropertyChanged(nameof(MainWindowWidth)); } [RelayCommand]