public InfoBarEvents(IVsInfoBarUIElement infoBar, IVsInfoBarHost infoBarHost) { _infoBar = infoBar; _infoBarHost = infoBarHost; _infoBar.Advise(this, out _cookie); _infoBarHost.AddInfoBar(infoBar); }
private void CreateInfoBarForCodeFix(IVsInfoBarUIFactory factory, IVsWindowFrame frame, string message, Action onClose, Action onEnable = null, Action onEnableAndIgnore = null) { object unknown; if (ErrorHandler.Failed(frame.GetProperty((int)__VSFPROPID7.VSFPROPID_InfoBarHost, out unknown))) { return; } var textSpans = new List <IVsInfoBarTextSpan>() { new InfoBarTextSpan(message) }; // create action item list var actionItems = new List <IVsInfoBarActionItem>(); if (onEnable != null) { actionItems.Add(s_enableItem); } if (onEnableAndIgnore != null) { actionItems.Add(s_enableAndIgnoreItem); } var infoBarModel = new InfoBarModel( textSpans, actionItems.ToArray(), KnownMonikers.StatusInformation, isCloseButtonVisible: true); IVsInfoBarUIElement infoBarUI; if (!TryCreateInfoBarUI(factory, infoBarModel, out infoBarUI)) { return; } uint?infoBarCookie = null; var eventSink = new CodeFixInfoBarEvents(() => { onClose(); if (infoBarCookie.HasValue) { infoBarUI.Unadvise(infoBarCookie.Value); } }, onEnable, onEnableAndIgnore); uint cookie; infoBarUI.Advise(eventSink, out cookie); infoBarCookie = cookie; IVsInfoBarHost host = (IVsInfoBarHost)unknown; host.AddInfoBar(infoBarUI); }
public void ShowInfoBar(InfoBarModel infoBarModel) { TryGetInfoBarData(out var host); _host = host; if (_host != null) { CreateInfoBar(infoBarModel); } }
bool ShowInfoBar(IVsInfoBarHost host, InfoBarModel infoBar) { var factory = _ServiceProvider.GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory; if (factory != null) { _InfoBarUI = factory.CreateInfoBar(infoBar); _InfoBarUI.Advise(this, out _Cookie); host.AddInfoBar(_InfoBarUI); return(true); } return(false); }
private bool TryGetInfoBarHost(out IVsInfoBarHost infoBarHost) { var shell = this.Package.GetService(typeof(SVsShell)) as IVsShell; if (ErrorHandler.Failed(shell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out object infoBarHostObj))) { infoBarHost = null; return(false); } infoBarHost = infoBarHostObj as IVsInfoBarHost; return(infoBarHost != null); }
private static bool TryGetInfoBarHost(IVsWindowFrame frame, out IVsInfoBarHost infoBarHost) { object infoBarHostObj; if (ErrorHandler.Failed(frame.GetProperty((int)__VSFPROPID7.VSFPROPID_InfoBarHost, out infoBarHostObj))) { infoBarHost = null; return(false); } infoBarHost = infoBarHostObj as IVsInfoBarHost; return(infoBarHost != null); }
private void CreateInfoBar(IVsInfoBarUIFactory factory, IVsWindowFrame frame, string title, Action onClose, Action onEnableClicked = null, Action onEnableAndIgnoreClicked = null) { object unknown; if (frame.GetProperty((int)__VSFPROPID7.VSFPROPID_InfoBarHost, out unknown) == VSConstants.S_OK) { var textSpans = new List <IVsInfoBarTextSpan>() { new InfoBarTextSpan(title) }; // create action item list var actionItems = new List <IVsInfoBarActionItem>(); if (onEnableClicked != null) { actionItems.Add(s_enableItem); } if (onEnableAndIgnoreClicked != null) { actionItems.Add(s_enableAndIgnoreItem); } var infoBarModel = new InfoBarModel( textSpans, actionItems.ToArray(), KnownMonikers.StatusInformation, isCloseButtonVisible: true); IVsInfoBarUIElement infoBarUI; if (TryCreateInfoBarUI(factory, infoBarModel, out infoBarUI)) { uint? infoBarCookie = null; InfoBarEvents eventSink = new InfoBarEvents(() => { onClose(); if (infoBarCookie.HasValue) { infoBarUI.Unadvise(infoBarCookie.Value); } }, onEnableClicked, onEnableAndIgnoreClicked); uint cookie; infoBarUI.Advise(eventSink, out cookie); infoBarCookie = cookie; IVsInfoBarHost host = (IVsInfoBarHost)unknown; host.AddInfoBar(infoBarUI); } } }
private void CreateInfoBar(IVsInfoBarHost host, string message) { InfoBarTextSpan text = new InfoBarTextSpan(message); InfoBarHyperlink install = new InfoBarHyperlink("Install extension...", "install"); InfoBarHyperlink ignore = new InfoBarHyperlink("Ignore file type", "ignore"); InfoBarTextSpan[] spans = new InfoBarTextSpan[] { text }; InfoBarActionItem[] actions = new InfoBarActionItem[] { install, ignore }; InfoBarModel infoBarModel = new InfoBarModel(spans, actions, KnownMonikers.VisualStudioFeedback, isCloseButtonVisible: true); var factory = _serviceProvider.GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory; IVsInfoBarUIElement element = factory.CreateInfoBar(infoBarModel); element.Advise(this, out _cookie); host.AddInfoBar(element); }
private bool TryGetInfoBarData(out IVsInfoBarHost infoBarHost) { infoBarHost = null; var vsShell = (IVsShell)_serviceContainer.GetService(typeof(SVsShell)); if (vsShell == null || ErrorHandler.Failed(vsShell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out var globalInfoBar))) { return(false); } infoBarHost = (IVsInfoBarHost)globalInfoBar; return(infoBarHost != null); }
private bool TryGetInfoBarData(out IVsInfoBarHost infoBarHost) { AssertIsForeground(); infoBarHost = null; // global error info, show it on main window info bar if (_serviceProvider.GetService(typeof(SVsShell)) is not IVsShell shell || ErrorHandler.Failed(shell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out var globalInfoBar))) { return(false); } infoBarHost = globalInfoBar as IVsInfoBarHost; return(infoBarHost != null); }
private void CreateInfoBar(string name, Action onEnableClicked, Action onEnableAndIgnoreClicked, Action onClose, IVsWindowFrame frame, IVsInfoBarUIFactory factory) { object unknown; if (frame.GetProperty((int)__VSFPROPID7.VSFPROPID_InfoBarHost, out unknown) == VSConstants.S_OK) { var textSpans = new List <IVsInfoBarTextSpan>() { new InfoBarTextSpan(string.Format(ServicesVSResources.CodefixOrRefactoringEncounteredError, name)), }; var infoBarModel = new InfoBarModel( textSpans, new IVsInfoBarActionItem[] { s_enableItem, s_enableAndIgnoreItem }, KnownMonikers.StatusInformation, isCloseButtonVisible: true); IVsInfoBarUIElement infoBarUI; if (TryCreateInfoBarUI(factory, infoBarModel, out infoBarUI)) { uint? infoBarCookie = null; InfoBarEvents eventSink = new InfoBarEvents(onEnableClicked, onEnableAndIgnoreClicked, () => { onClose(); if (infoBarCookie.HasValue) { infoBarUI.Unadvise(infoBarCookie.Value); } }); uint cookie; infoBarUI.Advise(eventSink, out cookie); infoBarCookie = cookie; IVsInfoBarHost host = (IVsInfoBarHost)unknown; host.AddInfoBar(infoBarUI); } } }
bool TryGetInfoBarHost(out IVsInfoBarHost infoBarHost) { var shell = _ServiceProvider.GetService(typeof(SVsShell)) as IVsShell; if (shell == null) { goto Exit; } object infoBarHostObj; if (ErrorHandler.Failed(shell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out infoBarHostObj))) { goto Exit; } return((infoBarHost = infoBarHostObj as IVsInfoBarHost) != null); Exit: infoBarHost = null; return(false); }
private bool TryGetInfoBarData(bool activeView, out IVsInfoBarHost infoBarHost) { AssertIsForeground(); infoBarHost = null; if (activeView) { var monitorSelectionService = _serviceProvider.GetService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection; // We want to get whichever window is currently in focus (including toolbars) as we could have had an exception thrown from the error list // or interactive window if (monitorSelectionService == null || ErrorHandler.Failed(monitorSelectionService.GetCurrentElementValue((uint)VSConstants.VSSELELEMID.SEID_WindowFrame, out var value))) { return(false); } var frame = value as IVsWindowFrame; if (ErrorHandler.Failed(frame.GetProperty((int)__VSFPROPID7.VSFPROPID_InfoBarHost, out var activeViewInfoBar))) { return(false); } infoBarHost = activeViewInfoBar as IVsInfoBarHost; return(infoBarHost != null); } // global error info, show it on main window info bar var shell = _serviceProvider.GetService(typeof(SVsShell)) as IVsShell; if (shell == null || ErrorHandler.Failed(shell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out var globalInfoBar))) { return(false); } infoBarHost = globalInfoBar as IVsInfoBarHost; return(infoBarHost != null); }
private bool TryGetInfoBarData(out IVsInfoBarHost infoBarHost) { infoBarHost = null; if (_useActiveView) { // We want to get whichever window is currently in focus (including toolbars) as we could have had an exception thrown from the error list // or interactive window if (!(ServiceProvider.GlobalProvider.GetService(typeof(SVsShellMonitorSelection)) is IVsMonitorSelection monitorSelectionService) || ErrorHandler.Failed(monitorSelectionService.GetCurrentElementValue((uint)VSConstants.VSSELELEMID.SEID_WindowFrame, out var value))) { return(false); } if (!(value is IVsWindowFrame frame)) { OutputLogger.WriteToOutputWindow(Resource.ErrorMessage_UnknownInfobarError, MessageType.Error); return(false); } if (ErrorHandler.Failed(frame.GetProperty((int)__VSFPROPID7.VSFPROPID_InfoBarHost, out var activeViewInfoBar))) { return(false); } infoBarHost = activeViewInfoBar as IVsInfoBarHost; return(infoBarHost != null); } // Show on main window info bar if (!(ServiceProvider.GlobalProvider.GetService(typeof(SVsShell)) is IVsShell shell) || ErrorHandler.Failed(shell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out var globalInfoBar))) { return(false); } infoBarHost = globalInfoBar as IVsInfoBarHost; return(infoBarHost != null); }
private void CreateInfoBar(IVsInfoBarHost infoBarHost, string message, InfoBarUI[] items) { if ( !( _serviceProvider.GetService(typeof(SVsInfoBarUIFactory)) is IVsInfoBarUIFactory factory ) ) { // no info bar factory, don't do anything return; } var textSpans = new List <IVsInfoBarTextSpan>() { new InfoBarTextSpan(message) }; // create action item list var actionItems = new List <IVsInfoBarActionItem>(); foreach (var item in items) { switch (item.Kind) { case InfoBarUI.UIKind.Button: actionItems.Add(new InfoBarButton(item.Title)); break; case InfoBarUI.UIKind.HyperLink: actionItems.Add(new InfoBarHyperlink(item.Title)); break; case InfoBarUI.UIKind.Close: break; default: throw ExceptionUtilities.UnexpectedValue(item.Kind); } } var infoBarModel = new InfoBarModel( textSpans, actionItems.ToArray(), KnownMonikers.StatusInformation, isCloseButtonVisible: true ); if (!TryCreateInfoBarUI(factory, infoBarModel, out var infoBarUI)) { return; } uint?infoBarCookie = null; var eventSink = new InfoBarEvents( items, () => { // run given onClose action if there is one. items.FirstOrDefault(i => i.Kind == InfoBarUI.UIKind.Close).Action?.Invoke(); if (infoBarCookie.HasValue) { infoBarUI.Unadvise(infoBarCookie.Value); } } ); infoBarUI.Advise(eventSink, out var cookie); infoBarCookie = cookie; infoBarHost.AddInfoBar(infoBarUI); }
/// <summary> /// Creates a new instance of the InfoBar in a specific window frame or document window. /// </summary> internal InfoBar(IVsInfoBarHost host, InfoBarModel model) { _host = host; _model = model; }
private static bool TryGetInfoBarHost(IVsWindowFrame frame, out IVsInfoBarHost infoBarHost) { object infoBarHostObj; if (ErrorHandler.Failed(frame.GetProperty((int)__VSFPROPID7.VSFPROPID_InfoBarHost, out infoBarHostObj))) { infoBarHost = null; return false; } infoBarHost = infoBarHostObj as IVsInfoBarHost; return infoBarHost != null; }
public VsInfoBar(IVsInfoBarHost infoBarHost, IServiceContainer services) { _factoryLazy = new Lazy <IVsInfoBarUIFactory>(() => services.GetService <IVsInfoBarUIFactory>(typeof(SVsInfoBarUIFactory))); _infoBarHost = infoBarHost; }