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 4 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,12 +16,15 @@
using Avalonia.Rendering.Composition;
using Avalonia.Threading;
using Consolonia.Core.Drawing.PixelBufferImplementation;
using Consolonia.Core.Helpers;
using Consolonia.Core.Text;

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;
Expand All @@ -39,6 +43,10 @@ public ConsoleWindow()
Console.FocusEvent += ConsoleOnFocusEvent;
Handle = null!;
PixelBuffer = new PixelBuffer(Console.Size);
_accessKeysAlwaysOn = !Console.SupportsAltSolo;
if (_accessKeysAlwaysOn)
_accessKeysAlwaysOnDisposable =
AccessText.ShowAccessKeyProperty.Changed.SubscribeAction(OnShowAccessKeyPropertyChanged);
}

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

public Point PointToClient(PixelPoint point)
Expand Down Expand Up @@ -296,6 +306,14 @@ public void Dispose()
GC.SuppressFinalize(this);
}

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

_inputRoot.ShowAccessKeys = true;
}
jinek marked this conversation as resolved.
Show resolved Hide resolved

private void ConsoleOnMouseEvent(RawPointerEventType type, Point point, Vector? wheelDelta,
RawInputModifiers modifiers)
{
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 @@ -47,6 +47,8 @@ public DefaultNetConsole()
StartInputReading();
}

public override bool SupportsAltSolo => false;

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
Expand Down
2 changes: 2 additions & 0 deletions src/Consolonia.Core/Infrastructure/IConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public interface IConsole : IDisposable
/// </summary>
bool SupportsComplexEmoji { get; }

bool SupportsAltSolo { get; }

void SetTitle(string title);

void SetCaretPosition(PixelBufferCoordinate bufferPoint);
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 @@ -115,6 +115,8 @@ public CursesConsole()
StartEventLoop();
}

public override bool SupportsAltSolo => false;

private void StartEventLoop()
{
//todo: cleanup
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