mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-30 01:38:01 +01:00
Revoved defunct api
This commit is contained in:
@@ -83,28 +83,4 @@ public class ApplicationNavigation
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the deepest focused subview of the specified <paramref name="view"/>.
|
||||
/// </summary>
|
||||
/// <param name="view"></param>
|
||||
/// <returns></returns>
|
||||
internal static View? GetDeepestFocusedSubview (View? view)
|
||||
{
|
||||
if (view is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (View v in view.Subviews)
|
||||
{
|
||||
if (v.HasFocus)
|
||||
{
|
||||
return GetDeepestFocusedSubview (v);
|
||||
}
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,12 +57,7 @@ public partial class View // Focus and cross-view navigation management (TabStop
|
||||
// We're moving beyond the last subview
|
||||
|
||||
// Determine if focus should remain in this focus chain, or move to the superview's focus chain
|
||||
//// - If we are TabStop and our SuperView is TabStop move to superview's focus chain
|
||||
//if (TabStop == TabBehavior.TabStop && SuperView is { TabStop: TabBehavior.TabStop })
|
||||
//{
|
||||
// return false;
|
||||
//}
|
||||
|
||||
// BUGBUG: The logic below is sketchy and barely works. In fact, it doesn't work propertly for all nested TabGroups.
|
||||
// - If we are TabStop and our SuperView has at least one other TabStop subview, move to the SuperView's chain
|
||||
if (TabStop == TabBehavior.TabStop && SuperView is { } && SuperView.GetSubviewFocusChain (direction, behavior).Length > 1)
|
||||
{
|
||||
@@ -691,7 +686,7 @@ public partial class View // Focus and cross-view navigation management (TabStop
|
||||
get => _tabStop;
|
||||
set
|
||||
{
|
||||
if (_tabStop == value)
|
||||
if (_tabStop is { } && _tabStop == value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ internal class NumericUpDownEditor<T> : View where T : notnull
|
||||
_numericUpDown.Value = (T)Convert.ChangeType (_value.Text, typeof (T));
|
||||
}
|
||||
|
||||
_value.ColorScheme = SuperView.ColorScheme;
|
||||
_value.ColorScheme = SuperView!.ColorScheme;
|
||||
|
||||
}
|
||||
catch (System.FormatException)
|
||||
@@ -184,7 +184,7 @@ internal class NumericUpDownEditor<T> : View where T : notnull
|
||||
_ = string.Format (_format.Text, _value);
|
||||
_numericUpDown.Format = _format.Text;
|
||||
|
||||
_format.ColorScheme = SuperView.ColorScheme;
|
||||
_format.ColorScheme = SuperView!.ColorScheme;
|
||||
|
||||
}
|
||||
catch (System.FormatException)
|
||||
@@ -239,7 +239,7 @@ internal class NumericUpDownEditor<T> : View where T : notnull
|
||||
_numericUpDown.Increment = (T)Convert.ChangeType (_increment.Text, typeof (T));
|
||||
}
|
||||
|
||||
_increment.ColorScheme = SuperView.ColorScheme;
|
||||
_increment.ColorScheme = SuperView!.ColorScheme;
|
||||
|
||||
}
|
||||
catch (System.FormatException)
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using Moq;
|
||||
using Xunit.Abstractions;
|
||||
using Terminal.Gui;
|
||||
using Terminal.Gui.ViewTests;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Terminal.Gui.ApplicationTests.NavigationTests;
|
||||
|
||||
@@ -10,214 +6,15 @@ public class ApplicationNavigationTests (ITestOutputHelper output)
|
||||
{
|
||||
private readonly ITestOutputHelper _output = output;
|
||||
|
||||
[Fact]
|
||||
public void Focused_Change_Raises_FocusedChanged ()
|
||||
{
|
||||
bool raised = false;
|
||||
|
||||
Application.Navigation = new ApplicationNavigation ();
|
||||
|
||||
Application.Navigation.FocusedChanged += ApplicationNavigationOnFocusedChanged;
|
||||
|
||||
Application.Navigation.SetFocused (new View ());
|
||||
|
||||
Assert.True (raised);
|
||||
|
||||
Application.Navigation.GetFocused ().Dispose ();
|
||||
Application.Navigation.SetFocused (null);
|
||||
|
||||
Application.Navigation.FocusedChanged -= ApplicationNavigationOnFocusedChanged;
|
||||
|
||||
Application.Navigation = null;
|
||||
|
||||
return;
|
||||
|
||||
void ApplicationNavigationOnFocusedChanged (object sender, EventArgs e) { raised = true; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDeepestFocusedSubview_ShouldReturnNull_WhenViewIsNull ()
|
||||
{
|
||||
// Act
|
||||
var result = ApplicationNavigation.GetDeepestFocusedSubview (null);
|
||||
|
||||
// Assert
|
||||
Assert.Null (result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDeepestFocusedSubview_ShouldReturnSameView_WhenNoSubviewsHaveFocus ()
|
||||
{
|
||||
// Arrange
|
||||
var view = new View () { Id = "view", CanFocus = true };
|
||||
;
|
||||
|
||||
// Act
|
||||
var result = ApplicationNavigation.GetDeepestFocusedSubview (view);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (view, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDeepestFocusedSubview_ShouldReturnFocusedSubview ()
|
||||
{
|
||||
// Arrange
|
||||
var parentView = new View () { Id = "parentView", CanFocus = true };
|
||||
;
|
||||
var childView1 = new View () { Id = "childView1", CanFocus = true };
|
||||
;
|
||||
var childView2 = new View () { Id = "childView2", CanFocus = true };
|
||||
;
|
||||
var grandChildView = new View () { Id = "grandChildView", CanFocus = true };
|
||||
;
|
||||
|
||||
parentView.Add (childView1, childView2);
|
||||
childView2.Add (grandChildView);
|
||||
|
||||
grandChildView.SetFocus ();
|
||||
|
||||
// Act
|
||||
var result = ApplicationNavigation.GetDeepestFocusedSubview (parentView);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (grandChildView, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDeepestFocusedSubview_ShouldReturnDeepestFocusedSubview ()
|
||||
{
|
||||
// Arrange
|
||||
var parentView = new View () { Id = "parentView", CanFocus = true };
|
||||
;
|
||||
var childView1 = new View () { Id = "childView1", CanFocus = true };
|
||||
;
|
||||
var childView2 = new View () { Id = "childView2", CanFocus = true };
|
||||
;
|
||||
var grandChildView = new View () { Id = "grandChildView", CanFocus = true };
|
||||
;
|
||||
var greatGrandChildView = new View () { Id = "greatGrandChildView", CanFocus = true };
|
||||
;
|
||||
|
||||
parentView.Add (childView1, childView2);
|
||||
childView2.Add (grandChildView);
|
||||
grandChildView.Add (greatGrandChildView);
|
||||
|
||||
grandChildView.SetFocus ();
|
||||
|
||||
// Act
|
||||
var result = ApplicationNavigation.GetDeepestFocusedSubview (parentView);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (greatGrandChildView, result);
|
||||
|
||||
// Arrange
|
||||
greatGrandChildView.CanFocus = false;
|
||||
grandChildView.SetFocus ();
|
||||
|
||||
// Act
|
||||
result = ApplicationNavigation.GetDeepestFocusedSubview (parentView);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (grandChildView, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetFocused_Returns_Null_If_No_Focused_View ()
|
||||
{
|
||||
Application.Navigation = new ();
|
||||
|
||||
Application.Current = new Toplevel()
|
||||
{
|
||||
Id = "top",
|
||||
CanFocus = true
|
||||
};
|
||||
|
||||
View subView1 = new View ()
|
||||
{
|
||||
Id = "subView1",
|
||||
CanFocus = true
|
||||
};
|
||||
|
||||
Application.Current.Add (subView1);
|
||||
Assert.False (Application.Current.HasFocus);
|
||||
|
||||
Application.Current.SetFocus ();
|
||||
Assert.True (subView1.HasFocus);
|
||||
Assert.Equal (subView1, Application.Navigation.GetFocused ());
|
||||
|
||||
subView1.HasFocus = false;
|
||||
Assert.False (subView1.HasFocus);
|
||||
Assert.True (Application.Current.HasFocus);
|
||||
Assert.Equal (Application.Current, Application.Navigation.GetFocused ());
|
||||
|
||||
Application.Current.HasFocus = false;
|
||||
Assert.False (Application.Current.HasFocus);
|
||||
Assert.Null (Application.Navigation.GetFocused ());
|
||||
|
||||
Application.ResetState ();
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void GetFocused_Returns_Focused_View ()
|
||||
{
|
||||
Application.Navigation = new ();
|
||||
|
||||
Application.Current = new Toplevel ()
|
||||
{
|
||||
Id = "top",
|
||||
CanFocus = true
|
||||
};
|
||||
|
||||
View subView1 = new View ()
|
||||
{
|
||||
Id = "subView1",
|
||||
CanFocus = true
|
||||
};
|
||||
|
||||
View subView2 = new View ()
|
||||
{
|
||||
Id = "subView2",
|
||||
CanFocus = true
|
||||
};
|
||||
Application.Current.Add (subView1, subView2);
|
||||
Assert.False (Application.Current.HasFocus);
|
||||
|
||||
Application.Current.SetFocus ();
|
||||
Assert.True (subView1.HasFocus);
|
||||
Assert.Equal(subView1, Application.Navigation.GetFocused());
|
||||
|
||||
Application.Current.AdvanceFocus (NavigationDirection.Forward, null);
|
||||
Assert.Equal (subView2, Application.Navigation.GetFocused ());
|
||||
|
||||
Application.ResetState ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Begin_SetsFocus_On_Top ()
|
||||
{
|
||||
Application.Init(new FakeDriver());
|
||||
|
||||
var top = new Toplevel ();
|
||||
Assert.False (top.HasFocus);
|
||||
|
||||
RunState rs = Application.Begin (top);
|
||||
Assert.True (top.HasFocus);
|
||||
|
||||
top.Dispose ();
|
||||
Application.Shutdown();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(TabBehavior.NoStop)]
|
||||
[InlineData (TabBehavior.NoStop)]
|
||||
[InlineData (TabBehavior.TabStop)]
|
||||
[InlineData (TabBehavior.TabGroup)]
|
||||
public void Begin_SetsFocus_On_Deepest_Focusable_View (TabBehavior behavior)
|
||||
{
|
||||
Application.Init (new FakeDriver ());
|
||||
|
||||
var top = new Toplevel ()
|
||||
var top = new Toplevel
|
||||
{
|
||||
TabStop = behavior
|
||||
};
|
||||
@@ -246,4 +43,115 @@ public class ApplicationNavigationTests (ITestOutputHelper output)
|
||||
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Begin_SetsFocus_On_Top ()
|
||||
{
|
||||
Application.Init (new FakeDriver ());
|
||||
|
||||
var top = new Toplevel ();
|
||||
Assert.False (top.HasFocus);
|
||||
|
||||
RunState rs = Application.Begin (top);
|
||||
Assert.True (top.HasFocus);
|
||||
|
||||
top.Dispose ();
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Focused_Change_Raises_FocusedChanged ()
|
||||
{
|
||||
var raised = false;
|
||||
|
||||
Application.Navigation = new ();
|
||||
|
||||
Application.Navigation.FocusedChanged += ApplicationNavigationOnFocusedChanged;
|
||||
|
||||
Application.Navigation.SetFocused (new ());
|
||||
|
||||
Assert.True (raised);
|
||||
|
||||
Application.Navigation.GetFocused ().Dispose ();
|
||||
Application.Navigation.SetFocused (null);
|
||||
|
||||
Application.Navigation.FocusedChanged -= ApplicationNavigationOnFocusedChanged;
|
||||
|
||||
Application.Navigation = null;
|
||||
|
||||
return;
|
||||
|
||||
void ApplicationNavigationOnFocusedChanged (object sender, EventArgs e) { raised = true; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetFocused_Returns_Focused_View ()
|
||||
{
|
||||
Application.Navigation = new ();
|
||||
|
||||
Application.Current = new()
|
||||
{
|
||||
Id = "top",
|
||||
CanFocus = true
|
||||
};
|
||||
|
||||
var subView1 = new View
|
||||
{
|
||||
Id = "subView1",
|
||||
CanFocus = true
|
||||
};
|
||||
|
||||
var subView2 = new View
|
||||
{
|
||||
Id = "subView2",
|
||||
CanFocus = true
|
||||
};
|
||||
Application.Current.Add (subView1, subView2);
|
||||
Assert.False (Application.Current.HasFocus);
|
||||
|
||||
Application.Current.SetFocus ();
|
||||
Assert.True (subView1.HasFocus);
|
||||
Assert.Equal (subView1, Application.Navigation.GetFocused ());
|
||||
|
||||
Application.Current.AdvanceFocus (NavigationDirection.Forward, null);
|
||||
Assert.Equal (subView2, Application.Navigation.GetFocused ());
|
||||
|
||||
Application.ResetState ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetFocused_Returns_Null_If_No_Focused_View ()
|
||||
{
|
||||
Application.Navigation = new ();
|
||||
|
||||
Application.Current = new()
|
||||
{
|
||||
Id = "top",
|
||||
CanFocus = true
|
||||
};
|
||||
|
||||
var subView1 = new View
|
||||
{
|
||||
Id = "subView1",
|
||||
CanFocus = true
|
||||
};
|
||||
|
||||
Application.Current.Add (subView1);
|
||||
Assert.False (Application.Current.HasFocus);
|
||||
|
||||
Application.Current.SetFocus ();
|
||||
Assert.True (subView1.HasFocus);
|
||||
Assert.Equal (subView1, Application.Navigation.GetFocused ());
|
||||
|
||||
subView1.HasFocus = false;
|
||||
Assert.False (subView1.HasFocus);
|
||||
Assert.True (Application.Current.HasFocus);
|
||||
Assert.Equal (Application.Current, Application.Navigation.GetFocused ());
|
||||
|
||||
Application.Current.HasFocus = false;
|
||||
Assert.False (Application.Current.HasFocus);
|
||||
Assert.Null (Application.Navigation.GetFocused ());
|
||||
|
||||
Application.ResetState ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1232,7 +1232,7 @@ public class OverlappedTests
|
||||
Assert.Equal (superView.MostFocused, current);
|
||||
|
||||
// Act
|
||||
ApplicationOverlapped.SetFocusToNextViewWithWrap (Application.Current.SuperView.Subviews, NavigationDirection.Forward);
|
||||
ApplicationOverlapped.SetFocusToNextViewWithWrap (Application.Current!.SuperView!.Subviews, NavigationDirection.Forward);
|
||||
|
||||
// Assert
|
||||
Assert.True (view1.HasFocus);
|
||||
|
||||
Reference in New Issue
Block a user