diff --git a/UnitTests/View/NavigationTests.cs b/UnitTests/View/NavigationTests.cs index a23f29359..3ae1ac500 100644 --- a/UnitTests/View/NavigationTests.cs +++ b/UnitTests/View/NavigationTests.cs @@ -620,135 +620,133 @@ public class NavigationTests (ITestOutputHelper output) top1.Dispose (); } -#if V2_STATUSBAR - [Fact] - [AutoInitShutdown] - public void HotKey_Will_Invoke_KeyPressed_Only_For_The_MostFocused_With_Top_KeyPress_Event () - { - var sbQuiting = false; - var tfQuiting = false; - var topQuiting = false; +// [Fact] +// [AutoInitShutdown] +// public void HotKey_Will_Invoke_KeyPressed_Only_For_The_MostFocused_With_Top_KeyPress_Event () +// { +// var sbQuiting = false; +// var tfQuiting = false; +// var topQuiting = false; - var sb = new StatusBar ( - new StatusItem [] - { - new ( - KeyCode.CtrlMask | KeyCode.Q, - "~^Q~ Quit", - () => sbQuiting = true - ) - } - ); - var tf = new TextField (); - tf.KeyDown += Tf_KeyPressed; +// var sb = new StatusBar ( +// new Shortcut [] +// { +// new ( +// KeyCode.CtrlMask | KeyCode.Q, +// "Quit", +// () => sbQuiting = true +// ) +// } +// ); +// var tf = new TextField (); +// tf.KeyDown += Tf_KeyPressed; - void Tf_KeyPressed (object sender, Key obj) - { - if (obj.KeyCode == (KeyCode.Q | KeyCode.CtrlMask)) - { - obj.Handled = tfQuiting = true; - } - } +// void Tf_KeyPressed (object sender, Key obj) +// { +// if (obj.KeyCode == (KeyCode.Q | KeyCode.CtrlMask)) +// { +// obj.Handled = tfQuiting = true; +// } +// } - var win = new Window (); - win.Add (sb, tf); - Toplevel top = new (); - top.KeyDown += Top_KeyPress; +// var win = new Window (); +// win.Add (sb, tf); +// Toplevel top = new (); +// top.KeyDown += Top_KeyPress; - void Top_KeyPress (object sender, Key obj) - { - if (obj.KeyCode == (KeyCode.Q | KeyCode.CtrlMask)) - { - obj.Handled = topQuiting = true; - } - } +// void Top_KeyPress (object sender, Key obj) +// { +// if (obj.KeyCode == (KeyCode.Q | KeyCode.CtrlMask)) +// { +// obj.Handled = topQuiting = true; +// } +// } - top.Add (win); - Application.Begin (top); +// top.Add (win); +// Application.Begin (top); - Assert.False (sbQuiting); - Assert.False (tfQuiting); - Assert.False (topQuiting); +// Assert.False (sbQuiting); +// Assert.False (tfQuiting); +// Assert.False (topQuiting); - Application.Driver.SendKeys ('Q', ConsoleKey.Q, false, false, true); - Assert.False (sbQuiting); - Assert.True (tfQuiting); - Assert.False (topQuiting); +// Application.Driver.SendKeys ('Q', ConsoleKey.Q, false, false, true); +// Assert.False (sbQuiting); +// Assert.True (tfQuiting); +// Assert.False (topQuiting); -#if BROKE_WITH_2927 - tf.KeyPressed -= Tf_KeyPress; - tfQuiting = false; - Application.Driver.SendKeys ('q', ConsoleKey.Q, false, false, true); - Application.MainLoop.RunIteration (); - Assert.True (sbQuiting); - Assert.False (tfQuiting); - Assert.False (topQuiting); +//#if BROKE_WITH_2927 +// tf.KeyPressed -= Tf_KeyPress; +// tfQuiting = false; +// Application.Driver.SendKeys ('q', ConsoleKey.Q, false, false, true); +// Application.MainLoop.RunIteration (); +// Assert.True (sbQuiting); +// Assert.False (tfQuiting); +// Assert.False (topQuiting); - sb.RemoveItem (0); - sbQuiting = false; - Application.Driver.SendKeys ('q', ConsoleKey.Q, false, false, true); - Application.MainLoop.RunIteration (); - Assert.False (sbQuiting); - Assert.False (tfQuiting); +// sb.RemoveItem (0); +// sbQuiting = false; +// Application.Driver.SendKeys ('q', ConsoleKey.Q, false, false, true); +// Application.MainLoop.RunIteration (); +// Assert.False (sbQuiting); +// Assert.False (tfQuiting); -// This test is now invalid because `win` is focused, so it will receive the keypress - Assert.True (topQuiting); -#endif - top.Dispose (); - } +//// This test is now invalid because `win` is focused, so it will receive the keypress +// Assert.True (topQuiting); +//#endif +// top.Dispose (); +// } - [Fact] - [AutoInitShutdown] - public void HotKey_Will_Invoke_KeyPressed_Only_For_The_MostFocused_Without_Top_KeyPress_Event () - { - var sbQuiting = false; - var tfQuiting = false; +// [Fact] +// [AutoInitShutdown] +// public void HotKey_Will_Invoke_KeyPressed_Only_For_The_MostFocused_Without_Top_KeyPress_Event () +// { +// var sbQuiting = false; +// var tfQuiting = false; - var sb = new StatusBar ( - new StatusItem [] - { - new ( - KeyCode.CtrlMask | KeyCode.Q, - "~^Q~ Quit", - () => sbQuiting = true - ) - } - ); - var tf = new TextField (); - tf.KeyDown += Tf_KeyPressed; +// var sb = new StatusBar ( +// new Shortcut [] +// { +// new ( +// KeyCode.CtrlMask | KeyCode.Q, +// "~^Q~ Quit", +// () => sbQuiting = true +// ) +// } +// ); +// var tf = new TextField (); +// tf.KeyDown += Tf_KeyPressed; - void Tf_KeyPressed (object sender, Key obj) - { - if (obj.KeyCode == (KeyCode.Q | KeyCode.CtrlMask)) - { - obj.Handled = tfQuiting = true; - } - } +// void Tf_KeyPressed (object sender, Key obj) +// { +// if (obj.KeyCode == (KeyCode.Q | KeyCode.CtrlMask)) +// { +// obj.Handled = tfQuiting = true; +// } +// } - var win = new Window (); - win.Add (sb, tf); - Toplevel top = new (); - top.Add (win); - Application.Begin (top); +// var win = new Window (); +// win.Add (sb, tf); +// Toplevel top = new (); +// top.Add (win); +// Application.Begin (top); - Assert.False (sbQuiting); - Assert.False (tfQuiting); +// Assert.False (sbQuiting); +// Assert.False (tfQuiting); - Application.Driver.SendKeys ('Q', ConsoleKey.Q, false, false, true); - Assert.False (sbQuiting); - Assert.True (tfQuiting); +// Application.Driver.SendKeys ('Q', ConsoleKey.Q, false, false, true); +// Assert.False (sbQuiting); +// Assert.True (tfQuiting); - tf.KeyDown -= Tf_KeyPressed; - tfQuiting = false; - Application.Driver.SendKeys ('Q', ConsoleKey.Q, false, false, true); - Application.MainLoop.RunIteration (); -#if BROKE_WITH_2927 - Assert.True (sbQuiting); - Assert.False (tfQuiting); -#endif - top.Dispose (); - } -#endif +// tf.KeyDown -= Tf_KeyPressed; +// tfQuiting = false; +// Application.Driver.SendKeys ('Q', ConsoleKey.Q, false, false, true); +// Application.MainLoop.RunIteration (); +//#if BROKE_WITH_2927 +// Assert.True (sbQuiting); +// Assert.False (tfQuiting); +//#endif +// top.Dispose (); +// } [Fact] [SetupFakeDriver] diff --git a/UnitTests/Views/StatusBarTests.cs b/UnitTests/Views/StatusBarTests.cs index d702dd95a..ef710c332 100644 --- a/UnitTests/Views/StatusBarTests.cs +++ b/UnitTests/Views/StatusBarTests.cs @@ -1,137 +1,97 @@ using Xunit.Abstractions; namespace Terminal.Gui.ViewsTests; -#if V2_STATUSBAR public class StatusBarTests (ITestOutputHelper output) { [Fact] public void AddItemAt_RemoveItem_Replacing () { - var sb = new StatusBar ( - new StatusItem [] - { - new (KeyCode.CtrlMask | KeyCode.Q, "~^O~ Open", null), - new (KeyCode.CtrlMask | KeyCode.Q, "~^S~ Save", null), - new (KeyCode.CtrlMask | KeyCode.Q, "~^Q~ Quit", null) - } + var sb = new StatusBar ([ + new (Key.O.WithCtrl, "Open", null), + new (Key.S.WithCtrl, "Save", null), + new (Key.Q.WithCtrl, "Quit", null) + ] ); - sb.AddShortcutAt (2, new (KeyCode.CtrlMask | KeyCode.Q, "~^C~ Close", null)); + sb.AddShortcutAt (2, new (Key.C.WithCtrl, "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 ("Open", sb.Subviews [0].Title); + Assert.Equal ("Save", sb.Subviews [1].Title); + Assert.Equal ("Close", sb.Subviews [2].Title); + Assert.Equal ("Quit", sb.Subviews [^1].Title); - Assert.Equal ("~^S~ Save", sb.RemoveItem (1).Title); + Assert.Equal ("Save", sb.RemoveShortcut (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); + Assert.Equal ("Open", sb.Subviews [0].Title); + Assert.Equal ("Close", sb.Subviews [1].Title); + Assert.Equal ("Quit", sb.Subviews [^1].Title); - sb.Items [1] = new (KeyCode.CtrlMask | KeyCode.A, "~^A~ Save As", null); + sb.AddShortcutAt (1, new Shortcut (Key.A.WithCtrl, "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); + Assert.Equal ("Open", sb.Subviews [0].Title); + Assert.Equal ("Save As", sb.Subviews [1].Title); + Assert.Equal ("Quit", sb.Subviews [^1].Title); } - [Fact] - [AutoInitShutdown] - public void CanExecute_ProcessHotKey () - { - Window win = null; + //[Fact] + //[AutoInitShutdown] + //public void CanExecute_ProcessHotKey () + //{ + // Window win = null; - var statusBar = new StatusBar ( - new StatusItem [] - { - new ( - KeyCode.CtrlMask | KeyCode.N, - "~^N~ New", - New, - CanExecuteNew - ), - new ( - KeyCode.CtrlMask | KeyCode.C, - "~^C~ Close", - Close, - CanExecuteClose - ) - } - ); - Toplevel top = new (); - top.Add (statusBar); + // var statusBar = new StatusBar ( + // new Shortcut [] + // { + // new ( + // KeyCode.CtrlMask | KeyCode.N, + // "~^N~ New", + // New, + // CanExecuteNew + // ), + // new ( + // KeyCode.CtrlMask | KeyCode.C, + // "~^C~ Close", + // Close, + // CanExecuteClose + // ) + // } + // ); + // Toplevel top = new (); + // top.Add (statusBar); - bool CanExecuteNew () { return win == null; } + // bool CanExecuteNew () { return win == null; } - void New () { win = new (); } + // void New () { win = new (); } - bool CanExecuteClose () { return win != null; } + // bool CanExecuteClose () { return win != null; } - void Close () { win = null; } + // void Close () { win = null; } - Application.Begin (top); + // Application.Begin (top); - Assert.Null (win); - Assert.True (CanExecuteNew ()); - Assert.False (CanExecuteClose ()); + // Assert.Null (win); + // Assert.True (CanExecuteNew ()); + // Assert.False (CanExecuteClose ()); - Assert.True (top.NewKeyDownEvent (Key.N.WithCtrl)); - Application.MainLoop.RunIteration (); - Assert.NotNull (win); - Assert.False (CanExecuteNew ()); - Assert.True (CanExecuteClose ()); - top.Dispose (); - } + // Assert.True (top.NewKeyDownEvent (Key.N.WithCtrl)); + // Application.MainLoop.RunIteration (); + // Assert.NotNull (win); + // Assert.False (CanExecuteNew ()); + // Assert.True (CanExecuteClose ()); + // top.Dispose (); + //} [Fact] [AutoInitShutdown] public void Redraw_Output () { - var sb = new StatusBar ( - new StatusItem [] - { - new (KeyCode.CtrlMask | KeyCode.O, "~^O~ Open", null), - new (Application.QuitKey, $"{Application.QuitKey} to Quit!", null) - } - ); - var top = new Toplevel (); - top.Add (sb); - - sb.OnDrawContent (sb.Viewport); - - var expected = @$" -^O Open { - CM.Glyphs.VLine -} Ctrl+Q to Quit! -"; - TestHelpers.AssertDriverContentsAre (expected, output); - top.Dispose (); } [Fact] [AutoInitShutdown] public void Redraw_Output_CTRLQ () { - var sb = new StatusBar ( - new StatusItem [] - { - new (KeyCode.CtrlMask | KeyCode.O, "~CTRL-O~ Open", null), - new (KeyCode.CtrlMask | KeyCode.Q, "~CTRL-Q~ Quit", null) - } - ); - var top = new Toplevel (); - top.Add (sb); - sb.OnDrawContent (sb.Viewport); - var expected = @$" -CTRL-O Open { - CM.Glyphs.VLine -} CTRL-Q Quit -"; - - TestHelpers.AssertDriverContentsAre (expected, output); - top.Dispose (); } [Fact] @@ -141,11 +101,11 @@ CTRL-O Open { var msg = ""; var sb = new StatusBar ( - new StatusItem [] + new Shortcut [] { new ( Application.QuitKey, - $"{Application.QuitKey} to Quit", + $"Quit", () => msg = "Quiting..." ) } @@ -157,13 +117,13 @@ CTRL-O Open { if (iteration == 0) { Assert.Equal ("", msg); - sb.NewKeyDownEvent (Key.Q.WithCtrl); + Application.OnKeyDown (Application.QuitKey); } else if (iteration == 1) { Assert.Equal ("Quiting...", msg); msg = ""; - sb.NewMouseEvent (new() { Position = new (1, 24), Flags = MouseFlags.Button1Clicked }); + sb.NewMouseEvent (new () { Position = new (0, 0), Flags = MouseFlags.Button1Clicked }); } else { @@ -183,26 +143,13 @@ CTRL-O Open { { var sb = new StatusBar (); - Assert.Empty (sb.Items); - Assert.False (sb.CanFocus); + Assert.Empty (sb.Subviews); + Assert.True (sb.CanFocus); Assert.Equal (Colors.ColorSchemes ["Menu"], sb.ColorScheme); Assert.Equal (0, sb.X); Assert.Equal ("AnchorEnd()", sb.Y.ToString ()); Assert.Equal (Dim.Fill (), sb.Width); - Assert.Equal (1, sb.Height); + Assert.Equal (1, sb.Frame.Height); } - [Fact] - public void StatusItem_Constructor () - { - Application.Init (); - var si = new StatusItem (Application.QuitKey, $"{Application.QuitKey} to Quit", null); - Assert.Equal (KeyCode.CtrlMask | KeyCode.Q, si.Shortcut); - Assert.Equal ($"{Application.QuitKey} to Quit", si.Title); - Assert.Null (si.Action); - si = new (Application.QuitKey, $"{Application.QuitKey} to Quit", () => { }); - Assert.NotNull (si.Action); - Application.Shutdown (); - } } -#endif diff --git a/UnitTests/Views/WindowTests.cs b/UnitTests/Views/WindowTests.cs index 26956ff42..24ea77876 100644 --- a/UnitTests/Views/WindowTests.cs +++ b/UnitTests/Views/WindowTests.cs @@ -29,7 +29,6 @@ public class WindowTests top.Dispose (); } -#if V2_STATUSBAR [Fact] [AutoInitShutdown] public void MenuBar_And_StatusBar_Inside_Window () @@ -46,14 +45,7 @@ public class WindowTests ] }; - var sb = new StatusBar ( - new StatusItem [] - { - new ((KeyCode)Key.Q.WithCtrl, "~^Q~ Quit", null), - new ((KeyCode)Key.O.WithCtrl, "~^O~ Open", null), - new ((KeyCode)Key.C.WithCtrl, "~^C~ Copy", null) - } - ); + var sb = new StatusBar (); var fv = new FrameView { Y = 1, Width = Dim.Fill (), Height = Dim.Fill (1), Title = "Frame View" }; var win = new Window (); @@ -73,7 +65,7 @@ public class WindowTests ││ ││ ││ ││ │└────────────────┘│ -│ ^Q Quit │ ^O Open│ +│ │ └──────────────────┘", _output ); @@ -100,7 +92,7 @@ public class WindowTests ││ ││ ││ ││ │└────────────────────────────────────┘│ -│ ^Q Quit │ ^O Open │ ^C Copy │ +│ │ └──────────────────────────────────────┘", _output ); @@ -117,13 +109,12 @@ public class WindowTests ││ ││ ││ ││ │└────────────────┘│ -│ ^Q Quit │ ^O Open│ +│ │ └──────────────────┘", _output ); top.Dispose (); } -#endif [Fact] public void New_Initializes ()