Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Runtime.InteropServices;
using System.Threading;
using CodingWithCalvin.BreakpointNotifier.Options;
using CodingWithCalvin.Otel4Vsix;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
Expand All @@ -12,6 +13,7 @@ namespace CodingWithCalvin.BreakpointNotifier
[InstalledProductRegistration(Vsix.Name, Vsix.Description, Vsix.Version)]
[Guid("136f3004-4048-4dd9-bd6d-7ff910b2c900")]
[ProvideAutoLoad(UIContextGuids80.SolutionExists, PackageAutoLoadFlags.BackgroundLoad)]
[ProvideOptionPage(typeof(GeneralOptions), "Breakpoint Notifier", "General", 0, 0, true)]
public sealed class BreakpointNotifierPackage : AsyncPackage
{
protected override async Task InitializeAsync(
Expand All @@ -35,7 +37,7 @@ IProgress<ServiceProgressData> progress

builder.Initialize();

DebuggerEvents.Initialize();
DebuggerEvents.Initialize(this);
}

protected override void Dispose(bool disposing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<PackageReference Include="CodingWithCalvin.Otel4Vsix" Version="0.2.2" />
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.*" />
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.14.40265" />
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.*" PrivateAssets="all" />
</ItemGroup>
Expand Down
43 changes: 39 additions & 4 deletions src/CodingWithCalvin.BreakpointNotifier/DebuggerEvents.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using CodingWithCalvin.BreakpointNotifier.Options;
using CodingWithCalvin.Otel4Vsix;
using Microsoft;
using Microsoft.Toolkit.Uwp.Notifications;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Debugger.Interop;
using Microsoft.VisualStudio.Shell;
Expand All @@ -12,20 +14,24 @@ namespace CodingWithCalvin.BreakpointNotifier
{
public sealed class DebuggerEvents : IVsDebuggerEvents, IDebugEventCallback2
{
private DebuggerEvents()
private readonly BreakpointNotifierPackage _package;

private DebuggerEvents(BreakpointNotifierPackage package)
{
ThreadHelper.ThrowIfNotOnUIThread();

_package = package;

var debugger = (IVsDebugger)
ServiceProvider.GlobalProvider.GetService(typeof(IVsDebugger));
Assumes.Present(debugger);
debugger.AdviseDebuggerEvents(this, out _);
debugger.AdviseDebugEventCallback(this);
}

public static DebuggerEvents Initialize()
public static DebuggerEvents Initialize(BreakpointNotifierPackage package)
{
return new DebuggerEvents();
return new DebuggerEvents(package);
}

public int OnModeChange(DBGMODE dbgmodeNew)
Expand All @@ -43,14 +49,16 @@ public int Event(
ref Guid riidEvent,
uint dwAttrib)
{
ThreadHelper.ThrowIfNotOnUIThread();

if (pEvent is IDebugBreakpointEvent2)
{
using var activity = VsixTelemetry.StartCommandActivity("BreakpointNotifier.BreakpointHit");

try
{
VsixTelemetry.LogInformation("Breakpoint hit detected");
MessageBox.Show("Breakpoint Hit!");
ShowNotification();
}
catch (Exception ex)
{
Expand All @@ -64,5 +72,32 @@ public int Event(

return VSConstants.S_OK;
}

private void ShowNotification()
{
ThreadHelper.ThrowIfNotOnUIThread();

var style = GetNotificationStyle();

if (style == NotificationStyle.MessageBox || style == NotificationStyle.Both)
{
MessageBox.Show("Breakpoint Hit!");
}

if (style == NotificationStyle.Toast || style == NotificationStyle.Both)
{
new ToastContentBuilder()
.AddText("Breakpoint Hit!")
.Show();
}
}

private NotificationStyle GetNotificationStyle()
{
ThreadHelper.ThrowIfNotOnUIThread();

var options = _package.GetDialogPage(typeof(GeneralOptions)) as GeneralOptions;
return options?.Style ?? NotificationStyle.Toast;
}
}
}
27 changes: 27 additions & 0 deletions src/CodingWithCalvin.BreakpointNotifier/Options/GeneralOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.ComponentModel;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Shell;

namespace CodingWithCalvin.BreakpointNotifier.Options
{
public enum NotificationStyle
{
[Description("Message Box")]
MessageBox,

[Description("Toast Notification")]
Toast,

[Description("Both")]
Both
}

[ComVisible(true)]
public class GeneralOptions : DialogPage
{
[Category("Notification")]
[DisplayName("Notification Style")]
[Description("Choose how breakpoint notifications are displayed. Toast notifications are less intrusive and don't steal focus.")]
public NotificationStyle Style { get; set; } = NotificationStyle.Toast;
}
}