Wizard.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. using System;
  2. using System.Collections.Generic;
  3. using NStack;
  4. using Terminal.Gui.Resources;
  5. namespace Terminal.Gui {
  6. /// <summary>
  7. /// Provides a step-based "wizard" UI. The Wizard supports multiple steps. Each step (<see cref="WizardStep"/>) can host
  8. /// arbitrary <see cref="View"/>s, much like a <see cref="Dialog"/>. Each step also has a pane for help text. Along the
  9. /// bottom of the Wizard view are customizable buttons enabling the user to navigate forward and backward through the Wizard.
  10. /// </summary>
  11. /// <remarks>
  12. /// </remarks>
  13. public class Wizard : Dialog {
  14. /// <summary>
  15. /// One step for the Wizard. The <see cref="WizardStep"/> view hosts two sub-views: 1) add <see cref="View"/>s to <see cref="WizardStep.Controls"/>,
  16. /// 2) use <see cref="WizardStep.HelpText"/> to set the contents of the <see cref="TextView"/> that shows on the
  17. /// right side. Use <see cref="WizardStep.showControls"/> and <see cref="WizardStep.showHelp"/> to
  18. /// control wether the control or help pane are shown.
  19. /// </summary>
  20. /// <remarks>
  21. /// If <see cref="Button"/>s are added, do not set <see cref="Button.IsDefault"/> to true as this will conflict
  22. /// with the Next button of the Wizard.
  23. ///
  24. /// Subscribe to the <see cref="View.VisibleChanged"/> event to be notified when the step is active; see also: <see cref="Wizard.StepChanged"/>.
  25. ///
  26. /// To enable or disable a step from being shown to the user, set <see cref="View.Enabled"/>.
  27. ///
  28. /// </remarks>
  29. public class WizardStep : View {
  30. /// <summary>
  31. /// The title of the <see cref="WizardStep"/>.
  32. /// </summary>
  33. public ustring Title { get => title; set => title = value; }
  34. // TODO: Update Wizard title when step title is changed if step is current - this will require step to slueth it's parent
  35. private ustring title;
  36. // The controlPane is a separate view, so when devs add controls to the Step and help is visible, Y = Pos.AnchorEnd()
  37. // will work as expected.
  38. private View controlPane = new FrameView ();
  39. /// <summary>
  40. /// THe pane that holds the controls for the <see cref="WizardStep"/>. Use <see cref="WizardStep.Controls"/> `Add(View`) to add
  41. /// controls. Note that the Controls view is sized to take 70% of the Wizard's width and the <see cref="WizardStep.HelpText"/>
  42. /// takes the other 30%. This can be adjusted by setting `Width` from `Dim.Percent(70)` to
  43. /// another value. If <see cref="WizardStep.ShowHelp"/> is set to `false` the control pane will fill the entire
  44. /// Wizard.
  45. /// </summary>
  46. public View Controls { get => controlPane; }
  47. /// <summary>
  48. /// Sets or gets help text for the <see cref="WizardStep"/>.If <see cref="WizardStep.ShowHelp"/> is set to
  49. /// `false` the control pane will fill the entire wizard.
  50. /// </summary>
  51. /// <remarks>The help text is displayed using a read-only <see cref="TextView"/>.</remarks>
  52. public ustring HelpText { get => helpTextView.Text; set => helpTextView.Text = value; }
  53. private TextView helpTextView = new TextView ();
  54. /// <summary>
  55. /// Sets or gets the text for the back button. The back button will only be visible on
  56. /// steps after the first step.
  57. /// </summary>
  58. /// <remarks>The default text is "Back"</remarks>
  59. public ustring BackButtonText { get; set; } = ustring.Empty;
  60. // TODO: Update button text of Wizard button when step's button text is changed if step is current - this will require step to slueth it's parent
  61. /// <summary>
  62. /// Sets or gets the text for the next/finish button.
  63. /// </summary>
  64. /// <remarks>The default text is "Next..." if the Pane is not the last pane. Otherwise it is "Finish"</remarks>
  65. public ustring NextButtonText { get; set; } = ustring.Empty;
  66. // TODO: Update button text of Wizard button when step's button text is changed if step is current - this will require step to slueth it's parent
  67. /// <summary>
  68. /// Initializes a new instance of the <see cref="Wizard"/> class using <see cref="LayoutStyle.Computed"/> positioning.
  69. /// </summary>
  70. /// <param name="title">Title for the Step. Will be appended to the containing Wizard's title as
  71. /// "Wizard Title - Wizard Step Title" when this step is active.</param>
  72. /// <remarks>
  73. /// </remarks>
  74. public WizardStep (ustring title)
  75. {
  76. this.Title = title; // this.Title holds just the "Wizard Title"; base.Title holds "Wizard Title - Step Title"
  77. this.ColorScheme = Colors.Dialog;
  78. Y = 0;
  79. Height = Dim.Fill (1); // for button frame
  80. Width = Dim.Fill ();
  81. Controls.ColorScheme = Colors.Dialog;
  82. Controls.Border.BorderStyle = BorderStyle.None;
  83. Controls.Border.Padding = new Thickness (0);
  84. Controls.Border.BorderThickness = new Thickness (0);
  85. this.Add (Controls);
  86. helpTextView.ColorScheme = Colors.Menu;
  87. helpTextView.Y = 0;
  88. helpTextView.ReadOnly = true;
  89. helpTextView.WordWrap = true;
  90. this.Add (helpTextView);
  91. ShowHide ();
  92. var scrollBar = new ScrollBarView (helpTextView, true);
  93. scrollBar.ChangedPosition += () => {
  94. helpTextView.TopRow = scrollBar.Position;
  95. if (helpTextView.TopRow != scrollBar.Position) {
  96. scrollBar.Position = helpTextView.TopRow;
  97. }
  98. helpTextView.SetNeedsDisplay ();
  99. };
  100. scrollBar.OtherScrollBarView.ChangedPosition += () => {
  101. helpTextView.LeftColumn = scrollBar.OtherScrollBarView.Position;
  102. if (helpTextView.LeftColumn != scrollBar.OtherScrollBarView.Position) {
  103. scrollBar.OtherScrollBarView.Position = helpTextView.LeftColumn;
  104. }
  105. helpTextView.SetNeedsDisplay ();
  106. };
  107. scrollBar.VisibleChanged += () => {
  108. if (scrollBar.Visible && helpTextView.RightOffset == 0) {
  109. helpTextView.RightOffset = 1;
  110. } else if (!scrollBar.Visible && helpTextView.RightOffset == 1) {
  111. helpTextView.RightOffset = 0;
  112. }
  113. };
  114. scrollBar.OtherScrollBarView.VisibleChanged += () => {
  115. if (scrollBar.OtherScrollBarView.Visible && helpTextView.BottomOffset == 0) {
  116. helpTextView.BottomOffset = 1;
  117. } else if (!scrollBar.OtherScrollBarView.Visible && helpTextView.BottomOffset == 1) {
  118. helpTextView.BottomOffset = 0;
  119. }
  120. };
  121. helpTextView.DrawContent += (e) => {
  122. scrollBar.Size = helpTextView.Lines;
  123. scrollBar.Position = helpTextView.TopRow;
  124. if (scrollBar.OtherScrollBarView != null) {
  125. scrollBar.OtherScrollBarView.Size = helpTextView.Maxlength;
  126. scrollBar.OtherScrollBarView.Position = helpTextView.LeftColumn;
  127. }
  128. scrollBar.LayoutSubviews ();
  129. scrollBar.Refresh ();
  130. };
  131. this.Add (scrollBar);
  132. }
  133. //public override void OnEnabledChanged()
  134. //{
  135. // if (Enabled) { }
  136. // base.OnEnabledChanged ();
  137. //}
  138. /// <summary>
  139. /// If true (the default) the help will be visible. If false, the help will not be shown and the control pane will
  140. /// fill the wizard step.
  141. /// </summary>
  142. public bool ShowHelp {
  143. get => showHelp;
  144. set {
  145. showHelp = value;
  146. ShowHide ();
  147. }
  148. }
  149. private bool showHelp = true;
  150. /// <summary>
  151. /// If true (the default) the <see cref="Controls"/> View will be visible. If false, the controls will not be shown and the help will
  152. /// fill the wizard step.
  153. /// </summary>
  154. public bool ShowControls {
  155. get => showControls;
  156. set {
  157. showControls = value;
  158. ShowHide ();
  159. }
  160. }
  161. private bool showControls = true;
  162. /// <summary>
  163. /// Does the work to show and hide the controls, help, and buttons as appropriate
  164. /// </summary>
  165. private void ShowHide ()
  166. {
  167. Controls.Height = Dim.Fill (1);
  168. helpTextView.Height = Dim.Fill (1);
  169. helpTextView.Width = Dim.Fill ();
  170. if (showControls) {
  171. if (showHelp) {
  172. Controls.Width = Dim.Percent (70);
  173. helpTextView.X = Pos.Right (Controls);
  174. helpTextView.Width = Dim.Fill ();
  175. } else {
  176. Controls.Width = Dim.Percent (100);
  177. }
  178. } else {
  179. if (showHelp) {
  180. helpTextView.X = 0;
  181. } else {
  182. // Error - no pane shown
  183. }
  184. }
  185. Controls.Visible = showControls;
  186. helpTextView.Visible = showHelp;
  187. }
  188. } // WizardStep
  189. /// <summary>
  190. /// Initializes a new instance of the <see cref="Wizard"/> class using <see cref="LayoutStyle.Computed"/> positioning.
  191. /// </summary>
  192. /// <remarks>
  193. /// The Wizard will be vertically and horizontally centered in the container.
  194. /// After initialization use <c>X</c>, <c>Y</c>, <c>Width</c>, and <c>Height</c> change size and position.
  195. /// </remarks>
  196. public Wizard () : this (ustring.Empty)
  197. {
  198. }
  199. /// <summary>
  200. /// Initializes a new instance of the <see cref="Wizard"/> class using <see cref="LayoutStyle.Computed"/> positioning.
  201. /// </summary>
  202. /// <param name="title">Title for the Wizard.</param>
  203. /// <remarks>
  204. /// The Wizard will be vertically and horizontally centered in the container.
  205. /// After initialization use <c>X</c>, <c>Y</c>, <c>Width</c>, and <c>Height</c> change size and position.
  206. /// </remarks>
  207. public Wizard (ustring title) : base (title)
  208. {
  209. wizardTitle = title;
  210. // Using Justify causes the Back and Next buttons to be hard justified against
  211. // the left and right edge
  212. ButtonAlignment = ButtonAlignments.Justify;
  213. this.Border.BorderStyle = BorderStyle.Double;
  214. // Add a horiz separator
  215. var separator = new LineView (Graphs.Orientation.Horizontal) {
  216. Y = Pos.AnchorEnd (2)
  217. };
  218. Add (separator);
  219. // BUGBUG: Space is to work around https://github.com/migueldeicaza/gui.cs/issues/1812
  220. backBtn = new Button (Strings.wzBack) { AutoSize = true };
  221. AddButton (backBtn);
  222. nextfinishBtn = new Button (Strings.wzFinish) { AutoSize = true };
  223. nextfinishBtn.IsDefault = true;
  224. AddButton (nextfinishBtn);
  225. backBtn.Clicked += BackBtn_Clicked;
  226. nextfinishBtn.Clicked += NextfinishBtn_Clicked;
  227. Loaded += Wizard_Loaded;
  228. Closing += Wizard_Closing;
  229. }
  230. private bool finishedPressed = false;
  231. private void Wizard_Closing (ToplevelClosingEventArgs obj)
  232. {
  233. if (!finishedPressed) {
  234. var args = new WizardButtonEventArgs ();
  235. Cancelled?.Invoke (args);
  236. }
  237. }
  238. private void Wizard_Loaded ()
  239. {
  240. foreach (var step in steps) {
  241. step.Y = 0;
  242. }
  243. if (steps.Count > 0) {
  244. CurrentStep = steps.First.Value;
  245. }
  246. }
  247. private void NextfinishBtn_Clicked ()
  248. {
  249. if (CurrentStep == steps.Last.Value) {
  250. var args = new WizardButtonEventArgs ();
  251. Finished?.Invoke (args);
  252. if (!args.Cancel) {
  253. finishedPressed = true;
  254. Application.RequestStop (this);
  255. }
  256. } else {
  257. var args = new WizardButtonEventArgs ();
  258. MovingNext?.Invoke (args);
  259. if (!args.Cancel) {
  260. GoNext ();
  261. }
  262. }
  263. }
  264. /// <summary>
  265. /// Causes the wizad to move to the next enabled step (or last step if <see cref="CurrentStep"/> is not set).
  266. /// If there is no previous step, does nothing.
  267. /// </summary>
  268. public void GoNext ()
  269. {
  270. var nextStep = GetNextStep ();
  271. if (nextStep != null) {
  272. GoToStep (nextStep);
  273. }
  274. }
  275. /// <summary>
  276. /// Returns the next enabled <see cref="WizardStep"/> after the current step. Takes into account steps which
  277. /// are disabled. If <see cref="CurrentStep"/> is `null` returns the first enabled step.
  278. /// </summary>
  279. /// <returns>The next step after the current step, if there is one; otherwise returns `null`, which
  280. /// indicates either there are no enabled steps or the current step is the last enabled step.</returns>
  281. public WizardStep GetNextStep ()
  282. {
  283. LinkedListNode<WizardStep> step = null;
  284. if (CurrentStep == null) {
  285. // Get last step, assume it is next
  286. step = steps.First;
  287. } else {
  288. // Get the step after current
  289. step = steps.Find (CurrentStep);
  290. if (step != null) {
  291. step = step.Next;
  292. }
  293. }
  294. // step now points to the potential next step
  295. while (step != null) {
  296. if (step.Value.Enabled) {
  297. return step.Value;
  298. }
  299. step = step.Next;
  300. }
  301. return null;
  302. }
  303. private void BackBtn_Clicked ()
  304. {
  305. var args = new WizardButtonEventArgs ();
  306. MovingBack?.Invoke (args);
  307. if (!args.Cancel) {
  308. GoBack ();
  309. }
  310. }
  311. /// <summary>
  312. /// Causes the wizad to move to the previous enabled step (or first step if <see cref="CurrentStep"/> is not set).
  313. /// If there is no previous step, does nothing.
  314. /// </summary>
  315. public void GoBack ()
  316. {
  317. var previous = GetPreviousStep ();
  318. if (previous != null) {
  319. GoToStep (previous);
  320. }
  321. }
  322. /// <summary>
  323. /// Returns the first enabled <see cref="WizardStep"/> before the current step. Takes into account steps which
  324. /// are disabled. If <see cref="CurrentStep"/> is `null` returns the last enabled step.
  325. /// </summary>
  326. /// <returns>The first step ahead of the current step, if there is one; otherwise returns `null`, which
  327. /// indicates either there are no enabled steps or the current step is the first enabled step.</returns>
  328. public WizardStep GetPreviousStep ()
  329. {
  330. LinkedListNode<WizardStep> step = null;
  331. if (CurrentStep == null) {
  332. // Get last step, assume it is previous
  333. step = steps.Last;
  334. } else {
  335. // Get the step before current
  336. step = steps.Find (CurrentStep);
  337. if (step != null) {
  338. step = step.Previous;
  339. }
  340. }
  341. // step now points to the potential previous step
  342. while (step != null) {
  343. if (step.Value.Enabled) {
  344. return step.Value;
  345. }
  346. step = step.Previous;
  347. }
  348. return null;
  349. }
  350. private LinkedList<WizardStep> steps = new LinkedList<WizardStep> ();
  351. private WizardStep currentStep = null;
  352. /// <summary>
  353. /// If the <see cref="CurrentStep"/> is not the first step in the wizard, this button causes
  354. /// the <see cref="MovingBack"/> event to be fired and the wizard moves to the previous step.
  355. /// </summary>
  356. /// <remarks>
  357. /// Use the <see cref="MovingBack"></see> event to be notified when the user attempts to go back.
  358. /// </remarks>
  359. public Button BackButton { get => backBtn; }
  360. private Button backBtn;
  361. /// <summary>
  362. /// If the <see cref="CurrentStep"/> is the last step in the wizard, this button causes
  363. /// the <see cref="Finished"/> event to be fired and the wizard to close. If the step is not the last step,
  364. /// the <see cref="MovingNext"/> event will be fired and the wizard will move next step.
  365. /// </summary>
  366. /// <remarks>
  367. /// Use the <see cref="MovingNext"></see> and <see cref="Finished"></see> events to be notified
  368. /// when the user attempts go to the next step or finish the wizard.
  369. /// </remarks>
  370. public Button NextFinishButton { get => nextfinishBtn; }
  371. private Button nextfinishBtn;
  372. /// <summary>
  373. /// Adds a step to the wizard. The Next and Back buttons navigate through the added steps in the
  374. /// order they were added.
  375. /// </summary>
  376. /// <param name="newStep"></param>
  377. /// <remarks>The "Next..." button of the last step added will read "Finish" (unless changed from default).</remarks>
  378. public void AddStep (WizardStep newStep)
  379. {
  380. steps.AddLast (newStep);
  381. this.Add (newStep);
  382. SetNeedsLayout ();
  383. }
  384. /// <summary>
  385. /// The title of the Wizard, shown at the top of the Wizard with " - currentStep.Title" appended.
  386. /// </summary>
  387. public new ustring Title {
  388. get {
  389. // The base (Dialog) Title holds the full title ("Wizard Title - Step Title")
  390. return base.Title;
  391. }
  392. set {
  393. wizardTitle = value;
  394. base.Title = $"{wizardTitle}{(steps.Count > 0 ? " - " + currentStep.Title : string.Empty)}";
  395. }
  396. }
  397. private ustring wizardTitle = ustring.Empty;
  398. /// <summary>
  399. /// <see cref="EventArgs"/> for <see cref="WizardStep"/> transition events.
  400. /// </summary>
  401. public class WizardButtonEventArgs : EventArgs {
  402. /// <summary>
  403. /// Set to true to cancel the transition to the next step.
  404. /// </summary>
  405. public bool Cancel { get; set; }
  406. /// <summary>
  407. /// Initializes a new instance of <see cref="WizardButtonEventArgs"/>
  408. /// </summary>
  409. public WizardButtonEventArgs ()
  410. {
  411. Cancel = false;
  412. }
  413. }
  414. /// <summary>
  415. /// This event is raised when the Back button in the <see cref="Wizard"/> is clicked. The Back button is always
  416. /// the first button in the array of Buttons passed to the <see cref="Wizard"/> constructor, if any.
  417. /// </summary>
  418. public event Action<WizardButtonEventArgs> MovingBack;
  419. /// <summary>
  420. /// This event is raised when the Next/Finish button in the <see cref="Wizard"/> is clicked. The Next/Finish button is always
  421. /// the last button in the array of Buttons passed to the <see cref="Wizard"/> constructor, if any. This event is only
  422. /// raised if the <see cref="CurrentStep"/> is the last Step in the Wizard flow
  423. /// (otherwise the <see cref="Finished"/> event is raised).
  424. /// </summary>
  425. public event Action<WizardButtonEventArgs> MovingNext;
  426. /// <summary>
  427. /// This event is raised when the Next/Finish button in the <see cref="Wizard"/> is clicked. The Next/Finish button is always
  428. /// the last button in the array of Buttons passed to the <see cref="Wizard"/> constructor, if any. This event is only
  429. /// raised if the <see cref="CurrentStep"/> is the last Step in the Wizard flow
  430. /// (otherwise the <see cref="Finished"/> event is raised).
  431. /// </summary>
  432. public event Action<WizardButtonEventArgs> Finished;
  433. /// <summary>
  434. /// This event is raised when the user has cancelled the <see cref="Wizard"/> (with Ctrl-Q or ESC).
  435. /// </summary>
  436. public event Action<WizardButtonEventArgs> Cancelled;
  437. /// <summary>
  438. /// <see cref="EventArgs"/> for <see cref="WizardStep"/> events.
  439. /// </summary>
  440. public class StepChangeEventArgs : EventArgs {
  441. /// <summary>
  442. /// The current (or previous) <see cref="WizardStep"/>.
  443. /// </summary>
  444. public WizardStep OldStep { get; }
  445. /// <summary>
  446. /// The <see cref="WizardStep"/> the <see cref="Wizard"/> is changing to or has changed to.
  447. /// </summary>
  448. public WizardStep NewStep { get; }
  449. /// <summary>
  450. /// Event handlers can set to true before returning to cancel the step transition.
  451. /// </summary>
  452. public bool Cancel { get; set; }
  453. /// <summary>
  454. /// Initializes a new instance of <see cref="StepChangeEventArgs"/>
  455. /// </summary>
  456. /// <param name="oldStep">The current <see cref="WizardStep"/>.</param>
  457. /// <param name="newStep">The new <see cref="WizardStep"/>.</param>
  458. public StepChangeEventArgs (WizardStep oldStep, WizardStep newStep)
  459. {
  460. OldStep = oldStep;
  461. NewStep = newStep;
  462. Cancel = false;
  463. }
  464. }
  465. /// <summary>
  466. /// This event is raised when the current <see cref="CurrentStep"/>) is about to change. Use <see cref="StepChangeEventArgs.Cancel"/>
  467. /// to abort the transition.
  468. /// </summary>
  469. public event Action<StepChangeEventArgs> StepChanging;
  470. /// <summary>
  471. /// This event is raised after the <see cref="Wizard"/> has changed the <see cref="CurrentStep"/>.
  472. /// </summary>
  473. public event Action<StepChangeEventArgs> StepChanged;
  474. /// <summary>
  475. /// Gets or sets the currently active <see cref="WizardStep"/>.
  476. /// </summary>
  477. public WizardStep CurrentStep {
  478. get => currentStep;
  479. set {
  480. GoToStep (value);
  481. }
  482. }
  483. /// <summary>
  484. /// Called when the <see cref="Wizard"/> is about to transition to another <see cref="WizardStep"/>. Fires the <see cref="StepChanging"/> event.
  485. /// </summary>
  486. /// <param name="oldStep">The step the Wizard is about to change from</param>
  487. /// <param name="newStep">The step the Wizard is about to change to</param>
  488. /// <returns>True if the change is to be cancelled.</returns>
  489. public virtual bool OnStepChanging (WizardStep oldStep, WizardStep newStep)
  490. {
  491. var args = new StepChangeEventArgs (oldStep, newStep);
  492. StepChanging?.Invoke (args);
  493. return args.Cancel;
  494. }
  495. /// <summary>
  496. /// Called when the <see cref="Wizard"/> has completed transition to a new <see cref="WizardStep"/>. Fires the <see cref="StepChanged"/> event.
  497. /// </summary>
  498. /// <param name="oldStep">The step the Wizard changed from</param>
  499. /// <param name="newStep">The step the Wizard has changed to</param>
  500. /// <returns>True if the change is to be cancelled.</returns>
  501. public virtual bool OnStepChanged (WizardStep oldStep, WizardStep newStep)
  502. {
  503. var args = new StepChangeEventArgs (oldStep, newStep);
  504. StepChanged?.Invoke (args);
  505. return args.Cancel;
  506. }
  507. /// <summary>
  508. /// Changes to the specified <see cref="WizardStep"/>.
  509. /// </summary>
  510. /// <param name="newStep">The step to go to.</param>
  511. /// <returns>True if the transition to the step succeeded. False if the step was not found or the operation was cancelled.</returns>
  512. public bool GoToStep (WizardStep newStep)
  513. {
  514. if (OnStepChanging (currentStep, newStep) || (newStep != null && !newStep.Enabled)) {
  515. return false;
  516. }
  517. // Hide all but the new step
  518. foreach (WizardStep step in steps) {
  519. step.Visible = (step == newStep);
  520. }
  521. if (newStep != null) {
  522. base.Title = $"{wizardTitle}{(steps.Count > 0 ? " - " + newStep.Title : string.Empty)}";
  523. // Configure the Back button
  524. backBtn.Text = newStep.BackButtonText != ustring.Empty ? newStep.BackButtonText : Strings.wzBack; // "_Back";
  525. backBtn.Visible = (newStep != steps.First.Value);
  526. // Configure the Next/Finished button
  527. if (newStep == steps.Last.Value) {
  528. nextfinishBtn.Text = newStep.NextButtonText != ustring.Empty ? newStep.NextButtonText : Strings.wzFinish; // "Fi_nish";
  529. } else {
  530. nextfinishBtn.Text = newStep.NextButtonText != ustring.Empty ? newStep.NextButtonText : Strings.wzNext; // "_Next...";
  531. }
  532. }
  533. // Set focus to the nav buttons
  534. if (backBtn.HasFocus) {
  535. backBtn.SetFocus ();
  536. } else {
  537. nextfinishBtn.SetFocus ();
  538. }
  539. var oldStep = currentStep;
  540. currentStep = newStep;
  541. LayoutSubviews ();
  542. Redraw (this.Bounds);
  543. if (OnStepChanged (oldStep, currentStep)) {
  544. // For correctness we do this, but it's meaningless because there's nothing to cancel
  545. return false;
  546. }
  547. return true;
  548. }
  549. }
  550. }