Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accesskey always on for non windows #207

Merged
merged 5 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Consolonia.Core/Dummy/DummyConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
Size = new PixelBufferSize(width, height);
}

public PixelBufferSize Size { get; set; }

Check notice on line 27 in src/Consolonia.Core/Dummy/DummyConsole.cs

View workflow job for this annotation

GitHub Actions / build

"[AutoPropertyCanBeMadeGetOnly.Global] Auto-property can be made get-only" on /home/runner/work/Consolonia/Consolonia/src/Consolonia.Core/Dummy/DummyConsole.cs(27,44)

public bool CaretVisible
{
Expand All @@ -33,6 +33,7 @@
}

public bool SupportsComplexEmoji => true;
public bool SupportsAltSolo => false;

public void ClearOutput()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Consolonia.Core/Helpers/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ namespace Consolonia.Core.Helpers
{
public static class Extensions
{
public static void SubscribeAction<TValue>(
public static IDisposable SubscribeAction<TValue>(
this IObservable<AvaloniaPropertyChangedEventArgs<TValue>> observable,
Action<AvaloniaPropertyChangedEventArgs<TValue>> action)
{
observable.Subscribe(new AnonymousObserver<AvaloniaPropertyChangedEventArgs<TValue>>(action));
return observable.Subscribe(new AnonymousObserver<AvaloniaPropertyChangedEventArgs<TValue>>(action));
}

public static void AddConsoloniaDesignMode(this Application application)
Expand Down
19 changes: 19 additions & 0 deletions src/Consolonia.Core/Infrastructure/ConsoleWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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<IKeyboardDevice>();
Expand All @@ -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);
}
jinek marked this conversation as resolved.
Show resolved Hide resolved

private void OnShowAccessKeyPropertyChanged(AvaloniaPropertyChangedEventArgs<bool> args)
{
if (args.Sender != _inputRoot) return;
if (args.GetNewValue<bool>()) return;

_inputRoot.ShowAccessKeys = true;
}

public PixelBuffer PixelBuffer { get; set; }
Expand All @@ -49,6 +65,8 @@ public ConsoleWindow()
public void SetInputRoot(IInputRoot inputRoot)
{
_inputRoot = inputRoot;
if(_accessKeysAlwaysOn)
_inputRoot.ShowAccessKeys = true;
}

public Point PointToClient(PixelPoint point)
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/Consolonia.Core/Infrastructure/DefaultNetConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/Consolonia.Core/Infrastructure/IConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public interface IConsole : IDisposable
/// This is true if console supports composing multiple emojis together (like: 👨‍👩‍👧‍👦).
/// </summary>
bool SupportsComplexEmoji { get; }
bool SupportsAltSolo { get; }

void SetTitle(string title);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Consolonia.Core.Infrastructure
{
public class InputLessDefaultNetConsole : IConsole
public abstract class InputLessDefaultNetConsole : IConsole
{
private const string TestEmoji = "👨‍👩‍👧‍👦";
private bool _caretVisible;
Expand Down Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/Consolonia.NUnit/UnitTestConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Consolonia.PlatformSupport/CursesConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ private void StartEventLoop()
});
}

public override bool SupportsAltSolo => false;

public override void PauseIO(Task task)
{
base.PauseIO(task);
Expand Down
2 changes: 2 additions & 0 deletions src/Consolonia.PlatformSupport/WindowsConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public Win32Console()
StartEventLoop();
}

public override bool SupportsAltSolo => true;

public override void PauseIO(Task task)
{
base.PauseIO(task);
Expand Down
Loading