HotkeyControl: add click handlers, add default hotkey

This commit is contained in:
Yusyuriv 2024-04-12 18:32:33 +06:00
parent 7458e10174
commit 78a6b27aa1
No known key found for this signature in database
GPG key ID: A91C52E6F73148E0
3 changed files with 36 additions and 7 deletions

View file

@ -39,8 +39,7 @@
</Popup>
<ToggleButton
x:Name="HotkeyBtn"
Click="OnButtonClicked"
IsChecked="{Binding IsEditingHotkey, Mode=TwoWay, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
FontSize="13"
FontWeight="Bold"
Foreground="{DynamicResource Color01B}">
@ -60,9 +59,9 @@
BorderThickness="1"
CornerRadius="5">
<StackPanel Orientation="Horizontal">
<Button Content="Reset" />
<Button Content="Delete" />
<Button Content="Stop Rec" />
<Button Content="Reset" Click="OnResetToDefaultClicked" />
<Button Content="Delete" Click="OnDeleteClicked" />
<Button Content="Stop Rec" Click="OnStopRecordingClicked" />
</StackPanel>
</Border>

View file

@ -36,8 +36,19 @@ namespace Flow.Launcher
}
}
public string DefaultHotkey { get; set; }
public string[] KeysToDisplay => Hotkey.Split(" + ");
private bool _isEditingHotkey = false;
public bool IsEditingHotkey {
get => _isEditingHotkey;
set {
_isEditingHotkey = value;
OnPropertyChanged();
}
}
#nullable enable
public EventHandler<HotkeyEventArgs>? Action { get; set; }
#nullable restore
@ -202,9 +213,26 @@ namespace Flow.Launcher
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private void OnButtonClicked(object sender, RoutedEventArgs e)
private void OnStopRecordingClicked(object sender, RoutedEventArgs e)
{
// TODO
IsEditingHotkey = false;
}
private void OnResetToDefaultClicked(object sender, RoutedEventArgs e)
{
IsEditingHotkey = false;
if (!string.IsNullOrEmpty(Hotkey))
HotKeyMapper.RemoveHotkey(Hotkey);
Hotkey = DefaultHotkey;
HotKeyMapper.SetHotkey(new HotkeyModel(Hotkey), Action);
}
private void OnDeleteClicked(object sender, RoutedEventArgs e)
{
IsEditingHotkey = false;
if (!string.IsNullOrEmpty(Hotkey))
HotKeyMapper.RemoveHotkey(Hotkey);
Hotkey = "";
}
}
}

View file

@ -2649,6 +2649,7 @@
Margin="0,0,16,0"
HorizontalAlignment="Right"
HorizontalContentAlignment="Right"
DefaultHotkey="Alt + Space"
Action="OnToggleHotkey"
Hotkey="{Binding Settings.Hotkey}" />
@ -2673,6 +2674,7 @@
Margin="0,0,16,0"
HorizontalAlignment="Right"
HorizontalContentAlignment="Right"
DefaultHotkey="F1"
Hotkey="{Binding Settings.PreviewHotkey}"
ValidateKeyGesture="True" />
<TextBlock Style="{StaticResource Glyph}">