From 914f4009566be72ee7d376be91ddabe48335afc7 Mon Sep 17 00:00:00 2001 From: Yusyuriv Date: Fri, 12 Apr 2024 17:13:45 +0600 Subject: [PATCH 01/82] WIP: new HotkeyControl --- Flow.Launcher/HotkeyControl.xaml | 62 +++++++++++++++------ Flow.Launcher/HotkeyControl.xaml.cs | 83 ++++++++++++++++++++++++++--- Flow.Launcher/SettingWindow.xaml | 14 +++-- Flow.Launcher/SettingWindow.xaml.cs | 37 ++----------- 4 files changed, 132 insertions(+), 64 deletions(-) diff --git a/Flow.Launcher/HotkeyControl.xaml b/Flow.Launcher/HotkeyControl.xaml index acf4a21ec..bea652d56 100644 --- a/Flow.Launcher/HotkeyControl.xaml +++ b/Flow.Launcher/HotkeyControl.xaml @@ -5,14 +5,10 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:input="clr-namespace:System.Windows.Input;assembly=PresentationCore" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Height="24" - d:DesignHeight="300" + d:DesignHeight="45" d:DesignWidth="300" mc:Ignorable="d"> - - - - + - \ No newline at end of file + diff --git a/Flow.Launcher/HotkeyControl.xaml.cs b/Flow.Launcher/HotkeyControl.xaml.cs index 3da66caeb..f08a80147 100644 --- a/Flow.Launcher/HotkeyControl.xaml.cs +++ b/Flow.Launcher/HotkeyControl.xaml.cs @@ -1,4 +1,6 @@ using System; +using System.ComponentModel; +using System.Runtime.CompilerServices; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; @@ -9,14 +11,37 @@ using Flow.Launcher.Helper; using Flow.Launcher.Infrastructure.Hotkey; using Flow.Launcher.Plugin; using System.Threading; +using NHotkey; namespace Flow.Launcher { - public partial class HotkeyControl : UserControl + public partial class HotkeyControl : UserControl, IDisposable, INotifyPropertyChanged { + public static readonly DependencyProperty HotkeyProperty = DependencyProperty.Register( + nameof(Hotkey), + typeof(string), + typeof(HotkeyControl), + new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault) + ); public HotkeyModel CurrentHotkey { get; private set; } public bool CurrentHotkeyAvailable { get; private set; } + public string Hotkey + { + get => (string)GetValue(HotkeyProperty); + set + { + SetValue(HotkeyProperty, value); + OnPropertyChanged(nameof(KeysToDisplay)); + } + } + + public string[] KeysToDisplay => Hotkey.Split(" + "); + + #nullable enable + public EventHandler? Action { get; set; } + #nullable restore + public event EventHandler HotkeyChanged; /// @@ -29,6 +54,28 @@ namespace Flow.Launcher public HotkeyControl() { InitializeComponent(); + Loaded += HotkeyControl_Loaded; + } + + private void HotkeyControl_LostFocus(object o, RoutedEventArgs routedEventArgs) + { + HotKeyMapper.SetHotkey(CurrentHotkey, Action); + } + + private void HotkeyControl_GotFocus(object o, RoutedEventArgs routedEventArgs) + { + HotKeyMapper.RemoveHotkey(Hotkey); + } + + private void HotkeyControl_Loaded(object sender, RoutedEventArgs e) + { + _ = SetHotkeyAsync(Hotkey, false); + + if (Action is not null) + { + GotFocus += HotkeyControl_GotFocus; + LostFocus += HotkeyControl_LostFocus; + } } private CancellationTokenSource hotkeyUpdateSource; @@ -68,8 +115,8 @@ namespace Flow.Launcher public async Task SetHotkeyAsync(HotkeyModel keyModel, bool triggerValidate = true) { - tbHotkey.Text = keyModel.ToString(); - tbHotkey.Select(tbHotkey.Text.Length, 0); + // tbHotkey.Text = keyModel.ToString(); + // tbHotkey.Select(tbHotkey.Text.Length, 0); if (triggerValidate) { @@ -86,6 +133,7 @@ namespace Flow.Launcher if (CurrentHotkeyAvailable) { CurrentHotkey = keyModel; + Hotkey = keyModel.ToString(); // To trigger LostFocus FocusManager.SetFocusedElement(FocusManager.GetFocusScope(this), null); Keyboard.ClearFocus(); @@ -94,9 +142,10 @@ namespace Flow.Launcher else { CurrentHotkey = keyModel; + Hotkey = keyModel.ToString(); } } - + public Task SetHotkeyAsync(string keyStr, bool triggerValidate = true) { return SetHotkeyAsync(new HotkeyModel(keyStr), triggerValidate); @@ -104,12 +153,12 @@ namespace Flow.Launcher private static bool CheckHotkeyAvailability(HotkeyModel hotkey, bool validateKeyGesture) => hotkey.Validate(validateKeyGesture) && HotKeyMapper.CheckAvailability(hotkey); - public new bool IsFocused => tbHotkey.IsFocused; + // public new bool IsFocused => tbHotkey.IsFocused; private void tbHotkey_LostFocus(object sender, RoutedEventArgs e) { - tbHotkey.Text = CurrentHotkey?.ToString() ?? ""; - tbHotkey.Select(tbHotkey.Text.Length, 0); + // tbHotkey.Text = CurrentHotkey?.ToString() ?? ""; + // tbHotkey.Select(tbHotkey.Text.Length, 0); } private void tbHotkey_GotFocus(object sender, RoutedEventArgs e) @@ -137,5 +186,25 @@ namespace Flow.Launcher } tbMsg.Visibility = Visibility.Visible; } + + public void Dispose() + { + hotkeyUpdateSource?.Dispose(); + Loaded -= HotkeyControl_Loaded; + GotFocus -= HotkeyControl_GotFocus; + LostFocus -= HotkeyControl_LostFocus; + } + + public event PropertyChangedEventHandler PropertyChanged; + + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + private void OnButtonClicked(object sender, RoutedEventArgs e) + { + // TODO + } } } diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 96f80f0c5..e1b42e3d3 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -693,7 +693,7 @@ - @@ -720,7 +720,7 @@ - + @@ -2657,9 +2657,8 @@ Margin="0,0,0,0" HorizontalAlignment="Right" HorizontalContentAlignment="Right" - GotFocus="OnHotkeyControlFocused" - Loaded="OnHotkeyControlLoaded" - LostFocus="OnHotkeyControlFocusLost" /> + Hotkey="{Binding Settings.Hotkey}" + Action="OnToggleHotkey" />  @@ -2684,8 +2683,7 @@ Margin="0,0,0,0" HorizontalAlignment="Right" HorizontalContentAlignment="Right" - Loaded="OnPreviewHotkeyControlLoaded" - LostFocus="OnPreviewHotkeyControlFocusLost" + Hotkey="{Binding Settings.PreviewHotkey}" ValidateKeyGesture="True" />  diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index 7301be130..e7e9273bb 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -17,6 +17,7 @@ using System.Windows.Forms; using System.Windows.Input; using System.Windows.Interop; using System.Windows.Navigation; +using NHotkey; using Button = System.Windows.Controls.Button; using Control = System.Windows.Controls.Control; using KeyEventArgs = System.Windows.Input.KeyEventArgs; @@ -110,41 +111,9 @@ namespace Flow.Launcher #region Hotkey - private void OnHotkeyControlLoaded(object sender, RoutedEventArgs e) + private void OnToggleHotkey(object sender, HotkeyEventArgs e) { - _ = HotkeyControl.SetHotkeyAsync(viewModel.Settings.Hotkey, false); - } - - private void OnHotkeyControlFocused(object sender, RoutedEventArgs e) - { - HotKeyMapper.RemoveHotkey(settings.Hotkey); - } - - private void OnHotkeyControlFocusLost(object sender, RoutedEventArgs e) - { - if (HotkeyControl.CurrentHotkeyAvailable) - { - HotKeyMapper.SetHotkey(HotkeyControl.CurrentHotkey, HotKeyMapper.OnToggleHotkey); - HotKeyMapper.RemoveHotkey(settings.Hotkey); - settings.Hotkey = HotkeyControl.CurrentHotkey.ToString(); - } - else - { - HotKeyMapper.SetHotkey(new HotkeyModel(settings.Hotkey), HotKeyMapper.OnToggleHotkey); - } - } - - private void OnPreviewHotkeyControlLoaded(object sender, RoutedEventArgs e) - { - _ = PreviewHotkeyControl.SetHotkeyAsync(settings.PreviewHotkey, false); - } - - private void OnPreviewHotkeyControlFocusLost(object sender, RoutedEventArgs e) - { - if (PreviewHotkeyControl.CurrentHotkeyAvailable) - { - settings.PreviewHotkey = PreviewHotkeyControl.CurrentHotkey.ToString(); - } + HotKeyMapper.OnToggleHotkey(sender, e); } private void OnDeleteCustomHotkeyClick(object sender, RoutedEventArgs e) From a0b9d7155844aaf3c5c15a4d8cc95d55bb7af919 Mon Sep 17 00:00:00 2001 From: DB p Date: Fri, 12 Apr 2024 20:56:27 +0900 Subject: [PATCH 02/82] Sizes and Margins Adjust --- Flow.Launcher/HotkeyControl.xaml | 13 ++++++++----- Flow.Launcher/SettingWindow.xaml | 30 ++++++++++-------------------- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/Flow.Launcher/HotkeyControl.xaml b/Flow.Launcher/HotkeyControl.xaml index bea652d56..2dc051205 100644 --- a/Flow.Launcher/HotkeyControl.xaml +++ b/Flow.Launcher/HotkeyControl.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:input="clr-namespace:System.Windows.Input;assembly=PresentationCore" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - d:DesignHeight="45" d:DesignWidth="300" mc:Ignorable="d"> @@ -39,11 +38,16 @@ - + + + + - - - - - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 2339941008f40344479c0ac318c223575c633a0f Mon Sep 17 00:00:00 2001 From: DB p Date: Sat, 13 Apr 2024 18:13:25 +0900 Subject: [PATCH 16/82] Fix Rec Button --- Flow.Launcher/HotkeyControl.xaml | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/Flow.Launcher/HotkeyControl.xaml b/Flow.Launcher/HotkeyControl.xaml index cf0fff2ee..1a347ab13 100644 --- a/Flow.Launcher/HotkeyControl.xaml +++ b/Flow.Launcher/HotkeyControl.xaml @@ -79,7 +79,7 @@ + + diff --git a/Flow.Launcher/Resources/Controls/HotkeyDisplay.xaml.cs b/Flow.Launcher/Resources/Controls/HotkeyDisplay.xaml.cs new file mode 100644 index 000000000..d83b44fac --- /dev/null +++ b/Flow.Launcher/Resources/Controls/HotkeyDisplay.xaml.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Flow.Launcher.Resources.Controls +{ + public partial class HotkeyDisplay : UserControl + { + public HotkeyDisplay() + { + InitializeComponent(); + } + + public string Keys + { + get { return (string)GetValue(KeysValueProperty); } + set { SetValue(KeysValueProperty, value); } + } + public static readonly DependencyProperty KeysValueProperty = + DependencyProperty.Register("Keys", typeof(string), typeof(HotkeyDisplay), new PropertyMetadata(string.Empty)); + } +} diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 3e4f827a6..064e86382 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -2722,7 +2722,9 @@ Title="{DynamicResource flowlauncherHotkey}" Icon="" Sub="{DynamicResource flowlauncherHotkeyToolTip}" - Type="Inside" /> + Type="Inside"> + + Date: Thu, 18 Apr 2024 00:32:10 +0900 Subject: [PATCH 32/82] Added Hotkey Display Control --- .../Resources/Controls/HotkeyDisplay.xaml | 61 ++++++++++++++++++- .../Resources/Controls/HotkeyDisplay.xaml.cs | 25 +++++++- Flow.Launcher/SettingWindow.xaml | 4 +- 3 files changed, 85 insertions(+), 5 deletions(-) diff --git a/Flow.Launcher/Resources/Controls/HotkeyDisplay.xaml b/Flow.Launcher/Resources/Controls/HotkeyDisplay.xaml index 269f095f3..d4483393d 100644 --- a/Flow.Launcher/Resources/Controls/HotkeyDisplay.xaml +++ b/Flow.Launcher/Resources/Controls/HotkeyDisplay.xaml @@ -9,7 +9,62 @@ d:DesignWidth="800" mc:Ignorable="d"> - + + + + + + + + diff --git a/Flow.Launcher/Resources/Controls/HotkeyDisplay.xaml.cs b/Flow.Launcher/Resources/Controls/HotkeyDisplay.xaml.cs index d83b44fac..3549647aa 100644 --- a/Flow.Launcher/Resources/Controls/HotkeyDisplay.xaml.cs +++ b/Flow.Launcher/Resources/Controls/HotkeyDisplay.xaml.cs @@ -1,5 +1,8 @@ using System; +using System.Collections; using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; using System.Globalization; using System.Linq; using System.Text; @@ -13,6 +16,9 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using Windows.Media.Capture.Frames; +using static System.Windows.Forms.LinkLabel; +using static ABI.System.Collections.Generic.IReadOnlyDictionary_Delegates; namespace Flow.Launcher.Resources.Controls { @@ -21,6 +27,9 @@ namespace Flow.Launcher.Resources.Controls public HotkeyDisplay() { InitializeComponent(); + //List stringList =e.NewValue.Split('+').ToList(); + KeysControl.ItemsSource = Values; + } public string Keys @@ -29,6 +38,20 @@ namespace Flow.Launcher.Resources.Controls set { SetValue(KeysValueProperty, value); } } public static readonly DependencyProperty KeysValueProperty = - DependencyProperty.Register("Keys", typeof(string), typeof(HotkeyDisplay), new PropertyMetadata(string.Empty)); + DependencyProperty.Register("Keys", typeof(string), typeof(HotkeyDisplay), new PropertyMetadata(string.Empty, valueChanged)); + + private static void valueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var control = d as UserControl; + if (null == control) return; // This should not be possible + + var newValue = e.NewValue as string; + if (null == newValue) return; + + //String[] Values = newValue.Split('+'); + //Debug.WriteLine(Values[0]); + } + + public ObservableCollection Values { get; set; } } } diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 064e86382..1beafd26b 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -2729,7 +2729,9 @@ Title="{DynamicResource flowlauncherHotkey}" Icon="" Sub="{DynamicResource flowlauncherHotkeyToolTip}" - Type="Inside" /> + Type="Inside"> + + From 66125fce2c041472c667f9b2a400dd670aa4231f Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Wed, 17 Apr 2024 10:45:09 -0500 Subject: [PATCH 33/82] Split Key to display --- .../Resources/Controls/HotkeyDisplay.xaml.cs | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Flow.Launcher/Resources/Controls/HotkeyDisplay.xaml.cs b/Flow.Launcher/Resources/Controls/HotkeyDisplay.xaml.cs index 3549647aa..7ffd90d5f 100644 --- a/Flow.Launcher/Resources/Controls/HotkeyDisplay.xaml.cs +++ b/Flow.Launcher/Resources/Controls/HotkeyDisplay.xaml.cs @@ -28,8 +28,8 @@ namespace Flow.Launcher.Resources.Controls { InitializeComponent(); //List stringList =e.NewValue.Split('+').ToList(); + Values = new ObservableCollection(); KeysControl.ItemsSource = Values; - } public string Keys @@ -37,10 +37,13 @@ namespace Flow.Launcher.Resources.Controls get { return (string)GetValue(KeysValueProperty); } set { SetValue(KeysValueProperty, value); } } - public static readonly DependencyProperty KeysValueProperty = - DependencyProperty.Register("Keys", typeof(string), typeof(HotkeyDisplay), new PropertyMetadata(string.Empty, valueChanged)); - private static void valueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + public static readonly DependencyProperty KeysValueProperty = + DependencyProperty.Register("Keys", typeof(string), typeof(HotkeyDisplay), + new PropertyMetadata(string.Empty, keyChanged)); + + + private static void keyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var control = d as UserControl; if (null == control) return; // This should not be possible @@ -48,8 +51,14 @@ namespace Flow.Launcher.Resources.Controls var newValue = e.NewValue as string; if (null == newValue) return; - //String[] Values = newValue.Split('+'); - //Debug.WriteLine(Values[0]); + if (d is not HotkeyDisplay hotkeyDisplay) + return; + + hotkeyDisplay.Values.Clear(); + foreach (var key in newValue.Split('+')) + { + hotkeyDisplay.Values.Add(key); + } } public ObservableCollection Values { get; set; } From c6b62f9917ddaf1fa3adba0978372b8e62b4eb62 Mon Sep 17 00:00:00 2001 From: DB p Date: Thu, 18 Apr 2024 00:48:29 +0900 Subject: [PATCH 34/82] Fix HotkeyDisplay xaml --- .../Resources/Controls/HotkeyDisplay.xaml | 59 +------------------ 1 file changed, 2 insertions(+), 57 deletions(-) diff --git a/Flow.Launcher/Resources/Controls/HotkeyDisplay.xaml b/Flow.Launcher/Resources/Controls/HotkeyDisplay.xaml index d4483393d..778c77fe5 100644 --- a/Flow.Launcher/Resources/Controls/HotkeyDisplay.xaml +++ b/Flow.Launcher/Resources/Controls/HotkeyDisplay.xaml @@ -9,62 +9,7 @@ d:DesignWidth="800" mc:Ignorable="d"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + From 5c3d3c7fbfb2fa5f34fcd711b247e21705a8c240 Mon Sep 17 00:00:00 2001 From: DB p Date: Thu, 18 Apr 2024 01:00:31 +0900 Subject: [PATCH 35/82] Custom Hotkeys to Expander --- Flow.Launcher/SettingWindow.xaml | 241 ++++++++++++++++--------------- 1 file changed, 122 insertions(+), 119 deletions(-) diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 1beafd26b..1f60e326d 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -2751,128 +2751,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + diff --git a/Flow.Launcher/HotkeyControl.xaml.cs b/Flow.Launcher/HotkeyControl.xaml.cs index 01584ee27..546b252df 100644 --- a/Flow.Launcher/HotkeyControl.xaml.cs +++ b/Flow.Launcher/HotkeyControl.xaml.cs @@ -1,30 +1,38 @@ -using System; +#nullable enable + using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Linq; -using System.Runtime.CompilerServices; +using System.Threading.Tasks; using System.Windows; -using System.Windows.Controls; using System.Windows.Input; -using System.Windows.Media; using Flow.Launcher.Core.Resource; using Flow.Launcher.Helper; using Flow.Launcher.Infrastructure.Hotkey; -using Flow.Launcher.Plugin; -using JetBrains.Annotations; - -#nullable enable namespace Flow.Launcher { - public partial class HotkeyControl : INotifyPropertyChanged + public partial class HotkeyControl { + public string WindowTitle { + get { return (string)GetValue(WindowTitleProperty); } + set { SetValue(WindowTitleProperty, value); } + } + + public static readonly DependencyProperty WindowTitleProperty = DependencyProperty.Register( + nameof(WindowTitle), + typeof(string), + typeof(HotkeyControl), + new PropertyMetadata(string.Empty) + ); + /// /// Designed for Preview Hotkey and KeyGesture. /// public static readonly DependencyProperty ValidateKeyGestureProperty = DependencyProperty.Register( - nameof(ValidateKeyGesture), typeof(bool), typeof(HotkeyControl), - new PropertyMetadata(default(bool))); + nameof(ValidateKeyGesture), + typeof(bool), + typeof(HotkeyControl), + new PropertyMetadata(default(bool)) + ); public bool ValidateKeyGesture { @@ -33,7 +41,11 @@ namespace Flow.Launcher } public static readonly DependencyProperty DefaultHotkeyProperty = DependencyProperty.Register( - nameof(DefaultHotkey), typeof(string), typeof(HotkeyControl), new PropertyMetadata(default(string))); + nameof(DefaultHotkey), + typeof(string), + typeof(HotkeyControl), + new PropertyMetadata(default(string)) + ); public string DefaultHotkey { @@ -54,7 +66,11 @@ namespace Flow.Launcher public static readonly DependencyProperty ChangeHotkeyProperty = DependencyProperty.Register( - nameof(ChangeHotkey), typeof(ICommand), typeof(HotkeyControl), new PropertyMetadata(default(ICommand))); + nameof(ChangeHotkey), + typeof(ICommand), + typeof(HotkeyControl), + new PropertyMetadata(default(ICommand)) + ); public ICommand? ChangeHotkey { @@ -64,8 +80,11 @@ namespace Flow.Launcher public static readonly DependencyProperty HotkeyProperty = DependencyProperty.Register( - nameof(Hotkey), typeof(string), typeof(HotkeyControl), - new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnHotkeyChanged)); + nameof(Hotkey), + typeof(string), + typeof(HotkeyControl), + new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnHotkeyChanged) + ); public string Hotkey { @@ -81,148 +100,50 @@ namespace Flow.Launcher SetKeysToDisplay(CurrentHotkey); } - /*------------------ New Logic Structure Part------------------------*/ - - private void OnPreviewKeyDown(object sender, KeyEventArgs e) - { - if (HotkeyBtn.IsChecked != true) - return; - e.Handled = true; - - //when alt is pressed, the real key should be e.SystemKey - Key key = e.Key == Key.System ? e.SystemKey : e.Key; - - SpecialKeyState specialKeyState = GlobalHotkey.CheckModifiers(); - - var hotkeyModel = new HotkeyModel( - specialKeyState.AltPressed, - specialKeyState.ShiftPressed, - specialKeyState.WinPressed, - specialKeyState.CtrlPressed, - key); - - CurrentHotkey = hotkeyModel; - SetKeysToDisplay(CurrentHotkey); - } - - - // public new bool IsFocused => tbHotkey.IsFocused; - - private void tbHotkey_LostFocus(object sender, RoutedEventArgs e) - { - // tbHotkey.Text = CurrentHotkey?.ToString() ?? ""; - // tbHotkey.Select(tbHotkey.Text.Length, 0); - } - - private void tbHotkey_GotFocus(object sender, RoutedEventArgs e) - { - ResetMessage(); - } - - private void ResetMessage() - { - tbMsg.Text = InternationalizationManager.Instance.GetTranslation("flowlauncherPressHotkey"); - tbMsg.SetResourceReference(TextBox.ForegroundProperty, "Color05B"); - } - - public event PropertyChangedEventHandler? PropertyChanged; - - protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } - - private static bool CheckHotkeyAvailability(HotkeyModel hotkey, bool validateKeyGesture) => hotkey.Validate(validateKeyGesture) && HotKeyMapper.CheckAvailability(hotkey); - public string? Message { get; set; } - public bool MessageVisibility { get; set; } - public SolidColorBrush? MessageColor { get; set; } + public string EmptyHotkey => InternationalizationManager.Instance.GetTranslation("none"); - - public bool CurrentHotkeyAvailable { get; private set; } - - - private void SetMessage(string messageKey, bool error) - { - Message = InternationalizationManager.Instance.GetTranslation(messageKey); - MessageColor = error ? new SolidColorBrush(Colors.Green) : new SolidColorBrush(Colors.Red); - MessageVisibility = true; - } - - - private string EmptyHotkeyKey = "none"; - public string EmptyHotkey => InternationalizationManager.Instance.GetTranslation(EmptyHotkeyKey); - private const string KeySeparator = " + "; - - public ObservableCollection KeysToDisplay { get; set; } = new ObservableCollection(); - - public bool IsEmpty => KeysToDisplay.Count == 0 || (KeysToDisplay.Count == 1 && KeysToDisplay[0] == EmptyHotkey); + public ObservableCollection KeysToDisplay { get; set; } = new(); public HotkeyModel CurrentHotkey { get; private set; } = new(false, false, false, false, Key.None); - public void StartRecording() + public void GetNewHotkey(object sender, RoutedEventArgs e) { - if (!HotkeyBtn.IsChecked ?? false) - { - return; - } + OpenHotkeyDialog(); + } + private async Task OpenHotkeyDialog() + { if (!string.IsNullOrEmpty(Hotkey)) { HotKeyMapper.RemoveHotkey(Hotkey); } - /* 1. Key Recording Start */ - /* 2. Key Display area clear - * 3. Key Display when typing*/ - } - private void StopRecording() - { - try + var dialog = new HotkeyControlDialog(Hotkey, DefaultHotkey, WindowTitle); + await dialog.ShowAsync(); + switch (dialog.ResultType) { - var converter = new KeyGestureConverter(); - _ = (KeyGesture)converter.ConvertFromString(CurrentHotkey.ToString())!; + case HotkeyControlDialog.EResultType.Cancel: + SetHotkey(Hotkey); + return; + case HotkeyControlDialog.EResultType.Save: + SetHotkey(dialog.ResultValue); + break; + case HotkeyControlDialog.EResultType.Delete: + Delete(); + break; } - catch (Exception e) when (e is NotSupportedException or InvalidEnumArgumentException) - { - SetMessage("Hotkey Invalid", true); - CurrentHotkey = new HotkeyModel(Hotkey); - SetKeysToDisplay(CurrentHotkey); - return; - } - - HotkeyBtn.IsChecked = false; - - SetHotkey(CurrentHotkey, true); - } - - private void ResetToDefault() - { - if (!string.IsNullOrEmpty(Hotkey)) - HotKeyMapper.RemoveHotkey(Hotkey); - Hotkey = DefaultHotkey; - CurrentHotkey = new HotkeyModel(Hotkey); - - SetKeysToDisplay(CurrentHotkey); - - SetHotkey(CurrentHotkey); - - HotkeyBtn.IsChecked = false; } private void SetHotkey(HotkeyModel keyModel, bool triggerValidate = true) { - // tbHotkey.Text = keyModel.ToString(); - // tbHotkey.Select(tbHotkey.Text.Length, 0); - if (triggerValidate) { bool hotkeyAvailable = CheckHotkeyAvailability(keyModel, ValidateKeyGesture); - SetMessage(hotkeyAvailable ? "success" : "hotkeyUnavailable", !hotkeyAvailable); if (!hotkeyAvailable) { @@ -246,7 +167,6 @@ namespace Flow.Launcher HotKeyMapper.RemoveHotkey(Hotkey); Hotkey = ""; SetKeysToDisplay(new HotkeyModel(false, false, false, false, Key.None)); - HotkeyBtn.IsChecked = false; } private void SetKeysToDisplay(HotkeyModel? hotkey) @@ -269,14 +189,5 @@ namespace Flow.Launcher { SetHotkey(new HotkeyModel(keyStr), triggerValidate); } - - - private void HotkeyBtn_OnChecked(object sender, RoutedEventArgs e) => StartRecording(); - - - private void ResetButton_OnClick(object sender, RoutedEventArgs e) => ResetToDefault(); - private void DeleteBtn_OnClick(object sender, RoutedEventArgs e) => Delete(); - - private void StopRecordingBtn_Click(object sender, RoutedEventArgs e) => StopRecording(); } } diff --git a/Flow.Launcher/HotkeyControl2.xaml b/Flow.Launcher/HotkeyControl2.xaml deleted file mode 100644 index 730c9604b..000000000 --- a/Flow.Launcher/HotkeyControl2.xaml +++ /dev/null @@ -1,77 +0,0 @@ - - - diff --git a/Flow.Launcher/HotkeyControl2.xaml.cs b/Flow.Launcher/HotkeyControl2.xaml.cs deleted file mode 100644 index 86973a754..000000000 --- a/Flow.Launcher/HotkeyControl2.xaml.cs +++ /dev/null @@ -1,193 +0,0 @@ -#nullable enable - -using System.Collections.ObjectModel; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Input; -using Flow.Launcher.Core.Resource; -using Flow.Launcher.Helper; -using Flow.Launcher.Infrastructure.Hotkey; - -namespace Flow.Launcher -{ - public partial class HotkeyControl2 - { - public string WindowTitle { - get { return (string)GetValue(WindowTitleProperty); } - set { SetValue(WindowTitleProperty, value); } - } - - public static readonly DependencyProperty WindowTitleProperty = DependencyProperty.Register( - nameof(WindowTitle), - typeof(string), - typeof(HotkeyControl2), - new PropertyMetadata(string.Empty) - ); - - /// - /// Designed for Preview Hotkey and KeyGesture. - /// - public static readonly DependencyProperty ValidateKeyGestureProperty = DependencyProperty.Register( - nameof(ValidateKeyGesture), - typeof(bool), - typeof(HotkeyControl2), - new PropertyMetadata(default(bool)) - ); - - public bool ValidateKeyGesture - { - get { return (bool)GetValue(ValidateKeyGestureProperty); } - set { SetValue(ValidateKeyGestureProperty, value); } - } - - public static readonly DependencyProperty DefaultHotkeyProperty = DependencyProperty.Register( - nameof(DefaultHotkey), - typeof(string), - typeof(HotkeyControl2), - new PropertyMetadata(default(string)) - ); - - public string DefaultHotkey - { - get { return (string)GetValue(DefaultHotkeyProperty); } - set { SetValue(DefaultHotkeyProperty, value); } - } - - private static void OnHotkeyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - if (d is not HotkeyControl2 hotkeyControl) - { - return; - } - - hotkeyControl.SetKeysToDisplay(new HotkeyModel(hotkeyControl.Hotkey)); - hotkeyControl.CurrentHotkey = new HotkeyModel(hotkeyControl.Hotkey); - } - - - public static readonly DependencyProperty ChangeHotkeyProperty = DependencyProperty.Register( - nameof(ChangeHotkey), - typeof(ICommand), - typeof(HotkeyControl2), - new PropertyMetadata(default(ICommand)) - ); - - public ICommand? ChangeHotkey - { - get { return (ICommand)GetValue(ChangeHotkeyProperty); } - set { SetValue(ChangeHotkeyProperty, value); } - } - - - public static readonly DependencyProperty HotkeyProperty = DependencyProperty.Register( - nameof(Hotkey), - typeof(string), - typeof(HotkeyControl2), - new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnHotkeyChanged) - ); - - public string Hotkey - { - get { return (string)GetValue(HotkeyProperty); } - set { SetValue(HotkeyProperty, value); } - } - - public HotkeyControl2() - { - InitializeComponent(); - - HotkeyList.ItemsSource = KeysToDisplay; - SetKeysToDisplay(CurrentHotkey); - } - - private static bool CheckHotkeyAvailability(HotkeyModel hotkey, bool validateKeyGesture) => - hotkey.Validate(validateKeyGesture) && HotKeyMapper.CheckAvailability(hotkey); - - public string EmptyHotkey => InternationalizationManager.Instance.GetTranslation("none"); - - public ObservableCollection KeysToDisplay { get; set; } = new(); - - public HotkeyModel CurrentHotkey { get; private set; } = new(false, false, false, false, Key.None); - - - public void GetNewHotkey(object sender, RoutedEventArgs e) - { - OpenHotkeyDialog(); - } - - private async Task OpenHotkeyDialog() - { - if (!string.IsNullOrEmpty(Hotkey)) - { - HotKeyMapper.RemoveHotkey(Hotkey); - } - - var dialog = new HotkeyControl2Dialog(Hotkey, DefaultHotkey, WindowTitle); - await dialog.ShowAsync(); - switch (dialog.ResultType) - { - case HotkeyControl2Dialog.EResultType.Cancel: - SetHotkey(Hotkey); - return; - case HotkeyControl2Dialog.EResultType.Save: - SetHotkey(dialog.ResultValue); - break; - case HotkeyControl2Dialog.EResultType.Delete: - Delete(); - break; - } - } - - - private void SetHotkey(HotkeyModel keyModel, bool triggerValidate = true) - { - if (triggerValidate) - { - bool hotkeyAvailable = CheckHotkeyAvailability(keyModel, ValidateKeyGesture); - - if (!hotkeyAvailable) - { - return; - } - - Hotkey = keyModel.ToString(); - SetKeysToDisplay(CurrentHotkey); - ChangeHotkey?.Execute(keyModel); - } - else - { - Hotkey = keyModel.ToString(); - ChangeHotkey?.Execute(keyModel); - } - } - - public void Delete() - { - if (!string.IsNullOrEmpty(Hotkey)) - HotKeyMapper.RemoveHotkey(Hotkey); - Hotkey = ""; - SetKeysToDisplay(new HotkeyModel(false, false, false, false, Key.None)); - } - - private void SetKeysToDisplay(HotkeyModel? hotkey) - { - KeysToDisplay.Clear(); - - if (hotkey == null || hotkey == default(HotkeyModel)) - { - KeysToDisplay.Add(EmptyHotkey); - return; - } - - foreach (var key in hotkey.Value.EnumerateDisplayKeys()!) - { - KeysToDisplay.Add(key); - } - } - - public void SetHotkey(string? keyStr, bool triggerValidate = true) - { - SetHotkey(new HotkeyModel(keyStr), triggerValidate); - } - } -} diff --git a/Flow.Launcher/HotkeyControl2Dialog.xaml b/Flow.Launcher/HotkeyControlDialog.xaml similarity index 99% rename from Flow.Launcher/HotkeyControl2Dialog.xaml rename to Flow.Launcher/HotkeyControlDialog.xaml index 2eb62c419..6912a1999 100644 --- a/Flow.Launcher/HotkeyControl2Dialog.xaml +++ b/Flow.Launcher/HotkeyControlDialog.xaml @@ -1,5 +1,5 @@  InternationalizationManager.Instance.GetTranslation("none"); - public HotkeyControl2Dialog(string hotkey, string defaultHotkey, string windowTitle = "") + public HotkeyControlDialog(string hotkey, string defaultHotkey, string windowTitle = "") { WindowTitle = windowTitle switch { diff --git a/Flow.Launcher/Resources/Pages/WelcomePage2.xaml b/Flow.Launcher/Resources/Pages/WelcomePage2.xaml index 84615c155..b60b8e47e 100644 --- a/Flow.Launcher/Resources/Pages/WelcomePage2.xaml +++ b/Flow.Launcher/Resources/Pages/WelcomePage2.xaml @@ -110,7 +110,7 @@ FontSize="14" FontWeight="SemiBold" Text="{DynamicResource flowlauncherHotkey}" /> - - - - @@ -2771,7 +2771,7 @@ Title="{DynamicResource SettingWindowHotkey}" Icon="" Type="Inside"> - @@ -2793,7 +2793,7 @@ Title="{DynamicResource SelectNextPageHotkey}" Icon="" Type="Inside"> - @@ -2802,7 +2802,7 @@ Title="{DynamicResource SelectPrevPageHotkey}" Icon="" Type="Inside"> - @@ -2836,7 +2836,7 @@ Icon="" Sub="{DynamicResource autoCompleteHotkeyToolTip}"> - @@ -2845,7 +2845,7 @@ Title="{DynamicResource autoCompleteHotkey}" Sub="{DynamicResource AdditionalHotkeyToolTip}" Type="InsideFit"> - @@ -2858,7 +2858,7 @@ Margin="0,4,0,0" Icon=""> - @@ -2867,7 +2867,7 @@ Title="{DynamicResource SelectNextItemHotkey}" Sub="{DynamicResource AdditionalHotkeyToolTip}" Type="InsideFit"> - @@ -2879,7 +2879,7 @@ Margin="0,4,0,0" Icon=""> - @@ -2888,7 +2888,7 @@ Title="{DynamicResource SelectPrevItemHotkey}" Sub="{DynamicResource AdditionalHotkeyToolTip}" Type="InsideFit"> - From 806e1246126a242908f43e406290f60a88775ddb Mon Sep 17 00:00:00 2001 From: DB p Date: Tue, 23 Apr 2024 12:40:23 +0900 Subject: [PATCH 74/82] - Fix Static Hotkey's Uppercases - Adjust Warning Style in dialog - Adjust Warning Text --- Flow.Launcher/HotkeyControlDialog.xaml | 42 +++++++++++--------------- Flow.Launcher/Languages/en.xaml | 2 +- Flow.Launcher/SettingWindow.xaml | 18 +++++------ 3 files changed, 28 insertions(+), 34 deletions(-) diff --git a/Flow.Launcher/HotkeyControlDialog.xaml b/Flow.Launcher/HotkeyControlDialog.xaml index 6912a1999..322f82366 100644 --- a/Flow.Launcher/HotkeyControlDialog.xaml +++ b/Flow.Launcher/HotkeyControlDialog.xaml @@ -24,9 +24,7 @@ - + @@ -38,9 +36,7 @@ FontWeight="SemiBold" Text="{Binding WindowTitle}" TextAlignment="Left" /> - + - + - - - - - - + + + + diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index c92f227b3..6205c06bc 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -310,7 +310,7 @@ Invalid plugin hotkey Update Binding Hotkey - It's unavailable hotkey. + This hotkey is unavailable. Press the keys you want to use for this function. diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 15db60573..89a454fc0 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -2731,13 +2731,13 @@ Title="{DynamicResource OpenContainFolderHotkey}" Icon="" Type="Inside"> - + - + - + - + - + - - + + - - + + From 2f471b6273a8f7ce26e60471d3c6b3aeff9386f7 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Wed, 24 Apr 2024 23:40:44 +1000 Subject: [PATCH 75/82] update wording --- Flow.Launcher/Languages/en.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index 6205c06bc..fa07a62ea 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -176,7 +176,7 @@ Enter shortcut to show/hide Flow Launcher. Toggle Preview Enter shortcut to show/hide preview in search window. - Basic Hotkeys + Hotkey Presets List of shortcuts used by basic Open Result Modifier Key Select a modifier key to open selected result via keyboard. From 7a5f9dd0ff1fc9d6669747f23e1a3d40cbdfac6a Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Wed, 24 Apr 2024 23:41:03 +1000 Subject: [PATCH 76/82] update wording --- Flow.Launcher/Languages/en.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index fa07a62ea..b1a5a1ac2 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -177,7 +177,7 @@ Toggle Preview Enter shortcut to show/hide preview in search window. Hotkey Presets - List of shortcuts used by basic + List of currently registered hotkeys Open Result Modifier Key Select a modifier key to open selected result via keyboard. Show Hotkey From db2765a4c14010f2e909d30b08a79e9461863ab4 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Wed, 24 Apr 2024 23:42:07 +1000 Subject: [PATCH 77/82] update wording --- Flow.Launcher/Languages/en.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index b1a5a1ac2..a07555a66 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -198,7 +198,7 @@ Reload Plugins Data Quick Adjust Window Width Size Quick Adjust Window Height Size - Use it when the plugin settings you changed don't take effect. + Use when require plugins to reload and update their existing data. You can add one more hotkey for this function. Custom Query Hotkeys Custom Query Shortcuts From 30463b1a8318ee19829bb7682791e407dd40d7bd Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Wed, 24 Apr 2024 23:42:28 +1000 Subject: [PATCH 78/82] update wording --- Flow.Launcher/Languages/en.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index a07555a66..f9f76e9f3 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -310,7 +310,7 @@ Invalid plugin hotkey Update Binding Hotkey - This hotkey is unavailable. + Current hotkey is unavailable. Press the keys you want to use for this function. From 3e2e5c3e3273cf04c55c49c9dba22d28150711d7 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Wed, 24 Apr 2024 23:59:17 +1000 Subject: [PATCH 79/82] update translation key --- Flow.Launcher/Languages/en.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index f9f76e9f3..ca2c2889b 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -176,7 +176,7 @@ Enter shortcut to show/hide Flow Launcher. Toggle Preview Enter shortcut to show/hide preview in search window. - Hotkey Presets + Hotkey Presets List of currently registered hotkeys Open Result Modifier Key Select a modifier key to open selected result via keyboard. From 1b8d310712bd6ad383778b504deb0b9579fcd768 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Wed, 24 Apr 2024 23:59:34 +1000 Subject: [PATCH 80/82] update translation key --- Flow.Launcher/Languages/en.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index ca2c2889b..b71e25e8f 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -177,7 +177,7 @@ Toggle Preview Enter shortcut to show/hide preview in search window. Hotkey Presets - List of currently registered hotkeys + List of currently registered hotkeys Open Result Modifier Key Select a modifier key to open selected result via keyboard. Show Hotkey From c27f58fe3ee1b8530080db98c0fcb7c1cbbbd498 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Wed, 24 Apr 2024 23:59:45 +1000 Subject: [PATCH 81/82] update translation key --- Flow.Launcher/SettingWindow.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 89a454fc0..3b1319355 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -2722,7 +2722,7 @@ From 55f2b6a55025244bf42d921996617e97aa132541 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Thu, 25 Apr 2024 00:00:00 +1000 Subject: [PATCH 82/82] update translation key --- Flow.Launcher/SettingWindow.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 3b1319355..8730c2156 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -2725,7 +2725,7 @@ Title="{DynamicResource hotkeyPresets}" Margin="0,14,0,0" Icon="" - Sub="{DynamicResource basicHotkeyToolTip}"> + Sub="{DynamicResource hotkeyPresetsToolTip}">