public void DisplayInfoBar()
        {
            InfoBarTextSpan  textSpan1 = new InfoBarTextSpan("This is a sample info bar ");
            InfoBarHyperlink link1     = new InfoBarHyperlink("sample link1 ", Resources.InfoBarLinkActionContext1);
            InfoBarHyperlink link2     = new InfoBarHyperlink("sample link2 ", Resources.InfoBarLinkActionContext2);
            InfoBarButton    button1   = new InfoBarButton("sample button1", Resources.InfoBarButtonActionContext1);
            InfoBarButton    button2   = new InfoBarButton("sample button2", Resources.InfoBarButtonActionContext2);

            InfoBarTextSpan[]   textSpanCollection   = new InfoBarTextSpan[] { textSpan1, link1, link2 };
            InfoBarActionItem[] actionItemCollection = new InfoBarActionItem[] { button1, button2 };
            InfoBarModel        infoBarModel         = new InfoBarModel(textSpanCollection, actionItemCollection,
                                                                        KnownMonikers.StatusInformation, isCloseButtonVisible: true);

            this.AddInfoBar(infoBarModel);
            SubscribeToInfoBarEvents();
        }
        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);
            }
        }
Exemplo n.º 3
0
        void Build(string description, params InfoBarItem[] items)
        {
            var mainBox = new HBox {
                BackgroundColor = Styles.NotificationBar.BarBackgroundColor,
            };

            mainBox.PackStart(new ImageView(ImageService.GetIcon(Stock.Information, Gtk.IconSize.Menu)), marginLeft: 11);
            mainBox.PackStart(new Label(description));

            if (items.Length > 0)
            {
                mainBox.PackStart(new Label("–"));
            }

            var closeButton = new InfoBarCloseButton {
                Image       = closeImageInactive,
                MarginRight = 9,
            };

            closeButton.AddAction(() => Dispose());

            foreach (var item in items)
            {
                // TODO: abstract this into a factory.
                Widget toAdd = null;
                switch (item.Kind)
                {
                case InfoBarItem.InfoBarItemKind.Button:
                    var btn = new InfoBarButton {
                        Label      = item.Title,
                        LabelColor = Styles.NotificationBar.ButtonLabelColor,
                        Style      = ButtonStyle.Normal,

                        MinWidth = 77,
                    };

                    btn.AddAction(item.Action);
                    if (item.CloseAfter)
                    {
                        btn.AddAction(() => Dispose());
                    }
                    toAdd = btn;
                    break;

                // Creates a clickable hyperlink
                case InfoBarItem.InfoBarItemKind.Hyperlink:
                    var link = new InfoBarLink {
                        Text = item.Title,
                    };
                    link.AddAction(item.Action);
                    if (item.CloseAfter)
                    {
                        link.AddAction(() => Dispose());
                    }
                    toAdd = link;
                    break;

                // We only have 1 close button, we attach all close actions to it
                case InfoBarItem.InfoBarItemKind.Close:
                    closeButton.AddAction(item.Action);
                    break;
                }

                if (toAdd != null)
                {
                    mainBox.PackStart(toAdd);
                }
            }

            mainBox.PackEnd(closeButton);

            if (IdeApp.Preferences == null || IdeApp.Preferences.UserInterfaceTheme == Theme.Light)
            {
                Content = new FrameBox(mainBox)
                {
                    BorderWidthBottom = 1,
                    BorderColor       = Styles.NotificationBar.BarBorderColor,
                };
            }
            else
            {
                Content = mainBox;
            }
        }
Exemplo n.º 4
0
        public XwtInfoBar(string description, Action onDispose, params InfoBarItem[] items)
        {
            items ??= Array.Empty <InfoBarItem> ();

            this.onDispose = onDispose;

            var mainBox = new HBox {
                BackgroundColor = Styles.NotificationBar.BarBackgroundColor,
                MinHeight       = 30
            };

            mainBox.PackStart(new ImageView(ImageService.GetIcon(Stock.Information, Gtk.IconSize.Menu)), marginLeft: 11);
            mainBox.PackStart(descriptionLabel = new Label(description));

            int firstItem = 0;

            if (items.Length > 0 && items[0].Kind == InfoBarItemKind.Hyperlink)
            {
                firstItem = 1;
                var link = new InfoBarLink {
                    Text = items [0].Title,
                };
                link.AddAction(items [0].Action);
                if (items [0].CloseAfter)
                {
                    link.AddAction(() => Dispose());
                }
                mainBox.PackStart(new Label("–"));
                mainBox.PackStart(link);
            }

            var closeButton = new InfoBarCloseButton {
                Image       = closeImageInactive,
                MarginRight = 9,
            };

            closeButton.AddAction(() => Dispose());

            var widgets = new List <Widget> (items.Length);

            for (int i = items.Length - 1; i >= firstItem; i--)
            {
                var item = items [i];
                // TODO: abstract this into a factory.
                Widget toAdd = null;
                switch (item.Kind)
                {
                case InfoBarItemKind.Button:
                    var btn = new InfoBarButton {
                        Label      = item.Title,
                        LabelColor = Styles.NotificationBar.ButtonLabelColor,
                        Style      = ButtonStyle.Normal,

                        MinWidth = 77,
                    };

                    btn.AddAction(item.Action);
                    if (item.CloseAfter)
                    {
                        btn.AddAction(() => Dispose());
                    }
                    toAdd = btn;
                    break;

                // Creates a clickable hyperlink
                case InfoBarItemKind.Hyperlink:
                    var link = new InfoBarLink {
                        Text = item.Title,
                    };
                    link.AddAction(item.Action);
                    if (item.CloseAfter)
                    {
                        link.AddAction(() => Dispose());
                    }
                    toAdd = link;
                    break;

                // We only have 1 close button, we attach all close actions to it
                case InfoBarItemKind.Close:
                    closeButton.AddAction(item.Action);
                    break;
                }

                if (toAdd != null)
                {
                    widgets.Add(toAdd);
                }
            }

            mainBox.PackEnd(closeButton);
            foreach (var widget in widgets)
            {
                mainBox.PackEnd(widget);
            }

            if (IdeApp.Preferences == null || IdeApp.Preferences.UserInterfaceTheme == Theme.Light)
            {
                Content = new FrameBox(mainBox)
                {
                    BorderWidthBottom = 1,
                    BorderColor       = Styles.NotificationBar.BarBorderColor,
                };
            }
            else
            {
                Content = mainBox;
            }
        }
        public void DisplayInfoBar()
        {
            InfoBarTextSpan textSpan1 = new InfoBarTextSpan("This is a sample info bar ");
            InfoBarHyperlink link1 = new InfoBarHyperlink("sample link1 ", Resources.InfoBarLinkActionContext1);
            InfoBarHyperlink link2 = new InfoBarHyperlink("sample link2 ", Resources.InfoBarLinkActionContext2);
            InfoBarButton button1 = new InfoBarButton("sample button1", Resources.InfoBarButtonActionContext1);
            InfoBarButton button2 = new InfoBarButton("sample button2", Resources.InfoBarButtonActionContext2);
            InfoBarTextSpan[] textSpanCollection = new InfoBarTextSpan[] { textSpan1, link1, link2 };
            InfoBarActionItem[] actionItemCollection = new InfoBarActionItem[] { button1, button2 };
            InfoBarModel infoBarModel = new InfoBarModel(textSpanCollection, actionItemCollection,
                KnownMonikers.StatusInformation, isCloseButtonVisible: true);

            this.AddInfoBar(infoBarModel);
            SubscribeToInfoBarEvents();
        }