diff --git a/Terminal.Gui/Core/Toplevel.cs b/Terminal.Gui/Core/Toplevel.cs index 9c85c2681..46b2a99d9 100644 --- a/Terminal.Gui/Core/Toplevel.cs +++ b/Terminal.Gui/Core/Toplevel.cs @@ -179,6 +179,10 @@ namespace Terminal.Gui { IEnumerable GetToplevelSubviews (bool isForward) { + if (SuperView == null) { + return null; + } + HashSet views = new HashSet (); foreach (var v in SuperView.Subviews) { @@ -190,6 +194,10 @@ namespace Terminal.Gui { void FocusNearestView (IEnumerable views) { + if (views == null) { + return; + } + bool found = false; foreach (var v in views) { @@ -205,7 +213,7 @@ namespace Terminal.Gui { } } - /// + /// public override void Add (View view) { if (this == Application.Top) { diff --git a/Terminal.Gui/Core/Window.cs b/Terminal.Gui/Core/Window.cs index daea97f93..1cd4be592 100644 --- a/Terminal.Gui/Core/Window.cs +++ b/Terminal.Gui/Core/Window.cs @@ -69,7 +69,7 @@ namespace Terminal.Gui { } /// - /// Initializes a new instance of the class with an optional title. + /// Initializes a new instance of the class with an optional title using positioning. /// /// Title. /// @@ -80,9 +80,14 @@ namespace Terminal.Gui { { } + /// + /// Initializes a new instance of the class using positioning. + /// + public Window () : this (title: null) { } + int padding; /// - /// Initializes a new instance of the with the specified frame for its location, with the specified border, + /// Initializes a new instance of the using positioning with the specified frame for its location, with the specified frame padding, /// and an optional title. /// /// Superview-relatie rectangle specifying the location and size @@ -103,7 +108,7 @@ namespace Terminal.Gui { } /// - /// Initializes a new instance of the with the specified frame for its location, with the specified border, + /// Initializes a new instance of the using positioning with the specified frame for its location, with the specified frame padding, /// and an optional title. /// /// Number of characters to use for padding of the drawn frame. diff --git a/Terminal.Gui/Views/Button.cs b/Terminal.Gui/Views/Button.cs index 0474e4363..4bd53a68a 100644 --- a/Terminal.Gui/Views/Button.cs +++ b/Terminal.Gui/Views/Button.cs @@ -54,6 +54,15 @@ namespace Terminal.Gui { /// public Action Clicked; + /// + /// Initializes a new instance of using layout. + /// + /// + /// The width of the is computed based on the + /// text length. The height will always be 1. + /// + public Button () : this (string.Empty) { } + /// /// Initializes a new instance of using layout. /// diff --git a/Terminal.Gui/Views/Checkbox.cs b/Terminal.Gui/Views/Checkbox.cs index 29813ebc5..8f68f9823 100644 --- a/Terminal.Gui/Views/Checkbox.cs +++ b/Terminal.Gui/Views/Checkbox.cs @@ -30,12 +30,18 @@ namespace Terminal.Gui { /// /// Called when the property changes. Invokes the event. /// - public virtual void OnToggled (bool previousChecked) { + public virtual void OnToggled (bool previousChecked) + { Toggled?.Invoke (this, previousChecked); } /// - /// Initializes a new instance of based on the given text, uses Computed layout and sets the height and width. + /// Initializes a new instance of based on the given text, using layout. + /// + public CheckBox () : this (string.Empty) { } + + /// + /// Initializes a new instance of based on the given text, using layout. /// /// S. /// If set to true is checked. @@ -49,7 +55,7 @@ namespace Terminal.Gui { } /// - /// Initializes a new instance of based on the given text at the given position and a state. + /// Initializes a new instance of using layout. /// /// /// The size of is computed based on the @@ -60,7 +66,7 @@ namespace Terminal.Gui { } /// - /// Initializes a new instance of based on the given text at the given position and a state. + /// Initializes a new instance of using layout. /// /// /// The size of is computed based on the diff --git a/Terminal.Gui/Views/DateField.cs b/Terminal.Gui/Views/DateField.cs index bb0268d4e..f857d521d 100644 --- a/Terminal.Gui/Views/DateField.cs +++ b/Terminal.Gui/Views/DateField.cs @@ -29,20 +29,25 @@ namespace Terminal.Gui { string Format { get { return isShort ? shortFormat : longFormat; } } /// - /// Initializes a new instance of at an absolute position and fixed size. + /// Initializes a new instance of using layout. /// /// The x coordinate. /// The y coordinate. /// Initial date contents. /// If true, shows only two digits for the year. - public DateField (int x, int y, DateTime date, bool isShort = false) : base(x, y, isShort ? 10 : 12, "") + public DateField (int x, int y, DateTime date, bool isShort = false) : base (x, y, isShort ? 10 : 12, "") { this.isShort = isShort; Initialize (date); } /// - /// Initializes a new instance of + /// Initializes a new instance of using layout. + /// + public DateField () : this (DateTime.MinValue) { } + + /// + /// Initializes a new instance of using layout. /// /// public DateField (DateTime date) : base ("") @@ -65,7 +70,7 @@ namespace Terminal.Gui { void DateField_Changed (object sender, ustring e) { - if (!DateTime.TryParseExact (GetDate (Text).ToString(), GetInvarianteFormat (), CultureInfo.CurrentCulture, DateTimeStyles.None, out DateTime result)) + if (!DateTime.TryParseExact (GetDate (Text).ToString (), GetInvarianteFormat (), CultureInfo.CurrentCulture, DateTimeStyles.None, out DateTime result)) Text = e; } @@ -259,8 +264,8 @@ namespace Terminal.Gui { CursorPosition++; } - /// - public override bool ProcessKey(KeyEvent kb) + /// + public override bool ProcessKey (KeyEvent kb) { switch (kb.Key) { case Key.DeleteChar: @@ -306,8 +311,8 @@ namespace Terminal.Gui { return true; } - /// - public override bool MouseEvent(MouseEvent ev) + /// + public override bool MouseEvent (MouseEvent ev) { if (!ev.Flags.HasFlag (MouseFlags.Button1Clicked)) return false; diff --git a/Terminal.Gui/Views/FrameView.cs b/Terminal.Gui/Views/FrameView.cs index dd5280349..5b7f49a4f 100644 --- a/Terminal.Gui/Views/FrameView.cs +++ b/Terminal.Gui/Views/FrameView.cs @@ -4,10 +4,10 @@ // Authors: // Miguel de Icaza (miguel@gnome.org) // - using System; - using System.Collections; - using System.Collections.Generic; - using NStack; +using System; +using System.Collections; +using System.Collections.Generic; +using NStack; namespace Terminal.Gui { /// @@ -36,27 +36,25 @@ namespace Terminal.Gui { } /// - /// Initializes a new instance of the class with - /// an absolute position and a title. + /// Initializes a new instance of the class using layout. /// /// Frame. /// Title. public FrameView (Rect frame, ustring title) : base (frame) { - var cFrame = new Rect (1, 1 , frame.Width - 2, frame.Height - 2); + var cFrame = new Rect (1, 1, frame.Width - 2, frame.Height - 2); this.title = title; contentView = new ContentView (cFrame); Initialize (); } /// - /// Initializes a new instance of the class with - /// an absolute position, a title and s. + /// Initializes a new instance of the class using layout. /// /// Frame. /// Title. /// /// Views. - public FrameView (Rect frame, ustring title, View[] views) : this (frame, title) + public FrameView (Rect frame, ustring title, View [] views) : this (frame, title) { foreach (var view in views) { contentView.Add (view); @@ -65,8 +63,7 @@ namespace Terminal.Gui { } /// - /// Initializes a new instance of the class with - /// a title and the result is suitable to have its X, Y, Width and Height properties computed. + /// Initializes a new instance of the class using layout. /// /// Title. public FrameView (ustring title) @@ -81,6 +78,11 @@ namespace Terminal.Gui { Initialize (); } + /// + /// Initializes a new instance of the class using layout. + /// + public FrameView () : this (title: string.Empty) { } + void Initialize () { base.Add (contentView); @@ -126,9 +128,9 @@ namespace Terminal.Gui { /// /// /// - public override void RemoveAll() + public override void RemoveAll () { - contentView.RemoveAll(); + contentView.RemoveAll (); } /// diff --git a/Terminal.Gui/Views/HexView.cs b/Terminal.Gui/Views/HexView.cs index 5397552f2..af9d55e66 100644 --- a/Terminal.Gui/Views/HexView.cs +++ b/Terminal.Gui/Views/HexView.cs @@ -41,10 +41,10 @@ namespace Terminal.Gui { bool firstNibble, leftSide; /// - /// Initialzies a + /// Initialzies a class using layout. /// /// The to view and edit as hex, this must support seeking, or an exception will be thrown. - public HexView (Stream source) : base() + public HexView (Stream source) : base () { Source = source; this.source = source; @@ -53,6 +53,11 @@ namespace Terminal.Gui { firstNibble = true; } + /// + /// Initialzies a class using layout. + /// + public HexView () : this (source: new MemoryStream ()) { } + /// /// Sets or gets the the is operating on; the stream must support seeking ( == true). /// @@ -151,7 +156,7 @@ namespace Terminal.Gui { var lineRect = new Rect (0, line, frame.Width, 1); if (!bounds.Contains (lineRect)) continue; - + Move (0, line); Driver.SetAttribute (ColorScheme.HotNormal); Driver.AddStr (string.Format ("{0:x8} ", displayStart + line * nblocks * 4)); @@ -197,7 +202,7 @@ namespace Terminal.Gui { SetAttribute (leftSide ? trackingColor : activeColor); else SetAttribute (ColorScheme.Normal); - + Driver.AddRune (c); } } @@ -229,7 +234,7 @@ namespace Terminal.Gui { void RedisplayLine (long pos) { - var delta = (int) (pos - DisplayStart); + var delta = (int)(pos - DisplayStart); var line = delta / bytesPerLine; SetNeedsDisplay (new Rect (0, line, Frame.Width, 1)); @@ -277,7 +282,7 @@ namespace Terminal.Gui { SetDisplayStart (DisplayStart + bytes); SetNeedsDisplay (); } else - RedisplayLine (position); + RedisplayLine (position); } /// @@ -376,7 +381,7 @@ namespace Terminal.Gui { /// Each Key indicates an offset where an edit was made and the Value is the changed byte. /// /// The edits. - public IReadOnlyDictionary Edits => edits; + public IReadOnlyDictionary Edits => edits; /// /// This method applies andy edits made to the and resets the diff --git a/Terminal.Gui/Views/Label.cs b/Terminal.Gui/Views/Label.cs index 334949e2b..f558b13e8 100644 --- a/Terminal.Gui/Views/Label.cs +++ b/Terminal.Gui/Views/Label.cs @@ -64,29 +64,59 @@ namespace Terminal.Gui { } /// - /// Initializes a new instance of at the given - /// coordinate with the given string, computes the bounding box - /// based on the size of the string, assumes that the string contains - /// newlines for multiple lines, no special breaking rules are used. + /// Initializes a new instance of using layout. /// + /// + /// + /// The will be created at the given + /// coordinates with the given string. The size ( will be + /// adjusted to fit the contents of , including newlines ('\n') for multiple lines. + /// + /// + /// No line wraping is provided. + /// + /// + /// column to locate the Label. + /// row to locate the Label. + /// text to initialize the property with. public Label (int x, int y, ustring text) : this (CalcRect (x, y, text), text) { } /// - /// Initializes a new instance of at the given - /// coordinate with the given string and uses the specified - /// frame for the string. + /// Initializes a new instance of using layout. /// + /// + /// + /// The will be created at the given + /// coordinates with the given string. The initial size ( will be + /// adjusted to fit the contents of , including newlines ('\n') for multiple lines. + /// + /// + /// No line wraping is provided. + /// + /// + /// Location. + /// text to initialize the property with. public Label (Rect rect, ustring text) : base (rect) { this.text = text; } /// - /// Initializes a new instance of and configures the default Width and Height based on the text, the result is suitable for Computed layout. + /// Initializes a new instance of using layout. /// - /// Text. + /// + /// + /// The will be created using + /// coordinates with the given string. The initial size ( will be + /// adjusted to fit the contents of , including newlines ('\n') for multiple lines. + /// + /// + /// No line wraping is provided. + /// + /// + /// text to initialize the property with. public Label (ustring text) : base () { this.text = text; @@ -95,6 +125,21 @@ namespace Terminal.Gui { Height = r.Height; } + /// + /// Initializes a new instance of using layout. + /// + /// + /// + /// The will be created using + /// coordinates. The initial size ( will be + /// adjusted to fit the contents of , including newlines ('\n') for multiple lines. + /// + /// + /// No line wraping is provided. + /// + /// + public Label () : this (text: string.Empty) { } + static char [] whitespace = new char [] { ' ', '\t' }; static ustring ClipAndJustify (ustring str, int width, TextAlignment talign) diff --git a/Terminal.Gui/Views/Menu.cs b/Terminal.Gui/Views/Menu.cs index a5f77a100..7b482cbb3 100644 --- a/Terminal.Gui/Views/Menu.cs +++ b/Terminal.Gui/Views/Menu.cs @@ -173,9 +173,12 @@ namespace Terminal.Gui { /// Initializes a new . /// /// The items in the current menu. - public MenuBarItem (MenuItem [] children) : this (new string (' ', GetMaxTitleLength (children)), children) - { - } + public MenuBarItem (MenuItem [] children) : this (new string (' ', GetMaxTitleLength (children)), children) { } + + /// + /// Initializes a new . + /// + public MenuBarItem () : this (children: new MenuItem [] { }) { } static int GetMaxTitleLength (MenuItem [] children) { @@ -550,6 +553,11 @@ namespace Terminal.Gui { /// public bool UseKeysUpDownAsKeysLeftRight { get; set; } = true; + /// + /// Initializes a new instance of the . + /// + public MenuBar () : this (new MenuBarItem [] { }) { } + /// /// Initializes a new instance of the class with the specified set of toplevel menu items. /// diff --git a/Terminal.Gui/Views/RadioGroup.cs b/Terminal.Gui/Views/RadioGroup.cs index 67af0e110..88b8b12c9 100644 --- a/Terminal.Gui/Views/RadioGroup.cs +++ b/Terminal.Gui/Views/RadioGroup.cs @@ -7,9 +7,7 @@ namespace Terminal.Gui { int selected, cursor; /// - /// Initializes a new instance of the class - /// setting up the initial set of radio labels and the item that should be selected and uses - /// an absolute layout for the result. + /// Initializes a new instance of the class using layout. /// /// Boundaries for the radio group. /// The radio labels; an array of strings that can contain hotkeys using an underscore before the letter. @@ -35,8 +33,12 @@ namespace Terminal.Gui { } /// - /// Initializes a new instance of the class - /// setting up the initial set of radio labels and the item that should be selected. + /// Initializes a new instance of the class using layout. + /// + public RadioGroup () : this (radioLabels: new string [] { }) { } + + /// + /// Initializes a new instance of the class using layout. /// /// The radio labels; an array of strings that can contain hotkeys using an underscore before the letter. /// The index of the item to be selected, the value is clamped to the number of items. @@ -66,17 +68,14 @@ namespace Terminal.Gui { } /// - /// Initializes a new instance of the class - /// setting up the initial set of radio labels and the item that should be selected. + /// Initializes a new instance of the class using layout. /// The frame is computed from the provided radio labels. /// /// The x coordinate. /// The y coordinate. /// The radio labels; an array of strings that can contain hotkeys using an underscore before the letter. /// The item to be selected, the value is clamped to the number of items. - public RadioGroup (int x, int y, string [] radioLabels, int selected = 0) : this (MakeRect (x, y, radioLabels), radioLabels, selected) - { - } + public RadioGroup (int x, int y, string [] radioLabels, int selected = 0) : this (MakeRect (x, y, radioLabels), radioLabels, selected) { } string [] radioLabels; diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index db1171e63..f93de4c22 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -125,7 +125,7 @@ namespace Terminal.Gui { /// public override void Redraw (Rect region) { - if (ColorScheme == null) + if (ColorScheme == null || Size == 0) return; Driver.SetAttribute (ColorScheme.Normal); diff --git a/Terminal.Gui/Views/StatusBar.cs b/Terminal.Gui/Views/StatusBar.cs index a7897ca77..93d205ea5 100644 --- a/Terminal.Gui/Views/StatusBar.cs +++ b/Terminal.Gui/Views/StatusBar.cs @@ -47,7 +47,7 @@ namespace Terminal.Gui { /// A set to `~F1~ Help` will render as *F1* using and /// *Help* as . /// - public ustring Title { get; set;} + public ustring Title { get; set; } /// /// Gets or sets the action to be invoked when the statusbar item is triggered @@ -103,6 +103,11 @@ namespace Terminal.Gui { /// public StatusItem [] Items { get; set; } + /// + /// Initializes a new instance of the class. + /// + public StatusBar () : this (items: new StatusItem [] { }) { } + /// /// Initializes a new instance of the class with the specified set of s. /// The will be drawn on the lowest line of the terminal or (if not null). @@ -131,11 +136,11 @@ namespace Terminal.Gui { break; case StatusBarStyle.SnapToBottom: #endif - if (Parent == null) { - Y = Driver.Rows - 1; - } else { - Y = Pos.Bottom (Parent); - } + if (Parent == null) { + Y = Driver.Rows - 1; + } else { + Y = Pos.Bottom (Parent); + } #if SNAP_TO_TOP break; } diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs index a2383abbb..6252115e3 100644 --- a/Terminal.Gui/Views/TextField.cs +++ b/Terminal.Gui/Views/TextField.cs @@ -44,7 +44,7 @@ namespace Terminal.Gui { public event EventHandler Changed; /// - /// Public constructor that creates a text field, with layout controlled with X, Y, Width and Height. + /// Initializes a new instance of the class using positioning. /// /// Initial text contents. public TextField (string text) : this (ustring.Make (text)) @@ -53,7 +53,12 @@ namespace Terminal.Gui { } /// - /// Public constructor that creates a text field, with layout controlled with X, Y, Width and Height. + /// Initializes a new instance of the class using positioning. + /// + public TextField () : this (string.Empty) { } + + /// + /// Initializes a new instance of the class using positioning. /// /// Initial text contents. public TextField (ustring text) @@ -62,7 +67,7 @@ namespace Terminal.Gui { } /// - /// Public constructor that creates a text field at an absolute position and size. + /// Initializes a new instance of the class using positioning. /// /// The x coordinate. /// The y coordinate. diff --git a/Terminal.Gui/Views/TimeField.cs b/Terminal.Gui/Views/TimeField.cs index c339e3835..3ac52aecb 100644 --- a/Terminal.Gui/Views/TimeField.cs +++ b/Terminal.Gui/Views/TimeField.cs @@ -30,12 +30,12 @@ namespace Terminal.Gui { /// - /// Initializes a new instance of at an absolute position and fixed size. + /// Initializes a new instance of using positioning. /// /// The x coordinate. /// The y coordinate. - /// Initial time contents. - /// If true, the seconds are hidden. + /// Initial time. + /// If true, the seconds are hidden. Sets the property. public TimeField (int x, int y, DateTime time, bool isShort = false) : base (x, y, isShort ? 7 : 10, "") { this.isShort = isShort; @@ -43,16 +43,21 @@ namespace Terminal.Gui { } /// - /// Initializes a new instance of + /// Initializes a new instance of using positioning. /// - /// - public TimeField (DateTime time) : base ("") + /// Initial time + public TimeField (DateTime time) : base (string.Empty) { this.isShort = true; Width = FieldLen + 2; Initialize (time); } + /// + /// Initializes a new instance of using positioning. + /// + public TimeField () : this (time: DateTime.MinValue) { } + void Initialize (DateTime time) { CultureInfo cultureInfo = CultureInfo.CurrentCulture; @@ -86,7 +91,7 @@ namespace Terminal.Gui { } /// - /// Get or set the data format for the widget. + /// Get or sets whether uses the short or long time format. /// public bool IsShortFormat { get => isShort; diff --git a/Terminal.Gui/Windows/Dialog.cs b/Terminal.Gui/Windows/Dialog.cs index b52827579..2d160483a 100644 --- a/Terminal.Gui/Windows/Dialog.cs +++ b/Terminal.Gui/Windows/Dialog.cs @@ -24,7 +24,7 @@ namespace Terminal.Gui { const int padding = 0; /// - /// Initializes a new instance of the class using positioning + /// Initializes a new instance of the class using positioning /// and an optional set of s to display /// /// Title for the dialog. @@ -61,10 +61,22 @@ namespace Terminal.Gui { Add (b); } } - - //LayoutComplete += (sender, a) => AdjustButtonLayout (); } + /// + /// Initializes a new instance of the class using . + /// + /// + /// + /// Te Dialog will be vertically and horizontally centered in the container and the size will be 85% of the container. + /// After initialzation use X, Y, Width, and Height to override this with a location or size. + /// + /// + /// Use to add buttons to the dialog. + /// + /// + public Dialog () : this (title: string.Empty, width: 0, height: 0, buttons: null) { } + /// /// Initializes a new instance of the class using positioning /// and with an optional set of s to display @@ -72,12 +84,10 @@ namespace Terminal.Gui { /// Title for the dialog. /// Optional buttons to lay out at the bottom of the dialog. /// - /// if width and height are both 0, the Dialog will be vertically and horizontally centered in the - /// container and the size will be 85% of the container. + /// Te Dialog will be vertically and horizontally centered in the container and the size will be 85% of the container. /// After initialzation use X, Y, Width, and Height to override this with a location or size. /// - public Dialog (ustring title, params Button [] buttons) : this (title: title, width: 0, height: 0, buttons: buttons) { - } + public Dialog (ustring title, params Button [] buttons) : this (title: title, width: 0, height: 0, buttons: buttons) { } /// /// Adds a to the , its layout will be controled by the diff --git a/Terminal.Gui/Windows/FileDialog.cs b/Terminal.Gui/Windows/FileDialog.cs index 3390febc6..974cfd61a 100644 --- a/Terminal.Gui/Windows/FileDialog.cs +++ b/Terminal.Gui/Windows/FileDialog.cs @@ -19,7 +19,7 @@ namespace Terminal.Gui { internal class DirListView : View { int top, selected; DirectoryInfo dirInfo; - List<(string,bool,bool)> infos; + List<(string, bool, bool)> infos; internal bool canChooseFiles = true; internal bool canChooseDirectories = false; internal bool allowsMultipleSelection = false; @@ -27,7 +27,7 @@ namespace Terminal.Gui { public DirListView (FileDialog host) { - infos = new List<(string,bool,bool)> (); + infos = new List<(string, bool, bool)> (); CanFocus = true; this.host = host; } @@ -35,7 +35,7 @@ namespace Terminal.Gui { bool IsAllowed (FileSystemInfo fsi) { if (fsi.Attributes.HasFlag (FileAttributes.Directory)) - return true; + return true; if (allowedFileTypes == null) return true; foreach (var ft in allowedFileTypes) @@ -48,9 +48,9 @@ namespace Terminal.Gui { { dirInfo = new DirectoryInfo (directory.ToString ()); infos = (from x in dirInfo.GetFileSystemInfos () - where IsAllowed (x) - orderby (!x.Attributes.HasFlag (FileAttributes.Directory)) + x.Name - select (x.Name, x.Attributes.HasFlag (FileAttributes.Directory), false)).ToList (); + where IsAllowed (x) + orderby (!x.Attributes.HasFlag (FileAttributes.Directory)) + x.Name + select (x.Name, x.Attributes.HasFlag (FileAttributes.Directory), false)).ToList (); infos.Insert (0, ("..", true, false)); top = 0; selected = 0; @@ -407,7 +407,7 @@ namespace Terminal.Gui { return new List () { MakePath (infos [selected].Item1) }; return Array.Empty (); } else { - if (canChooseFiles) + if (canChooseFiles) return new List () { MakePath (infos [selected].Item1) }; return Array.Empty (); } @@ -425,6 +425,11 @@ namespace Terminal.Gui { TextField dirEntry, nameEntry; internal DirListView dirListView; + /// + /// Initializes a new . + /// + public FileDialog () : this (title: string.Empty, prompt: string.Empty, nameFieldLabel: string.Empty, message: string.Empty) { } + /// /// Initializes a new instance of /// @@ -582,9 +587,9 @@ namespace Terminal.Gui { /// /// The absolute file path for the file path entered. public ustring FilePath { - get => dirListView.MakePath(nameEntry.Text.ToString()); + get => dirListView.MakePath (nameEntry.Text.ToString ()); set { - nameEntry.Text = Path.GetFileName(value.ToString()); + nameEntry.Text = Path.GetFileName (value.ToString ()); } } @@ -608,13 +613,16 @@ namespace Terminal.Gui { /// public class SaveDialog : FileDialog { /// - /// Initializes a new + /// Initializes a new . + /// + public SaveDialog () : this (title: string.Empty, message: string.Empty) { } + + /// + /// Initializes a new . /// /// The title. /// The message. - public SaveDialog (ustring title, ustring message) : base (title, prompt: "Save", nameFieldLabel: "Save as:", message: message) - { - } + public SaveDialog (ustring title, ustring message) : base (title, prompt: "Save", nameFieldLabel: "Save as:", message: message) { } /// /// Gets the name of the file the user selected for saving, or null @@ -625,7 +633,7 @@ namespace Terminal.Gui { get { if (canceled) return null; - return Path.GetFileName(FilePath.ToString()); + return Path.GetFileName (FilePath.ToString ()); } } } @@ -650,7 +658,12 @@ namespace Terminal.Gui { /// public class OpenDialog : FileDialog { /// - /// Initializes a new + /// Initializes a new . + /// + public OpenDialog () : this (title: string.Empty, message: string.Empty) { } + + /// + /// Initializes a new . /// /// /// diff --git a/UICatalog/Scenarios/ComputedLayout.cs b/UICatalog/Scenarios/ComputedLayout.cs index 0ca45c525..3ca51d9ec 100644 --- a/UICatalog/Scenarios/ComputedLayout.cs +++ b/UICatalog/Scenarios/ComputedLayout.cs @@ -1,6 +1,8 @@ -using System; +using NStack; +using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using Terminal.Gui; @@ -17,13 +19,27 @@ namespace UICatalog { public override void Setup () { + var menu = new MenuBar (new MenuBarItem [] { + new MenuBarItem ("_Settings", new MenuItem [] { + null, + new MenuItem ("_Quit", "", () => Quit()), + }), + new MenuBarItem ("_All Controls", "Tests all controls", () => DemoAllViewClasses() ), + }); + Top.Add (menu); + + var statusBar = new StatusBar (new StatusItem [] { + new StatusItem(Key.ControlQ, "~^Q~ Quit", () => Quit()), + }); + Top.Add (statusBar); + //Top.LayoutStyle = LayoutStyle.Computed; // Demonstrate using Dim to create a horizontal ruler that always measures the parent window's width // BUGBUG: Dim.Fill returns too big a value sometimes. const string rule = "|123456789"; var horizontalRuler = new Label ("") { X = 0, - Y = 0, + Y = 0, Width = Dim.Fill (1), // BUGBUG: I don't think this should be needed; DimFill() should respect container's frame. X does. ColorScheme = Colors.Error }; @@ -44,7 +60,7 @@ namespace UICatalog { Win.LayoutComplete += (sender, a) => { horizontalRuler.Text = rule.Repeat ((int)Math.Ceiling ((double)(horizontalRuler.Bounds.Width) / (double)rule.Length)) [0..(horizontalRuler.Bounds.Width)]; - verticalRuler.Text = vrule.Repeat ((int)Math.Ceiling ((double)(verticalRuler.Bounds.Height*2) / (double)rule.Length)) [0..(verticalRuler.Bounds.Height*2)]; + verticalRuler.Text = vrule.Repeat ((int)Math.Ceiling ((double)(verticalRuler.Bounds.Height * 2) / (double)rule.Length)) [0..(verticalRuler.Bounds.Height * 2)]; }; Win.Add (verticalRuler); @@ -59,7 +75,7 @@ namespace UICatalog { // Demonstrate using Dim to create a window that fills the parent with a margin int margin = 10; var subWin = new Window ($"Centered Sub Window with {margin} character margin") { - X = Pos.Center(), + X = Pos.Center (), Y = 2, Width = Dim.Fill (margin), Height = 7 @@ -79,7 +95,7 @@ namespace UICatalog { // #522 repro? var frameView = new FrameView ($"Centered FrameView with {margin} character margin") { X = Pos.Center (), - Y = Pos.Bottom(subWin), + Y = Pos.Bottom (subWin), Width = Dim.Fill (margin), Height = 7 }; @@ -176,7 +192,7 @@ namespace UICatalog { // Center three buttons with 5 spaces between them // TODO: Use Pos.Width instead of (Right-Left) when implemented (#502) - leftButton.X = Pos.Left (centerButton) - (Pos.Right(leftButton) - Pos.Left (leftButton)) - 5; + leftButton.X = Pos.Left (centerButton) - (Pos.Right (leftButton) - Pos.Left (leftButton)) - 5; rightButton.X = Pos.Right (centerButton) + 5; Win.Add (leftButton); @@ -184,10 +200,110 @@ namespace UICatalog { Win.Add (rightButton); } + /// + /// Displays a Dialog that uses a wizard (next/prev) idom to step through each class derived from View + /// testing various Computed layout scenarios + /// + private void DemoAllViewClasses () + { + List GetAllViewClassesCollection () + { + List objects = new List (); + foreach (Type type in typeof (View).Assembly.GetTypes () + .Where (myType => myType.IsClass && !myType.IsAbstract && myType.IsPublic && myType.IsSubclassOf (typeof (View)))) { + objects.Add (type); + } + return objects; + } + + var viewClasses = GetAllViewClassesCollection ().OrderByDescending (c => c.Name).ToList (); + var curClass = 0; + + var closeBtn = new Button ("_Close") { + Clicked = () => { + Application.RequestStop (); + }, + }; + var nextBtn = new Button ("_Next"); + var prevBtn = new Button ("_Previous"); + var dialog = new Dialog ("Demoing all View classs", new [] { prevBtn, nextBtn, closeBtn }); + + var label = new Label ("Class:") { + X = 0, + Y = 0, + }; + dialog.Add (label); + var currentClassLabel = new Label ("") { + X = Pos.Right (label) + 1, + Y = Pos.Y (label), + }; + dialog.Add (currentClassLabel); + + View curView = null; + void SetCurrentClass () + { + currentClassLabel.Text = $"{viewClasses [curClass].Name}"; + + // Remove existing class, if any + if (curView != null) { + dialog.Remove (curView); + curView = null; + } + + // Instantiate view + curView = (View)Activator.CreateInstance (viewClasses [curClass]); + + curView.X = Pos.Center (); + curView.Y = Pos.Center (); + curView.Width = Dim.Fill (5); + curView.Height = Dim.Fill (5); + + // If the view supports a Text property, set it so we have something to look at + if (viewClasses [curClass].GetProperty("Text") != null) { + curView.GetType ().GetProperty ("Text")?.GetSetMethod ()?.Invoke (curView, new [] { ustring.Make("09/10/1966") }); + } + + // If the view supports a Title property, set it so we have something to look at + if (viewClasses [curClass].GetProperty ("Title") != null) { + curView.GetType ().GetProperty ("Title")?.GetSetMethod ()?.Invoke (curView, new [] { ustring.Make ("Test Title") }); + } + + + dialog.Add (curView); + dialog.LayoutSubviews (); + } + + nextBtn.Clicked = () => { + curClass++; + if (curClass >= viewClasses.Count) { + curClass = 0; + } + SetCurrentClass (); + }; + + prevBtn.Clicked = () => { + if (curClass == 0) { + curClass = viewClasses.Count - 1; + } else { + curClass--; + } + SetCurrentClass (); + }; + + SetCurrentClass (); + + Application.Run (dialog); + } + public override void Run () { base.Run (); } + + private void Quit () + { + Application.RequestStop (); + } } internal static class StringExtensions {