protected IMenuOption <IMenuFunc> CreateMenuFuncOption(MenuOptionKey key, string label, Action action, bool handleException = true, PostInvokeCommand postInvokeCommand = PostInvokeCommand.StayInSubmenu, bool waitForKeyPress = true) { return(this.CreateMenuFuncOption(key, label, MenuFunc)); PostInvokeCommand MenuFunc() { try { action(); } catch (Exception exception) { if (!handleException) { throw exception; } Print.Error("Uh-oh! Something unexpected happened and an exception was thrown."); if (this.Confirm("Do you want to view the exception?")) { Print.Exception(exception, PostPrintOption.PrintNewLineAndWaitForKeyPress); } } return(waitForKeyPress ? this.WaitForKeyPressAndReturn(postInvokeCommand) : postInvokeCommand); } }
protected IMenu CreateYesOrNoMenu(string label, Action yesAction, Action noAction, PostInvokeCommand yesActionPostInvokeCommand = PostInvokeCommand.ExitSubmenu, bool yesAsDefault = true) { var yesOption = this.CreateMenuFuncOption(MenuOptionKey.Y, "Yes", YesFunc); var noOption = this.CreateMenuFuncOption(MenuOptionKey.N, "No", NoFunc); var yesNoMenu = yesAsDefault ? new Menu(label, yesOption, noOption) : new Menu(label, noOption, yesOption); return(yesNoMenu); PostInvokeCommand YesFunc() { yesAction(); return(yesActionPostInvokeCommand); } PostInvokeCommand NoFunc() { noAction(); return(PostInvokeCommand.ExitSubmenu); } }
private void SetEmptyMenuReturnCommand(bool isRootMenu) { this._emptyMenuReturnCommand = isRootMenu ? PostInvokeCommand.ExitRootMenu : PostInvokeCommand.ExitSubmenu; }
protected PostInvokeCommand WaitForKeyPressAndReturn(PostInvokeCommand postInvokeCommand = PostInvokeCommand.StayInSubmenu) { this.WaitForKeyPress(); return(postInvokeCommand); }