mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Use databinding for preview hotkey
This commit is contained in:
parent
979aa3ddff
commit
3ff7566daa
3 changed files with 37 additions and 15 deletions
32
Flow.Launcher/Converters/StringToKeyBindingConverter.cs
Normal file
32
Flow.Launcher/Converters/StringToKeyBindingConverter.cs
Normal file
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -40,6 +40,7 @@
|
|||
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
|
||||
<converters:BoolToIMEConversionModeConverter x:Key="BoolToIMEConversionModeConverter"/>
|
||||
<converters:BoolToIMEStateConverter x:Key="BoolToIMEStateConverter"/>
|
||||
<converters:StringToKeyBindingConverter x:Key="StringToKeyBindingConverter"/>
|
||||
</Window.Resources>
|
||||
<Window.InputBindings>
|
||||
<KeyBinding Key="Escape" Command="{Binding EscCommand}" />
|
||||
|
|
@ -181,9 +182,9 @@
|
|||
Command="{Binding ToggleGameModeCommand}"
|
||||
Modifiers="Ctrl"/>
|
||||
<KeyBinding
|
||||
Key="{Binding TogglePreviewHotkey}"
|
||||
Key="{Binding PreviewHotkey, Converter={StaticResource StringToKeyBindingConverter}, ConverterParameter='key'}"
|
||||
Command="{Binding TogglePreviewCommand}"
|
||||
Modifiers="{Binding TogglePreviewModifiers}"/>
|
||||
Modifiers="{Binding PreviewHotkey, Converter={StaticResource StringToKeyBindingConverter}, ConverterParameter='modifiers'}"/>
|
||||
</Window.InputBindings>
|
||||
<Grid>
|
||||
<Border MouseDown="OnMouseDown" Style="{DynamicResource WindowBorderStyle}">
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue