WizardAsView.cs 4.1 KB

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