From 17e14aba6394cd3894aa8bcea503f30680377730 Mon Sep 17 00:00:00 2001 From: Tig Date: Sun, 4 Aug 2024 15:49:34 -0600 Subject: [PATCH 01/13] Initial commit. --- Terminal.Gui/Views/NumericUpDown.cs | 178 ++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 Terminal.Gui/Views/NumericUpDown.cs diff --git a/Terminal.Gui/Views/NumericUpDown.cs b/Terminal.Gui/Views/NumericUpDown.cs new file mode 100644 index 000000000..67650f0de --- /dev/null +++ b/Terminal.Gui/Views/NumericUpDown.cs @@ -0,0 +1,178 @@ +using System.ComponentModel; +using Terminal.Gui; + +/// +/// Enables the user to increase or decrease a value by clicking on the up or down buttons. +/// +/// +/// Supports the following types: , , , , +/// . +/// Supports only one digit of precision. +/// +public class NumericUpDown : View +{ + private readonly Button _down; + + // TODO: Use a TextField instead of a Label + private readonly View _number; + private readonly Button _up; + + public NumericUpDown () + { + Type type = typeof (T); + + if (!(type == typeof (int) || type == typeof (long) || type == typeof (float) || type == typeof (double) || type == typeof (decimal))) + { + // Support object for AllViewsTester + if (type != typeof (object)) + { + throw new InvalidOperationException ("T must be a numeric type that supports addition and subtraction."); + } + } + + Width = Dim.Auto (DimAutoStyle.Content); //Dim.Function (() => Digits + 2); // button + 3 for number + button + Height = Dim.Auto (DimAutoStyle.Content); + + _down = new () + { + Height = 1, + Width = 1, + NoPadding = true, + NoDecorations = true, + Title = $"{Glyphs.DownArrow}", + WantContinuousButtonPressed = true, + CanFocus = false, + ShadowStyle = ShadowStyle.None + }; + + _number = new () + { + Text = Value?.ToString () ?? "Err", + X = Pos.Right (_down), + Y = Pos.Top (_down), + Width = Dim.Func (() => Digits), + Height = 1, + TextAlignment = Alignment.Center, + CanFocus = true + }; + + _up = new () + { + X = Pos.AnchorEnd (), + Y = Pos.Top (_number), + Height = 1, + Width = 1, + NoPadding = true, + NoDecorations = true, + Title = $"{Glyphs.UpArrow}", + WantContinuousButtonPressed = true, + CanFocus = false, + ShadowStyle = ShadowStyle.None + }; + + CanFocus = true; + + _down.Accept += OnDownButtonOnAccept; + _up.Accept += OnUpButtonOnAccept; + + Add (_down, _number, _up); + + AddCommand ( + Command.ScrollUp, + () => + { + if (type == typeof (object)) + { + return false; + } + + Value = (dynamic)Value + 1; + _number.Text = Value?.ToString () ?? string.Empty; + + return true; + }); + + AddCommand ( + Command.ScrollDown, + () => + { + if (type == typeof (object)) + { + return false; + } + + Value = (dynamic)Value - 1; + _number.Text = Value.ToString () ?? string.Empty; + + return true; + }); + + KeyBindings.Add (Key.CursorUp, Command.ScrollUp); + KeyBindings.Add (Key.CursorDown, Command.ScrollDown); + + return; + + void OnDownButtonOnAccept (object s, HandledEventArgs e) { InvokeCommand (Command.ScrollDown); } + + void OnUpButtonOnAccept (object s, HandledEventArgs e) { InvokeCommand (Command.ScrollUp); } + } + + private void _up_Enter (object sender, FocusEventArgs e) { throw new NotImplementedException (); } + + private T _value; + + /// + /// The value that will be incremented or decremented. + /// + public T Value + { + get => _value; + set + { + if (_value.Equals (value)) + { + return; + } + + T oldValue = value; + CancelEventArgs args = new (ref _value, ref value); + ValueChanging?.Invoke (this, args); + + if (args.Cancel) + { + return; + } + + _value = value; + _number.Text = _value.ToString (); + ValueChanged?.Invoke (this, new (ref _value)); + } + } + + /// + /// Fired when the value is about to change. Set to true to prevent the change. + /// + [CanBeNull] + public event EventHandler> ValueChanging; + + /// + /// Fired when the value has changed. + /// + [CanBeNull] + public event EventHandler> ValueChanged; + + /// + /// The number of digits to display. The will be resized to fit this number of characters + /// plus the buttons. The default is 3. + /// + public int Digits { get; set; } = 3; +} + + +/// +/// Enables the user to increase or decrease an by clicking on the up or down buttons. +/// +public class NumericUpDown : NumericUpDown +{ + +} From cebf1773af29fd09c972fabd5e9c0fa75ee25d0d Mon Sep 17 00:00:00 2001 From: Tig Date: Sun, 4 Aug 2024 17:10:00 -0600 Subject: [PATCH 02/13] Added other types --- Terminal.Gui/Views/NumericUpDown.cs | 113 +++++++++++++++-- UICatalog/Scenarios/AdornmentEditor.cs | 8 +- UICatalog/Scenarios/Buttons.cs | 154 ----------------------- UICatalog/Scenarios/ContentScrolling.cs | 4 +- UICatalog/Scenarios/PosAlignDemo.cs | 2 +- UICatalog/Scenarios/Sliders.cs | 2 +- UnitTests/Views/NumericUpDownTests.cs | 160 ++++++++++++++++++++++++ 7 files changed, 272 insertions(+), 171 deletions(-) create mode 100644 UnitTests/Views/NumericUpDownTests.cs diff --git a/Terminal.Gui/Views/NumericUpDown.cs b/Terminal.Gui/Views/NumericUpDown.cs index 67650f0de..496872546 100644 --- a/Terminal.Gui/Views/NumericUpDown.cs +++ b/Terminal.Gui/Views/NumericUpDown.cs @@ -1,3 +1,4 @@ +#nullable enable using System.ComponentModel; using Terminal.Gui; @@ -5,7 +6,7 @@ using Terminal.Gui; /// Enables the user to increase or decrease a value by clicking on the up or down buttons. /// /// -/// Supports the following types: , , , , +/// Supports the following types: , , , , /// . /// Supports only one digit of precision. /// @@ -21,7 +22,7 @@ public class NumericUpDown : View { Type type = typeof (T); - if (!(type == typeof (int) || type == typeof (long) || type == typeof (float) || type == typeof (double) || type == typeof (decimal))) + if (!(type == typeof (int) || type == typeof (long) || type == typeof (double) || type == typeof (float) || type == typeof (double) || type == typeof (decimal))) { // Support object for AllViewsTester if (type != typeof (object)) @@ -30,6 +31,45 @@ public class NumericUpDown : View } } + switch (typeof (T)) + { + case { } i when i == typeof (int): + Minimum = (dynamic)int.MinValue; + Maximum = (dynamic)int.MaxValue; + Increment = (dynamic)1; + + break; + + case { } i when i == typeof (long): + Minimum = (dynamic)long.MinValue; + Maximum = (dynamic)long.MaxValue; + Increment = (dynamic)1; + + break; + + case { } i when i == typeof (double): + Minimum = (dynamic)double.MinValue; + Maximum = (dynamic)double.MaxValue; + Increment = (dynamic)1; + + break; + + case { } i when i == typeof (float): + Minimum = (dynamic)float.MinValue; + Maximum = (dynamic)float.MaxValue; + Increment = (dynamic)1; + + break; + + + case { } i when i == typeof (decimal): + Minimum = (dynamic)decimal.MinValue; + Maximum = (dynamic)decimal.MaxValue; + Increment = (dynamic)1; + + break; + } + Width = Dim.Auto (DimAutoStyle.Content); //Dim.Function (() => Digits + 2); // button + 3 for number + button Height = Dim.Auto (DimAutoStyle.Content); @@ -86,8 +126,11 @@ public class NumericUpDown : View return false; } - Value = (dynamic)Value + 1; - _number.Text = Value?.ToString () ?? string.Empty; + if (Value is { }) + { + Value = (dynamic)Value + Increment; + _number.Text = Value?.ToString () ?? string.Empty; + } return true; }); @@ -101,8 +144,11 @@ public class NumericUpDown : View return false; } - Value = (dynamic)Value - 1; - _number.Text = Value.ToString () ?? string.Empty; + if (Value is { }) + { + Value = (dynamic)Value - Increment; + _number.Text = Value.ToString () ?? string.Empty; + } return true; }); @@ -112,9 +158,15 @@ public class NumericUpDown : View return; - void OnDownButtonOnAccept (object s, HandledEventArgs e) { InvokeCommand (Command.ScrollDown); } + void OnDownButtonOnAccept (object s, HandledEventArgs e) + { + InvokeCommand (Command.ScrollDown); + } - void OnUpButtonOnAccept (object s, HandledEventArgs e) { InvokeCommand (Command.ScrollUp); } + void OnUpButtonOnAccept (object s, HandledEventArgs e) + { + InvokeCommand (Command.ScrollUp); + } } private void _up_Enter (object sender, FocusEventArgs e) { throw new NotImplementedException (); } @@ -143,8 +195,18 @@ public class NumericUpDown : View return; } + if (Comparer.Default.Compare (value, Minimum) < 0) + { + value = Minimum; + } + + if (Comparer.Default.Compare (value, Maximum) > 0) + { + value = Maximum; + } + _value = value; - _number.Text = _value.ToString (); + _number.Text = _value?.ToString () ?? string.Empty; ValueChanged?.Invoke (this, new (ref _value)); } } @@ -166,6 +228,39 @@ public class NumericUpDown : View /// plus the buttons. The default is 3. /// public int Digits { get; set; } = 3; + + private T _minimum; + + /// + /// + /// + public T Minimum + { + get { return _minimum; } + set { _minimum = value; } + } + + private T _maximum; + + /// + /// + /// + public T Maximum + { + get { return _maximum; } + set { _maximum = value; } + } + + private T _increment; + + /// + /// + /// + public T Increment + { + get { return _increment; } + set { _increment = value; } + } } diff --git a/UICatalog/Scenarios/AdornmentEditor.cs b/UICatalog/Scenarios/AdornmentEditor.cs index e97d25ada..ba99f9e84 100644 --- a/UICatalog/Scenarios/AdornmentEditor.cs +++ b/UICatalog/Scenarios/AdornmentEditor.cs @@ -78,10 +78,10 @@ public class AdornmentEditor : View AdornmentChanged?.Invoke (this, EventArgs.Empty); } - private Buttons.NumericUpDown _topEdit; - private Buttons.NumericUpDown _leftEdit; - private Buttons.NumericUpDown _bottomEdit; - private Buttons.NumericUpDown _rightEdit; + private NumericUpDown _topEdit; + private NumericUpDown _leftEdit; + private NumericUpDown _bottomEdit; + private NumericUpDown _rightEdit; public AdornmentEditor () { diff --git a/UICatalog/Scenarios/Buttons.cs b/UICatalog/Scenarios/Buttons.cs index aab815a96..807f98dd3 100644 --- a/UICatalog/Scenarios/Buttons.cs +++ b/UICatalog/Scenarios/Buttons.cs @@ -395,159 +395,5 @@ public class Buttons : Scenario main.Dispose (); Application.Shutdown (); } - - /// - /// Enables the user to increase or decrease a value by clicking on the up or down buttons. - /// - /// - /// Supports the following types: , , , , . - /// Supports only one digit of precision. - /// - public class NumericUpDown : View - { - private readonly Button _down; - // TODO: Use a TextField instead of a Label - private readonly View _number; - private readonly Button _up; - - public NumericUpDown () - { - Type type = typeof (T); - if (!(type == typeof (int) || type == typeof (long) || type == typeof (float) || type == typeof (double) || type == typeof (decimal))) - { - throw new InvalidOperationException ("T must be a numeric type that supports addition and subtraction."); - } - - Width = Dim.Auto (DimAutoStyle.Content); //Dim.Function (() => Digits + 2); // button + 3 for number + button - Height = Dim.Auto (DimAutoStyle.Content); - - _down = new () - { - Height = 1, - Width = 1, - NoPadding = true, - NoDecorations = true, - Title = $"{CM.Glyphs.DownArrow}", - WantContinuousButtonPressed = true, - CanFocus = false, - ShadowStyle = ShadowStyle.None, - }; - - _number = new () - { - Text = Value.ToString (), - X = Pos.Right (_down), - Y = Pos.Top (_down), - Width = Dim.Func (() => Digits), - Height = 1, - TextAlignment = Alignment.Center, - CanFocus = true - }; - - _up = new () - { - X = Pos.AnchorEnd (), - Y = Pos.Top (_number), - Height = 1, - Width = 1, - NoPadding = true, - NoDecorations = true, - Title = $"{CM.Glyphs.UpArrow}", - WantContinuousButtonPressed = true, - CanFocus = false, - ShadowStyle = ShadowStyle.None, - }; - - CanFocus = true; - - _down.Accept += OnDownButtonOnAccept; - _up.Accept += OnUpButtonOnAccept; - - Add (_down, _number, _up); - - - AddCommand (Command.ScrollUp, () => - { - Value = (dynamic)Value + 1; - _number.Text = Value.ToString (); - - return true; - }); - AddCommand (Command.ScrollDown, () => - { - Value = (dynamic)Value - 1; - _number.Text = Value.ToString (); - - return true; - }); - - KeyBindings.Add (Key.CursorUp, Command.ScrollUp); - KeyBindings.Add (Key.CursorDown, Command.ScrollDown); - - return; - - void OnDownButtonOnAccept (object s, HandledEventArgs e) - { - InvokeCommand (Command.ScrollDown); - } - - void OnUpButtonOnAccept (object s, HandledEventArgs e) - { - InvokeCommand (Command.ScrollUp); - } - } - - private void _up_Enter (object sender, FocusEventArgs e) - { - throw new NotImplementedException (); - } - - private T _value; - - /// - /// The value that will be incremented or decremented. - /// - public T Value - { - get => _value; - set - { - if (_value.Equals (value)) - { - return; - } - - T oldValue = value; - CancelEventArgs args = new (ref _value, ref value); - ValueChanging?.Invoke (this, args); - - if (args.Cancel) - { - return; - } - - _value = value; - _number.Text = _value.ToString (); - ValueChanged?.Invoke (this, new (ref _value)); - } - } - - /// - /// Fired when the value is about to change. Set to true to prevent the change. - /// - [CanBeNull] - public event EventHandler> ValueChanging; - - /// - /// Fired when the value has changed. - /// - [CanBeNull] - public event EventHandler> ValueChanged; - - /// - /// The number of digits to display. The will be resized to fit this number of characters plus the buttons. The default is 3. - /// - public int Digits { get; set; } = 3; - } } diff --git a/UICatalog/Scenarios/ContentScrolling.cs b/UICatalog/Scenarios/ContentScrolling.cs index 5d4a1a3c2..9e4416658 100644 --- a/UICatalog/Scenarios/ContentScrolling.cs +++ b/UICatalog/Scenarios/ContentScrolling.cs @@ -229,7 +229,7 @@ public class ContentScrolling : Scenario Y = Pos.Bottom (cbAllowYGreaterThanContentHeight) }; - Buttons.NumericUpDown contentSizeWidth = new Buttons.NumericUpDown + NumericUpDown contentSizeWidth = new NumericUpDown { Value = view.GetContentSize ().Width, X = Pos.Right (labelContentSize) + 1, @@ -256,7 +256,7 @@ public class ContentScrolling : Scenario Y = Pos.Top (labelContentSize) }; - Buttons.NumericUpDown contentSizeHeight = new Buttons.NumericUpDown + NumericUpDown contentSizeHeight = new NumericUpDown { Value = view.GetContentSize ().Height, X = Pos.Right (labelComma) + 1, diff --git a/UICatalog/Scenarios/PosAlignDemo.cs b/UICatalog/Scenarios/PosAlignDemo.cs index d7ae5146e..03e90b806 100644 --- a/UICatalog/Scenarios/PosAlignDemo.cs +++ b/UICatalog/Scenarios/PosAlignDemo.cs @@ -236,7 +236,7 @@ public sealed class PosAlignDemo : Scenario } ]; - Buttons.NumericUpDown addedViewsUpDown = new() + NumericUpDown addedViewsUpDown = new() { Width = 9, Title = "Added", diff --git a/UICatalog/Scenarios/Sliders.cs b/UICatalog/Scenarios/Sliders.cs index c65d28093..bf81264fe 100644 --- a/UICatalog/Scenarios/Sliders.cs +++ b/UICatalog/Scenarios/Sliders.cs @@ -407,7 +407,7 @@ public class Sliders : Scenario Text = "Min _Inner Spacing:", }; - Buttons.NumericUpDown innerSpacingUpDown = new () + NumericUpDown innerSpacingUpDown = new () { X = Pos.Right (label) + 1 }; diff --git a/UnitTests/Views/NumericUpDownTests.cs b/UnitTests/Views/NumericUpDownTests.cs new file mode 100644 index 000000000..12c66993c --- /dev/null +++ b/UnitTests/Views/NumericUpDownTests.cs @@ -0,0 +1,160 @@ +using System.ComponentModel; +using Xunit.Abstractions; + +namespace Terminal.Gui.ViewsTests; + +public class NumericUpDownTests (ITestOutputHelper _output) +{ + + [Fact] + public void WhenCreated_ShouldHaveDefaultValues_int () + { + NumericUpDown numericUpDown = new (); + + Assert.Equal (0, numericUpDown.Value); + Assert.Equal (int.MinValue, numericUpDown.Minimum); + Assert.Equal (int.MaxValue, numericUpDown.Maximum); + Assert.Equal (1, numericUpDown.Increment); + } + + [Fact] + public void WhenCreated_ShouldHaveDefaultValues_long () + { + NumericUpDown numericUpDown = new (); + + Assert.Equal (0, numericUpDown.Value); + Assert.Equal (long.MinValue, numericUpDown.Minimum); + Assert.Equal (long.MaxValue, numericUpDown.Maximum); + Assert.Equal (1, numericUpDown.Increment); + } + + [Fact] + public void WhenCreated_ShouldHaveDefaultValues_float () + { + NumericUpDown numericUpDown = new (); + + Assert.Equal (0F, numericUpDown.Value); + Assert.Equal (float.MinValue, numericUpDown.Minimum); + Assert.Equal (float.MaxValue, numericUpDown.Maximum); + Assert.Equal (1.0F, numericUpDown.Increment); + } + + [Fact] + public void WhenCreated_ShouldHaveDefaultValues_double () + { + NumericUpDown numericUpDown = new (); + + Assert.Equal (0F, numericUpDown.Value); + Assert.Equal (double.MinValue, numericUpDown.Minimum); + Assert.Equal (double.MaxValue, numericUpDown.Maximum); + Assert.Equal (1.0F, numericUpDown.Increment); + } + + [Fact] + public void WhenCreated_ShouldHaveDefaultValues_decimal () + { + NumericUpDown numericUpDown = new (); + + Assert.Equal (0, numericUpDown.Value); + Assert.Equal (decimal.MinValue, numericUpDown.Minimum); + Assert.Equal (decimal.MaxValue, numericUpDown.Maximum); + Assert.Equal (1, numericUpDown.Increment); + } + + [Fact] + public void WhenCreatedWithCustomValues_ShouldHaveCustomValues_int () + { + var numericUpDown = new NumericUpDown () + { + Value = 10, + Minimum = 5, + Maximum = 15, + Increment = 2 + }; + + Assert.Equal (10, numericUpDown.Value); + Assert.Equal (5, numericUpDown.Minimum); + Assert.Equal (15, numericUpDown.Maximum); + Assert.Equal (2, numericUpDown.Increment); + } + + [Fact] + public void WhenCreatedWithCustomValues_ShouldHaveCustomValues_float () + { + var numericUpDown = new NumericUpDown () + { + Value = 10.5F, + Minimum = 5.5F, + Maximum = 15.5F, + Increment = 2.5F + }; + + Assert.Equal (10.5F, numericUpDown.Value); + Assert.Equal (5.5F, numericUpDown.Minimum); + Assert.Equal (15.5F, numericUpDown.Maximum); + Assert.Equal (2.5F, numericUpDown.Increment); + } + + [Fact] + public void NumericUpDown_WhenCreatedWithInvalidType_ShouldThrowInvalidOperationException () + { + Assert.Throws (() => new NumericUpDown ()); + } + + [Fact] + public void NumericUpDown_WhenCreatedWithInvalidTypeObject_ShouldNotThrowInvalidOperationException () + { + var numericUpDown = new NumericUpDown (); + + Assert.Equal (0, numericUpDown.Value); + Assert.Equal (0, numericUpDown.Minimum); + Assert.Equal (100, numericUpDown.Maximum); + Assert.Equal (1, numericUpDown.Increment); + } + + [Fact] + public void NumericUpDown_WhenCreatedWithInvalidTypeObjectAndCustomValues_ShouldHaveCustomValues () + { + var numericUpDown = new NumericUpDown () + { + Value = 10, + Minimum = 5, + Maximum = 15, + Increment = 2 + }; + + Assert.Equal (10, numericUpDown.Value); + Assert.Equal (5, numericUpDown.Minimum); + Assert.Equal (15, numericUpDown.Maximum); + Assert.Equal (2, numericUpDown.Increment); + } + + [Fact] + public void NumericUpDown_WhenCreated_ShouldHaveDefaultWidthAndHeight_int () + { + var numericUpDown = new NumericUpDown (); + numericUpDown.SetRelativeLayout(Application.Screen.Size); + + Assert.Equal (5, numericUpDown.Frame.Width); + Assert.Equal (1, numericUpDown.Frame.Height); + } + + [Fact] + public void NumericUpDown_WhenCreated_ShouldHaveDefaultWidthAndHeight_float () + { + var numericUpDown = new NumericUpDown (); + numericUpDown.SetRelativeLayout (Application.Screen.Size); + + Assert.Equal (5, numericUpDown.Frame.Width); + Assert.Equal (1, numericUpDown.Frame.Height); + } + + [Fact] + public void NumericUpDown_WhenCreated_ShouldHaveDefaultUpDownButtons () + { + var numericUpDown = new NumericUpDown (); + + // Assert.Equal (1, numericUpDown + } + +} \ No newline at end of file From de10e22b220a3e22360a542d1cfce642cb3750fc Mon Sep 17 00:00:00 2001 From: Tig Date: Mon, 5 Aug 2024 12:41:37 -0600 Subject: [PATCH 03/13] Code cleanup --- Terminal.Gui/Views/NumericUpDown.cs | 45 +++++++++++++++-------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/Terminal.Gui/Views/NumericUpDown.cs b/Terminal.Gui/Views/NumericUpDown.cs index c1a46e972..44b43c0c2 100644 --- a/Terminal.Gui/Views/NumericUpDown.cs +++ b/Terminal.Gui/Views/NumericUpDown.cs @@ -1,16 +1,14 @@ #nullable enable using System.ComponentModel; -using Microsoft.CodeAnalysis.Operations; namespace Terminal.Gui; /// -/// Enables the user to increase or decrease a value by clicking on the up or down buttons. +/// Enables the user to increase or decrease a value with the mouse or keyboard. /// /// /// Supports the following types: , , , , -/// . -/// Supports only one digit of precision. +/// . Attempting to use any other type will result in an . /// public class NumericUpDown : View where T : notnull { @@ -28,19 +26,26 @@ public class NumericUpDown : View where T : notnull { Type type = typeof (T); - if (!(type == typeof (object) || type == typeof (int) || type == typeof (long) || type == typeof (double) || type == typeof (float) || type == typeof (double) || type == typeof (decimal))) + if (!(type == typeof (object) + || type == typeof (int) + || type == typeof (long) + || type == typeof (double) + || type == typeof (float) + || type == typeof (double) + || type == typeof (decimal))) { throw new InvalidOperationException ("T must be a numeric type that supports addition and subtraction."); } Increment = (dynamic)1; + // `object` is supported only for AllViewsTester if (type != typeof (object)) { Value = (dynamic)0; } - Width = Dim.Auto (DimAutoStyle.Content); //Dim.Function (() => Digits + 2); // button + 3 for number + button + Width = Dim.Auto (DimAutoStyle.Content); Height = Dim.Auto (DimAutoStyle.Content); _down = new () @@ -128,22 +133,23 @@ public class NumericUpDown : View where T : notnull return; - void OnDownButtonOnAccept (object? s, HandledEventArgs e) - { - InvokeCommand (Command.ScrollDown); - } + void OnDownButtonOnAccept (object? s, HandledEventArgs e) { InvokeCommand (Command.ScrollDown); } - void OnUpButtonOnAccept (object? s, HandledEventArgs e) - { - InvokeCommand (Command.ScrollUp); - } + void OnUpButtonOnAccept (object? s, HandledEventArgs e) { InvokeCommand (Command.ScrollUp); } } private T _value = default!; /// - /// The value that will be incremented or decremented. + /// Gets or sets the value that will be incremented or decremented. /// + /// + /// + /// and events are raised when the value changes. + /// The event can be canceled the change setting to + /// . + /// + /// public T Value { get => _value; @@ -196,7 +202,8 @@ public class NumericUpDown : View where T : notnull } /// - /// Raised when the value is about to change. Set to true to prevent the change. + /// Raised when the value is about to change. Set to true to prevent the + /// change. /// public event EventHandler>? ValueChanging; @@ -206,16 +213,12 @@ public class NumericUpDown : View where T : notnull public event EventHandler>? ValueChanged; /// - /// /// public T Increment { get; set; } } - /// /// Enables the user to increase or decrease an by clicking on the up or down buttons. /// public class NumericUpDown : NumericUpDown -{ - -} +{ } From c0fc83bd78af4e4e3f53f167c86514149b15b05d Mon Sep 17 00:00:00 2001 From: Tig Date: Mon, 5 Aug 2024 17:44:48 -0600 Subject: [PATCH 04/13] Added Scenario and expanded API --- Terminal.Gui/Views/NumericUpDown.cs | 53 ++++- UICatalog/Scenarios/Buttons.cs | 18 +- UICatalog/Scenarios/NumericUpDownDemo.cs | 291 +++++++++++++++++++++++ UnitTests/Views/NumericUpDownTests.cs | 29 +++ 4 files changed, 370 insertions(+), 21 deletions(-) create mode 100644 UICatalog/Scenarios/NumericUpDownDemo.cs diff --git a/Terminal.Gui/Views/NumericUpDown.cs b/Terminal.Gui/Views/NumericUpDown.cs index 44b43c0c2..c36534172 100644 --- a/Terminal.Gui/Views/NumericUpDown.cs +++ b/Terminal.Gui/Views/NumericUpDown.cs @@ -146,7 +146,8 @@ public class NumericUpDown : View where T : notnull /// /// /// and events are raised when the value changes. - /// The event can be canceled the change setting to + /// The event can be canceled the change setting + /// to /// . /// /// @@ -175,6 +176,17 @@ public class NumericUpDown : View where T : notnull } } + /// + /// Raised when the value is about to change. Set to true to prevent the + /// change. + /// + public event EventHandler>? ValueChanging; + + /// + /// Raised when the value has changed. + /// + public event EventHandler>? ValueChanged; + private string _format = "{0}"; /// @@ -191,30 +203,47 @@ public class NumericUpDown : View where T : notnull } _format = value; + + FormatChanged?.Invoke (this, new (value)); SetText (); } } + /// + /// Raised when has changed. + /// + public event EventHandler>? FormatChanged; + private void SetText () { _number.Text = string.Format (Format, _value); Text = _number.Text; } - /// - /// Raised when the value is about to change. Set to true to prevent the - /// change. - /// - public event EventHandler>? ValueChanging; - - /// - /// Raised when the value has changed. - /// - public event EventHandler>? ValueChanged; + private T _increment; /// /// - public T Increment { get; set; } + public T Increment + { + get => _increment; + set + { + if (_increment == (dynamic)value) + { + return; + } + + _increment = value; + + IncrementChanged?.Invoke (this, new (value)); + } + } + + /// + /// Raised when has changed. + /// + public event EventHandler>? IncrementChanged; } /// diff --git a/UICatalog/Scenarios/Buttons.cs b/UICatalog/Scenarios/Buttons.cs index 64da37ca2..8edcdf42b 100644 --- a/UICatalog/Scenarios/Buttons.cs +++ b/UICatalog/Scenarios/Buttons.cs @@ -388,16 +388,16 @@ public class Buttons : Scenario enableCB.Toggle += (s, e) => { repeatButton.Enabled = !repeatButton.Enabled; }; main.Add (label, repeatButton, enableCB); - //var decNumericUpDown = new NumericUpDown - //{ - // Value = 42.11m, - // Increment = 11.31m, - // Format = "{0:0%}", - // X = 0, - // Y = Pos.Bottom (enableCB) + 1, - //}; + var decNumericUpDown = new NumericUpDown + { + Value = 911, + Increment = 1, + Format = "{0:X}", + X = 0, + Y = Pos.Bottom (enableCB) + 1, + }; - //main.Add (decNumericUpDown); + main.Add (decNumericUpDown); main.Ready += (s, e) => { diff --git a/UICatalog/Scenarios/NumericUpDownDemo.cs b/UICatalog/Scenarios/NumericUpDownDemo.cs new file mode 100644 index 000000000..b514a041a --- /dev/null +++ b/UICatalog/Scenarios/NumericUpDownDemo.cs @@ -0,0 +1,291 @@ +#nullable enable +using System; +using Terminal.Gui; + +namespace UICatalog.Scenarios; + +[ScenarioMetadata ("NumericUpDown", "Demonstrates the NumericUpDown View")] +[ScenarioCategory ("Controls")] +public class NumericUpDownDemo : Scenario +{ + public override void Main () + { + Application.Init (); + + Window app = new () + { + Title = GetQuitKeyAndName (), + TabStop = TabBehavior.TabGroup + }; + + var editor = new AdornmentsEditor + { + X = 0, + Y = 0, + AutoSelectViewToEdit = true, + TabStop = TabBehavior.NoStop + }; + app.Add (editor); + + NumericUpDownEditor intEditor = new () + { + X = Pos.Right (editor), + Y = 0, + Title = "int", + }; + + app.Add (intEditor); + + NumericUpDownEditor floatEditor = new () + { + X = Pos.Right (intEditor), + Y = 0, + Title = "float", + }; + app.Add (floatEditor); + + app.Initialized += AppInitialized; + + void AppInitialized (object? sender, EventArgs e) + { + floatEditor!.NumericUpDown!.Increment = 0.1F; + floatEditor!.NumericUpDown!.Format = "{0:0.0}"; + + } + + Application.Run (app); + app.Dispose (); + Application.Shutdown (); + + } + +} + +internal class NumericUpDownEditor : View where T : notnull +{ + private NumericUpDown? _numericUpDown; + + internal NumericUpDown? NumericUpDown + { + get => _numericUpDown; + set + { + if (value == _numericUpDown) + { + return; + } + _numericUpDown = value; + + if (_numericUpDown is { } && _value is { }) + { + _value.Text = _numericUpDown.Text; + } + } + } + + private TextField? _value; + private TextField? _format; + private TextField? _increment; + + internal NumericUpDownEditor () + { + _numericUpDown = null; + Title = "NumericUpDownEditor"; + BorderStyle = LineStyle.Single; + Width = Dim.Auto (DimAutoStyle.Content); + Height = Dim.Auto (DimAutoStyle.Content); + TabStop = TabBehavior.TabGroup; + + Initialized += NumericUpDownEditorInitialized; + + return; + + void NumericUpDownEditorInitialized (object? sender, EventArgs e) + { + Label label = new () + { + Title = "_Value: ", + Width = 12, + }; + label.TextFormatter.Alignment = Alignment.End; + _value = new () + { + X = Pos.Right (label), + Y = Pos.Top (label), + Width = 8, + Title = "Value", + }; + _value.Accept += ValuedOnAccept; + + void ValuedOnAccept (object? sender, EventArgs e) + { + if (_numericUpDown is null) + { + return; + } + + try + { + if (string.IsNullOrEmpty (_value.Text)) + { + // Handle empty or null text if needed + _numericUpDown.Value = default!; + } + else + { + // Parse _value.Text and then convert to type T + _numericUpDown.Value = (T)Convert.ChangeType (_value.Text, typeof (T)); + } + + _value.ColorScheme = SuperView.ColorScheme; + + } + catch (System.FormatException) + { + _value.ColorScheme = Colors.ColorSchemes ["Error"]; + } + catch (InvalidCastException) + { + _value.ColorScheme = Colors.ColorSchemes ["Error"]; + } + finally + { + } + + } + Add (label, _value); + + label = new () + { + Y = Pos.Bottom (_value), + Width = 12, + Title = "_Format: ", + }; + label.TextFormatter.Alignment = Alignment.End; + + _format = new () + { + X = Pos.Right (label), + Y = Pos.Top (label), + Title = "Format", + Width = Dim.Width (_value), + }; + _format.Accept += FormatOnAccept; + + void FormatOnAccept (object? o, EventArgs eventArgs) + { + if (_numericUpDown is null) + { + return; + } + + try + { + // Test format to ensure it's valid + _ = string.Format (_format.Text, _value); + _numericUpDown.Format = _format.Text; + + _format.ColorScheme = SuperView.ColorScheme; + + } + catch (System.FormatException) + { + _format.ColorScheme = Colors.ColorSchemes ["Error"]; + } + catch (InvalidCastException) + { + _format.ColorScheme = Colors.ColorSchemes ["Error"]; + } + finally + { + } + } + + Add (label, _format); + + label = new () + { + Y = Pos.Bottom (_format), + Width = 12, + Title = "_Increment: ", + }; + label.TextFormatter.Alignment = Alignment.End; + _increment = new () + { + X = Pos.Right (label), + Y = Pos.Top (label), + Title = "Increment", + Width = Dim.Width (_value), + }; + + _increment.Accept += IncrementOnAccept; + + void IncrementOnAccept (object? o, EventArgs eventArgs) + { + if (_numericUpDown is null) + { + return; + } + + try + { + if (string.IsNullOrEmpty (_value.Text)) + { + // Handle empty or null text if needed + _numericUpDown.Increment = default!; + } + else + { + // Parse _value.Text and then convert to type T + _numericUpDown.Increment = (T)Convert.ChangeType (_increment.Text, typeof (T)); + } + + _increment.ColorScheme = SuperView.ColorScheme; + + } + catch (System.FormatException) + { + _increment.ColorScheme = Colors.ColorSchemes ["Error"]; + } + catch (InvalidCastException) + { + _increment.ColorScheme = Colors.ColorSchemes ["Error"]; + } + finally + { + } + } + + Add (label, _increment); + + _numericUpDown = new () + { + X = Pos.Center (), + Y = Pos.Bottom (_increment) + 1, + Increment = (dynamic)1, + }; + + _numericUpDown.ValueChanged += NumericUpDownOnValueChanged; + + void NumericUpDownOnValueChanged (object? o, EventArgs eventArgs) + { + _value.Text = _numericUpDown.Text; + } + + _numericUpDown.IncrementChanged += NumericUpDownOnIncrementChanged; + + void NumericUpDownOnIncrementChanged (object? o, EventArgs eventArgs) + { + _increment.Text = _numericUpDown.Increment.ToString (); + } + + Add (_numericUpDown); + + _value.Text = _numericUpDown.Text; + _format.Text = _numericUpDown.Format; + _increment.Text = _numericUpDown.Increment.ToString (); + } + } + + +} diff --git a/UnitTests/Views/NumericUpDownTests.cs b/UnitTests/Views/NumericUpDownTests.cs index 3f9ab4051..103371f19 100644 --- a/UnitTests/Views/NumericUpDownTests.cs +++ b/UnitTests/Views/NumericUpDownTests.cs @@ -1,3 +1,4 @@ +using System.Globalization; using Xunit.Abstractions; namespace Terminal.Gui.ViewsTests; @@ -184,12 +185,39 @@ public class NumericUpDownTests (ITestOutputHelper _output) [InlineData (.75F, "{0:0%}", "75%")] public void Format_decimal (float value, string format, string expectedText) { + CultureInfo currentCulture = CultureInfo.CurrentCulture; + CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; + NumericUpDown numericUpDown = new NumericUpDown (); numericUpDown.Format = format; numericUpDown.Value = value; Assert.Equal (expectedText, numericUpDown.Text); + + CultureInfo.CurrentCulture = currentCulture; + } + + [Theory] + [InlineData (0, "{0}", "0")] + [InlineData (11, "{0}", "11")] + [InlineData (-1, "{0}", "-1")] + [InlineData (911, "{0:X}", "38F")] + [InlineData (911, "0x{0:X04}", "0x038F")] + + public void Format_int (int value, string format, string expectedText) + { + CultureInfo currentCulture = CultureInfo.CurrentCulture; + CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; + + NumericUpDown numericUpDown = new NumericUpDown (); + + numericUpDown.Format = format; + numericUpDown.Value = value; + + Assert.Equal (expectedText, numericUpDown.Text); + + CultureInfo.CurrentCulture = currentCulture; } [Fact] @@ -211,4 +239,5 @@ public class NumericUpDownTests (ITestOutputHelper _output) Assert.Equal (-1, numericUpDown.Value); } + } From b6db4a327c4dd060a12bbedd57a434a016f95fb0 Mon Sep 17 00:00:00 2001 From: Tig Date: Mon, 5 Aug 2024 17:48:14 -0600 Subject: [PATCH 05/13] Fixed warning --- Terminal.Gui/Views/NumericUpDown.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Terminal.Gui/Views/NumericUpDown.cs b/Terminal.Gui/Views/NumericUpDown.cs index c36534172..d704c213e 100644 --- a/Terminal.Gui/Views/NumericUpDown.cs +++ b/Terminal.Gui/Views/NumericUpDown.cs @@ -147,8 +147,7 @@ public class NumericUpDown : View where T : notnull /// /// and events are raised when the value changes. /// The event can be canceled the change setting - /// to - /// . + /// .Cancel to . /// /// public T Value @@ -177,7 +176,7 @@ public class NumericUpDown : View where T : notnull } /// - /// Raised when the value is about to change. Set to true to prevent the + /// Raised when the value is about to change. Set .Cancel to true to prevent the /// change. /// public event EventHandler>? ValueChanging; @@ -229,7 +228,7 @@ public class NumericUpDown : View where T : notnull get => _increment; set { - if (_increment == (dynamic)value) + if ((dynamic)_increment == (dynamic)value) { return; } From 5dd3db92cb364c756d3af920ee8998ec6c260d71 Mon Sep 17 00:00:00 2001 From: Tig Date: Mon, 5 Aug 2024 17:49:48 -0600 Subject: [PATCH 06/13] Fixed linux/mac failure --- Terminal.Gui/Views/NumericUpDown.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Terminal.Gui/Views/NumericUpDown.cs b/Terminal.Gui/Views/NumericUpDown.cs index d704c213e..279cfd6cf 100644 --- a/Terminal.Gui/Views/NumericUpDown.cs +++ b/Terminal.Gui/Views/NumericUpDown.cs @@ -37,11 +37,10 @@ public class NumericUpDown : View where T : notnull throw new InvalidOperationException ("T must be a numeric type that supports addition and subtraction."); } - Increment = (dynamic)1; - // `object` is supported only for AllViewsTester if (type != typeof (object)) { + Increment = (dynamic)1; Value = (dynamic)0; } From 12df9beebe0275e02a027872396f913131b72486 Mon Sep 17 00:00:00 2001 From: Tig Date: Mon, 5 Aug 2024 18:03:08 -0600 Subject: [PATCH 07/13] Fixed linux/mac test failure --- UnitTests/Views/NumericUpDownTests.cs | 37 ++++++++++++--------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/UnitTests/Views/NumericUpDownTests.cs b/UnitTests/Views/NumericUpDownTests.cs index 103371f19..916053001 100644 --- a/UnitTests/Views/NumericUpDownTests.cs +++ b/UnitTests/Views/NumericUpDownTests.cs @@ -53,7 +53,7 @@ public class NumericUpDownTests (ITestOutputHelper _output) [Fact] public void WhenCreatedWithCustomValues_ShouldHaveCustomValues_int () { - NumericUpDown numericUpDown = new NumericUpDown + NumericUpDown numericUpDown = new() { Value = 10, Increment = 2 @@ -66,7 +66,7 @@ public class NumericUpDownTests (ITestOutputHelper _output) [Fact] public void WhenCreatedWithCustomValues_ShouldHaveCustomValues_float () { - NumericUpDown numericUpDown = new NumericUpDown + NumericUpDown numericUpDown = new() { Value = 10.5F, Increment = 2.5F @@ -79,7 +79,7 @@ public class NumericUpDownTests (ITestOutputHelper _output) [Fact] public void WhenCreatedWithCustomValues_ShouldHaveCustomValues_decimal () { - NumericUpDown numericUpDown = new NumericUpDown + NumericUpDown numericUpDown = new () { Value = 10.5m, Increment = 2.5m @@ -98,16 +98,13 @@ public class NumericUpDownTests (ITestOutputHelper _output) [Fact] public void WhenCreatedWithInvalidTypeObject_ShouldNotThrowInvalidOperationException () { - NumericUpDown numericUpDown = new NumericUpDown (); - - Assert.Null (numericUpDown.Value); - Assert.Equal (1, numericUpDown.Increment); + NumericUpDown numericUpDown = new (); } [Fact] public void WhenCreated_ShouldHaveDefaultWidthAndHeight_int () { - NumericUpDown numericUpDown = new NumericUpDown (); + NumericUpDown numericUpDown = new (); numericUpDown.SetRelativeLayout (Application.Screen.Size); Assert.Equal (3, numericUpDown.Frame.Width); @@ -117,7 +114,7 @@ public class NumericUpDownTests (ITestOutputHelper _output) [Fact] public void WhenCreated_ShouldHaveDefaultWidthAndHeight_float () { - NumericUpDown numericUpDown = new NumericUpDown (); + NumericUpDown numericUpDown = new (); numericUpDown.SetRelativeLayout (Application.Screen.Size); Assert.Equal (3, numericUpDown.Frame.Width); @@ -127,7 +124,7 @@ public class NumericUpDownTests (ITestOutputHelper _output) [Fact] public void WhenCreated_ShouldHaveDefaultWidthAndHeight_double () { - NumericUpDown numericUpDown = new NumericUpDown (); + NumericUpDown numericUpDown = new (); numericUpDown.SetRelativeLayout (Application.Screen.Size); Assert.Equal (3, numericUpDown.Frame.Width); @@ -137,7 +134,7 @@ public class NumericUpDownTests (ITestOutputHelper _output) [Fact] public void WhenCreated_ShouldHaveDefaultWidthAndHeight_long () { - NumericUpDown numericUpDown = new NumericUpDown (); + NumericUpDown numericUpDown = new (); numericUpDown.SetRelativeLayout (Application.Screen.Size); Assert.Equal (3, numericUpDown.Frame.Width); @@ -147,7 +144,7 @@ public class NumericUpDownTests (ITestOutputHelper _output) [Fact] public void WhenCreated_ShouldHaveDefaultWidthAndHeight_decimal () { - NumericUpDown numericUpDown = new NumericUpDown (); + NumericUpDown numericUpDown = new (); numericUpDown.SetRelativeLayout (Application.Screen.Size); Assert.Equal (3, numericUpDown.Frame.Width); @@ -157,7 +154,7 @@ public class NumericUpDownTests (ITestOutputHelper _output) [Fact] public void WhenCreated_Text_Should_Be_Correct_int () { - NumericUpDown numericUpDown = new NumericUpDown (); + NumericUpDown numericUpDown = new (); Assert.Equal ("0", numericUpDown.Text); } @@ -165,7 +162,7 @@ public class NumericUpDownTests (ITestOutputHelper _output) [Fact] public void WhenCreated_Text_Should_Be_Correct_float () { - NumericUpDown numericUpDown = new NumericUpDown (); + NumericUpDown numericUpDown = new (); Assert.Equal ("0", numericUpDown.Text); } @@ -173,7 +170,7 @@ public class NumericUpDownTests (ITestOutputHelper _output) [Fact] public void Format_Default () { - NumericUpDown numericUpDown = new NumericUpDown (); + NumericUpDown numericUpDown = new (); Assert.Equal ("{0}", numericUpDown.Format); } @@ -188,7 +185,7 @@ public class NumericUpDownTests (ITestOutputHelper _output) CultureInfo currentCulture = CultureInfo.CurrentCulture; CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; - NumericUpDown numericUpDown = new NumericUpDown (); + NumericUpDown numericUpDown = new (); numericUpDown.Format = format; numericUpDown.Value = value; @@ -204,13 +201,12 @@ public class NumericUpDownTests (ITestOutputHelper _output) [InlineData (-1, "{0}", "-1")] [InlineData (911, "{0:X}", "38F")] [InlineData (911, "0x{0:X04}", "0x038F")] - public void Format_int (int value, string format, string expectedText) { CultureInfo currentCulture = CultureInfo.CurrentCulture; CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; - NumericUpDown numericUpDown = new NumericUpDown (); + NumericUpDown numericUpDown = new (); numericUpDown.Format = format; numericUpDown.Value = value; @@ -223,7 +219,7 @@ public class NumericUpDownTests (ITestOutputHelper _output) [Fact] public void KeDown_CursorUp_Increments () { - NumericUpDown numericUpDown = new NumericUpDown (); + NumericUpDown numericUpDown = new (); numericUpDown.NewKeyDownEvent (Key.CursorUp); @@ -233,11 +229,10 @@ public class NumericUpDownTests (ITestOutputHelper _output) [Fact] public void KeyDown_CursorDown_Decrements () { - NumericUpDown numericUpDown = new NumericUpDown (); + NumericUpDown numericUpDown = new (); numericUpDown.NewKeyDownEvent (Key.CursorDown); Assert.Equal (-1, numericUpDown.Value); } - } From 0bd50c5b93c8b47bfff6419c75b75bc139b5bc87 Mon Sep 17 00:00:00 2001 From: Tig Date: Tue, 6 Aug 2024 08:39:55 -0600 Subject: [PATCH 08/13] Fixes #3641. `CheckBox.State` -> `CheckBox.CheckState` (#3648) * State->CheckState. Toggled->CheckStateChanging. * Code cleanup & doc fix * Updated migration guide * Updated migration guide --- Terminal.Gui/Views/CheckBox.cs | 64 +++++++++++-------- UICatalog/Scenarios/AdornmentsEditor.cs | 8 +-- UICatalog/Scenarios/BorderEditor.cs | 12 ++-- UICatalog/Scenarios/Buttons.cs | 4 +- UICatalog/Scenarios/ContentScrolling.cs | 24 +++---- UICatalog/Scenarios/Dialogs.cs | 6 +- UICatalog/Scenarios/DynamicMenuBar.cs | 60 ++++++++--------- UICatalog/Scenarios/Editor.cs | 16 ++--- UICatalog/Scenarios/FileDialogExamples.cs | 32 +++++----- UICatalog/Scenarios/GraphViewExample.cs | 2 +- UICatalog/Scenarios/Images.cs | 6 +- UICatalog/Scenarios/ListViewWithSelection.cs | 12 ++-- UICatalog/Scenarios/Localization.cs | 4 +- UICatalog/Scenarios/MessageBoxes.cs | 6 +- UICatalog/Scenarios/Mouse.cs | 6 +- UICatalog/Scenarios/PosAlignDemo.cs | 20 +++--- UICatalog/Scenarios/ProgressBarStyles.cs | 6 +- UICatalog/Scenarios/Scrolling.cs | 28 ++++---- UICatalog/Scenarios/SendKeys.cs | 6 +- UICatalog/Scenarios/Shortcuts.cs | 4 +- UICatalog/Scenarios/Sliders.cs | 2 +- UICatalog/Scenarios/SpinnerStyles.cs | 20 +++--- UICatalog/Scenarios/Text.cs | 20 +++--- .../Scenarios/TextAlignmentAndDirection.cs | 8 +-- UICatalog/Scenarios/TextEffectsScenario.cs | 2 +- UICatalog/Scenarios/TextFormatterDemo.cs | 4 +- UICatalog/Scenarios/TileViewNesting.cs | 26 ++++---- UICatalog/Scenarios/TrueColors.cs | 6 +- UICatalog/Scenarios/Wizards.cs | 14 ++-- UICatalog/UICatalog.cs | 6 +- UnitTests/Views/CheckBoxTests.cs | 64 +++++++++---------- docfx/docs/migratingfromv1.md | 30 +++++++++ 32 files changed, 283 insertions(+), 245 deletions(-) diff --git a/Terminal.Gui/Views/CheckBox.cs b/Terminal.Gui/Views/CheckBox.cs index c43000953..d806e7abb 100644 --- a/Terminal.Gui/Views/CheckBox.cs +++ b/Terminal.Gui/Views/CheckBox.cs @@ -1,12 +1,9 @@ #nullable enable namespace Terminal.Gui; -/// Shows a check box that can be toggled. +/// Shows a check box that can be cycled between three states. public class CheckBox : View { - private bool _allowNone; - private CheckState _checked = CheckState.UnChecked; - /// /// Initializes a new instance of . /// @@ -18,8 +15,8 @@ public class CheckBox : View CanFocus = true; // Things this view knows how to do - AddCommand (Command.Accept, OnToggle); - AddCommand (Command.HotKey, OnToggle); + AddCommand (Command.Accept, AdvanceCheckState); + AddCommand (Command.HotKey, AdvanceCheckState); // Default keybindings for this view KeyBindings.Add (Key.Space, Command.Accept); @@ -32,7 +29,7 @@ public class CheckBox : View private void CheckBox_MouseClick (object? sender, MouseEventEventArgs e) { - e.Handled = OnToggle () == true; + e.Handled = AdvanceCheckState () == true; } private void Checkbox_TitleChanged (object? sender, EventArgs e) @@ -55,8 +52,10 @@ public class CheckBox : View set => TextFormatter.HotKeySpecifier = base.HotKeySpecifier = value; } + private bool _allowNone = false; + /// - /// If allows to be . + /// If allows to be . The default is . /// public bool AllowCheckStateNone { @@ -69,13 +68,15 @@ public class CheckBox : View } _allowNone = value; - if (State == CheckState.None) + if (CheckedState == CheckState.None) { - State = CheckState.UnChecked; + CheckedState = CheckState.UnChecked; } } } + private CheckState _checkedState = CheckState.UnChecked; + /// /// The state of the . /// @@ -93,35 +94,42 @@ public class CheckBox : View /// will display the ConfigurationManager.Glyphs.CheckStateChecked character (☑). /// /// - public CheckState State + public CheckState CheckedState { - get => _checked; + get => _checkedState; set { - if (_checked == value || (value is CheckState.None && !AllowCheckStateNone)) + if (_checkedState == value || (value is CheckState.None && !AllowCheckStateNone)) { return; } - _checked = value; + _checkedState = value; UpdateTextFormatterText (); OnResizeNeeded (); } } - /// Called when the property changes. Invokes the cancelable event. + /// + /// Advances to the next value. Invokes the cancelable event. + /// /// /// - /// If the event was canceled. + /// If the event was canceled. /// - /// Toggling cycles through the states , , and . + /// + /// Cycles through the states , , and . + /// + /// + /// If the event is not canceled, the will be updated and the event will be raised. + /// /// - public bool? OnToggle () + public bool? AdvanceCheckState () { - CheckState oldValue = State; - CancelEventArgs e = new (ref _checked, ref oldValue); + CheckState oldValue = CheckedState; + CancelEventArgs e = new (in _checkedState, ref oldValue); - switch (State) + switch (CheckedState) { case CheckState.None: e.NewValue = CheckState.Checked; @@ -144,35 +152,35 @@ public class CheckBox : View break; } - Toggle?.Invoke (this, e); + CheckedStateChanging?.Invoke (this, e); if (e.Cancel) { return e.Cancel; } - // By default, Command.Accept calls OnAccept, so we need to call it here to ensure that the event is fired. + // By default, Command.Accept calls OnAccept, so we need to call it here to ensure that the Accept event is fired. if (OnAccept () == true) { return true; } - State = e.NewValue; + CheckedState = e.NewValue; return true; } - /// Toggle event, raised when the is toggled. + /// Raised when the state is changing. /// /// /// This event can be cancelled. If cancelled, the will not change its state. /// /// - public event EventHandler>? Toggle; + public event EventHandler>? CheckedStateChanging; /// protected override void UpdateTextFormatterText () { - base.UpdateTextFormatterText(); + base.UpdateTextFormatterText (); switch (TextAlignment) { case Alignment.Start: @@ -190,7 +198,7 @@ public class CheckBox : View private Rune GetCheckedGlyph () { - return State switch + return CheckedState switch { CheckState.Checked => Glyphs.CheckStateChecked, CheckState.UnChecked => Glyphs.CheckStateUnChecked, diff --git a/UICatalog/Scenarios/AdornmentsEditor.cs b/UICatalog/Scenarios/AdornmentsEditor.cs index 2f389552a..59e283b97 100644 --- a/UICatalog/Scenarios/AdornmentsEditor.cs +++ b/UICatalog/Scenarios/AdornmentsEditor.cs @@ -120,9 +120,9 @@ public class AdornmentsEditor : View Add (_paddingEditor); _diagPaddingCheckBox = new () { Text = "_Diagnostic Padding" }; - _diagPaddingCheckBox.State = Diagnostics.FastHasFlags (ViewDiagnosticFlags.Padding) ? CheckState.Checked : CheckState.UnChecked; + _diagPaddingCheckBox.CheckedState = Diagnostics.FastHasFlags (ViewDiagnosticFlags.Padding) ? CheckState.Checked : CheckState.UnChecked; - _diagPaddingCheckBox.Toggle += (s, e) => + _diagPaddingCheckBox.CheckedStateChanging += (s, e) => { if (e.NewValue == CheckState.Checked) { @@ -138,9 +138,9 @@ public class AdornmentsEditor : View _diagPaddingCheckBox.Y = Pos.Bottom (_paddingEditor); _diagRulerCheckBox = new () { Text = "_Diagnostic Ruler" }; - _diagRulerCheckBox.State = Diagnostics.FastHasFlags (ViewDiagnosticFlags.Ruler) ? CheckState.Checked : CheckState.UnChecked; + _diagRulerCheckBox.CheckedState = Diagnostics.FastHasFlags (ViewDiagnosticFlags.Ruler) ? CheckState.Checked : CheckState.UnChecked; - _diagRulerCheckBox.Toggle += (s, e) => + _diagRulerCheckBox.CheckedStateChanging += (s, e) => { if (e.NewValue == CheckState.Checked) { diff --git a/UICatalog/Scenarios/BorderEditor.cs b/UICatalog/Scenarios/BorderEditor.cs index c2bf93570..ce5df6dce 100644 --- a/UICatalog/Scenarios/BorderEditor.cs +++ b/UICatalog/Scenarios/BorderEditor.cs @@ -20,9 +20,9 @@ public class BorderEditor : AdornmentEditor private void BorderEditor_AdornmentChanged (object sender, EventArgs e) { - _ckbTitle.State = ((Border)AdornmentToEdit).Settings.FastHasFlags (BorderSettings.Title) ? CheckState.Checked : CheckState.UnChecked; + _ckbTitle.CheckedState = ((Border)AdornmentToEdit).Settings.FastHasFlags (BorderSettings.Title) ? CheckState.Checked : CheckState.UnChecked; _rbBorderStyle.SelectedItem = (int)((Border)AdornmentToEdit).LineStyle; - _ckbGradient.State = ((Border)AdornmentToEdit).Settings.FastHasFlags (BorderSettings.Gradient) ? CheckState.Checked : CheckState.UnChecked; + _ckbGradient.CheckedState = ((Border)AdornmentToEdit).Settings.FastHasFlags (BorderSettings.Gradient) ? CheckState.Checked : CheckState.UnChecked; } private void BorderEditor_Initialized (object sender, EventArgs e) @@ -51,13 +51,13 @@ public class BorderEditor : AdornmentEditor X = 0, Y = Pos.Bottom (_rbBorderStyle), - State = CheckState.Checked, + CheckedState = CheckState.Checked, SuperViewRendersLineCanvas = true, Text = "Title", Enabled = AdornmentToEdit is { } }; - _ckbTitle.Toggle += OnCkbTitleOnToggle; + _ckbTitle.CheckedStateChanging += OnCkbTitleOnToggle; Add (_ckbTitle); _ckbGradient = new () @@ -65,13 +65,13 @@ public class BorderEditor : AdornmentEditor X = 0, Y = Pos.Bottom (_ckbTitle), - State = CheckState.Checked, + CheckedState = CheckState.Checked, SuperViewRendersLineCanvas = true, Text = "Gradient", Enabled = AdornmentToEdit is { } }; - _ckbGradient.Toggle += OnCkbGradientOnToggle; + _ckbGradient.CheckedStateChanging += OnCkbGradientOnToggle; Add (_ckbGradient); return; diff --git a/UICatalog/Scenarios/Buttons.cs b/UICatalog/Scenarios/Buttons.cs index 8edcdf42b..5c8e0865c 100644 --- a/UICatalog/Scenarios/Buttons.cs +++ b/UICatalog/Scenarios/Buttons.cs @@ -383,9 +383,9 @@ public class Buttons : Scenario X = Pos.Right (repeatButton) + 1, Y = Pos.Top (repeatButton), Title = "Enabled", - State = CheckState.Checked + CheckedState = CheckState.Checked }; - enableCB.Toggle += (s, e) => { repeatButton.Enabled = !repeatButton.Enabled; }; + enableCB.CheckedStateChanging += (s, e) => { repeatButton.Enabled = !repeatButton.Enabled; }; main.Add (label, repeatButton, enableCB); var decNumericUpDown = new NumericUpDown diff --git a/UICatalog/Scenarios/ContentScrolling.cs b/UICatalog/Scenarios/ContentScrolling.cs index 9e4416658..57589459a 100644 --- a/UICatalog/Scenarios/ContentScrolling.cs +++ b/UICatalog/Scenarios/ContentScrolling.cs @@ -135,8 +135,8 @@ public class ContentScrolling : Scenario Y = 0, CanFocus = false }; - cbAllowNegativeX.State = view.ViewportSettings.HasFlag(ViewportSettings.AllowNegativeX) ? CheckState.Checked : CheckState.UnChecked; - cbAllowNegativeX.Toggle += AllowNegativeX_Toggle; + cbAllowNegativeX.CheckedState = view.ViewportSettings.HasFlag(ViewportSettings.AllowNegativeX) ? CheckState.Checked : CheckState.UnChecked; + cbAllowNegativeX.CheckedStateChanging += AllowNegativeX_Toggle; void AllowNegativeX_Toggle (object sender, CancelEventArgs e) { @@ -159,8 +159,8 @@ public class ContentScrolling : Scenario Y = 0, CanFocus = false }; - cbAllowNegativeY.State = view.ViewportSettings.HasFlag(ViewportSettings.AllowNegativeY) ? CheckState.Checked : CheckState.UnChecked; - cbAllowNegativeY.Toggle += AllowNegativeY_Toggle; + cbAllowNegativeY.CheckedState = view.ViewportSettings.HasFlag(ViewportSettings.AllowNegativeY) ? CheckState.Checked : CheckState.UnChecked; + cbAllowNegativeY.CheckedStateChanging += AllowNegativeY_Toggle; void AllowNegativeY_Toggle (object sender, CancelEventArgs e) { @@ -182,8 +182,8 @@ public class ContentScrolling : Scenario Y = Pos.Bottom (cbAllowNegativeX), CanFocus = false }; - cbAllowXGreaterThanContentWidth.State = view.ViewportSettings.HasFlag(ViewportSettings.AllowXGreaterThanContentWidth) ? CheckState.Checked : CheckState.UnChecked; - cbAllowXGreaterThanContentWidth.Toggle += AllowXGreaterThanContentWidth_Toggle; + cbAllowXGreaterThanContentWidth.CheckedState = view.ViewportSettings.HasFlag(ViewportSettings.AllowXGreaterThanContentWidth) ? CheckState.Checked : CheckState.UnChecked; + cbAllowXGreaterThanContentWidth.CheckedStateChanging += AllowXGreaterThanContentWidth_Toggle; void AllowXGreaterThanContentWidth_Toggle (object sender, CancelEventArgs e) { @@ -206,8 +206,8 @@ public class ContentScrolling : Scenario Y = Pos.Bottom (cbAllowNegativeX), CanFocus = false }; - cbAllowYGreaterThanContentHeight.State = view.ViewportSettings.HasFlag(ViewportSettings.AllowYGreaterThanContentHeight) ? CheckState.Checked : CheckState.UnChecked; - cbAllowYGreaterThanContentHeight.Toggle += AllowYGreaterThanContentHeight_Toggle; + cbAllowYGreaterThanContentHeight.CheckedState = view.ViewportSettings.HasFlag(ViewportSettings.AllowYGreaterThanContentHeight) ? CheckState.Checked : CheckState.UnChecked; + cbAllowYGreaterThanContentHeight.CheckedStateChanging += AllowYGreaterThanContentHeight_Toggle; void AllowYGreaterThanContentHeight_Toggle (object sender, CancelEventArgs e) { @@ -284,8 +284,8 @@ public class ContentScrolling : Scenario Y = Pos.Top (labelContentSize), CanFocus = false }; - cbClearOnlyVisible.State = view.ViewportSettings.HasFlag(ViewportSettings.ClearContentOnly) ? CheckState.Checked : CheckState.UnChecked; - cbClearOnlyVisible.Toggle += ClearVisibleContentOnly_Toggle; + cbClearOnlyVisible.CheckedState = view.ViewportSettings.HasFlag(ViewportSettings.ClearContentOnly) ? CheckState.Checked : CheckState.UnChecked; + cbClearOnlyVisible.CheckedStateChanging += ClearVisibleContentOnly_Toggle; void ClearVisibleContentOnly_Toggle (object sender, CancelEventArgs e) { @@ -306,8 +306,8 @@ public class ContentScrolling : Scenario Y = Pos.Top (labelContentSize), CanFocus = false }; - cbDoNotClipContent.State = view.ViewportSettings.HasFlag (ViewportSettings.ClipContentOnly) ? CheckState.Checked : CheckState.UnChecked; - cbDoNotClipContent.Toggle += ClipVisibleContentOnly_Toggle; + cbDoNotClipContent.CheckedState = view.ViewportSettings.HasFlag (ViewportSettings.ClipContentOnly) ? CheckState.Checked : CheckState.UnChecked; + cbDoNotClipContent.CheckedStateChanging += ClipVisibleContentOnly_Toggle; void ClipVisibleContentOnly_Toggle (object sender, CancelEventArgs e) { diff --git a/UICatalog/Scenarios/Dialogs.cs b/UICatalog/Scenarios/Dialogs.cs index 096cc1ec4..cba52dbb1 100644 --- a/UICatalog/Scenarios/Dialogs.cs +++ b/UICatalog/Scenarios/Dialogs.cs @@ -136,7 +136,7 @@ public class Dialogs : Scenario Y = Pos.Bottom (numButtonsLabel), TextAlignment = Alignment.End, Text = $"_Add {char.ConvertFromUtf32 (CODE_POINT)} to button text to stress wide char support", - State = CheckState.UnChecked + CheckedState = CheckState.UnChecked }; frame.Add (glyphsNotWords); @@ -235,7 +235,7 @@ public class Dialogs : Scenario int buttonId = i; Button button = null; - if (glyphsNotWords.State == CheckState.Checked) + if (glyphsNotWords.CheckedState == CheckState.Checked) { buttonId = i; @@ -289,7 +289,7 @@ public class Dialogs : Scenario int buttonId = buttons.Count; Button button; - if (glyphsNotWords.State == CheckState.Checked) + if (glyphsNotWords.CheckedState == CheckState.Checked) { button = new () { diff --git a/UICatalog/Scenarios/DynamicMenuBar.cs b/UICatalog/Scenarios/DynamicMenuBar.cs index 4d39958a6..79af23d23 100644 --- a/UICatalog/Scenarios/DynamicMenuBar.cs +++ b/UICatalog/Scenarios/DynamicMenuBar.cs @@ -142,7 +142,7 @@ public class DynamicMenuBar : Scenario { X = Pos.Left (_lblTitle), Y = Pos.Bottom (CkbIsTopLevel), - State = (_menuItem == null ? !_hasParent : HasSubMenus (_menuItem)) ? CheckState.Checked : CheckState.UnChecked, + CheckedState = (_menuItem == null ? !_hasParent : HasSubMenus (_menuItem)) ? CheckState.Checked : CheckState.UnChecked, Text = "Has sub-menus" }; Add (CkbSubMenu); @@ -249,36 +249,36 @@ public class DynamicMenuBar : Scenario _btnShortcut.Accept += (s, e) => { TextShortcut.Text = ""; }; Add (_btnShortcut); - CkbIsTopLevel.Toggle += (s, e) => + CkbIsTopLevel.CheckedStateChanging += (s, e) => { - if ((_menuItem != null && _menuItem.Parent != null && CkbIsTopLevel.State == CheckState.Checked) - || (_menuItem == null && _hasParent && CkbIsTopLevel.State == CheckState.Checked)) + if ((_menuItem != null && _menuItem.Parent != null && CkbIsTopLevel.CheckedState == CheckState.Checked) + || (_menuItem == null && _hasParent && CkbIsTopLevel.CheckedState == CheckState.Checked)) { MessageBox.ErrorQuery ( "Invalid IsTopLevel", "Only menu bar can have top level menu item!", "Ok" ); - CkbIsTopLevel.State = CheckState.UnChecked; + CkbIsTopLevel.CheckedState = CheckState.UnChecked; return; } - if (CkbIsTopLevel.State == CheckState.Checked) + if (CkbIsTopLevel.CheckedState == CheckState.Checked) { - CkbSubMenu.State = CheckState.UnChecked; + CkbSubMenu.CheckedState = CheckState.UnChecked; CkbSubMenu.SetNeedsDisplay (); TextHelp.Enabled = true; TextAction.Enabled = true; TextShortcut.Enabled = - CkbIsTopLevel.State == CheckState.UnChecked && CkbSubMenu.State == CheckState.UnChecked; + CkbIsTopLevel.CheckedState == CheckState.UnChecked && CkbSubMenu.CheckedState == CheckState.UnChecked; } else { if ((_menuItem == null && !_hasParent) || _menuItem.Parent == null) { - CkbSubMenu.State = CheckState.Checked; + CkbSubMenu.CheckedState = CheckState.Checked; CkbSubMenu.SetNeedsDisplay (); TextShortcut.Enabled = false; } @@ -290,11 +290,11 @@ public class DynamicMenuBar : Scenario } }; - CkbSubMenu.Toggle += (s, e) => + CkbSubMenu.CheckedStateChanging += (s, e) => { if (e.NewValue == CheckState.Checked) { - CkbIsTopLevel.State = CheckState.UnChecked; + CkbIsTopLevel.CheckedState = CheckState.UnChecked; CkbIsTopLevel.SetNeedsDisplay (); TextHelp.Text = ""; TextHelp.Enabled = false; @@ -307,7 +307,7 @@ public class DynamicMenuBar : Scenario { if (!_hasParent) { - CkbIsTopLevel.State = CheckState.Checked; + CkbIsTopLevel.CheckedState = CheckState.Checked; CkbIsTopLevel.SetNeedsDisplay (); TextShortcut.Enabled = false; } @@ -316,11 +316,11 @@ public class DynamicMenuBar : Scenario TextAction.Enabled = true; TextShortcut.Enabled = - CkbIsTopLevel.State == CheckState.UnChecked && CkbSubMenu.State == CheckState.UnChecked; + CkbIsTopLevel.CheckedState == CheckState.UnChecked && CkbSubMenu.CheckedState == CheckState.UnChecked; } }; - CkbNullCheck.Toggle += (s, e) => + CkbNullCheck.CheckedStateChanging += (s, e) => { if (_menuItem != null) { @@ -394,14 +394,14 @@ public class DynamicMenuBar : Scenario TextAction.Text = menuItem != null && menuItem.Action != null ? GetTargetAction (menuItem.Action) : string.Empty; - CkbIsTopLevel.State = IsTopLevel (menuItem) ? CheckState.Checked : CheckState.UnChecked; - CkbSubMenu.State = HasSubMenus (menuItem) ? CheckState.Checked : CheckState.UnChecked; - CkbNullCheck.State = menuItem.AllowNullChecked ? CheckState.Checked : CheckState.UnChecked; - TextHelp.Enabled = CkbSubMenu.State == CheckState.Checked; - TextAction.Enabled = CkbSubMenu.State == CheckState.Checked; + CkbIsTopLevel.CheckedState = IsTopLevel (menuItem) ? CheckState.Checked : CheckState.UnChecked; + CkbSubMenu.CheckedState = HasSubMenus (menuItem) ? CheckState.Checked : CheckState.UnChecked; + CkbNullCheck.CheckedState = menuItem.AllowNullChecked ? CheckState.Checked : CheckState.UnChecked; + TextHelp.Enabled = CkbSubMenu.CheckedState == CheckState.Checked; + TextAction.Enabled = CkbSubMenu.CheckedState == CheckState.Checked; RbChkStyle.SelectedItem = (int)(menuItem?.CheckType ?? MenuItemCheckStyle.NoCheck); TextShortcut.Text = menuItem?.ShortcutTag ?? ""; - TextShortcut.Enabled = CkbIsTopLevel.State == CheckState.UnChecked && CkbSubMenu.State == CheckState.UnChecked; + TextShortcut.Enabled = CkbIsTopLevel.CheckedState == CheckState.UnChecked && CkbSubMenu.CheckedState == CheckState.UnChecked; } public DynamicMenuItem EnterMenuItem () @@ -414,9 +414,9 @@ public class DynamicMenuBar : Scenario TextTitle.Text = m.Title; TextHelp.Text = m.Help; TextAction.Text = m.Action; - CkbIsTopLevel.State = CheckState.UnChecked; - CkbSubMenu.State = !_hasParent ? CheckState.Checked : CheckState.UnChecked; - CkbNullCheck.State = CheckState.UnChecked; + CkbIsTopLevel.CheckedState = CheckState.UnChecked; + CkbSubMenu.CheckedState = !_hasParent ? CheckState.Checked : CheckState.UnChecked; + CkbNullCheck.CheckedState = CheckState.UnChecked; TextHelp.Enabled = _hasParent; TextAction.Enabled = _hasParent; TextShortcut.Enabled = _hasParent; @@ -466,13 +466,13 @@ public class DynamicMenuBar : Scenario Title = TextTitle.Text, Help = TextHelp.Text, Action = TextAction.Text, - IsTopLevel = CkbIsTopLevel?.State == CheckState.Checked, - HasSubMenu = CkbSubMenu?.State == CheckState.UnChecked, + IsTopLevel = CkbIsTopLevel?.CheckedState == CheckState.Checked, + HasSubMenu = CkbSubMenu?.CheckedState == CheckState.UnChecked, CheckStyle = RbChkStyle.SelectedItem == 0 ? MenuItemCheckStyle.NoCheck : RbChkStyle.SelectedItem == 1 ? MenuItemCheckStyle.Checked : MenuItemCheckStyle.Radio, Shortcut = TextShortcut.Text, - AllowNullChecked = CkbNullCheck?.State == CheckState.Checked, + AllowNullChecked = CkbNullCheck?.CheckedState == CheckState.Checked, }; } @@ -515,8 +515,8 @@ public class DynamicMenuBar : Scenario TextTitle.Text = ""; TextHelp.Text = ""; TextAction.Text = ""; - CkbIsTopLevel.State = CheckState.UnChecked; - CkbSubMenu.State = CheckState.UnChecked; + CkbIsTopLevel.CheckedState = CheckState.UnChecked; + CkbSubMenu.CheckedState = CheckState.UnChecked; RbChkStyle.SelectedItem = (int)MenuItemCheckStyle.NoCheck; TextShortcut.Text = ""; } @@ -835,8 +835,8 @@ public class DynamicMenuBar : Scenario Title = _frmMenuDetails.TextTitle.Text, Help = _frmMenuDetails.TextHelp.Text, Action = _frmMenuDetails.TextAction.Text, - IsTopLevel = _frmMenuDetails.CkbIsTopLevel?.State == CheckState.UnChecked, - HasSubMenu = _frmMenuDetails.CkbSubMenu?.State == CheckState.UnChecked, + IsTopLevel = _frmMenuDetails.CkbIsTopLevel?.CheckedState == CheckState.UnChecked, + HasSubMenu = _frmMenuDetails.CkbSubMenu?.CheckedState == CheckState.UnChecked, CheckStyle = _frmMenuDetails.RbChkStyle.SelectedItem == 0 ? MenuItemCheckStyle.NoCheck : _frmMenuDetails.RbChkStyle.SelectedItem == 1 diff --git a/UICatalog/Scenarios/Editor.cs b/UICatalog/Scenarios/Editor.cs index e427f01c6..a1cec8e42 100644 --- a/UICatalog/Scenarios/Editor.cs +++ b/UICatalog/Scenarios/Editor.cs @@ -895,16 +895,16 @@ public class Editor : Scenario var ckbMatchCase = new CheckBox { - X = 0, Y = Pos.Top (txtToFind) + 2, State = _matchCase ? CheckState.Checked : CheckState.UnChecked, Text = "Match c_ase" + X = 0, Y = Pos.Top (txtToFind) + 2, CheckedState = _matchCase ? CheckState.Checked : CheckState.UnChecked, Text = "Match c_ase" }; - ckbMatchCase.Toggle += (s, e) => _matchCase = e.NewValue == CheckState.Checked; + ckbMatchCase.CheckedStateChanging += (s, e) => _matchCase = e.NewValue == CheckState.Checked; d.Add (ckbMatchCase); var ckbMatchWholeWord = new CheckBox { - X = 0, Y = Pos.Top (ckbMatchCase) + 1, State = _matchWholeWord ? CheckState.Checked : CheckState.UnChecked, Text = "Match _whole word" + X = 0, Y = Pos.Top (ckbMatchCase) + 1, CheckedState = _matchWholeWord ? CheckState.Checked : CheckState.UnChecked, Text = "Match _whole word" }; - ckbMatchWholeWord.Toggle += (s, e) => _matchWholeWord = e.NewValue == CheckState.Checked; + ckbMatchWholeWord.CheckedStateChanging += (s, e) => _matchWholeWord = e.NewValue == CheckState.Checked; d.Add (ckbMatchWholeWord); return d; } @@ -1153,16 +1153,16 @@ public class Editor : Scenario var ckbMatchCase = new CheckBox { - X = 0, Y = Pos.Top (txtToFind) + 2, State = _matchCase ? CheckState.Checked : CheckState.UnChecked, Text = "Match c_ase" + X = 0, Y = Pos.Top (txtToFind) + 2, CheckedState = _matchCase ? CheckState.Checked : CheckState.UnChecked, Text = "Match c_ase" }; - ckbMatchCase.Toggle += (s, e) => _matchCase = e.NewValue == CheckState.Checked; + ckbMatchCase.CheckedStateChanging += (s, e) => _matchCase = e.NewValue == CheckState.Checked; d.Add (ckbMatchCase); var ckbMatchWholeWord = new CheckBox { - X = 0, Y = Pos.Top (ckbMatchCase) + 1, State = _matchWholeWord ? CheckState.Checked : CheckState.UnChecked, Text = "Match _whole word" + X = 0, Y = Pos.Top (ckbMatchCase) + 1, CheckedState = _matchWholeWord ? CheckState.Checked : CheckState.UnChecked, Text = "Match _whole word" }; - ckbMatchWholeWord.Toggle += (s, e) => _matchWholeWord = e.NewValue == CheckState.Checked; + ckbMatchWholeWord.CheckedStateChanging += (s, e) => _matchWholeWord = e.NewValue == CheckState.Checked; d.Add (ckbMatchWholeWord); return d; diff --git a/UICatalog/Scenarios/FileDialogExamples.cs b/UICatalog/Scenarios/FileDialogExamples.cs index 48f8cf510..094f210e7 100644 --- a/UICatalog/Scenarios/FileDialogExamples.cs +++ b/UICatalog/Scenarios/FileDialogExamples.cs @@ -33,25 +33,25 @@ public class FileDialogExamples : Scenario var x = 1; var win = new Window { Title = GetQuitKeyAndName () }; - _cbMustExist = new CheckBox { State = CheckState.Checked, Y = y++, X = x, Text = "Must Exist" }; + _cbMustExist = new CheckBox { CheckedState = CheckState.Checked, Y = y++, X = x, Text = "Must Exist" }; win.Add (_cbMustExist); - _cbUseColors = new CheckBox { State = FileDialogStyle.DefaultUseColors ? CheckState.Checked : CheckState.UnChecked, Y = y++, X = x, Text = "Use Colors" }; + _cbUseColors = new CheckBox { CheckedState = FileDialogStyle.DefaultUseColors ? CheckState.Checked : CheckState.UnChecked, Y = y++, X = x, Text = "Use Colors" }; win.Add (_cbUseColors); - _cbCaseSensitive = new CheckBox { State = CheckState.UnChecked, Y = y++, X = x, Text = "Case Sensitive Search" }; + _cbCaseSensitive = new CheckBox { CheckedState = CheckState.UnChecked, Y = y++, X = x, Text = "Case Sensitive Search" }; win.Add (_cbCaseSensitive); - _cbAllowMultipleSelection = new CheckBox { State = CheckState.UnChecked, Y = y++, X = x, Text = "Multiple" }; + _cbAllowMultipleSelection = new CheckBox { CheckedState = CheckState.UnChecked, Y = y++, X = x, Text = "Multiple" }; win.Add (_cbAllowMultipleSelection); - _cbShowTreeBranchLines = new CheckBox { State = CheckState.Checked, Y = y++, X = x, Text = "Tree Branch Lines" }; + _cbShowTreeBranchLines = new CheckBox { CheckedState = CheckState.Checked, Y = y++, X = x, Text = "Tree Branch Lines" }; win.Add (_cbShowTreeBranchLines); - _cbAlwaysTableShowHeaders = new CheckBox { State = CheckState.Checked, Y = y++, X = x, Text = "Always Show Headers" }; + _cbAlwaysTableShowHeaders = new CheckBox { CheckedState = CheckState.Checked, Y = y++, X = x, Text = "Always Show Headers" }; win.Add (_cbAlwaysTableShowHeaders); - _cbDrivesOnlyInTree = new CheckBox { State = CheckState.UnChecked, Y = y++, X = x, Text = "Only Show Drives" }; + _cbDrivesOnlyInTree = new CheckBox { CheckedState = CheckState.UnChecked, Y = y++, X = x, Text = "Only Show Drives" }; win.Add (_cbDrivesOnlyInTree); y = 0; @@ -151,8 +151,8 @@ public class FileDialogExamples : Scenario OpenMode = Enum.Parse ( _rgOpenMode.RadioLabels [_rgOpenMode.SelectedItem] ), - MustExist = _cbMustExist.State == CheckState.Checked, - AllowsMultipleSelection = _cbAllowMultipleSelection.State == CheckState.Checked + MustExist = _cbMustExist.CheckedState == CheckState.Checked, + AllowsMultipleSelection = _cbAllowMultipleSelection.CheckedState == CheckState.Checked }; fd.Style.OkButtonText = _rgCaption.RadioLabels [_rgCaption.SelectedItem]; @@ -166,19 +166,19 @@ public class FileDialogExamples : Scenario fd.Style.IconProvider.UseUnicodeCharacters = _rgIcons.SelectedItem == 1; fd.Style.IconProvider.UseNerdIcons = _rgIcons.SelectedItem == 2; - if (_cbCaseSensitive.State == CheckState.Checked) + if (_cbCaseSensitive.CheckedState == CheckState.Checked) { fd.SearchMatcher = new CaseSensitiveSearchMatcher (); } - fd.Style.UseColors = _cbUseColors.State == CheckState.Checked; + fd.Style.UseColors = _cbUseColors.CheckedState == CheckState.Checked; - fd.Style.TreeStyle.ShowBranchLines = _cbShowTreeBranchLines.State == CheckState.Checked; - fd.Style.TableStyle.AlwaysShowHeaders = _cbAlwaysTableShowHeaders.State == CheckState.Checked; + fd.Style.TreeStyle.ShowBranchLines = _cbShowTreeBranchLines.CheckedState == CheckState.Checked; + fd.Style.TableStyle.AlwaysShowHeaders = _cbAlwaysTableShowHeaders.CheckedState == CheckState.Checked; IDirectoryInfoFactory dirInfoFactory = new FileSystem ().DirectoryInfo; - if (_cbDrivesOnlyInTree.State == CheckState.Checked) + if (_cbDrivesOnlyInTree.CheckedState == CheckState.Checked) { fd.Style.TreeRootGetter = () => { return Environment.GetLogicalDrives ().ToDictionary (dirInfoFactory.New, k => k); }; } @@ -203,7 +203,7 @@ public class FileDialogExamples : Scenario fd.Style.CancelButtonText = _tbCancelButton.Text; } - if (_cbFlipButtonOrder.State == CheckState.Checked) + if (_cbFlipButtonOrder.CheckedState == CheckState.Checked) { fd.Style.FlipOkCancelButtonLayoutOrder = true; } @@ -225,7 +225,7 @@ public class FileDialogExamples : Scenario "Ok" ); } - else if (_cbAllowMultipleSelection.State == CheckState.Checked) + else if (_cbAllowMultipleSelection.CheckedState == CheckState.Checked) { MessageBox.Query ( "Chosen!", diff --git a/UICatalog/Scenarios/GraphViewExample.cs b/UICatalog/Scenarios/GraphViewExample.cs index 7bef3e70e..2ddb8bd44 100644 --- a/UICatalog/Scenarios/GraphViewExample.cs +++ b/UICatalog/Scenarios/GraphViewExample.cs @@ -202,7 +202,7 @@ public class GraphViewExample : Scenario if (sender is Shortcut shortcut && shortcut.CommandView is CheckBox checkBox) { - checkBox.State = _miDiags.Checked ?? false ? CheckState.Checked : CheckState.UnChecked; + checkBox.CheckedState = _miDiags.Checked ?? false ? CheckState.Checked : CheckState.UnChecked; } } diff --git a/UICatalog/Scenarios/Images.cs b/UICatalog/Scenarios/Images.cs index f17246742..4faab9b8b 100644 --- a/UICatalog/Scenarios/Images.cs +++ b/UICatalog/Scenarios/Images.cs @@ -29,7 +29,7 @@ public class Images : Scenario { X = Pos.Right (lblDriverName) + 2, Y = 0, - State = canTrueColor ? CheckState.Checked : CheckState.UnChecked, + CheckedState = canTrueColor ? CheckState.Checked : CheckState.UnChecked, CanFocus = false, Text = "supports true color " }; @@ -39,11 +39,11 @@ public class Images : Scenario { X = Pos.Right (cbSupportsTrueColor) + 2, Y = 0, - State = !Application.Force16Colors ? CheckState.Checked : CheckState.UnChecked, + CheckedState = !Application.Force16Colors ? CheckState.Checked : CheckState.UnChecked, Enabled = canTrueColor, Text = "Use true color" }; - cbUseTrueColor.Toggle += (_, evt) => Application.Force16Colors = evt.NewValue == CheckState.UnChecked; + cbUseTrueColor.CheckedStateChanging += (_, evt) => Application.Force16Colors = evt.NewValue == CheckState.UnChecked; win.Add (cbUseTrueColor); var btnOpenImage = new Button { X = Pos.Right (cbUseTrueColor) + 2, Y = 0, Text = "Open Image" }; diff --git a/UICatalog/Scenarios/ListViewWithSelection.cs b/UICatalog/Scenarios/ListViewWithSelection.cs index 27e1bf5d2..f9bb7ea03 100644 --- a/UICatalog/Scenarios/ListViewWithSelection.cs +++ b/UICatalog/Scenarios/ListViewWithSelection.cs @@ -34,24 +34,24 @@ public class ListViewWithSelection : Scenario _customRenderCB = new CheckBox { X = 0, Y = 0, Text = "Use custom rendering" }; _appWindow.Add (_customRenderCB); - _customRenderCB.Toggle += _customRenderCB_Toggle; + _customRenderCB.CheckedStateChanging += _customRenderCB_Toggle; _allowMarkingCB = new CheckBox { X = Pos.Right (_customRenderCB) + 1, Y = 0, Text = "Allow Marking", AllowCheckStateNone = false }; _appWindow.Add (_allowMarkingCB); - _allowMarkingCB.Toggle += AllowMarkingCB_Toggle; + _allowMarkingCB.CheckedStateChanging += AllowMarkingCB_Toggle; _allowMultipleCB = new CheckBox { X = Pos.Right (_allowMarkingCB) + 1, Y = 0, - Visible = _allowMarkingCB.State == CheckState.Checked, + Visible = _allowMarkingCB.CheckedState == CheckState.Checked, Text = "Allow Multi-Select" }; _appWindow.Add (_allowMultipleCB); - _allowMultipleCB.Toggle += AllowMultipleCB_Toggle; + _allowMultipleCB.CheckedStateChanging += AllowMultipleCB_Toggle; _listView = new ListView { @@ -108,9 +108,9 @@ public class ListViewWithSelection : Scenario var keepCheckBox = new CheckBox { - X = Pos.AnchorEnd (k.Length + 3), Y = 0, Text = k, State = scrollBar.AutoHideScrollBars ? CheckState.Checked : CheckState.UnChecked + X = Pos.AnchorEnd (k.Length + 3), Y = 0, Text = k, CheckedState = scrollBar.AutoHideScrollBars ? CheckState.Checked : CheckState.UnChecked }; - keepCheckBox.Toggle += (s, e) => scrollBar.KeepContentAlwaysInViewport = e.NewValue == CheckState.Checked; + keepCheckBox.CheckedStateChanging += (s, e) => scrollBar.KeepContentAlwaysInViewport = e.NewValue == CheckState.Checked; _appWindow.Add (keepCheckBox); Application.Run (_appWindow); diff --git a/UICatalog/Scenarios/Localization.cs b/UICatalog/Scenarios/Localization.cs index 1207db528..08e01493d 100644 --- a/UICatalog/Scenarios/Localization.cs +++ b/UICatalog/Scenarios/Localization.cs @@ -143,7 +143,7 @@ public class Localization : Scenario { X = Pos.Right (textField) + 1, Y = Pos.Bottom (textAndFileDialogLabel) + 1, - State = CheckState.UnChecked, + CheckedState = CheckState.UnChecked, Text = "Allow any" }; win.Add (_allowAnyCheckBox); @@ -190,7 +190,7 @@ public class Localization : Scenario dialog.AllowedTypes = [ - _allowAnyCheckBox.State == CheckState.Checked + _allowAnyCheckBox.CheckedState == CheckState.Checked ? new AllowedTypeAny () : new AllowedType ("Dynamic link library", ".dll"), new AllowedType ("Json", ".json"), diff --git a/UICatalog/Scenarios/MessageBoxes.cs b/UICatalog/Scenarios/MessageBoxes.cs index e2e8f941f..b3e791eff 100644 --- a/UICatalog/Scenarios/MessageBoxes.cs +++ b/UICatalog/Scenarios/MessageBoxes.cs @@ -190,7 +190,7 @@ public class MessageBoxes : Scenario var ckbWrapMessage = new CheckBox { - X = Pos.Right (label) + 1, Y = Pos.Bottom (styleRadioGroup), Text = "_Wrap Message", State = CheckState.Checked + X = Pos.Right (label) + 1, Y = Pos.Bottom (styleRadioGroup), Text = "_Wrap Message", CheckedState = CheckState.Checked }; frame.Add (ckbWrapMessage); @@ -241,7 +241,7 @@ public class MessageBoxes : Scenario titleEdit.Text, messageEdit.Text, defaultButton, - ckbWrapMessage.State == CheckState.Checked, + ckbWrapMessage.CheckedState == CheckState.Checked, btns.ToArray () )}"; } @@ -254,7 +254,7 @@ public class MessageBoxes : Scenario titleEdit.Text, messageEdit.Text, defaultButton, - ckbWrapMessage.State == CheckState.Checked, + ckbWrapMessage.CheckedState == CheckState.Checked, btns.ToArray () )}"; } diff --git a/UICatalog/Scenarios/Mouse.cs b/UICatalog/Scenarios/Mouse.cs index 0f5a4bac5..1e921c423 100644 --- a/UICatalog/Scenarios/Mouse.cs +++ b/UICatalog/Scenarios/Mouse.cs @@ -67,7 +67,7 @@ public class Mouse : Scenario Y = Pos.Bottom (ml), Title = "_Want Continuous Button Pressed" }; - cbWantContinuousPresses.Toggle += (s, e) => { win.WantContinuousButtonPressed = !win.WantContinuousButtonPressed; }; + cbWantContinuousPresses.CheckedStateChanging += (s, e) => { win.WantContinuousButtonPressed = !win.WantContinuousButtonPressed; }; win.Add (cbWantContinuousPresses); @@ -77,9 +77,9 @@ public class Mouse : Scenario Y = Pos.Bottom (cbWantContinuousPresses), Title = "_Highlight on Press" }; - cbHighlightOnPress.State = win.HighlightStyle == (HighlightStyle.Pressed | HighlightStyle.PressedOutside) ? CheckState.Checked : CheckState.UnChecked; + cbHighlightOnPress.CheckedState = win.HighlightStyle == (HighlightStyle.Pressed | HighlightStyle.PressedOutside) ? CheckState.Checked : CheckState.UnChecked; - cbHighlightOnPress.Toggle += (s, e) => + cbHighlightOnPress.CheckedStateChanging += (s, e) => { if (e.NewValue == CheckState.Checked) { diff --git a/UICatalog/Scenarios/PosAlignDemo.cs b/UICatalog/Scenarios/PosAlignDemo.cs index 03e90b806..b5aa98b31 100644 --- a/UICatalog/Scenarios/PosAlignDemo.cs +++ b/UICatalog/Scenarios/PosAlignDemo.cs @@ -87,18 +87,18 @@ public sealed class PosAlignDemo : Scenario if (dimension == Dimension.Width) { - endToStartCheckBox.State = _horizAligner.AlignmentModes.HasFlag (AlignmentModes.EndToStart) ? CheckState.Checked : CheckState.UnChecked; + endToStartCheckBox.CheckedState = _horizAligner.AlignmentModes.HasFlag (AlignmentModes.EndToStart) ? CheckState.Checked : CheckState.UnChecked; endToStartCheckBox.X = Pos.Align (_horizAligner.Alignment); endToStartCheckBox.Y = Pos.Top (alignRadioGroup); } else { - endToStartCheckBox.State = _vertAligner.AlignmentModes.HasFlag (AlignmentModes.EndToStart) ? CheckState.Checked : CheckState.UnChecked; + endToStartCheckBox.CheckedState = _vertAligner.AlignmentModes.HasFlag (AlignmentModes.EndToStart) ? CheckState.Checked : CheckState.UnChecked; endToStartCheckBox.X = Pos.Left (alignRadioGroup); endToStartCheckBox.Y = Pos.Align (_vertAligner.Alignment); } - endToStartCheckBox.Toggle += (s, e) => + endToStartCheckBox.CheckedStateChanging += (s, e) => { if (dimension == Dimension.Width) { @@ -125,18 +125,18 @@ public sealed class PosAlignDemo : Scenario if (dimension == Dimension.Width) { - ignoreFirstOrLast.State = _horizAligner.AlignmentModes.HasFlag (AlignmentModes.IgnoreFirstOrLast) ? CheckState.Checked : CheckState.UnChecked; + ignoreFirstOrLast.CheckedState = _horizAligner.AlignmentModes.HasFlag (AlignmentModes.IgnoreFirstOrLast) ? CheckState.Checked : CheckState.UnChecked; ignoreFirstOrLast.X = Pos.Align (_horizAligner.Alignment); ignoreFirstOrLast.Y = Pos.Top (alignRadioGroup); } else { - ignoreFirstOrLast.State = _vertAligner.AlignmentModes.HasFlag (AlignmentModes.IgnoreFirstOrLast) ? CheckState.Checked : CheckState.UnChecked; + ignoreFirstOrLast.CheckedState = _vertAligner.AlignmentModes.HasFlag (AlignmentModes.IgnoreFirstOrLast) ? CheckState.Checked : CheckState.UnChecked; ignoreFirstOrLast.X = Pos.Left (alignRadioGroup); ignoreFirstOrLast.Y = Pos.Align (_vertAligner.Alignment); } - ignoreFirstOrLast.Toggle += (s, e) => + ignoreFirstOrLast.CheckedStateChanging += (s, e) => { if (dimension == Dimension.Width) { @@ -163,18 +163,18 @@ public sealed class PosAlignDemo : Scenario if (dimension == Dimension.Width) { - addSpacesBetweenItems.State = _horizAligner.AlignmentModes.HasFlag (AlignmentModes.AddSpaceBetweenItems) ? CheckState.Checked : CheckState.UnChecked; + addSpacesBetweenItems.CheckedState = _horizAligner.AlignmentModes.HasFlag (AlignmentModes.AddSpaceBetweenItems) ? CheckState.Checked : CheckState.UnChecked; addSpacesBetweenItems.X = Pos.Align (_horizAligner.Alignment); addSpacesBetweenItems.Y = Pos.Top (alignRadioGroup); } else { - addSpacesBetweenItems.State = _vertAligner.AlignmentModes.HasFlag (AlignmentModes.AddSpaceBetweenItems) ? CheckState.Checked : CheckState.UnChecked; + addSpacesBetweenItems.CheckedState = _vertAligner.AlignmentModes.HasFlag (AlignmentModes.AddSpaceBetweenItems) ? CheckState.Checked : CheckState.UnChecked; addSpacesBetweenItems.X = Pos.Left (alignRadioGroup); addSpacesBetweenItems.Y = Pos.Align (_vertAligner.Alignment); } - addSpacesBetweenItems.Toggle += (s, e) => + addSpacesBetweenItems.CheckedStateChanging += (s, e) => { if (dimension == Dimension.Width) { @@ -211,7 +211,7 @@ public sealed class PosAlignDemo : Scenario margin.Y = Pos.Align (_vertAligner.Alignment); } - margin.Toggle += (s, e) => + margin.CheckedStateChanging += (s, e) => { if (dimension == Dimension.Width) { diff --git a/UICatalog/Scenarios/ProgressBarStyles.cs b/UICatalog/Scenarios/ProgressBarStyles.cs index 05fe2a07e..705b68d68 100644 --- a/UICatalog/Scenarios/ProgressBarStyles.cs +++ b/UICatalog/Scenarios/ProgressBarStyles.cs @@ -236,7 +236,7 @@ public class ProgressBarStyles : Scenario X = Pos.Center (), Y = Pos.Bottom (continuousPB), Text = "BidirectionalMarquee", - State = CheckState.Checked + CheckedState = CheckState.Checked }; container.Add (ckbBidirectional); @@ -289,9 +289,9 @@ public class ProgressBarStyles : Scenario marqueesContinuousPB.ProgressBarFormat = (ProgressBarFormat)e.SelectedItem; }; - ckbBidirectional.Toggle += (s, e) => + ckbBidirectional.CheckedStateChanging += (s, e) => { - ckbBidirectional.State = e.NewValue; + ckbBidirectional.CheckedState = e.NewValue; marqueesBlocksPB.BidirectionalMarquee = marqueesContinuousPB.BidirectionalMarquee = e.NewValue == CheckState.Checked; }; diff --git a/UICatalog/Scenarios/Scrolling.cs b/UICatalog/Scenarios/Scrolling.cs index ee1252d18..125b7e3bc 100644 --- a/UICatalog/Scenarios/Scrolling.cs +++ b/UICatalog/Scenarios/Scrolling.cs @@ -148,7 +148,7 @@ public class Scrolling : Scenario X = Pos.X (scrollView), Y = Pos.Bottom (scrollView), Text = "Horizontal Scrollbar", - State = scrollView.ShowHorizontalScrollIndicator ? CheckState.Checked : CheckState.UnChecked + CheckedState = scrollView.ShowHorizontalScrollIndicator ? CheckState.Checked : CheckState.UnChecked }; app.Add (hCheckBox); @@ -157,7 +157,7 @@ public class Scrolling : Scenario X = Pos.Right (hCheckBox) + 3, Y = Pos.Bottom (scrollView), Text = "Vertical Scrollbar", - State = scrollView.ShowVerticalScrollIndicator ? CheckState.Checked : CheckState.UnChecked + CheckedState = scrollView.ShowVerticalScrollIndicator ? CheckState.Checked : CheckState.UnChecked }; app.Add (vCheckBox); @@ -165,50 +165,50 @@ public class Scrolling : Scenario var ahCheckBox = new CheckBox { - X = Pos.Left (scrollView), Y = Pos.Bottom (hCheckBox), Text = t, State = scrollView.AutoHideScrollBars ? CheckState.Checked : CheckState.UnChecked + X = Pos.Left (scrollView), Y = Pos.Bottom (hCheckBox), Text = t, CheckedState = scrollView.AutoHideScrollBars ? CheckState.Checked : CheckState.UnChecked }; var k = "Keep Content Always In Viewport"; var keepCheckBox = new CheckBox { - X = Pos.Left (scrollView), Y = Pos.Bottom (ahCheckBox), Text = k, State = scrollView.AutoHideScrollBars ? CheckState.Checked : CheckState.UnChecked + X = Pos.Left (scrollView), Y = Pos.Bottom (ahCheckBox), Text = k, CheckedState = scrollView.AutoHideScrollBars ? CheckState.Checked : CheckState.UnChecked }; - hCheckBox.Toggle += (s, e) => + hCheckBox.CheckedStateChanging += (s, e) => { - if (ahCheckBox.State == CheckState.UnChecked) + if (ahCheckBox.CheckedState == CheckState.UnChecked) { scrollView.ShowHorizontalScrollIndicator = e.NewValue == CheckState.Checked; } else { - hCheckBox.State = CheckState.Checked; + hCheckBox.CheckedState = CheckState.Checked; MessageBox.Query ("Message", "Disable Auto Hide Scrollbars first.", "Ok"); } }; - vCheckBox.Toggle += (s, e) => + vCheckBox.CheckedStateChanging += (s, e) => { - if (ahCheckBox.State == CheckState.UnChecked) + if (ahCheckBox.CheckedState == CheckState.UnChecked) { scrollView.ShowVerticalScrollIndicator = e.NewValue == CheckState.Checked; } else { - vCheckBox.State = CheckState.Checked; + vCheckBox.CheckedState = CheckState.Checked; MessageBox.Query ("Message", "Disable Auto Hide Scrollbars first.", "Ok"); } }; - ahCheckBox.Toggle += (s, e) => + ahCheckBox.CheckedStateChanging += (s, e) => { scrollView.AutoHideScrollBars = e.NewValue == CheckState.Checked; - hCheckBox.State = CheckState.Checked; - vCheckBox.State = CheckState.Checked; + hCheckBox.CheckedState = CheckState.Checked; + vCheckBox.CheckedState = CheckState.Checked; }; app.Add (ahCheckBox); - keepCheckBox.Toggle += (s, e) => scrollView.KeepContentAlwaysInViewport = e.NewValue == CheckState.Checked; + keepCheckBox.CheckedStateChanging += (s, e) => scrollView.KeepContentAlwaysInViewport = e.NewValue == CheckState.Checked; app.Add (keepCheckBox); var count = 0; diff --git a/UICatalog/Scenarios/SendKeys.cs b/UICatalog/Scenarios/SendKeys.cs index 6dc4a3bdf..2ac87f67b 100644 --- a/UICatalog/Scenarios/SendKeys.cs +++ b/UICatalog/Scenarios/SendKeys.cs @@ -89,9 +89,9 @@ public class SendKeys : Scenario Application.Driver?.SendKeys ( r, ck, - ckbShift.State == CheckState.Checked, - ckbAlt.State == CheckState.Checked, - ckbControl.State == CheckState.Checked + ckbShift.CheckedState == CheckState.Checked, + ckbAlt.CheckedState == CheckState.Checked, + ckbControl.CheckedState == CheckState.Checked ); } diff --git a/UICatalog/Scenarios/Shortcuts.cs b/UICatalog/Scenarios/Shortcuts.cs index 2cf9a8bae..11313f5c4 100644 --- a/UICatalog/Scenarios/Shortcuts.cs +++ b/UICatalog/Scenarios/Shortcuts.cs @@ -107,7 +107,7 @@ public class Shortcuts : Scenario KeyBindingScope = KeyBindingScope.HotKey, }; - ((CheckBox)vShortcut3.CommandView).Toggle += (s, e) => + ((CheckBox)vShortcut3.CommandView).CheckedStateChanging += (s, e) => { if (vShortcut3.CommandView is CheckBox cb) { @@ -166,7 +166,7 @@ public class Shortcuts : Scenario CommandView = new CheckBox { Text = "_CanFocus" }, }; - ((CheckBox)vShortcut5.CommandView).Toggle += (s, e) => + ((CheckBox)vShortcut5.CommandView).CheckedStateChanging += (s, e) => { if (vShortcut5.CommandView is CheckBox cb) { diff --git a/UICatalog/Scenarios/Sliders.cs b/UICatalog/Scenarios/Sliders.cs index 40e98dd33..3deeb40fc 100644 --- a/UICatalog/Scenarios/Sliders.cs +++ b/UICatalog/Scenarios/Sliders.cs @@ -236,7 +236,7 @@ public class Sliders : Scenario Y = Pos.Bottom (optionsSlider) }; - dimAutoUsesMin.Toggle += (sender, e) => + dimAutoUsesMin.CheckedStateChanging += (sender, e) => { foreach (Slider s in app.Subviews.OfType ()) { diff --git a/UICatalog/Scenarios/SpinnerStyles.cs b/UICatalog/Scenarios/SpinnerStyles.cs index c5e5f73f1..294d47491 100644 --- a/UICatalog/Scenarios/SpinnerStyles.cs +++ b/UICatalog/Scenarios/SpinnerStyles.cs @@ -53,7 +53,7 @@ public class SpinnerViewStyles : Scenario X = Pos.Center () - 7, Y = Pos.Bottom (preview), Enabled = false, - State = CheckState.Checked, + CheckedState = CheckState.Checked, Text = "Ascii Only" }; app.Add (ckbAscii); @@ -63,20 +63,20 @@ public class SpinnerViewStyles : Scenario X = Pos.Center () + 7, Y = Pos.Bottom (preview), Enabled = false, - State = CheckState.Checked, + CheckedState = CheckState.Checked, Text = "No Special" }; app.Add (ckbNoSpecial); var ckbReverse = new CheckBox { - X = Pos.Center () - 22, Y = Pos.Bottom (preview) + 1, State = CheckState.UnChecked, Text = "Reverse" + X = Pos.Center () - 22, Y = Pos.Bottom (preview) + 1, CheckedState = CheckState.UnChecked, Text = "Reverse" }; app.Add (ckbReverse); var ckbBounce = new CheckBox { - X = Pos.Right (ckbReverse) + 2, Y = Pos.Bottom (preview) + 1, State = CheckState.UnChecked, Text = "Bounce" + X = Pos.Right (ckbReverse) + 2, Y = Pos.Bottom (preview) + 1, CheckedState = CheckState.UnChecked, Text = "Bounce" }; app.Add (ckbBounce); @@ -157,16 +157,16 @@ public class SpinnerViewStyles : Scenario spinner.Visible = true; spinner.Style = (SpinnerStyle)Activator.CreateInstance (styleDict [e.Item].Value); delayField.Text = spinner.SpinDelay.ToString (); - ckbBounce.State = spinner.SpinBounce ? CheckState.Checked : CheckState.UnChecked; - ckbNoSpecial.State = !spinner.HasSpecialCharacters ? CheckState.Checked : CheckState.UnChecked; - ckbAscii.State = spinner.IsAsciiOnly ? CheckState.Checked : CheckState.UnChecked; - ckbReverse.State = CheckState.UnChecked; + ckbBounce.CheckedState = spinner.SpinBounce ? CheckState.Checked : CheckState.UnChecked; + ckbNoSpecial.CheckedState = !spinner.HasSpecialCharacters ? CheckState.Checked : CheckState.UnChecked; + ckbAscii.CheckedState = spinner.IsAsciiOnly ? CheckState.Checked : CheckState.UnChecked; + ckbReverse.CheckedState = CheckState.UnChecked; } }; - ckbReverse.Toggle += (s, e) => { spinner.SpinReverse = e.NewValue == CheckState.Checked; }; + ckbReverse.CheckedStateChanging += (s, e) => { spinner.SpinReverse = e.NewValue == CheckState.Checked; }; - ckbBounce.Toggle += (s, e) => { spinner.SpinBounce = e.NewValue == CheckState.Checked; }; + ckbBounce.CheckedStateChanging += (s, e) => { spinner.SpinBounce = e.NewValue == CheckState.Checked; }; app.Unloaded += App_Unloaded; diff --git a/UICatalog/Scenarios/Text.cs b/UICatalog/Scenarios/Text.cs index 4057ac10c..3fe43379a 100644 --- a/UICatalog/Scenarios/Text.cs +++ b/UICatalog/Scenarios/Text.cs @@ -107,7 +107,7 @@ public class Text : Scenario // single-line mode. var chxMultiline = new CheckBox { - X = Pos.Left (textView), Y = Pos.Bottom (textView), State = textView.Multiline ? CheckState.Checked : CheckState.UnChecked, Text = "_Multiline" + X = Pos.Left (textView), Y = Pos.Bottom (textView), CheckedState = textView.Multiline ? CheckState.Checked : CheckState.UnChecked, Text = "_Multiline" }; win.Add (chxMultiline); @@ -115,10 +115,10 @@ public class Text : Scenario { X = Pos.Right (chxMultiline) + 2, Y = Pos.Top (chxMultiline), - State = textView.WordWrap ? CheckState.Checked : CheckState.UnChecked, + CheckedState = textView.WordWrap ? CheckState.Checked : CheckState.UnChecked, Text = "_Word Wrap" }; - chxWordWrap.Toggle += (s, e) => textView.WordWrap = e.NewValue == CheckState.Checked; + chxWordWrap.CheckedStateChanging += (s, e) => textView.WordWrap = e.NewValue == CheckState.Checked; win.Add (chxWordWrap); // TextView captures Tabs (so users can enter /t into text) by default; @@ -128,29 +128,29 @@ public class Text : Scenario { X = Pos.Right (chxWordWrap) + 2, Y = Pos.Top (chxWordWrap), - State = textView.AllowsTab ? CheckState.Checked : CheckState.UnChecked, + CheckedState = textView.AllowsTab ? CheckState.Checked : CheckState.UnChecked, Text = "_Capture Tabs" }; - chxMultiline.Toggle += (s, e) => + chxMultiline.CheckedStateChanging += (s, e) => { textView.Multiline = e.NewValue == CheckState.Checked; - if (!textView.Multiline && chxWordWrap.State == CheckState.Checked) + if (!textView.Multiline && chxWordWrap.CheckedState == CheckState.Checked) { - chxWordWrap.State = CheckState.UnChecked; + chxWordWrap.CheckedState = CheckState.UnChecked; } - if (!textView.Multiline && chxCaptureTabs.State == CheckState.Checked) + if (!textView.Multiline && chxCaptureTabs.CheckedState == CheckState.Checked) { - chxCaptureTabs.State = CheckState.UnChecked; + chxCaptureTabs.CheckedState = CheckState.UnChecked; } }; Key keyTab = textView.KeyBindings.GetKeyFromCommands (Command.Tab); Key keyBackTab = textView.KeyBindings.GetKeyFromCommands (Command.BackTab); - chxCaptureTabs.Toggle += (s, e) => + chxCaptureTabs.CheckedStateChanging += (s, e) => { if (e.NewValue == CheckState.Checked) { diff --git a/UICatalog/Scenarios/TextAlignmentAndDirection.cs b/UICatalog/Scenarios/TextAlignmentAndDirection.cs index 6861aed8d..7f6207268 100644 --- a/UICatalog/Scenarios/TextAlignmentAndDirection.cs +++ b/UICatalog/Scenarios/TextAlignmentAndDirection.cs @@ -484,7 +484,7 @@ public class TextAlignmentAndDirection : Scenario Enabled = false }; - justifyCheckbox.Toggle += (s, e) => ToggleJustify (e.NewValue != CheckState.Checked); + justifyCheckbox.CheckedStateChanging += (s, e) => ToggleJustify (e.NewValue != CheckState.Checked); justifyOptions.SelectedItemChanged += (s, e) => { ToggleJustify (false, true); }; @@ -500,9 +500,9 @@ public class TextAlignmentAndDirection : Scenario Height = 1, Text = "Word Wrap" }; - wrapCheckbox.State = wrapCheckbox.TextFormatter.WordWrap ? CheckState.Checked : CheckState.UnChecked; + wrapCheckbox.CheckedState = wrapCheckbox.TextFormatter.WordWrap ? CheckState.Checked : CheckState.UnChecked; - wrapCheckbox.Toggle += (s, e) => + wrapCheckbox.CheckedStateChanging += (s, e) => { if (e.CurrentValue == CheckState.Checked) { @@ -536,7 +536,7 @@ public class TextAlignmentAndDirection : Scenario directionOptions.SelectedItemChanged += (s, ev) => { - bool justChecked = justifyCheckbox.State == CheckState.Checked; + bool justChecked = justifyCheckbox.CheckedState == CheckState.Checked; if (justChecked) { diff --git a/UICatalog/Scenarios/TextEffectsScenario.cs b/UICatalog/Scenarios/TextEffectsScenario.cs index 7d5d0e156..12f9e9a4b 100644 --- a/UICatalog/Scenarios/TextEffectsScenario.cs +++ b/UICatalog/Scenarios/TextEffectsScenario.cs @@ -70,7 +70,7 @@ public class TextEffectsScenario : Scenario Y = Pos.AnchorEnd (1) }; - cbLooping.Toggle += (s, e) => + cbLooping.CheckedStateChanging += (s, e) => { LoopingGradient = e.NewValue == CheckState.Checked; SetupGradientLineCanvas (w, w.Frame.Size); diff --git a/UICatalog/Scenarios/TextFormatterDemo.cs b/UICatalog/Scenarios/TextFormatterDemo.cs index e70138c35..d24f863cf 100644 --- a/UICatalog/Scenarios/TextFormatterDemo.cs +++ b/UICatalog/Scenarios/TextFormatterDemo.cs @@ -58,7 +58,7 @@ public class TextFormatterDemo : Scenario X = 0, Y = Pos.Bottom (blockText) + 1, Text = "Unicode", - State = app.HotKeySpecifier == (Rune)' ' ? CheckState.Checked : CheckState.UnChecked + CheckedState = app.HotKeySpecifier == (Rune)' ' ? CheckState.Checked : CheckState.UnChecked }; app.Add (unicodeCheckBox); @@ -121,7 +121,7 @@ public class TextFormatterDemo : Scenario label = multipleLines [i]; } - unicodeCheckBox.Toggle += (s, e) => + unicodeCheckBox.CheckedStateChanging += (s, e) => { for (int i = 0; i < alignments.Count; i++) { diff --git a/UICatalog/Scenarios/TileViewNesting.cs b/UICatalog/Scenarios/TileViewNesting.cs index 4562b3628..728fdf26f 100644 --- a/UICatalog/Scenarios/TileViewNesting.cs +++ b/UICatalog/Scenarios/TileViewNesting.cs @@ -35,16 +35,16 @@ public class TileViewNesting : Scenario _textField.TextChanged += (s, e) => SetupTileView (); _cbHorizontal = new() { X = Pos.Right (_textField) + 1, Text = "Horizontal" }; - _cbHorizontal.Toggle += (s, e) => SetupTileView (); + _cbHorizontal.CheckedStateChanging += (s, e) => SetupTileView (); _cbBorder = new() { X = Pos.Right (_cbHorizontal) + 1, Text = "Border" }; - _cbBorder.Toggle += (s, e) => SetupTileView (); + _cbBorder.CheckedStateChanging += (s, e) => SetupTileView (); _cbTitles = new() { X = Pos.Right (_cbBorder) + 1, Text = "Titles" }; - _cbTitles.Toggle += (s, e) => SetupTileView (); + _cbTitles.CheckedStateChanging += (s, e) => SetupTileView (); _cbUseLabels = new() { X = Pos.Right (_cbTitles) + 1, Text = "Use Labels" }; - _cbUseLabels.Toggle += (s, e) => SetupTileView (); + _cbUseLabels.CheckedStateChanging += (s, e) => SetupTileView (); _workArea = new() { X = 0, Y = 1, Width = Dim.Fill (), Height = Dim.Fill () }; @@ -101,7 +101,7 @@ public class TileViewNesting : Scenario } } - private View CreateContentControl (int number) { return _cbUseLabels.State == CheckState.Checked ? CreateLabelView (number) : CreateTextView (number); } + private View CreateContentControl (int number) { return _cbUseLabels.CheckedState == CheckState.Checked ? CreateLabelView (number) : CreateTextView (number); } private View CreateLabelView (int number) { @@ -136,8 +136,8 @@ public class TileViewNesting : Scenario Orientation = orientation }; - toReturn.Tiles.ElementAt (0).Title = _cbTitles.State == CheckState.Checked ? $"View {titleNumber}" : string.Empty; - toReturn.Tiles.ElementAt (1).Title = _cbTitles.State == CheckState.Checked ? $"View {titleNumber + 1}" : string.Empty; + toReturn.Tiles.ElementAt (0).Title = _cbTitles.CheckedState == CheckState.Checked ? $"View {titleNumber}" : string.Empty; + toReturn.Tiles.ElementAt (1).Title = _cbTitles.CheckedState == CheckState.Checked ? $"View {titleNumber + 1}" : string.Empty; return toReturn; } @@ -158,9 +158,9 @@ public class TileViewNesting : Scenario { int numberOfViews = GetNumberOfViews (); - CheckState titles = _cbTitles.State; - CheckState border = _cbBorder.State; - CheckState startHorizontal = _cbHorizontal.State; + CheckState titles = _cbTitles.CheckedState; + CheckState border = _cbBorder.CheckedState; + CheckState startHorizontal = _cbHorizontal.CheckedState; foreach (View sub in _workArea.Subviews) { @@ -177,9 +177,9 @@ public class TileViewNesting : Scenario TileView root = CreateTileView (1, startHorizontal == CheckState.Checked ? Orientation.Horizontal : Orientation.Vertical); root.Tiles.ElementAt (0).ContentView.Add (CreateContentControl (1)); - root.Tiles.ElementAt (0).Title = _cbTitles.State == CheckState.Checked ? "View 1" : string.Empty; + root.Tiles.ElementAt (0).Title = _cbTitles.CheckedState == CheckState.Checked ? "View 1" : string.Empty; root.Tiles.ElementAt (1).ContentView.Add (CreateContentControl (2)); - root.Tiles.ElementAt (1).Title = _cbTitles.State == CheckState.Checked ? "View 2" : string.Empty; + root.Tiles.ElementAt (1).Title = _cbTitles.CheckedState == CheckState.Checked ? "View 2" : string.Empty; root.LineStyle = border == CheckState.Checked? LineStyle.Rounded : LineStyle.None; @@ -225,7 +225,7 @@ public class TileViewNesting : Scenario // During splitting the old Title will have been migrated to View1 so we only need // to set the Title on View2 (the one that gets our new TextView) - newView.Tiles.ElementAt (1).Title = _cbTitles.State == CheckState.Checked ? $"View {_viewsCreated}" : string.Empty; + newView.Tiles.ElementAt (1).Title = _cbTitles.CheckedState == CheckState.Checked ? $"View {_viewsCreated}" : string.Empty; // Flip orientation newView.Orientation = to.Orientation == Orientation.Vertical diff --git a/UICatalog/Scenarios/TrueColors.cs b/UICatalog/Scenarios/TrueColors.cs index d08d9685a..a40114984 100644 --- a/UICatalog/Scenarios/TrueColors.cs +++ b/UICatalog/Scenarios/TrueColors.cs @@ -32,7 +32,7 @@ public class TrueColors : Scenario { X = x, Y = y++, - State = canTrueColor ? CheckState.Checked : CheckState.UnChecked, + CheckedState = canTrueColor ? CheckState.Checked : CheckState.UnChecked, CanFocus = false, Enabled = false, Text = "Driver supports true color " @@ -43,11 +43,11 @@ public class TrueColors : Scenario { X = x, Y = y++, - State = Application.Force16Colors ? CheckState.Checked : CheckState.UnChecked, + CheckedState = Application.Force16Colors ? CheckState.Checked : CheckState.UnChecked, Enabled = canTrueColor, Text = "Force 16 colors" }; - cbUseTrueColor.Toggle += (_, evt) => { Application.Force16Colors = evt.NewValue == CheckState.Checked; }; + cbUseTrueColor.CheckedStateChanging += (_, evt) => { Application.Force16Colors = evt.NewValue == CheckState.Checked; }; app.Add (cbUseTrueColor); y += 2; diff --git a/UICatalog/Scenarios/Wizards.cs b/UICatalog/Scenarios/Wizards.cs index 530b066e6..dbd210cc2 100644 --- a/UICatalog/Scenarios/Wizards.cs +++ b/UICatalog/Scenarios/Wizards.cs @@ -198,7 +198,7 @@ public class Wizards : Scenario var thirdStepEnabledCeckBox = new CheckBox { Text = "Enable Step _3", - State = CheckState.UnChecked, + CheckedState = CheckState.UnChecked, X = Pos.Left (lastNameField), Y = Pos.Bottom (lastNameField) }; @@ -245,8 +245,8 @@ public class Wizards : Scenario X = Pos.Right (progLbl), Y = Pos.Top (progLbl), Width = 40, Fraction = 0.42F }; thirdStep.Add (progLbl, progressBar); - thirdStep.Enabled = thirdStepEnabledCeckBox.State == CheckState.Checked; - thirdStepEnabledCeckBox.Toggle += (s, e) => { thirdStep.Enabled = thirdStepEnabledCeckBox.State == CheckState.Checked; }; + thirdStep.Enabled = thirdStepEnabledCeckBox.CheckedState == CheckState.Checked; + thirdStepEnabledCeckBox.CheckedStateChanging += (s, e) => { thirdStep.Enabled = thirdStepEnabledCeckBox.CheckedState == CheckState.Checked; }; // Add 4th step var fourthStep = new WizardStep { Title = "Step Four" }; @@ -323,7 +323,7 @@ public class Wizards : Scenario "The wizard is complete!\n\nPress the Finish button to continue.\n\nPressing ESC will cancel the wizard."; var finalFinalStepEnabledCeckBox = - new CheckBox { Text = "Enable _Final Final Step", State = CheckState.UnChecked, X = 0, Y = 1 }; + new CheckBox { Text = "Enable _Final Final Step", CheckedState = CheckState.UnChecked, X = 0, Y = 1 }; lastStep.Add (finalFinalStepEnabledCeckBox); // Add an optional FINAL last step @@ -332,11 +332,11 @@ public class Wizards : Scenario finalFinalStep.HelpText = "This step only shows if it was enabled on the other last step."; - finalFinalStep.Enabled = thirdStepEnabledCeckBox.State == CheckState.Checked; + finalFinalStep.Enabled = thirdStepEnabledCeckBox.CheckedState == CheckState.Checked; - finalFinalStepEnabledCeckBox.Toggle += (s, e) => + finalFinalStepEnabledCeckBox.CheckedStateChanging += (s, e) => { - finalFinalStep.Enabled = finalFinalStepEnabledCeckBox.State == CheckState.Checked; + finalFinalStep.Enabled = finalFinalStepEnabledCeckBox.CheckedState == CheckState.Checked; }; Application.Run (wizard); diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index 51c54681b..25425782d 100644 --- a/UICatalog/UICatalog.cs +++ b/UICatalog/UICatalog.cs @@ -492,14 +492,14 @@ public class UICatalogApp CommandView = new CheckBox { Title = "16 color mode", - State = Application.Force16Colors ? CheckState.Checked : CheckState.UnChecked, + CheckedState = Application.Force16Colors ? CheckState.Checked : CheckState.UnChecked, CanFocus = false }, HelpText = "", Key = Key.F6 }; - ((CheckBox)ShForce16Colors.CommandView).Toggle += (sender, args) => + ((CheckBox)ShForce16Colors.CommandView).CheckedStateChanging += (sender, args) => { Application.Force16Colors = args.NewValue == CheckState.Checked; MiForce16Colors!.Checked = Application.Force16Colors; @@ -1027,7 +1027,7 @@ public class UICatalogApp { MiForce16Colors.Checked = Application.Force16Colors = (bool)!MiForce16Colors.Checked!; - ((CheckBox)ShForce16Colors!.CommandView!).State = + ((CheckBox)ShForce16Colors!.CommandView!).CheckedState = Application.Force16Colors ? CheckState.Checked : CheckState.UnChecked; Application.Refresh (); }; diff --git a/UnitTests/Views/CheckBoxTests.cs b/UnitTests/Views/CheckBoxTests.cs index f0682fa89..5d6e6a06e 100644 --- a/UnitTests/Views/CheckBoxTests.cs +++ b/UnitTests/Views/CheckBoxTests.cs @@ -98,15 +98,15 @@ public class CheckBoxTests (ITestOutputHelper output) { var checkBox = new CheckBox { Text = "Check this out 你" }; - Assert.Equal (CheckState.UnChecked, checkBox.State); + Assert.Equal (CheckState.UnChecked, checkBox.CheckedState); Assert.True (checkBox.NewKeyDownEvent (Key.Space)); - Assert.Equal (CheckState.Checked, checkBox.State); + Assert.Equal (CheckState.Checked, checkBox.CheckedState); Assert.True (checkBox.NewMouseEvent (new () { Position = new (0, 0), Flags = MouseFlags.Button1Clicked })); - Assert.Equal (CheckState.UnChecked, checkBox.State); + Assert.Equal (CheckState.UnChecked, checkBox.CheckedState); checkBox.AllowCheckStateNone = true; Assert.True (checkBox.NewKeyDownEvent (Key.Space)); - Assert.Equal (CheckState.None, checkBox.State); + Assert.Equal (CheckState.None, checkBox.CheckedState); checkBox.Draw (); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -115,14 +115,14 @@ public class CheckBoxTests (ITestOutputHelper output) output ); Assert.True (checkBox.NewMouseEvent (new () { Position = new (0, 0), Flags = MouseFlags.Button1Clicked })); - Assert.Equal (CheckState.Checked, checkBox.State); + Assert.Equal (CheckState.Checked, checkBox.CheckedState); Assert.True (checkBox.NewKeyDownEvent (Key.Space)); - Assert.Equal (CheckState.UnChecked, checkBox.State); + Assert.Equal (CheckState.UnChecked, checkBox.CheckedState); Assert.True (checkBox.NewMouseEvent (new () { Position = new (0, 0), Flags = MouseFlags.Button1Clicked })); - Assert.Equal (CheckState.None, checkBox.State); + Assert.Equal (CheckState.None, checkBox.CheckedState); checkBox.AllowCheckStateNone = false; - Assert.Equal (CheckState.UnChecked, checkBox.State); + Assert.Equal (CheckState.UnChecked, checkBox.CheckedState); } [Fact] @@ -131,17 +131,17 @@ public class CheckBoxTests (ITestOutputHelper output) var ckb = new CheckBox (); Assert.True (ckb.Width is DimAuto); Assert.True (ckb.Height is DimAuto); - Assert.Equal (CheckState.UnChecked, ckb.State); + Assert.Equal (CheckState.UnChecked, ckb.CheckedState); Assert.False (ckb.AllowCheckStateNone); Assert.Equal (string.Empty, ckb.Text); Assert.Equal ($"{CM.Glyphs.CheckStateUnChecked} ", ckb.TextFormatter.Text); Assert.True (ckb.CanFocus); Assert.Equal (new (0, 0, 2, 1), ckb.Frame); - ckb = new () { Text = "Test", State = CheckState.Checked }; + ckb = new () { Text = "Test", CheckedState = CheckState.Checked }; Assert.True (ckb.Width is DimAuto); Assert.True (ckb.Height is DimAuto); - Assert.Equal (CheckState.Checked, ckb.State); + Assert.Equal (CheckState.Checked, ckb.CheckedState); Assert.False (ckb.AllowCheckStateNone); Assert.Equal ("Test", ckb.Text); Assert.Equal ($"{CM.Glyphs.CheckStateChecked} Test", ckb.TextFormatter.Text); @@ -151,17 +151,17 @@ public class CheckBoxTests (ITestOutputHelper output) ckb = new () { Text = "Test", X = 1, Y = 2 }; Assert.True (ckb.Width is DimAuto); Assert.True (ckb.Height is DimAuto); - Assert.Equal (CheckState.UnChecked, ckb.State); + Assert.Equal (CheckState.UnChecked, ckb.CheckedState); Assert.False (ckb.AllowCheckStateNone); Assert.Equal ("Test", ckb.Text); Assert.Equal ($"{CM.Glyphs.CheckStateUnChecked} Test", ckb.TextFormatter.Text); Assert.True (ckb.CanFocus); Assert.Equal (new (1, 2, 6, 1), ckb.Frame); - ckb = new () { Text = "Test", X = 3, Y = 4, State = CheckState.Checked }; + ckb = new () { Text = "Test", X = 3, Y = 4, CheckedState = CheckState.Checked }; Assert.True (ckb.Width is DimAuto); Assert.True (ckb.Height is DimAuto); - Assert.Equal (CheckState.Checked, ckb.State); + Assert.Equal (CheckState.Checked, ckb.CheckedState); Assert.False (ckb.AllowCheckStateNone); Assert.Equal ("Test", ckb.Text); Assert.Equal ($"{CM.Glyphs.CheckStateChecked} Test", ckb.TextFormatter.Text); @@ -174,16 +174,16 @@ public class CheckBoxTests (ITestOutputHelper output) { var toggled = false; var ckb = new CheckBox (); - ckb.Toggle += (s, e) => toggled = true; + ckb.CheckedStateChanging += (s, e) => toggled = true; - Assert.Equal (CheckState.UnChecked, ckb.State); + Assert.Equal (CheckState.UnChecked, ckb.CheckedState); Assert.False (toggled); Assert.Equal (Key.Empty, ckb.HotKey); ckb.Text = "_Test"; Assert.Equal (Key.T, ckb.HotKey); Assert.True (ckb.NewKeyDownEvent (Key.T)); - Assert.Equal (CheckState.Checked, ckb.State); + Assert.Equal (CheckState.Checked, ckb.CheckedState); Assert.True (toggled); ckb.Text = "T_est"; @@ -191,28 +191,28 @@ public class CheckBoxTests (ITestOutputHelper output) Assert.Equal (Key.E, ckb.HotKey); Assert.True (ckb.NewKeyDownEvent (Key.E.WithAlt)); Assert.True (toggled); - Assert.Equal (CheckState.UnChecked, ckb.State); + Assert.Equal (CheckState.UnChecked, ckb.CheckedState); toggled = false; Assert.Equal (Key.E, ckb.HotKey); Assert.True (ckb.NewKeyDownEvent (Key.E)); Assert.True (toggled); - Assert.Equal (CheckState.Checked, ckb.State); + Assert.Equal (CheckState.Checked, ckb.CheckedState); toggled = false; Assert.True (ckb.NewKeyDownEvent (Key.Space)); Assert.True (toggled); - Assert.Equal (CheckState.UnChecked, ckb.State); + Assert.Equal (CheckState.UnChecked, ckb.CheckedState); toggled = false; Assert.True (ckb.NewKeyDownEvent (Key.Space)); Assert.True (toggled); - Assert.Equal (CheckState.Checked, ckb.State); + Assert.Equal (CheckState.Checked, ckb.CheckedState); toggled = false; Assert.False (ckb.NewKeyDownEvent (Key.Enter)); Assert.False (toggled); - Assert.Equal (CheckState.Checked, ckb.State); + Assert.Equal (CheckState.Checked, ckb.CheckedState); } [Fact] @@ -271,7 +271,7 @@ public class CheckBoxTests (ITestOutputHelper output) Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); Assert.Equal (new (0, 0, 30, 5), pos); - checkBox.State = CheckState.Checked; + checkBox.CheckedState = CheckState.Checked; Application.Refresh (); expected = @$" @@ -333,10 +333,10 @@ public class CheckBoxTests (ITestOutputHelper output) Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); Assert.Equal (new (0, 0, 30, 6), pos); - checkBox1.State = CheckState.Checked; + checkBox1.CheckedState = CheckState.Checked; Assert.Equal (new (1, 1, 25, 1), checkBox1.Frame); Assert.Equal (_size25x1, checkBox1.TextFormatter.ConstrainToSize); - checkBox2.State = CheckState.Checked; + checkBox2.CheckedState = CheckState.Checked; Assert.Equal (new (1, 2, 25, 1), checkBox2.Frame); Assert.Equal (_size25x1, checkBox2.TextFormatter.ConstrainToSize); Application.Refresh (); @@ -389,7 +389,7 @@ public class CheckBoxTests (ITestOutputHelper output) Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); Assert.Equal (new (0, 0, 30, 5), pos); - checkBox.State = CheckState.Checked; + checkBox.CheckedState = CheckState.Checked; Application.Refresh (); expected = @$" @@ -440,7 +440,7 @@ public class CheckBoxTests (ITestOutputHelper output) Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); Assert.Equal (new (0, 0, 30, 5), pos); - checkBox.State = CheckState.Checked; + checkBox.CheckedState = CheckState.Checked; Application.Refresh (); expected = @$" @@ -481,14 +481,14 @@ public class CheckBoxTests (ITestOutputHelper output) var ckb = new CheckBox { AllowCheckStateNone = true }; var checkedInvoked = false; - ckb.Toggle += CheckBoxToggle; + ckb.CheckedStateChanging += CheckBoxToggle; - ckb.State = initialState; - Assert.Equal (initialState, ckb.State); - bool? ret = ckb.OnToggle (); + ckb.CheckedState = initialState; + Assert.Equal (initialState, ckb.CheckedState); + bool? ret = ckb.AdvanceCheckState (); Assert.True (ret); Assert.True (checkedInvoked); - Assert.Equal (initialState, ckb.State); + Assert.Equal (initialState, ckb.CheckedState); return; diff --git a/docfx/docs/migratingfromv1.md b/docfx/docs/migratingfromv1.md index 9c833cbfb..742521e02 100644 --- a/docfx/docs/migratingfromv1.md +++ b/docfx/docs/migratingfromv1.md @@ -296,3 +296,33 @@ The [Aligner](~/api/Terminal.Gui.Aligner.yml) class makes it easy to align eleme - ); + var statusBar = new StatusBar (new Shortcut [] { new (Application.QuitKey, "Quit", Quit) }); ``` + +## `CheckBox` - API renamed and simplified + +In v1 `CheckBox` used `bool?` to represent the 3 states. To support consistent behavior for the `Accept` event, `CheckBox` was refactored to use the new `CheckState` enum instead of `bool?`. + +Additionally the `Toggle` event was renamed `CheckStateChanging` and made cancelable. The `Toggle` method was renamed to `AdvanceCheckState`. + +### How to Fix + +```diff +-var cb = new CheckBox ("_Checkbox", true); { +- X = Pos.Right (label) + 1, +- Y = Pos.Top (label) + 2 +- }; +- cb.Toggled += (e) => { +- }; +- cb.Toggle (); ++ ++var cb = new CheckBox () ++{ ++ Title = "_Checkbox", ++ CheckState = CheckState.Checked ++} ++cb.CheckStateChanging += (s, e) => ++{ ++ e.Cancel = preventChange; ++} ++preventChange = false; ++cb.AdvanceCheckState (); +``` \ No newline at end of file From 1b973eed5ae733f541ad13db13cab7ea16a72046 Mon Sep 17 00:00:00 2001 From: Tig Date: Tue, 6 Aug 2024 08:45:31 -0600 Subject: [PATCH 09/13] Trying to fix publish issue --- GitVersion.yml | 24 ++++++++++++++---------- Terminal.sln | 1 + 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/GitVersion.yml b/GitVersion.yml index 3a183efa2..1946a6c7a 100644 --- a/GitVersion.yml +++ b/GitVersion.yml @@ -2,14 +2,6 @@ mode: ContinuousDeployment tag-prefix: '[vV]' continuous-delivery-fallback-tag: dev branches: - v1_develop: - mode: ContinuousDeployment - tag: dev - regex: v1_develop - source-branches: - - v1_release - pre-release-weight: 100 - v2_develop: mode: ContinuousDeployment tag: dev @@ -25,6 +17,20 @@ branches: is-release-branch: true source-branches: ['v2_develop'] + v1_develop: + mode: ContinuousDeployment + tag: dev + regex: v1_develop + source-branches: + - v1_release + pre-release-weight: 100 + + v1_release: + mode: ContinuousDeployment + regex: v1_release + is-release-branch: true + source-branches: ['v1_develop'] + pull-request: mode: ContinuousDeployment tag: PullRequest.{BranchName} @@ -32,8 +38,6 @@ branches: tag-number-pattern: '[/-](?\d+)' regex: ^(pull|pull\-requests|pr)[/-] source-branches: - - v1_develop - - v1_release - v2_develop - v2_release - feature diff --git a/Terminal.sln b/Terminal.sln index 550bbe4ed..1f2c73a21 100644 --- a/Terminal.sln +++ b/Terminal.sln @@ -21,6 +21,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Settings", "Settings", "{B8 .editorconfig = .editorconfig .filenesting.json = .filenesting.json .gitignore = .gitignore + GitVersion.yml = GitVersion.yml global.json = global.json nuget.config = nuget.config Terminal.sln.DotSettings = Terminal.sln.DotSettings From 63e75b7413a9d15b00ec0bd47abf06200a94e47b Mon Sep 17 00:00:00 2001 From: BDisp Date: Tue, 6 Aug 2024 19:05:36 +0100 Subject: [PATCH 10/13] Fixes #3109. AOT support with .Net 8. (#3638) * Add a native AOT project. * Fixes Text.Json to work with native AOT. * Fix silent errors on unit tests when testing the Red color which has a length of 3. * Allowing test custom configuration without the config.json file match the unit tests configurations. * Fix unit test if tested alone. * Add native project into solution. * Fix merge errors. * Setting ConfigurationManager.ThrowOnJsonErrors as true to throw any serialization issue when published file runs. * Remove unnecessary using's. * Added unit test to ensure all serialization is properly configured. * Fix warnings. * Remove ThrowOnJsonErrors. * Fix warnings. --------- Co-authored-by: Tig --- NativeAot/NativeAot.csproj | 22 ++++ NativeAot/Program.cs | 113 ++++++++++++++++++ .../FolderProfile_net8.0_win-x64_Debug.pubxml | 18 +++ ...olderProfile_net8.0_win-x64_Release.pubxml | 18 +++ NativeAot/Publish_linux-x64_Debug.sh | 5 + NativeAot/Publish_linux-x64_Release.sh | 5 + NativeAot/Publish_osx-x64_Debug.sh | 5 + NativeAot/Publish_osx-x64_Release.sh | 5 + NativeAot/README.md | 10 ++ .../Configuration/SourceGenerationContext.cs | 12 +- Terminal.Gui/Drawing/Alignment.cs | 3 +- Terminal.Gui/Drawing/AlignmentModes.cs | 3 +- Terminal.Gui/Drawing/Color.Formatting.cs | 2 +- Terminal.Gui/Drawing/LineStyle.cs | 3 + Terminal.Gui/View/Adornment/ShadowStyle.cs | 5 +- Terminal.Gui/Views/Button.cs | 4 - Terminal.Gui/Views/Dialog.cs | 10 +- Terminal.Gui/Views/FrameView.cs | 5 +- Terminal.Gui/Views/MessageBox.cs | 7 +- Terminal.Gui/Views/Window.cs | 5 +- Terminal.sln | 6 + .../Configuration/ConfigurationMangerTests.cs | 80 ++++++------- .../SerializableConfigurationPropertyTests.cs | 86 +++++++++++++ UnitTests/Configuration/ThemeScopeTests.cs | 13 +- UnitTests/Configuration/ThemeTests.cs | 3 + UnitTests/TestHelpers.cs | 72 +++++++++++ UnitTests/Views/NumericUpDownTests.cs | 5 +- 27 files changed, 443 insertions(+), 82 deletions(-) create mode 100644 NativeAot/NativeAot.csproj create mode 100644 NativeAot/Program.cs create mode 100644 NativeAot/Properties/PublishProfiles/FolderProfile_net8.0_win-x64_Debug.pubxml create mode 100644 NativeAot/Properties/PublishProfiles/FolderProfile_net8.0_win-x64_Release.pubxml create mode 100644 NativeAot/Publish_linux-x64_Debug.sh create mode 100644 NativeAot/Publish_linux-x64_Release.sh create mode 100644 NativeAot/Publish_osx-x64_Debug.sh create mode 100644 NativeAot/Publish_osx-x64_Release.sh create mode 100644 NativeAot/README.md create mode 100644 UnitTests/Configuration/SerializableConfigurationPropertyTests.cs diff --git a/NativeAot/NativeAot.csproj b/NativeAot/NativeAot.csproj new file mode 100644 index 000000000..6c5e1f136 --- /dev/null +++ b/NativeAot/NativeAot.csproj @@ -0,0 +1,22 @@ + + + + Exe + net8.0 + enable + enable + true + false + + + + + + + + + + + + + diff --git a/NativeAot/Program.cs b/NativeAot/Program.cs new file mode 100644 index 000000000..5ef38db05 --- /dev/null +++ b/NativeAot/Program.cs @@ -0,0 +1,113 @@ +// This is a test application for a native Aot file. + +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using Terminal.Gui; + +namespace NativeAot; + +public static class Program +{ + [RequiresUnreferencedCode ("Calls Terminal.Gui.Application.Init(ConsoleDriver, String)")] + [RequiresDynamicCode ("Calls Terminal.Gui.Application.Init(ConsoleDriver, String)")] + private static void Main (string [] args) + { + Application.Init (); + + #region The code in this region is not intended for use in a native Aot self-contained. It's just here to make sure there is no functionality break with localization in Terminal.Gui using self-contained + + if (Equals(Thread.CurrentThread.CurrentUICulture, CultureInfo.InvariantCulture) && Application.SupportedCultures.Count == 0) + { + // Only happens if the project has true + Debug.Assert (Application.SupportedCultures.Count == 0); + } + else + { + Debug.Assert (Application.SupportedCultures.Count > 0); + Debug.Assert (Equals (CultureInfo.CurrentCulture, Thread.CurrentThread.CurrentUICulture)); + } + + #endregion + + ExampleWindow app = new (); + Application.Run (app); + + // Dispose the app object before shutdown + app.Dispose (); + + // Before the application exits, reset Terminal.Gui for clean shutdown + Application.Shutdown (); + + // To see this output on the screen it must be done after shutdown, + // which restores the previous screen. + Console.WriteLine ($@"Username: {ExampleWindow.UserName}"); + } +} + +// Defines a top-level window with border and title +public class ExampleWindow : Window +{ + public static string? UserName; + + public ExampleWindow () + { + Title = $"Example App ({Application.QuitKey} to quit)"; + + // Create input components and labels + var usernameLabel = new Label { Text = "Username:" }; + + var userNameText = new TextField + { + // Position text field adjacent to the label + X = Pos.Right (usernameLabel) + 1, + + // Fill remaining horizontal space + Width = Dim.Fill () + }; + + var passwordLabel = new Label + { + Text = "Password:", X = Pos.Left (usernameLabel), Y = Pos.Bottom (usernameLabel) + 1 + }; + + var passwordText = new TextField + { + Secret = true, + + // align with the text box above + X = Pos.Left (userNameText), + Y = Pos.Top (passwordLabel), + Width = Dim.Fill () + }; + + // Create login button + var btnLogin = new Button + { + Text = "Login", + Y = Pos.Bottom (passwordLabel) + 1, + + // center the login button horizontally + X = Pos.Center (), + IsDefault = true + }; + + // When login button is clicked display a message popup + btnLogin.Accept += (s, e) => + { + if (userNameText.Text == "admin" && passwordText.Text == "password") + { + MessageBox.Query ("Logging In", "Login Successful", "Ok"); + UserName = userNameText.Text; + Application.RequestStop (); + } + else + { + MessageBox.ErrorQuery ("Logging In", "Incorrect username or password", "Ok"); + } + }; + + // Add the views to the Window + Add (usernameLabel, userNameText, passwordLabel, passwordText, btnLogin); + } +} diff --git a/NativeAot/Properties/PublishProfiles/FolderProfile_net8.0_win-x64_Debug.pubxml b/NativeAot/Properties/PublishProfiles/FolderProfile_net8.0_win-x64_Debug.pubxml new file mode 100644 index 000000000..c883267bf --- /dev/null +++ b/NativeAot/Properties/PublishProfiles/FolderProfile_net8.0_win-x64_Debug.pubxml @@ -0,0 +1,18 @@ + + + + + Debug + Any CPU + bin\Debug\net8.0\publish\win-x64\ + FileSystem + <_TargetId>Folder + net8.0 + win-x64 + true + false + false + + \ No newline at end of file diff --git a/NativeAot/Properties/PublishProfiles/FolderProfile_net8.0_win-x64_Release.pubxml b/NativeAot/Properties/PublishProfiles/FolderProfile_net8.0_win-x64_Release.pubxml new file mode 100644 index 000000000..79576fb52 --- /dev/null +++ b/NativeAot/Properties/PublishProfiles/FolderProfile_net8.0_win-x64_Release.pubxml @@ -0,0 +1,18 @@ + + + + + Release + Any CPU + bin\Release\net8.0\publish\win-x64\ + FileSystem + <_TargetId>Folder + net8.0 + win-x64 + true + false + false + + \ No newline at end of file diff --git a/NativeAot/Publish_linux-x64_Debug.sh b/NativeAot/Publish_linux-x64_Debug.sh new file mode 100644 index 000000000..b58a83cc1 --- /dev/null +++ b/NativeAot/Publish_linux-x64_Debug.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +dotnet clean +dotnet build +dotnet publish -c Debug -r linux-x64 --self-contained diff --git a/NativeAot/Publish_linux-x64_Release.sh b/NativeAot/Publish_linux-x64_Release.sh new file mode 100644 index 000000000..3cb8feb26 --- /dev/null +++ b/NativeAot/Publish_linux-x64_Release.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +dotnet clean +dotnet build +dotnet publish -c Release -r linux-x64 --self-contained diff --git a/NativeAot/Publish_osx-x64_Debug.sh b/NativeAot/Publish_osx-x64_Debug.sh new file mode 100644 index 000000000..1fe41513c --- /dev/null +++ b/NativeAot/Publish_osx-x64_Debug.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +dotnet clean +dotnet build +dotnet publish -c Debug -r osx-x64 --self-contained diff --git a/NativeAot/Publish_osx-x64_Release.sh b/NativeAot/Publish_osx-x64_Release.sh new file mode 100644 index 000000000..06b748b79 --- /dev/null +++ b/NativeAot/Publish_osx-x64_Release.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +dotnet clean +dotnet build +dotnet publish -c Release -r osx-x64 --self-contained diff --git a/NativeAot/README.md b/NativeAot/README.md new file mode 100644 index 000000000..7a55ccfc7 --- /dev/null +++ b/NativeAot/README.md @@ -0,0 +1,10 @@ +# Terminal.Gui C# SelfContained + +This project aims to test the `Terminal.Gui` library to create a simple `native AOT` `self-container` GUI application in C#, ensuring that all its features are available. + +With `Debug` the `.csproj` is used and with `Release` the latest `nuget package` is used, either in `Solution Configurations` or in `Profile Publish` or in the `Publish_linux-x64` or in the `Publish_osx-x64` files. +Unlike self-contained single-file publishing, native AOT publishing must be generated on the same platform as the target execution version. Therefore, if the target execution is Linux, then the publishing must be generated on a Linux operating system. Attempting to generate on Windows for the Linux target will throw an exception. + +To publish the `native AOT` file in `Debug` or `Release` mode, it is not necessary to select it in the `Solution Configurations`, just choose the `Debug` or `Release` configuration in the `Publish Profile` or the `*.sh` files. + +When executing the file directly from the `native AOT` file and needing to debug it, it will be necessary to attach it to the debugger, just like any other standalone application and selecting `Native Code`. \ No newline at end of file diff --git a/Terminal.Gui/Configuration/SourceGenerationContext.cs b/Terminal.Gui/Configuration/SourceGenerationContext.cs index ed93b68ca..85a438b83 100644 --- a/Terminal.Gui/Configuration/SourceGenerationContext.cs +++ b/Terminal.Gui/Configuration/SourceGenerationContext.cs @@ -7,17 +7,17 @@ namespace Terminal.Gui; /// [JsonSerializable (typeof (Attribute))] [JsonSerializable (typeof (Color))] -[JsonSerializable (typeof (ThemeScope))] -[JsonSerializable (typeof (ColorScheme))] -[JsonSerializable (typeof (SettingsScope))] [JsonSerializable (typeof (AppScope))] +[JsonSerializable (typeof (SettingsScope))] [JsonSerializable (typeof (Key))] [JsonSerializable (typeof (GlyphDefinitions))] -[JsonSerializable (typeof (ConfigProperty))] +[JsonSerializable (typeof (Alignment))] +[JsonSerializable (typeof (AlignmentModes))] +[JsonSerializable (typeof (LineStyle))] [JsonSerializable (typeof (ShadowStyle))] -[JsonSerializable (typeof (string))] -[JsonSerializable (typeof (bool))] [JsonSerializable (typeof (bool?))] [JsonSerializable (typeof (Dictionary))] +[JsonSerializable (typeof (Dictionary))] +[JsonSerializable (typeof (Dictionary))] internal partial class SourceGenerationContext : JsonSerializerContext { } diff --git a/Terminal.Gui/Drawing/Alignment.cs b/Terminal.Gui/Drawing/Alignment.cs index 6a160096f..169e4c323 100644 --- a/Terminal.Gui/Drawing/Alignment.cs +++ b/Terminal.Gui/Drawing/Alignment.cs @@ -1,10 +1,11 @@ - +using System.Text.Json.Serialization; namespace Terminal.Gui; /// /// Determines the position of items when arranged in a container. /// +[JsonConverter (typeof (JsonStringEnumConverter))] public enum Alignment { /// diff --git a/Terminal.Gui/Drawing/AlignmentModes.cs b/Terminal.Gui/Drawing/AlignmentModes.cs index b7e0bb87e..1b6e262c4 100644 --- a/Terminal.Gui/Drawing/AlignmentModes.cs +++ b/Terminal.Gui/Drawing/AlignmentModes.cs @@ -1,10 +1,11 @@ - +using System.Text.Json.Serialization; namespace Terminal.Gui; /// /// Determines alignment modes for . /// +[JsonConverter (typeof (JsonStringEnumConverter))] [Flags] public enum AlignmentModes { diff --git a/Terminal.Gui/Drawing/Color.Formatting.cs b/Terminal.Gui/Drawing/Color.Formatting.cs index e38128957..406ceff4b 100644 --- a/Terminal.Gui/Drawing/Color.Formatting.cs +++ b/Terminal.Gui/Drawing/Color.Formatting.cs @@ -284,7 +284,7 @@ public readonly partial record struct Color ), // Any string too short to possibly be any supported format. - { Length: > 0 and < 4 } => throw new ColorParseException ( + { Length: > 0 and < 3 } => throw new ColorParseException ( in text, "Text was too short to be any possible supported format.", in text diff --git a/Terminal.Gui/Drawing/LineStyle.cs b/Terminal.Gui/Drawing/LineStyle.cs index 47e37a97a..a696bc943 100644 --- a/Terminal.Gui/Drawing/LineStyle.cs +++ b/Terminal.Gui/Drawing/LineStyle.cs @@ -1,7 +1,10 @@ #nullable enable +using System.Text.Json.Serialization; + namespace Terminal.Gui; /// Defines the style of lines for a . +[JsonConverter (typeof (JsonStringEnumConverter))] public enum LineStyle { /// No border is drawn. diff --git a/Terminal.Gui/View/Adornment/ShadowStyle.cs b/Terminal.Gui/View/Adornment/ShadowStyle.cs index a410292c6..7a95e78ed 100644 --- a/Terminal.Gui/View/Adornment/ShadowStyle.cs +++ b/Terminal.Gui/View/Adornment/ShadowStyle.cs @@ -1,8 +1,11 @@ -namespace Terminal.Gui; +using System.Text.Json.Serialization; + +namespace Terminal.Gui; /// /// Defines the style of shadow to be drawn on the right and bottom sides of the . /// +[JsonConverter (typeof (JsonStringEnumConverter))] public enum ShadowStyle { /// diff --git a/Terminal.Gui/Views/Button.cs b/Terminal.Gui/Views/Button.cs index f489a8bb4..e5845fbb5 100644 --- a/Terminal.Gui/Views/Button.cs +++ b/Terminal.Gui/Views/Button.cs @@ -5,8 +5,6 @@ // Miguel de Icaza (miguel@gnome.org) // -using System.Text.Json.Serialization; - namespace Terminal.Gui; /// Button is a that provides an item that invokes raises the event. @@ -39,8 +37,6 @@ public class Button : View, IDesignable /// Gets or sets whether s are shown with a shadow effect by default. /// [SerializableConfigurationProperty (Scope = typeof (ThemeScope))] - [JsonConverter (typeof (JsonStringEnumConverter))] - public static ShadowStyle DefaultShadow { get; set; } = ShadowStyle.None; /// Initializes a new instance of . diff --git a/Terminal.Gui/Views/Dialog.cs b/Terminal.Gui/Views/Dialog.cs index c1f18e8fb..aefc6eb5a 100644 --- a/Terminal.Gui/Views/Dialog.cs +++ b/Terminal.Gui/Views/Dialog.cs @@ -1,6 +1,4 @@ -using System.Text.Json.Serialization; - -namespace Terminal.Gui; +namespace Terminal.Gui; /// /// The is a that by default is centered and contains @@ -19,13 +17,11 @@ public class Dialog : Window /// The default for . /// This property can be set in a Theme. [SerializableConfigurationProperty (Scope = typeof (ThemeScope))] - [JsonConverter (typeof (JsonStringEnumConverter))] public static Alignment DefaultButtonAlignment { get; set; } = Alignment.End; // Default is set in config.json - /// The default for . + /// The default for . /// This property can be set in a Theme. [SerializableConfigurationProperty (Scope = typeof (ThemeScope))] - [JsonConverter (typeof (JsonStringEnumConverter))] public static AlignmentModes DefaultButtonAlignmentModes { get; set; } = AlignmentModes.StartToEnd | AlignmentModes.AddSpaceBetweenItems; /// @@ -47,7 +43,6 @@ public class Dialog : Window /// Gets or sets whether all s are shown with a shadow effect by default. /// [SerializableConfigurationProperty (Scope = typeof (ThemeScope))] - [JsonConverter (typeof (JsonStringEnumConverter))] public new static ShadowStyle DefaultShadow { get; set; } = ShadowStyle.None; // Default is set in config.json /// @@ -56,7 +51,6 @@ public class Dialog : Window /// [SerializableConfigurationProperty (Scope = typeof (ThemeScope))] - [JsonConverter (typeof (JsonStringEnumConverter))] public new static LineStyle DefaultBorderStyle { get; set; } = LineStyle.Single; // Default is set in config.json private readonly List