Skip to content

Commit 6a92d87

Browse files
committed
Closes #4008
1 parent 9d5f49a commit 6a92d87

File tree

7 files changed

+70
-22
lines changed

7 files changed

+70
-22
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.Host;
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 = _vbe.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 = _vbe.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 = _vbe.CommandBarLocations[CommandBarSite.MsForms];
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 = _vbe.CommandBarLocations[CommandBarSite.MsFormsControl];
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 = _vbe.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.Host
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.Host
2+
{
3+
public enum CommandBarSite
4+
{
5+
MenuBar,
6+
CodeWindow,
7+
ProjectExplorer,
8+
MsForms,
9+
MsFormsControl
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="Host\CommandBarLocation.cs" />
6970
<Compile Include="ISourceCodeHandler.cs" />
7071
<Compile Include="SafeComWrappers\Abstract\HostApplicationBase.cs" />
7172
<Compile Include="SafeComWrappers\Abstract\ISafeComWrapper.cs" />
73+
<Compile Include="Host\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/IVBE.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
using Rubberduck.VBEditor.Host;
12
using System;
3+
using System.Collections.Generic;
24

35
namespace Rubberduck.VBEditor.SafeComWrappers.Abstract
46
{
@@ -20,7 +22,7 @@ public interface IVBE : ISafeComWrapper, IEquatable<IVBE>
2022
IWindows Windows { get; }
2123
IHostApplication HostApplication();
2224
IWindow ActiveMDIChild();
23-
25+
IReadOnlyDictionary<CommandBarSite, CommandBarLocation> CommandBarLocations { get; }
2426
QualifiedSelection? GetActiveSelection();
2527

2628
bool IsInDesignMode { get; }

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
24
using System.Linq;
35
using System.Runtime.InteropServices;
46
using System.Text;
7+
using Rubberduck.VBEditor.Host;
58
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
69
using Rubberduck.VBEditor.SafeComWrappers.Office8;
710
using Rubberduck.VBEditor.VB6;
@@ -17,11 +20,20 @@ public VBE(VB.VBE target, bool rewrapping = false)
1720
: base(target, rewrapping)
1821
{
1922
SourceCodeHandler = new SourceCodeHandler();
23+
CommandBarLocations = new ReadOnlyDictionary<CommandBarSite, CommandBarLocation>(new Dictionary<CommandBarSite, CommandBarLocation>
24+
{
25+
{CommandBarSite.MenuBar, new CommandBarLocation(1, 30009)},
26+
{CommandBarSite.CodeWindow, new CommandBarLocation(15, 2529)},
27+
{CommandBarSite.ProjectExplorer, new CommandBarLocation(22, 2578)},
28+
{CommandBarSite.MsForms, new CommandBarLocation(20, 746)},
29+
{CommandBarSite.MsFormsControl, new CommandBarLocation(21, 2558)}
30+
});
2031
}
2132

2233
public VBEKind Kind => VBEKind.Standalone;
2334
public object HardReference => Target;
2435
public ISourceCodeHandler SourceCodeHandler { get; }
36+
public IReadOnlyDictionary<CommandBarSite, CommandBarLocation> CommandBarLocations { get; }
2537

2638
public string Version => IsWrappingNullReference ? string.Empty : Target.Version;
2739

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
34
using System.IO;
45
using System.Linq;
56
using System.Runtime.InteropServices;
67
using System.Text;
8+
using Rubberduck.VBEditor.Host;
79
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
810
using Rubberduck.VBEditor.SafeComWrappers.Office12;
911
using Rubberduck.VBEditor.VBA;
@@ -19,11 +21,21 @@ public VBE(VB.VBE target, bool rewrapping = false)
1921
: base(target, rewrapping)
2022
{
2123
SourceCodeHandler = new SourceCodeHandler();
24+
CommandBarLocations = new ReadOnlyDictionary<CommandBarSite, CommandBarLocation>(new Dictionary<CommandBarSite, CommandBarLocation>
25+
{
26+
{CommandBarSite.MenuBar, new CommandBarLocation(1, 30009)},
27+
{CommandBarSite.CodeWindow, new CommandBarLocation(9, 2529)},
28+
{CommandBarSite.ProjectExplorer, new CommandBarLocation(14, 2578)},
29+
{CommandBarSite.MsForms, new CommandBarLocation(17, 2558)},
30+
{CommandBarSite.MsFormsControl, new CommandBarLocation(18, 2558)}
31+
});
32+
2233
}
2334

2435
public VBEKind Kind => VBEKind.Hosted;
2536
public object HardReference => Target;
2637
public ISourceCodeHandler SourceCodeHandler { get; }
38+
public IReadOnlyDictionary<CommandBarSite, CommandBarLocation> CommandBarLocations { get; }
2739

2840
public string Version => IsWrappingNullReference ? string.Empty : Target.Version;
2941

0 commit comments

Comments
 (0)