Skip to content

Commit b1a8ca7

Browse files
committed
Update CanExecute logic for (i|uni)gnore commands
1 parent 332b963 commit b1a8ca7

File tree

3 files changed

+63
-59
lines changed

3 files changed

+63
-59
lines changed

-multiinst

Whitespace-only changes.

Rubberduck.Core/UI/UnitTesting/TestExplorerControl.xaml

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -437,46 +437,45 @@
437437
<Image Source="{StaticResource RunAllTestsImage}" />
438438
</MenuItem.Icon>
439439
</MenuItem>
440+
441+
<Separator/>
442+
440443
<MenuItem Command="{Binding IgnoreTestCommand}"
441-
Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_TestToggle_Ignore}"
442-
Visibility="{Binding DisplayIgnoreTestLabel, Converter={StaticResource BoolToVisibility}}">
444+
Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_TestToggle_Ignore}" >
443445
<MenuItem.Icon>
444446
<Image Source="{StaticResource IgnoreTestImage}" />
445447
</MenuItem.Icon>
446448
</MenuItem>
447449
<MenuItem Command="{Binding UnignoreTestCommand}"
448-
Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_TestToggle_Unignore}"
449-
Visibility="{Binding DisplayUnignoreTestLabel, Converter={StaticResource BoolToVisibility}}">
450+
Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_TestToggle_Unignore}" >
450451
<MenuItem.Icon>
451452
<Image Source="{StaticResource UnignoreTestImage}" />
452453
</MenuItem.Icon>
453454
</MenuItem>
454-
455+
456+
<MenuItem Command="{Binding IgnoreSelectedTestsCommand}"
457+
CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItems}"
458+
Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_ContextMenuIgnoreSelectedTests}" >
459+
<MenuItem.Icon>
460+
<Image Source="{StaticResource IgnoreTestImage}" />
461+
</MenuItem.Icon>
462+
</MenuItem>
463+
<MenuItem Command="{Binding UnignoreSelectedTestsCommand}"
464+
CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItems}"
465+
Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_ContextMenuUnignoreSelectedTests}" >
466+
<MenuItem.Icon>
467+
<Image Source="{StaticResource UnignoreTestImage}" />
468+
</MenuItem.Icon>
469+
</MenuItem>
470+
455471
<MenuItem Command="{Binding IgnoreGroupCommand}"
456-
Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_ContextMenuIgnoreGroup}"
457-
Visibility="{Binding DisplayIgnoreGroupLabel, Converter={StaticResource BoolToVisibility}}">
472+
Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_ContextMenuIgnoreGroup}" >
458473
<MenuItem.Icon>
459474
<Image Source="{StaticResource IgnoreTestImage}" />
460475
</MenuItem.Icon>
461476
</MenuItem>
462-
<MenuItem Command="{Binding UnignoreGroupCommand}"
463-
Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_ContextMenuUnignoreGroup}"
464-
Visibility="{Binding DisplayUnignoreGroupLabel, Converter={StaticResource BoolToVisibility}}">
465-
<MenuItem.Icon>
466-
<Image Source="{StaticResource UnignoreTestImage}" />
467-
</MenuItem.Icon>
468-
</MenuItem>
469-
470-
<MenuItem Command="{Binding IgnoreSelectedTestsCommand}"
471-
CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItems}"
472-
Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_ContextMenuIgnoreSelectedTests}" >
473-
<MenuItem.Icon>
474-
<Image Source="{StaticResource IgnoreTestImage}" />
475-
</MenuItem.Icon>
476-
</MenuItem>
477-
<MenuItem Command="{Binding UnignoreSelectedTestsCommand}"
478-
CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItems}"
479-
Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_ContextMenuUnignoreSelectedTests}" >
477+
<MenuItem Command="{Binding UnignoreGroupCommand}"
478+
Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_ContextMenuUnignoreGroup}" >
480479
<MenuItem.Icon>
481480
<Image Source="{StaticResource UnignoreTestImage}" />
482481
</MenuItem.Icon>

Rubberduck.Core/UI/UnitTesting/TestExplorerViewModel.cs

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4+
using System.Collections.ObjectModel;
45
using System.ComponentModel;
56
using System.Globalization;
67
using System.Linq;
@@ -66,20 +67,20 @@ public TestExplorerViewModel(ISelectionService selectionService,
6667

6768
NavigateCommand = new NavigateCommand(selectionService);
6869
RunSingleTestCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteSingleTestCommand, CanExecuteSingleTest);
69-
RunSelectedTestsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteSelectedTestsCommand, CanExecuteSelectionCommand);
70+
RunSelectedTestsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteSelectedTestsCommand, CanExecuteSelectedCommands);
7071
RunSelectedGroupCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteRunSelectedGroupCommand, CanExecuteGroupCommand);
7172
CancelTestRunCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteCancelTestRunCommand, CanExecuteCancelTestRunCommand);
7273
ResetResultsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteResetResultsCommand, CanExecuteResetResultsCommand);
7374
CopyResultsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteCopyResultsCommand);
7475
OpenTestSettingsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), OpenSettings);
7576
CollapseAllCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteCollapseAll);
7677
ExpandAllCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteExpandAll);
77-
IgnoreTestCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteIgnoreTestCommand);
78-
UnignoreTestCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteUnignoreTestCommand);
79-
IgnoreGroupCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteIgnoreGroupCommand, CanExecuteGroupCommand);
80-
UnignoreGroupCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteUnignoreGroupCommand, CanExecuteGroupCommand);
81-
IgnoreSelectedTestsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteIgnoreSelectedTestsCommand, CanExecuteSelectionCommand);
82-
UnignoreSelectedTestsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteUnignoreSelectedTestsCommand, CanExecuteSelectionCommand);
78+
IgnoreTestCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteIgnoreTestCommand, CanExecuteIgnoreTestCommand);
79+
UnignoreTestCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteUnignoreTestCommand, CanExecuteUnignoreTestCommand);
80+
IgnoreSelectedTestsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteIgnoreSelectedTestsCommand, CanExecuteIgnoreSelectedTests);
81+
UnignoreSelectedTestsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteUnignoreSelectedTestsCommand, CanExecuteUnignoreSelectedTests);
82+
IgnoreGroupCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteIgnoreGroupCommand, CanExecuteIgnoreGroupCommand);
83+
UnignoreGroupCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteUnignoreGroupCommand, CanExecuteUnignoreGroupCommand);
8384

8485
RewritingManager = rewritingManager;
8586
AnnotationUpdater = annotationUpdater;
@@ -140,10 +141,10 @@ public CollectionViewGroup MouseOverGroup
140141

141142
private void RefreshContextMenu()
142143
{
143-
OnPropertyChanged(nameof(DisplayUnignoreTestLabel));
144-
OnPropertyChanged(nameof(DisplayIgnoreTestLabel));
145-
OnPropertyChanged(nameof(DisplayUnignoreGroupLabel));
146-
OnPropertyChanged(nameof(DisplayIgnoreGroupLabel));
144+
OnPropertyChanged(nameof(CanExecuteUnignoreTestCommand));
145+
OnPropertyChanged(nameof(CanExecuteIgnoreTestCommand));
146+
OnPropertyChanged(nameof(CanExecuteUnignoreGroupCommand));
147+
OnPropertyChanged(nameof(CanExecuteIgnoreGroupCommand));
147148
}
148149

149150
private static readonly Dictionary<TestExplorerGrouping, PropertyGroupDescription> GroupDescriptions = new Dictionary<TestExplorerGrouping, PropertyGroupDescription>
@@ -247,37 +248,41 @@ private void HandleTestCompletion(object sender, TestCompletedEventArgs e)
247248
public IAnnotationUpdater AnnotationUpdater { get; }
248249

249250
private TestMethod _mousedOverTestMethod => ((TestMethodViewModel)SelectedItem).Method;
250-
public bool DisplayUnignoreTestLabel => SelectedItem != null && _mousedOverTestMethod.IsIgnored;
251-
public bool DisplayIgnoreTestLabel => SelectedItem != null && !_mousedOverTestMethod.IsIgnored;
251+
public bool CanExecuteUnignoreTestCommand(object obj) => SelectedItem != null && _mousedOverTestMethod.IsIgnored;
252+
public bool CanExecuteIgnoreTestCommand(object obj) => SelectedItem != null && !_mousedOverTestMethod.IsIgnored;
252253

253-
public bool DisplayUnignoreGroupLabel
254+
public bool CanExecuteIgnoreSelectedTests(object obj)
254255
{
255-
get
256+
if (!Model.IsBusy && obj is IList viewModels && viewModels.Count > 0)
256257
{
257-
if (MouseOverGroup?.Items == null)
258-
{
259-
return false;
260-
}
261-
262-
var testsInGroup = MouseOverGroup.Items.Cast<TestMethodViewModel>();
258+
return viewModels.Cast<TestMethodViewModel>().Count(test => test.Method.IsIgnored) != viewModels.Count;
259+
}
263260

264-
return testsInGroup.Any(test => test.Method.IsIgnored);
261+
return false;
262+
}
263+
public bool CanExecuteUnignoreSelectedTests(object obj)
264+
{
265+
if (!Model.IsBusy && obj is IList viewModels && viewModels.Count > 0)
266+
{
267+
return viewModels.Cast<TestMethodViewModel>().Any(test => test.Method.IsIgnored);
265268
}
269+
270+
return false;
266271
}
267272

268-
public bool DisplayIgnoreGroupLabel
273+
public bool CanExecuteIgnoreGroupCommand(object obj)
269274
{
270-
get
271-
{
272-
if (MouseOverGroup?.Items == null)
273-
{
274-
return false;
275-
}
275+
var groupItems = MouseOverGroup?.Items
276+
?? GroupContainingSelectedTest(MouseOverTest).Items;
276277

277-
var testsInGroup = MouseOverGroup.Items.Cast<TestMethodViewModel>();
278+
return groupItems.Cast<TestMethodViewModel>().Count(test => test.Method.IsIgnored) != groupItems.Count;
279+
}
280+
public bool CanExecuteUnignoreGroupCommand(object obj)
281+
{
282+
var groupItems = MouseOverGroup?.Items
283+
?? GroupContainingSelectedTest(MouseOverTest).Items;
278284

279-
return testsInGroup.Count(test => test.Method.IsIgnored) != MouseOverGroup.ItemCount;
280-
}
285+
return groupItems.Cast<TestMethodViewModel>().Any(test => test.Method.IsIgnored);
281286
}
282287

283288
#region Commands
@@ -329,7 +334,7 @@ private bool CanExecuteSingleTest(object obj)
329334
return !Model.IsBusy && MouseOverTest != null;
330335
}
331336

332-
private bool CanExecuteSelectionCommand(object obj)
337+
private bool CanExecuteSelectedCommands(object obj)
333338
{
334339
return !Model.IsBusy && obj is IList viewModels && viewModels.Count > 0;
335340
}
@@ -452,7 +457,7 @@ private void ExecuteUnignoreTestCommand(object parameter)
452457
rewriteSession.TryRewrite();
453458
}
454459

455-
private void ExecuteIgnoreGroupCommand (object parameter)
460+
private void ExecuteIgnoreGroupCommand(object parameter)
456461
{
457462
var rewriteSession = RewritingManager.CheckOutCodePaneSession();
458463
var testGroup = GroupContainingSelectedTest(MouseOverTest);

0 commit comments

Comments
 (0)