Skip to content

Commit be07f5a

Browse files
committed
Rename to SubscribeDriverEvents and add UnsubscribeDriverEvents method.
1 parent 0832bab commit be07f5a

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

Terminal.Gui/Application/Application.Initialization.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ internal static void InternalInit (
150150
try
151151
{
152152
MainLoop = Driver!.Init ();
153+
SubscribeDriverEvents ();
153154
}
154155
catch (InvalidOperationException ex)
155156
{
@@ -163,8 +164,6 @@ internal static void InternalInit (
163164
);
164165
}
165166

166-
InitState ();
167-
168167
SynchronizationContext.SetSynchronizationContext (new MainLoopSyncContext ());
169168

170169
SupportedCultures = GetSupportedCultures ();
@@ -173,7 +172,7 @@ internal static void InternalInit (
173172
InitializedChanged?.Invoke (null, new (init));
174173
}
175174

176-
internal static void InitState ()
175+
internal static void SubscribeDriverEvents ()
177176
{
178177
ArgumentNullException.ThrowIfNull (Driver);
179178

@@ -183,6 +182,14 @@ internal static void InitState ()
183182
Driver.MouseEvent += Driver_MouseEvent;
184183
}
185184

185+
internal static void UnsubscribeDriverEvents ()
186+
{
187+
Driver.SizeChanged -= Driver_SizeChanged;
188+
Driver.KeyDown -= Driver_KeyDown;
189+
Driver.KeyUp -= Driver_KeyUp;
190+
Driver.MouseEvent -= Driver_MouseEvent;
191+
}
192+
186193
private static void Driver_SizeChanged (object? sender, SizeChangedEventArgs e) { OnSizeChanging (e); }
187194
private static void Driver_KeyDown (object? sender, Key e) { RaiseKeyDownEvent (e); }
188195
private static void Driver_KeyUp (object? sender, Key e) { RaiseKeyUpEvent (e); }

Terminal.Gui/Application/Application.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,7 @@ internal static void ResetState (bool ignoreDisposed = false)
177177
// Driver stuff
178178
if (Driver is { })
179179
{
180-
Driver.SizeChanged -= Driver_SizeChanged;
181-
Driver.KeyDown -= Driver_KeyDown;
182-
Driver.KeyUp -= Driver_KeyUp;
183-
Driver.MouseEvent -= Driver_MouseEvent;
180+
UnsubscribeDriverEvents ();
184181
Driver?.End ();
185182
Driver = null;
186183
}

UnitTests/Application/ApplicationScreenTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void Screen_Changes_OnSizeChanged_Without_Call_Application_Init ()
7373
Application.ResetState (true);
7474
Assert.Null (Application.Driver);
7575
Application.Driver = new FakeDriver { Rows = 25, Cols = 25 };
76-
Application.InitState ();
76+
Application.SubscribeDriverEvents ();
7777
Assert.Equal (new (0, 0, 25, 25), Application.Screen);
7878

7979
// Act

UnitTests/Application/ApplicationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ public void Screen_Size_Changes ()
644644
[Fact]
645645
public void InitState_Throws_If_Driver_Is_Null ()
646646
{
647-
Assert.Throws<ArgumentNullException> (static () => Application.InitState ());
647+
Assert.Throws<ArgumentNullException> (static () => Application.SubscribeDriverEvents ());
648648
}
649649

650650
private void Init ()

UnitTests/TestHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public override void Before (MethodInfo methodUnderTest)
212212
Application.Driver = new FakeDriver { Rows = 25, Cols = 25 };
213213
Assert.Equal (new (0, 0, 25, 25), Application.Screen);
214214
// Ensures subscribing events, at least for the SizeChanged event
215-
Application.InitState ();
215+
Application.SubscribeDriverEvents ();
216216

217217
base.Before (methodUnderTest);
218218
}

0 commit comments

Comments
 (0)