mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Merge branch 'development' into feature/update-avalonia
This commit is contained in:
commit
81a7b0d089
7 files changed
+100
-21
No files matched your search
@@ -10,8 +10,16 @@
|
||||
<Style Selector="TextBox#DisplayTextBox:focus:not(TextBox:empty)">
|
||||
<Setter Property="InnerRightContent">
|
||||
<Template>
|
||||
<Button Classes="textBoxClearButton"
|
||||
Click="Button_OnClick" />
|
||||
<Button Theme="{StaticResource TextBoxDeleteButtonStyle}"
|
||||
Click="Button_OnClick"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="{DynamicResource ControlCornerRadius}"
|
||||
Padding="{StaticResource HelperButtonThemePadding}"
|
||||
IsTabStop="False"
|
||||
Focusable="False"
|
||||
FontSize="{TemplateBinding FontSize}"
|
||||
Width="30"
|
||||
VerticalAlignment="Stretch" />
|
||||
</Template>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
@@ -8,6 +8,8 @@ using Avalonia.Data;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Threading;
|
||||
using DryIoc;
|
||||
using FluentAvalonia.Core;
|
||||
using Humanizer;
|
||||
using Material.Icons;
|
||||
@@ -19,44 +21,62 @@ namespace Artemis.UI.Shared;
|
||||
/// </summary>
|
||||
public partial class HotkeyBox : UserControl
|
||||
{
|
||||
private readonly IInputService _inputService;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="HotkeyBox" /> class
|
||||
/// </summary>
|
||||
public HotkeyBox()
|
||||
{
|
||||
_inputService = UI.Locator.Resolve<IInputService>();
|
||||
|
||||
InitializeComponent();
|
||||
PropertyChanged += OnPropertyChanged;
|
||||
DisplayTextBox.KeyDown += DisplayTextBoxOnKeyDown;
|
||||
DisplayTextBox.KeyUp += DisplayTextBoxOnKeyUp;
|
||||
UpdateDisplayTextBox();
|
||||
}
|
||||
|
||||
protected override void OnGotFocus(GotFocusEventArgs e)
|
||||
{
|
||||
_inputService.KeyboardKeyDown += InputServiceOnKeyboardKeyDown;
|
||||
_inputService.KeyboardKeyUp += InputServiceOnKeyboardKeyUp;
|
||||
|
||||
base.OnGotFocus(e);
|
||||
}
|
||||
|
||||
protected override void OnLostFocus(RoutedEventArgs e)
|
||||
{
|
||||
_inputService.KeyboardKeyDown -= InputServiceOnKeyboardKeyDown;
|
||||
_inputService.KeyboardKeyUp -= InputServiceOnKeyboardKeyUp;
|
||||
|
||||
base.OnLostFocus(e);
|
||||
}
|
||||
|
||||
private void OnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.Property == HotkeyProperty)
|
||||
UpdateDisplayTextBox();
|
||||
}
|
||||
|
||||
private void DisplayTextBoxOnKeyDown(object? sender, KeyEventArgs e)
|
||||
private void InputServiceOnKeyboardKeyDown(object? sender, ArtemisKeyboardKeyEventArgs e)
|
||||
{
|
||||
if (e.Key >= Key.LeftShift && e.Key <= Key.RightAlt)
|
||||
if (e.Key >= KeyboardKey.LeftShift && e.Key <= KeyboardKey.RightAlt)
|
||||
return;
|
||||
|
||||
Hotkey ??= new Hotkey();
|
||||
Hotkey.Key = (KeyboardKey?) e.Key;
|
||||
Hotkey.Modifiers = (KeyboardModifierKey?) e.KeyModifiers;
|
||||
UpdateDisplayTextBox();
|
||||
HotkeyChanged?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
e.Handled = true;
|
||||
Hotkey.Key = e.Key;
|
||||
Hotkey.Modifiers = e.Modifiers;
|
||||
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
UpdateDisplayTextBox();
|
||||
HotkeyChanged?.Invoke(this, EventArgs.Empty);
|
||||
});
|
||||
}
|
||||
|
||||
private void DisplayTextBoxOnKeyUp(object? sender, KeyEventArgs e)
|
||||
private void InputServiceOnKeyboardKeyUp(object? sender, ArtemisKeyboardKeyEventArgs e)
|
||||
{
|
||||
if (e.KeyModifiers == KeyModifiers.None)
|
||||
FocusManager.Instance?.Focus(null);
|
||||
|
||||
e.Handled = true;
|
||||
if (e.Modifiers == KeyboardModifierKey.None)
|
||||
Dispatcher.UIThread.Post(() => FocusManager.Instance?.Focus(null));
|
||||
}
|
||||
|
||||
private void UpdateDisplayTextBox()
|
||||
|
||||
@@ -17,5 +17,7 @@ public static class ContainerExtensions
|
||||
{
|
||||
Assembly artemisShared = typeof(IArtemisSharedUIService).GetAssembly();
|
||||
container.RegisterMany(new[] { artemisShared }, type => type.IsAssignableTo<IArtemisSharedUIService>(), Reuse.Singleton);
|
||||
|
||||
UI.Locator = container;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using DryIoc;
|
||||
|
||||
namespace Artemis.UI.Shared;
|
||||
|
||||
internal static class UI
|
||||
{
|
||||
public static IContainer Locator { get; set; } = null!;
|
||||
}
|
||||
Reference in new issue
Block a user