Improving Application.Navigation

This commit is contained in:
Tig
2024-08-29 13:53:16 -04:00
parent 3902e62b4a
commit f0508b9831
3 changed files with 14 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
using Xunit.Abstractions;
using System.Reflection.Emit;
using Xunit.Abstractions;
using Color = Terminal.Gui.Color;
namespace Terminal.Gui.ViewsTests;
@@ -692,6 +693,10 @@ public class ColorPickerTests
public void ColorPicker_TabCompleteColorName ()
{
var cp = GetColorPicker (ColorModel.RGB, true, true);
Application.Navigation = new ();
Application.Current = new ();
Application.Current.Add (cp);
cp.Draw ();
var r = GetColorBar (cp, ColorPickerPart.Bar1);
@@ -728,6 +733,7 @@ public class ColorPickerTests
Assert.Equal ("#7FFFD4", hex.Text);
Application.Current?.Dispose ();
Application.ResetState ();
}
[Fact]
@@ -735,6 +741,10 @@ public class ColorPickerTests
public void ColorPicker_EnterHexFor_ColorName ()
{
var cp = GetColorPicker (ColorModel.RGB, true, true);
Application.Navigation = new ();
Application.Current = new ();
Application.Current.Add (cp);
cp.Draw ();
var name = GetTextField (cp, ColorPickerPart.ColorName);
@@ -777,6 +787,7 @@ public class ColorPickerTests
Assert.Equal ("Aquamarine", name.Text);
Application.Current?.Dispose ();
Application.ResetState ();
}
[Fact]

View File

@@ -1321,6 +1321,7 @@ e
{
Label label = new () { Text = "label" };
View view = new () { Text = "view", CanFocus = true };
Application.Navigation = new ();
Application.Current = new ();
Application.Current.Add (label, view);

View File

@@ -98,7 +98,7 @@ Causes the focus to advance (forward or backwards) to the next View in the appli
The implementation is simple:
```cs
return Application.GetFocused()?.AdvanceFocus (direction, behavior) ?? false;
return Application.Current?.AdvanceFocus (direction, behavior);
```
This method is called from the `Command` handlers bound to the application-scoped keybindings created during `Application.Init`. It is `public` as a convenience.