Exemplo n.º 1
0
        /// <summary>
        /// Manages the keys menu
        /// </summary>
        /// <returns><c>true</c>, if the exit command was issued, <c>false</c> otherwise.</returns>
        bool KeysMenu()
        {
            KeysCommand command = KeysCommand.Invalid;

            while (command != KeysCommand.Back)
            {
                Console.Write("\r" + commandPrefix);
                string cmd = Console.ReadLine();
                command = (KeysCommand)ToCommand(Menu.Keys, cmd);
                switch (command)
                {
                case KeysCommand.Add:
                    MenuEventArgs addArgs   = ProcessCommandArgs(Menu.Keys, KeysCommand.Add, cmd);
                    string        addEntity = (string)addArgs.Arguments.First(m => m.Key.Equals(KeysArg.Entity)).Value;
                    string        addKey    = (string)addArgs.Arguments.First(m => m.Key.Equals(KeysArg.Key)).Value;
                    Keys.AddAction(Keys.Action.Add, addEntity, addKey);
                    break;

                case KeysCommand.Back:
                    if (Keys.Pending > 0)
                    {
                        ProcessLog(ProcessPrint.Warn, "There are pending changes to apply!");
                        ProcessLog(ProcessPrint.Question, "Do you want to discard the changes (y/n)");
                        if (Console.ReadLine().ToBool())
                        {
                            Keys.Discard();
                        }
                        else
                        {
                            Keys.Save();
                        }
                    }
                    break;

                case KeysCommand.Clear: Console.Clear(); break;

                case KeysCommand.Del:
                    MenuEventArgs delArgs   = ProcessCommandArgs(Menu.Keys, KeysCommand.Del, cmd);
                    string        delEntity = (string)delArgs.Arguments.First(m => m.Key.Equals(KeysArg.Entity)).Value;
                    Keys.AddAction(Keys.Action.Del, delEntity, "");
                    break;

                case KeysCommand.Discard: Keys.Discard(); break;

                case KeysCommand.Exit: return(true);

                case KeysCommand.Help: HelpPrints.PrintKeyshelp(); break;

                case KeysCommand.Invalid:
                    ProcessLog(ProcessPrint.Error, "Invalid command", true);
                    break;

                case KeysCommand.List:
                    MenuEventArgs listArgs = ProcessCommandArgs(Menu.Keys, KeysCommand.List, cmd);
                    bool          showKey  = (bool)listArgs.Arguments.First(m => m.Key.Equals(KeysArg.ShowKey)).Value;
                    Program.database.PrintEntities(showKey);
                    break;

                case KeysCommand.ListChanges: Keys.PrintChanges(); break;

                case KeysCommand.Save: Keys.Save(); break;
                }
            }
            return(false);
        }