Browse Source

Refactor and improve modularity across multiple classes

Refactored `FillRectangles` in `RegionScenario` and `Region` to accept an `IDriver` parameter, reducing reliance on global state. Updated `ApplicationImpl` to replace static method calls with instance methods for better encapsulation. Renamed `Toplevel` to `Current` in `IPopover` and related classes for clarity.

Simplified `LineCanvas` methods by removing unnecessary `IDriver` parameters. Added `Id` and `App` properties to `View` for better state management and unique identification. Streamlined the `Driver` property in `View` with a concise getter.

Improved formatting and consistency across files, including `Region` and `IntersectionRuneResolver`. Enhanced thread safety in `Region` and cleaned up redundant code. Updated tests to align with interface changes and ensure compatibility.
Tig 1 month ago
parent
commit
8ebcc47974

+ 1 - 1
Examples/UICatalog/Scenarios/Images.cs

@@ -151,7 +151,7 @@ public class Images : Scenario
         _win.Add (_tabView);
         _win.Add (_tabView);
 
 
         // Start trying to detect sixel support
         // Start trying to detect sixel support
-        var sixelSupportDetector = new SixelSupportDetector ();
+        var sixelSupportDetector = new SixelSupportDetector (Application.Driver);
         sixelSupportDetector.Detect (UpdateSixelSupportState);
         sixelSupportDetector.Detect (UpdateSixelSupportState);
 
 
         Application.Run (_win);
         Application.Run (_win);

+ 4 - 4
Examples/UICatalog/Scenarios/RegionScenario.cs

@@ -89,19 +89,19 @@ public class RegionScenario : Scenario
                                   switch (_drawStyle)
                                   switch (_drawStyle)
                                   {
                                   {
                                       case RegionDrawStyles.FillOnly:
                                       case RegionDrawStyles.FillOnly:
-                                          _region.FillRectangles (tools.CurrentAttribute!.Value, _previewFillRune);
+                                          _region.FillRectangles (Application.Driver, tools.CurrentAttribute!.Value, _previewFillRune);
 
 
                                           break;
                                           break;
 
 
                                       case RegionDrawStyles.InnerBoundaries:
                                       case RegionDrawStyles.InnerBoundaries:
                                           _region.DrawBoundaries (app.LineCanvas, LineStyle.Single, tools.CurrentAttribute);
                                           _region.DrawBoundaries (app.LineCanvas, LineStyle.Single, tools.CurrentAttribute);
-                                          _region.FillRectangles (tools.CurrentAttribute!.Value, (Rune)' ');
+                                          _region.FillRectangles (Application.Driver, tools.CurrentAttribute!.Value, (Rune)' ');
 
 
                                           break;
                                           break;
 
 
                                       case RegionDrawStyles.OuterBoundary:
                                       case RegionDrawStyles.OuterBoundary:
                                           _region.DrawOuterBoundary (app.LineCanvas, LineStyle.Single, tools.CurrentAttribute);
                                           _region.DrawOuterBoundary (app.LineCanvas, LineStyle.Single, tools.CurrentAttribute);
-                                          _region.FillRectangles (tools.CurrentAttribute!.Value, (Rune)' ');
+                                          _region.FillRectangles (Application.Driver, tools.CurrentAttribute!.Value, (Rune)' ');
 
 
                                           break;
                                           break;
                                   }
                                   }
@@ -113,7 +113,7 @@ public class RegionScenario : Scenario
                                       Rectangle previewRect = GetRectFromPoints (_dragStart.Value, currentMousePos);
                                       Rectangle previewRect = GetRectFromPoints (_dragStart.Value, currentMousePos);
                                       var previewRegion = new Region (previewRect);
                                       var previewRegion = new Region (previewRect);
 
 
-                                      previewRegion.FillRectangles (tools.CurrentAttribute!.Value, (Rune)' ');
+                                      previewRegion.FillRectangles (Application.Driver, tools.CurrentAttribute!.Value, (Rune)' ');
 
 
                                       previewRegion.DrawBoundaries (
                                       previewRegion.DrawBoundaries (
                                                                     app.LineCanvas,
                                                                     app.LineCanvas,

+ 5 - 2
Terminal.Gui/App/ApplicationImpl.Run.cs

@@ -114,6 +114,9 @@ public partial class ApplicationImpl
                 Current?.OnDeactivate (toplevel);
                 Current?.OnDeactivate (toplevel);
                 Toplevel previousTop = Current!;
                 Toplevel previousTop = Current!;
 
 
+                previousTop.App = null;
+
+                toplevel.App = Instance;
                 Current = toplevel;
                 Current = toplevel;
                 Current.OnActivate (previousTop);
                 Current.OnActivate (previousTop);
             }
             }
@@ -194,7 +197,7 @@ public partial class ApplicationImpl
 
 
         Current = view;
         Current = view;
 
 
-        SessionToken rs = Application.Begin (view);
+        SessionToken rs = Begin (view);
 
 
         Current.Running = true;
         Current.Running = true;
 
 
@@ -219,7 +222,7 @@ public partial class ApplicationImpl
         }
         }
 
 
         Logging.Information ("Run - Calling End");
         Logging.Information ("Run - Calling End");
-        Application.End (rs);
+        End (rs);
     }
     }
 
 
     /// <inheritdoc/>
     /// <inheritdoc/>

+ 2 - 2
Terminal.Gui/App/ApplicationPopover.cs

@@ -37,7 +37,7 @@ public sealed class ApplicationPopover : IDisposable
         if (popover is { } && !_popovers.Contains (popover))
         if (popover is { } && !_popovers.Contains (popover))
         {
         {
             // When created, set IPopover.Toplevel to the current Application.Current
             // When created, set IPopover.Toplevel to the current Application.Current
-            popover.Toplevel ??= Application.Current;
+            popover.Current ??= Application.Current;
 
 
             _popovers.Add (popover);
             _popovers.Add (popover);
         }
         }
@@ -196,7 +196,7 @@ public sealed class ApplicationPopover : IDisposable
         {
         {
             if (popover == activePopover
             if (popover == activePopover
                 || popover is not View popoverView
                 || popover is not View popoverView
-                || (popover.Toplevel is { } && popover.Toplevel != Application.Current))
+                || (popover.Current is { } && popover.Current != Application.Current))
             {
             {
                 continue;
                 continue;
             }
             }

+ 5 - 5
Terminal.Gui/App/IPopover.cs

@@ -50,12 +50,12 @@ namespace Terminal.Gui.App;
 public interface IPopover
 public interface IPopover
 {
 {
     /// <summary>
     /// <summary>
-    ///     Gets or sets the <see cref="Toplevel"/> that this Popover is associated with. If null, it is not associated with
+    ///     Gets or sets the <see cref="Current"/> that this Popover is associated with. If null, it is not associated with
     ///     any Toplevel and will receive all keyboard
     ///     any Toplevel and will receive all keyboard
-    ///     events from the <see cref="Application"/>. If set, it will only receive keyboard events the Toplevel would normally
+    ///     events from the <see cref="IApplication"/>. If set, it will only receive keyboard events the Toplevel would normally
     ///     receive.
     ///     receive.
-    ///     When <see cref="ApplicationPopover.Register"/> is called, the <see cref="Toplevel"/> is set to the current
-    ///     <see cref="Application.Current"/> if not already set.
+    ///     When <see cref="ApplicationPopover.Register"/> is called, the <see cref="Current"/> is set to the current
+    ///     <see cref="IApplication.Current"/> if not already set.
     /// </summary>
     /// </summary>
-    Toplevel? Toplevel { get; set; }
+    Toplevel? Current { get; set; }
 }
 }

+ 1 - 1
Terminal.Gui/App/PopoverBaseImpl.cs

@@ -74,7 +74,7 @@ public abstract class PopoverBaseImpl : View, IPopover
     }
     }
 
 
     /// <inheritdoc/>
     /// <inheritdoc/>
-    public Toplevel? Toplevel { get; set; }
+    public Toplevel? Current { get; set; }
 
 
     /// <summary>
     /// <summary>
     ///     Called when the <see cref="View.Visible"/> property is changing.
     ///     Called when the <see cref="View.Visible"/> property is changing.

+ 7 - 7
Terminal.Gui/Drawing/LineCanvas/LineCanvas.cs

@@ -180,7 +180,7 @@ public class LineCanvas : IDisposable
                 }
                 }
                 // Safe as long as the list is not modified while the span is in use.
                 // Safe as long as the list is not modified while the span is in use.
                 ReadOnlySpan<IntersectionDefinition> intersects = CollectionsMarshal.AsSpan(intersectionsBufferList);
                 ReadOnlySpan<IntersectionDefinition> intersects = CollectionsMarshal.AsSpan(intersectionsBufferList);
-                Cell? cell = GetCellForIntersects (Application.Driver, intersects);
+                Cell? cell = GetCellForIntersects (intersects);
                 // TODO: Can we skip the whole nested looping if _exclusionRegion is null?
                 // TODO: Can we skip the whole nested looping if _exclusionRegion is null?
                 if (cell is { } && _exclusionRegion?.Contains (x, y) is null or false)
                 if (cell is { } && _exclusionRegion?.Contains (x, y) is null or false)
                 {
                 {
@@ -222,7 +222,7 @@ public class LineCanvas : IDisposable
                     .Where (i => i is not null)
                     .Where (i => i is not null)
                     .ToArray ();
                     .ToArray ();
 
 
-                Rune? rune = GetRuneForIntersects (Application.Driver, intersects);
+                Rune? rune = GetRuneForIntersects (intersects);
 
 
                 if (rune is { } && _exclusionRegion?.Contains (x, y) is null or false)
                 if (rune is { } && _exclusionRegion?.Contains (x, y) is null or false)
                 {
                 {
@@ -401,7 +401,7 @@ public class LineCanvas : IDisposable
         // TODO: Add other resolvers
         // TODO: Add other resolvers
     };
     };
 
 
-    private Cell? GetCellForIntersects (IDriver? driver, ReadOnlySpan<IntersectionDefinition> intersects)
+    private Cell? GetCellForIntersects (ReadOnlySpan<IntersectionDefinition> intersects)
     {
     {
         if (intersects.IsEmpty)
         if (intersects.IsEmpty)
         {
         {
@@ -409,7 +409,7 @@ public class LineCanvas : IDisposable
         }
         }
 
 
         var cell = new Cell ();
         var cell = new Cell ();
-        Rune? rune = GetRuneForIntersects (driver, intersects);
+        Rune? rune = GetRuneForIntersects (intersects);
 
 
         if (rune.HasValue)
         if (rune.HasValue)
         {
         {
@@ -421,7 +421,7 @@ public class LineCanvas : IDisposable
         return cell;
         return cell;
     }
     }
 
 
-    private Rune? GetRuneForIntersects (IDriver? driver, ReadOnlySpan<IntersectionDefinition> intersects)
+    private Rune? GetRuneForIntersects (ReadOnlySpan<IntersectionDefinition> intersects)
     {
     {
         if (intersects.IsEmpty)
         if (intersects.IsEmpty)
         {
         {
@@ -431,7 +431,7 @@ public class LineCanvas : IDisposable
         IntersectionRuneType runeType = GetRuneTypeForIntersects (intersects);
         IntersectionRuneType runeType = GetRuneTypeForIntersects (intersects);
         if (_runeResolvers.TryGetValue (runeType, out IntersectionRuneResolver? resolver))
         if (_runeResolvers.TryGetValue (runeType, out IntersectionRuneResolver? resolver))
         {
         {
-            return resolver.GetRuneForIntersects (driver, intersects);
+            return resolver.GetRuneForIntersects (intersects);
         }
         }
 
 
         // TODO: Remove these once we have all of the below ported to IntersectionRuneResolvers
         // TODO: Remove these once we have all of the below ported to IntersectionRuneResolvers
@@ -768,7 +768,7 @@ public class LineCanvas : IDisposable
         internal Rune _thickV;
         internal Rune _thickV;
         protected IntersectionRuneResolver () { SetGlyphs (); }
         protected IntersectionRuneResolver () { SetGlyphs (); }
 
 
-        public Rune? GetRuneForIntersects (IDriver? driver, ReadOnlySpan<IntersectionDefinition> intersects)
+        public Rune? GetRuneForIntersects (ReadOnlySpan<IntersectionDefinition> intersects)
         {
         {
             // Note that there aren't any glyphs for intersections of double lines with heavy lines
             // Note that there aren't any glyphs for intersections of double lines with heavy lines
 
 

+ 34 - 24
Terminal.Gui/Drawing/Region.cs

@@ -50,10 +50,10 @@ public class Region
     private readonly List<Rectangle> _rectangles = [];
     private readonly List<Rectangle> _rectangles = [];
 
 
     // Add a single reusable list for temp operations
     // Add a single reusable list for temp operations
-    private readonly List<Rectangle> _tempRectangles = new();
+    private readonly List<Rectangle> _tempRectangles = new ();
 
 
     // Object used for synchronization
     // Object used for synchronization
-    private readonly object _syncLock = new object();
+    private readonly object _syncLock = new object ();
 
 
     /// <summary>
     /// <summary>
     ///     Initializes a new instance of the <see cref="Region"/> class.
     ///     Initializes a new instance of the <see cref="Region"/> class.
@@ -120,12 +120,12 @@ public class Region
     {
     {
         lock (_syncLock)
         lock (_syncLock)
         {
         {
-            CombineInternal(region, operation);
+            CombineInternal (region, operation);
         }
         }
     }
     }
 
 
     // Private method to implement the combine logic within a lock
     // Private method to implement the combine logic within a lock
-    private void CombineInternal(Region? region, RegionOp operation)
+    private void CombineInternal (Region? region, RegionOp operation)
     {
     {
         if (region is null || region._rectangles.Count == 0)
         if (region is null || region._rectangles.Count == 0)
         {
         {
@@ -188,36 +188,36 @@ public class Region
 
 
             case RegionOp.Union:
             case RegionOp.Union:
                 // Avoid collection initialization with spread operator
                 // Avoid collection initialization with spread operator
-                _tempRectangles.Clear();
-                _tempRectangles.AddRange(_rectangles);
+                _tempRectangles.Clear ();
+                _tempRectangles.AddRange (_rectangles);
                 if (region != null)
                 if (region != null)
                 {
                 {
                     // Get the region's rectangles safely
                     // Get the region's rectangles safely
                     lock (region._syncLock)
                     lock (region._syncLock)
                     {
                     {
-                        _tempRectangles.AddRange(region._rectangles);
+                        _tempRectangles.AddRange (region._rectangles);
                     }
                     }
                 }
                 }
-                List<Rectangle> mergedUnion = MergeRectangles(_tempRectangles, false);
-                _rectangles.Clear();
-                _rectangles.AddRange(mergedUnion);
+                List<Rectangle> mergedUnion = MergeRectangles (_tempRectangles, false);
+                _rectangles.Clear ();
+                _rectangles.AddRange (mergedUnion);
                 break;
                 break;
 
 
             case RegionOp.MinimalUnion:
             case RegionOp.MinimalUnion:
                 // Avoid collection initialization with spread operator
                 // Avoid collection initialization with spread operator
-                _tempRectangles.Clear();
-                _tempRectangles.AddRange(_rectangles);
+                _tempRectangles.Clear ();
+                _tempRectangles.AddRange (_rectangles);
                 if (region != null)
                 if (region != null)
                 {
                 {
                     // Get the region's rectangles safely
                     // Get the region's rectangles safely
                     lock (region._syncLock)
                     lock (region._syncLock)
                     {
                     {
-                        _tempRectangles.AddRange(region._rectangles);
+                        _tempRectangles.AddRange (region._rectangles);
                     }
                     }
                 }
                 }
-                List<Rectangle> mergedMinimalUnion = MergeRectangles(_tempRectangles, true);
-                _rectangles.Clear();
-                _rectangles.AddRange(mergedMinimalUnion);
+                List<Rectangle> mergedMinimalUnion = MergeRectangles (_tempRectangles, true);
+                _rectangles.Clear ();
+                _rectangles.AddRange (mergedMinimalUnion);
                 break;
                 break;
 
 
             case RegionOp.XOR:
             case RegionOp.XOR:
@@ -587,17 +587,26 @@ public class Region
                      {
                      {
                          // 1. Sort by X
                          // 1. Sort by X
                          int cmp = a.x.CompareTo (b.x);
                          int cmp = a.x.CompareTo (b.x);
-                         if (cmp != 0) return cmp;
+                         if (cmp != 0)
+                         {
+                             return cmp;
+                         }
 
 
                          // 2. Sort End events before Start events
                          // 2. Sort End events before Start events
                          bool aIsEnd = !a.isStart;
                          bool aIsEnd = !a.isStart;
                          bool bIsEnd = !b.isStart;
                          bool bIsEnd = !b.isStart;
                          cmp = aIsEnd.CompareTo (bIsEnd); // True (End) comes after False (Start)
                          cmp = aIsEnd.CompareTo (bIsEnd); // True (End) comes after False (Start)
-                         if (cmp != 0) return -cmp; // Reverse: End (true) should come before Start (false)
+                         if (cmp != 0)
+                         {
+                             return -cmp; // Reverse: End (true) should come before Start (false)
+                         }
 
 
                          // 3. Tie-breaker: Sort by yTop
                          // 3. Tie-breaker: Sort by yTop
                          cmp = a.yTop.CompareTo (b.yTop);
                          cmp = a.yTop.CompareTo (b.yTop);
-                         if (cmp != 0) return cmp;
+                         if (cmp != 0)
+                         {
+                             return cmp;
+                         }
 
 
                          // 4. Final Tie-breaker: Sort by yBottom
                          // 4. Final Tie-breaker: Sort by yBottom
                          return a.yBottom.CompareTo (b.yBottom);
                          return a.yBottom.CompareTo (b.yBottom);
@@ -900,12 +909,13 @@ public class Region
     /// <summary>
     /// <summary>
     ///     Fills the interior of all rectangles in the region with the specified attribute and fill rune.
     ///     Fills the interior of all rectangles in the region with the specified attribute and fill rune.
     /// </summary>
     /// </summary>
+    /// <param name="driver"></param>
     /// <param name="attribute">The attribute (color/style) to use.</param>
     /// <param name="attribute">The attribute (color/style) to use.</param>
     /// <param name="fillRune">
     /// <param name="fillRune">
     ///     The rune to fill the interior of the rectangles with. If <cref langword="null"/> space will be
     ///     The rune to fill the interior of the rectangles with. If <cref langword="null"/> space will be
     ///     used.
     ///     used.
     /// </param>
     /// </param>
-    public void FillRectangles (Attribute attribute, Rune? fillRune = null)
+    public void FillRectangles (IDriver? driver, Attribute? attribute, Rune? fillRune = null)
     {
     {
         if (_rectangles.Count == 0)
         if (_rectangles.Count == 0)
         {
         {
@@ -919,14 +929,14 @@ public class Region
                 continue;
                 continue;
             }
             }
 
 
-            Application.Driver?.SetAttribute (attribute);
+            driver?.SetAttribute (attribute!.Value);
 
 
             for (int y = rect.Top; y < rect.Bottom; y++)
             for (int y = rect.Top; y < rect.Bottom; y++)
             {
             {
                 for (int x = rect.Left; x < rect.Right; x++)
                 for (int x = rect.Left; x < rect.Right; x++)
                 {
                 {
-                    Application.Driver?.Move (x, y);
-                    Application.Driver?.AddRune (fillRune ?? (Rune)' ');
+                    driver?.Move (x, y);
+                    driver?.AddRune (fillRune ?? (Rune)' ');
                 }
                 }
             }
             }
         }
         }
@@ -1045,7 +1055,7 @@ public class Region
         if (bounds.Width > 1000 || bounds.Height > 1000)
         if (bounds.Width > 1000 || bounds.Height > 1000)
         {
         {
             // Fall back to drawing each rectangle's boundary
             // Fall back to drawing each rectangle's boundary
-            DrawBoundaries(lineCanvas, style, attribute);
+            DrawBoundaries (lineCanvas, style, attribute);
             return;
             return;
         }
         }
 
 

+ 17 - 9
Terminal.Gui/Drawing/Sixel/SixelSupportDetector.cs

@@ -1,5 +1,4 @@
-#nullable disable
-using System.Text.RegularExpressions;
+using System.Text.RegularExpressions;
 
 
 namespace Terminal.Gui.Drawing;
 namespace Terminal.Gui.Drawing;
 
 
@@ -7,8 +6,19 @@ namespace Terminal.Gui.Drawing;
 ///     Uses Ansi escape sequences to detect whether sixel is supported
 ///     Uses Ansi escape sequences to detect whether sixel is supported
 ///     by the terminal.
 ///     by the terminal.
 /// </summary>
 /// </summary>
-public class SixelSupportDetector
+public class SixelSupportDetector ()
 {
 {
+    private readonly IDriver? _driver;
+
+    /// <summary>
+    ///     Creates a new instance of the <see cref="SixelSupportDetector"/> class.
+    /// </summary>
+    /// <param name="driver"></param>
+    public SixelSupportDetector (IDriver? driver) : this ()
+    {
+        _driver = driver;
+    }
+
     /// <summary>
     /// <summary>
     ///     Sends Ansi escape sequences to the console to determine whether
     ///     Sends Ansi escape sequences to the console to determine whether
     ///     sixel is supported (and <see cref="SixelSupportResult.Resolution"/>
     ///     sixel is supported (and <see cref="SixelSupportResult.Resolution"/>
@@ -128,17 +138,17 @@ public class SixelSupportDetector
                       () => resultCallback (result));
                       () => resultCallback (result));
     }
     }
 
 
-    private static void QueueRequest (AnsiEscapeSequence req, Action<string> responseCallback, Action abandoned)
+    private void QueueRequest (AnsiEscapeSequence req, Action<string> responseCallback, Action abandoned)
     {
     {
         var newRequest = new AnsiEscapeSequenceRequest
         var newRequest = new AnsiEscapeSequenceRequest
         {
         {
             Request = req.Request,
             Request = req.Request,
             Terminator = req.Terminator,
             Terminator = req.Terminator,
-            ResponseReceived = responseCallback,
+            ResponseReceived = responseCallback!,
             Abandoned = abandoned
             Abandoned = abandoned
         };
         };
 
 
-        Application.Driver?.QueueAnsiRequest (newRequest);
+        _driver?.QueueAnsiRequest (newRequest);
     }
     }
 
 
     private static bool ResponseIndicatesSupport (string response) { return response.Split (';').Contains ("4"); }
     private static bool ResponseIndicatesSupport (string response) { return response.Split (';').Contains ("4"); }
@@ -146,14 +156,12 @@ public class SixelSupportDetector
     private static bool IsVirtualTerminal ()
     private static bool IsVirtualTerminal ()
     {
     {
         return !string.IsNullOrWhiteSpace (Environment.GetEnvironmentVariable ("WT_SESSION"));
         return !string.IsNullOrWhiteSpace (Environment.GetEnvironmentVariable ("WT_SESSION"));
-
-        ;
     }
     }
 
 
     private static bool IsXtermWithTransparency ()
     private static bool IsXtermWithTransparency ()
     {
     {
         // Check if running in real xterm (XTERM_VERSION is more reliable than TERM)
         // Check if running in real xterm (XTERM_VERSION is more reliable than TERM)
-        string xtermVersionStr = Environment.GetEnvironmentVariable ("XTERM_VERSION");
+        string xtermVersionStr = Environment.GetEnvironmentVariable (@"XTERM_VERSION")!;
 
 
         // If XTERM_VERSION exists, we are in a real xterm
         // If XTERM_VERSION exists, we are in a real xterm
         if (!string.IsNullOrWhiteSpace (xtermVersionStr) && int.TryParse (xtermVersionStr, out int xtermVersion) && xtermVersion >= 370)
         if (!string.IsNullOrWhiteSpace (xtermVersionStr) && int.TryParse (xtermVersionStr, out int xtermVersion) && xtermVersion >= 370)

+ 15 - 9
Terminal.Gui/ViewBase/View.cs

@@ -103,11 +103,25 @@ public partial class View : IDisposable, ISupportInitializeNotification
     /// <remarks>This property is not used internally.</remarks>
     /// <remarks>This property is not used internally.</remarks>
     public object? Data { get; set; }
     public object? Data { get; set; }
 
 
+
+
     /// <summary>Gets or sets an identifier for the view;</summary>
     /// <summary>Gets or sets an identifier for the view;</summary>
     /// <value>The identifier.</value>
     /// <value>The identifier.</value>
     /// <remarks>The id should be unique across all Views that share a SuperView.</remarks>
     /// <remarks>The id should be unique across all Views that share a SuperView.</remarks>
     public string Id { get; set; } = "";
     public string Id { get; set; } = "";
 
 
+
+    private IApplication? _app;
+
+    /// <summary>
+    ///     Gets the <see cref="IApplication"/> instance this view is running in.
+    /// </summary>
+    public IApplication? App
+    {
+        get => _app ?? SuperView?.App;
+        internal set => _app = value;
+    }
+
     private IDriver? _driver;
     private IDriver? _driver;
 
 
     /// <summary>
     /// <summary>
@@ -117,15 +131,7 @@ public partial class View : IDisposable, ISupportInitializeNotification
     /// </summary>
     /// </summary>
     internal IDriver? Driver
     internal IDriver? Driver
     {
     {
-        get
-        {
-            if (_driver is { })
-            {
-                return _driver;
-            }
-
-            return Application.Driver;
-        }
+        get => _driver ?? Application.Driver;
         set => _driver = value;
         set => _driver = value;
     }
     }
 
 

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

@@ -1,5 +1,3 @@
-
-
 namespace Terminal.Gui.Views;
 namespace Terminal.Gui.Views;
 
 
 /// <summary>
 /// <summary>

+ 1 - 1
Tests/UnitTests/Application/ApplicationPopoverTests.cs

@@ -207,7 +207,7 @@ public class ApplicationPopoverTests
             Application.Popover?.Register (popover);
             Application.Popover?.Register (popover);
 
 
             // Assert
             // Assert
-            Assert.Equal (Application.Current, popover.Toplevel);
+            Assert.Equal (Application.Current, popover.Current);
         }
         }
         finally
         finally
         {
         {

+ 1 - 1
Tests/UnitTestsParallelizable/Application/ApplicationPopoverTests.cs

@@ -181,6 +181,6 @@ public class ApplicationPopoverTests
         }
         }
 
 
         /// <inheritdoc />
         /// <inheritdoc />
-        public Toplevel? Toplevel { get; set; }
+        public Toplevel? Current { get; set; }
     }
     }
 }
 }

+ 2 - 2
Tests/UnitTestsParallelizable/Application/PopoverBaseImplTests.cs

@@ -27,8 +27,8 @@ public class PopoverBaseImplTests
     {
     {
         var popover = new TestPopover ();
         var popover = new TestPopover ();
         var top = new Toplevel ();
         var top = new Toplevel ();
-        popover.Toplevel = top;
-        Assert.Same (top, popover.Toplevel);
+        popover.Current = top;
+        Assert.Same (top, popover.Current);
     }
     }
 
 
     [Fact]
     [Fact]