@@ -246,71 +246,75 @@ public void MouseClick_CheckBox_CommandView_Raises_Shortcut_Accepted_Selected_Co
246
246
}
247
247
248
248
[ Theory ]
249
- [ InlineData ( true , KeyCode . A , 1 , 1 ) ]
250
- [ InlineData ( true , KeyCode . C , 1 , 1 ) ]
251
- [ InlineData ( true , KeyCode . C | KeyCode . AltMask , 1 , 1 ) ]
252
- [ InlineData ( true , KeyCode . Enter , 1 , 1 ) ]
253
- [ InlineData ( true , KeyCode . Space , 1 , 1 ) ]
254
- [ InlineData ( true , KeyCode . F1 , 0 , 0 ) ]
255
- [ InlineData ( false , KeyCode . A , 1 , 1 ) ]
256
- [ InlineData ( false , KeyCode . C , 1 , 1 ) ]
257
- [ InlineData ( false , KeyCode . C | KeyCode . AltMask , 1 , 1 ) ]
258
- [ InlineData ( false , KeyCode . Enter , 0 , 0 ) ]
259
- [ InlineData ( false , KeyCode . Space , 0 , 0 ) ]
260
- [ InlineData ( false , KeyCode . F1 , 0 , 0 ) ]
261
- public void KeyDown_Raises_Accepted_Selected ( bool canFocus , KeyCode key , int expectedAccept , int expectedSelect )
249
+ [ InlineData ( true , KeyCode . A , 1 , 0 ) ] // CanFocus: Shortcut.key should activate and not Accept
250
+ [ InlineData ( true , KeyCode . C , 1 , 0 ) ] // CanFocus: CommandView.HotKey should activate and not Accept
251
+ [ InlineData ( true , KeyCode . C | KeyCode . AltMask , 1 , 0 ) ] // CanFocus: CommandView.HotKey should activate and not Accept
252
+ [ InlineData ( true , KeyCode . Enter , 1 , 1 ) ] // CanFocus: Enter should Activate and Accept
253
+ [ InlineData ( true , KeyCode . Space , 1 , 0 ) ] // CanFocus: Space should Activate and not Accept
254
+ [ InlineData ( true , KeyCode . F1 , 0 , 0 ) ] // CanFocus: Other key should do nothing
255
+ [ InlineData ( false , KeyCode . A , 1 , 0 ) ] // !CanFocus: Shortcut.key should Activate and not Accept
256
+ [ InlineData ( false , KeyCode . C , 1 , 0 ) ] // !CanFocus: CommandView.HotKey should Activate and not Accept
257
+ [ InlineData ( false , KeyCode . C | KeyCode . AltMask , 1 , 0 ) ] // !CanFocus: CommandView.HotKey should Activate and not Accept
258
+ [ InlineData ( false , KeyCode . Enter , 0 , 0 ) ] // !CanFocus: Enter should do nothing
259
+ [ InlineData ( false , KeyCode . Space , 0 , 0 ) ] // !CanFocus: Space should do nothing
260
+ [ InlineData ( false , KeyCode . F1 , 0 , 0 ) ] // !CanFocus: Other key should do nothing
261
+ public void KeyDown_Raises_Accepting_And_Activating_Correctly ( bool canFocus , KeyCode key , int expectedActivating , int expectedAccepting )
262
262
{
263
263
Application . Top = new ( ) ;
264
264
265
265
var shortcut = new Shortcut
266
266
{
267
267
Key = Key . A ,
268
- Text = "0" ,
269
268
Title = "_C" ,
270
269
CanFocus = canFocus
271
270
} ;
272
271
Application . Top . Add ( shortcut ) ;
273
272
shortcut . SetFocus ( ) ;
274
273
275
274
Assert . Equal ( canFocus , shortcut . HasFocus ) ;
275
+ // By default CommandView gets CanFocus set to false, so the CB will never have focus
276
+ Assert . Equal ( shortcut , Application . Top . MostFocused ) ;
276
277
277
- var accepted = 0 ;
278
- shortcut . Accepting += ( s , e ) => accepted ++ ;
278
+ var accepting = 0 ;
279
+ shortcut . Accepting += ( s , e ) =>
280
+ {
281
+ accepting ++ ;
282
+ e . Handled = true ;
283
+ } ;
279
284
280
- var selected = 0 ;
281
- shortcut . Activating += ( s , e ) => selected ++ ;
285
+ var activating = 0 ;
286
+ shortcut . Activating += ( s , e ) => activating ++ ;
282
287
283
288
Application . RaiseKeyDownEvent ( key ) ;
284
-
285
- Assert . Equal ( expectedAccept , accepted ) ;
286
- Assert . Equal ( expectedSelect , selected ) ;
287
-
288
289
Application . Top . Dispose ( ) ;
289
290
Application . ResetState ( true ) ;
291
+
292
+ Assert . Equal ( expectedActivating , activating ) ;
293
+ Assert . Equal ( expectedAccepting , accepting ) ;
290
294
}
291
295
292
296
293
297
[ Theory ]
294
- [ InlineData ( true , KeyCode . A , 1 , 1 ) ]
295
- [ InlineData ( true , KeyCode . C , 1 , 1 ) ]
296
- [ InlineData ( true , KeyCode . C | KeyCode . AltMask , 1 , 1 ) ]
297
- [ InlineData ( true , KeyCode . Enter , 1 , 1 ) ]
298
- [ InlineData ( true , KeyCode . Space , 0 , 1 ) ]
299
- [ InlineData ( true , KeyCode . F1 , 0 , 0 ) ]
300
- [ InlineData ( false , KeyCode . A , 1 , 1 ) ]
301
- [ InlineData ( false , KeyCode . C , 1 , 1 ) ]
302
- [ InlineData ( false , KeyCode . C | KeyCode . AltMask , 1 , 1 ) ]
303
- [ InlineData ( false , KeyCode . Enter , 0 , 0 ) ]
304
- [ InlineData ( false , KeyCode . Space , 0 , 0 ) ]
305
- [ InlineData ( false , KeyCode . F1 , 0 , 0 ) ]
306
- public void KeyDown_CheckBox_Raises_Accepted_Activated ( bool canFocus , KeyCode key , int expectedAccept , int expectedActivate )
298
+ [ InlineData ( true , KeyCode . A , 1 , 0 ) ] // CanFocus: Shortcut.key should activate and not Accept
299
+ [ InlineData ( true , KeyCode . C , 1 , 0 ) ] // CanFocus: CommandView.HotKey should activate and not Accept
300
+ [ InlineData ( true , KeyCode . C | KeyCode . AltMask , 1 , 0 ) ] // CanFocus: CommandView.HotKey should activate and not Accept
301
+ [ InlineData ( true , KeyCode . Enter , 1 , 1 ) ] // CanFocus: Enter should Activate and Accept
302
+ [ InlineData ( true , KeyCode . Space , 1 , 0 ) ] // CanFocus: Space should Activate and not Accept
303
+ [ InlineData ( true , KeyCode . F1 , 0 , 0 ) ] // CanFocus: Other key should do nothing
304
+ [ InlineData ( false , KeyCode . A , 1 , 0 ) ] // !CanFocus: Shortcut.key should Activate and not Accept
305
+ [ InlineData ( false , KeyCode . C , 1 , 0 ) ] // !CanFocus: CommandView.HotKey should Activate and not Accept
306
+ [ InlineData ( false , KeyCode . C | KeyCode . AltMask , 1 , 0 ) ] // !CanFocus: CommandView.HotKey should Activate and not Accept
307
+ [ InlineData ( false , KeyCode . Enter , 0 , 0 ) ] // !CanFocus: Enter should do nothing
308
+ [ InlineData ( false , KeyCode . Space , 0 , 0 ) ] // !CanFocus: Space should do nothing
309
+ [ InlineData ( false , KeyCode . F1 , 0 , 0 ) ] // !CanFocus: Other key should do nothing
310
+ public void With_NotCanFocusCheckBox_CommandView_KeyDown_Raises_Accepting_And_Activating_Correctly ( bool canFocus , KeyCode key , int expectedActivating , int expectedAccepting )
307
311
{
308
312
Application . Top = new ( ) ;
309
313
314
+ // Shortcut with Key = Key.A and CommandView Hotkey = Key.C
310
315
var shortcut = new Shortcut
311
316
{
312
317
Key = Key . A ,
313
- Text = "0" ,
314
318
CommandView = new CheckBox ( )
315
319
{
316
320
Title = "_C" ,
@@ -324,23 +328,79 @@ public void KeyDown_CheckBox_Raises_Accepted_Activated (bool canFocus, KeyCode k
324
328
// By default CommandView gets CanFocus set to false, so the CB will never have focus
325
329
Assert . Equal ( shortcut , Application . Top . MostFocused ) ;
326
330
327
- var accepted = 0 ;
331
+ var accepting = 0 ;
328
332
shortcut . Accepting += ( s , e ) =>
329
333
{
330
- accepted ++ ;
334
+ accepting ++ ;
331
335
e . Handled = true ;
332
336
} ;
333
337
334
- var activated = 0 ;
335
- shortcut . Activating += ( s , e ) => activated ++ ;
338
+ var activating = 0 ;
339
+ shortcut . Activating += ( s , e ) => activating ++ ;
336
340
337
341
Application . RaiseKeyDownEvent ( key ) ;
342
+ Application . Top . Dispose ( ) ;
343
+ Application . ResetState ( true ) ;
338
344
339
- Assert . Equal ( expectedAccept , accepted ) ;
340
- Assert . Equal ( expectedActivate , activated ) ;
345
+ Assert . Equal ( expectedActivating , activating ) ;
346
+ Assert . Equal ( expectedAccepting , accepting ) ;
347
+
348
+ }
349
+
350
+
351
+ [ Theory ]
352
+ [ InlineData ( true , KeyCode . A , 1 , 0 ) ] // CanFocus: Shortcut.key should activate and not Accept
353
+ [ InlineData ( true , KeyCode . C , 1 , 0 ) ] // CanFocus: CommandView.HotKey should activate and not Accept
354
+ [ InlineData ( true , KeyCode . C | KeyCode . AltMask , 1 , 0 ) ] // CanFocus: CommandView.HotKey should activate and not Accept
355
+ [ InlineData ( true , KeyCode . Enter , 1 , 1 ) ] // CanFocus: Enter should Activate and Accept
356
+ [ InlineData ( true , KeyCode . Space , 1 , 0 ) ] // CanFocus: Space should Activate and not Accept
357
+ [ InlineData ( true , KeyCode . F1 , 0 , 0 ) ] // CanFocus: Other key should do nothing
358
+ [ InlineData ( false , KeyCode . A , 1 , 0 ) ] // !CanFocus: Shortcut.key should Activate and not Accept
359
+ [ InlineData ( false , KeyCode . C , 1 , 0 ) ] // !CanFocus: CommandView.HotKey should Activate and not Accept
360
+ [ InlineData ( false , KeyCode . C | KeyCode . AltMask , 1 , 0 ) ] // !CanFocus: CommandView.HotKey should Activate and not Accept
361
+ [ InlineData ( false , KeyCode . Enter , 0 , 0 ) ] // !CanFocus: Enter should do nothing
362
+ [ InlineData ( false , KeyCode . Space , 0 , 0 ) ] // !CanFocus: Space should do nothing
363
+ [ InlineData ( false , KeyCode . F1 , 0 , 0 ) ] // !CanFocus: Other key should do nothing
364
+ public void With_CanFocusCheckBox_CommandView_KeyDown_Raises_Accepting_And_Activating_Correctly ( bool canFocus , KeyCode key , int expectedActivating , int expectedAccepting )
365
+ {
366
+ Application . Top = new ( ) ;
367
+
368
+ // Shortcut with Key = Key.A and CommandView Hotkey = Key.C
369
+ var shortcut = new Shortcut
370
+ {
371
+ Key = Key . A ,
372
+ HelpText = "0" ,
373
+ CommandView = new CheckBox ( )
374
+ {
375
+ Title = "_C" ,
376
+ } ,
377
+ CanFocus = canFocus
378
+ } ;
379
+ shortcut . CommandView . CanFocus = true ;
380
+
381
+ Application . Top . Add ( shortcut ) ;
382
+ shortcut . SetFocus ( ) ;
383
+
384
+ Assert . Equal ( canFocus , shortcut . HasFocus ) ;
385
+ Assert . Equal ( shortcut . CommandView , Application . Top . MostFocused ) ;
386
+
387
+ var accepting = 0 ;
388
+ shortcut . Accepting += ( s , e ) =>
389
+ {
390
+ accepting ++ ;
391
+ e . Handled = true ;
392
+ } ;
341
393
394
+ var activating = 0 ;
395
+ shortcut . Activating += ( s , e ) => activating ++ ;
396
+
397
+ Application . RaiseKeyDownEvent ( key ) ;
342
398
Application . Top . Dispose ( ) ;
343
399
Application . ResetState ( true ) ;
400
+
401
+ Assert . Equal ( expectedActivating , activating ) ;
402
+ Assert . Equal ( expectedAccepting , accepting ) ;
403
+
344
404
}
345
405
[ Theory ]
346
406
[ InlineData ( KeyCode . A , 1 ) ]
@@ -349,29 +409,32 @@ public void KeyDown_CheckBox_Raises_Accepted_Activated (bool canFocus, KeyCode k
349
409
[ InlineData ( KeyCode . Enter , 1 ) ]
350
410
[ InlineData ( KeyCode . Space , 1 ) ]
351
411
[ InlineData ( KeyCode . F1 , 0 ) ]
352
- public void KeyDown_App_Scope_Invokes_Accept ( KeyCode key , int expectedAccept )
412
+ public void KeyDown_App_Scope_Invokes_Activating ( KeyCode key , int expectedActivating )
353
413
{
354
414
Application . Top = new ( ) ;
355
415
356
416
var shortcut = new Shortcut
357
417
{
358
418
Key = Key . A ,
359
419
BindKeyToApplication = true ,
360
- Text = "0" ,
361
420
Title = "_C"
362
421
} ;
363
422
Application . Top . Add ( shortcut ) ;
364
423
Application . Top . SetFocus ( ) ;
365
424
366
- var accepted = 0 ;
367
- shortcut . Accepting += ( s , e ) => accepted ++ ;
368
-
369
- Application . RaiseKeyDownEvent ( key ) ;
425
+ var activating = 0 ;
426
+ shortcut . Activating += ( s , e ) => activating ++ ;
370
427
371
- Assert . Equal ( expectedAccept , accepted ) ;
428
+ var accepting = 0 ;
429
+ shortcut . Accepting += ( s , e ) => accepting ++ ;
372
430
431
+ Application . RaiseKeyDownEvent ( key ) ;
373
432
Application . Top . Dispose ( ) ;
374
433
Application . ResetState ( true ) ;
434
+
435
+ Assert . Equal ( expectedActivating , activating ) ;
436
+ Assert . Equal ( 0 , accepting ) ;
437
+
375
438
}
376
439
377
440
[ Theory ]
0 commit comments