Skip to content

Commit b6ce088

Browse files
committed
2 parents 5be9046 + 0e62425 commit b6ce088

File tree

63 files changed

+1548
-710
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1548
-710
lines changed

RetailCoder.VBE/API/ParserState.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public interface IParserStateEvents
3838
[ComDefaultInterface(typeof(IParserState))]
3939
[ComSourceInterfaces(typeof(IParserStateEvents))]
4040
[EditorBrowsable(EditorBrowsableState.Always)]
41-
public class ParserState : IParserState
41+
public sealed class ParserState : IParserState, IDisposable
4242
{
4343
private const string ClassId = "28754D11-10CC-45FD-9F6A-525A65412B7A";
4444
private const string ProgId = "Rubberduck.ParserState";
@@ -132,5 +132,21 @@ public Declaration[] UserDeclarations
132132
//[return: MarshalAs(UnmanagedType.SafeArray/*, SafeArraySubType = VarEnum.VT_VARIANT*/)]
133133
get { return _userDeclarations; }
134134
}
135+
136+
private bool _disposed;
137+
public void Dispose()
138+
{
139+
if (_disposed)
140+
{
141+
return;
142+
}
143+
144+
if (_state != null)
145+
{
146+
_state.StateChanged -= _state_StateChanged;
147+
}
148+
149+
_disposed = true;
150+
}
135151
}
136152
}

RetailCoder.VBE/App.cs

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@
2121

2222
namespace Rubberduck
2323
{
24-
public class App : IDisposable
24+
public sealed class App : IDisposable
2525
{
2626
private readonly VBE _vbe;
2727
private readonly IMessageBox _messageBox;
2828
private readonly IRubberduckParser _parser;
29-
private readonly AutoSave.AutoSave _autoSave;
30-
private readonly IGeneralConfigService _configService;
31-
private readonly IAppMenu _appMenus;
32-
private readonly RubberduckCommandBar _stateBar;
29+
private AutoSave.AutoSave _autoSave;
30+
private IGeneralConfigService _configService;
31+
private IAppMenu _appMenus;
32+
private RubberduckCommandBar _stateBar;
3333
private readonly IIndenter _indenter;
34-
private readonly IRubberduckHooks _hooks;
34+
private IRubberduckHooks _hooks;
3535

3636
private readonly Logger _logger;
3737

@@ -274,7 +274,7 @@ async void sink_ComponentRenamed(object sender, DispatcherRenamedEventArgs<VBCom
274274

275275
Debug.WriteLine(string.Format("Component '{0}' was renamed.", e.Item.Name));
276276

277-
_parser.State.OnParseRequested(sender, e.Item);
277+
_parser.State.RemoveRenamedComponent(e.Item, e.OldName);
278278
}
279279

280280
async void sink_ComponentRemoved(object sender, DispatcherEventArgs<VBComponent> e)
@@ -285,7 +285,7 @@ async void sink_ComponentRemoved(object sender, DispatcherEventArgs<VBComponent>
285285
}
286286

287287
Debug.WriteLine(string.Format("Component '{0}' was removed.", e.Item.Name));
288-
_parser.State.ClearStateCache(e.Item);
288+
_parser.State.ClearStateCache(e.Item, true);
289289
}
290290

291291
async void sink_ComponentReloaded(object sender, DispatcherEventArgs<VBComponent> e)
@@ -387,19 +387,50 @@ private void LoadConfig()
387387
}
388388
}
389389

390+
private bool _disposed;
390391
public void Dispose()
391392
{
392-
_hooks.MessageReceived -= _hooks_MessageReceived;
393-
_configService.SettingsChanged -= _configService_SettingsChanged;
394-
_configService.LanguageChanged -= ConfigServiceLanguageChanged;
395-
_parser.State.StateChanged -= Parser_StateChanged;
396-
_parser.State.StatusMessageUpdate -= State_StatusMessageUpdate;
397-
_stateBar.Refresh -= _stateBar_Refresh;
398-
399-
_sink.ProjectAdded -= sink_ProjectAdded;
400-
_sink.ProjectRemoved -= sink_ProjectRemoved;
401-
_sink.ProjectActivated -= sink_ProjectActivated;
402-
_sink.ProjectRenamed -= sink_ProjectRenamed;
393+
if (_disposed)
394+
{
395+
return;
396+
}
397+
398+
if (_hooks != null)
399+
{
400+
_hooks.MessageReceived -= _hooks_MessageReceived;
401+
_hooks.Dispose();
402+
_hooks = null;
403+
}
404+
405+
if (_configService != null)
406+
{
407+
_configService.SettingsChanged -= _configService_SettingsChanged;
408+
_configService.LanguageChanged -= ConfigServiceLanguageChanged;
409+
_configService = null;
410+
}
411+
412+
if (_parser != null && _parser.State != null)
413+
{
414+
_parser.State.StateChanged -= Parser_StateChanged;
415+
_parser.State.StatusMessageUpdate -= State_StatusMessageUpdate;
416+
// I won't set this to null because other components may try to release things
417+
}
418+
419+
if (_stateBar != null)
420+
{
421+
_stateBar.Refresh -= _stateBar_Refresh;
422+
_stateBar.Dispose();
423+
_stateBar = null;
424+
}
425+
426+
if (_sink != null)
427+
{
428+
_sink.ProjectAdded -= sink_ProjectAdded;
429+
_sink.ProjectRemoved -= sink_ProjectRemoved;
430+
_sink.ProjectActivated -= sink_ProjectActivated;
431+
_sink.ProjectRenamed -= sink_ProjectRenamed;
432+
_sink = null;
433+
}
403434

404435
foreach (var item in _componentsEventsSinks)
405436
{
@@ -411,7 +442,11 @@ public void Dispose()
411442
item.Value.ComponentSelected -= sink_ComponentSelected;
412443
}
413444

414-
_autoSave.Dispose();
445+
if (_autoSave != null)
446+
{
447+
_autoSave.Dispose();
448+
_autoSave = null;
449+
}
415450

416451
_projectsEventsConnectionPoint.Unadvise(_projectsEventsCookie);
417452
foreach (var item in _componentsEventsConnectionPoints)
@@ -422,9 +457,8 @@ public void Dispose()
422457
{
423458
item.Value.Item1.Unadvise(item.Value.Item2);
424459
}
425-
_hooks.Dispose();
426460

427-
_stateBar.Dispose();
461+
_disposed = true;
428462
}
429463
}
430464
}

RetailCoder.VBE/AutoSave/AutoSave.cs

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77

88
namespace Rubberduck.AutoSave
99
{
10-
public class AutoSave : IDisposable
10+
public sealed class AutoSave : IDisposable
1111
{
1212
private readonly VBE _vbe;
1313
private readonly IGeneralConfigService _configService;
14-
private readonly Timer _timer = new Timer();
15-
private Configuration _config;
14+
private Timer _timer = new Timer();
1615

1716
private const int VbeSaveCommandId = 3;
1817

@@ -29,12 +28,12 @@ public AutoSave(VBE vbe, IGeneralConfigService configService)
2928

3029
private void ConfigServiceSettingsChanged(object sender, EventArgs e)
3130
{
32-
_config = _configService.LoadConfiguration();
31+
var config = _configService.LoadConfiguration();
3332

34-
_timer.Enabled = _config.UserSettings.GeneralSettings.AutoSaveEnabled
35-
&& _config.UserSettings.GeneralSettings.AutoSavePeriod != 0;
33+
_timer.Enabled = config.UserSettings.GeneralSettings.AutoSaveEnabled
34+
&& config.UserSettings.GeneralSettings.AutoSavePeriod != 0;
3635

37-
_timer.Interval = _config.UserSettings.GeneralSettings.AutoSavePeriod * 1000;
36+
_timer.Interval = config.UserSettings.GeneralSettings.AutoSavePeriod * 1000;
3837
}
3938

4039
private void _timer_Elapsed(object sender, ElapsedEventArgs e)
@@ -57,10 +56,28 @@ private void _timer_Elapsed(object sender, ElapsedEventArgs e)
5756

5857
public void Dispose()
5958
{
60-
_configService.LanguageChanged -= ConfigServiceSettingsChanged;
61-
_timer.Elapsed -= _timer_Elapsed;
59+
Dispose(true);
60+
GC.SuppressFinalize(this);
61+
}
62+
63+
private void Dispose(bool disposing)
64+
{
65+
if (!disposing)
66+
{
67+
return;
68+
}
6269

63-
_timer.Dispose();
70+
if (_configService != null)
71+
{
72+
_configService.LanguageChanged -= ConfigServiceSettingsChanged;
73+
}
74+
75+
if (_timer != null)
76+
{
77+
_timer.Elapsed -= _timer_Elapsed;
78+
_timer.Dispose();
79+
_timer = null;
80+
}
6481
}
6582
}
6683
}

RetailCoder.VBE/Extension.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class _Extension : IDTExtensibility2
2323
private const string ClassId = "8D052AD8-BBD2-4C59-8DEC-F697CA1F8A66";
2424
private const string ProgId = "Rubberduck.Extension";
2525

26-
private readonly IKernel _kernel = new StandardKernel(new FuncModule());
26+
private IKernel _kernel;
2727
private App _app;
2828

2929
public void OnAddInsUpdate(ref Array custom)
@@ -37,6 +37,8 @@ public void OnBeginShutdown(ref Array custom)
3737
// ReSharper disable InconsistentNaming
3838
public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
3939
{
40+
_kernel = new StandardKernel(new FuncModule());
41+
4042
try
4143
{
4244
var currentDomain = AppDomain.CurrentDomain;
@@ -69,8 +71,17 @@ public void OnStartupComplete(ref Array custom)
6971

7072
public void OnDisconnection(ext_DisconnectMode RemoveMode, ref Array custom)
7173
{
72-
_app.Shutdown();
73-
_kernel.Dispose();
74+
if (_app != null)
75+
{
76+
_app.Shutdown();
77+
_app = null;
78+
}
79+
80+
if (_kernel != null)
81+
{
82+
_kernel.Dispose();
83+
_kernel = null;
84+
}
7485
}
7586
}
7687
}

RetailCoder.VBE/Inspections/Inspector.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,6 @@ before moving them into the ParseTreeResults after qualifying them
134134

135135
public void Dispose()
136136
{
137-
Dispose(true);
138-
}
139-
140-
protected virtual void Dispose(bool disposing)
141-
{
142-
if (!disposing) { return; }
143-
144137
if (_configService != null)
145138
{
146139
_configService.LanguageChanged -= ConfigServiceLanguageChanged;

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerComponentViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Rubberduck.Navigation.CodeExplorer
1313
{
14-
public class CodeExplorerComponentViewModel : CodeExplorerItemViewModel
14+
public class CodeExplorerComponentViewModel : CodeExplorerItemViewModel, ICodeExplorerDeclarationViewModel
1515
{
1616
private readonly Declaration _declaration;
1717
public Declaration Declaration { get { return _declaration; } }

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerMemberViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace Rubberduck.Navigation.CodeExplorer
1111
{
12-
public class CodeExplorerMemberViewModel : CodeExplorerItemViewModel
12+
public class CodeExplorerMemberViewModel : CodeExplorerItemViewModel, ICodeExplorerDeclarationViewModel
1313
{
1414
private readonly Declaration _declaration;
1515
public Declaration Declaration { get { return _declaration; } }

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerProjectViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace Rubberduck.Navigation.CodeExplorer
1212
{
13-
public class CodeExplorerProjectViewModel : CodeExplorerItemViewModel
13+
public class CodeExplorerProjectViewModel : CodeExplorerItemViewModel, ICodeExplorerDeclarationViewModel
1414
{
1515
private readonly Declaration _declaration;
1616
public Declaration Declaration { get { return _declaration; } }

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace Rubberduck.Navigation.CodeExplorer
1717
{
18-
public class CodeExplorerViewModel : ViewModelBase
18+
public sealed class CodeExplorerViewModel : ViewModelBase, IDisposable
1919
{
2020
private readonly FolderHelper _folderHelper;
2121
private readonly RubberduckParserState _state;
@@ -31,6 +31,7 @@ public CodeExplorerViewModel(FolderHelper folderHelper, RubberduckParserState st
3131
_state.ModuleStateChanged += ParserState_ModuleStateChanged;
3232

3333
_refreshCommand = commands.OfType<CodeExplorer_RefreshCommand>().FirstOrDefault();
34+
_refreshComponentCommand = commands.OfType<CodeExplorer_RefreshComponentCommand>().FirstOrDefault();
3435
_navigateCommand = commands.OfType<CodeExplorer_NavigateCommand>().FirstOrDefault();
3536

3637
_addTestModuleCommand = commands.OfType<CodeExplorer_AddTestModuleCommand>().FirstOrDefault();
@@ -54,6 +55,9 @@ public CodeExplorerViewModel(FolderHelper folderHelper, RubberduckParserState st
5455
}
5556

5657
_printCommand = commands.OfType<CodeExplorer_PrintCommand>().FirstOrDefault();
58+
59+
_commitCommand = commands.OfType<CodeExplorer_CommitCommand>().FirstOrDefault();
60+
_undoCommand = commands.OfType<CodeExplorer_UndoCommand>().FirstOrDefault();
5761
}
5862

5963
private CodeExplorerItemViewModel _selectedItem;
@@ -308,6 +312,9 @@ private void RemoveFailingComponent(CodeExplorerItemViewModel itemNode, string c
308312
private readonly ICommand _refreshCommand;
309313
public ICommand RefreshCommand { get { return _refreshCommand; } }
310314

315+
private readonly ICommand _refreshComponentCommand;
316+
public ICommand RefreshComponentCommand { get { return _refreshComponentCommand; } }
317+
311318
private readonly ICommand _navigateCommand;
312319
public ICommand NavigateCommand { get { return _navigateCommand; } }
313320

@@ -350,6 +357,12 @@ private void RemoveFailingComponent(CodeExplorerItemViewModel itemNode, string c
350357
private readonly ICommand _printCommand;
351358
public ICommand PrintCommand { get { return _printCommand; } }
352359

360+
private readonly ICommand _commitCommand;
361+
public ICommand CommitCommand { get { return _commitCommand; } }
362+
363+
private readonly ICommand _undoCommand;
364+
public ICommand UndoCommand { get { return _undoCommand; } }
365+
353366
private readonly ICommand _externalRemoveCommand;
354367

355368
// this is a special case--we have to reset SelectedItem to prevent a crash
@@ -360,5 +373,14 @@ private void ExecuteRemoveComand(object param)
360373

361374
_externalRemoveCommand.Execute(param);
362375
}
376+
377+
public void Dispose()
378+
{
379+
if (_state != null)
380+
{
381+
_state.StateChanged -= ParserState_StateChanged;
382+
_state.ModuleStateChanged -= ParserState_ModuleStateChanged;
383+
}
384+
}
363385
}
364386
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Rubberduck.Parsing.Symbols;
2+
3+
namespace Rubberduck.Navigation.CodeExplorer
4+
{
5+
public interface ICodeExplorerDeclarationViewModel
6+
{
7+
Declaration Declaration { get; }
8+
}
9+
}

0 commit comments

Comments
 (0)