Browse Source

Fixes #3941 - v2win/v2net: UICatalog crash - Fixes warnings (#3946)

* Tons of API doc updates

* Adjust timeout

* Code cleanuyp

* Disabled All_Scenarios_Benchmark

* Removed logs

* Fixed a bunch of warnings

* Fixed a bunch of warnings2

* Disabled All_Scenarios_Benchmark again...just to make sure

* Enabled All_Scenarios_Benchmark again...It is not the culprit
Tig 4 tháng trước cách đây
mục cha
commit
5984a3c564

+ 7 - 1
.gitignore

@@ -61,4 +61,10 @@ demo.*
 
 logs/
 
-log.*
+BenchmarkDotNet.Artifacts/
+
+*.log
+
+*.log.*
+
+log.*

+ 2 - 0
Terminal.Gui/Application/Application.Initialization.cs

@@ -167,6 +167,8 @@ public static partial class Application // Initialization (Init/Shutdown)
         InitializedChanged?.Invoke (null, new (init));
     }
 
+    [RequiresUnreferencedCode ("AOT")]
+    [RequiresDynamicCode ("AOT")]
     internal static void InitializeConfigurationManagement ()
     {
         // Start the process of configuration management.

+ 3 - 3
Terminal.Gui/Configuration/ConfigurationManager.cs

@@ -327,16 +327,16 @@ public static class ConfigurationManager
 
 
     /// <summary>
-    /// Logs any Json deserialization errors that occurred during deserialization to the logging system.
+    ///     Logs Json deserialization errors that occurred during deserialization.
     /// </summary>
     public static void LogJsonErrors ()
     {
         if (_jsonErrors.Length > 0)
         {
-            Logging.Warning (
+            Logging.Error (
                                @"Encountered the following errors while deserializing configuration files:"
                               );
-            Logging.Warning (_jsonErrors.ToString ());
+            Logging.Error (_jsonErrors.ToString ());
         }
     }
 

+ 1 - 1
Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/CsiKeyPattern.cs

@@ -53,7 +53,7 @@ public class CsiKeyPattern : AnsiKeyboardParserPattern
     }
 
     /// <summary>
-    /// 
+    ///     Called by the base class to determine the key that matches the input.
     /// </summary>
     /// <param name="input"></param>
     /// <returns></returns>

+ 1 - 1
Terminal.Gui/ConsoleDrivers/V2/MainLoop.cs

@@ -151,7 +151,7 @@ public class MainLoop<T> : IMainLoop<T>
 
     private void SetCursor ()
     {
-        View? mostFocused = Application.Top.MostFocused;
+        View? mostFocused = Application.Top!.MostFocused;
 
         if (mostFocused == null)
         {

+ 1 - 1
Terminal.Gui/ConsoleDrivers/V2/NetInputProcessor.cs

@@ -17,7 +17,7 @@ public class NetInputProcessor : InputProcessor<ConsoleKeyInfo>
     ///     </remarks>
     /// </summary>
     public static bool GenerateTestCasesForKeyPresses = false;
-#pragma warning enable CA2211
+#pragma warning restore CA2211
 
     /// <inheritdoc/>
     public NetInputProcessor (ConcurrentQueue<ConsoleKeyInfo> inputBuffer) : base (inputBuffer, new NetKeyConverter ()) { }

+ 1 - 1
Terminal.Gui/Drawing/Region.cs

@@ -658,7 +658,7 @@ public class Region
             }
             else
             {
-                result.Add (new (startX, currentTop.Value, endX - startX, currentBottom.Value - currentTop.Value));
+                result.Add (new (startX, currentTop.Value, endX - startX, currentBottom!.Value - currentTop.Value));
                 currentTop = yTop;
                 currentBottom = yBottom;
             }

+ 1 - 1
Terminal.Gui/Input/Keyboard/Key.cs

@@ -418,7 +418,7 @@ public class Key : EventArgs, IEquatable<Key>
     /// <param name="a"></param>
     /// <param name="b"></param>
     /// <returns></returns>
-    public static bool operator != (Key a, Key? b) { return !a!.Equals (b); }
+    public static bool operator != (Key? a, Key? b) { return !a!.Equals (b); }
 
     /// <summary>Compares two <see cref="Key"/>s for less-than.</summary>
     /// <param name="a"></param>

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

@@ -264,7 +264,7 @@ public partial class View
     ///     </para>
     ///     <para>
     ///         Altering the Viewport Size will eventually (when the view is next laid out) cause the
-    ///         <see cref="Layout()"/> and <see cref="OnDrawingContent"/> methods to be called.
+    ///         <see cref="Layout()"/> and <see cref="OnDrawingContent()"/> methods to be called.
     ///     </para>
     /// </remarks>
     public virtual Rectangle Viewport

+ 2 - 1
Terminal.Gui/View/View.Drawing.cs

@@ -483,6 +483,7 @@ public partial class View // Drawing APIs
             return;
         }
 
+        // TODO: Upgrade all overrides of OnDrawingContent to use DrawContext and remove this override
         if (OnDrawingContent ())
         {
             return;
@@ -504,7 +505,7 @@ public partial class View // Drawing APIs
     /// </summary>
     /// <param name="context">The draw context to report drawn areas to.</param>
     /// <returns><see langword="true"/> to stop further drawing content.</returns>
-    protected virtual bool OnDrawingContent (DrawContext? context = null) { return false; }
+    protected virtual bool OnDrawingContent (DrawContext? context) { return false; }
 
     /// <summary>
     ///     Called when the View's content is to be drawn. The default implementation does nothing.

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

@@ -762,7 +762,7 @@ public partial class View // Mouse APIs
     ///     INTERNAL: Gets the Views that are under the mouse at <paramref name="location"/>, including Adornments.
     /// </summary>
     /// <param name="location"></param>
-    /// <param name="ignoreTransparent"></param>
+    /// <param name="ignoreTransparent">If <see langword="true"/> any transparent views will be ignored.</param>
     /// <returns></returns>
     internal static List<View?> GetViewsUnderMouse (in Point location, bool ignoreTransparent = false)
     {

+ 2 - 0
Terminal.Gui/Views/RadioGroup.cs

@@ -411,6 +411,8 @@ public class RadioGroup : View, IDesignable, IOrientation
     public event EventHandler<EventArgs<Orientation>>? OrientationChanged;
 #pragma warning restore CS0067 // The event is never used
 
+#pragma warning restore CS0067
+
     /// <summary>Called when <see cref="Orientation"/> has changed.</summary>
     /// <param name="newOrientation"></param>
     public void OnOrientationChanged (Orientation newOrientation)

+ 1 - 0
Terminal.Gui/Views/ScrollBar/ScrollBar.cs

@@ -167,6 +167,7 @@ public class ScrollBar : View, IOrientation, IDesignable
 #pragma warning disable CS0067 // The event is never used
     /// <inheritdoc/>
     public event EventHandler<CancelEventArgs<Orientation>>? OrientationChanging;
+#pragma warning restore CS0067 // The event is never used
 
     /// <inheritdoc/>
     public event EventHandler<EventArgs<Orientation>>? OrientationChanged;

+ 1 - 1
UICatalog/Scenario.cs

@@ -149,7 +149,7 @@ public class Scenario : IDisposable
     public virtual void Main () { }
 
     private const uint BENCHMARK_MAX_NATURAL_ITERATIONS = 500; // not including needed for demo keys
-    private const int BENCHMARK_KEY_PACING = 1; // Must be non-zero
+    private const int BENCHMARK_KEY_PACING = 10; // Must be non-zero
 
     public static uint BenchmarkTimeout { get; set; } = 2500;
 

+ 32 - 34
UICatalog/Scenarios/RegionScenario.cs

@@ -19,10 +19,7 @@ public class RegionScenario : Scenario
     private Point? _dragStart;
     private bool _isDragging;
 
-
-    public Rune? _previewFillRune = Glyphs.Stipple;
-
-    public Rune? _fillRune = Glyphs.Dot;
+    private readonly Rune? _previewFillRune = Glyphs.Stipple;
 
     private RegionDrawStyles _drawStyle;
     private RegionOp _regionOp;
@@ -34,25 +31,22 @@ public class RegionScenario : Scenario
         Window app = new ()
         {
             Title = GetQuitKeyAndName (),
-            TabStop = TabBehavior.TabGroup,
-
+            TabStop = TabBehavior.TabGroup
         };
-        app.Padding.Thickness = new (1);
+        app.Padding!.Thickness = new (1);
 
         var tools = new ToolsView { Title = "Tools", X = Pos.AnchorEnd (), Y = 2 };
 
-        tools.CurrentAttribute = app.ColorScheme.HotNormal;
+        tools.CurrentAttribute = app.ColorScheme!.HotNormal;
 
         tools.SetStyle += b =>
                           {
                               _drawStyle = (RegionDrawStyles)b;
-                              app.SetNeedsDraw();
+                              app.SetNeedsDraw ();
                           };
 
-        tools.RegionOpChanged += (s, e) =>
-                                {
-                                    _regionOp = e;
-                                };
+        tools.RegionOpChanged += (s, e) => { _regionOp = e; };
+
         //tools.AddLayer += () => canvas.AddLayer ();
 
         app.Add (tools);
@@ -87,7 +81,7 @@ public class RegionScenario : Scenario
                                       _dragStart = null;
                                   }
 
-                                  app.SetNeedsDraw (); 
+                                  app.SetNeedsDraw ();
                               }
                           };
 
@@ -120,12 +114,17 @@ public class RegionScenario : Scenario
                                   if (_isDragging && _dragStart.HasValue)
                                   {
                                       Point currentMousePos = Application.GetLastMousePosition ()!.Value;
-                                      var previewRect = GetRectFromPoints (_dragStart.Value, currentMousePos);
+                                      Rectangle previewRect = GetRectFromPoints (_dragStart.Value, currentMousePos);
                                       var previewRegion = new Region (previewRect);
 
                                       previewRegion.FillRectangles (tools.CurrentAttribute!.Value, (Rune)' ');
 
-                                      previewRegion.DrawBoundaries (app.LineCanvas, LineStyle.Dashed, new (tools.CurrentAttribute!.Value.Foreground.GetHighlightColor(), tools.CurrentAttribute!.Value.Background));
+                                      previewRegion.DrawBoundaries (
+                                                                    app.LineCanvas,
+                                                                    LineStyle.Dashed,
+                                                                    new (
+                                                                         tools.CurrentAttribute!.Value.Foreground.GetHighlightColor (),
+                                                                         tools.CurrentAttribute!.Value.Background));
                                   }
                               };
 
@@ -138,7 +137,7 @@ public class RegionScenario : Scenario
 
     private void AddRectangleFromPoints (Point start, Point end, RegionOp op)
     {
-        var rect = GetRectFromPoints (start, end);
+        Rectangle rect = GetRectFromPoints (start, end);
         var region = new Region (rect);
         _region.Combine (region, op); // Or RegionOp.MinimalUnion if you want minimal rectangles
     }
@@ -154,7 +153,7 @@ public class RegionScenario : Scenario
         int width = Math.Max (1, right - left + 1);
         int height = Math.Max (1, bottom - top + 1);
 
-        return new Rectangle (left, top, width, height);
+        return new (left, top, width, height);
     }
 }
 
@@ -165,15 +164,14 @@ public enum RegionDrawStyles
     InnerBoundaries = 1,
 
     OuterBoundary = 2
-
 }
 
 public class ToolsView : Window
 {
     //private Button _addLayerBtn;
     private readonly AttributeView _attributeView = new ();
-    private RadioGroup _stylePicker;
-    private RegionOpSelector _regionOpSelector;
+    private RadioGroup? _stylePicker;
+    private RegionOpSelector? _regionOpSelector;
 
     public Attribute? CurrentAttribute
     {
@@ -187,7 +185,6 @@ public class ToolsView : Window
         Border!.Thickness = new (1, 2, 1, 1);
         Height = Dim.Auto ();
         Width = Dim.Auto ();
-
     }
 
     //public event Action AddLayer;
@@ -200,11 +197,11 @@ public class ToolsView : Window
 
         _stylePicker = new ()
         {
-            Width=Dim.Fill(),
-            X = 0, Y = Pos.Bottom (_attributeView) + 1, RadioLabels = Enum.GetNames<RegionDrawStyles> ().Select (n => n = "_" + n).ToArray()
+            Width = Dim.Fill (),
+            X = 0, Y = Pos.Bottom (_attributeView) + 1, RadioLabels = Enum.GetNames<RegionDrawStyles> ().Select (n => n = "_" + n).ToArray ()
         };
         _stylePicker.BorderStyle = LineStyle.Single;
-        _stylePicker.Border.Thickness = new (0, 1, 0, 0);
+        _stylePicker.Border!.Thickness = new (0, 1, 0, 0);
         _stylePicker.Title = "Draw Style";
 
         _stylePicker.SelectedItemChanged += (s, a) => { SetStyle?.Invoke ((LineStyle)a.SelectedItem); };
@@ -221,7 +218,7 @@ public class ToolsView : Window
         //_addLayerBtn = new () { Text = "New Layer", X = Pos.Center (), Y = Pos.Bottom (_stylePicker) };
 
         //_addLayerBtn.Accepting += (s, a) => AddLayer?.Invoke ();
-        Add (_attributeView, _stylePicker, _regionOpSelector);//, _addLayerBtn);
+        Add (_attributeView, _stylePicker, _regionOpSelector); //, _addLayerBtn);
     }
 
     public event EventHandler<Attribute?>? AttributeChanged;
@@ -231,14 +228,15 @@ public class ToolsView : Window
 
 public class RegionOpSelector : View
 {
-    private RadioGroup _radioGroup;
+    private readonly RadioGroup _radioGroup;
+
     public RegionOpSelector ()
     {
         Width = Dim.Auto ();
         Height = Dim.Auto ();
 
         BorderStyle = LineStyle.Single;
-        Border.Thickness = new (0, 1, 0, 0);
+        Border!.Thickness = new (0, 1, 0, 0);
         Title = "RegionOp";
 
         _radioGroup = new ()
@@ -250,14 +248,14 @@ public class RegionOpSelector : View
         _radioGroup.SelectedItemChanged += (s, a) => { SelectedItemChanged?.Invoke (this, (RegionOp)a.SelectedItem); };
         Add (_radioGroup);
     }
+
     public event EventHandler<RegionOp>? SelectedItemChanged;
 
     public RegionOp SelectedItem
     {
         get => (RegionOp)_radioGroup.SelectedItem;
-        set => _radioGroup.SelectedItem = (int) value;
+        set => _radioGroup.SelectedItem = (int)value;
     }
-
 }
 
 public class AttributeView : View
@@ -289,11 +287,11 @@ public class AttributeView : View
 
     public AttributeView ()
     {
-        Width = Dim.Fill();
+        Width = Dim.Fill ();
         Height = 4;
 
         BorderStyle = LineStyle.Single;
-        Border.Thickness = new (0, 1, 0, 0);
+        Border!.Thickness = new (0, 1, 0, 0);
         Title = "Attribute";
     }
 
@@ -366,8 +364,8 @@ public class AttributeView : View
             {
                 ClickedInBackground ();
             }
-
         }
+
         mouseEvent.Handled = true;
 
         return mouseEvent.Handled;
@@ -394,4 +392,4 @@ public class AttributeView : View
             SetNeedsDraw ();
         }
     }
-}
+}

+ 1 - 1
UICatalog/Scenarios/Transparent.cs

@@ -87,7 +87,7 @@ public sealed class Transparent : Scenario
                 Arrangement = ViewArrangement.Movable | ViewArrangement.Resizable,
                 ShadowStyle = ShadowStyle.Transparent,
             };
-            transparentSubView.Border.Thickness = new (1, 1, 1, 1);
+            transparentSubView.Border!.Thickness = new (1, 1, 1, 1);
             transparentSubView.ColorScheme = Colors.ColorSchemes ["Dialog"];
 
             Button button = new Button ()

+ 2 - 2
UICatalog/UICatalog.cs

@@ -1308,14 +1308,14 @@ public class UICatalogApp
         {
             List<MenuItem []> menuItems = new ()
             {
-                CreateLoggingFlagsMenuItems ()
+                CreateLoggingFlagsMenuItems ()!
             };
 
             return menuItems;
         }
 
         [SuppressMessage ("Style", "IDE1006:Naming Styles", Justification = "<Pending>")]
-        private MenuItem [] CreateLoggingFlagsMenuItems ()
+        private MenuItem? [] CreateLoggingFlagsMenuItems ()
         {
             string [] logLevelMenuStrings = Enum.GetNames<LogLevel> ().Select (n => n = "_" + n).ToArray ();
             LogLevel [] logLevels = Enum.GetValues<LogLevel> ();