WizardAsView.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Terminal.Gui;
  6. namespace UICatalog.Scenarios {
  7. [ScenarioMetadata (Name: "WizardAsView", Description: "Shows using the Wizard class in an non-modal way")]
  8. [ScenarioCategory ("Wizards")]
  9. public class WizardAsView : Scenario {
  10. public override void Init ()
  11. {
  12. Application.Init ();
  13. var menu = new MenuBar (new MenuBarItem [] {
  14. new MenuBarItem ("_File", new MenuItem [] {
  15. new MenuItem ("_Restart Configuration...", "", () => MessageBox.Query ("Wizaard", "Are you sure you want to reset the Wizard and start over?", "Ok", "Cancel")),
  16. new MenuItem ("Re_boot Server...", "", () => MessageBox.Query ("Wizaard", "Are you sure you want to reboot the server start over?", "Ok", "Cancel")),
  17. new MenuItem ("_Shutdown Server...", "", () => MessageBox.Query ("Wizaard", "Are you sure you want to cancel setup and shutdown?", "Ok", "Cancel")),
  18. })
  19. });
  20. Application.Top.Add (menu);
  21. // No need for a Title because the border is disabled
  22. var wizard = new Wizard () {
  23. X = 0,
  24. Y = 0,
  25. Width = Dim.Fill (),
  26. Height = Dim.Fill (),
  27. };
  28. // Set Mdoal to false to cause the Wizard class to render without a frame and
  29. // behave like an non-modal View (vs. a modal/pop-up Window).
  30. wizard.Modal = false;
  31. wizard.MovingBack += (s, args) => {
  32. //args.Cancel = true;
  33. //actionLabel.Text = "Moving Back";
  34. };
  35. wizard.MovingNext += (s, args) => {
  36. //args.Cancel = true;
  37. //actionLabel.Text = "Moving Next";
  38. };
  39. wizard.Finished += (s, args) => {
  40. //args.Cancel = true;
  41. MessageBox.Query ("Setup Wizard", "Finished", "Ok");
  42. Application.RequestStop ();
  43. };
  44. wizard.Cancelled += (s, args) => {
  45. var btn = MessageBox.Query ("Setup Wizard", "Are you sure you want to cancel?", "Yes", "No");
  46. args.Cancel = btn == 1;
  47. if (btn == 0) {
  48. Application.RequestStop ();
  49. }
  50. };
  51. // Add 1st step
  52. var firstStep = new WizardStep () { Title = "End User License Agreement" };
  53. wizard.AddStep (firstStep);
  54. firstStep.NextButtonText = "Accept!";
  55. firstStep.HelpText = "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.";
  56. // Add 2nd step
  57. var secondStep = new WizardStep () { Title = "Second Step" };
  58. wizard.AddStep (secondStep);
  59. secondStep.HelpText = "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.";
  60. var buttonLbl = new Label () { Text = "Second Step Button: ", X = 0, Y = 0 };
  61. var button = new Button () {
  62. Text = "Press Me to Rename Step",
  63. X = Pos.Right (buttonLbl),
  64. Y = Pos.Top (buttonLbl)
  65. };
  66. button.Clicked += (s, e) => {
  67. secondStep.Title = "2nd Step";
  68. MessageBox.Query ("Wizard Scenario", "This Wizard Step's title was changed to '2nd Step'", "Ok");
  69. };
  70. secondStep.Add (buttonLbl, button);
  71. var lbl = new Label () { Text = "First Name: ", X = Pos.Left (buttonLbl), Y = Pos.Bottom (buttonLbl) };
  72. var firstNameField = new TextField () { Text = "Number", Width = 30, X = Pos.Right (lbl), Y = Pos.Top (lbl) };
  73. secondStep.Add (lbl, firstNameField);
  74. lbl = new Label () { Text = "Last Name: ", X = Pos.Left (buttonLbl), Y = Pos.Bottom (lbl) };
  75. var lastNameField = new TextField () { Text = "Six", Width = 30, X = Pos.Right (lbl), Y = Pos.Top (lbl) };
  76. secondStep.Add (lbl, lastNameField);
  77. // Add last step
  78. var lastStep = new WizardStep () { Title = "The last step" };
  79. wizard.AddStep (lastStep);
  80. lastStep.HelpText = "The wizard is complete!\n\nPress the Finish button to continue.\n\nPressing Esc will cancel.";
  81. Application.Top.Add (wizard);
  82. Application.Run (Application.Top);
  83. }
  84. public override void Run ()
  85. {
  86. // Do nothing in the override because we call Application.Run above
  87. // (just to make it clear how the Top is being run and not the Wizard).
  88. }
  89. }
  90. }