mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-29 17:28:01 +01:00
Rename to SubscribeDriverEvents and add UnsubscribeDriverEvents method.
This commit is contained in:
@@ -150,6 +150,7 @@ public static partial class Application // Initialization (Init/Shutdown)
|
||||
try
|
||||
{
|
||||
MainLoop = Driver!.Init ();
|
||||
SubscribeDriverEvents ();
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
@@ -163,8 +164,6 @@ public static partial class Application // Initialization (Init/Shutdown)
|
||||
);
|
||||
}
|
||||
|
||||
InitState ();
|
||||
|
||||
SynchronizationContext.SetSynchronizationContext (new MainLoopSyncContext ());
|
||||
|
||||
SupportedCultures = GetSupportedCultures ();
|
||||
@@ -173,7 +172,7 @@ public static partial class Application // Initialization (Init/Shutdown)
|
||||
InitializedChanged?.Invoke (null, new (init));
|
||||
}
|
||||
|
||||
internal static void InitState ()
|
||||
internal static void SubscribeDriverEvents ()
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull (Driver);
|
||||
|
||||
@@ -183,6 +182,14 @@ public static partial class Application // Initialization (Init/Shutdown)
|
||||
Driver.MouseEvent += Driver_MouseEvent;
|
||||
}
|
||||
|
||||
internal static void UnsubscribeDriverEvents ()
|
||||
{
|
||||
Driver.SizeChanged -= Driver_SizeChanged;
|
||||
Driver.KeyDown -= Driver_KeyDown;
|
||||
Driver.KeyUp -= Driver_KeyUp;
|
||||
Driver.MouseEvent -= Driver_MouseEvent;
|
||||
}
|
||||
|
||||
private static void Driver_SizeChanged (object? sender, SizeChangedEventArgs e) { OnSizeChanging (e); }
|
||||
private static void Driver_KeyDown (object? sender, Key e) { RaiseKeyDownEvent (e); }
|
||||
private static void Driver_KeyUp (object? sender, Key e) { RaiseKeyUpEvent (e); }
|
||||
|
||||
@@ -177,10 +177,7 @@ public static partial class Application
|
||||
// Driver stuff
|
||||
if (Driver is { })
|
||||
{
|
||||
Driver.SizeChanged -= Driver_SizeChanged;
|
||||
Driver.KeyDown -= Driver_KeyDown;
|
||||
Driver.KeyUp -= Driver_KeyUp;
|
||||
Driver.MouseEvent -= Driver_MouseEvent;
|
||||
UnsubscribeDriverEvents ();
|
||||
Driver?.End ();
|
||||
Driver = null;
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class ApplicationScreenTests (ITestOutputHelper output)
|
||||
Application.ResetState (true);
|
||||
Assert.Null (Application.Driver);
|
||||
Application.Driver = new FakeDriver { Rows = 25, Cols = 25 };
|
||||
Application.InitState ();
|
||||
Application.SubscribeDriverEvents ();
|
||||
Assert.Equal (new (0, 0, 25, 25), Application.Screen);
|
||||
|
||||
// Act
|
||||
|
||||
@@ -644,7 +644,7 @@ public class ApplicationTests
|
||||
[Fact]
|
||||
public void InitState_Throws_If_Driver_Is_Null ()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException> (static () => Application.InitState ());
|
||||
Assert.Throws<ArgumentNullException> (static () => Application.SubscribeDriverEvents ());
|
||||
}
|
||||
|
||||
private void Init ()
|
||||
|
||||
@@ -212,7 +212,7 @@ public class SetupFakeDriverAttribute : BeforeAfterTestAttribute
|
||||
Application.Driver = new FakeDriver { Rows = 25, Cols = 25 };
|
||||
Assert.Equal (new (0, 0, 25, 25), Application.Screen);
|
||||
// Ensures subscribing events, at least for the SizeChanged event
|
||||
Application.InitState ();
|
||||
Application.SubscribeDriverEvents ();
|
||||
|
||||
base.Before (methodUnderTest);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user