44using System . ComponentModel ;
55using System . Globalization ;
66using System . Linq ;
7+ using System . Windows . Annotations ;
78using System . Windows . Data ;
89using NLog ;
910using Rubberduck . Common ;
1011using Rubberduck . Interaction . Navigation ;
12+ using Rubberduck . Parsing ;
13+ using Rubberduck . Parsing . Rewriter ;
14+ using Rubberduck . Parsing . VBA ;
15+ using Rubberduck . Resources ;
1116using Rubberduck . Settings ;
1217using Rubberduck . SettingsProvider ;
1318using Rubberduck . UI . Command ;
@@ -49,7 +54,9 @@ public TestExplorerViewModel(ISelectionService selectionService,
4954 IClipboardWriter clipboard ,
5055 // ReSharper disable once UnusedParameter.Local - left in place because it will likely be needed for app wide font settings, etc.
5156 IConfigurationService < Configuration > configService ,
52- ISettingsFormFactory settingsFormFactory )
57+ ISettingsFormFactory settingsFormFactory ,
58+ IRewritingManager rewritingManager ,
59+ IAnnotationUpdater annotationUpdater )
5360 {
5461 _clipboard = clipboard ;
5562 _settingsFormFactory = settingsFormFactory ;
@@ -64,6 +71,11 @@ public TestExplorerViewModel(ISelectionService selectionService,
6471 OpenTestSettingsCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , OpenSettings ) ;
6572 CollapseAllCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , ExecuteCollapseAll ) ;
6673 ExpandAllCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , ExecuteExpandAll ) ;
74+ IgnoreTestCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , ExecuteIgnoreTestCommand ) ;
75+ UnignoreTestCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , ExecuteUnignoreTestCommand ) ;
76+
77+ RewritingManager = rewritingManager ;
78+ AnnotationUpdater = annotationUpdater ;
6779
6880 Model = model ;
6981 Model . TestCompleted += HandleTestCompletion ;
@@ -99,6 +111,7 @@ public TestMethodViewModel MouseOverTest
99111 }
100112 _mouseOverTest = value ;
101113 OnPropertyChanged ( ) ;
114+ RefreshContextMenu ( ) ;
102115 }
103116 }
104117
@@ -114,9 +127,16 @@ public CollectionViewGroup MouseOverGroup
114127 }
115128 _mouseOverGroup = value ;
116129 OnPropertyChanged ( ) ;
130+ RefreshContextMenu ( ) ;
117131 }
118132 }
119133
134+ private void RefreshContextMenu ( )
135+ {
136+ OnPropertyChanged ( nameof ( DisplayUnignoreTestLabel ) ) ;
137+ OnPropertyChanged ( nameof ( DisplayIgnoreTestLabel ) ) ;
138+ }
139+
120140 private static readonly Dictionary < TestExplorerGrouping , PropertyGroupDescription > GroupDescriptions = new Dictionary < TestExplorerGrouping , PropertyGroupDescription >
121141 {
122142 { TestExplorerGrouping . Outcome , new PropertyGroupDescription ( "Result.Outcome" , new TestResultToOutcomeTextConverter ( ) ) } ,
@@ -214,6 +234,13 @@ private void HandleTestCompletion(object sender, TestCompletedEventArgs e)
214234 Tests . Refresh ( ) ;
215235 }
216236
237+ public IRewritingManager RewritingManager { get ; }
238+ public IAnnotationUpdater AnnotationUpdater { get ; }
239+
240+ private TestMethod _mousedOverTestMethod => ( ( TestMethodViewModel ) SelectedItem ) . Method ;
241+ public bool DisplayUnignoreTestLabel => SelectedItem != null && _mousedOverTestMethod . IsIgnored ;
242+ public bool DisplayIgnoreTestLabel => SelectedItem != null && ! _mousedOverTestMethod . IsIgnored ;
243+
217244 #region Commands
218245
219246 public ReparseCommand RefreshCommand { get ; set ; }
@@ -245,6 +272,9 @@ private void HandleTestCompletion(object sender, TestCompletedEventArgs e)
245272 public CommandBase CollapseAllCommand { get ; }
246273 public CommandBase ExpandAllCommand { get ; }
247274
275+ public CommandBase IgnoreTestCommand { get ; }
276+ public CommandBase UnignoreTestCommand { get ; }
277+
248278 #endregion
249279
250280 #region Delegates
@@ -340,6 +370,29 @@ private void ExecuteResetResultsCommand(object parameter)
340370 Tests . Refresh ( ) ;
341371 }
342372
373+ private void ExecuteIgnoreTestCommand ( object parameter )
374+ {
375+ var rewriteSession = RewritingManager . CheckOutCodePaneSession ( ) ;
376+
377+ AnnotationUpdater . AddAnnotation ( rewriteSession , _mousedOverTestMethod . Declaration , Parsing . Annotations . AnnotationType . IgnoreTest ) ;
378+
379+ rewriteSession . TryRewrite ( ) ;
380+ }
381+
382+ private void ExecuteUnignoreTestCommand ( object parameter )
383+ {
384+ var rewriteSession = RewritingManager . CheckOutCodePaneSession ( ) ;
385+ var ignoreTestAnnotations = _mousedOverTestMethod . Declaration . Annotations
386+ . Where ( iannotations => iannotations . AnnotationType == Parsing . Annotations . AnnotationType . IgnoreTest ) ;
387+
388+ foreach ( var ignoreTestAnnotation in ignoreTestAnnotations )
389+ {
390+ AnnotationUpdater . RemoveAnnotation ( rewriteSession , ignoreTestAnnotation ) ;
391+ }
392+
393+ rewriteSession . TryRewrite ( ) ;
394+ }
395+
343396 private void ExecuteCopyResultsCommand ( object parameter )
344397 {
345398 const string XML_SPREADSHEET_DATA_FORMAT = "XML Spreadsheet" ;
0 commit comments