diff --git a/Flow.Launcher/Converters/StringToKeyBindingConverter.cs b/Flow.Launcher/Converters/StringToKeyBindingConverter.cs new file mode 100644 index 000000000..3675f06fc --- /dev/null +++ b/Flow.Launcher/Converters/StringToKeyBindingConverter.cs @@ -0,0 +1,32 @@ +using System; +using System.Globalization; +using System.Windows.Data; +using System.Windows.Input; + +namespace Flow.Launcher.Converters +{ + class StringToKeyBindingConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + var mode = parameter as string; + var hotkeyStr = value as string; + var converter = new KeyGestureConverter(); + var key = (KeyGesture)converter.ConvertFromString(hotkeyStr); + if (mode == "key") + { + return key.Key; + } + else if (mode == "modifiers") + { + return key.Modifiers; + } + return null; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index 433c3ec7f..d6aec2a60 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -40,6 +40,7 @@ + @@ -181,9 +182,9 @@ Command="{Binding ToggleGameModeCommand}" Modifiers="Ctrl"/> + Modifiers="{Binding PreviewHotkey, Converter={StaticResource StringToKeyBindingConverter}, ConverterParameter='modifiers'}"/> diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index f7e6318ea..a220251f3 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -75,7 +75,7 @@ namespace Flow.Launcher.ViewModel OnPropertyChanged(nameof(OpenResultCommandModifiers)); break; case nameof(Settings.PreviewHotkey): - UpdatePreviewHotkey(); + OnPropertyChanged(nameof(PreviewHotkey)); break; } }; @@ -115,7 +115,6 @@ namespace Flow.Launcher.ViewModel RegisterViewUpdate(); RegisterResultsUpdatedEvent(); _ = RegisterClockAndDateUpdateAsync(); - UpdatePreviewHotkey(); } private void RegisterViewUpdate() @@ -584,9 +583,7 @@ namespace Flow.Launcher.ViewModel public string OpenResultCommandModifiers => Settings.OpenResultModifiers; - public Key TogglePreviewHotkey { get; set; } - - public ModifierKeys TogglePreviewModifiers { get; set; } + public string PreviewHotkey => Settings.PreviewHotkey; public string Image => Constant.QueryTextBoxIconImagePath; @@ -1018,14 +1015,6 @@ 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