Bladeren bron

V2 fix warnings (#3671)

* Fixed NumericUpDown warning

* Fixed Aot Warning

* Fixed warnings in Application.cs

* Fixed more NumericUpDown warning

* Fixed CommandImpl warning

* Fixed Thickness warnings

* Fixed Label warning

* Fixed warning

* Fixed menubar test warning

* Fixed warnings

* Fixed warnings

* Removed dead code

* Fixed warnings
Tig 11 maanden geleden
bovenliggende
commit
b267e1698e

+ 2 - 2
NativeAot/Program.cs

@@ -17,14 +17,14 @@ public static class Program
 
         #region The code in this region is not intended for use in a native Aot self-contained. It's just here to make sure there is no functionality break with localization in Terminal.Gui using self-contained
 
-        if (Equals(Thread.CurrentThread.CurrentUICulture, CultureInfo.InvariantCulture) && Application.SupportedCultures.Count == 0)
+        if (Equals(Thread.CurrentThread.CurrentUICulture, CultureInfo.InvariantCulture) && Application.SupportedCultures!.Count == 0)
         {
             // Only happens if the project has <InvariantGlobalization>true</InvariantGlobalization>
             Debug.Assert (Application.SupportedCultures.Count == 0);
         }
         else
         {
-            Debug.Assert (Application.SupportedCultures.Count > 0);
+            Debug.Assert (Application.SupportedCultures!.Count > 0);
             Debug.Assert (Equals (CultureInfo.CurrentCulture, Thread.CurrentThread.CurrentUICulture));
         }
 

+ 3 - 30
Terminal.Gui/Application/Application.Keyboard.cs

@@ -190,7 +190,7 @@ public static partial class Application // Keyboard handling
 
                 foreach (Command command in appBinding.Commands)
                 {
-                    if (!CommandImplementations.ContainsKey (command))
+                    if (!CommandImplementations!.ContainsKey (command))
                     {
                         throw new NotSupportedException (
                                                          @$"A KeyBinding was set up for the command {command} ({keyEvent}) but that command is not supported by Application."
@@ -274,7 +274,7 @@ public static partial class Application // Keyboard handling
     /// <summary>
     ///     Commands for Application.
     /// </summary>
-    private static Dictionary<Command, Func<CommandContext, bool?>> CommandImplementations { get; set; }
+    private static Dictionary<Command, Func<CommandContext, bool?>>? CommandImplementations { get; set; }
 
     /// <summary>
     ///     <para>
@@ -292,7 +292,7 @@ public static partial class Application // Keyboard handling
     /// </remarks>
     /// <param name="command">The command.</param>
     /// <param name="f">The function.</param>
-    private static void AddCommand (Command command, Func<bool?> f) { CommandImplementations [command] = ctx => f (); }
+    private static void AddCommand (Command command, Func<bool?> f) { CommandImplementations! [command] = ctx => f (); }
 
     static Application () { AddApplicationKeyBindings (); }
 
@@ -432,31 +432,4 @@ public static partial class Application // Keyboard handling
                           .Distinct ()
                           .ToList ();
     }
-
-    ///// <summary>
-    /////     Gets the list of Views that have <see cref="KeyBindingScope.Application"/> key bindings for the specified key.
-    ///// </summary>
-    ///// <remarks>
-    /////     This is an internal method used by the <see cref="View"/> class to add Application key bindings.
-    ///// </remarks>
-    ///// <param name="key">The key to check.</param>
-    ///// <param name="views">Outputs the list of views bound to <paramref name="key"/></param>
-    ///// <returns><see langword="True"/> if successful.</returns>
-    //internal static bool TryGetKeyBindings (Key key, out List<View> views) { return _keyBindings.TryGetValue (key, out views); }
-
-    /// <summary>
-    ///     Removes all <see cref="KeyBindingScope.Application"/> scoped key bindings for the specified view.
-    /// </summary>
-    /// <remarks>
-    ///     This is an internal method used by the <see cref="View"/> class to remove Application key bindings.
-    /// </remarks>
-    /// <param name="view">The view that is bound to the key.</param>
-    internal static void RemoveKeyBindings (View view)
-    {
-        List<KeyBinding> list = KeyBindings.Bindings
-                                           .Where (kv => kv.Value.Scope != KeyBindingScope.Application)
-                                           .Select (kv => kv.Value)
-                                           .Distinct ()
-                                           .ToList ();
-    }
 }

+ 8 - 4
Terminal.Gui/Application/Application.cs

@@ -32,7 +32,7 @@ public static partial class Application
     /// <returns>A string representation of the Application </returns>
     public new static string ToString ()
     {
-        ConsoleDriver driver = Driver;
+        ConsoleDriver? driver = Driver;
 
         if (driver is null)
         {
@@ -47,13 +47,17 @@ public static partial class Application
     /// </summary>
     /// <param name="driver">The driver to use to render the contents.</param>
     /// <returns>A string representation of the Application </returns>
-    public static string ToString (ConsoleDriver driver)
+    public static string ToString (ConsoleDriver? driver)
     {
+        if (driver is null)
+        {
+            return string.Empty;
+        }
         var sb = new StringBuilder ();
 
-        Cell [,] contents = driver.Contents;
+        Cell [,] contents = driver?.Contents!;
 
-        for (var r = 0; r < driver.Rows; r++)
+        for (var r = 0; r < driver!.Rows; r++)
         {
             for (var c = 0; c < driver.Cols; c++)
             {

+ 4 - 4
Terminal.Gui/Drawing/Thickness.cs

@@ -61,7 +61,7 @@ public record struct Thickness
     [JsonInclude]
     public int Bottom
     {
-        get => (int)_sides.W;
+        readonly get => (int)_sides.W;
         set => _sides.W = value;
     }
 
@@ -249,7 +249,7 @@ public record struct Thickness
     [JsonInclude]
     public int Left
     {
-        get => (int)_sides.X;
+        readonly get => (int)_sides.X;
         set => _sides.X = value;
     }
 
@@ -265,7 +265,7 @@ public record struct Thickness
     [JsonInclude]
     public int Right
     {
-        get => (int)_sides.Z;
+        readonly get => (int)_sides.Z;
         set => _sides.Z = value;
     }
 
@@ -273,7 +273,7 @@ public record struct Thickness
     [JsonInclude]
     public int Top
     {
-        get => (int)_sides.Y;
+        readonly get => (int)_sides.Y;
         set => _sides.Y = value;
     }
 

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

@@ -27,7 +27,6 @@ public partial class View  // Keyboard APIs
     private void DisposeKeyboard ()
     {
         TitleTextFormatter.HotKeyChanged -= TitleTextFormatter_HotKeyChanged;
-        Application.RemoveKeyBindings (this);
     }
 
     #region HotKey Support

+ 2 - 2
Terminal.Gui/Views/Label.cs

@@ -51,9 +51,9 @@ public class Label : View
         set => TextFormatter.HotKeySpecifier = base.HotKeySpecifier = value;
     }
 
-    private new bool? FocusNext ()
+    private bool? FocusNext ()
     {
-        var me = SuperView?.Subviews.IndexOf (this) ?? -1;
+        int me = SuperView?.Subviews.IndexOf (this) ?? -1;
         if (me != -1 && me < SuperView?.Subviews.Count - 1)
         {
             SuperView?.Subviews [me + 1].SetFocus ();

+ 7 - 6
Terminal.Gui/Views/NumericUpDown.cs

@@ -100,7 +100,7 @@ public class NumericUpDown<T> : View where T : notnull
                             return false;
                         }
 
-                        if (Value is { })
+                        if (Value is { } && Increment is { })
                         {
                             Value = (dynamic)Value + (dynamic)Increment;
                         }
@@ -117,11 +117,12 @@ public class NumericUpDown<T> : View where T : notnull
                             return false;
                         }
 
-                        if (Value is { })
+                        if (Value is { } && Increment is { })
                         {
                             Value = (dynamic)Value - (dynamic)Increment;
                         }
 
+
                         return true;
                     });
 
@@ -218,23 +219,23 @@ public class NumericUpDown<T> : View where T : notnull
         Text = _number.Text;
     }
 
-    private T _increment;
+    private T? _increment;
 
     /// <summary>
     /// </summary>
-    public T Increment
+    public T? Increment
     {
         get => _increment;
         set
         {
-            if ((dynamic)_increment == (dynamic)value)
+            if (_increment is { } && value is { } && (dynamic)_increment == (dynamic)value)
             {
                 return;
             }
 
             _increment = value;
 
-            IncrementChanged?.Invoke (this, new (value));
+            IncrementChanged?.Invoke (this, new (value!));
         }
     }
 

+ 3 - 1
UICatalog/Scenarios/ListViewWithSelection.cs

@@ -202,9 +202,11 @@ public class ListViewWithSelection : Scenario
 
             return false;
         }
-
+#pragma warning disable CS0067
         /// <inheritdoc />
         public event NotifyCollectionChangedEventHandler CollectionChanged;
+#pragma warning restore CS0067
+
         public int Count => Scenarios?.Count ?? 0;
         public int Length { get; private set; }
         public bool SuspendCollectionChangedEvent { get => throw new System.NotImplementedException (); set => throw new System.NotImplementedException (); }

+ 1 - 1
UICatalog/UICatalog.cs

@@ -643,7 +643,7 @@ public class UICatalogApp
             Add (CategoryList);
             Add (ScenarioList);
 
-            Add (MenuBar);
+            Add (MenuBar!);
 
             if (StatusBar is { })
             {

+ 2 - 0
UnitTests/Configuration/ConfigurationMangerTests.cs

@@ -389,6 +389,7 @@ public class ConfigurationManagerTests
                                             )
                    );
 
+#pragma warning disable xUnit2029
         Assert.Empty (
                       Settings.Where (
                                       cp => cp.Value.PropertyInfo!.GetCustomAttribute (
@@ -397,6 +398,7 @@ public class ConfigurationManagerTests
                                             == null
                                      )
                      );
+#pragma warning restore xUnit2029
 
         // Application is a static class
         PropertyInfo pi = typeof (Application).GetProperty ("QuitKey");

File diff suppressed because it is too large
+ 1410 - 3161
UnitTests/Text/TextFormatterTests.cs


+ 1 - 1
UnitTests/View/TitleTests.cs

@@ -3,7 +3,7 @@ using Xunit.Abstractions;
 
 namespace Terminal.Gui.ViewTests;
 
-public class TitleTests (ITestOutputHelper output)
+public class TitleTests
 {
     // Unit tests that verify look & feel of title are in BorderTests.cs
 

+ 2 - 0
UnitTests/Views/ListViewTests.cs

@@ -674,8 +674,10 @@ Item 6",
 
     private class NewListDataSource : IListDataSource
     {
+#pragma warning disable CS0067
         /// <inheritdoc />
         public event NotifyCollectionChangedEventHandler CollectionChanged;
+#pragma warning restore CS0067
 
         public int Count => 0;
         public int Length => 0;

+ 1 - 1
UnitTests/Views/MenuBarTests.cs

@@ -3800,7 +3800,7 @@ Edit
 
         menuItem.RemoveMenuItem ();
         Assert.Single (menuBar.Menus);
-        Assert.Equal (null, menuBar.Menus [0].Children);
+        Assert.Null (menuBar.Menus [0].Children);
         Assert.Contains (Key.N.WithAlt, menuBar.KeyBindings.Bindings);
         Assert.DoesNotContain (Key.I, menuBar.KeyBindings.Bindings);
 

+ 1 - 1
UnitTests/Views/NumericUpDownTests.cs

@@ -3,7 +3,7 @@ using Xunit.Abstractions;
 
 namespace Terminal.Gui.ViewsTests;
 
-public class NumericUpDownTests (ITestOutputHelper _output)
+public class NumericUpDownTests
 {
     [Fact]
     public void WhenCreated_ShouldHaveDefaultValues_int ()

+ 1 - 1
UnitTests/Views/StatusBarTests.cs

@@ -1,7 +1,7 @@
 using Xunit.Abstractions;
 
 namespace Terminal.Gui.ViewsTests;
-public class StatusBarTests (ITestOutputHelper output)
+public class StatusBarTests
 {
     [Fact]
     public void AddItemAt_RemoveItem_Replacing ()

+ 8 - 0
UnitTests/Views/TableViewTests.cs

@@ -2582,7 +2582,9 @@ A B C
 
         TestHelpers.AssertDriverContentsAre (expected, output);
 
+#pragma warning disable xUnit2029
         Assert.Empty (pets.Where (p => p.IsPicked));
+#pragma warning restore xUnit2029
 
         tv.NewKeyDownEvent (Key.Space);
 
@@ -2795,7 +2797,9 @@ A B C
 
         tv.NewKeyDownEvent (Key.Space);
 
+#pragma warning disable xUnit2029
         Assert.Empty (pets.Where (p => p.IsPicked));
+#pragma warning restore xUnit2029
 
         tv.Draw ();
 
@@ -2924,7 +2928,9 @@ A B C
 
         TestHelpers.AssertDriverContentsAre (expected, output);
 
+#pragma warning disable xUnit2029
         Assert.Empty (pets.Where (p => p.IsPicked));
+#pragma warning restore xUnit2029
 
         tv.NewKeyDownEvent (Key.Space);
 
@@ -3089,7 +3095,9 @@ A B C
         // Can untoggle at 1,0 even though 0,0 was initial toggle because FullRowSelect is on
         tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.Space });
 
+#pragma warning disable xUnit2029
         Assert.Empty (tableView.MultiSelectedRegions.Where (r => r.IsToggled));
+#pragma warning restore xUnit2029
     }
 
     [Fact]

Some files were not shown because too many files changed in this diff