Skip to content

Commit 22561bf

Browse files
authored
Merge pull request #4248 from mansellan/4008
Split VBA/VB6 menu locations/IDs.
2 parents e6a517e + 99b8a33 commit 22561bf

File tree

12 files changed

+145
-42
lines changed

12 files changed

+145
-42
lines changed

Rubberduck.Main/Root/RubberduckIoCInstaller.cs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
using Rubberduck.VBEditor.Utility;
5151
using Rubberduck.AutoComplete;
5252
using Rubberduck.CodeAnalysis.CodeMetrics;
53+
using Rubberduck.VBEditor;
5354

5455
namespace Rubberduck.Root
5556
{
@@ -59,12 +60,6 @@ public class RubberduckIoCInstaller : IWindsorInstaller
5960
private readonly IAddIn _addin;
6061
private readonly GeneralSettings _initialSettings;
6162

62-
private const int MenuBar = 1;
63-
private const int CodeWindow = 9;
64-
private const int ProjectWindow = 14;
65-
private const int MsForms = 17;
66-
private const int MsFormsControl = 18;
67-
6863
public RubberduckIoCInstaller(IVBE vbe, IAddIn addin, GeneralSettings initialSettings)
6964
{
7065
_vbe = vbe;
@@ -319,9 +314,9 @@ private void RegisterParseTreeInspections(IWindsorContainer container, Assembly[
319314

320315
private void RegisterRubberduckMenu(IWindsorContainer container)
321316
{
322-
const int windowMenuId = 30009;
323-
var controls = MainCommandBarControls(MenuBar);
324-
var beforeIndex = FindRubberduckMenuInsertionIndex(controls, windowMenuId);
317+
var location = _addin.CommandBarLocations[CommandBarSite.MenuBar];
318+
var controls = MainCommandBarControls(location.ParentId);
319+
var beforeIndex = FindRubberduckMenuInsertionIndex(controls, location.BeforeControlId);
325320
var menuItemTypes = RubberduckMenuItems();
326321
RegisterMenu<RubberduckParentMenu>(container, controls, beforeIndex, menuItemTypes);
327322
}
@@ -385,9 +380,9 @@ private ICommandBarControls MainCommandBarControls(int commandBarIndex)
385380

386381
private void RegisterCodePaneContextMenu(IWindsorContainer container)
387382
{
388-
const int listMembersMenuId = 2529;
389-
var controls = MainCommandBarControls(CodeWindow);
390-
var beforeIndex = FindRubberduckMenuInsertionIndex(controls, listMembersMenuId);
383+
var location = _addin.CommandBarLocations[CommandBarSite.CodeWindow];
384+
var controls = MainCommandBarControls(location.ParentId);
385+
var beforeIndex = FindRubberduckMenuInsertionIndex(controls, location.BeforeControlId);
391386
var menuItemTypes = CodePaneContextMenuItems();
392387
RegisterMenu<CodePaneContextParentMenu>(container, controls, beforeIndex, menuItemTypes);
393388
}
@@ -406,9 +401,9 @@ private Type[] CodePaneContextMenuItems()
406401

407402
private void RegisterFormDesignerContextMenu(IWindsorContainer container)
408403
{
409-
const int viewCodeMenuId = 2558;
410-
var controls = MainCommandBarControls(MsForms);
411-
var beforeIndex = FindRubberduckMenuInsertionIndex(controls, viewCodeMenuId);
404+
var location = _addin.CommandBarLocations[CommandBarSite.MsForm];
405+
var controls = MainCommandBarControls(location.ParentId);
406+
var beforeIndex = FindRubberduckMenuInsertionIndex(controls, location.BeforeControlId);
412407
var menuItemTypes = FormDesignerContextMenuItems();
413408
RegisterMenu<FormDesignerContextParentMenu>(container, controls, beforeIndex, menuItemTypes);
414409
}
@@ -424,18 +419,18 @@ private Type[] FormDesignerContextMenuItems()
424419

425420
private void RegisterFormDesignerControlContextMenu(IWindsorContainer container)
426421
{
427-
const int viewCodeMenuId = 2558;
428-
var controls = MainCommandBarControls(MsFormsControl);
429-
var beforeIndex = FindRubberduckMenuInsertionIndex(controls, viewCodeMenuId);
422+
var location = _addin.CommandBarLocations[CommandBarSite.MsFormControl];
423+
var controls = MainCommandBarControls(location.ParentId);
424+
var beforeIndex = FindRubberduckMenuInsertionIndex(controls, location.BeforeControlId);
430425
var menuItemTypes = FormDesignerContextMenuItems();
431426
RegisterMenu<FormDesignerControlContextParentMenu>(container, controls, beforeIndex, menuItemTypes);
432427
}
433428

434429
private void RegisterProjectExplorerContextMenu(IWindsorContainer container)
435430
{
436-
const int projectPropertiesMenuId = 2578;
437-
var controls = MainCommandBarControls(ProjectWindow);
438-
var beforeIndex = FindRubberduckMenuInsertionIndex(controls, projectPropertiesMenuId);
431+
var location = _addin.CommandBarLocations[CommandBarSite.ProjectExplorer];
432+
var controls = MainCommandBarControls(location.ParentId);
433+
var beforeIndex = FindRubberduckMenuInsertionIndex(controls, location.BeforeControlId);
439434
var menuItemTypes = ProjectWindowContextMenuItems();
440435
RegisterMenu<ProjectWindowContextParentMenu>(container, controls, beforeIndex, menuItemTypes);
441436
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace Rubberduck.VBEditor
2+
{
3+
public class CommandBarLocation
4+
{
5+
public CommandBarLocation(int parentId, int beforeControlId)
6+
{
7+
ParentId = parentId;
8+
BeforeControlId = beforeControlId;
9+
}
10+
11+
public int ParentId { get; }
12+
public int BeforeControlId { get; }
13+
}
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Rubberduck.VBEditor
2+
{
3+
public enum CommandBarSite
4+
{
5+
MenuBar,
6+
CodeWindow,
7+
ProjectExplorer,
8+
MsForm,
9+
MsFormControl
10+
}
11+
}

Rubberduck.VBEEditor/Rubberduck.VBEditor.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@
6666
<Compile Include="Factories\ISafeComWrapperProvider.cs" />
6767
<Compile Include="Factories\VBEFactory.cs" />
6868
<Compile Include="HashCode.cs" />
69+
<Compile Include="CommandBarLocation.cs" />
6970
<Compile Include="ISourceCodeHandler.cs" />
7071
<Compile Include="SafeComWrappers\Abstract\HostApplicationBase.cs" />
7172
<Compile Include="SafeComWrappers\Abstract\ISafeComWrapper.cs" />
73+
<Compile Include="CommandBarSite.cs" />
7274
<Compile Include="SafeComWrappers\SafeComWrapper.cs" />
7375
<Compile Include="SafeComWrappers\SafeRedirectedEventedComWrapper.cs" />
7476
<Compile Include="SafeComWrappers\VB\Abstract\IHostApplication.cs" />

Rubberduck.VBEEditor/SafeComWrappers/VB/Abstract/IAddIn.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23

34
namespace Rubberduck.VBEditor.SafeComWrappers.Abstract
45
{
@@ -12,5 +13,6 @@ public interface IAddIn : ISafeComWrapper, IEquatable<IAddIn>
1213

1314
IVBE VBE { get; }
1415
IAddIns Collection { get; }
16+
IReadOnlyDictionary<CommandBarSite, CommandBarLocation> CommandBarLocations { get; }
1517
}
1618
}

Rubberduck.VBEEditor/SafeComWrappers/VB/Abstract/IVBE.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public interface IVBE : ISafeComWrapper, IEquatable<IVBE>
2020
IWindows Windows { get; }
2121
IHostApplication HostApplication();
2222
IWindow ActiveMDIChild();
23-
2423
QualifiedSelection? GetActiveSelection();
2524

2625
bool IsInDesignMode { get; }

Rubberduck.VBEditor.VB6/SafeComWrappers/VB/AddIn.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,42 @@
1-
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
1+
using System.Collections.Generic;
2+
using System.Collections.ObjectModel;
3+
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
24
using VB = Microsoft.Vbe.Interop.VB6;
35

46
// ReSharper disable once CheckNamespace - Special dispensation due to conflicting file vs namespace priorities
57
namespace Rubberduck.VBEditor.SafeComWrappers.VB6
68
{
79
public class AddIn : SafeComWrapper<VB.AddIn>, IAddIn
810
{
11+
12+
private const int MenuBar = 1;
13+
private const int CodeWindow = 15;
14+
private const int ProjectExplorer = 22;
15+
private const int MsForm = 20;
16+
private const int MsFormControl = 21;
17+
18+
private const int WindowMenu = 30009;
19+
private const int ListProperties = 2529;
20+
private const int ProjectProperties = 2578;
21+
private const int UpdateUserControls = 746;
22+
private const int ViewCode = 2558;
23+
24+
925
public AddIn(VB.AddIn target, bool rewrapping = false)
1026
: base(target, rewrapping)
11-
{
27+
{
28+
CommandBarLocations = new ReadOnlyDictionary<CommandBarSite, CommandBarLocation>(new Dictionary<CommandBarSite, CommandBarLocation>
29+
{
30+
{CommandBarSite.MenuBar, new CommandBarLocation(MenuBar, WindowMenu)},
31+
{CommandBarSite.CodeWindow, new CommandBarLocation(CodeWindow, ListProperties)},
32+
{CommandBarSite.ProjectExplorer, new CommandBarLocation(ProjectExplorer, ProjectProperties)},
33+
{CommandBarSite.MsForm, new CommandBarLocation(MsForm, UpdateUserControls)},
34+
{CommandBarSite.MsFormControl, new CommandBarLocation(MsFormControl, ViewCode)}
35+
});
1236
}
1337

38+
public IReadOnlyDictionary<CommandBarSite, CommandBarLocation> CommandBarLocations { get; }
39+
1440
public string ProgId => IsWrappingNullReference ? string.Empty : Target.ProgId;
1541

1642
public string Guid => IsWrappingNullReference ? string.Empty : Target.Guid;

Rubberduck.VBEditor.VBA/SafeComWrappers/VB/AddIn.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,41 @@
1-
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
1+
using System.Collections.Generic;
2+
using System.Collections.ObjectModel;
3+
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
24
using VB = Microsoft.Vbe.Interop;
35

46
// ReSharper disable once CheckNamespace - Special dispensation due to conflicting file vs namespace priorities
57
namespace Rubberduck.VBEditor.SafeComWrappers.VBA
68
{
79
public class AddIn : SafeComWrapper<VB.AddIn>, IAddIn
810
{
11+
private const int MenuBar = 1;
12+
private const int CodeWindow = 9;
13+
private const int ProjectExplorer = 14;
14+
private const int MsForm = 17;
15+
private const int MsFormControl = 18;
16+
17+
private const int WindowMenu = 30009;
18+
private const int ListProperties = 2529;
19+
private const int ProjectProperties = 2578;
20+
private const int ViewCode = 2558;
21+
922
public AddIn(VB.AddIn target, bool rewrapping = false)
1023
: base(target, rewrapping)
1124
{
25+
CommandBarLocations = new ReadOnlyDictionary<CommandBarSite, CommandBarLocation>(new Dictionary<CommandBarSite, CommandBarLocation>
26+
{
27+
{CommandBarSite.MenuBar, new CommandBarLocation(MenuBar, WindowMenu)},
28+
{CommandBarSite.CodeWindow, new CommandBarLocation(CodeWindow, ListProperties)},
29+
{CommandBarSite.ProjectExplorer, new CommandBarLocation(ProjectExplorer, ProjectProperties)},
30+
{CommandBarSite.MsForm, new CommandBarLocation(MsForm, ViewCode)},
31+
{CommandBarSite.MsFormControl, new CommandBarLocation(MsFormControl, ViewCode)}
32+
});
33+
1234
}
1335

36+
37+
public IReadOnlyDictionary<CommandBarSite, CommandBarLocation> CommandBarLocations { get; }
38+
1439
public string ProgId => IsWrappingNullReference ? string.Empty : Target.ProgId;
1540

1641
public string Guid => IsWrappingNullReference ? string.Empty : Target.Guid;

RubberduckTests/IoCContainer/IoCRegistrationTests.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
using System.Collections.Generic;
22
using Castle.Windsor;
33
using NUnit.Framework;
4-
using Moq;
54
using Rubberduck.Settings;
6-
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
75
using Rubberduck.Root;
8-
using Rubberduck.UI;
96
using RubberduckTests.Mocks;
107

118
namespace RubberduckTests.IoCContainer
@@ -18,8 +15,9 @@ public class IoCRegistrationTests
1815
public void RegistrationOfRubberduckIoCContainerWithSC_NoException()
1916
{
2017
var vbeBuilder = new MockVbeBuilder();
21-
var ide = vbeBuilder.Build().Object;
22-
var addin = new Mock<IAddIn>().Object;
18+
var addInBuilder = new MockAddInBuilder();
19+
var ide = vbeBuilder.Build().Object;
20+
var addin = addInBuilder.Build().Object;
2321
var initialSettings = new GeneralSettings
2422
{
2523
EnableExperimentalFeatures = new List<ExperimentalFeatures>
@@ -41,8 +39,9 @@ public void RegistrationOfRubberduckIoCContainerWithSC_NoException()
4139
public void RegistrationOfRubberduckIoCContainerWithoutSC_NoException()
4240
{
4341
var vbeBuilder = new MockVbeBuilder();
42+
var addInBuilder = new MockAddInBuilder();
4443
var ide = vbeBuilder.Build().Object;
45-
var addin = new Mock<IAddIn>().Object;
44+
var addin = addInBuilder.Build().Object;
4645
var initialSettings = new GeneralSettings {EnableExperimentalFeatures = new List<ExperimentalFeatures>()};
4746

4847
using (var container =
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.Collections.Generic;
2+
using System.Collections.ObjectModel;
3+
using Moq;
4+
using Rubberduck.VBEditor;
5+
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
6+
7+
namespace RubberduckTests.Mocks
8+
{
9+
public class MockAddInBuilder
10+
{
11+
private readonly Mock<IAddIn> _addIn;
12+
13+
public MockAddInBuilder()
14+
{
15+
_addIn = CreateAddInMock();
16+
}
17+
18+
private Mock<IAddIn> CreateAddInMock()
19+
{
20+
var addIn = new Mock<IAddIn>();
21+
22+
addIn.Setup(a => a.CommandBarLocations).Returns(new ReadOnlyDictionary<CommandBarSite, CommandBarLocation>(new Dictionary<CommandBarSite, CommandBarLocation>
23+
{
24+
{CommandBarSite.MenuBar, new CommandBarLocation(1, 1)},
25+
{CommandBarSite.CodeWindow, new CommandBarLocation(2, 2)},
26+
{CommandBarSite.ProjectExplorer, new CommandBarLocation(3, 3)},
27+
{CommandBarSite.MsForm, new CommandBarLocation(4, 4)},
28+
{CommandBarSite.MsFormControl, new CommandBarLocation(5, 5)}
29+
}));
30+
31+
return addIn;
32+
}
33+
34+
public Mock<IAddIn> Build()
35+
{
36+
return _addIn;
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)