Beispiel #1
0
        public IEnumerable <KeyValuePair <ConsoleKeySelection, T> > PromptKeyMatrix <T>(ICollection <T> collection, string selectionTitle, MatrixSelectionMethod method = MatrixSelectionMethod.SelectMany, Nullable <int> defaultChoice = null)
        {
            var keyMatrix = CreateKeyMatrix <T>(collection, defaultChoice);

            return(PromptKeyMatrix <T>(keyMatrix, collection, selectionTitle, method));
        }
Beispiel #2
0
        public IEnumerable <KeyValuePair <ConsoleKeySelection, T> > PromptKeyMatrix <T>(Dictionary <ConsoleKeySelection, T> keyMatrix, ICollection <T> collection, string selectionTitle, MatrixSelectionMethod method = MatrixSelectionMethod.SelectOne)
        {
            while (1 == 1)
            {
                Console.WriteLine(selectionTitle + " [Results: " + collection.Count + "]" + (collection.Count > 22 ? " RESULTS TRUNCATED" : "") + ":");
                foreach (var choice in keyMatrix)
                {
                    Console.WriteLine(string.Format(
                                          "[{0}] {1}{2}{3}{4}) {5}",
                                          choice.Key.Selected ? "*" : " ",
                                          choice.Key.Ctrl || choice.Key.Shift ? choice.Key.Ctrl && choice.Key.Shift ? "" : "     " : "          ",
                                          choice.Key.Ctrl ? "ctrl+" : "",
                                          choice.Key.Shift ? "shft+" : "",
                                          choice.Key.Key.ToString().Substring(1),
                                          string.IsNullOrEmpty(choice.Key.DisplayName) ? choice.Value.ToString() : choice.Key.DisplayName
                                          ));
                }

                Console.WriteLine("Select one " + (method == MatrixSelectionMethod.SelectMany ? "or more " : "") + "from above and ENTER to continue.");
                Console.Write(">");
                var commandKey = Console.ReadKey();
                Console.WriteLine();

                if (commandKey.Key == ConsoleKey.Enter && keyMatrix.Any(o => o.Key.Selected == true))
                {
                    break;
                }
                var selection = keyMatrix.FirstOrDefault(o => o.Key.Key == commandKey.Key && o.Key.Ctrl == commandKey.Modifiers.HasFlag(ConsoleModifiers.Control) && o.Key.Shift == commandKey.Modifiers.HasFlag(ConsoleModifiers.Shift));
                if (!new KeyValuePair <ConsoleKeySelection, T>().Equals(selection))//not default
                {
                    if (method == MatrixSelectionMethod.SelectOne)
                    {
                        foreach (var k in keyMatrix.Where(o => o.Key.Selected))
                        {
                            k.Key.Selected = false;
                        }
                        selection.Key.Selected = true;
                    }
                    else
                    {
                        selection.Key.Selected = !selection.Key.Selected;
                    }
                }
                Console.Clear();
            }
            return(keyMatrix.Where(o => o.Key.Selected == true));
        }