Example #1
0
        private void BuildSelectableMenu()
        {
            this.selectableMenu =
                this.currentFolder.Folders
                .Concat(this.currentFolder.Files.Cast <object>())
                .Skip(this.itemIndex)
                .Take(ItemsPerPage)
                .Select(x => x is FileEntry
                                     ? new SelectableMenuItem((FileEntry)x)
                                     : new SelectableMenuItem(x as FolderEntry))
                .Select((x, i) => new { Key = MenuKeyChars[i], Value = x })
                .ToDictionary(x => x.Key, x => x.Value);

            this.selectedMenuItem = this.selectableMenu.First().Value;
        }
Example #2
0
        public void Run()
        {
            this.BuildSelectableMenu();
            if (!this.selectableMenu.Any())
            {
                Screen.Print("There is nothing in the vault");
                return;
            }

            this.PrintMenu();

            while (this.isRunning)
            {
                var keyInfo = Screen.ReadKey();

                ExecutableMenuItem executableMenuItem;
                if (this.executableMenu.TryGetValue(keyInfo.Key, out executableMenuItem))
                {
                    if (!executableMenuItem.Visible)
                    {
                        continue;
                    }

                    executableMenuItem.Execute();
                    if (!this.isRunning)
                    {
                        break;
                    }

                    this.PrintMenu();
                    continue;
                }

                var keyChar = keyInfo.KeyChar.ToString(CultureInfo.InvariantCulture).ToUpper()[0];

                SelectableMenuItem selectableMenuItem;
                if (!this.selectableMenu.TryGetValue(keyChar, out selectableMenuItem))
                {
                    continue;
                }

                this.selectedMenuItem = selectableMenuItem;
                this.PrintMenu();
            }
        }