Skip to content

Commit 3703083

Browse files
authored
Merge branch 'next' into next
2 parents 8fb3414 + c467e97 commit 3703083

File tree

7 files changed

+50
-16
lines changed

7 files changed

+50
-16
lines changed

RetailCoder.VBE/App.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public sealed class App : IDisposable
2626
private const string FILE_TARGET_NAME = "file";
2727
private readonly VBE _vbe;
2828
private readonly IMessageBox _messageBox;
29-
private readonly IRubberduckParser _parser;
29+
private IRubberduckParser _parser;
3030
private AutoSave.AutoSave _autoSave;
3131
private IGeneralConfigService _configService;
3232
private readonly IAppMenu _appMenus;
@@ -468,6 +468,16 @@ public void Dispose()
468468
_branchesVM.LoadingComponentsCompleted -= EnableSinkEventHandlersAndUpdateCache;
469469
}
470470

471+
_handleSinkEvents = false;
472+
473+
if (_parser != null && _parser.State != null)
474+
{
475+
_parser.State.StateChanged -= Parser_StateChanged;
476+
_parser.State.StatusMessageUpdate -= State_StatusMessageUpdate;
477+
_parser.Dispose();
478+
// I won't set this to null because other components may try to release things
479+
}
480+
471481
if (_hooks != null)
472482
{
473483
_hooks.MessageReceived -= _hooks_MessageReceived;
@@ -482,13 +492,6 @@ public void Dispose()
482492
_configService = null;
483493
}
484494

485-
if (_parser != null && _parser.State != null)
486-
{
487-
_parser.State.StateChanged -= Parser_StateChanged;
488-
_parser.State.StatusMessageUpdate -= State_StatusMessageUpdate;
489-
// I won't set this to null because other components may try to release things
490-
}
491-
492495
if (_stateBar != null)
493496
{
494497
_stateBar.Refresh -= _stateBar_Refresh;
@@ -531,6 +534,8 @@ public void Dispose()
531534
item.Value.Item1.Unadvise(item.Value.Item2);
532535
}
533536

537+
UiDispatcher.Shutdown();
538+
534539
_disposed = true;
535540
}
536541
}

RetailCoder.VBE/AppMenu.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using Rubberduck.Parsing.VBA;
45
using Rubberduck.UI.Command.MenuItems;
56
using Rubberduck.UI.Command.MenuItems.ParentMenus;
@@ -43,6 +44,7 @@ public void Dispose()
4344
{
4445
foreach (var menu in _menus)
4546
{
47+
menu.RemoveChildren();
4648
if (menu.Item != null)
4749
{
4850
menu.Item.Delete();

RetailCoder.VBE/UI/Command/MenuItems/ParentMenus/IParentMenuItem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using Microsoft.Office.Core;
23

34
namespace Rubberduck.UI.Command.MenuItems.ParentMenus
@@ -6,5 +7,6 @@ public interface IParentMenuItem : IMenuItem, IAppMenu
67
{
78
CommandBarControls Parent { get; set; }
89
CommandBarPopup Item { get; }
10+
void RemoveChildren();
911
}
1012
}

RetailCoder.VBE/UI/Command/MenuItems/ParentMenus/ParentMenuItemBase.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.Drawing;
45
using System.Linq;
56
using System.Runtime.InteropServices;
@@ -34,7 +35,7 @@ protected ParentMenuItemBase(string key, IEnumerable<IMenuItem> items, int? befo
3435

3536
public virtual bool BeginGroup { get { return false; } }
3637
public virtual int DisplayOrder { get { return default(int); } }
37-
38+
3839
public void Localize()
3940
{
4041
if (Item == null)
@@ -81,6 +82,23 @@ public void Initialize()
8182
_logger.Debug("'{0}' ({1}) parent menu initialized, hash code {2}.", _key, GetHashCode(), Item.GetHashCode());
8283
}
8384

85+
public void RemoveChildren()
86+
{
87+
foreach (var child in _items.Keys.Select(item => item as IParentMenuItem).Where(child => child != null))
88+
{
89+
Debug.WriteLine("Deleting menu item {0}.", child.Caption);
90+
child.RemoveChildren();
91+
Debug.Assert(_items[child] is CommandBarPopup);
92+
(_items[child] as CommandBarPopup).Delete();
93+
}
94+
foreach (var child in _items.Values.Select(item => item as CommandBarButton).Where(child => child != null))
95+
{
96+
child.Click -= child_Click;
97+
Debug.WriteLine("Deleting child menu item {0}.", child.Caption);
98+
child.Delete();
99+
}
100+
}
101+
84102
public void EvaluateCanExecute(RubberduckParserState state)
85103
{
86104
foreach (var kvp in _items)

RetailCoder.VBE/UI/Command/MenuItems/UiDispatcher.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,10 @@ private static void CheckInitialization()
5858
{
5959
if (UiContext == null) throw new InvalidOperationException("UiDispatcher is not initialized. Invoke Initialize() from UI thread first.");
6060
}
61+
62+
public static void Shutdown()
63+
{
64+
Invoke(() => Dispatcher.CurrentDispatcher.InvokeShutdown());
65+
}
6166
}
6267
}

Rubberduck.Parsing/IRubberduckParser.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
using System;
12
using Rubberduck.Parsing.VBA;
23

34
namespace Rubberduck.Parsing
45
{
5-
public interface IRubberduckParser
6+
public interface IRubberduckParser : IDisposable
67
{
78
RubberduckParserState State { get; }
89
}

Rubberduck.Parsing/VBA/RubberduckParser.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
namespace Rubberduck.Parsing.VBA
2121
{
22-
public class RubberduckParser : IRubberduckParser, IDisposable
22+
public class RubberduckParser : IRubberduckParser
2323
{
2424
public RubberduckParserState State { get { return _state; } }
2525

@@ -605,16 +605,17 @@ private void ResolveReferences(DeclarationFinder finder, VBComponent component,
605605
public void Dispose()
606606
{
607607
State.ParseRequest -= ReparseRequested;
608-
if (_resolverTokenSource != null)
609-
{
610-
_resolverTokenSource.Dispose();
611-
}
612608

613609
if (_central != null)
614610
{
615-
_central.Cancel();
611+
//_central.Cancel();
616612
_central.Dispose();
617613
}
614+
615+
if (_resolverTokenSource != null)
616+
{
617+
_resolverTokenSource.Dispose();
618+
}
618619
}
619620
}
620621
}

0 commit comments

Comments
 (0)