WizardAsView.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using Terminal.Gui;
  2. namespace UICatalog.Scenarios;
  3. [ScenarioMetadata ("WizardAsView", "Shows using the Wizard class in an non-modal way")]
  4. [ScenarioCategory ("Wizards")]
  5. public class WizardAsView : Scenario
  6. {
  7. public override void Main ()
  8. {
  9. Application.Init ();
  10. var menu = new MenuBar
  11. {
  12. Menus =
  13. [
  14. new MenuBarItem (
  15. "_File",
  16. new MenuItem []
  17. {
  18. new (
  19. "_Restart Configuration...",
  20. "",
  21. () => MessageBox.Query (
  22. "Wizaard",
  23. "Are you sure you want to reset the Wizard and start over?",
  24. "Ok",
  25. "Cancel"
  26. )
  27. ),
  28. new (
  29. "Re_boot Server...",
  30. "",
  31. () => MessageBox.Query (
  32. "Wizaard",
  33. "Are you sure you want to reboot the server start over?",
  34. "Ok",
  35. "Cancel"
  36. )
  37. ),
  38. new (
  39. "_Shutdown Server...",
  40. "",
  41. () => MessageBox.Query (
  42. "Wizaard",
  43. "Are you sure you want to cancel setup and shutdown?",
  44. "Ok",
  45. "Cancel"
  46. )
  47. )
  48. }
  49. )
  50. ]
  51. };
  52. Toplevel topLevel = new ();
  53. topLevel.Add (menu);
  54. // No need for a Title because the border is disabled
  55. var wizard = new Wizard { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill () };
  56. // Set Mdoal to false to cause the Wizard class to render without a frame and
  57. // behave like an non-modal View (vs. a modal/pop-up Window).
  58. wizard.Modal = false;
  59. wizard.MovingBack += (s, args) =>
  60. {
  61. //args.Cancel = true;
  62. //actionLabel.Text = "Moving Back";
  63. };
  64. wizard.MovingNext += (s, args) =>
  65. {
  66. //args.Cancel = true;
  67. //actionLabel.Text = "Moving Next";
  68. };
  69. wizard.Finished += (s, args) =>
  70. {
  71. //args.Cancel = true;
  72. MessageBox.Query ("Setup Wizard", "Finished", "Ok");
  73. Application.RequestStop ();
  74. };
  75. wizard.Cancelled += (s, args) =>
  76. {
  77. int btn = MessageBox.Query ("Setup Wizard", "Are you sure you want to cancel?", "Yes", "No");
  78. args.Cancel = btn == 1;
  79. if (btn == 0)
  80. {
  81. Application.RequestStop ();
  82. }
  83. };
  84. // Add 1st step
  85. var firstStep = new WizardStep { Title = "End User License Agreement" };
  86. wizard.AddStep (firstStep);
  87. firstStep.NextButtonText = "Accept!";
  88. firstStep.HelpText =
  89. "This is the End User License Agreement.\n\n\n\n\n\nThis is a test of the emergency broadcast system. This is a test of the emergency broadcast system.\nThis is a test of the emergency broadcast system.\n\n\nThis is a test of the emergency broadcast system.\n\nThis is a test of the emergency broadcast system.\n\n\n\nThe end of the EULA.";
  90. // Add 2nd step
  91. var secondStep = new WizardStep { Title = "Second Step" };
  92. wizard.AddStep (secondStep);
  93. secondStep.HelpText =
  94. "This is the help text for the Second Step.\n\nPress the button to change the Title.\n\nIf First Name is empty the step will prevent moving to the next step.";
  95. var buttonLbl = new Label { Text = "Second Step Button: ", X = 0, Y = 0 };
  96. var button = new Button
  97. {
  98. Text = "Press Me to Rename Step", X = Pos.Right (buttonLbl), Y = Pos.Top (buttonLbl)
  99. };
  100. button.Accept += (s, e) =>
  101. {
  102. secondStep.Title = "2nd Step";
  103. MessageBox.Query (
  104. "Wizard Scenario",
  105. "This Wizard Step's title was changed to '2nd Step'",
  106. "Ok"
  107. );
  108. };
  109. secondStep.Add (buttonLbl, button);
  110. var lbl = new Label { Text = "First Name: ", X = Pos.Left (buttonLbl), Y = Pos.Bottom (buttonLbl) };
  111. var firstNameField = new TextField { Text = "Number", Width = 30, X = Pos.Right (lbl), Y = Pos.Top (lbl) };
  112. secondStep.Add (lbl, firstNameField);
  113. lbl = new Label { Text = "Last Name: ", X = Pos.Left (buttonLbl), Y = Pos.Bottom (lbl) };
  114. var lastNameField = new TextField { Text = "Six", Width = 30, X = Pos.Right (lbl), Y = Pos.Top (lbl) };
  115. secondStep.Add (lbl, lastNameField);
  116. // Add last step
  117. var lastStep = new WizardStep { Title = "The last step" };
  118. wizard.AddStep (lastStep);
  119. lastStep.HelpText =
  120. "The wizard is complete!\n\nPress the Finish button to continue.\n\nPressing Esc will cancel.";
  121. topLevel.Add (wizard);
  122. Application.Run (topLevel);
  123. topLevel.Dispose ();
  124. Application.Shutdown ();
  125. }
  126. }