WizardAsView.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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
  56. {
  57. X = 0,
  58. Y = 0,
  59. Width = Dim.Fill (),
  60. Height = Dim.Fill (),
  61. ShadowStyle = ShadowStyle.None
  62. };
  63. // Set Mdoal to false to cause the Wizard class to render without a frame and
  64. // behave like an non-modal View (vs. a modal/pop-up Window).
  65. wizard.Modal = false;
  66. wizard.MovingBack += (s, args) =>
  67. {
  68. //args.Cancel = true;
  69. //actionLabel.Text = "Moving Back";
  70. };
  71. wizard.MovingNext += (s, args) =>
  72. {
  73. //args.Cancel = true;
  74. //actionLabel.Text = "Moving Next";
  75. };
  76. wizard.Finished += (s, args) =>
  77. {
  78. //args.Cancel = true;
  79. MessageBox.Query ("Setup Wizard", "Finished", "Ok");
  80. Application.RequestStop ();
  81. };
  82. wizard.Cancelled += (s, args) =>
  83. {
  84. int btn = MessageBox.Query ("Setup Wizard", "Are you sure you want to cancel?", "Yes", "No");
  85. args.Cancel = btn == 1;
  86. if (btn == 0)
  87. {
  88. Application.RequestStop ();
  89. }
  90. };
  91. // Add 1st step
  92. var firstStep = new WizardStep { Title = "End User License Agreement" };
  93. wizard.AddStep (firstStep);
  94. firstStep.NextButtonText = "Accept!";
  95. firstStep.HelpText =
  96. "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.";
  97. // Add 2nd step
  98. var secondStep = new WizardStep { Title = "Second Step" };
  99. wizard.AddStep (secondStep);
  100. secondStep.HelpText =
  101. "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.";
  102. var buttonLbl = new Label { Text = "Second Step Button: ", X = 0, Y = 0 };
  103. var button = new Button
  104. {
  105. Text = "Press Me to Rename Step", X = Pos.Right (buttonLbl), Y = Pos.Top (buttonLbl)
  106. };
  107. button.Accepted += (s, e) =>
  108. {
  109. secondStep.Title = "2nd Step";
  110. MessageBox.Query (
  111. "Wizard Scenario",
  112. "This Wizard Step's title was changed to '2nd Step'",
  113. "Ok"
  114. );
  115. };
  116. secondStep.Add (buttonLbl, button);
  117. var lbl = new Label { Text = "First Name: ", X = Pos.Left (buttonLbl), Y = Pos.Bottom (buttonLbl) };
  118. var firstNameField = new TextField { Text = "Number", Width = 30, X = Pos.Right (lbl), Y = Pos.Top (lbl) };
  119. secondStep.Add (lbl, firstNameField);
  120. lbl = new Label { Text = "Last Name: ", X = Pos.Left (buttonLbl), Y = Pos.Bottom (lbl) };
  121. var lastNameField = new TextField { Text = "Six", Width = 30, X = Pos.Right (lbl), Y = Pos.Top (lbl) };
  122. secondStep.Add (lbl, lastNameField);
  123. // Add last step
  124. var lastStep = new WizardStep { Title = "The last step" };
  125. wizard.AddStep (lastStep);
  126. lastStep.HelpText =
  127. "The wizard is complete!\n\nPress the Finish button to continue.\n\nPressing Esc will cancel.";
  128. topLevel.Add (wizard);
  129. Application.Run (topLevel);
  130. topLevel.Dispose ();
  131. Application.Shutdown ();
  132. }
  133. }