From dc4ce1e418b9e059e7b3bacc97c15039eda9ef4c Mon Sep 17 00:00:00 2001 From: Tig Date: Tue, 8 Oct 2024 01:03:23 -0400 Subject: [PATCH] Fixed Dialogs --- Terminal.Gui/Application/Application.Mouse.cs | 2 +- Terminal.Gui/View/View.Command.cs | 14 ++++++-------- Terminal.Gui/Views/MessageBox.cs | 2 +- UICatalog/Scenarios/Dialogs.cs | 13 ++++++++----- UICatalog/Scenarios/MessageBoxes.cs | 2 +- UICatalog/UICatalog.cs | 2 +- UnitTests/Application/ApplicationTests.cs | 2 +- UnitTests/Dialogs/MessageBoxTests.cs | 8 ++++---- UnitTests/TestHelpers.cs | 2 -- 9 files changed, 23 insertions(+), 24 deletions(-) diff --git a/Terminal.Gui/Application/Application.Mouse.cs b/Terminal.Gui/Application/Application.Mouse.cs index 9c7bc0881..d18cd48b5 100644 --- a/Terminal.Gui/Application/Application.Mouse.cs +++ b/Terminal.Gui/Application/Application.Mouse.cs @@ -6,7 +6,7 @@ namespace Terminal.Gui; public static partial class Application // Mouse handling { - internal static Point? _lastMousePosition = null; + internal static Point? _lastMousePosition; /// /// Gets the most recent position of the mouse. diff --git a/Terminal.Gui/View/View.Command.cs b/Terminal.Gui/View/View.Command.cs index 7ec42a747..1c6d7d6b1 100644 --- a/Terminal.Gui/View/View.Command.cs +++ b/Terminal.Gui/View/View.Command.cs @@ -106,7 +106,7 @@ public partial class View // Command APIs } /// - /// Called when the user is accepting the state of the View and the has been invoked. Set to + /// Called when the user is accepting the state of the View and the has been invoked. Set CommandEventArgs.Cancel to /// and return to stop processing. /// /// @@ -120,7 +120,7 @@ public partial class View // Command APIs /// /// Cancelable event raised when the user is accepting the state of the View and the has been invoked. Set - /// to cancel the event. + /// CommandEventArgs.Cancel to cancel the event. /// /// /// @@ -159,7 +159,7 @@ public partial class View // Command APIs /// /// Called when the user has performed an action (e.g. ) causing the View to change state. - /// Set to + /// Set CommandEventArgs.Cancel to /// and return to cancel the state change. The default implementation does nothing. /// /// The event arguments. @@ -168,8 +168,7 @@ public partial class View // Command APIs /// /// Cancelable event raised when the user has performed an action (e.g. ) causing the View to change state. - /// Set to - /// to cancel the state change. + /// CommandEventArgs.Cancel to to cancel the state change. /// public event EventHandler? Selecting; @@ -199,7 +198,7 @@ public partial class View // Command APIs } /// - /// Called when the View is handling the user pressing the View's . Set to + /// Called when the View is handling the user pressing the View's . Set CommandEventArgs.Cancel to /// to stop processing. /// /// @@ -208,8 +207,7 @@ public partial class View // Command APIs /// /// Cancelable event raised when the View is handling the user pressing the View's . Set - /// - /// to cancel the event. + /// CommandEventArgs.Cancel to cancel the event. /// public event EventHandler? HandlingHotKey; diff --git a/Terminal.Gui/Views/MessageBox.cs b/Terminal.Gui/Views/MessageBox.cs index 76da412b1..f36e41ace 100644 --- a/Terminal.Gui/Views/MessageBox.cs +++ b/Terminal.Gui/Views/MessageBox.cs @@ -351,7 +351,7 @@ public static class MessageBox { var b = new Button { - Text = $"_{s}", + Text = s, Data = count, }; diff --git a/UICatalog/Scenarios/Dialogs.cs b/UICatalog/Scenarios/Dialogs.cs index f16ae6410..9a4156a39 100644 --- a/UICatalog/Scenarios/Dialogs.cs +++ b/UICatalog/Scenarios/Dialogs.cs @@ -246,13 +246,13 @@ public class Dialogs : Scenario button = new () { - Text = NumberToWords.Convert (buttonId) + " " + char.ConvertFromUtf32 (buttonId + CODE_POINT), + Text = "_" + NumberToWords.Convert (buttonId) + " " + char.ConvertFromUtf32 (buttonId + CODE_POINT), IsDefault = buttonId == 0 }; } else { - button = new () { Text = NumberToWords.Convert (buttonId), IsDefault = buttonId == 0 }; + button = new () { Text = "_" + NumberToWords.Convert (buttonId), IsDefault = buttonId == 0 }; } button.Accepting += (s, e) => @@ -270,7 +270,7 @@ public class Dialogs : Scenario { Title = titleEdit.Text, Text = "Dialog Text", - ButtonAlignment = (Alignment)Enum.Parse (typeof (Alignment), alignmentRadioGroup.RadioLabels [alignmentRadioGroup.SelectedItem].Substring(1)), + ButtonAlignment = (Alignment)Enum.Parse (typeof (Alignment), alignmentRadioGroup.RadioLabels [alignmentRadioGroup.SelectedItem].Substring (1)), Buttons = buttons.ToArray () }; @@ -300,19 +300,20 @@ public class Dialogs : Scenario { button = new () { - Text = NumberToWords.Convert (buttonId) + " " + char.ConvertFromUtf32 (buttonId + CODE_POINT), + Text = "_" + NumberToWords.Convert (buttonId) + " " + char.ConvertFromUtf32 (buttonId + CODE_POINT), IsDefault = buttonId == 0 }; } else { - button = new () { Text = NumberToWords.Convert (buttonId), IsDefault = buttonId == 0 }; + button = new () { Text = "_" + NumberToWords.Convert (buttonId), IsDefault = buttonId == 0 }; } button.Accepting += (s, e) => { clicked = buttonId; Application.RequestStop (); + e.Cancel = true; }; buttons.Add (button); dialog.AddButton (button); @@ -321,6 +322,7 @@ public class Dialogs : Scenario //{ // button.TabIndex = buttons [buttons.Count - 2].TabIndex + 1; //} + e.Cancel = true; }; dialog.Add (add); @@ -339,6 +341,7 @@ public class Dialogs : Scenario } dialog.LayoutSubviews (); + e.Cancel = true; }; dialog.Add (addChar); diff --git a/UICatalog/Scenarios/MessageBoxes.cs b/UICatalog/Scenarios/MessageBoxes.cs index 833e98640..db9779482 100644 --- a/UICatalog/Scenarios/MessageBoxes.cs +++ b/UICatalog/Scenarios/MessageBoxes.cs @@ -241,7 +241,7 @@ public class MessageBoxes : Scenario for (var i = 0; i < numButtons; i++) { - btns.Add (NumberToWords.Convert (i)); + btns.Add ($"_{NumberToWords.Convert (i)}"); } if (styleRadioGroup.SelectedItem == 0) diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index 3c4daf4bc..049f365b7 100644 --- a/UICatalog/UICatalog.cs +++ b/UICatalog/UICatalog.cs @@ -695,7 +695,7 @@ public class UICatalogApp MenuBar!.Menus [0].Children! [0]!.ShortcutKey = Application.QuitKey; - ((Shortcut)_statusBar.Subviews [0]).Key = Application.QuitKey; + ((Shortcut)_statusBar!.Subviews [0]).Key = Application.QuitKey; _statusBar.Visible = ShowStatusBar; MiIsMouseDisabled!.Checked = Application.IsMouseDisabled; diff --git a/UnitTests/Application/ApplicationTests.cs b/UnitTests/Application/ApplicationTests.cs index b23703299..81209dddb 100644 --- a/UnitTests/Application/ApplicationTests.cs +++ b/UnitTests/Application/ApplicationTests.cs @@ -319,7 +319,7 @@ public class ApplicationTests Assert.Empty (Application.GetViewKeyBindings ()); // Mouse - Assert.Equal (null, Application._lastMousePosition); + Assert.Null (Application._lastMousePosition); // Navigation Assert.Null (Application.Navigation); diff --git a/UnitTests/Dialogs/MessageBoxTests.cs b/UnitTests/Dialogs/MessageBoxTests.cs index 65a97951c..541ecd9e4 100644 --- a/UnitTests/Dialogs/MessageBoxTests.cs +++ b/UnitTests/Dialogs/MessageBoxTests.cs @@ -52,8 +52,8 @@ public class MessageBoxTests }; Application.Run ().Dispose (); - Assert.Equal (0, result); - Assert.Equal (btnAcceptCount, 1); + Assert.Equal (1, result); + Assert.Equal (1, btnAcceptCount); } [Fact] @@ -134,8 +134,8 @@ public class MessageBoxTests }; Application.Run ().Dispose (); - Assert.Equal (0, result); - Assert.Equal (btnAcceptCount, 1); + Assert.Equal (1, result); + Assert.Equal (1, btnAcceptCount); } diff --git a/UnitTests/TestHelpers.cs b/UnitTests/TestHelpers.cs index 74d915d06..acc367e9a 100644 --- a/UnitTests/TestHelpers.cs +++ b/UnitTests/TestHelpers.cs @@ -140,8 +140,6 @@ public class AutoInitShutdownAttribute : BeforeAfterTestAttribute } private bool AutoInit { get; } - - private List _savedValues; } ///