mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Merge branch 'development' into feature/update-avalonia
This commit is contained in:
commit
81a7b0d089
@ -10,7 +10,7 @@ public class ArtemisPluginException : Exception
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new instance of the <see cref="ArtemisPluginException" /> class
|
/// Creates a new instance of the <see cref="ArtemisPluginException" /> class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ArtemisPluginException(Plugin plugin)
|
internal ArtemisPluginException(Plugin plugin)
|
||||||
{
|
{
|
||||||
Plugin = plugin;
|
Plugin = plugin;
|
||||||
}
|
}
|
||||||
@ -18,7 +18,7 @@ public class ArtemisPluginException : Exception
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new instance of the <see cref="ArtemisPluginException" /> class
|
/// Creates a new instance of the <see cref="ArtemisPluginException" /> class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ArtemisPluginException(Plugin plugin, string message) : base(message)
|
internal ArtemisPluginException(Plugin plugin, string message) : base(message)
|
||||||
{
|
{
|
||||||
Plugin = plugin;
|
Plugin = plugin;
|
||||||
}
|
}
|
||||||
@ -26,7 +26,7 @@ public class ArtemisPluginException : Exception
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new instance of the <see cref="ArtemisPluginException" /> class
|
/// Creates a new instance of the <see cref="ArtemisPluginException" /> class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ArtemisPluginException(Plugin plugin, string message, Exception inner) : base(message, inner)
|
internal ArtemisPluginException(Plugin plugin, string message, Exception inner) : base(message, inner)
|
||||||
{
|
{
|
||||||
Plugin = plugin;
|
Plugin = plugin;
|
||||||
}
|
}
|
||||||
@ -45,8 +45,30 @@ public class ArtemisPluginException : Exception
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new instance of the <see cref="ArtemisPluginException" /> class
|
||||||
|
/// </summary>
|
||||||
|
public ArtemisPluginException(string message, string helpDocument) : base(message)
|
||||||
|
{
|
||||||
|
HelpDocument = helpDocument;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new instance of the <see cref="ArtemisPluginException" /> class
|
||||||
|
/// </summary>
|
||||||
|
public ArtemisPluginException(string message, Exception inner, string helpDocument) : base(message, inner)
|
||||||
|
{
|
||||||
|
HelpDocument = helpDocument;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the plugin the error is related to
|
/// Gets the plugin the error is related to
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Plugin? Plugin { get; }
|
public Plugin? Plugin { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the help document related to this exception.
|
||||||
|
/// </summary>
|
||||||
|
public string? HelpDocument { get; }
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -127,6 +127,13 @@ public interface IPluginManagementService : IArtemisService, IDisposable
|
|||||||
/// <returns>If the current call stack contains a plugin, the plugin. Otherwise null</returns>
|
/// <returns>If the current call stack contains a plugin, the plugin. Otherwise null</returns>
|
||||||
Plugin? GetCallingPlugin();
|
Plugin? GetCallingPlugin();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the plugin that threw the provided exception.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="exception"></param>
|
||||||
|
/// <returns>If the exception was thrown by a plugin, the plugin. Otherwise null</returns>
|
||||||
|
Plugin? GetPluginFromException(Exception exception);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the plugin that defined the specified device
|
/// Gets the plugin that defined the specified device
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -192,7 +192,19 @@ internal class PluginManagementService : IPluginManagementService
|
|||||||
|
|
||||||
public Plugin? GetCallingPlugin()
|
public Plugin? GetCallingPlugin()
|
||||||
{
|
{
|
||||||
StackTrace stackTrace = new(); // get call stack
|
return GetPluginFromStackTrace(new StackTrace());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Plugin? GetPluginFromException(Exception exception)
|
||||||
|
{
|
||||||
|
if (exception is ArtemisPluginException pluginException && pluginException.Plugin != null)
|
||||||
|
return pluginException.Plugin;
|
||||||
|
|
||||||
|
return GetPluginFromStackTrace(new StackTrace(exception));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Plugin? GetPluginFromStackTrace(StackTrace stackTrace)
|
||||||
|
{
|
||||||
StackFrame[] stackFrames = stackTrace.GetFrames(); // get method calls (frames)
|
StackFrame[] stackFrames = stackTrace.GetFrames(); // get method calls (frames)
|
||||||
|
|
||||||
foreach (StackFrame stackFrame in stackFrames)
|
foreach (StackFrame stackFrame in stackFrames)
|
||||||
|
|||||||
@ -10,8 +10,16 @@
|
|||||||
<Style Selector="TextBox#DisplayTextBox:focus:not(TextBox:empty)">
|
<Style Selector="TextBox#DisplayTextBox:focus:not(TextBox:empty)">
|
||||||
<Setter Property="InnerRightContent">
|
<Setter Property="InnerRightContent">
|
||||||
<Template>
|
<Template>
|
||||||
<Button Classes="textBoxClearButton"
|
<Button Theme="{StaticResource TextBoxDeleteButtonStyle}"
|
||||||
Click="Button_OnClick" />
|
Click="Button_OnClick"
|
||||||
|
BorderThickness="{TemplateBinding BorderThickness}"
|
||||||
|
CornerRadius="{DynamicResource ControlCornerRadius}"
|
||||||
|
Padding="{StaticResource HelperButtonThemePadding}"
|
||||||
|
IsTabStop="False"
|
||||||
|
Focusable="False"
|
||||||
|
FontSize="{TemplateBinding FontSize}"
|
||||||
|
Width="30"
|
||||||
|
VerticalAlignment="Stretch" />
|
||||||
</Template>
|
</Template>
|
||||||
</Setter>
|
</Setter>
|
||||||
</Style>
|
</Style>
|
||||||
|
|||||||
@ -8,6 +8,8 @@ using Avalonia.Data;
|
|||||||
using Avalonia.Input;
|
using Avalonia.Input;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
|
using Avalonia.Threading;
|
||||||
|
using DryIoc;
|
||||||
using FluentAvalonia.Core;
|
using FluentAvalonia.Core;
|
||||||
using Humanizer;
|
using Humanizer;
|
||||||
using Material.Icons;
|
using Material.Icons;
|
||||||
@ -19,44 +21,62 @@ namespace Artemis.UI.Shared;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class HotkeyBox : UserControl
|
public partial class HotkeyBox : UserControl
|
||||||
{
|
{
|
||||||
|
private readonly IInputService _inputService;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new instance of the <see cref="HotkeyBox" /> class
|
/// Creates a new instance of the <see cref="HotkeyBox" /> class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public HotkeyBox()
|
public HotkeyBox()
|
||||||
{
|
{
|
||||||
|
_inputService = UI.Locator.Resolve<IInputService>();
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
PropertyChanged += OnPropertyChanged;
|
PropertyChanged += OnPropertyChanged;
|
||||||
DisplayTextBox.KeyDown += DisplayTextBoxOnKeyDown;
|
|
||||||
DisplayTextBox.KeyUp += DisplayTextBoxOnKeyUp;
|
|
||||||
UpdateDisplayTextBox();
|
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)
|
private void OnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Property == HotkeyProperty)
|
if (e.Property == HotkeyProperty)
|
||||||
UpdateDisplayTextBox();
|
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;
|
return;
|
||||||
|
|
||||||
Hotkey ??= new Hotkey();
|
Hotkey ??= new Hotkey();
|
||||||
Hotkey.Key = (KeyboardKey?) e.Key;
|
Hotkey.Key = e.Key;
|
||||||
Hotkey.Modifiers = (KeyboardModifierKey?) e.KeyModifiers;
|
Hotkey.Modifiers = e.Modifiers;
|
||||||
|
|
||||||
|
Dispatcher.UIThread.Post(() =>
|
||||||
|
{
|
||||||
UpdateDisplayTextBox();
|
UpdateDisplayTextBox();
|
||||||
HotkeyChanged?.Invoke(this, EventArgs.Empty);
|
HotkeyChanged?.Invoke(this, EventArgs.Empty);
|
||||||
|
});
|
||||||
e.Handled = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DisplayTextBoxOnKeyUp(object? sender, KeyEventArgs e)
|
private void InputServiceOnKeyboardKeyUp(object? sender, ArtemisKeyboardKeyEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.KeyModifiers == KeyModifiers.None)
|
if (e.Modifiers == KeyboardModifierKey.None)
|
||||||
FocusManager.Instance?.Focus(null);
|
Dispatcher.UIThread.Post(() => FocusManager.Instance?.Focus(null));
|
||||||
|
|
||||||
e.Handled = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateDisplayTextBox()
|
private void UpdateDisplayTextBox()
|
||||||
|
|||||||
@ -17,5 +17,7 @@ public static class ContainerExtensions
|
|||||||
{
|
{
|
||||||
Assembly artemisShared = typeof(IArtemisSharedUIService).GetAssembly();
|
Assembly artemisShared = typeof(IArtemisSharedUIService).GetAssembly();
|
||||||
container.RegisterMany(new[] { artemisShared }, type => type.IsAssignableTo<IArtemisSharedUIService>(), Reuse.Singleton);
|
container.RegisterMany(new[] { artemisShared }, type => type.IsAssignableTo<IArtemisSharedUIService>(), Reuse.Singleton);
|
||||||
|
|
||||||
|
UI.Locator = container;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
8
src/Artemis.UI.Shared/Utilities.cs
Normal file
8
src/Artemis.UI.Shared/Utilities.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
using DryIoc;
|
||||||
|
|
||||||
|
namespace Artemis.UI.Shared;
|
||||||
|
|
||||||
|
internal static class UI
|
||||||
|
{
|
||||||
|
public static IContainer Locator { get; set; } = null!;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user