Inheritance: PowerArgs.Cli.ConsolePanel
Example #1
0
        internal override ConsoleControl GetContent()
        {
            if (Options == null || Options.Count == 0)
            {
                throw new ArgumentException("You need to specify at least one button");
            }

            if (Mode == DialogButtonsPresentationMode.Buttons)
            {
                ConsolePanel    dialogContent = new ConsolePanel();
                ScrollablePanel messagePanel  = dialogContent.Add(new ScrollablePanel()).Fill(padding: new Thickness(0, 0, 1, 3));
                Label           messageLabel  = messagePanel.ScrollableContent.Add(new Label()
                {
                    Mode = LabelRenderMode.MultiLineSmartWrap, Text = Message
                }).FillHorizontally(padding: new Thickness(3, 3, 0, 0));
                StackPanel buttonPanel = dialogContent.Add(new StackPanel()
                {
                    Margin = 1, Height = 1, Orientation = Orientation.Horizontal
                }).FillHorizontally(padding: new Thickness(1, 0, 0, 0)).DockToBottom(padding: 1);

                foreach (var option in Options)
                {
                    var    myOption = option;
                    Button b        = new Button()
                    {
                        Text = option.DisplayText
                    };
                    b.Pressed.SubscribeOnce(() =>
                    {
                        SelectedOption = myOption;
                        Dialog.Dismiss();
                    });
                    buttonPanel.Controls.Add(b);
                }

                buttonPanel.Controls.Last().AddedToVisualTree.SubscribeOnce(() => buttonPanel.Application.QueueAction(() => { buttonPanel.Controls.Last().TryFocus(); }));
                return(dialogContent);
            }
            else
            {
                Grid optionsGrid = new Grid(Options.Select(o => o as object).ToList());
                optionsGrid.MoreDataMessage  = "More options below".ToYellow();
                optionsGrid.EndOfDataMessage = "End of menu";

                optionsGrid.VisibleColumns.Remove(optionsGrid.VisibleColumns.Where(v => v.ColumnName.ToString() == nameof(DialogOption.Id)).Single());
                optionsGrid.VisibleColumns[0].WidthPercentage   = 1;
                optionsGrid.VisibleColumns[0].ColumnDisplayName = Message.IsUnstyled ? Message.ToYellow() : Message;
                optionsGrid.VisibleColumns[0].OverflowBehavior  = new TruncateOverflowBehavior();
                (optionsGrid.VisibleColumns[0].OverflowBehavior as TruncateOverflowBehavior).ColumnWidth = 0;
                optionsGrid.SelectedItemActivated += () =>
                {
                    this.SelectedOption = optionsGrid.SelectedItem as DialogOption;
                    Dialog.Dismiss();
                };

                optionsGrid.AddedToVisualTree.SubscribeOnce(() => optionsGrid.Application.QueueAction(() => { optionsGrid.TryFocus(); }));

                return(optionsGrid);
            }
        }
 public ProgressOperationManagerControl(ProgressOperationsManager manager)
 {
     this.manager = manager;
     this.scrollablePanel = Add(new ScrollablePanel()).Fill();
     operationsStackPanel = scrollablePanel.ScrollableContent.Add(new StackPanel() { Orientation = Orientation.Vertical, AutoSize=true }).FillHoriontally();
     noNotificationsLabel = Add(new Label() { Text = "No notifications".ToConsoleString(), X=1, Y=1 });
     manager.Operations.SynchronizeForLifetime(Operations_Added, Operations_Removed, Operations_Changed, this.LifetimeManager);
 }
Example #3
0
 public LogTailControl()
 {
     scrollPanel = Add(new ScrollablePanel()).Fill();
     logStack    = scrollPanel.ScrollableContent.Add(new StackPanel()
     {
         Orientation = Orientation.Vertical
     }).FillHorizontally();
 }
Example #4
0
 public LogTailControl()
 {
     scrollPanel = Add(new ScrollablePanel()).Fill();
     logLabel    = scrollPanel.ScrollableContent.Add(new Label()
     {
         Text = ConsoleString.Empty, Mode = LabelRenderMode.ManualSizing
     }).FillHorizontally();
     this.SubscribeForLifetime(nameof(Background), () =>
     {
         scrollPanel.Background = Background;
         logLabel.Background    = Background;
     }, this);
 }
 public ProgressOperationManagerControl(ProgressOperationsManager manager)
 {
     this.manager         = manager;
     this.scrollablePanel = Add(new ScrollablePanel()).Fill();
     operationsStackPanel = scrollablePanel.ScrollableContent.Add(new StackPanel()
     {
         Orientation = Orientation.Vertical, AutoSize = true
     }).FillHorizontally();
     noNotificationsLabel = Add(new Label()
     {
         Text = "No notifications".ToConsoleString(), X = 1, Y = 1
     });
     manager.Operations.SynchronizeForLifetime(Operations_Added, Operations_Removed, Operations_Changed, this);
 }
Example #6
0
        public static void ShowMessage(ConsoleString message, Action <DialogButton> resultCallback, bool allowEscapeToCancel = true, int maxHeight = 10, params DialogButton [] buttons)
        {
            ConsoleApp.AssertAppThread();
            if (buttons.Length == 0)
            {
                throw new ArgumentException("You need to specify at least one button");
            }

            ConsolePanel dialogContent = new ConsolePanel();

            Dialog dialog = new Dialog(dialogContent);

            dialog.MaxHeight           = maxHeight;
            dialog.AllowEscapeToCancel = allowEscapeToCancel;
            dialog.Cancelled.SubscribeForLifetime(() => { resultCallback(null); }, dialog);

            ScrollablePanel messagePanel = dialogContent.Add(new ScrollablePanel()).Fill(padding: new Thickness(0, 0, 1, 3));
            Label           messageLabel = messagePanel.ScrollableContent.Add(new Label()
            {
                Mode = LabelRenderMode.MultiLineSmartWrap, Text = message
            }).FillHorizontally(padding: new Thickness(3, 3, 0, 0));

            StackPanel buttonPanel = dialogContent.Add(new StackPanel()
            {
                Margin = 1, Height = 1, Orientation = Orientation.Horizontal
            }).FillHorizontally(padding: new Thickness(1, 0, 0, 0)).DockToBottom(padding: 1);

            Button firstButton = null;

            foreach (var buttonInfo in buttons)
            {
                var    myButtonInfo = buttonInfo;
                Button b            = new Button()
                {
                    Text = buttonInfo.DisplayText
                };
                b.Pressed.SubscribeForLifetime(() =>
                {
                    ConsoleApp.Current.LayoutRoot.Controls.Remove(dialog);
                    resultCallback(myButtonInfo);
                }, dialog);
                buttonPanel.Controls.Add(b);
                firstButton = firstButton ?? b;
            }
            ConsoleApp.Current.LayoutRoot.Controls.Add(dialog);
        }