Skip to content

Commit

Permalink
Merge pull request #357 from MariaSolOs/use-infobar-cookie
Browse files Browse the repository at this point in the history
Using InfoBar listener cookie
  • Loading branch information
madskristensen authored Jul 11, 2022
2 parents e2ca0bc + c5aae09 commit f1c02be
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public class InfoBar : IVsInfoBarUIEvents
private readonly IVsInfoBarHost _host;
private readonly InfoBarModel _model;
private IVsInfoBarUIElement? _uiElement;
private uint _listenerCookie;

/// <summary>
/// Creates a new instance of the InfoBar in a specific window frame or document window.
Expand All @@ -112,14 +113,14 @@ internal InfoBar(IVsInfoBarHost host, InfoBarModel model)
/// <summary>
/// Displays the InfoBar in the tool window or document previously specified.
/// </summary>
/// <returns><c>true</c> if the InfoBar was shown; otherwise <c>false</c>.</returns>
/// <returns><see langword="true" /> if the InfoBar was shown; otherwise <see langword="false" />.</returns>
public async Task<bool> TryShowInfoBarUIAsync()
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
IVsInfoBarUIFactory infoBarUIFactory = (IVsInfoBarUIFactory)await VS.GetRequiredServiceAsync<SVsInfoBarUIFactory, object>();

_uiElement = infoBarUIFactory.CreateInfoBar(_model);
_uiElement.Advise(this, out _);
_uiElement.Advise(this, out _listenerCookie);

if (_host != null)
{
Expand All @@ -131,7 +132,7 @@ public async Task<bool> TryShowInfoBarUIAsync()
}

/// <summary>
/// Attempts to get the underlying WPF UI element of the InfoBar
/// Attempts to get the underlying WPF UI element of the InfoBar.
/// </summary>
public bool TryGetWpfElement(out Control? control)
{
Expand Down Expand Up @@ -171,6 +172,7 @@ public void Close()
void IVsInfoBarUIEvents.OnClosed(IVsInfoBarUIElement infoBarUIElement)
{
IsVisible = false;
_uiElement?.Unadvise(_listenerCookie);
}

void IVsInfoBarUIEvents.OnActionItemClicked(IVsInfoBarUIElement infoBarUIElement, IVsInfoBarActionItem actionItem)
Expand Down

0 comments on commit f1c02be

Please sign in to comment.