fix popup empty when same key press, add reset pop msg when lost focus

This commit is contained in:
Jeremy 2021-12-04 20:36:04 +11:00
parent 69b0dc9a62
commit 178776f200
3 changed files with 25 additions and 2 deletions

View file

@ -50,6 +50,7 @@
VerticalContentAlignment="Center"
input:InputMethod.IsInputMethodEnabled="False"
PreviewKeyDown="TbHotkey_OnPreviewKeyDown"
TabIndex="100" />
TabIndex="100"
LostFocus="tbHotkey_LostFocus"/>
</Grid>
</UserControl>

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}