From 202b7640bb0aa9223d18b342249f664d551d7c7f Mon Sep 17 00:00:00 2001 From: Evgeny Gorbovoy Date: Sun, 15 Dec 2024 02:01:06 +0100 Subject: [PATCH 1/3] accesskey always on for non windows --- src/Consolonia.Core/Dummy/DummyConsole.cs | 1 + src/Consolonia.Core/Helpers/Extensions.cs | 4 ++-- .../Infrastructure/ConsoleWindow.cs | 19 +++++++++++++++++++ .../Infrastructure/DefaultNetConsole.cs | 2 ++ .../Infrastructure/IConsole.cs | 1 + .../InputLessDefaultNetConsole.cs | 3 ++- src/Consolonia.NUnit/UnitTestConsole.cs | 1 + .../CursesConsole.cs | 2 ++ .../WindowsConsole.cs | 2 ++ 9 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/Consolonia.Core/Dummy/DummyConsole.cs b/src/Consolonia.Core/Dummy/DummyConsole.cs index b5ad80d3..f3fc6efc 100644 --- a/src/Consolonia.Core/Dummy/DummyConsole.cs +++ b/src/Consolonia.Core/Dummy/DummyConsole.cs @@ -33,6 +33,7 @@ public bool CaretVisible } public bool SupportsComplexEmoji => true; + public bool SupportsAltSolo => false; public void ClearOutput() { diff --git a/src/Consolonia.Core/Helpers/Extensions.cs b/src/Consolonia.Core/Helpers/Extensions.cs index d1497233..87f68dec 100644 --- a/src/Consolonia.Core/Helpers/Extensions.cs +++ b/src/Consolonia.Core/Helpers/Extensions.cs @@ -16,11 +16,11 @@ namespace Consolonia.Core.Helpers { public static class Extensions { - public static void SubscribeAction( + public static IDisposable SubscribeAction( this IObservable> observable, Action> action) { - observable.Subscribe(new AnonymousObserver>(action)); + return observable.Subscribe(new AnonymousObserver>(action)); } public static void AddConsoloniaDesignMode(this Application application) diff --git a/src/Consolonia.Core/Infrastructure/ConsoleWindow.cs b/src/Consolonia.Core/Infrastructure/ConsoleWindow.cs index e7082f4c..b5ade2d0 100644 --- a/src/Consolonia.Core/Infrastructure/ConsoleWindow.cs +++ b/src/Consolonia.Core/Infrastructure/ConsoleWindow.cs @@ -7,6 +7,7 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Platform; +using Avalonia.Controls.Primitives; using Avalonia.Input; using Avalonia.Input.Platform; using Avalonia.Input.Raw; @@ -15,6 +16,7 @@ using Avalonia.Rendering.Composition; using Avalonia.Threading; using Consolonia.Core.Drawing.PixelBufferImplementation; +using Consolonia.Core.Helpers; using Consolonia.Core.Text; namespace Consolonia.Core.Infrastructure @@ -28,6 +30,9 @@ public class ConsoleWindow : IWindowImpl private IInputRoot _inputRoot; private CancellationTokenSource _resizeCancellationTokenSource; + private bool _accessKeysAlwaysOn; + private IDisposable _accessKeysAlwaysOnDisposable; + public ConsoleWindow() { _myKeyboardDevice = AvaloniaLocator.Current.GetService(); @@ -39,6 +44,17 @@ public ConsoleWindow() Console.FocusEvent += ConsoleOnFocusEvent; Handle = null!; PixelBuffer = new PixelBuffer(Console.Size); + _accessKeysAlwaysOn = !Console.SupportsAltSolo; + if(_accessKeysAlwaysOn) + _accessKeysAlwaysOnDisposable = AccessText.ShowAccessKeyProperty.Changed.SubscribeAction(OnShowAccessKeyPropertyChanged); + } + + private void OnShowAccessKeyPropertyChanged(AvaloniaPropertyChangedEventArgs args) + { + if (args.Sender != _inputRoot) return; + if (args.GetNewValue()) return; + + _inputRoot.ShowAccessKeys = true; } public PixelBuffer PixelBuffer { get; set; } @@ -49,6 +65,8 @@ public ConsoleWindow() public void SetInputRoot(IInputRoot inputRoot) { _inputRoot = inputRoot; + if(_accessKeysAlwaysOn) + _inputRoot.ShowAccessKeys = true; } public Point PointToClient(PixelPoint point) @@ -427,6 +445,7 @@ protected virtual void Dispose(bool disposing) { // TODO: dispose managed state (managed objects) Closed?.Invoke(); + _accessKeysAlwaysOnDisposable.Dispose(); Console.Resized -= OnConsoleOnResized; Console.KeyEvent -= ConsoleOnKeyEvent; Console.MouseEvent -= ConsoleOnMouseEvent; diff --git a/src/Consolonia.Core/Infrastructure/DefaultNetConsole.cs b/src/Consolonia.Core/Infrastructure/DefaultNetConsole.cs index 2354baa3..667e0068 100644 --- a/src/Consolonia.Core/Infrastructure/DefaultNetConsole.cs +++ b/src/Consolonia.Core/Infrastructure/DefaultNetConsole.cs @@ -53,6 +53,8 @@ protected override void Dispose(bool disposing) RaiseFocusEvent(false); } + public override bool SupportsAltSolo => false; + public override void PauseIO(Task task) { base.PauseIO(task); diff --git a/src/Consolonia.Core/Infrastructure/IConsole.cs b/src/Consolonia.Core/Infrastructure/IConsole.cs index fb49195a..fa67fb1f 100644 --- a/src/Consolonia.Core/Infrastructure/IConsole.cs +++ b/src/Consolonia.Core/Infrastructure/IConsole.cs @@ -20,6 +20,7 @@ public interface IConsole : IDisposable /// This is true if console supports composing multiple emojis together (like: ๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ). /// bool SupportsComplexEmoji { get; } + bool SupportsAltSolo { get; } void SetTitle(string title); diff --git a/src/Consolonia.Core/Infrastructure/InputLessDefaultNetConsole.cs b/src/Consolonia.Core/Infrastructure/InputLessDefaultNetConsole.cs index b2b42f91..fb59bfab 100644 --- a/src/Consolonia.Core/Infrastructure/InputLessDefaultNetConsole.cs +++ b/src/Consolonia.Core/Infrastructure/InputLessDefaultNetConsole.cs @@ -11,7 +11,7 @@ namespace Consolonia.Core.Infrastructure { - public class InputLessDefaultNetConsole : IConsole + public abstract class InputLessDefaultNetConsole : IConsole { private const string TestEmoji = "๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ"; private bool _caretVisible; @@ -48,6 +48,7 @@ public bool CaretVisible public PixelBufferSize Size { get; private set; } public bool SupportsComplexEmoji => _supportEmoji ?? false; + public abstract bool SupportsAltSolo { get; } public void SetTitle(string title) { diff --git a/src/Consolonia.NUnit/UnitTestConsole.cs b/src/Consolonia.NUnit/UnitTestConsole.cs index c42cd357..66017930 100644 --- a/src/Consolonia.NUnit/UnitTestConsole.cs +++ b/src/Consolonia.NUnit/UnitTestConsole.cs @@ -39,6 +39,7 @@ public void Dispose() bool IConsole.CaretVisible { get; set; } public bool SupportsComplexEmoji => true; + public bool SupportsAltSolo => true; public void SetTitle(string title) { diff --git a/src/Consolonia.PlatformSupport/CursesConsole.cs b/src/Consolonia.PlatformSupport/CursesConsole.cs index a11c25e2..80a0204a 100644 --- a/src/Consolonia.PlatformSupport/CursesConsole.cs +++ b/src/Consolonia.PlatformSupport/CursesConsole.cs @@ -140,6 +140,8 @@ private void StartEventLoop() }); } + public override bool SupportsAltSolo => false; + public override void PauseIO(Task task) { base.PauseIO(task); diff --git a/src/Consolonia.PlatformSupport/WindowsConsole.cs b/src/Consolonia.PlatformSupport/WindowsConsole.cs index ee5bcbcc..596e37db 100644 --- a/src/Consolonia.PlatformSupport/WindowsConsole.cs +++ b/src/Consolonia.PlatformSupport/WindowsConsole.cs @@ -61,6 +61,8 @@ public Win32Console() StartEventLoop(); } + public override bool SupportsAltSolo => true; + public override void PauseIO(Task task) { base.PauseIO(task); From d2db20049dacfe824e5596259db477f701b94b23 Mon Sep 17 00:00:00 2001 From: Evgeny Gorbovoy Date: Sun, 15 Dec 2024 02:04:58 +0100 Subject: [PATCH 2/3] + pr fix --- src/Consolonia.Core/Infrastructure/ConsoleWindow.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Consolonia.Core/Infrastructure/ConsoleWindow.cs b/src/Consolonia.Core/Infrastructure/ConsoleWindow.cs index b5ade2d0..627e0471 100644 --- a/src/Consolonia.Core/Infrastructure/ConsoleWindow.cs +++ b/src/Consolonia.Core/Infrastructure/ConsoleWindow.cs @@ -445,7 +445,7 @@ protected virtual void Dispose(bool disposing) { // TODO: dispose managed state (managed objects) Closed?.Invoke(); - _accessKeysAlwaysOnDisposable.Dispose(); + _accessKeysAlwaysOnDisposable?.Dispose(); Console.Resized -= OnConsoleOnResized; Console.KeyEvent -= ConsoleOnKeyEvent; Console.MouseEvent -= ConsoleOnMouseEvent; From 51b89aac0f694d8368fbe9a2e1ed47022a892e0c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 15 Dec 2024 01:10:20 +0000 Subject: [PATCH 3/3] Automated JetBrains cleanup Co-authored-by: <+@users.noreply.github.com> --- .../Infrastructure/ConsoleWindow.cs | 28 +++++++++---------- .../Infrastructure/DefaultNetConsole.cs | 4 +-- .../Infrastructure/IConsole.cs | 1 + .../CursesConsole.cs | 4 +-- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/Consolonia.Core/Infrastructure/ConsoleWindow.cs b/src/Consolonia.Core/Infrastructure/ConsoleWindow.cs index 627e0471..c8363f00 100644 --- a/src/Consolonia.Core/Infrastructure/ConsoleWindow.cs +++ b/src/Consolonia.Core/Infrastructure/ConsoleWindow.cs @@ -23,6 +23,8 @@ namespace Consolonia.Core.Infrastructure { public class ConsoleWindow : IWindowImpl { + private readonly bool _accessKeysAlwaysOn; + private readonly IDisposable _accessKeysAlwaysOnDisposable; private readonly IKeyboardDevice _myKeyboardDevice; private readonly TimeSpan _resizeDelay = TimeSpan.FromMilliseconds(100); [NotNull] internal readonly IConsole Console; @@ -30,9 +32,6 @@ public class ConsoleWindow : IWindowImpl private IInputRoot _inputRoot; private CancellationTokenSource _resizeCancellationTokenSource; - private bool _accessKeysAlwaysOn; - private IDisposable _accessKeysAlwaysOnDisposable; - public ConsoleWindow() { _myKeyboardDevice = AvaloniaLocator.Current.GetService(); @@ -45,16 +44,9 @@ public ConsoleWindow() Handle = null!; PixelBuffer = new PixelBuffer(Console.Size); _accessKeysAlwaysOn = !Console.SupportsAltSolo; - if(_accessKeysAlwaysOn) - _accessKeysAlwaysOnDisposable = AccessText.ShowAccessKeyProperty.Changed.SubscribeAction(OnShowAccessKeyPropertyChanged); - } - - private void OnShowAccessKeyPropertyChanged(AvaloniaPropertyChangedEventArgs args) - { - if (args.Sender != _inputRoot) return; - if (args.GetNewValue()) return; - - _inputRoot.ShowAccessKeys = true; + if (_accessKeysAlwaysOn) + _accessKeysAlwaysOnDisposable = + AccessText.ShowAccessKeyProperty.Changed.SubscribeAction(OnShowAccessKeyPropertyChanged); } public PixelBuffer PixelBuffer { get; set; } @@ -65,7 +57,7 @@ private void OnShowAccessKeyPropertyChanged(AvaloniaPropertyChangedEventArgs args) + { + if (args.Sender != _inputRoot) return; + if (args.GetNewValue()) return; + + _inputRoot.ShowAccessKeys = true; + } + private void ConsoleOnMouseEvent(RawPointerEventType type, Point point, Vector? wheelDelta, RawInputModifiers modifiers) { diff --git a/src/Consolonia.Core/Infrastructure/DefaultNetConsole.cs b/src/Consolonia.Core/Infrastructure/DefaultNetConsole.cs index 667e0068..3437cd57 100644 --- a/src/Consolonia.Core/Infrastructure/DefaultNetConsole.cs +++ b/src/Consolonia.Core/Infrastructure/DefaultNetConsole.cs @@ -47,14 +47,14 @@ public DefaultNetConsole() StartInputReading(); } + public override bool SupportsAltSolo => false; + protected override void Dispose(bool disposing) { base.Dispose(disposing); RaiseFocusEvent(false); } - public override bool SupportsAltSolo => false; - public override void PauseIO(Task task) { base.PauseIO(task); diff --git a/src/Consolonia.Core/Infrastructure/IConsole.cs b/src/Consolonia.Core/Infrastructure/IConsole.cs index fa67fb1f..d4975340 100644 --- a/src/Consolonia.Core/Infrastructure/IConsole.cs +++ b/src/Consolonia.Core/Infrastructure/IConsole.cs @@ -20,6 +20,7 @@ public interface IConsole : IDisposable /// This is true if console supports composing multiple emojis together (like: ๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ). /// bool SupportsComplexEmoji { get; } + bool SupportsAltSolo { get; } void SetTitle(string title); diff --git a/src/Consolonia.PlatformSupport/CursesConsole.cs b/src/Consolonia.PlatformSupport/CursesConsole.cs index 80a0204a..74aee766 100644 --- a/src/Consolonia.PlatformSupport/CursesConsole.cs +++ b/src/Consolonia.PlatformSupport/CursesConsole.cs @@ -115,6 +115,8 @@ public CursesConsole() StartEventLoop(); } + public override bool SupportsAltSolo => false; + private void StartEventLoop() { //todo: cleanup @@ -140,8 +142,6 @@ private void StartEventLoop() }); } - public override bool SupportsAltSolo => false; - public override void PauseIO(Task task) { base.PauseIO(task);