mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* Fixes #1446. Added more features to the Border and Toplevel focus. * Prevents throwing exception on negative effect3DOffset values * Ensures that a view can be focused. * Only sets focus if it isn't disposing. * Fixes ViewToScreen and DrawChildBorder Effect3D. * Unit test for negative coordinates with the ViewToScreen method. * Added Tab navigation feature to the Editor scenario. * ComboBox cursonDownKey nullref fix (#1472) * added null guard to fix null ref when pressing keyDown inside combobox Improved an error message when view cannot be found * Added a unit test to ensure combobox can process all key events Found and fixed a new nullref * Found a new bug when source is already present and combobox is added to a top view * searchSet is auto initialized to new List() now to make the code a little bit safer * Fixes WindowsDriver HeightAsBuffer set to false. (#1466) * Bump ReportGenerator from 4.8.12 to 4.8.13 (#1473) Bumps [ReportGenerator](https://github.com/danielpalme/ReportGenerator) from 4.8.12 to 4.8.13. - [Release notes](https://github.com/danielpalme/ReportGenerator/releases) - [Commits](https://github.com/danielpalme/ReportGenerator/compare/v4.8.12...v4.8.13) --- updated-dependencies: - dependency-name: ReportGenerator dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Fixes #1445. Fixing more the Curses and WSL clipboard. (#1448) * Fixes #1445. Fixing more the Curses and WSL clipboard. * Fixing unit tests. * Changing namespace. * Fixes WSL2 clipboard unit test. * Upgrades devcontainer with the MainLoop fix. * Fixes pasting with no selection and with lines break. * Prevents the event button click being fired after a button pressed with mouse move. * Fixes the char [ not being processed. * Added Application.QuitKey property to allow change the quitting application key. (#1450) * Added Application.QuitKey property to allow change the quitting application key. * Fixes QuitKey unit test by reseting his value. * Locks timeouts until is added. * Fixes #1467. AlternateForward/BackwardKey bypasses dialog modality (#1468) * Changed namespace. * Fixing merge conflicts. * Fixes mouse click issue. * Removing windows resizing because buffer resizing is enough. * Fixes #1477. Mouse click and console bottom on Windows Terminal. Co-authored-by: Igor Bagdamyan <37334640+En3Tho@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
321 lines
11 KiB
C#
321 lines
11 KiB
C#
using System;
|
|
using Xunit;
|
|
|
|
namespace Terminal.Gui.Core {
|
|
public class ToplevelTests {
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Constructor_Default ()
|
|
{
|
|
var top = new Toplevel ();
|
|
|
|
Assert.Equal (Colors.TopLevel, top.ColorScheme);
|
|
Assert.Equal ("Dim.Fill(margin=0)", top.Width.ToString ());
|
|
Assert.Equal ("Dim.Fill(margin=0)", top.Height.ToString ());
|
|
Assert.False (top.Running);
|
|
Assert.False (top.Modal);
|
|
Assert.Null (top.MenuBar);
|
|
Assert.Null (top.StatusBar);
|
|
Assert.False (top.IsMdiContainer);
|
|
Assert.False (top.IsMdiChild);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Create_Toplevel ()
|
|
{
|
|
var top = Toplevel.Create ();
|
|
Assert.Equal (new Rect (0, 0, Application.Driver.Cols, Application.Driver.Rows), top.Bounds);
|
|
}
|
|
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Application_Top_EnsureVisibleBounds_To_Driver_Rows_And_Cols ()
|
|
{
|
|
var iterations = 0;
|
|
|
|
Application.Iteration += () => {
|
|
if (iterations == 0) {
|
|
Assert.Equal ("Top1", Application.Top.Text);
|
|
Assert.Equal (0, Application.Top.Frame.X);
|
|
Assert.Equal (0, Application.Top.Frame.Y);
|
|
Assert.Equal (Application.Driver.Cols, Application.Top.Frame.Width);
|
|
Assert.Equal (Application.Driver.Rows, Application.Top.Frame.Height);
|
|
|
|
Application.Top.ProcessHotKey (new KeyEvent (Key.CtrlMask | Key.R, new KeyModifiers ()));
|
|
} else if (iterations == 1) {
|
|
Assert.Equal ("Top2", Application.Top.Text);
|
|
Assert.Equal (0, Application.Top.Frame.X);
|
|
Assert.Equal (0, Application.Top.Frame.Y);
|
|
Assert.Equal (Application.Driver.Cols, Application.Top.Frame.Width);
|
|
Assert.Equal (Application.Driver.Rows, Application.Top.Frame.Height);
|
|
|
|
Application.Top.ProcessHotKey (new KeyEvent (Key.CtrlMask | Key.C, new KeyModifiers ()));
|
|
} else if (iterations == 3) {
|
|
Assert.Equal ("Top1", Application.Top.Text);
|
|
Assert.Equal (0, Application.Top.Frame.X);
|
|
Assert.Equal (0, Application.Top.Frame.Y);
|
|
Assert.Equal (Application.Driver.Cols, Application.Top.Frame.Width);
|
|
Assert.Equal (Application.Driver.Rows, Application.Top.Frame.Height);
|
|
|
|
Application.Top.ProcessHotKey (new KeyEvent (Key.CtrlMask | Key.R, new KeyModifiers ()));
|
|
} else if (iterations == 4) {
|
|
Assert.Equal ("Top2", Application.Top.Text);
|
|
Assert.Equal (0, Application.Top.Frame.X);
|
|
Assert.Equal (0, Application.Top.Frame.Y);
|
|
Assert.Equal (Application.Driver.Cols, Application.Top.Frame.Width);
|
|
Assert.Equal (Application.Driver.Rows, Application.Top.Frame.Height);
|
|
|
|
Application.Top.ProcessHotKey (new KeyEvent (Key.CtrlMask | Key.C, new KeyModifiers ()));
|
|
} else if (iterations == 6) {
|
|
Assert.Equal ("Top1", Application.Top.Text);
|
|
Assert.Equal (0, Application.Top.Frame.X);
|
|
Assert.Equal (0, Application.Top.Frame.Y);
|
|
Assert.Equal (Application.Driver.Cols, Application.Top.Frame.Width);
|
|
Assert.Equal (Application.Driver.Rows, Application.Top.Frame.Height);
|
|
|
|
Application.Top.ProcessHotKey (new KeyEvent (Key.CtrlMask | Key.Q, new KeyModifiers ()));
|
|
}
|
|
iterations++;
|
|
};
|
|
|
|
Application.Run (Top1 ());
|
|
|
|
Toplevel Top1 ()
|
|
{
|
|
var top = Application.Top;
|
|
top.Text = "Top1";
|
|
var menu = new MenuBar (new MenuBarItem [] {
|
|
new MenuBarItem ("_Options", new MenuItem [] {
|
|
new MenuItem ("_Run Top2", "", () => Application.Run (Top2 ()), null, null, Key.CtrlMask | Key.R),
|
|
new MenuItem ("_Quit", "", () => Application.RequestStop(), null, null, Key.CtrlMask | Key.Q)
|
|
})
|
|
});
|
|
top.Add (menu);
|
|
|
|
var statusBar = new StatusBar (new [] {
|
|
new StatusItem(Key.CtrlMask | Key.R, "~^R~ Run Top2", () => Application.Run (Top2 ())),
|
|
new StatusItem(Key.CtrlMask | Key.Q, "~^Q~ Quit", () => Application.RequestStop())
|
|
});
|
|
top.Add (statusBar);
|
|
|
|
var t1 = new Toplevel ();
|
|
top.Add (t1);
|
|
|
|
return top;
|
|
}
|
|
|
|
Toplevel Top2 ()
|
|
{
|
|
var top = new Toplevel (Application.Top.Frame);
|
|
top.Text = "Top2";
|
|
var win = new Window () { Width = Dim.Fill (), Height = Dim.Fill () };
|
|
var menu = new MenuBar (new MenuBarItem [] {
|
|
new MenuBarItem ("_Stage", new MenuItem [] {
|
|
new MenuItem ("_Close", "", () => Application.RequestStop(), null, null, Key.CtrlMask | Key.C)
|
|
})
|
|
});
|
|
top.Add (menu);
|
|
|
|
var statusBar = new StatusBar (new [] {
|
|
new StatusItem(Key.CtrlMask | Key.C, "~^C~ Close", () => Application.RequestStop()),
|
|
});
|
|
top.Add (statusBar);
|
|
|
|
win.Add (new ListView () {
|
|
X = 0,
|
|
Y = 0,
|
|
Width = Dim.Fill (),
|
|
Height = Dim.Fill ()
|
|
});
|
|
top.Add (win);
|
|
|
|
return top;
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Internal_Tests ()
|
|
{
|
|
var top = new Toplevel ();
|
|
var eventInvoked = "";
|
|
|
|
top.ChildUnloaded += (e) => eventInvoked = "ChildUnloaded";
|
|
top.OnChildUnloaded (top);
|
|
Assert.Equal ("ChildUnloaded", eventInvoked);
|
|
top.ChildLoaded += (e) => eventInvoked = "ChildLoaded";
|
|
top.OnChildLoaded (top);
|
|
Assert.Equal ("ChildLoaded", eventInvoked);
|
|
top.Closed += (e) => eventInvoked = "Closed";
|
|
top.OnClosed (top);
|
|
Assert.Equal ("Closed", eventInvoked);
|
|
top.Closing += (e) => eventInvoked = "Closing";
|
|
top.OnClosing (new ToplevelClosingEventArgs (top));
|
|
Assert.Equal ("Closing", eventInvoked);
|
|
top.AllChildClosed += () => eventInvoked = "AllChildClosed";
|
|
top.OnAllChildClosed ();
|
|
Assert.Equal ("AllChildClosed", eventInvoked);
|
|
top.ChildClosed += (e) => eventInvoked = "ChildClosed";
|
|
top.OnChildClosed (top);
|
|
Assert.Equal ("ChildClosed", eventInvoked);
|
|
top.Deactivate += (e) => eventInvoked = "Deactivate";
|
|
top.OnDeactivate (top);
|
|
Assert.Equal ("Deactivate", eventInvoked);
|
|
top.Activate += (e) => eventInvoked = "Activate";
|
|
top.OnActivate (top);
|
|
Assert.Equal ("Activate", eventInvoked);
|
|
top.Loaded += () => eventInvoked = "Loaded";
|
|
top.OnLoaded ();
|
|
Assert.Equal ("Loaded", eventInvoked);
|
|
top.Ready += () => eventInvoked = "Ready";
|
|
top.OnReady ();
|
|
Assert.Equal ("Ready", eventInvoked);
|
|
top.Unloaded += () => eventInvoked = "Unloaded";
|
|
top.OnUnloaded ();
|
|
Assert.Equal ("Unloaded", eventInvoked);
|
|
|
|
top.AddMenuStatusBar (new MenuBar ());
|
|
Assert.NotNull (top.MenuBar);
|
|
top.AddMenuStatusBar (new StatusBar ());
|
|
Assert.NotNull (top.StatusBar);
|
|
top.RemoveMenuStatusBar (top.MenuBar);
|
|
Assert.Null (top.MenuBar);
|
|
top.RemoveMenuStatusBar (top.StatusBar);
|
|
Assert.Null (top.StatusBar);
|
|
|
|
Application.Begin (top);
|
|
Assert.Equal (top, Application.Top);
|
|
|
|
// top is Application.Top without menu and status bar.
|
|
var supView = top.EnsureVisibleBounds (top, 2, 2, out int nx, out int ny, out View mb, out View sb);
|
|
Assert.Equal (Application.Top, supView);
|
|
Assert.Equal (0, nx);
|
|
Assert.Equal (0, ny);
|
|
Assert.Null (mb);
|
|
Assert.Null (sb);
|
|
|
|
top.AddMenuStatusBar (new MenuBar ());
|
|
Assert.NotNull (top.MenuBar);
|
|
|
|
// top is Application.Top with a menu and without status bar.
|
|
top.EnsureVisibleBounds (top, 2, 2, out nx, out ny, out mb, out sb);
|
|
Assert.Equal (0, nx);
|
|
Assert.Equal (1, ny);
|
|
Assert.NotNull (mb);
|
|
Assert.Null (sb);
|
|
|
|
top.AddMenuStatusBar (new StatusBar ());
|
|
Assert.NotNull (top.StatusBar);
|
|
|
|
// top is Application.Top with a menu and status bar.
|
|
top.EnsureVisibleBounds (top, 2, 2, out nx, out ny, out mb, out sb);
|
|
Assert.Equal (0, nx);
|
|
Assert.Equal (1, ny);
|
|
Assert.NotNull (mb);
|
|
Assert.NotNull (sb);
|
|
|
|
top.RemoveMenuStatusBar (top.MenuBar);
|
|
Assert.Null (top.MenuBar);
|
|
|
|
// top is Application.Top without a menu and with a status bar.
|
|
top.EnsureVisibleBounds (top, 2, 2, out nx, out ny, out mb, out sb);
|
|
Assert.Equal (0, nx);
|
|
Assert.Equal (0, ny);
|
|
Assert.Null (mb);
|
|
Assert.NotNull (sb);
|
|
|
|
top.RemoveMenuStatusBar (top.StatusBar);
|
|
Assert.Null (top.StatusBar);
|
|
Assert.Null (top.MenuBar);
|
|
|
|
var win = new Window () { Width = Dim.Fill (), Height = Dim.Fill () };
|
|
top.Add (win);
|
|
top.LayoutSubviews ();
|
|
|
|
// The SuperView is always the same regardless of the caller.
|
|
supView = top.EnsureVisibleBounds (win, 0, 0, out nx, out ny, out mb, out sb);
|
|
Assert.Equal (Application.Top, supView);
|
|
supView = win.EnsureVisibleBounds (win, 0, 0, out nx, out ny, out mb, out sb);
|
|
Assert.Equal (Application.Top, supView);
|
|
|
|
// top is Application.Top without menu and status bar.
|
|
top.EnsureVisibleBounds (win, 0, 0, out nx, out ny, out mb, out sb);
|
|
Assert.Equal (0, nx);
|
|
Assert.Equal (0, ny);
|
|
Assert.Null (mb);
|
|
Assert.Null (sb);
|
|
|
|
top.AddMenuStatusBar (new MenuBar ());
|
|
Assert.NotNull (top.MenuBar);
|
|
|
|
// top is Application.Top with a menu and without status bar.
|
|
top.EnsureVisibleBounds (win, 2, 2, out nx, out ny, out mb, out sb);
|
|
Assert.Equal (0, nx);
|
|
Assert.Equal (1, ny);
|
|
Assert.NotNull (mb);
|
|
Assert.Null (sb);
|
|
|
|
top.AddMenuStatusBar (new StatusBar ());
|
|
Assert.NotNull (top.StatusBar);
|
|
|
|
// top is Application.Top with a menu and status bar.
|
|
top.EnsureVisibleBounds (win, 30, 20, out nx, out ny, out mb, out sb);
|
|
Assert.Equal (0, nx);
|
|
Assert.Equal (1, ny);
|
|
Assert.NotNull (mb);
|
|
Assert.NotNull (sb);
|
|
|
|
top.RemoveMenuStatusBar (top.MenuBar);
|
|
top.RemoveMenuStatusBar (top.StatusBar);
|
|
Assert.Null (top.StatusBar);
|
|
Assert.Null (top.MenuBar);
|
|
|
|
top.Remove (win);
|
|
|
|
win = new Window () { Width = 60, Height = 15 };
|
|
top.Add (win);
|
|
|
|
// top is Application.Top without menu and status bar.
|
|
top.EnsureVisibleBounds (win, 0, 0, out nx, out ny, out mb, out sb);
|
|
Assert.Equal (0, nx);
|
|
Assert.Equal (0, ny);
|
|
Assert.Null (mb);
|
|
Assert.Null (sb);
|
|
|
|
top.AddMenuStatusBar (new MenuBar ());
|
|
Assert.NotNull (top.MenuBar);
|
|
|
|
// top is Application.Top with a menu and without status bar.
|
|
top.EnsureVisibleBounds (win, 2, 2, out nx, out ny, out mb, out sb);
|
|
Assert.Equal (2, nx);
|
|
Assert.Equal (2, ny);
|
|
Assert.NotNull (mb);
|
|
Assert.Null (sb);
|
|
|
|
top.AddMenuStatusBar (new StatusBar ());
|
|
Assert.NotNull (top.StatusBar);
|
|
|
|
// top is Application.Top with a menu and status bar.
|
|
top.EnsureVisibleBounds (win, 30, 20, out nx, out ny, out mb, out sb);
|
|
Assert.Equal (20, nx); // 20+60=80
|
|
Assert.Equal (9, ny); // 9+15+1(mb)=25
|
|
Assert.NotNull (mb);
|
|
Assert.NotNull (sb);
|
|
|
|
top.PositionToplevels ();
|
|
Assert.Equal (new Rect (0, 1, 60, 15), win.Frame);
|
|
|
|
Assert.Null (Toplevel.dragPosition);
|
|
win.MouseEvent (new MouseEvent () { X = 6, Y = 0, Flags = MouseFlags.Button1Pressed });
|
|
Assert.Equal (new Point (6, 0), Toplevel.dragPosition);
|
|
win.MouseEvent (new MouseEvent () { X = 6, Y = 0, Flags = MouseFlags.Button1Released });
|
|
Assert.Null (Toplevel.dragPosition);
|
|
win.CanFocus = false;
|
|
win.MouseEvent (new MouseEvent () { X = 6, Y = 0, Flags = MouseFlags.Button1Pressed });
|
|
Assert.Null (Toplevel.dragPosition);
|
|
}
|
|
}
|
|
}
|