예제 #1
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;
            }
        }
예제 #2
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;
            }
        }