From 2a989df553ecad83b908d144db79a62f89f649ee Mon Sep 17 00:00:00 2001 From: Tig Date: Mon, 7 Oct 2024 07:38:11 -0400 Subject: [PATCH] Selected->Selecting --- Terminal.Gui/Input/Command.cs | 2 +- Terminal.Gui/View/View.Command.cs | 34 ++++++++++---------- Terminal.Gui/Views/Button.cs | 2 +- Terminal.Gui/Views/CheckBox.cs | 2 +- Terminal.Gui/Views/ListView.cs | 4 +-- Terminal.Gui/Views/RadioGroup.cs | 6 ++-- Terminal.Gui/Views/Shortcut.cs | 6 ++-- Terminal.Gui/Views/TableView/TableView.cs | 2 +- UICatalog/Scenarios/ListViewWithSelection.cs | 2 +- UICatalog/Scenarios/Shortcuts.cs | 4 +-- UnitTests/View/HotKeyTests.cs | 2 +- UnitTests/View/Mouse/MouseTests.cs | 4 +-- UnitTests/View/ViewCommandTests.cs | 8 ++--- UnitTests/Views/AllViewsTests.cs | 6 ++-- UnitTests/Views/ButtonTests.cs | 4 +-- UnitTests/Views/CheckBoxTests.cs | 8 ++--- UnitTests/Views/RadioGroupTests.cs | 10 +++--- UnitTests/Views/ShortcutTests.cs | 12 +++---- UnitTests/Views/TextFieldTests.cs | 4 +-- 19 files changed, 61 insertions(+), 61 deletions(-) diff --git a/Terminal.Gui/Input/Command.cs b/Terminal.Gui/Input/Command.cs index 7201298aa..8b169c718 100644 --- a/Terminal.Gui/Input/Command.cs +++ b/Terminal.Gui/Input/Command.cs @@ -34,7 +34,7 @@ public enum Command /// /// Selects the View or an item in the View (e.g. a list item or menu item) without necessarily accepting it. /// - /// The default implementation in calls . + /// The default implementation in calls . /// /// Select, diff --git a/Terminal.Gui/View/View.Command.cs b/Terminal.Gui/View/View.Command.cs index d56126d49..ea82100f8 100644 --- a/Terminal.Gui/View/View.Command.cs +++ b/Terminal.Gui/View/View.Command.cs @@ -32,7 +32,7 @@ public partial class View // Command APIs // Space or single-click - Raise Selected AddCommand (Command.Select, (ctx) => { - if (RaiseSelected (ctx) is true) + if (RaiseSelecting (ctx) is true) { return true; } @@ -53,7 +53,7 @@ public partial class View // Command APIs /// event. The default handler calls this method. /// /// - /// The event should raised after the state of the View has changed (after is raised). + /// The event should raised after the state of the View has changed (after is raised). /// /// /// If the event was canceled. If the event was raised but not canceled. @@ -112,48 +112,48 @@ public partial class View // Command APIs public event EventHandler? Accepted; /// - /// Called when the user has selected the View or otherwise changed the state of the View. Calls which can be cancelled; if not cancelled raises . + /// Called when the user has performed an action (e.g. ) causing the View to change state. Calls which can be cancelled; if not cancelled raises . /// event. The default handler calls this method. /// /// - /// The event should raised after the state of the View has been changed and before see . + /// The event should raised after the state of the View has been changed and before see . /// /// /// If the event was canceled. If the event was raised but not canceled. /// If no event was raised. /// - protected bool? RaiseSelected (CommandContext ctx) + protected bool? RaiseSelecting (CommandContext ctx) { 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. - if (OnSelected (args) || args.Cancel) + if (OnSelecting (args) || args.Cancel) { return true; } // If the event is not canceled by the virtual method, raise the event to notify any external subscribers. - Selected?.Invoke (this, args); + Selecting?.Invoke (this, args); - return Selected is null ? null : args.Cancel; + return Selecting is null ? null : args.Cancel; } /// - /// Called when the user has selected the View or otherwise changed the state of the View. Set to - /// to stop processing. + /// Called when the user has performed an action (e.g. ) causing the View to change state. + /// Set to + /// and return to cancel the state change. The default implementation does nothing. /// - /// + /// The event arguments. /// to stop processing. - protected virtual bool OnSelected (CommandEventArgs args) { return false; } + protected virtual bool OnSelecting (CommandEventArgs args) { return false; } /// - /// Cancelable event raised when the user has selected the View or otherwise changed the state of the View. Set - /// - /// to cancel the event. + /// 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. /// - public event EventHandler? Selected; - + public event EventHandler? Selecting; // TODO: What does this event really do? "Called when the user has pressed the View's hot key or otherwise invoked the View's hot key command.???" /// diff --git a/Terminal.Gui/Views/Button.cs b/Terminal.Gui/Views/Button.cs index 394157da4..59e75be1e 100644 --- a/Terminal.Gui/Views/Button.cs +++ b/Terminal.Gui/Views/Button.cs @@ -85,7 +85,7 @@ public class Button : View, IDesignable { bool cachedIsDefault = IsDefault; // Supports "Swap Default" in Buttons scenario where IsDefault changes - if (RaiseSelected (ctx) is true) + if (RaiseSelecting (ctx) is true) { return true; } diff --git a/Terminal.Gui/Views/CheckBox.cs b/Terminal.Gui/Views/CheckBox.cs index 28ada24cc..843b94d60 100644 --- a/Terminal.Gui/Views/CheckBox.cs +++ b/Terminal.Gui/Views/CheckBox.cs @@ -43,7 +43,7 @@ public class CheckBox : View return true; } - if (RaiseSelected (ctx) is true) + if (RaiseSelecting (ctx) is true) { return true; } diff --git a/Terminal.Gui/Views/ListView.cs b/Terminal.Gui/Views/ListView.cs index b5ebdd0d0..ad9d35b8f 100644 --- a/Terminal.Gui/Views/ListView.cs +++ b/Terminal.Gui/Views/ListView.cs @@ -158,7 +158,7 @@ public class ListView : View, IDesignable { if (_allowsMarking) { - if (RaiseSelected (ctx) == true) + if (RaiseSelecting (ctx) == true) { return true; } @@ -179,7 +179,7 @@ public class ListView : View, IDesignable if (SelectedItem == -1) { SelectedItem = 0; - if (RaiseSelected (ctx) == true) + if (RaiseSelecting (ctx) == true) { return true; diff --git a/Terminal.Gui/Views/RadioGroup.cs b/Terminal.Gui/Views/RadioGroup.cs index f5c6d4d1a..121a4024a 100644 --- a/Terminal.Gui/Views/RadioGroup.cs +++ b/Terminal.Gui/Views/RadioGroup.cs @@ -40,7 +40,7 @@ public class RadioGroup : View, IDesignable, IOrientation if (cursorChanged || selectedItemChanged) { - if (RaiseSelected (ctx) == true) + if (RaiseSelecting (ctx) == true) { return true; } @@ -83,7 +83,7 @@ public class RadioGroup : View, IDesignable, IOrientation if (selectedItemChanged) { // Doesn't matter if it's handled - RaiseSelected (ctx); + RaiseSelecting (ctx); return true; } @@ -93,7 +93,7 @@ public class RadioGroup : View, IDesignable, IOrientation if (SelectedItem == -1 && ChangeSelectedItem (0)) { - if (RaiseSelected (ctx) == true) + if (RaiseSelecting (ctx) == true) { return true; } diff --git a/Terminal.Gui/Views/Shortcut.cs b/Terminal.Gui/Views/Shortcut.cs index f2ebc3928..5299456d4 100644 --- a/Terminal.Gui/Views/Shortcut.cs +++ b/Terminal.Gui/Views/Shortcut.cs @@ -334,7 +334,7 @@ public class Shortcut : View, IOrientation, IDesignable CommandView.InvokeCommand (Command.Select, ctx); } - if (RaiseSelected (ctx) is true) + if (RaiseSelecting (ctx) is true) { return true; } @@ -477,7 +477,7 @@ public class Shortcut : View, IOrientation, IDesignable } // Clean up old - _commandView.Selected -= CommandViewOnSelected; + _commandView.Selecting -= CommandViewOnSelected; _commandView.Accepted -= CommandViewOnAccepted; Remove (_commandView); _commandView?.Dispose (); @@ -503,7 +503,7 @@ public class Shortcut : View, IOrientation, IDesignable Title = _commandView.Text; - _commandView.Selected += CommandViewOnSelected; + _commandView.Selecting += CommandViewOnSelected; _commandView.Accepted += CommandViewOnAccepted; diff --git a/Terminal.Gui/Views/TableView/TableView.cs b/Terminal.Gui/Views/TableView/TableView.cs index baeb79c64..1717b35d6 100644 --- a/Terminal.Gui/Views/TableView/TableView.cs +++ b/Terminal.Gui/Views/TableView/TableView.cs @@ -246,7 +246,7 @@ public class TableView : View { if (ToggleCurrentCellSelection () is true) { - return RaiseSelected (ctx) is true; + return RaiseSelecting (ctx) is true; } return false; diff --git a/UICatalog/Scenarios/ListViewWithSelection.cs b/UICatalog/Scenarios/ListViewWithSelection.cs index da6125a4d..cb20a2a98 100644 --- a/UICatalog/Scenarios/ListViewWithSelection.cs +++ b/UICatalog/Scenarios/ListViewWithSelection.cs @@ -140,7 +140,7 @@ public class ListViewWithSelection : Scenario _listView.OpenSelectedItem += (s, a) => LogEvent (s as View, a, "OpenSelectedItem"); _listView.CollectionChanged += (s, a) => LogEvent (s as View, a, "CollectionChanged"); _listView.Accepted += (s, a) => LogEvent (s as View, a, "Accept"); - _listView.Selected += (s, a) => LogEvent (s as View, a, "Select"); + _listView.Selecting += (s, a) => LogEvent (s as View, a, "Select"); bool? LogEvent (View sender, EventArgs args, string message) { diff --git a/UICatalog/Scenarios/Shortcuts.cs b/UICatalog/Scenarios/Shortcuts.cs index e5a30ecbe..30fb0659e 100644 --- a/UICatalog/Scenarios/Shortcuts.cs +++ b/UICatalog/Scenarios/Shortcuts.cs @@ -359,7 +359,7 @@ public class Shortcuts : Scenario { if (sh is Shortcut shortcut) { - shortcut.Selected += (o, args) => + shortcut.Selecting += (o, args) => { if (args.Cancel) { @@ -369,7 +369,7 @@ public class Shortcuts : Scenario eventLog.MoveDown (); }; - shortcut.CommandView.Selected += (o, args) => + shortcut.CommandView.Selecting += (o, args) => { if (args.Cancel) { diff --git a/UnitTests/View/HotKeyTests.cs b/UnitTests/View/HotKeyTests.cs index 23015c7bb..3335276d4 100644 --- a/UnitTests/View/HotKeyTests.cs +++ b/UnitTests/View/HotKeyTests.cs @@ -359,7 +359,7 @@ public class HotKeyTests Application.Top.Add (view); view.HotKeyHandled += (s, e) => hotKeyRaised = true; view.Accepted += (s, e) => acceptRaised = true; - view.Selected += (s, e) => selectRaised = true; + view.Selecting += (s, e) => selectRaised = true; Assert.Equal (KeyCode.T, view.HotKey); Assert.True (Application.OnKeyDown (Key.T)); diff --git a/UnitTests/View/Mouse/MouseTests.cs b/UnitTests/View/Mouse/MouseTests.cs index 7ce54ed4d..bee3e3bc2 100644 --- a/UnitTests/View/Mouse/MouseTests.cs +++ b/UnitTests/View/Mouse/MouseTests.cs @@ -57,7 +57,7 @@ public class MouseTests (ITestOutputHelper output) : TestsAllViews } int selectedCount = 0; - testView.Selected += (sender, args) => selectedCount++; + testView.Selecting += (sender, args) => selectedCount++; testView.NewMouseEvent (new () { Position = new (0, 0), Flags = MouseFlags.Button1Clicked }); Assert.True (superView.HasFocus); @@ -280,7 +280,7 @@ public class MouseTests (ITestOutputHelper output) : TestsAllViews var selectedCount = 0; - view.Selected += (s, e) => selectedCount++; + view.Selecting += (s, e) => selectedCount++; me.Flags = clicked; view.NewMouseEvent (me); diff --git a/UnitTests/View/ViewCommandTests.cs b/UnitTests/View/ViewCommandTests.cs index b89655665..774709d2d 100644 --- a/UnitTests/View/ViewCommandTests.cs +++ b/UnitTests/View/ViewCommandTests.cs @@ -172,7 +172,7 @@ public class ViewCommandTests (ITestOutputHelper output) var view = new View (); var SelectedInvoked = false; - view.Selected += ViewOnSelect; + view.Selecting += ViewOnSelect; bool? ret = view.InvokeCommand (Command.Select); Assert.True (ret); @@ -193,7 +193,7 @@ public class ViewCommandTests (ITestOutputHelper output) var view = new View (); var selected = false; - view.Selected += ViewOnSelected; + view.Selecting += ViewOnSelected; view.InvokeCommand (Command.Select); Assert.True (selected); @@ -248,7 +248,7 @@ public class ViewCommandTests (ITestOutputHelper output) }; - Selected += (s, a) => + Selecting += (s, a) => { a.Cancel = HandleSelected; SelectedCount++; @@ -289,7 +289,7 @@ public class ViewCommandTests (ITestOutputHelper output) public bool HandleOnSelected { get; set; } /// - protected override bool OnSelected (CommandEventArgs args) + protected override bool OnSelecting (CommandEventArgs args) { OnSelectedCount++; diff --git a/UnitTests/Views/AllViewsTests.cs b/UnitTests/Views/AllViewsTests.cs index 4bbb62e61..eb3970a8a 100644 --- a/UnitTests/Views/AllViewsTests.cs +++ b/UnitTests/Views/AllViewsTests.cs @@ -114,7 +114,7 @@ public class AllViewsTests (ITestOutputHelper output) : TestsAllViews } var selectedCount = 0; - view.Selected += (s, e) => selectedCount++; + view.Selecting += (s, e) => selectedCount++; var acceptedCount = 0; view.Accepted += (s, e) => @@ -149,7 +149,7 @@ public class AllViewsTests (ITestOutputHelper output) : TestsAllViews } var selectedCount = 0; - view.Selected += (s, e) => selectedCount++; + view.Selecting += (s, e) => selectedCount++; var acceptedCount = 0; view.Accepted += (s, e) => @@ -189,7 +189,7 @@ public class AllViewsTests (ITestOutputHelper output) : TestsAllViews } var selectedCount = 0; - view.Selected += (s, e) => selectedCount++; + view.Selecting += (s, e) => selectedCount++; var acceptedCount = 0; view.Accepted += (s, e) => diff --git a/UnitTests/Views/ButtonTests.cs b/UnitTests/Views/ButtonTests.cs index 62b5a6293..052b385bd 100644 --- a/UnitTests/Views/ButtonTests.cs +++ b/UnitTests/Views/ButtonTests.cs @@ -610,7 +610,7 @@ public class ButtonTests (ITestOutputHelper output) var selectedCount = 0; - button.Selected += (s, e) => selectedCount++; + button.Selecting += (s, e) => selectedCount++; var acceptedCount = 0; button.Accepted += (s, e) => { @@ -665,7 +665,7 @@ public class ButtonTests (ITestOutputHelper output) var selectedCount = 0; - button.Selected += (s, e) => + button.Selecting += (s, e) => { selectedCount++; e.Cancel = true; diff --git a/UnitTests/Views/CheckBoxTests.cs b/UnitTests/Views/CheckBoxTests.cs index 5b2d5a720..d009aac97 100644 --- a/UnitTests/Views/CheckBoxTests.cs +++ b/UnitTests/Views/CheckBoxTests.cs @@ -181,7 +181,7 @@ public class CheckBoxTests (ITestOutputHelper output) ckb.CheckedStateChanging += (s, e) => checkedStateChangingCount++; int selectCount = 0; - ckb.Selected += (s, e) => selectCount++; + ckb.Selecting += (s, e) => selectCount++; int acceptCount = 0; ckb.Accepted += (s, e) => acceptCount++; @@ -256,7 +256,7 @@ public class CheckBoxTests (ITestOutputHelper output) checkBox.CheckedStateChanging += (s, e) => checkedStateChangingCount++; int selectCount = 0; - checkBox.Selected += (s, e) => selectCount++; + checkBox.Selecting += (s, e) => selectCount++; int acceptCount = 0; checkBox.Accepted += (s, e) => acceptCount++; @@ -300,7 +300,7 @@ public class CheckBoxTests (ITestOutputHelper output) checkBox.CheckedStateChanging += (s, e) => checkedStateChangingCount++; int selectCount = 0; - checkBox.Selected += (s, e) => selectCount++; + checkBox.Selecting += (s, e) => selectCount++; int acceptCount = 0; checkBox.Accepted += (s, e) => acceptCount++; @@ -566,7 +566,7 @@ public class CheckBoxTests (ITestOutputHelper output) ckb.CheckedState = initialState; - ckb.Selected += OnSelected; + ckb.Selecting += OnSelected; Assert.Equal (initialState, ckb.CheckedState); bool? ret = ckb.InvokeCommand (Command.Select); diff --git a/UnitTests/Views/RadioGroupTests.cs b/UnitTests/Views/RadioGroupTests.cs index bbf4aaa1a..b7342c9e6 100644 --- a/UnitTests/Views/RadioGroupTests.cs +++ b/UnitTests/Views/RadioGroupTests.cs @@ -91,7 +91,7 @@ public class RadioGroupTests (ITestOutputHelper output) rg.SelectedItemChanged += (s, e) => selectedItemChangedCount++; var selectedCount = 0; - rg.Selected += (s, e) => selectedCount++; + rg.Selecting += (s, e) => selectedCount++; var acceptedCount = 0; rg.Accepted += (s, e) => acceptedCount++; @@ -220,7 +220,7 @@ public class RadioGroupTests (ITestOutputHelper output) rg.SelectedItemChanged += (s, e) => selectedItemChangedCount++; var selectCount = 0; - rg.Selected += (s, e) => selectCount++; + rg.Selecting += (s, e) => selectCount++; var acceptCount = 0; rg.Accepted += (s, e) => acceptCount++; @@ -297,7 +297,7 @@ public class RadioGroupTests (ITestOutputHelper output) rg.SelectedItemChanged += (s, e) => selectedItemChangedCount++; var selectCount = 0; - rg.Selected += (s, e) => selectCount++; + rg.Selecting += (s, e) => selectCount++; var acceptCount = 0; rg.Accepted += (s, e) => acceptCount++; @@ -626,7 +626,7 @@ public class RadioGroupTests (ITestOutputHelper output) radioGroup.SelectedItemChanged += (s, e) => selectedItemChanged++; var selectedCount = 0; - radioGroup.Selected += (s, e) => selectedCount++; + radioGroup.Selecting += (s, e) => selectedCount++; var acceptedCount = 0; radioGroup.Accepted += (s, e) => acceptedCount++; @@ -676,7 +676,7 @@ public class RadioGroupTests (ITestOutputHelper output) radioGroup.SelectedItemChanged += (s, e) => selectedItemChanged++; var selectedCount = 0; - radioGroup.Selected += (s, e) => selectedCount++; + radioGroup.Selecting += (s, e) => selectedCount++; var acceptedCount = 0; var handleAccepted = false; diff --git a/UnitTests/Views/ShortcutTests.cs b/UnitTests/Views/ShortcutTests.cs index 5ac9c8b88..a7037cd3c 100644 --- a/UnitTests/Views/ShortcutTests.cs +++ b/UnitTests/Views/ShortcutTests.cs @@ -473,12 +473,12 @@ public class ShortcutTests var commandViewAcceptCount = 0; shortcut.CommandView.Accepted += (s, e) => { commandViewAcceptCount++; }; var commandViewSelectCount = 0; - shortcut.CommandView.Selected += (s, e) => { commandViewSelectCount++; }; + shortcut.CommandView.Selecting += (s, e) => { commandViewSelectCount++; }; var shortcutAcceptCount = 0; shortcut.Accepted += (s, e) => { shortcutAcceptCount++; }; var shortcutSelectCount = 0; - shortcut.Selected += (s, e) => { shortcutSelectCount++; }; + shortcut.Selecting += (s, e) => { shortcutSelectCount++; }; Application.Top.Add (shortcut); Application.Top.SetRelativeLayout (new (100, 100)); @@ -590,7 +590,7 @@ public class ShortcutTests shortcut.CommandView.Accepted += (s, e) => { checkboxAccepted++; }; var checkboxSelected = 0; - shortcut.CommandView.Selected += (s, e) => + shortcut.CommandView.Selecting += (s, e) => { if (e.Cancel) { @@ -604,7 +604,7 @@ public class ShortcutTests Application.Top.LayoutSubviews (); var selected = 0; - shortcut.Selected += (s, e) => + shortcut.Selecting += (s, e) => { selected++; }; @@ -665,7 +665,7 @@ public class ShortcutTests shortcut.Accepted += (s, e) => accepted++; var selected = 0; - shortcut.Selected += (s, e) => selected++; + shortcut.Selecting += (s, e) => selected++; Application.OnKeyDown (key); @@ -717,7 +717,7 @@ public class ShortcutTests }; var selected = 0; - shortcut.Selected += (s, e) => selected++; + shortcut.Selecting += (s, e) => selected++; Application.OnKeyDown (key); diff --git a/UnitTests/Views/TextFieldTests.cs b/UnitTests/Views/TextFieldTests.cs index ef5f3ee71..d2e7b7e44 100644 --- a/UnitTests/Views/TextFieldTests.cs +++ b/UnitTests/Views/TextFieldTests.cs @@ -521,7 +521,7 @@ public class TextFieldTests (ITestOutputHelper output) { TextField tf = new (); - tf.Selected += (sender, args) => Assert.Fail ("Selected should not be raied."); + tf.Selecting += (sender, args) => Assert.Fail ("Selected should not be raied."); Application.Top = new Toplevel (); Application.Top.Add (tf); @@ -538,7 +538,7 @@ public class TextFieldTests (ITestOutputHelper output) TextField tf = new (); int selectedCount = 0; - tf.Selected += (sender, args) => selectedCount++; + tf.Selecting += (sender, args) => selectedCount++; Application.Top = new Toplevel (); Application.Top.Add (tf);