Support hotkey modifiers

This commit is contained in:
Vic 2022-12-27 15:21:06 +08:00
parent 68ae8a1df3
commit 979aa3ddff
2 changed files with 16 additions and 3 deletions

View file

@ -182,7 +182,8 @@
Modifiers="Ctrl"/>
<KeyBinding
Key="{Binding TogglePreviewHotkey}"
Command="{Binding TogglePreviewCommand}"/>
Command="{Binding TogglePreviewCommand}"
Modifiers="{Binding TogglePreviewModifiers}"/>
</Window.InputBindings>
<Grid>
<Border MouseDown="OnMouseDown" Style="{DynamicResource WindowBorderStyle}">

View file

@ -23,6 +23,7 @@ using System.IO;
using System.Collections.Specialized;
using CommunityToolkit.Mvvm.Input;
using System.Globalization;
using System.Windows.Input;
namespace Flow.Launcher.ViewModel
{
@ -74,7 +75,7 @@ namespace Flow.Launcher.ViewModel
OnPropertyChanged(nameof(OpenResultCommandModifiers));
break;
case nameof(Settings.PreviewHotkey):
OnPropertyChanged(nameof(TogglePreviewHotkey));
UpdatePreviewHotkey();
break;
}
};
@ -114,6 +115,7 @@ namespace Flow.Launcher.ViewModel
RegisterViewUpdate();
RegisterResultsUpdatedEvent();
_ = RegisterClockAndDateUpdateAsync();
UpdatePreviewHotkey();
}
private void RegisterViewUpdate()
@ -582,7 +584,9 @@ namespace Flow.Launcher.ViewModel
public string OpenResultCommandModifiers => Settings.OpenResultModifiers;
public string TogglePreviewHotkey => Settings.PreviewHotkey; // TODO: is hotkey combo possible?
public Key TogglePreviewHotkey { get; set; }
public ModifierKeys TogglePreviewModifiers { get; set; }
public string Image => Constant.QueryTextBoxIconImagePath;
@ -1014,6 +1018,14 @@ namespace Flow.Launcher.ViewModel
return Settings.IgnoreHotkeysOnFullscreen && WindowsInteropHelper.IsWindowFullscreen() || GameModeStatus;
}
private void UpdatePreviewHotkey()
{
var converter = new KeyGestureConverter();
var key = (KeyGesture)converter.ConvertFromString(Settings.PreviewHotkey);
TogglePreviewHotkey = key.Key;
TogglePreviewModifiers = key.Modifiers;
}
#endregion
#region Public Methods