Tig 1 рік тому
батько
коміт
c2760783cd

+ 11 - 8
Terminal.Gui/View/Adornment/Adornment.cs

@@ -1,4 +1,6 @@
-namespace Terminal.Gui;
+#nullable enable
+using Terminal.Gui;
+using Attribute = Terminal.Gui.Attribute;
 
 /// <summary>
 ///     Adornments are a special form of <see cref="View"/> that appear outside the <see cref="View.Viewport"/>:
@@ -33,7 +35,7 @@ public class Adornment : View
     ///     Adornments are distinguished from typical View classes in that they are not sub-views, but have a parent/child
     ///     relationship with their containing View.
     /// </remarks>
-    public View Parent { get; set; }
+    public View? Parent { get; set; }
 
     #region Thickness
 
@@ -61,18 +63,19 @@ public class Adornment : View
                     Parent?.LayoutSubviews ();
                 }
 
-                OnThicknessChanged (new (Thickness));
+                OnThicknessChanged ();
             }
         }
     }
 
     /// <summary>Fired whenever the <see cref="Thickness"/> property changes.</summary>
-    public event EventHandler<EventArgs<Thickness>> ThicknessChanged;
+    [CanBeNull]
+    public event EventHandler? ThicknessChanged;
 
     /// <summary>Called whenever the <see cref="Thickness"/> property changes.</summary>
-    public void OnThicknessChanged (EventArgs<Thickness> args)
+    public void OnThicknessChanged ()
     {
-        ThicknessChanged?.Invoke (this, args);
+        ThicknessChanged?.Invoke (this, EventArgs.Empty);
     }
 
     #endregion Thickness
@@ -85,7 +88,7 @@ public class Adornment : View
     /// </summary>
     public override View SuperView
     {
-        get => null;
+        get => null!;
         set => throw new InvalidOperationException (@"Adornments can not be Subviews or have SuperViews. Use Parent instead.");
     }
 
@@ -134,7 +137,7 @@ public class Adornment : View
     /// <inheritdoc/>
     public override Point ScreenToFrame (in Point location)
     {
-        return Parent.ScreenToFrame (new (location.X - Frame.X, location.Y - Frame.Y));
+        return Parent!.ScreenToFrame (new (location.X - Frame.X, location.Y - Frame.Y));
     }
 
     /// <summary>Does nothing for Adornment</summary>

+ 7 - 41
Terminal.Gui/View/CancelEventArgs.cs

@@ -3,6 +3,8 @@ using System.ComponentModel;
 
 namespace Terminal.Gui;
 
+#pragma warning disable CS1711
+
 /// <summary>
 ///     <see cref="EventArgs"/> for events that convey changes to a property of type <typeparamref name="T"/>.
 /// </summary>
@@ -25,62 +27,26 @@ public class CancelEventArgs<T> : CancelEventArgs where T : notnull
         NewValue = newValue;
     }
 
-    /// <summary>The value the property will be set to if the event is not cancelled.</summary>
-    public T NewValue { get; set; }
-
     /// <summary>The current value of the property.</summary>
     public T CurrentValue { get; }
-}
 
+    /// <summary>The value the property will be set to if the event is not cancelled.</summary>
+    public T NewValue { get; set; }
+}
 
 /// <summary>
 ///     <see cref="EventArgs"/> for events that convey changes to a property of type <typeparamref name="T"/>.
 /// </summary>
 /// <typeparam name="T">The type of the value that was part of the change being canceled.</typeparam>
-/// <remarks>
-///     Events that use this class can be cancellable. Where applicable, the <see cref="CancelEventArgs.Cancel"/> property
-///     should be set to
-///     <see langword="true"/> to prevent the state change from occurring.
-/// </remarks>
 public class EventArgs<T> : EventArgs where T : notnull
 {
     /// <summary>Initializes a new instance of the <see cref="EventArgs{T}"/> class.</summary>
     /// <param name="currentValue">The current value of the property.</param>
     /// <typeparam name="T">The type of the value.</typeparam>
-    public EventArgs (ref readonly T currentValue) : base ()
-    {
-        CurrentValue = currentValue;
-    }
+    public EventArgs (ref readonly T currentValue) { CurrentValue = currentValue; }
 
     /// <summary>The current value of the property.</summary>
     public T CurrentValue { get; }
 }
 
-/// <summary>
-///     <see cref="EventArgs"/> for events that convey changes to a property of type <typeparamref name="T"/>.
-/// </summary>
-/// <typeparam name="T">The type of the value that was part of the change being canceled.</typeparam>
-/// <remarks>
-///     Events that use this class can be cancellable. Where applicable, the <see cref="CancelEventArgs.Cancel"/> property
-///     should be set to
-///     <see langword="true"/> to prevent the state change from occurring.
-/// </remarks>
-public class CancelEventArgsStruct<T> : CancelEventArgs where T : notnull
-{
-    /// <summary>Initializes a new instance of the <see cref="CancelEventArgs{T}"/> class.</summary>
-    /// <param name="currentValue">The current (old) value of the property.</param>
-    /// <param name="newValue">The value the property will be set to if the event is not cancelled.</param>
-    /// <param name="cancel">Whether the event should be canceled or not.</param>
-    /// <typeparam name="T">The type of the value for the change being canceled.</typeparam>
-    public CancelEventArgsStruct (T currentValue, T newValue, bool cancel = false) : base (cancel)
-    {
-        CurrentValue = currentValue;
-        NewValue = newValue;
-    }
-
-    /// <summary>The value the property will be set to if the event is not cancelled.</summary>
-    public T NewValue { get; set; }
-
-    /// <summary>The current value of the property.</summary>
-    public T CurrentValue { get; }
-}
+#pragma warning disable CS1711

+ 18 - 0
Terminal.Gui/View/EventArgs.cs

@@ -0,0 +1,18 @@
+#nullable enable
+namespace Terminal.Gui;
+
+#pragma warning disable CS1711
+/// <summary>
+///     <see cref="EventArgs"/> for events that convey changes to a property of type <typeparamref name="T"/>.
+/// </summary>
+/// <typeparam name="T">The type of the value that was part of the change being canceled.</typeparam>
+public class EventArgs<T> : EventArgs where T : notnull
+{
+    /// <summary>Initializes a new instance of the <see cref="EventArgs{T}"/> class.</summary>
+    /// <param name="currentValue">The current value of the property.</param>
+    /// <typeparam name="T">The type of the value.</typeparam>
+    public EventArgs (ref readonly T currentValue) { CurrentValue = currentValue; }
+
+    /// <summary>The current value of the property.</summary>
+    public T CurrentValue { get; }
+}

+ 0 - 1
Terminal.Gui/View/View.cs

@@ -497,7 +497,6 @@ public partial class View : Responder, ISupportInitializeNotification
     ///     Called before the <see cref="View.Title"/> changes. Invokes the <see cref="TitleChanging"/> event, which can
     ///     be cancelled.
     /// </summary>
-    /// <param name="oldTitle">The <see cref="View.Title"/> that is/has been replaced.</param>
     /// <param name="newTitle">The new <see cref="View.Title"/> to be replaced.</param>
     /// <returns>`true` if an event handler canceled the Title change.</returns>
     protected bool OnTitleChanging (ref string newTitle)

+ 4 - 4
Terminal.Gui/View/ViewText.cs

@@ -1,4 +1,4 @@
-using static Terminal.Gui.SpinnerStyle;
+#nullable enable
 
 namespace Terminal.Gui;
 
@@ -84,7 +84,7 @@ public partial class View
     /// <summary>
     ///     Text changed event, raised when the text has changed.
     /// </summary>
-    public event EventHandler<EventArgs> TextChanged;
+    public event EventHandler? TextChanged;
 
     /// <summary>
     ///     Gets or sets how the View's <see cref="Text"/> is aligned horizontally when drawn. Changing this property will
@@ -191,8 +191,8 @@ public partial class View
 
         // TODO: This is a hack. Figure out how to move this into DimDimAuto
         // Use _width & _height instead of Width & Height to avoid debug spew
-        DimAuto widthAuto = _width as DimAuto;
-        DimAuto heightAuto = _height as DimAuto;
+        DimAuto? widthAuto = _width as DimAuto;
+        DimAuto? heightAuto = _height as DimAuto;
         if ((widthAuto is { } && widthAuto.Style.FastHasFlags (DimAutoStyle.Text))
             || (heightAuto is { } && heightAuto.Style.FastHasFlags (DimAutoStyle.Text)))
         {

+ 1 - 1
Terminal.Gui/Views/TextValidateField.cs

@@ -333,7 +333,7 @@ namespace Terminal.Gui
                 {
                     string oldValue = Text;
                     _text.RemoveAt (pos);
-                    OnTextChanged (new EventArgs<string> (oldValue));
+                    OnTextChanged (new EventArgs<string> (ref oldValue));
                 }
 
                 return true;

+ 5 - 4
Terminal.Gui/Views/Tile.cs

@@ -1,4 +1,5 @@
-using System.ComponentModel;
+#nullable enable
+using System.ComponentModel;
 
 namespace Terminal.Gui;
 
@@ -61,7 +62,7 @@ public class Tile
     /// <param name="newTitle">The new <see cref="Title"/> to be replaced.</param>
     public virtual void OnTitleChanged (string oldTitle, string newTitle)
     {
-        var args = new EventArgs<string> (newTitle);
+        var args = new EventArgs<string> (ref newTitle);
         TitleChanged?.Invoke (this, args);
     }
 
@@ -81,11 +82,11 @@ public class Tile
     }
 
     /// <summary>Event fired after the <see cref="Title"/> has been changed.</summary>
-    public event EventHandler<EventArgs<string>> TitleChanged;
+    public event EventHandler? TitleChanged;
 
     /// <summary>
     ///     Event fired when the <see cref="Title"/> is changing.
     ///     <see cref="CancelEventArgs.Cancel"/> can be set to <c>true</c> to cancel the change.
     /// </summary>
-    public event EventHandler<CancelEventArgs<string>> TitleChanging;
+    public event EventHandler<CancelEventArgs<string>>? TitleChanging;
 }

+ 0 - 2
UnitTests/View/Adornment/AdornmentTests.cs

@@ -322,11 +322,9 @@ public class AdornmentTests (ITestOutputHelper output)
         var adornment = new Adornment (null);
         var super = new View ();
         var raised = false;
-
         adornment.ThicknessChanged += (s, e) =>
                                       {
                                           raised = true;
-                                          Assert.Equal (new Thickness (1, 2, 3, 4), e.CurrentValue);
                                           Assert.Equal (new Thickness (1, 2, 3, 4), adornment.Thickness);
                                       };
         adornment.Thickness = new Thickness (1, 2, 3, 4);