From 77d2cd8dc112ce775cb2734a69dc35e63b643bb1 Mon Sep 17 00:00:00 2001 From: ShH Y <74806550+1208nn@users.noreply.github.com> Date: Fri, 8 Nov 2024 23:36:43 +0800 Subject: [PATCH 1/2] Add setting to select all query text on window reopen * **SettingsPaneGeneralViewModel.cs** - Add `SelectAllQueryOnReopen` property - Bind the new property to the settings in the constructor * **MainWindow.xaml.cs** - Update `OnLoaded` method to select all query text if the new setting is enabled - Add `SelectAllQueryText` method to handle selecting all query text * **MainWindow.xaml** - Bind `QueryTextBox` to the new setting to select all query text when the window is reopened * **SettingWindow.xaml.cs** - Initialize the new checkbox based on the settings --- Flow.Launcher/MainWindow.xaml | 3 ++- Flow.Launcher/MainWindow.xaml.cs | 10 ++++++++++ .../ViewModels/SettingsPaneGeneralViewModel.cs | 6 ++++++ Flow.Launcher/SettingWindow.xaml | 2 +- Flow.Launcher/SettingWindow.xaml.cs | 7 +++++++ 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index f5fd729d45b..2a5b7057953 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -244,7 +244,8 @@ Style="{DynamicResource QueryBoxStyle}" Text="{Binding QueryText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Visibility="Visible" - WindowChrome.IsHitTestVisibleInChrome="True"> + WindowChrome.IsHitTestVisibleInChrome="True" + Loaded="SelectAllQueryText"> diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 8ca153afc34..51ac56c77c3 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -293,6 +293,11 @@ private void OnLoaded(object sender, RoutedEventArgs _) break; } }; + + if (_settings.SelectAllQueryOnReopen) + { + SelectAllQueryText(); + } } private void InitializePosition() @@ -852,5 +857,10 @@ private void QueryTextBox_KeyUp(object sender, KeyEventArgs e) be.UpdateSource(); } } + + private void SelectAllQueryText() + { + QueryTextBox.SelectAll(); + } } } diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs index 3d94355e687..39a6ff3a005 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs @@ -25,6 +25,7 @@ public SettingsPaneGeneralViewModel(Settings settings, Updater updater, IPortabl _updater = updater; _portable = portable; UpdateEnumDropdownLocalizations(); + SelectAllQueryOnReopen = settings.SelectAllQueryOnReopen; // Pfa33 } public class SearchWindowScreenData : DropdownDataGeneric { } @@ -54,6 +55,11 @@ public bool StartFlowLauncherOnSystemStartup } } + public bool SelectAllQueryOnReopen // Pbff7 + { + get => Settings.SelectAllQueryOnReopen; + set => Settings.SelectAllQueryOnReopen = value; + } public List SearchWindowScreens { get; } = DropdownDataGeneric.GetValues("SearchWindowScreen"); diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index a81d9e0d108..abbf18c8930 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -1,4 +1,4 @@ - Date: Thu, 13 Mar 2025 15:05:41 +0800 Subject: [PATCH 2/2] Clean up codes --- Flow.Launcher.Infrastructure/UserSettings/Settings.cs | 1 + Flow.Launcher/MainWindow.xaml | 6 +++--- .../ViewModels/SettingsPaneGeneralViewModel.cs | 7 ------- Flow.Launcher/SettingWindow.xaml.cs | 7 ------- 4 files changed, 4 insertions(+), 17 deletions(-) diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 93f6db111a2..505eb4d3cc2 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -297,6 +297,7 @@ public bool HideNotifyIcon [JsonIgnore] public bool WMPInstalled { get; set; } = true; + public bool SelectAllQueryOnReopen { get; set; } = true; // This needs to be loaded last by staying at the bottom public PluginsSettings PluginSettings { get; set; } = new PluginsSettings(); diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index 550f5c8a180..23c2e771c09 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -20,7 +20,6 @@ Closing="OnClosing" Deactivated="OnDeactivated" Icon="Images/app.png" - SourceInitialized="OnSourceInitialized" Initialized="OnInitialized" Left="{Binding Settings.WindowLeft, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Loaded="OnLoaded" @@ -31,6 +30,7 @@ ResizeMode="CanResize" ShowInTaskbar="False" SizeToContent="Height" + SourceInitialized="OnSourceInitialized" Topmost="True" Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" WindowStartupLocation="Manual" @@ -240,13 +240,13 @@ FontSize="{Binding QueryBoxFontSize, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" InputMethod.PreferredImeConversionMode="{Binding StartWithEnglishMode, Converter={StaticResource BoolToIMEConversionModeConverter}}" InputMethod.PreferredImeState="{Binding StartWithEnglishMode, Converter={StaticResource BoolToIMEStateConverter}}" + Loaded="SelectAllQueryText" PreviewDragOver="OnPreviewDragOver" PreviewKeyUp="QueryTextBox_KeyUp" Style="{DynamicResource QueryBoxStyle}" Text="{Binding QueryText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Visibility="Visible" - WindowChrome.IsHitTestVisibleInChrome="True" - Loaded="SelectAllQueryText"> + WindowChrome.IsHitTestVisibleInChrome="True"> diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs index 5bc59679c90..fc2e8a607a8 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs @@ -24,7 +24,6 @@ public SettingsPaneGeneralViewModel(Settings settings, Updater updater, IPortabl _updater = updater; _portable = portable; UpdateEnumDropdownLocalizations(); - SelectAllQueryOnReopen = settings.SelectAllQueryOnReopen; // Pfa33 } public class SearchWindowScreenData : DropdownDataGeneric { } @@ -65,12 +64,6 @@ public bool StartFlowLauncherOnSystemStartup } } - public bool SelectAllQueryOnReopen - { - get => Settings.SelectAllQueryOnReopen; - set => Settings.SelectAllQueryOnReopen = value; - } - public bool UseLogonTaskForStartup { get => Settings.UseLogonTaskForStartup; diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index d1a22c65d25..f87194c30cb 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -47,13 +47,6 @@ private void OnLoaded(object sender, RoutedEventArgs e) hwndTarget.RenderMode = RenderMode.SoftwareOnly; // Must use software only render mode here InitializePosition(); - - // Initialize the new checkbox based on the settings - var selectAllQueryOnReopenCheckbox = (System.Windows.Controls.CheckBox)FindName("SelectAllQueryOnReopenCheckbox"); - if (selectAllQueryOnReopenCheckbox != null) - { - selectAllQueryOnReopenCheckbox.IsChecked = _settings.SelectAllQueryOnReopen; - } } private void OnClosed(object sender, EventArgs e)