Esempio n. 1
0
        /// <summary>
        /// This method executes the action or selects the menu option.
        /// </summary>
        /// <param name="option">The option to execute.</param>
        protected virtual void OptionAction(ConsoleOption option)
        {
            option.Action?.Invoke(this, option);

            if (option.Menu != null)
            {
                option.Menu.Show(Context.State, Context.PageOptionsLength, contextInfo: ContextInfo);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// This method traverses the menu structure and executes the shortcut option.
        /// </summary>
        /// <param name="option">The option.</param>
        /// <param name="shortcut">The shortcut id to execute.</param>
        protected void ShortcutInvoke(ConsoleOption option, string shortcut)
        {
            if (option == null || string.IsNullOrEmpty(shortcut))
            {
                return;
            }

            if (option.Shortcut == shortcut)
            {
                ContextInfo.Add($"Shortcut '{shortcut}' executed.");
                option.Action?.Invoke(this, option);

                return;
            }

            ShortcutInvoke(option.Menu?.Context, shortcut);
        }
Esempio n. 3
0
        /// <summary>
        /// This method can be called by an external process to update the info messages displayed in the menu.
        /// </summary>
        /// <param name="message">The info message</param>
        /// <param name="refresh">The refresh option flag.</param>
        /// <param name="type">The log type.</param>
        public static ConsoleMenu AddOption(this ConsoleMenu menu, ConsoleOption option)
        {
            menu.Context.Options.Add(option);

            return(menu);
        }