Esempio n. 1
0
        public override bool SelectObjects <T>(DialogArgs args, T[] available, out T[] selected)
        {
            if (available.Length == 0)
            {
                selected = new T[0];
                return(true);
            }

            for (int i = 0; i < available.Length; i++)
            {
                Console.WriteLine($"{i}:{available[i]}");
            }

            var result = Console.ReadLine();

            if (string.IsNullOrWhiteSpace(result))
            {
                // selecting none is a valid user selection
                selected = new T[0];
                return(true);
            }

            var selectIdx = result.Split(",", StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();

            selected = available.Where((e, idx) => selectIdx.Contains(idx)).ToArray();
            return(true);
        }
Esempio n. 2
0
        public override IMapsDirectlyToDatabaseTable SelectOne(DialogArgs args, IMapsDirectlyToDatabaseTable[] availableObjects)
        {
            if (!availableObjects.Any())
            {
                MessageBox.Show($"There are no compatible objects in your RMDP for:{Environment.NewLine}{args}");
                return(null);
            }

            //if there is only one object available to select
            if (availableObjects.Length == 1)
            {
                if (args.AllowAutoSelect)
                {
                    return(availableObjects[0]);
                }
            }

            var selectDialog = new SelectDialog <IMapsDirectlyToDatabaseTable>(args, this, availableObjects, false, false);

            if (selectDialog.ShowDialog() == DialogResult.OK)
            {
                return(selectDialog.Selected);
            }

            return(null); //user didn't select one of the IMapsDirectlyToDatabaseTable objects shown in the dialog
        }
Esempio n. 3
0
        public override IMapsDirectlyToDatabaseTable[] SelectMany(DialogArgs args, Type arrayElementType,
                                                                  IMapsDirectlyToDatabaseTable[] availableObjects)
        {
            if (!availableObjects.Any())
            {
                MessageBox.Show("There are no '" + arrayElementType.Name + "' objects in your RMDP");
                return(null);
            }

            var selectDialog = new SelectDialog <IMapsDirectlyToDatabaseTable>(args, this, availableObjects, false, false);

            selectDialog.AllowMultiSelect = true;

            if (selectDialog.ShowDialog() == DialogResult.OK)
            {
                var ms       = selectDialog.MultiSelected.ToList();
                var toReturn = Array.CreateInstance(arrayElementType, ms.Count);

                for (int i = 0; i < ms.Count; i++)
                {
                    toReturn.SetValue(ms[i], i);
                }

                return(toReturn.Cast <IMapsDirectlyToDatabaseTable>().ToArray());
            }

            return(null);
        }
Esempio n. 4
0
 public override bool TypeText(DialogArgs args, int maxLength, string initialText, out string text,
                               bool requireSaneHeaderText)
 {
     WritePromptFor(args);
     text = ReadLineWithAuto();
     return(!string.IsNullOrWhiteSpace(text));
 }
Esempio n. 5
0
        public string GetString(DialogArgs args, List <string> options)
        {
            WritePromptFor(args);

            ReadLine.AutoCompletionHandler = new AutoComplete(options);
            return(ReadLine.Read());
        }
Esempio n. 6
0
        protected override bool SelectValueTypeImpl(DialogArgs args, Type paramType, object initialValue, out object chosen)
        {
            WritePromptFor(args);

            chosen = UsefulStuff.ChangeType(ReadLineWithAuto(), paramType);

            return(true);
        }
Esempio n. 7
0
        public override IMapsDirectlyToDatabaseTable[] SelectMany(DialogArgs args, Type arrayElementType,
                                                                  IMapsDirectlyToDatabaseTable[] availableObjects)
        {
            var dlg = new ConsoleGuiSelectMany(this, args.WindowTitle, availableObjects);

            Application.Run(dlg);

            return(dlg.ResultOk ? dlg.Result.Cast <IMapsDirectlyToDatabaseTable>().ToArray() : new IMapsDirectlyToDatabaseTable[0]);
        }
Esempio n. 8
0
        public override bool SelectObjects <T>(DialogArgs args, T[] available, out T[] selected)
        {
            var dlg = new ConsoleGuiSelectMany(this, args.WindowTitle, available);

            Application.Run(dlg);

            selected = dlg.Result.Cast <T>().ToArray();
            return(dlg.ResultOk);
        }
Esempio n. 9
0
        public SelectDialog(DialogArgs args, IBasicActivateItems activator, IEnumerable <T> toSelectFrom, bool allowSelectingNULL, bool allowDeleting) :
            this(activator, toSelectFrom, allowSelectingNULL, allowDeleting)
        {
            taskDescriptionLabel1.Visible = true;
            taskDescriptionLabel1.SetupFor(args);

            Text = args.WindowTitle;
            SetInitialFilter(args.InitialSearchText);
        }
Esempio n. 10
0
        public override bool TypeText(DialogArgs args, int maxLength, string initialText, out string text, bool requireSaneHeaderText)
        {
            var textTyper = new TypeTextOrCancelDialog(args, maxLength, initialText, allowBlankText: false, multiLine: maxLength > 1000)
            {
                RequireSaneHeaderText = requireSaneHeaderText
            };

            text = textTyper.ShowDialog() == DialogResult.OK ? textTyper.ResultText : null;
            return(!string.IsNullOrWhiteSpace(text));
        }
Esempio n. 11
0
        public override void SelectAnythingThen(DialogArgs args, Action <IMapsDirectlyToDatabaseTable> callback)
        {
            NavigateToObjectUI navigate = new NavigateToObjectUI(this)
            {
                Text = args.WindowTitle
            };

            navigate.CompletionAction = callback;
            navigate.Show();
        }
Esempio n. 12
0
        public TypeTextOrCancelDialog(DialogArgs args, int maxCharacters, string startingTextForInputBox = null, bool allowBlankText = false, bool multiLine = false)
        {
            _allowBlankText = allowBlankText;
            _multiline      = multiLine;

            InitializeComponent();

            var header = args.WindowTitle;


            if (header != null && header.Length > WideMessageBox.MAX_LENGTH_TITLE)
            {
                header = header.Substring(0, WideMessageBox.MAX_LENGTH_TITLE);
            }

            taskDescriptionLabel1.SetupFor(args);

            this.Text = header;
            this.textBox1.MaxLength = maxCharacters;

            if (_multiline)
            {
                var editor = new ScintillaTextEditorFactory();
                _scintilla              = editor.Create(null, SyntaxLanguage.None, null, true, false);
                _scintilla.Dock         = DockStyle.Fill;
                _scintilla.TextChanged += _scintilla_TextChanged;
                _scintilla.KeyDown     += _scintilla_KeyDown;
                _scintilla.Text         = startingTextForInputBox;
                _scintilla.WrapMode     = WrapMode.Word;

                pTextEditor.Controls.Remove(textBox1);
                pTextEditor.Controls.Add(_scintilla);

                //Move cursor to the end of the textbox
                this.ActiveControl        = _scintilla;
                _scintilla.SelectionStart = _scintilla.TextLength;

                this.textBox1.Anchor     = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
                this.textBox1.ScrollBars = ScrollBars.Vertical;
                this.Width = 740;

                //Update the tooltip for the OK button
                toolTip.SetToolTip(btnOk, "Press to Save (SHIFT + ENTER)");
            }
            else
            {
                textBox1.Text = startingTextForInputBox;
                Width         = Math.Max(540, Math.Min(740, taskDescriptionLabel1.PreferredWidth));

                this.ActiveControl = textBox1;
            }

            SetEnabledness();
        }
Esempio n. 13
0
        public override bool YesNo(DialogArgs args, out bool chosen)
        {
            WritePromptFor(args, false);

            Console.WriteLine(args.EntryLabel + "(Y/n)");

            //if user picks no then it's false otherwise true
            chosen = !string.Equals(Console.ReadLine()?.Trim(), "n", StringComparison.CurrentCultureIgnoreCase);

            //user made a conscious decision
            return(true);
        }
Esempio n. 14
0
        public override bool SelectType(DialogArgs args, Type[] available, out Type chosen)
        {
            var dlg = new ConsoleGuiBigListBox <Type>(args.WindowTitle, "Ok", true, available.ToList(), null, true);

            if (dlg.ShowDialog())
            {
                chosen = dlg.Selected;
                return(true);
            }

            chosen = null;
            return(false);
        }
Esempio n. 15
0
        public override bool SelectEnum(DialogArgs args, Type enumType, out Enum chosen)
        {
            var dlg = new ConsoleGuiBigListBox <Enum>(args.WindowTitle, "Ok", false, Enum.GetValues(enumType).Cast <Enum>().ToList(), null, false);

            if (dlg.ShowDialog())
            {
                chosen = dlg.Selected;
                return(true);
            }

            chosen = null;
            return(false);
        }
Esempio n. 16
0
        public override bool YesNo(DialogArgs args, out bool chosen)
        {
            GetDialogDimensions(out var w, out var h);

            // dont use the full height if your just asking a yes/no question with no big description
            h = Math.Min(5 + ((args.TaskDescription?.Length ?? 0) / 20), h);

            int result = MessageBox.Query(w, h, args.WindowTitle ?? "", args.TaskDescription ?? "", "yes", "no", "cancel");

            chosen = result == 0;

            return(result != 2);
        }
Esempio n. 17
0
        public override bool SelectObject <T>(DialogArgs args, T[] available, out T selected)
        {
            var pick = new SelectDialog <T>(args, this, available, false, false);

            if (pick.ShowDialog() == DialogResult.OK)
            {
                selected = pick.Selected;
                return(true);
            }

            selected = default(T);
            return(false);
        }
Esempio n. 18
0
        public override bool YesNo(DialogArgs args, out bool chosen)
        {
            if (YesNoResponse.HasValue)
            {
                chosen = YesNoResponse.Value;

                //'user' consciously chose a value
                return(true);
            }


            throw new Exception("Did not expect to be asked a question but we were asked :" + args);
        }
Esempio n. 19
0
        public override bool SelectEnum(DialogArgs args, Type enumType, out Enum chosen)
        {
            var selector = new SelectDialog <Enum>(args, this, Enum.GetValues(enumType).Cast <Enum>().ToArray(), false, false);

            if (selector.ShowDialog() == DialogResult.OK)
            {
                chosen = selector.Selected;
                return(true);
            }

            chosen = default;
            return(false);
        }
Esempio n. 20
0
        public override bool SelectType(DialogArgs args, Type[] available, out Type chosen)
        {
            var dlg = new SelectDialog <Type>(args, this, available, false, false);

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                chosen = dlg.Selected;
                return(true);
            }


            chosen = null;
            return(false);
        }
Esempio n. 21
0
        protected override bool SelectValueTypeImpl(DialogArgs args, Type paramType, object initialValue, out object chosen)
        {
            //whatever else it is use string
            var typeTextDialog = new TypeTextOrCancelDialog(args, 1000, initialValue?.ToString());

            if (typeTextDialog.ShowDialog() == DialogResult.OK)
            {
                chosen = UsefulStuff.ChangeType(typeTextDialog.ResultText, paramType);
                return(true);
            }

            chosen = null;
            return(false);
        }
Esempio n. 22
0
        public override bool TypeText(DialogArgs args, int maxLength, string initialText, out string text,
                                      bool requireSaneHeaderText)
        {
            var dlg = new ConsoleGuiTextDialog(args, initialText);

            if (dlg.ShowDialog())
            {
                text = dlg.ResultText;
                return(true);
            }

            text = null;
            return(false);
        }
Esempio n. 23
0
        public override bool SelectObjects <T>(DialogArgs args, T[] available, out T[] selected)
        {
            var pick = new SelectDialog <T>(args, this, available, false, false);

            pick.AllowMultiSelect = true;

            if (pick.ShowDialog() == DialogResult.OK)
            {
                selected = pick.MultiSelected.ToArray();
                return(true);
            }

            selected = default(T[]);
            return(false);
        }
Esempio n. 24
0
        public override IMapsDirectlyToDatabaseTable SelectOne(DialogArgs args, IMapsDirectlyToDatabaseTable[] availableObjects)
        {
            if (args.AllowAutoSelect && availableObjects.Length == 1)
            {
                return(availableObjects[0]);
            }

            var dlg = new ConsoleGuiSelectOne(CoreChildProvider, availableObjects);

            if (dlg.ShowDialog())
            {
                return(dlg.Selected);
            }

            return(null);
        }
Esempio n. 25
0
        public void SetupFor(DialogArgs args)
        {
            var task       = args.TaskDescription;
            var entryLabel = args.EntryLabel;


            tbTaskDescription.Visible = pnlTaskDescription.Visible = !string.IsNullOrWhiteSpace(task);
            tbTaskDescription.Text    = task;

            tbEntryLabel.Visible = pnlEntryLabel.Visible = !string.IsNullOrWhiteSpace(entryLabel);

            if (entryLabel != null && entryLabel.Length > WideMessageBox.MAX_LENGTH_BODY)
            {
                entryLabel = entryLabel.Substring(0, WideMessageBox.MAX_LENGTH_BODY);
            }

            // set prompt text. If theres a TaskDescription too then leave a bit of extra space
            this.tbEntryLabel.Text = entryLabel;

            this.Height = (!string.IsNullOrWhiteSpace(entryLabel) ? tbEntryLabel.Height : 0) +
                          (!string.IsNullOrWhiteSpace(task) ? tbTaskDescription.Height : 0);

            //Switch style based on args.DesciptionSeverity
            switch (args.DesciptionSeverity)
            {
            case (ProgressEventType.Warning):
                _backColour = Color.FromArgb(253, 248, 228);
                _foreColour = Color.FromArgb(134, 105, 53);
                break;

            case (ProgressEventType.Error):
                _backColour = Color.FromArgb(242, 222, 223);
                _foreColour = Color.FromArgb(143, 58, 75);
                break;

            //Default blue information colours
            default:
                _backColour = Color.FromArgb(217, 236, 242);
                _foreColour = Color.FromArgb(44, 108, 128);
                break;
            }

            pnlTaskDescriptionBorder.BackColor = _backColour;
            tbTaskDescription.BackColor        = _backColour;
            tbTaskDescription.ForeColor        = _foreColour;
        }
Esempio n. 26
0
        public override IMapsDirectlyToDatabaseTable[] SelectMany(DialogArgs args, Type arrayElementType,
                                                                  IMapsDirectlyToDatabaseTable[] availableObjects)
        {
            WritePromptFor(args);

            var value = ReadLineWithAuto(new PickObjectBase[]
                                         { new PickObjectByID(this), new PickObjectByName(this) },
                                         availableObjects.Select(t => t.GetType().Name).Distinct());

            var unavailable = value.DatabaseEntities.Except(availableObjects).ToArray();

            if (unavailable.Any())
            {
                throw new Exception("The following objects were not among the listed available objects " + string.Join(",", unavailable.Select(o => o.ToString())));
            }

            return(value.DatabaseEntities.ToArray());
        }
Esempio n. 27
0
        /// <inheritdoc/>
        public override bool SelectObject <T>(DialogArgs args, T[] available, out T selected)
        {
            if (args.AllowAutoSelect && available.Length == 1)
            {
                selected = available[0];
                return(true);
            }

            var dlg = new ConsoleGuiBigListBox <T>(args.WindowTitle, "Ok", true, available, t => t.ToString(), true);

            if (dlg.ShowDialog())
            {
                selected = dlg.Selected;
                return(true);
            }

            selected = default(T);
            return(false);
        }
Esempio n. 28
0
        /// <inheritdoc/>
        public override bool YesNo(DialogArgs args, out bool chosen)
        {
            var dr = MessageBox.Show(args.TaskDescription, args.WindowTitle, MessageBoxButtons.YesNo);

            if (dr == DialogResult.Yes)
            {
                chosen = true;
                return(true);
            }

            if (dr == DialogResult.No)
            {
                chosen = false;
                return(true);
            }

            chosen = false;
            return(false);
        }
Esempio n. 29
0
        public override bool SelectEnum(DialogArgs args, Type enumType, out Enum chosen)
        {
            if (DisallowInput)
            {
                throw new InputDisallowedException($"Value required for '{args}'");
            }

            string chosenStr = GetString(args, Enum.GetNames(enumType).ToList());

            try
            {
                chosen = (Enum)Enum.Parse(enumType, chosenStr);
            }
            catch (Exception)
            {
                Console.WriteLine($"Could not parse value.  Valid Enum values are:{Environment.NewLine}{string.Join(Environment.NewLine,Enum.GetNames(enumType))}");
                throw;
            }

            return(true);
        }
Esempio n. 30
0
        public override IMapsDirectlyToDatabaseTable SelectOne(DialogArgs args, IMapsDirectlyToDatabaseTable[] availableObjects)
        {
            if (DisallowInput)
            {
                throw new InputDisallowedException($"Value required for '{args}'");
            }

            if (availableObjects.Length == 0)
            {
                throw new Exception("No available objects found");
            }

            //handle auto selection when there is one object
            if (availableObjects.Length == 1 && args.AllowAutoSelect)
            {
                return(availableObjects[0]);
            }

            Console.WriteLine(args.WindowTitle);

            Console.Write(args.EntryLabel);

            var value = ReadLineWithAuto(new PickObjectBase[]
                                         { new PickObjectByID(this), new PickObjectByName(this) },
                                         availableObjects.Select(t => t.GetType().Name).Distinct());

            var chosen = value.DatabaseEntities?.SingleOrDefault();

            if (chosen == null)
            {
                return(null);
            }

            if (!availableObjects.Contains(chosen))
            {
                throw new Exception("Picked object was not one of the listed available objects");
            }

            return(chosen);
        }