public void ShowInfoBar(VCProject project) { ThreadHelper.ThrowIfNotOnUIThread(); var shell = _serviceProvider.GetService(typeof(SVsShell)) as IVsShell; if (shell != null) { // Get the main window handle to host our InfoBar shell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out var obj); var host = (IVsInfoBarHost)obj; //If we cannot find the handle, we cannot do much, so return. if (host == null) { return; } InfoBarModel infoBarModel = CreateInfoBarModel(); //Get the factory object from IVsInfoBarUIFactory, create it and add it to host. var factory = _serviceProvider.GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory; if (factory == null) { return; } IVsInfoBarUIElement element = factory.CreateInfoBar(infoBarModel); var infoBarEventsHandler = new InfoBarEventsHandler(project); element.Advise(infoBarEventsHandler, out var _cookie); host.AddInfoBar(element); } }
public InfoBarEvents(IVsInfoBarUIElement infoBar, IVsInfoBarHost infoBarHost) { _infoBar = infoBar; _infoBarHost = infoBarHost; _infoBar.Advise(this, out _cookie); _infoBarHost.AddInfoBar(infoBar); }
public void ShowInfoBar(string message) { var shell = _serviceProvider.GetService(typeof(SVsShell)) as IVsShell; if (shell != null) { shell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out var obj); var host = (IVsInfoBarHost)obj; if (host == null) { return; } InfoBarTextSpan text = new InfoBarTextSpan(message); InfoBarHyperlink yes = new InfoBarHyperlink("Yes", "yes"); InfoBarHyperlink no = new InfoBarHyperlink("No", "no"); InfoBarTextSpan[] spans = new InfoBarTextSpan[] { text }; InfoBarActionItem[] actions = new InfoBarActionItem[] { yes, no }; InfoBarModel infoBarModel = new InfoBarModel(spans, actions, KnownMonikers.StatusInformation, isCloseButtonVisible: true); var factory = _serviceProvider.GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory; IVsInfoBarUIElement element = factory.CreateInfoBar(infoBarModel); element.Advise(this, out _cookie); host.AddInfoBar(element); } }
private static void Show(Microsoft.VisualStudio.Shell.SVsServiceProvider serviceProvider, EnvDTE.Project project) { var shell = serviceProvider.GetService(typeof(SVsShell)) as IVsShell; if (shell != null) { // Get the main window handle to host our InfoBar shell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out var obj); var host = (IVsInfoBarHost)obj; //If we cannot find the handle, we cannot do much, so return. if (host == null) { return; } InfoBarModel infoBarModel = CreateInfoBarModel(project); //Get the factory object from IVsInfoBarUIFactory, create it and add it to host. var factory = serviceProvider.GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory; IVsInfoBarUIElement element = factory.CreateInfoBar(infoBarModel); var infoBarEventsHandler = new InfoBarEventsHandler(serviceProvider, project); element.Advise(infoBarEventsHandler, out var _cookie); host.AddInfoBar(element); } }
public void Show() { ThreadHelper.ThrowIfNotOnUIThread(); if (Factory == null) { return; } if (UIElement != null) // Message already shown { return; } var textSpans = Enumerable.Empty <InfoBarTextSpan>(); if (Text != null) { textSpans = Text .Select(x => new InfoBarTextSpan(x.Text, x.Bold, x.Italic, x.Underline)); } var hyperlinks = Enumerable.Empty <InfoBarHyperlink>(); if (Hyperlinks != null) { hyperlinks = Hyperlinks .Select(x => new InfoBarHyperlink(x.Text, x)); } var model = new InfoBarModel(textSpans, hyperlinks, Icon, true); UIElement = Factory.CreateInfoBar(model); if (UIElement != null) { UIElement.Advise(this, out cookie); VsShell.InfoBarHost?.AddInfoBar(UIElement); } }
public void ShowInfoBar(string message, params InfoBarHyperlink[] hyperLinkObjects) { if (_serviceProvider.GetService(typeof(SVsShell)) is IVsShell shell) { shell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out var obj); var host = (IVsInfoBarHost)obj; if (host == null) { return; } var text = new InfoBarTextSpan(message); var spans = new InfoBarTextSpan[] { text }; var actions = new InfoBarActionItem[hyperLinkObjects.Length]; for (int i = 0; i < hyperLinkObjects.Length; i++) { actions[i] = hyperLinkObjects[i]; } var infoBarModel = new InfoBarModel(spans, actions, KnownMonikers.StatusInformation, isCloseButtonVisible: true); var factory = _serviceProvider.GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory; Assumes.Present(factory); IVsInfoBarUIElement element = factory.CreateInfoBar(infoBarModel); element.Advise(this, out _cookie); host.AddInfoBar(element); } }
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 void CreateInfoBar(InfoBarModel infoBarModel) { if (!(ServiceProvider.GlobalProvider.GetService(typeof(SVsInfoBarUIFactory)) is IVsInfoBarUIFactory factory)) { OutputLogger.WriteToOutputWindow(Resource.ErrorMessage_UnknownInfobarError, MessageType.Error); return; } var element = factory.CreateInfoBar(infoBarModel); _element = element; _element.Advise(this, out _cookie); _host.AddInfoBar(_element); }
private void AddInfoBar() { Action showHelp = () => Process.Start(UrlConstants.HelpUrl); var messages = new List<IVsInfoBarTextSpan>(); var actions = new List<InfoBarActionItem>(); messages.Add(new InfoBarTextSpan(Strings.InfoBarMessage)); actions.Add(new InfoBarHyperlink(Strings.InfoBarMessageLink, showHelp)); _infoBarModel = new InfoBarModel(messages, actions, KnownMonikers.StatusInformation, isCloseButtonVisible: true); _infoBar = _infoBarFactory.CreateInfoBar(_infoBarModel); AddInfoBar(_infoBar); _infoBar.Advise(this, out _infoBarAdviseCookie); }
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 void AddInfoBar() { Action showHelp = () => Process.Start(UrlConstants.HelpUrl); Action installGit = () => Process.Start(UrlConstants.InstallGitUrl); Action installPython = () => Process.Start(UrlConstants.InstallPythonUrl); Action installCookiecutter = () => Process.Start(UrlConstants.InstallCookiecutterUrl); var messages = new List <IVsInfoBarTextSpan>(); var actions = new List <InfoBarActionItem>(); if (_missingDependencies) { messages.Add(new InfoBarTextSpan(Strings.MissingDependenciesInfoBarMessage)); } else { messages.Add(new InfoBarTextSpan(Strings.InfoBarMessage)); } if (!_missingDependencies) { actions.Add(new InfoBarHyperlink(Strings.InfoBarMessageLink, showHelp)); } if (_missingGit) { actions.Add(new InfoBarHyperlink(Strings.InstallGitInfoBarLink, installGit)); } if (_missingPython) { actions.Add(new InfoBarHyperlink(Strings.InstallPythonInfoBarLink, installPython)); } if (_missingCookiecutter) { actions.Add(new InfoBarHyperlink(Strings.InstallCookiecutterInfoBarLink, installCookiecutter)); } var image = _missingDependencies ? KnownMonikers.StatusError : KnownMonikers.StatusInformation; _infoBarModel = new InfoBarModel(messages, actions, image, isCloseButtonVisible: true); _infoBar = _infoBarFactory.CreateInfoBar(_infoBarModel); AddInfoBar(_infoBar); _infoBar.Advise(this, out _infoBarAdviseCookie); }
public void ShowInfoBar(InfoBarMdl ib, Action onInfoBarClosedOrDismissed) { var shell = _serviceProvider.GetService(typeof(SVsShell)) as IVsShell; if (shell != null) { shell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out var obj); var host = (IVsInfoBarHost)obj; if (host == null) { return; } var factory = _serviceProvider.GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory; _element = factory.CreateInfoBar(ib.getInfoBarModel()); _element.Advise(this, out _cookie); host.AddInfoBar(_element); _onInfoBarCloseOrDismissAction = onInfoBarClosedOrDismissed; } }
public void ShowInfoBar(string message, ToolWindowPane toolWindow = null) { Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); // Construct an InfoBar. InfoBarTextSpan text = new InfoBarTextSpan(message); InfoBarHyperlink yes = new InfoBarHyperlink("Yes", "yes"); InfoBarHyperlink no = new InfoBarHyperlink("No", "no"); InfoBarButton noButton = new InfoBarButton("No", "no"); InfoBarTextSpan[] spans = new InfoBarTextSpan[] { text }; InfoBarActionItem[] actions = new InfoBarActionItem[] { yes, no, noButton }; InfoBarModel infoBarModel = new InfoBarModel(spans, actions, KnownMonikers.StatusInformation, isCloseButtonVisible: true); var factory = serviceProvider.GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory; Assumes.Present(factory); IVsInfoBarUIElement element = factory.CreateInfoBar(infoBarModel); element.Advise(this, out cookie); if (toolWindow == null) { var shell = serviceProvider.GetService(typeof(SVsShell)) as IVsShell; if (shell != null) { shell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out var obj); var host = (IVsInfoBarHost)obj; if (host == null) { return; } host.AddInfoBar(element); } } else { toolWindow.AddInfoBar(element); } }
/// <summary> /// Shows this bar in the Visual Studio environment. /// </summary> /// <param name="serviceProvider"></param> /// <returns></returns> public async Task <string> ShowAsync([NotNull] IServiceProvider serviceProvider) { if (IsShown) { throw new InvalidOperationException("Bar is already shown"); } ServiceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); if (serviceProvider.GetService(typeof(SVsShell)) is IVsShell shell) { shell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out var obj); var host = (IVsInfoBarHost)obj; if (host == null) { return(null); } _tcs = new TaskCompletionSource <string>(); _result = null; var infoBarModel = new InfoBarModel(Spans.Where(span => span.IsVisible).ToArray(), Actions.Where(action => action.IsVisible).ToArray(), ImageMoniker, HasCloseButton); var factory = serviceProvider.GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory; _element = factory.CreateInfoBar(infoBarModel); _element.Advise(this, out _cookie); host.AddInfoBar(_element); if (Timeout > 0) { if (await Task.WhenAny(_tcs.Task, Task.Delay(Timeout * 1000)) != _tcs.Task) { Close(); } } var response = await _tcs.Task; _tcs = null; _element = null; ServiceProvider = null; return(response); } return(null); }
protected void FinishCreate() { if (_infoBar != null) { Debug.Fail("Should not try to create info bar more than once."); return; } if (ErrorHandler.Failed(_shell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out object infoBarHostObj)) || infoBarHostObj == null) { // Main window is not ready yet, finish creating it later _idleManager.OnIdle += OnIdle; return; } var infoBarHost = (IVsInfoBarHost)infoBarHostObj; _infoBar = _infoBarFactory.CreateInfoBar(_infoBarModel); infoBarHost.AddInfoBar(_infoBar); _infoBar.Advise(this, out uint cookie); _adviseCookie = cookie; }
public static void Show(NodejsProjectNode projectNode) { var serviceProvider = projectNode.Site; serviceProvider.GetUIThread().MustBeCalledFromUIThread(); var vsShell = (IVsShell)serviceProvider.GetService(typeof(SVsShell)); var infoBarUIFactory = (IVsInfoBarUIFactory)serviceProvider.GetService(typeof(SVsInfoBarUIFactory)); if (ErrorHandler.Failed(vsShell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out var tmp))) { // we don't want to crash just because we can't show the error bar return; } var infoBarHost = (IVsInfoBarHost)tmp; // make sure we close the previous infobar CurrentInfoBarElement?.Close(); Action downloadNode = DownloadNode; Action openProjectProps = ShowProjectProperties; var actionItems = new[] { new InfoBarHyperlink(Resources.ConfigureProjectProperties, openProjectProps), new InfoBarHyperlink(Resources.DownloadNodejs, downloadNode), }; var infoBarModel = new InfoBarModel(Resources.NodejsNotInstalledInfoBar, actionItems, isCloseButtonVisible: true, image: KnownMonikers.StatusError); uint eventCookie = 0; CurrentInfoBarElement = infoBarUIFactory.CreateInfoBar(infoBarModel); CurrentInfoBarElement.Advise(new InfoBarUIEvents(OnClose), out eventCookie); infoBarHost.AddInfoBar(CurrentInfoBarElement); void OnClose() { CurrentInfoBarElement.Unadvise(eventCookie); } void DownloadNode() { const string url = @"https://aka.ms/downloadnode"; VsShellUtilities.OpenBrowser(url, (uint)__VSOSPFLAGS.OSP_LaunchNewBrowser); } void ShowProjectProperties() { // open Project Properties var logicalView = VSConstants.LOGVIEWID_Primary; if (ErrorHandler.Succeeded(projectNode.GetGuidProperty(VSConstants.VSITEMID_ROOT, (int)VsHierarchyPropID.ProjectDesignerEditor, out var editorType)) && ErrorHandler.Succeeded(projectNode.OpenItemWithSpecific(VSConstants.VSITEMID_ROOT, 0, ref editorType, "", ref logicalView, (IntPtr)(-1), out var frame))) { frame?.Show(); } } }