Rename IApplication.Current to TopRunnable

Co-authored-by: tig <585482+tig@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-11-20 19:34:48 +00:00
parent 16b42e86fd
commit 4b975fd5b7
90 changed files with 916 additions and 820 deletions

View File

@@ -14,14 +14,14 @@ public class AdornmentSubViewTests (ITestOutputHelper output)
[InlineData (2, 1, true)]
public void Adornment_WithSubView_Finds (int viewMargin, int subViewMargin, bool expectedFound)
{
Application.Current = new Toplevel()
Application.TopRunnable = new Toplevel()
{
Width = 10,
Height = 10
};
Application.Current.Margin!.Thickness = new Thickness (viewMargin);
Application.TopRunnable.Margin!.Thickness = new Thickness (viewMargin);
// Turn of TransparentMouse for the test
Application.Current.Margin!.ViewportSettings = ViewportSettingsFlags.None;
Application.TopRunnable.Margin!.ViewportSettings = ViewportSettingsFlags.None;
var subView = new View ()
{
@@ -34,26 +34,26 @@ public class AdornmentSubViewTests (ITestOutputHelper output)
// Turn of TransparentMouse for the test
subView.Margin!.ViewportSettings = ViewportSettingsFlags.None;
Application.Current.Margin!.Add (subView);
Application.Current.Layout ();
Application.TopRunnable.Margin!.Add (subView);
Application.TopRunnable.Layout ();
var foundView = Application.Current.GetViewsUnderLocation (new Point(0, 0), ViewportSettingsFlags.None).LastOrDefault ();
var foundView = Application.TopRunnable.GetViewsUnderLocation (new Point(0, 0), ViewportSettingsFlags.None).LastOrDefault ();
bool found = foundView == subView || foundView == subView.Margin;
Assert.Equal (expectedFound, found);
Application.Current.Dispose ();
Application.TopRunnable.Dispose ();
Application.ResetState (ignoreDisposed: true);
}
[Fact]
public void Adornment_WithNonVisibleSubView_Finds_Adornment ()
{
Application.Current = new Toplevel ()
Application.TopRunnable = new Toplevel ()
{
Width = 10,
Height = 10
};
Application.Current.Padding.Thickness = new Thickness (1);
Application.TopRunnable.Padding.Thickness = new Thickness (1);
var subView = new View ()
{
@@ -63,11 +63,11 @@ public class AdornmentSubViewTests (ITestOutputHelper output)
Height = 1,
Visible = false
};
Application.Current.Padding.Add (subView);
Application.Current.Layout ();
Application.TopRunnable.Padding.Add (subView);
Application.TopRunnable.Layout ();
Assert.Equal (Application.Current.Padding, Application.Current.GetViewsUnderLocation (new Point(0, 0), ViewportSettingsFlags.None).LastOrDefault ());
Application.Current?.Dispose ();
Assert.Equal (Application.TopRunnable.Padding, Application.TopRunnable.GetViewsUnderLocation (new Point(0, 0), ViewportSettingsFlags.None).LastOrDefault ());
Application.TopRunnable?.Dispose ();
Application.ResetState (ignoreDisposed: true);
}
}

View File

@@ -15,27 +15,27 @@ public class MarginTests (ITestOutputHelper output)
view.Margin!.Diagnostics = ViewDiagnosticFlags.Thickness;
view.Margin.Thickness = new (1);
Application.Current = new Toplevel ();
Application.SessionStack.Push (Application.Current);
Application.TopRunnable = new Toplevel ();
Application.SessionStack.Push (Application.TopRunnable);
Application.Current.SetScheme (new()
Application.TopRunnable.SetScheme (new()
{
Normal = new (Color.Red, Color.Green), Focus = new (Color.Green, Color.Red)
});
Application.Current.Add (view);
Application.TopRunnable.Add (view);
Assert.Equal (ColorName16.Red, view.Margin.GetAttributeForRole (VisualRole.Normal).Foreground.GetClosestNamedColor16 ());
Assert.Equal (ColorName16.Red, Application.Current.GetAttributeForRole (VisualRole.Normal).Foreground.GetClosestNamedColor16 ());
Assert.Equal (ColorName16.Red, Application.TopRunnable.GetAttributeForRole (VisualRole.Normal).Foreground.GetClosestNamedColor16 ());
Application.Current.BeginInit ();
Application.Current.EndInit ();
Application.TopRunnable.BeginInit ();
Application.TopRunnable.EndInit ();
Application.LayoutAndDraw();
DriverAssert.AssertDriverContentsAre (
@"",
output
);
DriverAssert.AssertDriverAttributesAre ("0", output, null, Application.Current.GetAttributeForRole (VisualRole.Normal));
DriverAssert.AssertDriverAttributesAre ("0", output, null, Application.TopRunnable.GetAttributeForRole (VisualRole.Normal));
Application.ResetState (true);
}
@@ -51,20 +51,20 @@ public class MarginTests (ITestOutputHelper output)
view.Margin.Thickness = new (1);
view.Margin.ViewportSettings = ViewportSettingsFlags.None;
Application.Current = new Toplevel ();
Application.SessionStack.Push (Application.Current);
Application.TopRunnable = new Toplevel ();
Application.SessionStack.Push (Application.TopRunnable);
Application.Current.SetScheme (new ()
Application.TopRunnable.SetScheme (new ()
{
Normal = new (Color.Red, Color.Green), Focus = new (Color.Green, Color.Red)
});
Application.Current.Add (view);
Application.TopRunnable.Add (view);
Assert.Equal (ColorName16.Red, view.Margin.GetAttributeForRole (VisualRole.Normal).Foreground.GetClosestNamedColor16 ());
Assert.Equal (ColorName16.Red, Application.Current.GetAttributeForRole (VisualRole.Normal).Foreground.GetClosestNamedColor16 ());
Assert.Equal (ColorName16.Red, Application.TopRunnable.GetAttributeForRole (VisualRole.Normal).Foreground.GetClosestNamedColor16 ());
Application.Current.BeginInit ();
Application.Current.EndInit ();
Application.TopRunnable.BeginInit ();
Application.TopRunnable.EndInit ();
Application.LayoutAndDraw ();
DriverAssert.AssertDriverContentsAre (
@@ -74,7 +74,7 @@ M M
MMM",
output
);
DriverAssert.AssertDriverAttributesAre ("0", output, null, Application.Current.GetAttributeForRole (VisualRole.Normal));
DriverAssert.AssertDriverAttributesAre ("0", output, null, Application.TopRunnable.GetAttributeForRole (VisualRole.Normal));
Application.ResetState (true);
}

View File

@@ -160,14 +160,14 @@ public class KeyBindingsTests ()
var hotKeyRaised = false;
var acceptRaised = false;
var selectRaised = false;
Application.Current = new Toplevel ();
Application.TopRunnable = new Toplevel ();
var view = new View
{
CanFocus = true,
HotKeySpecifier = new Rune ('_'),
Title = "_Test"
};
Application.Current.Add (view);
Application.TopRunnable.Add (view);
view.HandlingHotKey += (s, e) => hotKeyRaised = true;
view.Accepting += (s, e) => acceptRaised = true;
view.Selecting += (s, e) => selectRaised = true;
@@ -191,7 +191,7 @@ public class KeyBindingsTests ()
Assert.False (acceptRaised);
Assert.False (selectRaised);
Application.Current.Dispose ();
Application.TopRunnable.Dispose ();
Application.ResetState (true);
}
// tests that test KeyBindingScope.Focus and KeyBindingScope.HotKey (tests for KeyBindingScope.Application are in Application/KeyboardTests.cs)

View File

@@ -70,22 +70,22 @@ public class GetViewsUnderLocationTests
)
{
// Arrange
Application.Current = new ()
Application.TopRunnable = new ()
{
Id = "Top",
Frame = new (frameX, frameY, 10, 10)
};
Application.Current.Margin!.Thickness = new (marginThickness);
Application.Current.Margin!.Id = "Margin";
Application.Current.Border!.Thickness = new (borderThickness);
Application.Current.Border!.Id = "Border";
Application.Current.Padding!.Thickness = new (paddingThickness);
Application.Current.Padding.Id = "Padding";
Application.TopRunnable.Margin!.Thickness = new (marginThickness);
Application.TopRunnable.Margin!.Id = "Margin";
Application.TopRunnable.Border!.Thickness = new (borderThickness);
Application.TopRunnable.Border!.Id = "Border";
Application.TopRunnable.Padding!.Thickness = new (paddingThickness);
Application.TopRunnable.Padding.Id = "Padding";
var location = new Point (testX, testY);
// Act
List<View?> viewsUnderMouse = Application.Current.GetViewsUnderLocation (location, ViewportSettingsFlags.TransparentMouse);
List<View?> viewsUnderMouse = Application.TopRunnable.GetViewsUnderLocation (location, ViewportSettingsFlags.TransparentMouse);
// Assert
if (expectedViewsFound.Length == 0)
@@ -98,7 +98,7 @@ public class GetViewsUnderLocationTests
Assert.Equal (expectedViewsFound, foundIds);
}
Application.Current.Dispose ();
Application.TopRunnable.Dispose ();
Application.ResetState (true);
}
@@ -109,7 +109,7 @@ public class GetViewsUnderLocationTests
public void Returns_Top_If_No_SubViews (int testX, int testY)
{
// Arrange
Application.Current = new ()
Application.TopRunnable = new ()
{
Frame = new (0, 0, 10, 10)
};
@@ -117,11 +117,11 @@ public class GetViewsUnderLocationTests
var location = new Point (testX, testY);
// Act
List<View?> viewsUnderMouse = Application.Current.GetViewsUnderLocation (location, ViewportSettingsFlags.TransparentMouse);
List<View?> viewsUnderMouse = Application.TopRunnable.GetViewsUnderLocation (location, ViewportSettingsFlags.TransparentMouse);
// Assert
Assert.Contains (viewsUnderMouse, v => v == Application.Current);
Application.Current.Dispose ();
Assert.Contains (viewsUnderMouse, v => v == Application.TopRunnable);
Application.TopRunnable.Dispose ();
Application.ResetState (true);
}
@@ -134,13 +134,13 @@ public class GetViewsUnderLocationTests
{
Application.ResetState (true);
Application.Current = new ()
Application.TopRunnable = new ()
{
Width = 10, Height = 10
};
Assert.Same (Application.Current, Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ());
Application.Current.Dispose ();
Assert.Same (Application.TopRunnable, Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ());
Application.TopRunnable.Dispose ();
Application.ResetState (true);
}
@@ -155,7 +155,7 @@ public class GetViewsUnderLocationTests
[InlineData (5, 6, true)]
public void Returns_Correct_If_SubViews (int testX, int testY, bool expectedSubViewFound)
{
Application.Current = new ()
Application.TopRunnable = new ()
{
Width = 10, Height = 10
};
@@ -165,12 +165,12 @@ public class GetViewsUnderLocationTests
X = 1, Y = 2,
Width = 5, Height = 5
};
Application.Current.Add (subview);
Application.TopRunnable.Add (subview);
View? found = Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
Assert.Equal (expectedSubViewFound, found == subview);
Application.Current.Dispose ();
Application.TopRunnable.Dispose ();
Application.ResetState (true);
}
@@ -184,7 +184,7 @@ public class GetViewsUnderLocationTests
[InlineData (5, 6, false)]
public void Returns_Null_If_SubView_NotVisible (int testX, int testY, bool expectedSubViewFound)
{
Application.Current = new ()
Application.TopRunnable = new ()
{
Width = 10, Height = 10
};
@@ -195,12 +195,12 @@ public class GetViewsUnderLocationTests
Width = 5, Height = 5,
Visible = false
};
Application.Current.Add (subview);
Application.TopRunnable.Add (subview);
View? found = Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
Assert.Equal (expectedSubViewFound, found == subview);
Application.Current.Dispose ();
Application.TopRunnable.Dispose ();
Application.ResetState (true);
}
@@ -214,7 +214,7 @@ public class GetViewsUnderLocationTests
[InlineData (5, 6, false)]
public void Returns_Null_If_Not_Visible_And_SubView_Visible (int testX, int testY, bool expectedSubViewFound)
{
Application.Current = new ()
Application.TopRunnable = new ()
{
Width = 10, Height = 10,
Visible = false
@@ -225,14 +225,14 @@ public class GetViewsUnderLocationTests
X = 1, Y = 2,
Width = 5, Height = 5
};
Application.Current.Add (subview);
Application.TopRunnable.Add (subview);
subview.Visible = true;
Assert.True (subview.Visible);
Assert.False (Application.Current.Visible);
View? found = Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
Assert.False (Application.TopRunnable.Visible);
View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
Assert.Equal (expectedSubViewFound, found == subview);
Application.Current.Dispose ();
Application.TopRunnable.Dispose ();
Application.ResetState (true);
}
@@ -249,23 +249,23 @@ public class GetViewsUnderLocationTests
[InlineData (6, 7, true)]
public void Returns_Correct_If_Start_Has_Adornments (int testX, int testY, bool expectedSubViewFound)
{
Application.Current = new ()
Application.TopRunnable = new ()
{
Width = 10, Height = 10
};
Application.Current.Margin!.Thickness = new (1);
Application.TopRunnable.Margin!.Thickness = new (1);
var subview = new View
{
X = 1, Y = 2,
Width = 5, Height = 5
};
Application.Current.Add (subview);
Application.TopRunnable.Add (subview);
View? found = Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
Assert.Equal (expectedSubViewFound, found == subview);
Application.Current.Dispose ();
Application.TopRunnable.Dispose ();
Application.ResetState (true);
}
@@ -280,24 +280,24 @@ public class GetViewsUnderLocationTests
[InlineData (-1, 0, 0, false)]
public void Returns_Correct_If_Start_Has_Offset_Viewport (int offset, int testX, int testY, bool expectedSubViewFound)
{
Application.Current = new ()
Application.TopRunnable = new ()
{
Width = 10, Height = 10,
ViewportSettings = ViewportSettingsFlags.AllowNegativeLocation
};
Application.Current.Viewport = new (offset, offset, 10, 10);
Application.TopRunnable.Viewport = new (offset, offset, 10, 10);
var subview = new View
{
X = 1, Y = 1,
Width = 2, Height = 2
};
Application.Current.Add (subview);
Application.TopRunnable.Add (subview);
View? found = Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
Assert.Equal (expectedSubViewFound, found == subview);
Application.Current.Dispose ();
Application.TopRunnable.Dispose ();
Application.ResetState (true);
}
@@ -313,25 +313,25 @@ public class GetViewsUnderLocationTests
[InlineData (6, 7, false)]
public void Returns_Correct_If_Start_Has_Adornment_WithSubView (int testX, int testY, bool expectedSubViewFound)
{
Application.Current = new ()
Application.TopRunnable = new ()
{
Width = 10, Height = 10
};
Application.Current.Padding!.Thickness = new (1);
Application.TopRunnable.Padding!.Thickness = new (1);
var subview = new View
{
X = Pos.AnchorEnd (1), Y = Pos.AnchorEnd (1),
Width = 1, Height = 1
};
Application.Current.Padding.Add (subview);
Application.Current.BeginInit ();
Application.Current.EndInit ();
Application.TopRunnable.Padding.Add (subview);
Application.TopRunnable.BeginInit ();
Application.TopRunnable.EndInit ();
View? found = Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
Assert.Equal (expectedSubViewFound, found == subview);
Application.Current.Dispose ();
Application.TopRunnable.Dispose ();
Application.ResetState (true);
}
@@ -347,17 +347,17 @@ public class GetViewsUnderLocationTests
{
Application.ResetState (true);
Application.Current = new ()
Application.TopRunnable = new ()
{
Id = "Top",
Width = 10, Height = 10
};
Application.Current.Margin!.Thickness = new (1);
Application.Current.Margin!.Id = "Margin";
Application.Current.Border!.Thickness = new (1);
Application.Current.Border!.Id = "Border";
Application.Current.Padding!.Thickness = new (1);
Application.Current.Padding.Id = "Padding";
Application.TopRunnable.Margin!.Thickness = new (1);
Application.TopRunnable.Margin!.Id = "Margin";
Application.TopRunnable.Border!.Thickness = new (1);
Application.TopRunnable.Border!.Id = "Border";
Application.TopRunnable.Padding!.Thickness = new (1);
Application.TopRunnable.Padding.Id = "Padding";
var subview = new View
{
@@ -365,13 +365,13 @@ public class GetViewsUnderLocationTests
X = 1, Y = 1,
Width = 1, Height = 1
};
Application.Current.Add (subview);
Application.TopRunnable.Add (subview);
List<View?> viewsUnderMouse = Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse);
List<View?> viewsUnderMouse = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse);
string [] foundIds = viewsUnderMouse.Select (v => v!.Id).ToArray ();
Assert.Equal (expectedViewsFound, foundIds);
Application.Current.Dispose ();
Application.TopRunnable.Dispose ();
Application.ResetState (true);
}
@@ -388,7 +388,7 @@ public class GetViewsUnderLocationTests
[InlineData (2, 3, new [] { "Top", "subview" })]
public void Returns_Correct_If_SubView_Has_Adornments (int testX, int testY, string [] expectedViewsFound)
{
Application.Current = new ()
Application.TopRunnable = new ()
{
Id = "Top",
Width = 10, Height = 10
@@ -402,13 +402,13 @@ public class GetViewsUnderLocationTests
};
subview.Border!.Thickness = new (1);
subview.Border!.Id = "border";
Application.Current.Add (subview);
Application.TopRunnable.Add (subview);
List<View?> viewsUnderMouse = Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse);
List<View?> viewsUnderMouse = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse);
string [] foundIds = viewsUnderMouse.Select (v => v!.Id).ToArray ();
Assert.Equal (expectedViewsFound, foundIds);
Application.Current.Dispose ();
Application.TopRunnable.Dispose ();
Application.ResetState (true);
}
@@ -425,7 +425,7 @@ public class GetViewsUnderLocationTests
[InlineData (2, 3, new [] { "Top", "subview" })]
public void Returns_Correct_If_SubView_Has_Adornments_With_TransparentMouse (int testX, int testY, string [] expectedViewsFound)
{
Application.Current = new ()
Application.TopRunnable = new ()
{
Id = "Top",
Width = 10, Height = 10
@@ -440,13 +440,13 @@ public class GetViewsUnderLocationTests
subview.Border!.Thickness = new (1);
subview.Border!.ViewportSettings = ViewportSettingsFlags.TransparentMouse;
subview.Border!.Id = "border";
Application.Current.Add (subview);
Application.TopRunnable.Add (subview);
List<View?> viewsUnderMouse = Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse);
List<View?> viewsUnderMouse = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse);
string [] foundIds = viewsUnderMouse.Select (v => v!.Id).ToArray ();
Assert.Equal (expectedViewsFound, foundIds);
Application.Current.Dispose ();
Application.TopRunnable.Dispose ();
Application.ResetState (true);
}
@@ -463,7 +463,7 @@ public class GetViewsUnderLocationTests
[InlineData (5, 5, true)]
public void Returns_Correct_If_SubView_Has_Adornment_WithSubView (int testX, int testY, bool expectedSubViewFound)
{
Application.Current = new ()
Application.TopRunnable = new ()
{
Width = 10, Height = 10
};
@@ -486,14 +486,14 @@ public class GetViewsUnderLocationTests
Height = 1
};
subview.Padding.Add (paddingSubView);
Application.Current.Add (subview);
Application.Current.BeginInit ();
Application.Current.EndInit ();
Application.TopRunnable.Add (subview);
Application.TopRunnable.BeginInit ();
Application.TopRunnable.EndInit ();
View? found = Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
Assert.Equal (expectedSubViewFound, found == paddingSubView);
Application.Current.Dispose ();
Application.TopRunnable.Dispose ();
Application.ResetState (true);
}
@@ -510,7 +510,7 @@ public class GetViewsUnderLocationTests
[InlineData (5, 5, true)]
public void Returns_Correct_If_SubView_Is_Scrolled_And_Has_Adornment_WithSubView (int testX, int testY, bool expectedSubViewFound)
{
Application.Current = new ()
Application.TopRunnable = new ()
{
Width = 10, Height = 10
};
@@ -537,14 +537,14 @@ public class GetViewsUnderLocationTests
Height = 1
};
subview.Padding.Add (paddingSubView);
Application.Current.Add (subview);
Application.Current.BeginInit ();
Application.Current.EndInit ();
Application.TopRunnable.Add (subview);
Application.TopRunnable.BeginInit ();
Application.TopRunnable.EndInit ();
View? found = Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
Assert.Equal (expectedSubViewFound, found == paddingSubView);
Application.Current.Dispose ();
Application.TopRunnable.Dispose ();
Application.ResetState (true);
}
@@ -560,7 +560,7 @@ public class GetViewsUnderLocationTests
[InlineData (5, 5, 2)]
public void Returns_Correct_With_NestedSubViews (int testX, int testY, int expectedSubViewFound)
{
Application.Current = new ()
Application.TopRunnable = new ()
{
Width = 10, Height = 10
};
@@ -583,11 +583,11 @@ public class GetViewsUnderLocationTests
}
}
Application.Current.Add (subviews [0]);
Application.TopRunnable.Add (subviews [0]);
View? found = Application.Current.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
View? found = Application.TopRunnable.GetViewsUnderLocation (new (testX, testY), ViewportSettingsFlags.TransparentMouse).LastOrDefault ();
Assert.Equal (expectedSubViewFound, subviews.IndexOf (found!));
Application.Current.Dispose ();
Application.TopRunnable.Dispose ();
Application.ResetState (true);
}
@@ -604,7 +604,7 @@ public class GetViewsUnderLocationTests
public void Tiled_SubViews (int mouseX, int mouseY, string [] viewIdStrings)
{
// Arrange
Application.Current = new ()
Application.TopRunnable = new ()
{
Frame = new (0, 0, 10, 10),
Id = "top"
@@ -630,15 +630,15 @@ public class GetViewsUnderLocationTests
Arrangement = ViewArrangement.Overlapped
}; // at 2,2 to 4,3 (screen)
view.Add (subView);
Application.Current.Add (view);
Application.TopRunnable.Add (view);
List<View?> found = Application.Current.GetViewsUnderLocation (new (mouseX, mouseY), ViewportSettingsFlags.TransparentMouse);
List<View?> found = Application.TopRunnable.GetViewsUnderLocation (new (mouseX, mouseY), ViewportSettingsFlags.TransparentMouse);
string [] foundIds = found.Select (v => v!.Id).ToArray ();
Assert.Equal (viewIdStrings, foundIds);
Application.Current.Dispose ();
Application.TopRunnable.Dispose ();
Application.ResetState (true);
}
@@ -656,7 +656,7 @@ public class GetViewsUnderLocationTests
public void Popover (int mouseX, int mouseY, string [] viewIdStrings)
{
// Arrange
Application.Current = new ()
Application.TopRunnable = new ()
{
Frame = new (0, 0, 10, 10),
Id = "top"
@@ -683,15 +683,15 @@ public class GetViewsUnderLocationTests
}; // at 2,2 to 4,3 (screen)
view.Add (popOver);
Application.Current.Add (view);
Application.TopRunnable.Add (view);
List<View?> found = Application.Current.GetViewsUnderLocation (new (mouseX, mouseY), ViewportSettingsFlags.TransparentMouse);
List<View?> found = Application.TopRunnable.GetViewsUnderLocation (new (mouseX, mouseY), ViewportSettingsFlags.TransparentMouse);
string [] foundIds = found.Select (v => v!.Id).ToArray ();
Assert.Equal (viewIdStrings, foundIds);
Application.Current.Dispose ();
Application.TopRunnable.Dispose ();
Application.ResetState (true);
}
@@ -717,9 +717,9 @@ public class GetViewsUnderLocationTests
Application.SessionStack.Clear ();
Application.SessionStack.Push (topToplevel);
Application.SessionStack.Push (secondaryToplevel);
Application.Current = secondaryToplevel;
Application.TopRunnable = secondaryToplevel;
List<View?> found = Application.Current.GetViewsUnderLocation (new (2, 2), ViewportSettingsFlags.TransparentMouse);
List<View?> found = Application.TopRunnable.GetViewsUnderLocation (new (2, 2), ViewportSettingsFlags.TransparentMouse);
Assert.Contains (found, v => v?.Id == topToplevel.Id);
Assert.Contains (found, v => v == topToplevel);
@@ -751,9 +751,9 @@ public class GetViewsUnderLocationTests
Application.SessionStack.Clear ();
Application.SessionStack.Push (topToplevel);
Application.SessionStack.Push (secondaryToplevel);
Application.Current = secondaryToplevel;
Application.TopRunnable = secondaryToplevel;
List<View?> found = Application.Current.GetViewsUnderLocation (new (7, 7), ViewportSettingsFlags.TransparentMouse);
List<View?> found = Application.TopRunnable.GetViewsUnderLocation (new (7, 7), ViewportSettingsFlags.TransparentMouse);
Assert.Contains (found, v => v?.Id == secondaryToplevel.Id);
Assert.DoesNotContain (found, v => v?.Id == topToplevel.Id);
@@ -784,17 +784,17 @@ public class GetViewsUnderLocationTests
Application.SessionStack.Clear ();
Application.SessionStack.Push (topToplevel);
Application.SessionStack.Push (secondaryToplevel);
Application.Current = secondaryToplevel;
Application.TopRunnable = secondaryToplevel;
secondaryToplevel.Margin!.ViewportSettings = ViewportSettingsFlags.None;
List<View?> found = Application.Current.GetViewsUnderLocation (new (5, 5), ViewportSettingsFlags.TransparentMouse);
List<View?> found = Application.TopRunnable.GetViewsUnderLocation (new (5, 5), ViewportSettingsFlags.TransparentMouse);
Assert.Contains (found, v => v == secondaryToplevel);
Assert.Contains (found, v => v == secondaryToplevel.Margin);
Assert.DoesNotContain (found, v => v?.Id == topToplevel.Id);
secondaryToplevel.Margin!.ViewportSettings = ViewportSettingsFlags.TransparentMouse;
found = Application.Current.GetViewsUnderLocation (new (5, 5), ViewportSettingsFlags.TransparentMouse);
found = Application.TopRunnable.GetViewsUnderLocation (new (5, 5), ViewportSettingsFlags.TransparentMouse);
Assert.DoesNotContain (found, v => v == secondaryToplevel);
Assert.DoesNotContain (found, v => v == secondaryToplevel.Margin);
Assert.Contains (found, v => v?.Id == topToplevel.Id);
@@ -827,9 +827,9 @@ public class GetViewsUnderLocationTests
Application.SessionStack.Clear ();
Application.SessionStack.Push (topToplevel);
Application.SessionStack.Push (secondaryToplevel);
Application.Current = secondaryToplevel;
Application.TopRunnable = secondaryToplevel;
List<View?> found = Application.Current.GetViewsUnderLocation (new (20, 20), ViewportSettingsFlags.TransparentMouse);
List<View?> found = Application.TopRunnable.GetViewsUnderLocation (new (20, 20), ViewportSettingsFlags.TransparentMouse);
Assert.Empty (found);
topToplevel.Dispose ();

View File

@@ -40,7 +40,7 @@ public class PosCombineTests (ITestOutputHelper output)
[SetupFakeApplication]
public void PosCombine_DimCombine_View_With_SubViews ()
{
Application.Current = new Toplevel () { Width = 80, Height = 25 };
Application.TopRunnable = new Toplevel () { Width = 80, Height = 25 };
var win1 = new Window { Id = "win1", Width = 20, Height = 10 };
var view1 = new View
{
@@ -59,18 +59,18 @@ public class PosCombineTests (ITestOutputHelper output)
view2.Add (view3);
win2.Add (view2);
win1.Add (view1, win2);
Application.Current.Add (win1);
Application.Current.Layout ();
Application.TopRunnable.Add (win1);
Application.TopRunnable.Layout ();
Assert.Equal (new Rectangle (0, 0, 80, 25), Application.Current.Frame);
Assert.Equal (new Rectangle (0, 0, 80, 25), Application.TopRunnable.Frame);
Assert.Equal (new Rectangle (0, 0, 5, 1), view1.Frame);
Assert.Equal (new Rectangle (0, 0, 20, 10), win1.Frame);
Assert.Equal (new Rectangle (0, 2, 10, 3), win2.Frame);
Assert.Equal (new Rectangle (0, 0, 8, 1), view2.Frame);
Assert.Equal (new Rectangle (0, 0, 7, 1), view3.Frame);
var foundView = Application.Current.GetViewsUnderLocation (new Point(9, 4), ViewportSettingsFlags.None).LastOrDefault ();
var foundView = Application.TopRunnable.GetViewsUnderLocation (new Point(9, 4), ViewportSettingsFlags.None).LastOrDefault ();
Assert.Equal (foundView, view2);
Application.Current.Dispose ();
Application.TopRunnable.Dispose ();
}
[Fact]
@@ -89,13 +89,13 @@ public class PosCombineTests (ITestOutputHelper output)
top.Add (w);
Application.Begin (top);
f.X = Pos.X (Application.Current) + Pos.X (v2) - Pos.X (v1);
f.Y = Pos.Y (Application.Current) + Pos.Y (v2) - Pos.Y (v1);
f.X = Pos.X (Application.TopRunnable) + Pos.X (v2) - Pos.X (v1);
f.Y = Pos.Y (Application.TopRunnable) + Pos.Y (v2) - Pos.Y (v1);
Application.Current.SubViewsLaidOut += (s, e) =>
Application.TopRunnable.SubViewsLaidOut += (s, e) =>
{
Assert.Equal (0, Application.Current.Frame.X);
Assert.Equal (0, Application.Current.Frame.Y);
Assert.Equal (0, Application.TopRunnable.Frame.X);
Assert.Equal (0, Application.TopRunnable.Frame.Y);
Assert.Equal (2, w.Frame.X);
Assert.Equal (2, w.Frame.Y);
Assert.Equal (2, f.Frame.X);
@@ -109,7 +109,7 @@ public class PosCombineTests (ITestOutputHelper output)
Application.StopAfterFirstIteration = true;
Assert.Throws<LayoutException> (() => Application.Run ());
Application.Current.Dispose ();
Application.TopRunnable.Dispose ();
top.Dispose ();
Application.Shutdown ();
}

View File

@@ -12,7 +12,7 @@ public class SetLayoutTests (ITestOutputHelper output)
[AutoInitShutdown]
public void Screen_Size_Change_Causes_Layout ()
{
Application.Current = new ();
Application.TopRunnable = new ();
var view = new View
{
@@ -22,21 +22,21 @@ public class SetLayoutTests (ITestOutputHelper output)
Height = 1,
Text = "0123456789"
};
Application.Current.Add (view);
Application.TopRunnable.Add (view);
var rs = Application.Begin (Application.Current);
var rs = Application.Begin (Application.TopRunnable);
Application.Driver!.SetScreenSize (80, 25);
Assert.Equal (new (0, 0, 80, 25), new Rectangle (0, 0, Application.Screen.Width, Application.Screen.Height));
Assert.Equal (new (0, 0, Application.Screen.Width, Application.Screen.Height), Application.Current.Frame);
Assert.Equal (new (0, 0, 80, 25), Application.Current.Frame);
Assert.Equal (new (0, 0, Application.Screen.Width, Application.Screen.Height), Application.TopRunnable.Frame);
Assert.Equal (new (0, 0, 80, 25), Application.TopRunnable.Frame);
Application.Driver!.SetScreenSize (20, 10);
Assert.Equal (new (0, 0, Application.Screen.Width, Application.Screen.Height), Application.Current.Frame);
Assert.Equal (new (0, 0, Application.Screen.Width, Application.Screen.Height), Application.TopRunnable.Frame);
Assert.Equal (new (0, 0, 20, 10), Application.Current.Frame);
Assert.Equal (new (0, 0, 20, 10), Application.TopRunnable.Frame);
Application.End (rs);
Application.Current.Dispose ();
Application.TopRunnable.Dispose ();
}
}

View File

@@ -89,13 +89,13 @@ public class CanFocusTests
public void CanFocus_Set_True_Get_AdvanceFocus_Works ()
{
IApplication app = Application.Create ();
app.Current = new () { App = app };
app.TopRunnable = new () { App = app };
Label label = new () { Text = "label" };
View view = new () { Text = "view", CanFocus = true };
app.Current.Add (label, view);
app.TopRunnable.Add (label, view);
app.Current.SetFocus ();
app.TopRunnable.SetFocus ();
Assert.Equal (view, app.Navigation!.GetFocused ());
Assert.False (label.CanFocus);
Assert.False (label.HasFocus);
@@ -125,7 +125,7 @@ public class CanFocusTests
Assert.True (label.HasFocus);
Assert.False (view.HasFocus);
app.Current.Dispose ();
app.TopRunnable.Dispose ();
app.ResetState ();
}
}

View File

@@ -27,7 +27,7 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
}
Toplevel top = new ();
Application.Current = top;
Application.TopRunnable = top;
View otherView = new ()
{
@@ -117,7 +117,7 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
}
Toplevel top = new ();
Application.Current = top;
Application.TopRunnable = top;
View otherView = new ()
{
@@ -148,8 +148,8 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
// Ensure the view is Visible
view.Visible = true;
Application.Current.SetFocus ();
Assert.True (Application.Current!.HasFocus);
Application.TopRunnable.SetFocus ();
Assert.True (Application.TopRunnable!.HasFocus);
Assert.True (top.HasFocus);
// Start with the focus on our test view
@@ -280,7 +280,7 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
Toplevel top = new ();
Application.Current = top;
Application.TopRunnable = top;
View otherView = new ()
{

View File

@@ -396,7 +396,7 @@ Y
Assert.Equal (new (1, 5), view.TextFormatter.ConstrainToSize);
Assert.Equal (new () { "Views" }, view.TextFormatter.GetLines ());
Assert.Equal (new (0, 0, 4, 10), win.Frame);
Assert.Equal (new (0, 0, 4, 10), Application.Current.Frame);
Assert.Equal (new (0, 0, 4, 10), Application.TopRunnable.Frame);
var expected = @"
┌──┐

View File

@@ -46,9 +46,9 @@ public class ViewCommandTests
w.LayoutSubViews ();
Application.Current = w;
Application.TopRunnable = w;
Application.SessionStack.Push (w);
Assert.Same (Application.Current, w);
Assert.Same (Application.TopRunnable, w);
// Click button 2
Rectangle btn2Frame = btnB.FrameToScreen ();
@@ -121,9 +121,9 @@ public class ViewCommandTests
w.Add (btn);
Application.Current = w;
Application.TopRunnable = w;
Application.SessionStack.Push (w);
Assert.Same (Application.Current, w);
Assert.Same (Application.TopRunnable, w);
w.LayoutSubViews ();

View File

@@ -23,7 +23,7 @@ public class TransparentMouseTests
{
Id = "top",
};
Application.Current = top;
Application.TopRunnable = top;
var underlying = new MouseTrackingView { Id = "underlying", X = 0, Y = 0, Width = 10, Height = 10 };
var overlay = new MouseTrackingView { Id = "overlay", X = 0, Y = 0, Width = 10, Height = 10, ViewportSettings = ViewportSettingsFlags.TransparentMouse };
@@ -56,7 +56,7 @@ public class TransparentMouseTests
{
// Arrange
var top = new Toplevel ();
Application.Current = top;
Application.TopRunnable = top;
var underlying = new MouseTrackingView { X = 0, Y = 0, Width = 10, Height = 10 };
var overlay = new MouseTrackingView { X = 0, Y = 0, Width = 10, Height = 10, ViewportSettings = ViewportSettingsFlags.None };
@@ -90,7 +90,7 @@ public class TransparentMouseTests
{
// Arrange
var top = new Toplevel ();
Application.Current = top;
Application.TopRunnable = top;
var underlying = new MouseTrackingView { X = 0, Y = 0, Width = 10, Height = 10, ViewportSettings = ViewportSettingsFlags.TransparentMouse };
var overlay = new MouseTrackingView { X = 0, Y = 0, Width = 10, Height = 10, ViewportSettings = ViewportSettingsFlags.TransparentMouse };