mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
* Fixes #1384. Added a VisibleChanged event on the View class. * Getting the last char. * Fixes #871. Added Enable property to Responder and added Disabled color for all ColorSchemes. * Added GetNormalColor method to the View being more readable. * Fixes the contentBottomRightCorner Enable and Visible. * Fixes #643. Added AddItemAt and RemoveItem to StatusBar and fixed more bugs. * Typo fixes. * Fixes #1387. Allowing the UnitTests project to test internal keywords. * Fixes #1389. Added a unidirectional feature to the Marquee styles to the ProgressBar. * Fixes #1394. Added ReflectedType to check for overridden. * Fixes #1396. Using the Loaded event instead the Ready event. * Fixes #1402. Only WindowsDriver supports horizontal scroll. (#1403) * Fixes #1402. Only WindowsDriver supports horizontal scroll. * Fixes ProcessContinuousButtonPressedAsync on all drivers. * Fixed internal unit test. * Fixing warning. * Fixing Editor scenario error. * Fixes double and triple click on a touchpad. * Ensuring reset the counting. * Allowing touchpad double and triple click with one finger on CursesDriver. * Allowing touchpad double and triple click with one finger on WindowsDriver. * Fixes #1414. Fixed multi toplevels and mdi container issues. * Improving EnsureVisibleBounds and PositionToplevel. * Added mouseGrabView to the ResetState method. * Changing namespace. * Allowing file type on the SaveDialog. * Fixes SaveDialogs writing the extension twice.
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
using Terminal.Gui;
|
||||
using Terminal.Gui.Graphs;
|
||||
using Terminal.Gui.Views;
|
||||
using Terminal.Gui.Graphs;
|
||||
using Xunit;
|
||||
|
||||
namespace UnitTests {
|
||||
namespace Terminal.Gui.Views {
|
||||
public class LineViewTests {
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using Terminal.Gui;
|
||||
using Xunit;
|
||||
|
||||
// Alais Console to MockConsole so we don't accidentally use Console
|
||||
// Alias Console to MockConsole so we don't accidentally use Console
|
||||
using Console = Terminal.Gui.FakeConsole;
|
||||
|
||||
namespace Terminal.Gui.Core {
|
||||
@@ -17,6 +17,8 @@ namespace Terminal.Gui.Core {
|
||||
Assert.Equal ("Terminal.Gui.Responder", r.ToString ());
|
||||
Assert.False (r.CanFocus);
|
||||
Assert.False (r.HasFocus);
|
||||
Assert.True (r.Enabled);
|
||||
Assert.True (r.Visible);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
160
UnitTests/StatusBarTests.cs
Normal file
160
UnitTests/StatusBarTests.cs
Normal file
@@ -0,0 +1,160 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Terminal.Gui.Views {
|
||||
public class StatusBarTests {
|
||||
readonly ITestOutputHelper output;
|
||||
|
||||
public StatusBarTests (ITestOutputHelper output)
|
||||
{
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StatusItem_Constructor ()
|
||||
{
|
||||
var si = new StatusItem (Key.CtrlMask | Key.Q, "~^Q~ Quit", null);
|
||||
Assert.Equal (Key.CtrlMask | Key.Q, si.Shortcut);
|
||||
Assert.Equal ("~^Q~ Quit", si.Title);
|
||||
Assert.Null (si.Action);
|
||||
si = new StatusItem (Key.CtrlMask | Key.Q, "~^Q~ Quit", () => { });
|
||||
Assert.NotNull (si.Action);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StatusBar_Contructor_Default ()
|
||||
{
|
||||
var sb = new StatusBar ();
|
||||
|
||||
Assert.Empty (sb.Items);
|
||||
Assert.False (sb.CanFocus);
|
||||
Assert.Equal (Colors.Menu, sb.ColorScheme);
|
||||
Assert.Equal (0, sb.X);
|
||||
Assert.Equal (Dim.Fill (), sb.Width);
|
||||
Assert.Equal (1, sb.Height);
|
||||
|
||||
Assert.Equal (0, sb.Y);
|
||||
|
||||
var driver = new FakeDriver ();
|
||||
Application.Init (driver, new FakeMainLoop (() => FakeConsole.ReadKey (true)));
|
||||
|
||||
sb = new StatusBar ();
|
||||
|
||||
driver.SetCursorVisibility (CursorVisibility.Default);
|
||||
driver.GetCursorVisibility (out CursorVisibility cv);
|
||||
Assert.Equal (CursorVisibility.Default, cv);
|
||||
Assert.True (FakeConsole.CursorVisible);
|
||||
|
||||
Application.Iteration += () => {
|
||||
Assert.Equal (24, sb.Y);
|
||||
|
||||
driver.SetWindowSize (driver.Cols, 15);
|
||||
|
||||
Assert.Equal (14, sb.Y);
|
||||
|
||||
sb.OnEnter (null);
|
||||
driver.GetCursorVisibility (out cv);
|
||||
Assert.Equal (CursorVisibility.Invisible, cv);
|
||||
Assert.False (FakeConsole.CursorVisible);
|
||||
|
||||
Application.RequestStop ();
|
||||
};
|
||||
|
||||
Application.Top.Add (sb);
|
||||
|
||||
Application.Run ();
|
||||
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void Run_Action_With_Key_And_Mouse ()
|
||||
{
|
||||
var msg = "";
|
||||
var sb = new StatusBar (new StatusItem [] { new StatusItem (Key.CtrlMask | Key.Q, "~^Q~ Quit", () => msg = "Quiting...") });
|
||||
Application.Top.Add (sb);
|
||||
|
||||
var iteration = 0;
|
||||
|
||||
Application.Iteration += () => {
|
||||
if (iteration == 0) {
|
||||
Assert.Equal ("", msg);
|
||||
sb.ProcessHotKey (new KeyEvent (Key.CtrlMask | Key.Q, null));
|
||||
} else if (iteration == 1) {
|
||||
Assert.Equal ("Quiting...", msg);
|
||||
msg = "";
|
||||
sb.MouseEvent (new MouseEvent () { X = 1, Y = 24, Flags = MouseFlags.Button1Clicked });
|
||||
} else {
|
||||
Assert.Equal ("Quiting...", msg);
|
||||
|
||||
Application.RequestStop ();
|
||||
}
|
||||
iteration++;
|
||||
};
|
||||
|
||||
Application.Run ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void Redraw_Output ()
|
||||
{
|
||||
var sb = new StatusBar (new StatusItem [] {
|
||||
new StatusItem (Key.CtrlMask | Key.Q, "~^O~ Open", null),
|
||||
new StatusItem (Key.CtrlMask | Key.Q, "~^Q~ Quit", null)
|
||||
});
|
||||
Application.Top.Add (sb);
|
||||
|
||||
sb.Redraw (sb.Bounds);
|
||||
|
||||
string expected = @$"
|
||||
^O Open {Application.Driver.VLine} ^Q Quit
|
||||
";
|
||||
|
||||
GraphViewTests.AssertDriverContentsAre (expected, output);
|
||||
|
||||
sb = new StatusBar (new StatusItem [] {
|
||||
new StatusItem (Key.CtrlMask | Key.Q, "~CTRL-O~ Open", null),
|
||||
new StatusItem (Key.CtrlMask | Key.Q, "~CTRL-Q~ Quit", null)
|
||||
});
|
||||
sb.Redraw (sb.Bounds);
|
||||
|
||||
expected = @$"
|
||||
CTRL-O Open {Application.Driver.VLine} CTRL-Q Quit
|
||||
";
|
||||
|
||||
GraphViewTests.AssertDriverContentsAre (expected, output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddItemAt_RemoveItem_Replacing ()
|
||||
{
|
||||
var sb = new StatusBar (new StatusItem [] {
|
||||
new StatusItem (Key.CtrlMask | Key.Q, "~^O~ Open", null),
|
||||
new StatusItem (Key.CtrlMask | Key.Q, "~^S~ Save", null),
|
||||
new StatusItem (Key.CtrlMask | Key.Q, "~^Q~ Quit", null)
|
||||
});
|
||||
|
||||
sb.AddItemAt (2, new StatusItem (Key.CtrlMask | Key.Q, "~^C~ Close", null));
|
||||
|
||||
Assert.Equal ("~^O~ Open", sb.Items [0].Title);
|
||||
Assert.Equal ("~^S~ Save", sb.Items [1].Title);
|
||||
Assert.Equal ("~^C~ Close", sb.Items [2].Title);
|
||||
Assert.Equal ("~^Q~ Quit", sb.Items [^1].Title);
|
||||
|
||||
Assert.Equal ("~^S~ Save", sb.RemoveItem (1).Title);
|
||||
|
||||
Assert.Equal ("~^O~ Open", sb.Items [0].Title);
|
||||
Assert.Equal ("~^C~ Close", sb.Items [1].Title);
|
||||
Assert.Equal ("~^Q~ Quit", sb.Items [^1].Title);
|
||||
|
||||
sb.Items [1] = new StatusItem (Key.CtrlMask | Key.A, "~^A~ Save As", null);
|
||||
|
||||
Assert.Equal ("~^O~ Open", sb.Items [0].Title);
|
||||
Assert.Equal ("~^A~ Save As", sb.Items [1].Title);
|
||||
Assert.Equal ("~^Q~ Quit", sb.Items [^1].Title);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1801,10 +1801,7 @@ namespace Terminal.Gui.Views {
|
||||
if (r == '\t') {
|
||||
sumLength += tabWidth + 1;
|
||||
}
|
||||
if (sumLength > width) {
|
||||
if (cCol == line.Length) {
|
||||
col++;
|
||||
}
|
||||
if (sumLength >= width) {
|
||||
break;
|
||||
} else if (cCol < line.Length && col > 0 && start < cCol && col == start) {
|
||||
break;
|
||||
@@ -1968,6 +1965,7 @@ line.
|
||||
int col = 0;
|
||||
Assert.True (TextModel.SetCol (ref col, 80, 79));
|
||||
Assert.False (TextModel.SetCol (ref col, 80, 80));
|
||||
Assert.Equal (79, col);
|
||||
|
||||
var start = 0;
|
||||
var x = 8;
|
||||
@@ -1981,9 +1979,9 @@ line.
|
||||
Assert.Equal ((15, 15), TextModel.DisplaySize (txtRunes));
|
||||
Assert.Equal ((6, 6), TextModel.DisplaySize (txtRunes, 1, 7));
|
||||
|
||||
Assert.Equal (0, TextModel.CalculateLeftColumn (txtRunes, 0, 7, 8));
|
||||
Assert.Equal (1, TextModel.CalculateLeftColumn (txtRunes, 0, 8, 8));
|
||||
Assert.Equal (2, TextModel.CalculateLeftColumn (txtRunes, 0, 9, 8));
|
||||
Assert.Equal (1, TextModel.CalculateLeftColumn (txtRunes, 0, 7, 8));
|
||||
Assert.Equal (2, TextModel.CalculateLeftColumn (txtRunes, 0, 8, 8));
|
||||
Assert.Equal (3, TextModel.CalculateLeftColumn (txtRunes, 0, 9, 8));
|
||||
|
||||
var tm = new TextModel ();
|
||||
tm.AddLine (0, TextModel.ToRunes ("This is first line."));
|
||||
@@ -2020,5 +2018,65 @@ line.
|
||||
Assert.Equal (TextModel.ToRunes ("This really first line."), tm.GetLine (0));
|
||||
Assert.Equal (TextModel.ToRunes ("This really last line."), tm.GetLine (1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[InitShutdown]
|
||||
public void BottomOffset_Sets_To_Zero_Adjust_TopRow ()
|
||||
{
|
||||
string text = "";
|
||||
|
||||
for (int i = 0; i < 12; i++) {
|
||||
text += $"This is the line {i}\n";
|
||||
}
|
||||
var tv = new TextView () { Width = 10, Height = 10, BottomOffset = 1 };
|
||||
tv.Text = text;
|
||||
|
||||
tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.End, null));
|
||||
|
||||
Assert.Equal (4, tv.TopRow);
|
||||
Assert.Equal (1, tv.BottomOffset);
|
||||
|
||||
tv.BottomOffset = 0;
|
||||
Assert.Equal (3, tv.TopRow);
|
||||
Assert.Equal (0, tv.BottomOffset);
|
||||
|
||||
tv.BottomOffset = 2;
|
||||
Assert.Equal (5, tv.TopRow);
|
||||
Assert.Equal (2, tv.BottomOffset);
|
||||
|
||||
tv.BottomOffset = 0;
|
||||
Assert.Equal (3, tv.TopRow);
|
||||
Assert.Equal (0, tv.BottomOffset);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[InitShutdown]
|
||||
public void RightOffset_Sets_To_Zero_Adjust_leftColumn ()
|
||||
{
|
||||
string text = "";
|
||||
|
||||
for (int i = 0; i < 12; i++) {
|
||||
text += $"{i.ToString () [^1]}";
|
||||
}
|
||||
var tv = new TextView () { Width = 10, Height = 10, RightOffset = 1 };
|
||||
tv.Text = text;
|
||||
|
||||
tv.ProcessKey (new KeyEvent (Key.End, null));
|
||||
|
||||
Assert.Equal (4, tv.LeftColumn);
|
||||
Assert.Equal (1, tv.RightOffset);
|
||||
|
||||
tv.RightOffset = 0;
|
||||
Assert.Equal (3, tv.LeftColumn);
|
||||
Assert.Equal (0, tv.RightOffset);
|
||||
|
||||
tv.RightOffset = 2;
|
||||
Assert.Equal (5, tv.LeftColumn);
|
||||
Assert.Equal (2, tv.RightOffset);
|
||||
|
||||
tv.RightOffset = 0;
|
||||
Assert.Equal (3, tv.LeftColumn);
|
||||
Assert.Equal (0, tv.RightOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
315
UnitTests/ToplevelTests.cs
Normal file
315
UnitTests/ToplevelTests.cs
Normal file
@@ -0,0 +1,315 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1412,5 +1412,161 @@ namespace Terminal.Gui.Views {
|
||||
view.OnLayoutComplete (null);
|
||||
Assert.False (layoutStarted);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void Enabled_False_Sets_HasFocus_To_False ()
|
||||
{
|
||||
var wasClicked = false;
|
||||
var view = new Button ("Click Me");
|
||||
view.Clicked += () => wasClicked = !wasClicked;
|
||||
Application.Top.Add (view);
|
||||
|
||||
view.ProcessKey (new KeyEvent (Key.Enter, null));
|
||||
Assert.True (wasClicked);
|
||||
view.MouseEvent (new MouseEvent () { Flags = MouseFlags.Button1Clicked });
|
||||
Assert.False (wasClicked);
|
||||
Assert.True (view.Enabled);
|
||||
Assert.True (view.CanFocus);
|
||||
Assert.True (view.HasFocus);
|
||||
|
||||
view.Enabled = false;
|
||||
view.ProcessKey (new KeyEvent (Key.Enter, null));
|
||||
Assert.False (wasClicked);
|
||||
view.MouseEvent (new MouseEvent () { Flags = MouseFlags.Button1Clicked });
|
||||
Assert.False (wasClicked);
|
||||
Assert.False (view.Enabled);
|
||||
Assert.True (view.CanFocus);
|
||||
Assert.False (view.HasFocus);
|
||||
view.SetFocus ();
|
||||
Assert.False (view.HasFocus);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void Enabled_Sets_Also_Sets_Subviews ()
|
||||
{
|
||||
var wasClicked = false;
|
||||
var button = new Button ("Click Me");
|
||||
button.Clicked += () => wasClicked = !wasClicked;
|
||||
var win = new Window () { Width = Dim.Fill (), Height = Dim.Fill () };
|
||||
win.Add (button);
|
||||
Application.Top.Add (win);
|
||||
|
||||
var iterations = 0;
|
||||
|
||||
Application.Iteration += () => {
|
||||
iterations++;
|
||||
|
||||
button.ProcessKey (new KeyEvent (Key.Enter, null));
|
||||
Assert.True (wasClicked);
|
||||
button.MouseEvent (new MouseEvent () { Flags = MouseFlags.Button1Clicked });
|
||||
Assert.False (wasClicked);
|
||||
Assert.True (button.Enabled);
|
||||
Assert.True (button.CanFocus);
|
||||
Assert.True (button.HasFocus);
|
||||
Assert.True (win.Enabled);
|
||||
Assert.True (win.CanFocus);
|
||||
Assert.True (win.HasFocus);
|
||||
|
||||
win.Enabled = false;
|
||||
button.ProcessKey (new KeyEvent (Key.Enter, null));
|
||||
Assert.False (wasClicked);
|
||||
button.MouseEvent (new MouseEvent () { Flags = MouseFlags.Button1Clicked });
|
||||
Assert.False (wasClicked);
|
||||
Assert.False (button.Enabled);
|
||||
Assert.True (button.CanFocus);
|
||||
Assert.False (button.HasFocus);
|
||||
Assert.False (win.Enabled);
|
||||
Assert.True (win.CanFocus);
|
||||
Assert.False (win.HasFocus);
|
||||
button.SetFocus ();
|
||||
Assert.False (button.HasFocus);
|
||||
Assert.False (win.HasFocus);
|
||||
win.SetFocus ();
|
||||
Assert.False (button.HasFocus);
|
||||
Assert.False (win.HasFocus);
|
||||
|
||||
win.Enabled = true;
|
||||
win.FocusFirst ();
|
||||
Assert.True (button.HasFocus);
|
||||
Assert.True (win.HasFocus);
|
||||
|
||||
Application.RequestStop ();
|
||||
};
|
||||
|
||||
Application.Run ();
|
||||
|
||||
Assert.Equal (1, iterations);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void Visible_Sets_Also_Sets_Subviews ()
|
||||
{
|
||||
var button = new Button ("Click Me");
|
||||
var win = new Window () { Width = Dim.Fill (), Height = Dim.Fill () };
|
||||
win.Add (button);
|
||||
var top = Application.Top;
|
||||
top.Add (win);
|
||||
|
||||
var iterations = 0;
|
||||
|
||||
Application.Iteration += () => {
|
||||
iterations++;
|
||||
|
||||
Assert.True (button.Visible);
|
||||
Assert.True (button.CanFocus);
|
||||
Assert.True (button.HasFocus);
|
||||
Assert.True (win.Visible);
|
||||
Assert.True (win.CanFocus);
|
||||
Assert.True (win.HasFocus);
|
||||
Assert.True (RunesCount () > 0);
|
||||
|
||||
win.Visible = false;
|
||||
Assert.True (button.Visible);
|
||||
Assert.True (button.CanFocus);
|
||||
Assert.False (button.HasFocus);
|
||||
Assert.False (win.Visible);
|
||||
Assert.True (win.CanFocus);
|
||||
Assert.False (win.HasFocus);
|
||||
button.SetFocus ();
|
||||
Assert.False (button.HasFocus);
|
||||
Assert.False (win.HasFocus);
|
||||
win.SetFocus ();
|
||||
Assert.False (button.HasFocus);
|
||||
Assert.False (win.HasFocus);
|
||||
top.Redraw (top.Bounds);
|
||||
Assert.True (RunesCount () == 0);
|
||||
|
||||
win.Visible = true;
|
||||
win.FocusFirst ();
|
||||
Assert.True (button.HasFocus);
|
||||
Assert.True (win.HasFocus);
|
||||
top.Redraw (top.Bounds);
|
||||
Assert.True (RunesCount () > 0);
|
||||
|
||||
Application.RequestStop ();
|
||||
};
|
||||
|
||||
Application.Run ();
|
||||
|
||||
Assert.Equal (1, iterations);
|
||||
|
||||
int RunesCount ()
|
||||
{
|
||||
var contents = ((FakeDriver)Application.Driver).Contents;
|
||||
var runesCount = 0;
|
||||
|
||||
for (int i = 0; i < Application.Driver.Rows; i++) {
|
||||
for (int j = 0; j < Application.Driver.Cols; j++) {
|
||||
if (contents [i, j, 0] != ' ') {
|
||||
runesCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return runesCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user