コード例 #1
0
        public ProgressOperationControl(ProgressOperationsManager manager, ProgressOperation operation)
        {
            this.Tag                  = operation;
            this.Operation            = operation;
            this.manager              = manager;
            this.Height               = 2;
            messageAndOperationsPanel = Add(new StackPanel()
            {
                Orientation = Orientation.Vertical
            }).Fill();

            messageLabel = messageAndOperationsPanel.Add(new Label()
            {
                Mode = LabelRenderMode.ManualSizing
            }).FillHorizontally();
            messageLabel.CanFocus = true;

            messageLabel.KeyInputReceived.SubscribeForLifetime((k) =>
            {
                if (k.Key == ConsoleKey.Enter)
                {
                    var msg = operation.Message;
                    if (operation.Details != null)
                    {
                        msg += "\n" + operation.Details;
                    }
                    Dialog.ShowMessage(msg);
                }
                else if (k.Key == ConsoleKey.Delete)
                {
                    var app = Application;
                    manager.Operations.Remove(operation);
                    app.FocusManager.TryMoveFocus();
                }
            }, this);


            actionPanel = messageAndOperationsPanel.Add(new StackPanel()
            {
                Orientation = Orientation.Horizontal, Height = 1, Margin = 2
            }).FillHorizontally(messageAndOperationsPanel);
            spinner = actionPanel.Add(new Spinner()
            {
                CanFocus = false
            });
            timeLabel = actionPanel.Add(new Label()
            {
                Mode = LabelRenderMode.SingleLineAutoSize, Text = operation.StartTime.ToFriendlyPastTimeStamp().ToConsoleString()
            });


            spinner.IsSpinning = operation.State == OperationState.InProgress;

            foreach (var action in operation.Actions)
            {
                BindActionToActionPanel(action);
            }

            AddedToVisualTree.SubscribeForLifetime(OnAddedToVisualTree, this);
        }
コード例 #2
0
ファイル: LogTailControl.cs プロジェクト: jiaw37/PowerArgs
 private void AddLine()
 {
     logStack.Add(new Label()
     {
         Text = ConsoleString.Empty, Mode = LabelRenderMode.ManualSizing
     }).FillHorizontally();
     logStack.Height = logStack.Controls.Count;
 }
コード例 #3
0
        private void BindActionToActionPanel(ProgressOperationAction action)
        {
            var button = actionPanel.Add(new Button()
            {
                Text = action.DisplayName, Tag = action
            });

            button.Pressed.SubscribeForLifetime(action.Action, button);
        }
コード例 #4
0
        public ProgressOperationControl(ProgressOperationsManager manager, ProgressOperation operation)
        {
            this.Tag = operation;
            this.Operation = operation;
            this.manager = manager;
            this.Height = 2;
            messageAndOperationsPanel = Add(new StackPanel() { Orientation = Orientation.Vertical }).Fill();

            messageLabel = messageAndOperationsPanel.Add(new Label() { Mode = LabelRenderMode.ManualSizing }).FillHoriontally();
            messageLabel.CanFocus = true;

            messageLabel.KeyInputReceived.SubscribeForLifetime((k) =>
            {
                if (k.Key == ConsoleKey.Enter)
                {
                    var msg = operation.Message;
                    if (operation.Details != null)
                    {
                        msg += "\n" + operation.Details;
                    }
                    Dialog.ShowMessage(msg);
                }
                else if(k.Key == ConsoleKey.Delete)
                {
                    var app = Application;
                    manager.Operations.Remove(operation);
                    app.FocusManager.TryMoveFocus();
                }
            }, this.LifetimeManager);

            actionPanel = messageAndOperationsPanel.Add(new StackPanel() { Orientation = Orientation.Horizontal, Height = 1, Margin = 2 }).FillHoriontally(messageAndOperationsPanel);
            spinner = actionPanel.Add(new Spinner() { CanFocus=false});
            timeLabel = actionPanel.Add(new Label() { Mode = LabelRenderMode.SingleLineAutoSize, Text = operation.StartTime.ToFriendlyPastTimeStamp().ToConsoleString() });

            spinner.IsSpinning = operation.State == OperationState.InProgress;

            foreach (var action in operation.Actions)
            {
                BindActionToActionPanel(action);
            }

            AddedToVisualTree.SubscribeForLifetime(OnAddedToVisualTree, this.LifetimeManager);
        }
コード例 #5
0
        public static Promise <DialogOption> Pick(ConsoleString message, IEnumerable <DialogOption> options, bool allowEscapeToCancel = true, int maxHeight = 12)
        {
            var deferred = Deferred <DialogOption> .Create();

            ConsoleApp.AssertAppThread();

            ConsolePanel dialogContent = new StackPanel()
            {
            };

            Dialog dialog = new Dialog(dialogContent);

            dialog.MaxHeight           = maxHeight;
            dialog.AllowEscapeToCancel = allowEscapeToCancel;


            Grid optionsGrid = dialogContent.Add(new Grid(options.Select(o => o as object).ToList())).Fill();

            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;

            DialogOption result = null;

            optionsGrid.SelectedItemActivated += () =>
            {
                result = optionsGrid.SelectedItem as DialogOption;
                ConsoleApp.Current.LayoutRoot.Controls.Remove(dialog);
            };

            dialog.RemovedFromVisualTree.SubscribeForLifetime(() =>
            {
                deferred.Resolve(result);
            }, dialog);

            ConsoleApp.Current.LayoutRoot.Controls.Add(dialog);
            return(deferred.Promise);
        }
コード例 #6
0
        private void InitCommandBar()
        {
            var divider = ConsoleString.Parse("[B=White] ");

            buttonStack = commandBar.Add(new StackPanel()
            {
                X = 1, Margin = 1, Height = 1, Orientation = Orientation.Horizontal, AutoSize = true
            }).CenterVertically();

            var newCommand = buttonStack.Add(new Button()
            {
                Text = "New".ToWhite(), Shortcut = new KeyboardShortcut(ConsoleKey.N, ConsoleModifiers.Alt)
            });

            newCommand.Pressed.SubscribeForLifetime(NewCommandImpl, newCommand);

            var openCommand = buttonStack.Add(new Button()
            {
                Text = "Open".ToWhite(), Shortcut = new KeyboardShortcut(ConsoleKey.O, ConsoleModifiers.Alt)
            });

            openCommand.Pressed.SubscribeForLifetime(OpenCommandImpl, openCommand);

            var saveCommand = buttonStack.Add(new Button()
            {
                Text = "Save".ToWhite(), Shortcut = new KeyboardShortcut(ConsoleKey.S, ConsoleModifiers.Alt)
            });

            saveCommand.Pressed.SubscribeForLifetime(SaveCommandImpl, saveCommand);

            var saveAsCommand = buttonStack.Add(new Button()
            {
                Text = "Save as".ToWhite()
            });

            saveAsCommand.Pressed.SubscribeForLifetime(SaveAsCommandImpl, saveAsCommand);

            var undoCommand = buttonStack.Add(new Button()
            {
                Text = "Undo".ToWhite(), Shortcut = new KeyboardShortcut(ConsoleKey.Z, ConsoleModifiers.Alt)
            });

            undoCommand.Pressed.SubscribeForLifetime(UndoCommandImpl, undoCommand);

            var redoCommand = buttonStack.Add(new Button()
            {
                Text = "Redo".ToWhite(), Shortcut = new KeyboardShortcut(ConsoleKey.Y, ConsoleModifiers.Alt)
            });

            redoCommand.Pressed.SubscribeForLifetime(RedoCommandImpl, redoCommand);

            buttonStack.Add(new Label()
            {
                Text = divider
            });

            var frameUpCommand = buttonStack.Add(new Button()
            {
                Text = "Previous Frame".ToWhite(), Shortcut = new KeyboardShortcut(ConsoleKey.PageUp)
            });

            frameUpCommand.Pressed.SubscribeForLifetime(FrameUpCommandImpl, frameUpCommand);

            var frameDownCommand = buttonStack.Add(new Button()
            {
                Text = "Next Frame".ToWhite(), Shortcut = new KeyboardShortcut(ConsoleKey.PageDown)
            });

            frameDownCommand.Pressed.SubscribeForLifetime(FrameDownCommandImpl, frameDownCommand);

            var duplicateCommand = buttonStack.Add(new Button()
            {
                Text = "Duplicate Frame".ToWhite(), Shortcut = new KeyboardShortcut(ConsoleKey.D, ConsoleModifiers.Alt)
            });

            duplicateCommand.Pressed.SubscribeForLifetime(DuplicateFrameCommandImpl, frameUpCommand);

            buttonStack.Add(new Label()
            {
                Text = divider
            });

            foreach (var editorButton in editor.CreateStandardButtons())
            {
                buttonStack.Add(editorButton);
            }
        }