using System; using System.ComponentModel; using System.Reactive.Linq; using System.Reactive.Subjects; using Avalonia.Controls; using Avalonia.Input; using Avalonia.Input.Platform; using IContainer = DryIoc.IContainer; namespace Artemis.UI.Shared; /// /// Static UI helpers. /// public static class UI { private static readonly BehaviorSubject KeyBindingsEnabledSubject = new(false); static UI() { if (KeyboardDevice.Instance != null) KeyboardDevice.Instance.PropertyChanged += InstanceOnPropertyChanged; } /// /// Gets the current IoC locator. /// public static IContainer Locator { get; set; } = null!; /// /// Gets the clipboard. /// public static IClipboard Clipboard { get; set; } = null!; /// /// Gets a boolean indicating whether hotkeys are to be disabled. /// public static IObservable KeyBindingsEnabled { get; } = KeyBindingsEnabledSubject.AsObservable(); private static void InstanceOnPropertyChanged(object? sender, PropertyChangedEventArgs e) { if (KeyboardDevice.Instance == null || e.PropertyName != nameof(KeyboardDevice.FocusedElement)) return; bool enabled = KeyboardDevice.Instance.FocusedElement is not TextBox; if (KeyBindingsEnabledSubject.Value != enabled) KeyBindingsEnabledSubject.OnNext(enabled); } }