namespace Terminal.Gui; /// /// Represents a basic step that is displayed in a . The view is divided horizontally in two. On the left is the /// content view where s can be added, On the right is the help for the step. /// Set to set the help text. If the help text is empty the help pane will not /// be shown. /// /// If there are no Views added to the WizardStep the (if not empty) will fill the wizard step. /// /// /// If s are added, do not set to true as this will conflict /// with the Next button of the Wizard. /// /// Subscribe to the event to be notified when the step is active; see also: . /// /// To enable or disable a step from being shown to the user, set . /// /// public class WizardStep : FrameView { ///// ///// The title of the . ///// ///// The Title is only displayed when the is used as a modal pop-up (see . //public new string Title { // // BUGBUG: v2 - No need for this as View now has Title w/ notifications. // get => title; // set { // if (!OnTitleChanging (title, value)) { // var old = title; // title = value; // OnTitleChanged (old, title); // } // base.Title = value; // SetNeedsDisplay (); // } //} //private string title = string.Empty; // The contentView works like the ContentView in FrameView. private View contentView = new View () { Data = "WizardContentView" }; /// /// Sets or gets help text for the .If is empty /// the help pane will not be visible and the content will fill the entire WizardStep. /// /// The help text is displayed using a read-only . public string HelpText { get => helpTextView.Text; set { helpTextView.Text = value; ShowHide (); SetNeedsDisplay (); } } private TextView helpTextView = new TextView (); /// /// Sets or gets the text for the back button. The back button will only be visible on /// steps after the first step. /// /// The default text is "Back" public string BackButtonText { get; set; } = string.Empty; /// /// Sets or gets the text for the next/finish button. /// /// The default text is "Next..." if the Pane is not the last pane. Otherwise it is "Finish" public string NextButtonText { get; set; } = string.Empty; /// /// Initializes a new instance of the class using positioning. /// public WizardStep () { BorderStyle = LineStyle.None; base.Add (contentView); helpTextView.ReadOnly = true; helpTextView.WordWrap = true; base.Add (helpTextView); // BUGBUG: v2 - Disabling scrolling for now //var scrollBar = new ScrollBarView (helpTextView, true); //scrollBar.ChangedPosition += (s,e) => { // helpTextView.TopRow = scrollBar.Position; // if (helpTextView.TopRow != scrollBar.Position) { // scrollBar.Position = helpTextView.TopRow; // } // helpTextView.SetNeedsDisplay (); //}; //scrollBar.OtherScrollBarView.ChangedPosition += (s,e) => { // helpTextView.LeftColumn = scrollBar.OtherScrollBarView.Position; // if (helpTextView.LeftColumn != scrollBar.OtherScrollBarView.Position) { // scrollBar.OtherScrollBarView.Position = helpTextView.LeftColumn; // } // helpTextView.SetNeedsDisplay (); //}; //scrollBar.VisibleChanged += (s,e) => { // if (scrollBar.Visible && helpTextView.RightOffset == 0) { // helpTextView.RightOffset = 1; // } else if (!scrollBar.Visible && helpTextView.RightOffset == 1) { // helpTextView.RightOffset = 0; // } //}; //scrollBar.OtherScrollBarView.VisibleChanged += (s,e) => { // if (scrollBar.OtherScrollBarView.Visible && helpTextView.BottomOffset == 0) { // helpTextView.BottomOffset = 1; // } else if (!scrollBar.OtherScrollBarView.Visible && helpTextView.BottomOffset == 1) { // helpTextView.BottomOffset = 0; // } //}; //helpTextView.DrawContent += (s,e) => { // scrollBar.Size = helpTextView.Lines; // scrollBar.Position = helpTextView.TopRow; // if (scrollBar.OtherScrollBarView != null) { // scrollBar.OtherScrollBarView.Size = helpTextView.Maxlength; // scrollBar.OtherScrollBarView.Position = helpTextView.LeftColumn; // } // scrollBar.LayoutSubviews (); // scrollBar.Refresh (); //}; //base.Add (scrollBar); ShowHide (); } /// /// Does the work to show and hide the contentView and helpView as appropriate /// internal void ShowHide () { contentView.Height = Dim.Fill (); helpTextView.Height = Dim.Fill (); helpTextView.Width = Dim.Fill (); if (contentView.InternalSubviews?.Count > 0) { if (helpTextView.Text.Length > 0) { contentView.Width = Dim.Percent (70); helpTextView.X = Pos.Right (contentView); helpTextView.Width = Dim.Fill (); } else { contentView.Width = Dim.Fill (); } } else { if (helpTextView.Text.Length > 0) { helpTextView.X = 0; } else { // Error - no pane shown } } contentView.Visible = contentView.InternalSubviews?.Count > 0; helpTextView.Visible = helpTextView.Text.Length > 0; } /// /// Add the specified to the . /// /// to add to this container public override void Add (View view) { contentView.Add (view); if (view.CanFocus) { CanFocus = true; } ShowHide (); } /// /// Removes a from . /// /// /// public override void Remove (View view) { if (view == null) { return; } SetNeedsDisplay (); var touched = view.Frame; contentView.Remove (view); if (contentView.InternalSubviews.Count < 1) { this.CanFocus = false; } ShowHide (); } /// /// Removes all s from the . /// /// /// public override void RemoveAll () { contentView.RemoveAll (); ShowHide (); } } // end of WizardStep class