Skip to content

Commit 573339d

Browse files
committed
Merge pull request #96 from rubberduck-vba/next
sync with main repo
2 parents a68be5f + 67967a6 commit 573339d

25 files changed

+759
-725
lines changed

RetailCoder.VBE/Root/RubberduckModule.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
using System;
2-
using System.Collections;
32
using System.Collections.Generic;
43
using System.Diagnostics;
54
using System.Linq;
65
using System.Reflection;
76
using System.Windows.Input;
8-
//using LibGit2Sharp;
97
using Microsoft.Office.Core;
108
using Microsoft.Vbe.Interop;
119
using Ninject;
@@ -23,7 +21,6 @@
2321
using Rubberduck.SourceControl;
2422
using Rubberduck.UI;
2523
using Rubberduck.UI.CodeExplorer;
26-
using Rubberduck.UI.CodeExplorer.Commands;
2724
using Rubberduck.UI.CodeInspections;
2825
using Rubberduck.UI.Command;
2926
using Rubberduck.UI.Command.MenuItems;
@@ -70,7 +67,8 @@ public override void Load()
7067
_kernel.Bind<NewUnitTestModuleCommand>().ToSelf().InSingletonScope();
7168
_kernel.Bind<NewTestMethodCommand>().ToSelf().InSingletonScope();
7269
_kernel.Bind<RubberduckCommandBar>().ToSelf().InSingletonScope();
73-
70+
_kernel.Bind<TestExplorerModel>().ToSelf().InSingletonScope();
71+
7472
BindCodeInspectionTypes();
7573

7674
var assemblies = new[]
@@ -331,7 +329,7 @@ private void BindCommandsToMenuItems()
331329
//_kernel.Bind<ICommand>().To(command);
332330
}
333331
}
334-
catch (InvalidOperationException exception)
332+
catch (InvalidOperationException)
335333
{
336334
// rename one of the classes, "FooCommand" is expected to match exactly 1 "FooBarXyzCommandMenuItem"
337335
}
@@ -354,7 +352,7 @@ private void BindCommandsToCodeExplorer()
354352

355353
private IEnumerable<IMenuItem> GetRubberduckMenuItems()
356354
{
357-
return new IMenuItem[]
355+
return new[]
358356
{
359357
_kernel.Get<AboutCommandMenuItem>(),
360358
_kernel.Get<SettingsCommandMenuItem>(),
@@ -426,7 +424,7 @@ private IMenuItem GetSmartIndenterParentMenu()
426424

427425
private IEnumerable<IMenuItem> GetCodePaneContextMenuItems()
428426
{
429-
return new IMenuItem[]
427+
return new[]
430428
{
431429
GetRefactoringsParentMenu(),
432430
GetSmartIndenterParentMenu(),

RetailCoder.VBE/UI/CodeInspections/InspectionResultsViewModel.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ public sealed class InspectionResultsViewModel : ViewModelBase, INavigateSelecti
2828
private readonly VBE _vbe;
2929
private readonly IClipboardWriter _clipboard;
3030
private readonly IGeneralConfigService _configService;
31-
private readonly IEnumerable<IInspection> _inspections;
3231

3332
public InspectionResultsViewModel(RubberduckParserState state, IInspector inspector, VBE vbe, INavigateCommand navigateCommand, IClipboardWriter clipboard,
34-
IGeneralConfigService configService, IEnumerable<IInspection> inspections)
33+
IGeneralConfigService configService)
3534
{
3635
_dispatcher = Dispatcher.CurrentDispatcher;
3736

@@ -48,15 +47,19 @@ public InspectionResultsViewModel(RubberduckParserState state, IInspector inspec
4847
_quickFixInProjectCommand = new DelegateCommand(ExecuteQuickFixInProjectCommand);
4948
_copyResultsCommand = new DelegateCommand(ExecuteCopyResultsCommand, CanExecuteCopyResultsCommand);
5049
_openSettingsCommand = new DelegateCommand(OpenSettings);
51-
_inspections = inspections;
5250

5351
_state.StateChanged += _state_StateChanged;
5452
}
5553

56-
private readonly ObservableCollection<ICodeInspectionResult> _results = new ObservableCollection<ICodeInspectionResult>();
54+
private ObservableCollection<ICodeInspectionResult> _results = new ObservableCollection<ICodeInspectionResult>();
5755
public ObservableCollection<ICodeInspectionResult> Results
5856
{
59-
get { return _results; }
57+
get { return _results; }
58+
private set
59+
{
60+
_results = value;
61+
OnPropertyChanged();
62+
}
6063
}
6164

6265
private CodeInspectionQuickFix _defaultFix;
@@ -90,7 +93,6 @@ public INavigateSource SelectedItem
9093
}
9194

9295
private IInspection _selectedInspection;
93-
9496
public IInspection SelectedInspection
9597
{
9698
get { return _selectedInspection; }
@@ -148,7 +150,6 @@ private void OpenSettings(object param)
148150
}
149151

150152
private bool _canRefresh = true;
151-
152153
public bool CanRefresh
153154
{
154155
get { return _canRefresh; }
@@ -196,14 +197,13 @@ private async void _state_StateChanged(object sender, EventArgs e)
196197

197198
Debug.WriteLine("Running code inspections...");
198199
IsBusy = true;
199-
var results = await _inspector.FindIssuesAsync(_state, CancellationToken.None);
200+
201+
var results = (await _inspector.FindIssuesAsync(_state, CancellationToken.None)).ToList();
202+
200203
_dispatcher.Invoke(() =>
201204
{
202-
Results.Clear();
203-
foreach (var codeInspectionResult in results)
204-
{
205-
Results.Add(codeInspectionResult);
206-
}
205+
Results = new ObservableCollection<ICodeInspectionResult>(results);
206+
207207
CanRefresh = true;
208208
IsBusy = false;
209209
SelectedItem = null;

RetailCoder.VBE/UI/Command/AddTestMethodCommand.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ namespace Rubberduck.UI.Command
1010
[ComVisible(false)]
1111
public class AddTestMethodCommand : CommandBase
1212
{
13-
private readonly TestExplorerModel _model;
1413
private readonly NewTestMethodCommand _command;
1514

16-
public AddTestMethodCommand(TestExplorerModel model, NewTestMethodCommand command)
15+
public AddTestMethodCommand(NewTestMethodCommand command)
1716
{
18-
_model = model;
1917
_command = command;
2018
}
2119

RetailCoder.VBE/UI/Command/AddTestMethodExpectedErrorCommand.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Runtime.InteropServices;
2-
using Rubberduck.UI.UnitTesting;
32
using Rubberduck.UnitTesting;
43

54
namespace Rubberduck.UI.Command
@@ -10,12 +9,10 @@ namespace Rubberduck.UI.Command
109
[ComVisible(false)]
1110
public class AddTestMethodExpectedErrorCommand : CommandBase
1211
{
13-
private readonly TestExplorerModel _model;
1412
private readonly NewTestMethodCommand _command;
1513

16-
public AddTestMethodExpectedErrorCommand(TestExplorerModel model, NewTestMethodCommand command)
14+
public AddTestMethodExpectedErrorCommand(NewTestMethodCommand command)
1715
{
18-
_model = model;
1916
_command = command;
2017
}
2118

RetailCoder.VBE/UI/Command/RunAllTestsCommand.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Rubberduck.Parsing.VBA;
12
using Rubberduck.UI.UnitTesting;
23
using Rubberduck.UnitTesting;
34

@@ -10,20 +11,31 @@ public class RunAllTestsCommand : CommandBase
1011
{
1112
private readonly ITestEngine _engine;
1213
private readonly TestExplorerModel _model;
14+
private readonly RubberduckParserState _state;
1315

14-
public RunAllTestsCommand(ITestEngine engine, TestExplorerModel model)
16+
public RunAllTestsCommand(ITestEngine engine, TestExplorerModel model, RubberduckParserState state)
1517
{
1618
_engine = engine;
1719
_model = model;
20+
_state = state;
1821
}
1922

2023
public override void Execute(object parameter)
2124
{
25+
_state.StateChanged += StateChanged;
26+
2227
_model.Refresh();
28+
}
29+
30+
private void StateChanged(object sender, ParserStateEventArgs e)
31+
{
32+
if (e.State != ParserState.Ready) { return; }
33+
2334
_model.ClearLastRun();
2435
_model.IsBusy = true;
2536
_engine.Run(_model.Tests);
2637
_model.IsBusy = false;
38+
_state.StateChanged -= StateChanged;
2739
}
2840
}
2941
}

RetailCoder.VBE/UI/UnitTesting/TestExplorerControl.xaml

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@
462462
<Grid>
463463
<Grid.RowDefinitions>
464464
<RowDefinition Height="30"/>
465-
<RowDefinition Height="16"/>
465+
<RowDefinition Height="10"/>
466466
<RowDefinition Height="*" />
467467
</Grid.RowDefinitions>
468468

@@ -563,25 +563,19 @@
563563
</ToolBar>
564564
</ToolBarTray>
565565

566-
<Border Grid.Row="1" Margin="2">
567-
<StackPanel>
568-
569-
<Border BorderBrush="DimGray" BorderThickness="1,1,0,0">
570-
<ProgressBar Height="12"
571-
Background="DimGray"
572-
Maximum="{Binding Model.Tests.Count, Mode=OneWay}"
573-
Value="{Binding Model.ExecutedCount, Mode=OneWay}">
574-
<ProgressBar.Foreground>
575-
<SolidColorBrush Color="{Binding Model.ProgressBarColor}" />
576-
</ProgressBar.Foreground>
577-
</ProgressBar>
578-
</Border>
579-
580-
</StackPanel>
581-
</Border>
566+
<ProgressBar Height="6"
567+
Grid.Row="1"
568+
Margin="2"
569+
Background="DimGray"
570+
Maximum="{Binding Model.Tests.Count, Mode=OneWay}"
571+
Value="{Binding Model.ExecutedCount, Mode=OneWay}">
572+
<ProgressBar.Foreground>
573+
<SolidColorBrush Color="{Binding Model.ProgressBarColor, UpdateSourceTrigger=PropertyChanged}" />
574+
</ProgressBar.Foreground>
575+
</ProgressBar>
582576

583577
<Border Grid.Row="2" Padding="2">
584-
<ScrollViewer VerticalScrollBarVisibility="Visible">
578+
<ScrollViewer VerticalScrollBarVisibility="Auto">
585579
<Grid>
586580
<controls:GroupingGrid ItemsSource="{Binding Source={StaticResource ResultsByOutcome}}"
587581
SelectedItem="{Binding SelectedTest}"

RetailCoder.VBE/UI/UnitTesting/TestExplorerControl.xaml.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
using System;
2-
using System.Windows.Controls;
32
using System.Windows.Data;
3+
using System.Windows.Threading;
44

55
namespace Rubberduck.UI.UnitTesting
66
{
77
/// <summary>
88
/// Interaction logic for TestExplorerControl.xaml
99
/// </summary>
10-
public partial class TestExplorerControl : UserControl
10+
public partial class TestExplorerControl : IDisposable
1111
{
12+
private readonly Dispatcher _dispatcher;
13+
1214
public TestExplorerControl()
1315
{
1416
InitializeComponent();
1517
DataContextChanged += TestExplorerControl_DataContextChanged;
18+
_dispatcher = Dispatcher.CurrentDispatcher;
1619
}
1720

1821
void TestExplorerControl_DataContextChanged(object sender, System.Windows.DependencyPropertyChangedEventArgs e)
@@ -32,17 +35,25 @@ void TestExplorerControl_DataContextChanged(object sender, System.Windows.Depend
3235

3336
private void OnTestCompleted(object sender, EventArgs eventArgs)
3437
{
35-
try
38+
_dispatcher.Invoke(() =>
3639
{
3740
var resource = FindResource("ResultsByOutcome") as CollectionViewSource;
3841
if (resource != null)
3942
{
4043
resource.View.Refresh();
4144
}
42-
}
43-
catch (Exception)
44-
{
45-
}
45+
});
46+
}
47+
48+
private bool _isDisposed;
49+
public void Dispose()
50+
{
51+
if (_isDisposed || DataContext == null) { return; }
52+
53+
DataContextChanged -= TestExplorerControl_DataContextChanged;
54+
((TestExplorerViewModel)DataContext).TestCompleted -= OnTestCompleted;
55+
56+
_isDisposed = true;
4657
}
4758
}
4859
}

0 commit comments

Comments
 (0)