Skip to content

Commit f0fbd93

Browse files
committed
Had to do some weird Initialization stuff that I don't like; need to refactor that out.
1 parent de0f95b commit f0fbd93

File tree

6 files changed

+123
-8
lines changed

6 files changed

+123
-8
lines changed
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Runtime.InteropServices;
1+
using System;
2+
using System.Runtime.InteropServices;
23
using System.Threading;
34
using Microsoft.VisualStudio.Shell;
45
using Task = System.Threading.Tasks.Task;
@@ -7,14 +8,16 @@ namespace CodingWithCalvin.BreakpointNotifier.Vsix
78
{
89
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
910
[InstalledProductRegistration(Vsix.Name, Vsix.Description, Vsix.Version)]
11+
[Guid(PackageGuids.PackageGuidString)]
12+
[ProvideMenuResource("Menus.ctmenu", 1)]
1013
public sealed class BreakpointNotifierPackage : AsyncPackage
1114
{
12-
protected override Task OnAfterPackageLoadedAsync(CancellationToken cancellationToken)
15+
protected override Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
1316
{
14-
DebuggerEvents.Initialize();
17+
18+
InitializeCommand.Initialize(this);
1519

16-
return Task.CompletedTask;
20+
return base.InitializeAsync(cancellationToken, progress);
1721
}
18-
1922
}
2023
}

src/CodingWithCalvin.BreakpointNotifier.Vsix/CodingWithCalvin.BreakpointNotifier.Vsix.csproj

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
</PropertyGroup>
5050
<ItemGroup>
5151
<Compile Include="BreakpointNotifierPackage.cs" />
52+
<Compile Include="InitializeCommand.cs" />
53+
<Compile Include="VSCommandTable.cs">
54+
<AutoGen>True</AutoGen>
55+
<DesignTime>True</DesignTime>
56+
<DependentUpon>VSCommandTable.vsct</DependentUpon>
57+
</Compile>
5258
<Compile Include="DebuggerEvents.cs" />
5359
<Compile Include="Properties\AssemblyInfo.cs" />
5460
<Compile Include="source.extension.cs">
@@ -70,9 +76,16 @@
7076
<Reference Include="System.Design" />
7177
<Reference Include="System.Windows.Forms" />
7278
</ItemGroup>
79+
<ItemGroup>
80+
<VSCTCompile Include="VSCommandTable.vsct">
81+
<Generator>VsctGenerator</Generator>
82+
<LastGenOutput>VSCommandTable.cs</LastGenOutput>
83+
<ResourceName>Menus.ctmenu</ResourceName>
84+
</VSCTCompile>
85+
</ItemGroup>
7386
<ItemGroup>
7487
<PackageReference Include="Microsoft.VisualStudio.SDK">
75-
<Version>17.5.33428.388</Version>
88+
<Version>15.0.1</Version>
7689
</PackageReference>
7790
<PackageReference Include="Microsoft.VSSDK.BuildTools">
7891
<Version>17.5.4072</Version>

src/CodingWithCalvin.BreakpointNotifier.Vsix/DebuggerEvents.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ private DebuggerEvents()
1717
debugger.AdviseDebuggerEvents(this, out _);
1818
}
1919

20-
public static void Initialize()
20+
public static DebuggerEvents Initialize()
2121
{
22-
_ = new DebuggerEvents();
22+
return new DebuggerEvents();
2323
}
2424

2525
public int OnModeChange(DBGMODE dbgmodeNew)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Microsoft.VisualStudio.Shell;
2+
using System.ComponentModel.Design;
3+
using System;
4+
5+
namespace CodingWithCalvin.BreakpointNotifier.Vsix
6+
{
7+
internal class InitializeCommand
8+
{
9+
private readonly Package _package;
10+
private static DebuggerEvents _debuggerEvents;
11+
12+
private InitializeCommand(Package package)
13+
{
14+
_package = package;
15+
16+
var commandService = (OleMenuCommandService)ServiceProvider.GetService(typeof(IMenuCommandService));
17+
18+
if (commandService == null)
19+
{
20+
return;
21+
}
22+
23+
var menuCommandId = new CommandID(PackageGuids.CommandSetGuid, PackageIds.InitializeCommandId);
24+
var menuItem = new MenuCommand(InitializeDebuggerEvents, menuCommandId);
25+
commandService.AddCommand(menuItem);
26+
}
27+
28+
private IServiceProvider ServiceProvider => _package;
29+
30+
public static void Initialize(Package package)
31+
{
32+
_ = new InitializeCommand(package);
33+
}
34+
35+
private static void InitializeDebuggerEvents(object sender, EventArgs e)
36+
{
37+
_debuggerEvents = DebuggerEvents.Initialize();
38+
}
39+
}
40+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// ------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This file was generated by VSIX Synchronizer
4+
// </auto-generated>
5+
// ------------------------------------------------------------------------------
6+
namespace CodingWithCalvin.BreakpointNotifier.Vsix
7+
{
8+
using System;
9+
10+
/// <summary>
11+
/// Helper class that exposes all GUIDs used across VS Package.
12+
/// </summary>
13+
internal sealed partial class PackageGuids
14+
{
15+
public const string PackageGuidString = "136f3004-4048-4dd9-bd6d-7ff910b2c900";
16+
public static Guid PackageGuid = new Guid(PackageGuidString);
17+
18+
public const string CommandSetGuidString = "a12047f1-37ef-4dc0-80c3-4e3d43c5b767";
19+
public static Guid CommandSetGuid = new Guid(CommandSetGuidString);
20+
}
21+
/// <summary>
22+
/// Helper class that encapsulates all CommandIDs uses across VS Package.
23+
/// </summary>
24+
internal sealed partial class PackageIds
25+
{
26+
public const int InitializeCommandId = 0x0100;
27+
}
28+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<CommandTable xmlns="http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable" xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+
4+
<Extern href="stdidcmd.h"/>
5+
<Extern href="vsshlids.h"/>
6+
7+
<Commands package="PackageGuid">
8+
<Buttons>
9+
<Button guid="CommandSetGuid" id="InitializeCommandId" type="Button">
10+
<Strings>
11+
<ButtonText>Initialize Debugger Events</ButtonText>
12+
</Strings>
13+
</Button>
14+
</Buttons>
15+
</Commands>
16+
17+
<CommandPlacements>
18+
<CommandPlacement guid="CommandSetGuid" id="InitializeCommandId" priority="0x0100">
19+
<Parent guid="guidSHLMainMenu" id="IDG_VS_CTXT_PROJECT_EXPLORE" />
20+
</CommandPlacement>
21+
</CommandPlacements>
22+
23+
<Symbols>
24+
<GuidSymbol name="PackageGuid" value="{136f3004-4048-4dd9-bd6d-7ff910b2c900}" />
25+
26+
<GuidSymbol name="CommandSetGuid" value="{a12047f1-37ef-4dc0-80c3-4e3d43c5b767}">
27+
<IDSymbol name="InitializeCommandId" value="0x0100" />
28+
</GuidSymbol>
29+
30+
</Symbols>
31+
</CommandTable>

0 commit comments

Comments
 (0)