From b2049d8991d6d2704d3aae65e01dd7c50c4f92cb Mon Sep 17 00:00:00 2001 From: Tig Date: Tue, 8 Oct 2024 00:49:51 -0400 Subject: [PATCH] Fixed Dialog & Messagebox --- Terminal.Gui/View/View.Command.cs | 4 +-- Terminal.Gui/Views/Button.cs | 3 ++- Terminal.Gui/Views/ComboBox.cs | 6 ++--- Terminal.Gui/Views/ListView.cs | 4 +-- Terminal.Gui/Views/Menu/MenuBar.cs | 4 +-- Terminal.Gui/Views/MessageBox.cs | 36 +++++++++++++------------ Terminal.Gui/Views/RadioGroup.cs | 2 +- Terminal.Gui/Views/Shortcut.cs | 2 +- Terminal.Gui/Views/Slider.cs | 6 ++--- Terminal.Gui/Views/TextView.cs | 6 ++--- Terminal.Gui/Views/TreeView/TreeView.cs | 4 +-- UICatalog/Scenarios/Dialogs.cs | 1 + 12 files changed, 41 insertions(+), 37 deletions(-) diff --git a/Terminal.Gui/View/View.Command.cs b/Terminal.Gui/View/View.Command.cs index a75f368cd..7ec42a747 100644 --- a/Terminal.Gui/View/View.Command.cs +++ b/Terminal.Gui/View/View.Command.cs @@ -68,9 +68,9 @@ public partial class View // Command APIs /// If the event was canceled. If the event was raised but not canceled. /// If no event was raised. /// - protected bool? RaiseAccepting () + protected bool? RaiseAccepting (CommandContext ctx) { - CommandEventArgs args = new (); + CommandEventArgs args = new () { Context = ctx }; // Best practice is to invoke the virtual method first. // This allows derived classes to handle the event and potentially cancel it. diff --git a/Terminal.Gui/Views/Button.cs b/Terminal.Gui/Views/Button.cs index c10e29545..e29043ed9 100644 --- a/Terminal.Gui/Views/Button.cs +++ b/Terminal.Gui/Views/Button.cs @@ -79,7 +79,7 @@ public class Button : View, IDesignable return true; } - bool? handled = RaiseAccepting (); + bool? handled = RaiseAccepting (ctx); if (handled == true) { @@ -132,6 +132,7 @@ public class Button : View, IDesignable return; } + // TODO: With https://github.com/gui-cs/Terminal.Gui/issues/3778 we won't have to pass data: e.Handled = InvokeCommand (Command.HotKey, new (Command.HotKey, null, data: this)) == true; } diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index 746dc7d98..3f92174c8 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -84,7 +84,7 @@ public class ComboBox : View, IDesignable { return null; } - return ActivateSelected (); + return ActivateSelected (ctx); }); AddCommand (Command.Toggle, () => ExpandCollapse ()); AddCommand (Command.Expand, () => Expand ()); @@ -392,7 +392,7 @@ public class ComboBox : View, IDesignable } } - private bool ActivateSelected () + private bool ActivateSelected (CommandContext ctx) { if (HasItems ()) { @@ -401,7 +401,7 @@ public class ComboBox : View, IDesignable return false; } - return RaiseAccepting () == true; + return RaiseAccepting (ctx) == true; } return false; diff --git a/Terminal.Gui/Views/ListView.cs b/Terminal.Gui/Views/ListView.cs index 382fdbf87..0c54aa261 100644 --- a/Terminal.Gui/Views/ListView.cs +++ b/Terminal.Gui/Views/ListView.cs @@ -138,9 +138,9 @@ public class ListView : View, IDesignable AddCommand (Command.ScrollRight, () => ScrollHorizontal (1)); // Accept (Enter key) - Raise Accept event - DO NOT advance state - AddCommand (Command.Accept, () => + AddCommand (Command.Accept, (ctx) => { - if (RaiseAccepting () == true) + if (RaiseAccepting (ctx) == true) { return true; } diff --git a/Terminal.Gui/Views/Menu/MenuBar.cs b/Terminal.Gui/Views/Menu/MenuBar.cs index 957e568cf..731edc11c 100644 --- a/Terminal.Gui/Views/Menu/MenuBar.cs +++ b/Terminal.Gui/Views/Menu/MenuBar.cs @@ -119,14 +119,14 @@ public class MenuBar : View, IDesignable AddCommand ( Command.Accept, - () => + (ctx) => { if (Menus.Length > 0) { ProcessMenu (_selected, Menus [_selected]); } - return RaiseAccepting (); + return RaiseAccepting (ctx); } ); AddCommand (Command.Toggle, ctx => diff --git a/Terminal.Gui/Views/MessageBox.cs b/Terminal.Gui/Views/MessageBox.cs index af35b257e..76da412b1 100644 --- a/Terminal.Gui/Views/MessageBox.cs +++ b/Terminal.Gui/Views/MessageBox.cs @@ -338,6 +338,7 @@ public static class MessageBox // Create button array for Dialog var count = 0; List