Skip to content

Commit 9ec7848

Browse files
committed
Merge branch 'next' of https://github.com/rubberduck-vba/Rubberduck into next
2 parents 8f6f295 + 40a12cf commit 9ec7848

File tree

8 files changed

+58
-29
lines changed

8 files changed

+58
-29
lines changed

RetailCoder.VBE/AppMenu.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ public void Localize()
4242

4343
public void Dispose()
4444
{
45-
foreach (var menu in _menus.Where(menu => menu.Item != null))
46-
{
47-
menu.RemoveChildren();
48-
menu.Item.Delete();
49-
}
45+
// note: doing this wrecks the teardown process. counter-intuitive? sure. but hey it works.
46+
//foreach (var menu in _menus.Where(menu => menu.Item != null))
47+
//{
48+
// menu.RemoveChildren();
49+
// menu.Item.Delete();
50+
//}
5051
}
5152
}
5253
}

RetailCoder.VBE/Extension.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,15 @@ private void Startup()
212212

213213
_app = _kernel.Get<App>();
214214
_app.Startup();
215+
215216
_isInitialized = true;
216217
}
217218

218219
private void ShutdownAddIn()
219220
{
221+
var currentDomain = AppDomain.CurrentDomain;
222+
currentDomain.AssemblyResolve -= LoadFromSameFolder;
223+
220224
User32.EnumChildWindows(_ide.MainWindow.Handle(), EnumCallback, new IntPtr(0));
221225

222226
if (_app != null)

RetailCoder.VBE/UI/Command/MenuItems/CommandBars/AppCommandBarBase.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,13 @@ public void EvaluateCanExecute(RubberduckParserState state)
110110
public ICommandBar Item { get; private set; }
111111
public void RemoveChildren()
112112
{
113-
foreach (var child in _items.Values.Select(item => item as CommandBarButton).Where(child => child != null))
114-
{
115-
child.Click -= child_Click;
116-
child.Delete();
117-
//child.Release();
118-
}
113+
// note: doing this wrecks the teardown process. counter-intuitive? sure. but hey it works.
114+
//foreach (var child in _items.Values.Select(item => item as CommandBarButton).Where(child => child != null))
115+
//{
116+
// child.Click -= child_Click;
117+
// child.Delete();
118+
// child.Release();
119+
//}
119120
}
120121

121122
// note: HAAAAACK!!!

RetailCoder.VBE/UI/Command/MenuItems/CommandBars/RubberduckCommandBar.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ public void SetContextSelectionCaption(string caption)
5353

5454
public void Dispose()
5555
{
56-
RemoveChildren();
57-
Item.Delete();
58-
Item.Release(true);
56+
//note: doing this wrecks the teardown process. counter-intuitive? sure. but hey it works.
57+
//RemoveChildren();
58+
//Item.Delete();
59+
//Item.Release(true);
5960
}
6061
}
6162

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ public void RemoveChildren()
9696
foreach (var child in _items.Keys.Select(item => item as IParentMenuItem).Where(child => child != null))
9797
{
9898
child.RemoveChildren();
99-
var item = _items[child];
100-
Debug.Assert(item is CommandBarPopup);
101-
(item as CommandBarPopup).Delete();
99+
//var item = _items[child];
100+
//Debug.Assert(item is CommandBarPopup);
101+
//(item as CommandBarPopup).Delete();
102102
}
103103
foreach (var child in _items.Values.Select(item => item as CommandBarButton).Where(child => child != null))
104104
{
105105
child.Click -= child_Click;
106-
child.Delete();
106+
//child.Delete();
107107
}
108108
}
109109

Rubberduck.VBEEditor/SafeComWrappers/Office.Core/CommandBarButton.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ private void Target_Click(Microsoft.Office.Core.CommandBarButton ctrl, ref bool
5151
//note: event is fired for every parent the command exists under. not sure why.
5252
//System.Diagnostics.Debug.WriteLine("Target_Click: {0} '{1}' (tag: {2}, hashcode:{3})", Parent.Name, Target.Caption, Tag, Target.GetHashCode());
5353

54-
var args = new CommandBarButtonClickEventArgs(new CommandBarButton(ctrl));
54+
var button = new CommandBarButton(ctrl);
55+
var args = new CommandBarButtonClickEventArgs(button);
5556
handler.Invoke(this, args);
5657
cancelDefault = args.Cancel;
58+
button.Release(final:true);
5759
}
5860

5961
public bool IsBuiltInFace

Rubberduck.VBEEditor/SafeComWrappers/Office.Core/CommandBars.cs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Linq;
5+
using System.Runtime.InteropServices;
56
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
67
using Rubberduck.VBEditor.SafeComWrappers.MSForms;
78
using Rubberduck.VBEditor.SafeComWrappers.Office.Core.Abstract;
@@ -17,14 +18,33 @@ public CommandBars(Microsoft.Office.Core.CommandBars target)
1718

1819
public ICommandBar Add(string name)
1920
{
21+
DeleteExistingCommandBar(name);
2022
return new CommandBar(Target.Add(name, Temporary:true));
2123
}
2224

2325
public ICommandBar Add(string name, CommandBarPosition position)
2426
{
27+
DeleteExistingCommandBar(name);
2528
return new CommandBar(Target.Add(name, position, Temporary: true));
2629
}
2730

31+
private void DeleteExistingCommandBar(string name)
32+
{
33+
try
34+
{
35+
var existing = Target[name];
36+
if (existing != null)
37+
{
38+
existing.Delete();
39+
Marshal.FinalReleaseComObject(existing);
40+
}
41+
}
42+
catch
43+
{
44+
// specified commandbar didn't exist
45+
}
46+
}
47+
2848
public ICommandBarControl FindControl(int id)
2949
{
3050
return new CommandBarControl(Target.FindControl(Id:id));
@@ -57,15 +77,15 @@ public ICommandBar this[object index]
5777

5878
public override void Release(bool final = false)
5979
{
60-
if (!IsWrappingNullReference)
61-
{
62-
var commandBars = this.ToArray();
63-
foreach (var commandBar in commandBars)
64-
{
65-
commandBar.Release();
66-
}
67-
base.Release(final);
68-
}
80+
//if (!IsWrappingNullReference)
81+
//{
82+
// var commandBars = this.ToArray();
83+
// foreach (var commandBar in commandBars)
84+
// {
85+
// commandBar.Release();
86+
// }
87+
// base.Release(final);
88+
//}
6989
}
7090

7191
public override bool Equals(ISafeComWrapper<Microsoft.Office.Core.CommandBars> other)

Rubberduck.VBEEditor/SafeComWrappers/VBA/VBE.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public override void Release(bool final = false)
9090
{
9191
VBProjects.Release();
9292
CodePanes.Release();
93-
CommandBars.Release();
93+
//CommandBars.Release();
9494
Windows.Release();
9595
AddIns.Release();
9696
base.Release(final);

0 commit comments

Comments
 (0)