From e42c2b60204d61a9aee4ec7651804e7ce9c3b109 Mon Sep 17 00:00:00 2001 From: DB p Date: Wed, 7 Sep 2022 13:11:46 +0900 Subject: [PATCH 1/5] Remember Settingwindow Size and Location --- .../UserSettings/Settings.cs | 9 +++-- Flow.Launcher/SettingWindow.xaml | 6 ++-- Flow.Launcher/SettingWindow.xaml.cs | 36 +++++++++++++++++++ .../ViewModel/SettingWindowViewModel.cs | 26 +++++++++++++- 4 files changed, 72 insertions(+), 5 deletions(-) diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 8ecd6dc4b76..1b15a31f6c5 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Drawing; @@ -43,6 +43,11 @@ public string Language public bool UseSound { get; set; } = true; public bool FirstLaunch { get; set; } = true; + public double SettingWindowWidth { get; set; } = 1000; + public double SettingWindowHeight { get; set; } = 700; + public double SettingWindowTop { get; set; } = 0; + public double SettingWindowLeft { get; set; } = 0; + public int CustomExplorerIndex { get; set; } = 0; [JsonIgnore] @@ -220,4 +225,4 @@ public enum ColorSchemes Light, Dark } -} \ No newline at end of file +} diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index ba6569771d1..3c2d1834de3 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -13,17 +13,19 @@ xmlns:userSettings="clr-namespace:Flow.Launcher.Infrastructure.UserSettings;assembly=Flow.Launcher.Infrastructure" xmlns:vm="clr-namespace:Flow.Launcher.ViewModel" Title="{DynamicResource flowlauncher_settings}" - Width="1000" - Height="700" + Width="{Binding SettingWindowWidth, Mode=TwoWay}" + Height="{Binding SettingWindowHeight, Mode=TwoWay}" MinWidth="900" MinHeight="600" d:DataContext="{d:DesignInstance vm:SettingWindowViewModel}" Closed="OnClosed" Icon="Images\app.ico" + Left="{Binding SettingWindowLeft, Mode=TwoWay}" Loaded="OnLoaded" MouseDown="window_MouseDown" ResizeMode="CanResize" StateChanged="Window_StateChanged" + Top="{Binding SettingWindowTop, Mode=TwoWay}" WindowStartupLocation="CenterScreen" mc:Ignorable="d"> diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index 10c9aeffeec..b1e18192c58 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -12,6 +12,7 @@ using Microsoft.Win32; using ModernWpf; using System; +using System.Diagnostics; using System.IO; using System.Windows; using System.Windows.Controls; @@ -48,6 +49,7 @@ public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel) private void OnLoaded(object sender, RoutedEventArgs e) { + InitializePosition(); RefreshMaximizeRestoreButton(); // Fix (workaround) for the window freezes after lock screen (Win+L) // https://stackoverflow.com/questions/4951058/software-rendering-mode-wpf @@ -242,6 +244,8 @@ private void OnRequestNavigate(object sender, RequestNavigateEventArgs e) private void OnClosed(object sender, EventArgs e) { + settings.SettingWindowTop = Top; + settings.SettingWindowLeft = Left; viewModel.Save(); } @@ -319,6 +323,7 @@ private void OnMaximizeRestoreButtonClick(object sender, RoutedEventArgs e) private void OnCloseButtonClick(object sender, RoutedEventArgs e) { + Close(); } @@ -348,5 +353,36 @@ private void ItemSizeChanged(object sender, SizeChangedEventArgs e) { Plugins.ScrollIntoView(Plugins.SelectedItem); } + + public void InitializePosition() + { + if (settings.SettingWindowTop == 0 && settings.SettingWindowLeft == 0) + { + Top = WindowTop(); + Left = WindowLeft(); + } + else + { + Top = settings.SettingWindowTop; + Left = settings.SettingWindowLeft; + } + } + public double WindowLeft() + { + var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); + var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0); + var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0); + var left = (dip2.X - this.ActualWidth) / 2 + dip1.X; + return left; + } + + public double WindowTop() + { + var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); + var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y); + var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height); + var top = (dip2.Y - this.ActualHeight) / 2 + dip1.Y - 20; + return top; + } } } diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index a63e54f3b0a..fc6e3a16d07 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -51,7 +51,7 @@ public async void UpdateApp() { await _updater.UpdateAppAsync(App.API, false); } - + public bool AutoUpdates { get => Settings.AutoUpdates; @@ -385,6 +385,30 @@ public bool UseSound set => Settings.UseSound = value; } + public double SettingWindowWidth + { + get => Settings.SettingWindowWidth; + set => Settings.SettingWindowWidth = value; + } + + public double SettingWindowHeight + { + get => Settings.SettingWindowHeight; + set => Settings.SettingWindowHeight = value; + } + + public double SettingWindowTop + { + get => Settings.SettingWindowTop; + set => Settings.SettingWindowTop = value; + } + + public double SettingWindowLeft + { + get => Settings.SettingWindowLeft; + set => Settings.SettingWindowLeft = value; + } + public Brush PreviewBackground { get From f4e5bf4896aaef612d138578eeef1ceba3291eb6 Mon Sep 17 00:00:00 2001 From: DB p Date: Tue, 13 Sep 2022 11:31:23 +0900 Subject: [PATCH 2/5] Remove SettingPanel's Maxheight --- Flow.Launcher/SettingWindow.xaml | 1 - 1 file changed, 1 deletion(-) diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 3c2d1834de3..469294ad3f9 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -1112,7 +1112,6 @@ Date: Tue, 13 Sep 2022 15:26:34 +0900 Subject: [PATCH 3/5] - remove 'using system.diagnotics' - fix positioning --- Flow.Launcher/SettingWindow.xaml | 2 +- Flow.Launcher/SettingWindow.xaml.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 469294ad3f9..46e4178b8a0 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -26,7 +26,7 @@ ResizeMode="CanResize" StateChanged="Window_StateChanged" Top="{Binding SettingWindowTop, Mode=TwoWay}" - WindowStartupLocation="CenterScreen" + WindowStartupLocation="Manual" mc:Ignorable="d"> diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index b1e18192c58..fa06b14d12c 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -12,7 +12,6 @@ using Microsoft.Win32; using ModernWpf; using System; -using System.Diagnostics; using System.IO; using System.Windows; using System.Windows.Controls; @@ -38,9 +37,10 @@ public partial class SettingWindow public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel) { - InitializeComponent(); settings = viewModel.Settings; DataContext = viewModel; + InitializeComponent(); + InitializePosition(); this.viewModel = viewModel; API = api; } @@ -49,13 +49,13 @@ public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel) private void OnLoaded(object sender, RoutedEventArgs e) { - InitializePosition(); RefreshMaximizeRestoreButton(); // Fix (workaround) for the window freezes after lock screen (Win+L) // https://stackoverflow.com/questions/4951058/software-rendering-mode-wpf HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource; HwndTarget hwndTarget = hwndSource.CompositionTarget; hwndTarget.RenderMode = RenderMode.SoftwareOnly; + InitializePosition(); } private void OnSelectPythonDirectoryClick(object sender, RoutedEventArgs e) From abb8c49f19ac98f26868361a0280b6b8716306c3 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Tue, 13 Sep 2022 12:12:33 -0500 Subject: [PATCH 4/5] Arrange Setting window constructor property assignment and intialization order. --- Flow.Launcher/SettingWindow.xaml.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index fa06b14d12c..09c5105b224 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -39,10 +39,10 @@ public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel) { settings = viewModel.Settings; DataContext = viewModel; - InitializeComponent(); - InitializePosition(); this.viewModel = viewModel; API = api; + InitializePosition(); + InitializeComponent(); } #region General @@ -323,7 +323,7 @@ private void OnMaximizeRestoreButtonClick(object sender, RoutedEventArgs e) private void OnCloseButtonClick(object sender, RoutedEventArgs e) { - + Close(); } From 924dd746e655f4e13de00ee26b6aaf8674b8b269 Mon Sep 17 00:00:00 2001 From: DB p Date: Mon, 3 Oct 2022 16:12:08 +0900 Subject: [PATCH 5/5] Fix Defaut Position Logic --- Flow.Launcher.Infrastructure/UserSettings/Settings.cs | 4 ++-- Flow.Launcher/SettingWindow.xaml.cs | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 1b15a31f6c5..211bc179876 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -45,8 +45,8 @@ public string Language public double SettingWindowWidth { get; set; } = 1000; public double SettingWindowHeight { get; set; } = 700; - public double SettingWindowTop { get; set; } = 0; - public double SettingWindowLeft { get; set; } = 0; + public double SettingWindowTop { get; set; } + public double SettingWindowLeft { get; set; } public int CustomExplorerIndex { get; set; } = 0; diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index a69cfcbe29b..4ed6d642d85 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -357,15 +357,15 @@ private void ItemSizeChanged(object sender, SizeChangedEventArgs e) public void InitializePosition() { - if (settings.SettingWindowTop == 0 && settings.SettingWindowLeft == 0) + if (settings.SettingWindowTop >= 0 && settings.SettingWindowLeft >= 0) { - Top = WindowTop(); - Left = WindowLeft(); + Top = settings.SettingWindowTop; + Left = settings.SettingWindowLeft; } else { - Top = settings.SettingWindowTop; - Left = settings.SettingWindowLeft; + Top = WindowTop(); + Left = WindowLeft(); } } public double WindowLeft()