Browse Source

more unit tests and refactoring

Charlie Kindel 3 years ago
parent
commit
ab503d1de1
3 changed files with 16 additions and 28 deletions
  1. 1 1
      Terminal.Gui/Core/View.cs
  2. 2 4
      Terminal.Gui/Windows/Wizard.cs
  3. 13 23
      UICatalog/Scenarios/Wizards.cs

+ 1 - 1
Terminal.Gui/Core/View.cs

@@ -2399,7 +2399,7 @@ namespace Terminal.Gui {
 			}
 		}
 
-		bool oldEnabled = true;
+		bool oldEnabled;
 
 		/// <inheritdoc/>
 		public override bool Enabled {

+ 2 - 4
Terminal.Gui/Windows/Wizard.cs

@@ -276,9 +276,7 @@ namespace Terminal.Gui {
 			foreach (var step in steps) {
 				step.Y = 0;
 			}
-			if (steps.Count > 0) {
-				CurrentStep = steps.First.Value;
-			}
+			CurrentStep = GetNextStep (); // gets the first step if CurrentStep == null
 		}
 
 		private void NextfinishBtn_Clicked ()
@@ -440,7 +438,7 @@ namespace Terminal.Gui {
 			}
 			set {
 				wizardTitle = value;
-				base.Title = $"{wizardTitle}{(steps.Count > 0 ? " - " + currentStep.Title : string.Empty)}";
+				base.Title = $"{wizardTitle}{(steps.Count > 0 && currentStep != null ? " - " + currentStep.Title : string.Empty)}";
 			}
 		}
 		private ustring wizardTitle = ustring.Empty;

+ 13 - 23
UICatalog/Scenarios/Wizards.cs

@@ -150,8 +150,7 @@ namespace UICatalog.Scenarios {
 					// Add 2nd step
 					var secondStep = new Wizard.WizardStep ("Second Step");
 					wizard.AddStep (secondStep);
-					secondStep.HelpText = "This is the help text for the Second Step.\n\nPress the button to see a message box.\n\nEnter name too.";
-
+					secondStep.HelpText = "This is the help text for the Second Step.\n\nPress the button to see a message box.\n\nEnter First Name too.";
 
 					View viewForControls = secondStep.Controls;
 					ustring frameMsg = "Added to WizardStep.Controls";
@@ -191,15 +190,15 @@ namespace UICatalog.Scenarios {
 					};
 					frame.Add (new TextField ("This is a TextField inside of the frame."));
 					viewForControls.Add (frame);
+					wizard.StepChanging += (args) => {
+						if (args.OldStep == secondStep && firstNameField.Text.IsEmpty ) {
+							args.Cancel = true;
+							var btn = MessageBox.ErrorQuery ("Second Step", "You must enter a First Name to continue", "Ok");
+						}
+					};
 
 					// Add 3rd (optional) step
 					var thirdStep = new Wizard.WizardStep ("Third Step (Optional)");
-
-					thirdStep.Enabled = thirdStepEnabledCeckBox.Checked;
-					thirdStepEnabledCeckBox.Toggled += (args) => {
-						thirdStep.Enabled = thirdStepEnabledCeckBox.Checked;
-					};
-
 					wizard.AddStep (thirdStep);
 					thirdStep.HelpText = "This is step is optional (WizardStep.Enabled = false). Enable it with the checkbox in Step 2.";
 					var step3Label = new Label () {
@@ -217,7 +216,11 @@ namespace UICatalog.Scenarios {
 						Fraction = 0.42F
 					};
 					thirdStep.Controls.Add (progLbl, progressBar);
-
+					thirdStep.Enabled = thirdStepEnabledCeckBox.Checked;
+					thirdStepEnabledCeckBox.Toggled += (args) => {
+						thirdStep.Enabled = thirdStepEnabledCeckBox.Checked;
+					};
+	
 					// Add 4th step
 					var fourthStep = new Wizard.WizardStep ("Step Four");
 					wizard.AddStep (fourthStep);
@@ -232,22 +235,9 @@ namespace UICatalog.Scenarios {
 						AllowsTab = false
 					};
 					fourthStep.Controls.Add (someText);
-					//fourthStep.NextButtonText = "4";
+					fourthStep.NextButtonText = "Go To Last Step";
 					var scrollBar = new ScrollBarView (someText, true);
 
-					//wizard.StepChanging += (args) => {
-					//	if (args.NewStep == fourthStep) {
-					//		var btn = MessageBox.ErrorQuery ("Wizards", "Move to Step Four?", "Yes", "No");
-					//		args.Cancel = btn == 1;
-					//	}
-					//};
-
-					//wizard.StepChanged += (args) => {
-					//	if (args.NewStep == fourthStep) {
-					//		var btn = MessageBox.ErrorQuery ("Wizards", "Yay. Moved to Step Four", "Ok");
-					//	}
-					//};
-
 					scrollBar.ChangedPosition += () => {
 						someText.TopRow = scrollBar.Position;
 						if (someText.TopRow != scrollBar.Position) {