浏览代码

Selected->Selecting

Tig 9 月之前
父节点
当前提交
2a989df553

+ 1 - 1
Terminal.Gui/Input/Command.cs

@@ -34,7 +34,7 @@ public enum Command
     /// <summary>
     ///     Selects the View or an item in the View (e.g. a list item or menu item) without necessarily accepting it.
     ///     <para>
-    ///         The default implementation in <see cref="View"/> calls <see cref="View.RaiseSelected"/>.
+    ///         The default implementation in <see cref="View"/> calls <see cref="View.RaiseSelecting"/>.
     ///     </para>
     /// </summary>
     Select,

+ 17 - 17
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 <see cref="Command.Accept"/> handler calls this method.
     /// </summary>
     /// <remarks>
-    ///     The <see cref="Accepted"/> event should raised after the state of the View has changed (after <see cref="Selected"/> is raised).
+    ///     The <see cref="Accepted"/> event should raised after the state of the View has changed (after <see cref="Selecting"/> is raised).
     /// </remarks>
     /// <returns>
     ///     If <see langword="true"/> the event was canceled. If <see langword="false"/> the event was raised but not canceled.
@@ -112,48 +112,48 @@ public partial class View // Command APIs
     public event EventHandler<HandledEventArgs>? Accepted;
 
     /// <summary>
-    ///     Called when the user has selected the View or otherwise changed the state of the View. Calls <see cref="OnSelected"/> which can be cancelled; if not cancelled raises <see cref="Accepted"/>.
+    ///     Called when the user has performed an action (e.g. <see cref="Command.Select"/>) causing the View to change state. Calls <see cref="OnSelecting"/> which can be cancelled; if not cancelled raises <see cref="Accepted"/>.
     ///     event. The default <see cref="Command.Select"/> handler calls this method.
     /// </summary>
     /// <remarks>
-    ///     The <see cref="Selected"/> event should raised after the state of the View has been changed and before see <see cref="Accepted"/>.
+    ///     The <see cref="Selecting"/> event should raised after the state of the View has been changed and before see <see cref="Accepted"/>.
     /// </remarks>
     /// <returns>
     ///     If <see langword="true"/> the event was canceled. If <see langword="false"/> the event was raised but not canceled.
     ///     If <see langword="null"/> no event was raised.
     /// </returns>
-    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;
     }
 
     /// <summary>
-    ///     Called when the user has selected the View or otherwise changed the state of the View. Set <see cref="HandledEventArgs.Handled"/> to
-    ///     <see langword="true"/> to stop processing.
+    ///     Called when the user has performed an action (e.g. <see cref="Command.Select"/>) causing the View to change state.
+    ///     Set <see cref="CommandEventArgs.Cancel"/> to
+    ///     <see langword="true"/> and return <see langword="true"/> to cancel the state change. The default implementation does nothing.
     /// </summary>
-    /// <param name="args"></param>
+    /// <param name="args">The event arguments.</param>
     /// <returns><see langword="true"/> to stop processing.</returns>
-    protected virtual bool OnSelected (CommandEventArgs args) { return false; }
+    protected virtual bool OnSelecting (CommandEventArgs args) { return false; }
 
     /// <summary>
-    ///     Cancelable event raised when the user has selected the View or otherwise changed the state of the View. Set
-    ///     <see cref="HandledEventArgs.Handled"/>
-    ///     to cancel the event.
+    ///     Cancelable event raised when the user has performed an action (e.g. <see cref="Command.Select"/>) causing the View to change state.
+    ///     Set <see cref="CommandEventArgs.Cancel"/> to
+    ///     <see langword="true"/> to cancel the state change.
     /// </summary>
-    public event EventHandler<CommandEventArgs>? Selected;
-
+    public event EventHandler<CommandEventArgs>? 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.???"
     /// <summary>

+ 1 - 1
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;
         }

+ 1 - 1
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;
         }

+ 2 - 2
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;
 

+ 3 - 3
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;
                                     }

+ 3 - 3
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;
 

+ 1 - 1
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;

+ 1 - 1
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)
         {

+ 2 - 2
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)
                     {

+ 1 - 1
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)); 

+ 2 - 2
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);

+ 4 - 4
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; }
 
         /// <inheritdoc />
-        protected override bool OnSelected (CommandEventArgs args)
+        protected override bool OnSelecting (CommandEventArgs args)
         {
             OnSelectedCount++;
 

+ 3 - 3
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) =>

+ 2 - 2
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;

+ 4 - 4
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);

+ 5 - 5
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;

+ 6 - 6
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);
 

+ 2 - 2
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);