File tree 2 files changed +67
-0
lines changed
Terminal.Gui/ConsoleDrivers/V2
Tests/UnitTests/ConsoleDrivers/V2
2 files changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -194,6 +194,23 @@ public override void RequestStop (Toplevel? top)
194
194
{
195
195
Logging . Logger . LogInformation ( $ "RequestStop '{ top } '") ;
196
196
197
+ top ??= Application . Top ;
198
+
199
+ if ( top == null )
200
+ {
201
+ return ;
202
+ }
203
+
204
+ var ev = new ToplevelClosingEventArgs ( top ) ;
205
+ top . OnClosing ( ev ) ;
206
+
207
+ if ( ev . Cancel )
208
+ {
209
+ return ;
210
+ }
211
+
212
+ top . Running = false ;
213
+
197
214
// TODO: This definition of stop seems sketchy
198
215
Application . TopLevels . TryPop ( out _ ) ;
199
216
@@ -205,6 +222,9 @@ public override void RequestStop (Toplevel? top)
205
222
{
206
223
Application . Top = null ;
207
224
}
225
+
226
+ // Notify that it is closed
227
+ top . OnClosed ( top ) ;
208
228
}
209
229
210
230
/// <inheritdoc/>
Original file line number Diff line number Diff line change @@ -221,6 +221,53 @@ public void Test_InitRunShutdown_Generic_IdleForExit ()
221
221
222
222
ApplicationImpl . ChangeInstance ( orig ) ;
223
223
}
224
+
225
+ [ Fact ]
226
+ public void Test_V2_ClosingRaised ( )
227
+ {
228
+ var orig = ApplicationImpl . Instance ;
229
+
230
+ var v2 = NewApplicationV2 ( ) ;
231
+ ApplicationImpl . ChangeInstance ( v2 ) ;
232
+
233
+ v2 . Init ( ) ;
234
+
235
+ int closing = 0 ;
236
+ int closed = 0 ;
237
+ var t = new Toplevel ( ) ;
238
+ t . Closing
239
+ += ( _ , a ) =>
240
+ {
241
+ // Cancel the first time
242
+ if ( closing == 0 )
243
+ {
244
+ a . Cancel = true ;
245
+ }
246
+ closing ++ ;
247
+ Assert . Same ( t , a . RequestingTop ) ;
248
+ } ;
249
+
250
+ t . Closed
251
+ += ( _ , a ) =>
252
+ {
253
+ closed ++ ;
254
+ Assert . Same ( t , a . Toplevel ) ;
255
+ } ;
256
+
257
+ v2 . AddIdle ( IdleExit ) ;
258
+
259
+ // Blocks until the timeout call is hit
260
+
261
+ v2 . Run ( t ) ;
262
+
263
+ Assert . Null ( Application . Top ) ;
264
+ v2 . Shutdown ( ) ;
265
+
266
+ ApplicationImpl . ChangeInstance ( orig ) ;
267
+
268
+ Assert . Equal ( 2 , closing ) ;
269
+ Assert . Equal ( 1 , closed ) ;
270
+ }
224
271
private bool IdleExit ( )
225
272
{
226
273
if ( Application . Top != null )
You can’t perform that action at this time.
0 commit comments