From 178776f2006a749f17875fc9213624acf4bbee46 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sat, 4 Dec 2021 20:36:04 +1100 Subject: [PATCH] fix popup empty when same key press, add reset pop msg when lost focus --- Flow.Launcher/HotkeyControl.xaml | 3 ++- Flow.Launcher/HotkeyControl.xaml.cs | 13 ++++++++++++- Flow.Launcher/Resources/Pages/WelcomePage2.xaml.cs | 11 +++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher/HotkeyControl.xaml b/Flow.Launcher/HotkeyControl.xaml index 94cdc6703..9b5f671d8 100644 --- a/Flow.Launcher/HotkeyControl.xaml +++ b/Flow.Launcher/HotkeyControl.xaml @@ -50,6 +50,7 @@ VerticalContentAlignment="Center" input:InputMethod.IsInputMethodEnabled="False" PreviewKeyDown="TbHotkey_OnPreviewKeyDown" - TabIndex="100" /> + TabIndex="100" + LostFocus="tbHotkey_LostFocus"/> \ No newline at end of file diff --git a/Flow.Launcher/HotkeyControl.xaml.cs b/Flow.Launcher/HotkeyControl.xaml.cs index 43a4936b0..9ba7c4368 100644 --- a/Flow.Launcher/HotkeyControl.xaml.cs +++ b/Flow.Launcher/HotkeyControl.xaml.cs @@ -14,6 +14,10 @@ namespace Flow.Launcher { public partial class HotkeyControl : UserControl { + private Brush tbMsgForegroundColorOriginal; + + private string tbMsgTextOriginal; + public HotkeyModel CurrentHotkey { get; private set; } public bool CurrentHotkeyAvailable { get; private set; } @@ -24,6 +28,8 @@ namespace Flow.Launcher public HotkeyControl() { InitializeComponent(); + tbMsgTextOriginal = tbMsg.Text; + tbMsgForegroundColorOriginal = tbMsg.Foreground; } private CancellationTokenSource hotkeyUpdateSource; @@ -35,7 +41,6 @@ namespace Flow.Launcher hotkeyUpdateSource = new(); var token = hotkeyUpdateSource.Token; e.Handled = true; - tbMsg.Visibility = Visibility.Hidden; //when alt is pressed, the real key should be e.SystemKey Key key = e.Key == Key.System ? e.SystemKey : e.Key; @@ -104,5 +109,11 @@ namespace Flow.Launcher private bool CheckHotkeyAvailability() => HotKeyMapper.CheckAvailability(CurrentHotkey); public new bool IsFocused => tbHotkey.IsFocused; + + private void tbHotkey_LostFocus(object sender, RoutedEventArgs e) + { + tbMsg.Text = tbMsgTextOriginal; + tbMsg.Foreground = tbMsgForegroundColorOriginal; + } } } \ No newline at end of file diff --git a/Flow.Launcher/Resources/Pages/WelcomePage2.xaml.cs b/Flow.Launcher/Resources/Pages/WelcomePage2.xaml.cs index 70c828f47..a433611f6 100644 --- a/Flow.Launcher/Resources/Pages/WelcomePage2.xaml.cs +++ b/Flow.Launcher/Resources/Pages/WelcomePage2.xaml.cs @@ -3,6 +3,7 @@ using Flow.Launcher.Infrastructure.Hotkey; using Flow.Launcher.Infrastructure.UserSettings; using System; using System.Windows; +using System.Windows.Media; using System.Windows.Navigation; namespace Flow.Launcher.Resources.Pages @@ -11,13 +12,20 @@ namespace Flow.Launcher.Resources.Pages { private Settings Settings { get; set; } + private Brush tbMsgForegroundColorOriginal; + + private string tbMsgTextOriginal; + protected override void OnNavigatedTo(NavigationEventArgs e) { if (e.ExtraData is Settings settings) Settings = settings; else throw new ArgumentException("Unexpected Parameter setting."); + InitializeComponent(); + tbMsgTextOriginal = HotkeyControl.tbMsg.Text; + tbMsgForegroundColorOriginal = HotkeyControl.tbMsg.Foreground; HotkeyControl.SetHotkey(new Infrastructure.Hotkey.HotkeyModel(Settings.Hotkey), false); } @@ -36,6 +44,9 @@ namespace Flow.Launcher.Resources.Pages { HotKeyMapper.SetHotkey(new HotkeyModel(Settings.Hotkey), HotKeyMapper.OnToggleHotkey); } + + HotkeyControl.tbMsg.Text = tbMsgTextOriginal; + HotkeyControl.tbMsg.Foreground = tbMsgForegroundColorOriginal; } } } \ No newline at end of file